|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdsto.dfc.databeans.AbstractDataObject
dsto.dfc.databeans.SimpleDataObject
dsto.dfc.databeans.FancyDataObject
livespace.services.Entity
public abstract class Entity
Base class for Livespace service entities. An entity is simply a data bean (IDataBean) with a two guaranteed fields: a unique ID and a human-readable name (where possible).
Entities may be published and replicated using the Livespace container
classes EntityClient
and
EntityServer
.
Entities must have a default constructor, although this may be non-public.
Entities have a logical type, which is simply a string accessed via
getType()
e.g. "computer", "light", "person". Although specialised
subclasses of Entity are often used for representing difference types as a
convenience (e.g. ComputerEntity
) the
only thing that matters on the Livespace bus is the entity type. When an
entity is instantiated locally from a remote copy, the framework checks to
see if a mapping from entity type to a Java class exists using
Livespace.findEntityClass(String)
and uses that class for the local
entity instance if it exists. If not, then a
GenericEntity
is used. Clients that care if a
particular Java class will be used for a given type must therefore make sure
that it is registered using
Livespace.registerEntityClass(String, Class)
.
Field Summary | |
---|---|
EntityContainer |
container
The client or server container this entity is managed by. |
String |
id
The unique ID for the entity. |
protected long |
lastTouched
Last time the entity got an update from the server (used by client container only). |
String |
name
The human-readable name of the entity for presentation purposes. |
protected int |
unconfirmedUpdates
The number of updates for which we haven't seen a response from the server yet (used by client container only). |
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 | |
---|---|
Entity()
Create a default instance with an automatic ID and name. |
|
Entity(String id)
Create a new instance. |
|
Entity(String id,
String name)
Create a new instance. |
Method Summary | |
---|---|
protected static Entity |
create(String id,
String entityType)
Create an instance of an Entity using the registered type class if available. |
protected static String |
createId()
Shortcut to create a unique ID. |
Elvin |
getElvin()
Shortcut to get the Elvin connection from the current container. |
abstract String |
getType()
The type of the object (eg "room", "light", "volume", etc). |
static String |
getType(Class<? extends Entity> entityClass)
Shortcut to extract the type of an Entity class. |
TypeInfo |
getTypeInfo()
Get meta data type info for the entity (if any). |
Object |
mutex()
Get the mutual exclusion lock for this entity. |
static boolean |
sameEntity(Entity e1,
Entity e2)
Test if two entities are the same by ID comparison. |
IDataObject |
shallowClone()
Clone the entity. |
void |
waitForProperty(String property,
boolean value)
Wait for a property value to be changed from the client container's thread. |
void |
waitForProperty(String property,
int value)
Wait for a property value to be changed from the client container's thread. |
Object |
waitForProperty(String property,
Object value)
Wait for a property value to be changed from the client container's thread. |
Object |
waitForProperty(String property,
Object value,
long maxWait)
Wait for a property value to be changed from the client container's thread. |
Methods inherited from class dsto.dfc.databeans.FancyDataObject |
---|
childPropertyChanged, getValue, isTransient, propertyIterator, setValue |
Methods inherited from class dsto.dfc.databeans.SimpleDataObject |
---|
getFieldNames, setValue |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public String id
public String name
public transient EntityContainer container
protected transient int unconfirmedUpdates
protected transient long lastTouched
Constructor Detail |
---|
public Entity()
public Entity(String id)
id
- The entity ID (will be used as default name also).public Entity(String id, String name)
id
- The entity ID.name
- The entity name.Method Detail |
---|
public IDataObject shallowClone()
Livespace.createUniqueId()
) if
the original entity will continue to be used.
shallowClone
in interface IDataObject
shallowClone
in class FancyDataObject
DataObjects.deepClone(IDataObject)
public TypeInfo getTypeInfo()
TypeRegistry.peekTypeInfo(String)
with the entity's type (getType
()) as the argument.
To register meta type info for an entity, use
TypeRegistry.register(String, TypeInfo)
.
getTypeInfo
in interface IDataObject
getTypeInfo
in class SimpleDataObject
TypeRegistry
public abstract String getType()
NOTE: it is also a good practice to provide a static field that defines the entity type on the class: eg
public static final String ENTITY_TYPE = "room";
public Elvin getElvin() throws IllegalStateException
IllegalStateException
- if there is no container for the entity.public void waitForProperty(String property, boolean value) throws SynchronizationException
property
- The property name,value
- The required value.
SynchronizationException
- if the value hasn't changed in the default
time.Livespace.ENTITY_RESPONSE_TIMEOUT
public void waitForProperty(String property, int value) throws SynchronizationException
property
- The property name,value
- The required value.
SynchronizationException
- if the value hasn't changed in the default
time.Livespace.ENTITY_RESPONSE_TIMEOUT
public Object waitForProperty(String property, Object value) throws SynchronizationException
property
- The property name,value
- The required value.
SynchronizationException
- if the value hasn't changed in the default
time.Livespace.ENTITY_RESPONSE_TIMEOUT
public Object waitForProperty(String property, Object value, long maxWait) throws SynchronizationException
property
- The property name,value
- The required value.maxWait
- The maximum time (in millis) to wait.
SynchronizationException
- if the value hasn't changed in the default
time.public static String getType(Class<? extends Entity> entityClass)
entityClass
- An Entity-derived class.
getType()
.public static boolean sameEntity(Entity e1, Entity e2)
public Object mutex()
protected static Entity create(String id, String entityType) throws IllegalArgumentException
id
- The ID for the entity.entityType
- The entity type.
IllegalArgumentException
- if the entity could not be instantiated or
ID is null.Livespace.findEntityClass(String)
,
EntityContainer.createEntity(String, String)
protected static String createId()
Livespace.createUniqueId()
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |