EDU.oswego.cs.dl.util.concurrent

Class ObservableSync

public class ObservableSync extends Object implements Sync

The ObservableSync class performs no synchronization itself, but invokes event-style messages to other observer objects upon invocation of Sync methods. These observers typically perform monitoring, logging, or other bookkeeping operations surrounding the object being managed by this Sync object.

Because ObservableSync does not itself perform any synchronization control, the attempt operation always succeeds. This class is typically used (via LayeredSync) as a wrapper around those that do perform synchronization control.

This class is based around a standard Observer design pattern. It is not hard to convert this to instead use a Listener design (as seen in AWT and JavaBeans), by defining associated EventObjects and forwarding them.

[ Introduction to this package. ]

See Also:

Nested Class Summary
interfaceObservableSync.SyncObserver
Interface for objects that observe ObservableSyncs.
Field Summary
protected Objectarg_
protected CopyOnWriteArraySetobservers_
Constructor Summary
ObservableSync(Object notificationArgument)
Create an ObservableSync that uses the supplied argument for all notifications.
Method Summary
voidacquire()
voidattach(ObservableSync.SyncObserver obs)
Add obs to the set of observers *
booleanattempt(long msecs)
voiddetach(ObservableSync.SyncObserver obs)
Remove obs from the set of observers.
ObjectgetNotificationArgument()
Return the argument used for notifications
Iteratorobservers()
Return an iterator that can be used to traverse through current set of observers
voidrelease()
ObjectsetNotificationArgument(Object notificationArg)
Set the argument used for notifications.

Field Detail

arg_

protected Object arg_

observers_

protected final CopyOnWriteArraySet observers_

Constructor Detail

ObservableSync

public ObservableSync(Object notificationArgument)
Create an ObservableSync that uses the supplied argument for all notifications. The argument is typically an object that is being managed by this Sync object.

Method Detail

acquire

public void acquire()

attach

public void attach(ObservableSync.SyncObserver obs)
Add obs to the set of observers *

attempt

public boolean attempt(long msecs)

detach

public void detach(ObservableSync.SyncObserver obs)
Remove obs from the set of observers. No effect if not in set *

getNotificationArgument

public Object getNotificationArgument()
Return the argument used for notifications

observers

public Iterator observers()
Return an iterator that can be used to traverse through current set of observers

release

public void release()

setNotificationArgument

public Object setNotificationArgument(Object notificationArg)
Set the argument used for notifications.

Returns: the previous value of this argument