livespace.services
Class Synchronizer

java.lang.Object
  extended by livespace.services.Synchronizer
All Implemented Interfaces:
PropertyListener, EventListener
Direct Known Subclasses:
PropertySynchronizer, SizeSynchronizer

public abstract class Synchronizer
extends Object
implements PropertyListener

Base for classes that support synchronizing a thread with a property change triggered by another thread. Subclasses need to implement isSynchronized() which is called whenever a property change takes place.

Author:
Matthew Phillips
See Also:
isSynchronized(), SizeSynchronizer, PropertySynchronizer

Field Summary
protected  IDataObject source
           
protected  boolean synced
           
 
Constructor Summary
Synchronizer(IDataObject source)
          Create a new instance.
 
Method Summary
protected abstract  String createFailMessage()
          Create an error message indicating why synchronization has failed.
protected abstract  boolean isSynchronized()
          Called to test whether the object is currently synchronized.
protected  boolean isSynchronized(PropertyEvent e)
          This is called whenever a property changes on the object of interest.
 void propertyValueChanged(PropertyEvent e)
           
 void synchronize()
          Wait up to the default time (ENTITY_RESPONSE_TIMEOUT millis) for synchronization to take place,
 void synchronize(long maxWait)
          Wait a given amount of time for a synchronization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

source

protected IDataObject source

synced

protected boolean synced
Constructor Detail

Synchronizer

public Synchronizer(IDataObject source)
Create a new instance.

Parameters:
source - The source to listen for property changes on.
Method Detail

synchronize

public void synchronize()
                 throws SynchronizationException
Wait up to the default time (ENTITY_RESPONSE_TIMEOUT millis) for synchronization to take place,

Throws:
SynchronizationException - if exactly one entity isn't in the registry by the given timeout.

synchronize

public void synchronize(long maxWait)
                 throws SynchronizationException
Wait a given amount of time for a synchronization.

Parameters:
maxWait - The maximum time (in millis) to wait.
Throws:
SynchronizationException - if synchronization hasn't occurred by the given timeout.

isSynchronized

protected boolean isSynchronized(PropertyEvent e)
This is called whenever a property changes on the object of interest. By default it simply calls isSynchronized(). Subclasses may override this if they want to use the property change event as part of the test.


isSynchronized

protected abstract boolean isSynchronized()
Called to test whether the object is currently synchronized.


createFailMessage

protected abstract String createFailMessage()
Create an error message indicating why synchronization has failed.


propertyValueChanged

public void propertyValueChanged(PropertyEvent e)
Specified by:
propertyValueChanged in interface PropertyListener


Copyright © 2008 Commonwealth of Australia