livespace.services
Class EntityRegistry

java.lang.Object
  extended by dsto.dfc.databeans.AbstractDataObject
      extended by dsto.dfc.databeans.DataObject
          extended by livespace.services.EntityRegistry
All Implemented Interfaces:
IDataObject, IDataObjectChildListener, Serializable, Cloneable, Iterable<Entity>

public class EntityRegistry
extends DataObject
implements Iterable<Entity>

A registry of Entity's. This is a data object whose properties are entity ID's and values are the entiites themselves.

Author:
Matthew Phillips
See Also:
Serialized Form

Field Summary
 
Fields inherited from class dsto.dfc.databeans.DataObject
propertyToValue, typeInfo
 
Fields inherited from class dsto.dfc.databeans.AbstractDataObject
listeners
 
Fields inherited from interface dsto.dfc.databeans.IDataObject
OVERRIDE, PERSISTENT, PERSISTENT_OVERRIDE, TRANSIENT, TRANSIENT_OVERRIDE
 
Constructor Summary
EntityRegistry()
           
 
Method Summary
 void add(Entity entity)
          Add an entity to the registry.
 void clear()
          Remove all entities.
 boolean contains(Entity entity)
           
 boolean containsId(String id)
          Test if a given ID exists in the registry.
 Entity find(String id)
          Find an entity with a given ID.
protected  int getEventNestingLevel()
           
 Iterator<Entity> iterator()
          Create an iterator over all the values in the object.
 Object mutex()
          The mutex that must be held to ensure thread safety.
 Entity peek(String id)
          Peek to see if an entity exists.
 void remove(Entity entity)
          Remove an entity.
 void remove(String id)
          Remove an entity with a given ID.
 void setValue(Object name, Object value, int mode)
          Set the value of a given property.
 Entity singleton()
          Get the entity that is the sole entry in the registry, This is usually used for entity types where only one instance will exist (eg room).
 int size()
          The number of entities in the registry.
 Set<Entity> snapshot()
          Create a snapshot of the current entities.
 Entity[] toArray()
           
 void waitForEntities(int count)
          Wait a default amount of time for a given number of entities to arrive.
 Entity waitForEntity()
          Wait up to a default amount of time for a single entity to arrive.
 Entity waitForEntity(String id)
          Wait for an entity with a given ID to appear and then return it.
 
Methods inherited from class dsto.dfc.databeans.DataObject
getTypeInfo, getValue, isTransient, propertyIterator, setTypeInfo, shallowClone
 
Methods inherited from class dsto.dfc.databeans.AbstractDataObject
addFirstPropertyListener, addPropertyListener, childPropertyChanged, firePropertyChangedEvent, firePropertyChangedEvent, firePropertyChangedEvent, firePropertyChangedEvent, firePropertyChangedEvent, firePropertyChangedEvent, getBeanValue, getBooleanValue, getBooleanValue, getCharValue, getCharValue, getDoubleValue, getDoubleValue, getFloatValue, getFloatValue, getIntValue, getIntValue, getLongValue, getLongValue, getObjectValue, getPropertyListeners, getShortValue, getStringValue, registerValue, removePropertyListener, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, toString, unregisterValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EntityRegistry

public EntityRegistry()
Method Detail

mutex

public Object mutex()
The mutex that must be held to ensure thread safety.

See Also:
EntityContainer.mutex(), Entity.mutex()

clear

public void clear()
Remove all entities.


iterator

public Iterator<Entity> iterator()
Description copied from class: DataObject
Create an iterator over all the values in the object.

Specified by:
iterator in interface Iterable<Entity>
Overrides:
iterator in class DataObject

add

public void add(Entity entity)
         throws IllegalArgumentException
Add an entity to the registry.

Parameters:
entity - The entity to add.
Throws:
IllegalArgumentException - if ID is null or already in use.

remove

public void remove(Entity entity)
            throws IllegalStateException
Remove an entity. This actually removes an entity by its ID, not by its object identity, so the remote possibility that another entity instance with the same ID is checked for and flagged with an IllegalStateException.

Parameters:
entity -
Throws:
IllegalStateException - if another entity with the same ID is in the registry.

remove

public void remove(String id)
Remove an entity with a given ID. No effect if no such entity exists.


setValue

public void setValue(Object name,
                     Object value,
                     int mode)
Description copied from interface: IDataObject
Set the value of a given property. If the object supports it, a property change event should be emitted.

Specified by:
setValue in interface IDataObject
Overrides:
setValue in class DataObject
Parameters:
name - A property name.
value - The new value. On most objects using null removes the property.
mode - The mode for the value. This is a bitwise OR of TRANSIENT and/or OVERRIDE. Using TRANSIENT specifies the value is to be marked transient (ie isTransient (name) will return true). Not all data object implementations support dynamic transience. OVERRIDE must be set if an existing value is to be overwritten: if not set and a value is already defined, then nothing is changed. The IDataObject.setValue (name, value) call corresponds to IDataBean.setValue (name, value, OVERRIDE).
See Also:
IDataObject.setValue(Object, Object)

peek

public Entity peek(String id)
Peek to see if an entity exists.

Parameters:
id - The entity ID.
Returns:
The entity, or null if not found.
See Also:
find(String)

find

public Entity find(String id)
            throws IllegalArgumentException
Find an entity with a given ID. Generates an error if no entity with the ID is found.

Parameters:
id - The entity ID.
Returns:
The entity.
Throws:
IllegalArgumentException - if no entity with the ID exists.
See Also:
peek(String)

containsId

public boolean containsId(String id)
Test if a given ID exists in the registry.


contains

public boolean contains(Entity entity)

singleton

public Entity singleton()
                 throws IllegalStateException
Get the entity that is the sole entry in the registry, This is usually used for entity types where only one instance will exist (eg room).

Returns:
The entity,
Throws:
IllegalStateException - if there is not exactly one entity in the registry.

size

public int size()
The number of entities in the registry.


snapshot

public Set<Entity> snapshot()
Create a snapshot of the current entities. This will not change if the registry is later modified,

See Also:
iterator()

toArray

public Entity[] toArray()

getEventNestingLevel

protected int getEventNestingLevel()
See Also:
EventListenerList.getEventNestingLevel()

waitForEntity

public Entity waitForEntity()
                     throws SynchronizationException
Wait up to a default amount of time for a single entity to arrive.

Returns:
The singleton entity.
Throws:
SynchronizationException - if exactly one entity isn't in the registry by the given timeout.
See Also:
SizeSynchronizer.waitForEntity(EntityRegistry)

waitForEntities

public void waitForEntities(int count)
                     throws SynchronizationException
Wait a default amount of time for a given number of entities to arrive.

Parameters:
count - The required minimum number of entities.
Throws:
SynchronizationException - if exactly one entity isn't in the registry by the given timeout.
See Also:
SizeSynchronizer.waitForEntities(EntityRegistry, int)

waitForEntity

public Entity waitForEntity(String id)
                     throws SynchronizationException
Wait for an entity with a given ID to appear and then return it.

Parameters:
id - The entity ID.
Throws:
SynchronizationException - if the entity does not appear within the default timeout period.
See Also:
PropertySynchronizer.waitForNonNullProperty(IDataObject, String)


Copyright © 2008 Commonwealth of Australia