org.jdesktop.wonderland.server.cell
Class CellMO

java.lang.Object
  extended by org.jdesktop.wonderland.server.cell.CellMO
All Implemented Interfaces:
com.sun.sgs.app.ManagedObject, java.io.Serializable
Direct Known Subclasses:
EnvironmentCellMO, ModelCellMO, ViewCellMO

public abstract class CellMO
extends java.lang.Object
implements com.sun.sgs.app.ManagedObject, java.io.Serializable

Superclass for all server side representation of a cell

Author:
paulby
See Also:
Serialized Form

Field Summary
protected  com.sun.sgs.app.ManagedReference<com.sun.sgs.app.Channel> cellChannelRef
           
protected  CellID cellID
           
protected  java.util.HashSet<com.sun.sgs.app.ManagedReference<com.sun.sgs.app.ClientSession>> clientSessionRefs
           
protected static java.util.logging.Logger logger
           
 
Constructor Summary
CellMO()
          Default constructor, used when the cell is created via WFS
CellMO(com.jme.bounding.BoundingVolume localBounds, CellTransform transform)
          Create a CellMO with the specified localBounds and transform.
 
Method Summary
 void addChild(CellMO child)
          Add a child cell to list of children contained within this cell.
 void addChildrenChangeListener(CellChildrenChangeListenerSrv listener)
          Add a children change listener to this cell.
protected  CellSessionProperties addClient(WonderlandClientID clientID, ClientCapabilities capabilities)
          Add a client session with the specified capabilities to this cell.
 void addComponent(CellComponentMO component)
          Add a component to this cell.
 void addComponent(CellComponentMO component, java.lang.Class componentClass)
           
 void addComponentChangeListener(ComponentChangeListenerSrv listener)
          Add a component change listener to this cell.
 void addParentChangeListener(CellParentChangeListenerSrv listener)
          Add a parent change listener to this cell.
 void addTransformChangeListener(TransformChangeListenerSrv listener)
          Add a TransformChangeListener to this cell.
protected  CellSessionProperties changeClient(WonderlandClientID clientID, ClientCapabilities capabilities)
          Called to notify the cell that some aspect of the client sessions capabilities have changed.
 void detach()
          Detach this cell from its parent
protected  void fireChildChangedEvent(CellMO child, boolean added)
          Notification of a children change event
protected  void fireComponentChangeEvent(ComponentChangeListenerSrv.ChangeType type, CellComponentMO component)
          Notification of a component change event
protected  void fireParentChangeEvent(CellMO parent)
          Notification of a parent change event
 java.util.Collection<com.sun.sgs.app.ManagedReference<CellMO>> getAllChildrenRefs()
          Return the collection of children references for this cell.
 java.util.Collection<com.sun.sgs.app.ManagedReference<CellComponentMO>> getAllComponentRefs()
          Get all cell components associated with this cell
 CellID getCellID()
          Return the cellID for this cell
protected abstract  java.lang.String getClientCellClassName(WonderlandClientID clientID, ClientCapabilities capabilities)
          Returns the fully qualified name of the class that represents this cell on the client
protected  CellClientState getClientState(CellClientState cellClientState, WonderlandClientID clientID, ClientCapabilities capabilities)
          Returns the client-side state of the cell.
<T extends CellComponentMO>
T
getComponent(java.lang.Class<T> cellComponentClass)
          If this cell supports the capabilities of cellComponent then return an instance of cellComponent associated with this cell.
 com.jme.bounding.BoundingVolume getLocalBounds()
          Return (a clone) of the cells bounds in cell local coordinates
 CellTransform getLocalTransform(CellTransform result)
          Return the cells transform
 java.lang.String getName()
          Get the name of the cell, by default the name is the cell id.
 int getNumChildren()
          Return the number of children of this cell
 CellMO getParent()
          Return the cell which is the parentRef of this cell, null if this not attached to a parentRef
 short getPriority()
          Return the priorty of the cell.
 CellServerState getServerState(CellServerState setup)
          Returns the setup information currently configured on the cell.
protected  ViewCellCacheRevalidationListener getViewCellCacheRevalidationListener()
          Returns the ViewCacheOperation, or null
 com.jme.bounding.BoundingVolume getWorldBounds()
          Returns the local bounds transformed into VW coordinates.
 CellTransform getWorldTransform(CellTransform result)
          Get the world transform of this cells origin.
 boolean isLive()
          Get the live state of this cell.
 boolean removeChild(CellMO child)
          Remove the child from the list of children of this cell.
 void removeChildrenChangeListener(CellChildrenChangeListenerSrv listener)
          Remove a children change listener.
 void removeComponent(CellComponentMO component)
          Removes a component from this cell.
 void removeComponentChangeListener(ComponentChangeListenerSrv listener)
          Remove a component change listener.
 void removeParentChangeListener(CellParentChangeListenerSrv listener)
          Remove a parent change listener.
protected  void removeSession(WonderlandClientID clientID)
          Remove this cell from the specified session, only applicable to cells with a ChannelComponent.
 void removeTransformChangeListener(TransformChangeListenerSrv listener)
          Remove the specified listener.
 void sendCellMessage(WonderlandClientID clientID, CellMessage message)
          A utility routine that fetches the channel component of the cell and sends a message on it.
protected  void setLive(boolean live)
          Set the live state of this cell.
 void setLocalBounds(com.jme.bounding.BoundingVolume bounds)
          Set the bounds of the cell in cell local coordinates
protected  void setLocalTransform(CellTransform transform)
          Set the transform for this cell.
 void setName(java.lang.String name)
          Set the name of the cell.
 void setPriority(short priority)
          Set the cell priority.
 void setServerState(CellServerState state)
          Sets the server-side state of the cell, given the server state properties passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cellID

protected CellID cellID

cellChannelRef

protected com.sun.sgs.app.ManagedReference<com.sun.sgs.app.Channel> cellChannelRef

logger

protected static java.util.logging.Logger logger

clientSessionRefs

protected java.util.HashSet<com.sun.sgs.app.ManagedReference<com.sun.sgs.app.ClientSession>> clientSessionRefs
Constructor Detail

CellMO

public CellMO()
Default constructor, used when the cell is created via WFS


CellMO

public CellMO(com.jme.bounding.BoundingVolume localBounds,
              CellTransform transform)
Create a CellMO with the specified localBounds and transform. If either parameter is null an IllegalArgumentException will be thrown.

Parameters:
localBounds - the bounds of the new cell, must not be null
transform - the transform for this cell, must not be null
Method Detail

setLocalBounds

public void setLocalBounds(com.jme.bounding.BoundingVolume bounds)
Set the bounds of the cell in cell local coordinates

Parameters:
bounds -

getLocalBounds

public com.jme.bounding.BoundingVolume getLocalBounds()
Return (a clone) of the cells bounds in cell local coordinates

Returns:
the bounds in local coordinates

getWorldBounds

public com.jme.bounding.BoundingVolume getWorldBounds()
Returns the local bounds transformed into VW coordinates. These bounds do not include the subgraph bounds. This call is only valid for live cells

Returns:

getWorldTransform

public CellTransform getWorldTransform(CellTransform result)
Get the world transform of this cells origin. This call can only be made on live cells, an IllegalStateException will be thrown if the cell is not live. TODO - should we create our own exception type ?

Parameters:
result - the CellTransform to populate with the result and return, can be null in which case a new CellTransform will be returned.
Returns:

addChild

public void addChild(CellMO child)
              throws MultipleParentException
Add a child cell to list of children contained within this cell. A cell can only be attached to a single parent cell at any given time, attempting to add a cell to multiple parents will result in a MultipleParentException being thrown.

Parameters:
child -
Throws:
MultipleParentException

removeChild

public boolean removeChild(CellMO child)
Remove the child from the list of children of this cell.

Parameters:
child - to remove
Returns:
true if the child was removed, false if the cell was not a child of this cell.

getNumChildren

public int getNumChildren()
Return the number of children of this cell

Returns:
the number of children

getAllChildrenRefs

public java.util.Collection<com.sun.sgs.app.ManagedReference<CellMO>> getAllChildrenRefs()
Return the collection of children references for this cell. If this cell has no children an empty collection is returned. Users of this call should not make changes to the collection directly

Returns:
a collection of references to the children of this cell.

getParent

public CellMO getParent()
Return the cell which is the parentRef of this cell, null if this not attached to a parentRef


detach

public void detach()
Detach this cell from its parent


setLocalTransform

protected void setLocalTransform(CellTransform transform)
Set the transform for this cell. This will define the localOrigin of the cell on the client. This transform is combined with all parentRef transforms to define the location of the cell in 3 space. Changing the transform repositions the cell which is a fairly expensive operation as it changes the computed bounds of this cell and potentially all it's parent cells. This method is usually called during cell construction or from reconfigureCell. If you want a cell that moves regularly around the world use MovableComponent.

Parameters:
transform -

getLocalTransform

public CellTransform getLocalTransform(CellTransform result)
Return the cells transform

Returns:
return a clone of the transform

getCellID

public CellID getCellID()
Return the cellID for this cell

Returns:
cellID

isLive

public boolean isLive()
Get the live state of this cell. live cells are connected to the world root, inlive cells are not


setLive

protected void setLive(boolean live)
Set the live state of this cell. Live cells are connected to the world root and are present in the world, non-live cells are not

Parameters:
live -

getName

public java.lang.String getName()
Get the name of the cell, by default the name is the cell id.

Returns:
the cell's name

setName

public void setName(java.lang.String name)
Set the name of the cell. The name is simply for developer reference.

Parameters:
name -

addClient

protected CellSessionProperties addClient(WonderlandClientID clientID,
                                          ClientCapabilities capabilities)
Add a client session with the specified capabilities to this cell. Called by the ViewCellCacheMO as part of makeing a cell active, only applicable to cells with a ChannelComponent.

Parameters:
clientID - the ID of the client that is being added
capabilities -
Returns:

changeClient

protected CellSessionProperties changeClient(WonderlandClientID clientID,
                                             ClientCapabilities capabilities)
Called to notify the cell that some aspect of the client sessions capabilities have changed. This call is made from the ViewCellCacheOperations exectue method returned by addSession.

Parameters:
clientID -
capabilities -
Returns:

removeSession

protected void removeSession(WonderlandClientID clientID)
Remove this cell from the specified session, only applicable to cells with a ChannelComponent. This modifies the ChannelComponent for this cell (if it exists) but does not modify the CellMO itself.

Parameters:
clientID -

getClientCellClassName

protected abstract java.lang.String getClientCellClassName(WonderlandClientID clientID,
                                                           ClientCapabilities capabilities)
Returns the fully qualified name of the class that represents this cell on the client


getClientState

protected CellClientState getClientState(CellClientState cellClientState,
                                         WonderlandClientID clientID,
                                         ClientCapabilities capabilities)
Returns the client-side state of the cell. If the cellClientState argument is null, then the method should create an appropriate class, otherwise, the method should just fill in details in the class. Returns the client- side state class

Parameters:
cellClientState - If null, create a new object
clientID - The unique ID of the client
capabilities - The client capabilities

getViewCellCacheRevalidationListener

protected ViewCellCacheRevalidationListener getViewCellCacheRevalidationListener()
Returns the ViewCacheOperation, or null

Returns:

setServerState

public void setServerState(CellServerState state)
Sets the server-side state of the cell, given the server state properties passed in.

Parameters:
state - the properties to set the state with

getServerState

public CellServerState getServerState(CellServerState setup)
Returns the setup information currently configured on the cell. If the setup argument is non-null, fill in that object and return it. If the setup argument is null, create a new setup object.

Parameters:
setup - The setup object, if null, creates one.
Returns:
The current setup information

getPriority

public short getPriority()
Return the priorty of the cell. A cells priority dictates the order in which it is loaded by a client. Priortity 0 cells are loaded first, followed by subsequent priority levels. Priority is only a hint to the client, it has no effect on the server The default priority is 5

Returns:

setPriority

public void setPriority(short priority)
Set the cell priority. The priority must be >=0 otherwise an IllegalArgumentException will be thrown. The default priority is 5

Parameters:
priority -

getComponent

public <T extends CellComponentMO> T getComponent(java.lang.Class<T> cellComponentClass)
If this cell supports the capabilities of cellComponent then return an instance of cellComponent associated with this cell. Otherwise return null.

Parameters:
cellComponent -
Returns:
See Also:
MovableCellComponent

getAllComponentRefs

public java.util.Collection<com.sun.sgs.app.ManagedReference<CellComponentMO>> getAllComponentRefs()
Get all cell components associated with this cell

Returns:
a collection of ManagedReferences to cell components

addComponent

public void addComponent(CellComponentMO component)
Add a component to this cell. Only a single instance of each component class can be added to a cell. Adding duplicate components will result in an IllegalArgumentException

Parameters:
component -

addComponent

public void addComponent(CellComponentMO component,
                         java.lang.Class componentClass)

removeComponent

public void removeComponent(CellComponentMO component)
Removes a component from this cell. If the cell component does not exist on this cell, this method does nothing.

Parameters:
component - The component to remove from this cell

addComponentChangeListener

public void addComponentChangeListener(ComponentChangeListenerSrv listener)
Add a component change listener to this cell. This listener will be notified any time a component is added or removed from this cell. The listener can either be a Serializable object or and instance of ManagedObject.

Parameters:
listener - the listener to add

removeComponentChangeListener

public void removeComponentChangeListener(ComponentChangeListenerSrv listener)
Remove a component change listener.

Parameters:
listener - the listener to remove

fireComponentChangeEvent

protected void fireComponentChangeEvent(ComponentChangeListenerSrv.ChangeType type,
                                        CellComponentMO component)
Notification of a component change event

Parameters:
type - the type of event (addition or removal)
component - the component that was added or removed

addTransformChangeListener

public void addTransformChangeListener(TransformChangeListenerSrv listener)
Add a TransformChangeListener to this cell. The listener will be called for any changes to the cells transform. The listener can either be a Serialized object, or an instance of ManagedReference. Both types are handled correctly. Listeners should generally execute quickly, if they take a long time it is recommended that the listener schedules a new task to service the callback.

Parameters:
listener - to add

removeTransformChangeListener

public void removeTransformChangeListener(TransformChangeListenerSrv listener)
Remove the specified listener.

Parameters:
listener - to be removed

addParentChangeListener

public void addParentChangeListener(CellParentChangeListenerSrv listener)
Add a parent change listener to this cell. This listener will be notified any time the parent of this cell changes. The listener can either be a Serializable object or and instance of ManagedObject.

Parameters:
listener - the listener to add

removeParentChangeListener

public void removeParentChangeListener(CellParentChangeListenerSrv listener)
Remove a parent change listener.

Parameters:
listener - the listener to remove

fireParentChangeEvent

protected void fireParentChangeEvent(CellMO parent)
Notification of a parent change event

Parameters:
parent - the new parent cell (may be null)

addChildrenChangeListener

public void addChildrenChangeListener(CellChildrenChangeListenerSrv listener)
Add a children change listener to this cell. This listener will be notified any time the children of this cell change. The listener can either be a Serializable object or and instance of ManagedObject.

Parameters:
listener - the listener to add

removeChildrenChangeListener

public void removeChildrenChangeListener(CellChildrenChangeListenerSrv listener)
Remove a children change listener.

Parameters:
listener - the listener to remove

fireChildChangedEvent

protected void fireChildChangedEvent(CellMO child,
                                     boolean added)
Notification of a children change event

Parameters:
child - the child cell
added - true if the child was added, or false if it was removed

sendCellMessage

public void sendCellMessage(WonderlandClientID clientID,
                            CellMessage message)
A utility routine that fetches the channel component of the cell and sends a message on it. If there is no channel component (should never happen), this method logs an error message.

Parameters:
clientID - An optional client-side if the message is in response
message - The CellMessage


Open Wonderland - http://openwonderland.org