monitor
Class Monitor

java.lang.Object
  extended by monitor.AbstractMonitor
      extended by monitor.Monitor

public final class Monitor
extends AbstractMonitor

A final class for Monitors.

Use an object of this class if you want to use delegation.

Extend AbstractMonitor, if you want to use inheritance.

The methods have the same meaning as in AbstractMonitor, but here they are public.

Version:
2.0
Author:
Theodore S. Norvell
See Also:
AbstractMonitor, Condition

Constructor Summary
Monitor()
           
Monitor(Assertion invariant)
           
Monitor(java.lang.String name)
           
Monitor(java.lang.String name, Assertion invariant)
           
 
Method Summary
 void doWithin(java.lang.Runnable runnable)
          Run the runnable inside the monitor.
<T> T
doWithin(RunnableWithResult<T> runnable)
          Run the runnable inside the monitor.
 void enter()
          Enter the monitor.
 boolean invariant()
          The invariant.
 void leave()
          Leave the monitor.
<T> T
leave(T result)
          Leave the monitor.
 Condition makeCondition()
          Create a condition queue with no associated checked Assertion.
 Condition makeCondition(Assertion assertion)
          Create a condition queue associated with a checked Assertion.
 Condition makeCondition(java.lang.String name)
          Create a condition queue with no associated checked Assertion.
 Condition makeCondition(java.lang.String name, Assertion assertion)
          Create a condition queue associated with a checked Assertion.
 
Methods inherited from class monitor.AbstractMonitor
addListener, getName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Monitor

public Monitor()

Monitor

public Monitor(Assertion invariant)

Monitor

public Monitor(java.lang.String name)

Monitor

public Monitor(java.lang.String name,
               Assertion invariant)
Method Detail

invariant

public boolean invariant()
Description copied from class: AbstractMonitor
The invariant. The default implementation always returns true. This method should be overridden if at all possible with the strongest economically evaluable invariant.

Overrides:
invariant in class AbstractMonitor

enter

public void enter()
Description copied from class: AbstractMonitor
Enter the monitor. Any thread calling this method is delayed until the monitor is unoccupied. Upon returning from this method, the monitor is considered occupied.

A thread must not attempt to enter a Monitor it is already in.

Overrides:
enter in class AbstractMonitor

leave

public void leave()
Description copied from class: AbstractMonitor
Leave the monitor. After returning from this method, the thread no longer occupies the monitor.

Only a thread that is in the monitor may leave it.

Overrides:
leave in class AbstractMonitor

leave

public <T> T leave(T result)
Description copied from class: AbstractMonitor
Leave the monitor. After returning from this method, the thread no longer occupies the monitor.

Only a thread that is in the monitor may leave it.

Overrides:
leave in class AbstractMonitor

doWithin

public void doWithin(java.lang.Runnable runnable)
Description copied from class: AbstractMonitor
Run the runnable inside the monitor.

Any thread calling this method will be delayed until the monitor is empty. The "run" method of its argument is then executed within the protection of the monitor.

When the run method returns, if the thread still occupies the monitor, it leaves the monitor.

Overrides:
doWithin in class AbstractMonitor
Parameters:
runnable - A Runnable object.

doWithin

public <T> T doWithin(RunnableWithResult<T> runnable)
Description copied from class: AbstractMonitor
Run the runnable inside the monitor.

Any thread calling this method will be delayed until the monitor is empty. The "run" method of its argument is then executed within the protection of the monitor.

When the run method returns, if the thread still occupies the monitor, it leaves the monitor.

Thus the signalAndLeave method may be called within the run method.

Overrides:
doWithin in class AbstractMonitor
Parameters:
runnable - A RunnableWithResult object.
Returns:
The value computed by the run method of the runnable.

makeCondition

public Condition makeCondition()
Description copied from class: AbstractMonitor
Create a condition queue with no associated checked Assertion.

Overrides:
makeCondition in class AbstractMonitor

makeCondition

public Condition makeCondition(Assertion assertion)
Description copied from class: AbstractMonitor
Create a condition queue associated with a checked Assertion. The Assertion will be checked prior to an signal of the condition.

Overrides:
makeCondition in class AbstractMonitor

makeCondition

public Condition makeCondition(java.lang.String name)
Description copied from class: AbstractMonitor
Create a condition queue with no associated checked Assertion.

Overrides:
makeCondition in class AbstractMonitor

makeCondition

public Condition makeCondition(java.lang.String name,
                               Assertion assertion)
Description copied from class: AbstractMonitor
Create a condition queue associated with a checked Assertion. The Assertion will be checked prior to an signal of the condition.

Overrides:
makeCondition in class AbstractMonitor