livespace.services
Class SizeSynchronizer

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

public class SizeSynchronizer
extends Synchronizer
implements PropertyListener

Used to wait for a limited time until a required number of elements arrive in a registry or IDataObject-based collection.

See Also:
waitForEntity(EntityRegistry), waitForEntities(EntityRegistry, int), waitForElement(Collection), waitForElements(Collection, int)

Field Summary
 
Fields inherited from class livespace.services.Synchronizer
source, synced
 
Constructor Summary
SizeSynchronizer(Collection<?> collection, int requiredSize)
          Create a new instance.
SizeSynchronizer(EntityRegistry registry, int requiredSize)
          Create a new instance.
 
Method Summary
protected  String createFailMessage()
          Create an error message indicating why synchronization has failed.
protected  int getSize()
           
protected  boolean isSynchronized()
          Called to test whether the object is currently synchronized.
static Object waitForElement(Collection<?> collection)
          Shortcut to wait up to the default time (ENTITY_WAIT_TIMEOUT millis) for a single element to arrive.
static void waitForElements(Collection<?> collection, int requiredSize)
          Shortcut to wait for up to a given time for a given number of entities to arrive.
static void waitForElements(Collection<?> collection, int requiredSize, int timeout)
          Shortcut to wait up to the default time (ENTITY_WAIT_TIMEOUT millis) for a given number of entities to arrive.
static void waitForEntities(EntityRegistry registry, int requiredSize)
          Shortcut to wait up to the default time (ENTITY_WAIT_TIMEOUT millis) for a given number of entities to arrive.
static Entity waitForEntity(EntityRegistry registry)
          Shortcut to wait up to the default time (ENTITY_WAIT_TIMEOUT millis) for a single entity to arrive.
 
Methods inherited from class livespace.services.Synchronizer
isSynchronized, propertyValueChanged, synchronize, synchronize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface dsto.dfc.databeans.PropertyListener
propertyValueChanged
 

Constructor Detail

SizeSynchronizer

public SizeSynchronizer(EntityRegistry registry,
                        int requiredSize)
Create a new instance. You may find it more convenient to use waitForEntities(EntityRegistry, int) instead.

Parameters:
registry - The registry.
requiredSize - The required number of entities. To indicate the a number of entities (eg >= requiredSize), using a negative number. eg for >= 3 entities, use -3.

SizeSynchronizer

public SizeSynchronizer(Collection<?> collection,
                        int requiredSize)
Create a new instance. You may find it more convenient to use waitForElements(Collection, int)instead.

Parameters:
collection - The collection. This must also implement the IDataObject interface.
requiredSize - The required number of entities. To indicate the a number of entities (eg >= requiredSize), using a negative number. eg for >= 3 entities, use -3.
Method Detail

waitForEntity

public static Entity waitForEntity(EntityRegistry registry)
                            throws SynchronizationException
Shortcut to wait up to the default time (ENTITY_WAIT_TIMEOUT millis) for a single entity to arrive.

Parameters:
registry - The registry to listen to.
Returns:
The singleton entity.
Throws:
SynchronizationException - if exactly one entity isn't in the registry by the given timeout.
See Also:
waitForEntities(EntityRegistry, int)

waitForEntities

public static void waitForEntities(EntityRegistry registry,
                                   int requiredSize)
                            throws SynchronizationException
Shortcut to wait up to the default time (ENTITY_WAIT_TIMEOUT millis) for a given number of entities to arrive.

Parameters:
registry - The registry to listen to.
requiredSize - The required number of entities. To indicate the a number of entities (eg >= requiredSize), using a negative number. eg for >= 3 entities, use -3.
Throws:
SynchronizationException - if exactly one entity isn't in the registry by the given timeout.

waitForElement

public static Object waitForElement(Collection<?> collection)
                             throws SynchronizationException
Shortcut to wait up to the default time (ENTITY_WAIT_TIMEOUT millis) for a single element to arrive.

Parameters:
collection - The collection. This must also implement the IDataObject interface.
Throws:
SynchronizationException - if exactly one entity isn't in the collection by the given timeout.
See Also:
waitForElements(Collection, int)

waitForElements

public static void waitForElements(Collection<?> collection,
                                   int requiredSize)
                            throws SynchronizationException
Shortcut to wait for up to a given time for a given number of entities to arrive.

Parameters:
collection - The collection. This must also implement the IDataObject interface.
requiredSize - The required number of entities. To indicate the a number of entities (eg >= requiredSize), using a negative number. eg for >= 3 entities, use -3.
Throws:
SynchronizationException - if exactly one entity isn't in the registry by the given timeout.
See Also:
waitForElements(Collection,int,int)

waitForElements

public static void waitForElements(Collection<?> collection,
                                   int requiredSize,
                                   int timeout)
                            throws SynchronizationException
Shortcut to wait up to the default time (ENTITY_WAIT_TIMEOUT millis) for a given number of entities to arrive.

Parameters:
collection - The collection. This must also implement the IDataObject interface.
requiredSize - The required number of entities. To indicate the a number of entities (eg >= requiredSize), using a negative number. eg for >= 3 entities, use -3.
timeout - The max amount of time (in millis) to wait.
Throws:
SynchronizationException - if exactly one entity isn't in the registry by the given timeout.
See Also:
waitForElement(Collection)

isSynchronized

protected boolean isSynchronized()
Description copied from class: Synchronizer
Called to test whether the object is currently synchronized.

Specified by:
isSynchronized in class Synchronizer

getSize

protected int getSize()

createFailMessage

protected String createFailMessage()
Description copied from class: Synchronizer
Create an error message indicating why synchronization has failed.

Specified by:
createFailMessage in class Synchronizer


Copyright © 2008 Commonwealth of Australia