livespace.services
Class EntityServer

java.lang.Object
  extended by livespace.services.EntityContainer
      extended by livespace.services.EntityServer
All Implemented Interfaces:
PropertyListener, Disposable, Closeable, EventListener, CloseListener, NotificationListener

public class EntityServer
extends EntityContainer

A container that publishes its entities for access by clients. Clients may discover entities published by the server and perform create/read/write/delete operations on them.

Performance note: the server only subscribes to changes to entities it publishes which means that the server's subscription needs to change every time an entity is added or deleted. Since resubscription is a relatively costly operation it's a good idea performance-wise if services that know what their initial entity set is try to add all them to a registry and then publish them in one step. You can do this thus:

   // create a registry
   EntityRegistry entities = new EntityRegistry ();
        
   // add entities to registry
   ...
           
   // publish the entities
   EntityServer server = new EntityServer (elvin, room, "light", entities);
 

Author:
Matthew Phillips
See Also:
EntityClient

Nested Class Summary
 
Nested classes/interfaces inherited from class livespace.services.EntityContainer
EntityContainer.EmitNotificationTask
 
Field Summary
protected  boolean disposed
           
 
Fields inherited from class livespace.services.EntityContainer
containerId, elvin, entities, room, scheduler
 
Constructor Summary
EntityServer(Elvin elvin, RoomEntity room, String entityType)
          Create an instance hosting entities within a given room scope (ie contained entities are visible only to the current room).
EntityServer(Elvin elvin, RoomEntity room, String entityType, EntityRegistry entities)
          Create an instance hosting entities within a given room scope (ie contained entities are visible only to the current room).
EntityServer(Elvin elvin, String entityType)
          Create an instance with no room scope (ie contained entities have global scope).
 
Method Summary
 void dispose()
          Dispose of the object (unregister listeners, close open resources etc).
 boolean getAllowClientCreate()
           
 boolean getAllowClientDelete()
           
protected  void handleNotification(NotificationEvent e)
           
 void propertyValueChanged(PropertyEvent e)
           
 void setAllowClientCreate(boolean allowClientCreate)
          Set to true to allow clients to create new entities in this server (default is false).
 void setAllowClientDelete(boolean allowClientDelete)
          Set to true to allow clients to delete entities from this server (default is false).
protected  void subscribeDiscover()
          Subscribe to entity discovery ("find" and "ping") requests.
protected  void subscribeUpdate(String expr)
          Create/update the Elvin subscription for entity modification requests.
 void testCrash()
          Used to simulate a service crash (unclean exit without notification).
 void testUncrash()
          Reverse the effect of testCrash().
 
Methods inherited from class livespace.services.EntityContainer
close, connectionClosed, createEntity, createXmlInput, createXmlOutput, emit, emitAsync, getOrCreateEntity, isClosed, isInResponseToMe, mutex, notificationReceived, read, registerEntityTree, setContainerRecursively, setContainerRecursively, setDefaultUpdaterForThread, setUpdateExecutor, shouldPublish, splitPropertyPath, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

disposed

protected volatile boolean disposed
Constructor Detail

EntityServer

public EntityServer(Elvin elvin,
                    String entityType)
             throws IOException
Create an instance with no room scope (ie contained entities have global scope). This version is usually used just for hosting a RoomEntity.

Parameters:
elvin - The Elvin service.
entityType - The type of entity to discover. This is the value returned by Entity.getType().
Throws:
IOException
See Also:
todo add an allow create/delete option

EntityServer

public EntityServer(Elvin elvin,
                    RoomEntity room,
                    String entityType)
             throws IOException
Create an instance hosting entities within a given room scope (ie contained entities are visible only to the current room).

Parameters:
elvin - The Elvin connection.
room - The room the entities are part of. This may be null meaning the entities are not part of a room.
entityType - The type of entity to discover. This is the value returned by Entity.getType().
Throws:
IOException
See Also:
EntityServer(Elvin, String)

EntityServer

public EntityServer(Elvin elvin,
                    RoomEntity room,
                    String entityType,
                    EntityRegistry entities)
             throws IOException
Create an instance hosting entities within a given room scope (ie contained entities are visible only to the current room).

Parameters:
elvin - The Elvin connection.
room - The room the entities are part of. This may be null meaning the entities are not part of a room.
entityType - The type of entity to discover. This is the value returned by Entity.getType().
entities - The initial set of entities. This instance becomes the set of entities that is shared with clients.
Throws:
IOException
See Also:
EntityServer(Elvin, String)
Method Detail

getAllowClientCreate

public boolean getAllowClientCreate()

setAllowClientCreate

public void setAllowClientCreate(boolean allowClientCreate)
Set to true to allow clients to create new entities in this server (default is false). This only makes sense when there is a single visible server for the given entity type: if there are multiple servers this will result in duplicate entities being created in each one.


getAllowClientDelete

public boolean getAllowClientDelete()

setAllowClientDelete

public void setAllowClientDelete(boolean allowClientDelete)
Set to true to allow clients to delete entities from this server (default is false).


testCrash

public void testCrash()
Used to simulate a service crash (unclean exit without notification). Use only for testing purposes.

See Also:
testUncrash()

testUncrash

public void testUncrash()
Reverse the effect of testCrash(). Use only for testing.


dispose

public void dispose()
Description copied from interface: Disposable
Dispose of the object (unregister listeners, close open resources etc). It should be safe to call this method more than once. Note for beans that support client event listeners: if there are listeners registered when this is called, this method should do nothing.

Specified by:
dispose in interface Disposable
Overrides:
dispose in class EntityContainer

subscribeDiscover

protected void subscribeDiscover()
                          throws IOException
Subscribe to entity discovery ("find" and "ping") requests.

Throws:
IOException

subscribeUpdate

protected void subscribeUpdate(String expr)
                        throws IOException
Create/update the Elvin subscription for entity modification requests.

Parameters:
expr - The modification subscription.
Throws:
IOException

propertyValueChanged

public void propertyValueChanged(PropertyEvent e)

handleNotification

protected void handleNotification(NotificationEvent e)
Specified by:
handleNotification in class EntityContainer


Copyright © 2008 Commonwealth of Australia