|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlivespace.services.EntityContainer
public abstract class EntityContainer
Base class for containers that manage distributed Entity instances.
EntityClient
,
EntityServer
Nested Class Summary | |
---|---|
protected class |
EntityContainer.EmitNotificationTask
Used to emit a notification as a background task. |
Field Summary | |
---|---|
protected String |
containerId
UUID for this container. |
Elvin |
elvin
The elvin connection being used by the container. |
EntityRegistry |
entities
The entities being managed by the container. |
RoomEntity |
room
The room the conatiner is operating within. |
protected Scheduler |
scheduler
Scheduler used for periodic and one-off background tasks. |
Constructor Summary | |
---|---|
EntityContainer(Elvin elvin,
RoomEntity room)
|
|
EntityContainer(Elvin elvin,
RoomEntity room,
EntityRegistry entities)
|
Method Summary | |
---|---|
void |
close()
Synonym for dispose() . |
void |
connectionClosed(CloseEvent e)
|
protected Entity |
createEntity(String id,
String entityType)
Create a new entity or re-use an existing weakly-cached version previously created in this container. |
protected XmlInput |
createXmlInput()
|
protected XmlOutput |
createXmlOutput()
|
void |
dispose()
Dispose of the object (unregister listeners, close open resources etc). |
protected void |
emit(Notification ntfn)
Shortcut to emit a notification. |
protected void |
emitAsync(Notification ntfn)
Emit a notification asynchronously using a scheduler task. |
protected Entity |
getOrCreateEntity(String id,
String entityType)
Find an existing entity in the registry or create a new one if none exists. |
protected abstract void |
handleNotification(NotificationEvent e)
|
boolean |
isClosed()
|
protected boolean |
isInResponseToMe(Notification ntfn)
Test if a notification was generated in response to something I sent. |
Object |
mutex()
The lock that must be held to ensure thread-safe access to entities in this container. |
void |
notificationReceived(NotificationEvent e)
|
protected void |
read(Entity entity,
Notification ntfn,
boolean init)
Read and update state from an incoming info notification. |
protected void |
registerEntityTree(Object object)
Register any entities found in a tree of data objects. |
protected static void |
setContainerRecursively(IDataObject object,
EntityContainer container)
Set the container property for a tree of data objects. |
protected static void |
setContainerRecursively(IDataObject object,
EntityContainer container,
boolean shouldEmitNotification)
Set the container property for a tree of data objects. |
static void |
setDefaultUpdaterForThread(Executor executor)
Set the default update executor for the current thread, or null to revert to the default. |
void |
setUpdateExecutor(Executor newExecutor)
Set the update executor for this container, or null to use the default executor. |
protected static boolean |
shouldPublish(Entity entity,
Object property)
Test if a given property should be automatically exported/imported by the read ()/write () functions. |
protected static String[] |
splitPropertyPath(String str)
Split a property path of the form "prop1/prop2/prop3" into a string array. |
protected void |
write(Entity entity,
Notification ntfn)
Write the entity's significant state into a notification for publication. |
protected void |
write(Notification ntfn,
PropertyPath path,
Object value)
Write an abbreviated version of the entity's significant state into a notification, given that a specified property has just changed. |
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 |
Field Detail |
---|
public final Elvin elvin
public final EntityRegistry entities
public final RoomEntity room
protected String containerId
protected Scheduler scheduler
Livespace.acquireScheduler()
.
Constructor Detail |
---|
public EntityContainer(Elvin elvin, RoomEntity room) throws IOException
IOException
public EntityContainer(Elvin elvin, RoomEntity room, EntityRegistry entities) throws IOException
IOException
Method Detail |
---|
public void close()
dispose()
.
close
in interface Closeable
public void dispose()
Disposable
dispose
in interface Disposable
public boolean isClosed()
public Object mutex()
Entity.mutex()
,
EntityRegistry.mutex()
public static void setDefaultUpdaterForThread(Executor executor)
UI application use note: you can set the default updater for your UI toolkit's thread using code like (for SWT in this case):
Executor entityUpdateExecutor = new Executor () { public void execute (Runnable command) { display.asyncExec (command); } }; setDefaultUpdaterForThread (entityUpdateExecutor);If you do this, then all UI elements no longer need to worry about thread sync issues, since all entity containers will update their contents using async runnables executed in the same thread as the UI. This invalidates the need for adaptors like DFC's UIPropertyListener.
setUpdateExecutor(Executor)
public void setUpdateExecutor(Executor newExecutor)
The default executor for a newly-created container is the
thread-local one set by
setDefaultUpdaterForThread(Executor)
.
protected void registerEntityTree(Object object)
object
- An object being added to the registry (not
necessarily a top-level entity).public void connectionClosed(CloseEvent e)
connectionClosed
in interface CloseListener
public void notificationReceived(NotificationEvent e)
notificationReceived
in interface NotificationListener
protected abstract void handleNotification(NotificationEvent e)
protected void emit(Notification ntfn) throws IOException
IOException
emitAsync(Notification)
protected void emitAsync(Notification ntfn)
emit(Notification)
protected Entity getOrCreateEntity(String id, String entityType)
id
- The entity ID.entityType
- The entity type.protected Entity createEntity(String id, String entityType)
id
- The entity ID.entityType
- The entity type.
protected void read(Entity entity, Notification ntfn, boolean init) throws InvalidFormatException
entity
- The entity to read into.ntfn
- The info notification to read from.init
- True if this is an initialisation info i.e. contains
the entire entity state rather than just a delta. If
this is true any properties in entity that aren't
present in ntfn are considered to be defunct and are
removed.
InvalidFormatException
write(Entity, Notification)
protected void write(Entity entity, Notification ntfn) throws InvalidFormatException
The default implementation writes out all the emittable (see
shouldPublish(Entity, Object)
) properties of the entity
using write(Entity, Notification)
. Subclasses that don't
wish to follow this pattern may override.
InvalidFormatException
read(Entity, Notification, boolean)
,
write(Notification, PropertyPath, Object)
protected void write(Notification ntfn, PropertyPath path, Object value) throws InvalidFormatException
write(livespace.services.Entity, org.avis.client.Notification)
if they wish.
The default implementation simply handballs to write(livespace.services.Entity, org.avis.client.Notification)
.
ntfn
- The notificationpath
- The path to the property that changed.
InvalidFormatException
- if an error occurred while writing
the data to the notification (eg unserializable object).protected static String[] splitPropertyPath(String str)
protected XmlInput createXmlInput()
protected XmlOutput createXmlOutput()
protected boolean isInResponseToMe(Notification ntfn)
protected static boolean shouldPublish(Entity entity, Object property)
protected static void setContainerRecursively(IDataObject object, EntityContainer container)
object
- The root object to set the.container
- The new container reference.protected static void setContainerRecursively(IDataObject object, EntityContainer container, boolean shouldEmitNotification)
object
- The root object to set the .container
- The new container reference.shouldEmitNotification
- If true, an event notification will fire
if the container property on the entity has changed. If
false, no event notification will be fired.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |