org.elkoserver.server.context
Class Contextor

java.lang.Object
  extended by org.elkoserver.foundation.actor.RefTable
      extended by org.elkoserver.server.context.Contextor
All Implemented Interfaces:
Iterable<DispatchTarget>

public class Contextor
extends RefTable

Main state data structure in a Context Server.


Method Summary
 Trace appTrace()
          Obtain the application trace object for this context server.
 Item createGeoItem(String name, boolean isPossibleContainer, boolean isDeletable, double lat, double lon)
          Return a newly minted geo-positioned Item (i.e., one created at runtime rather than loaded from the object database).
 Item createItem(String name, boolean isPossibleContainer, boolean isDeletable)
          Return a newly minted Item (i.e., one created at runtime rather than loaded from the object database).
 void createObjectRecord(String ref, String contRef, BasicObject obj)
          Create a new (offline) object and store its description in the object database.
 void findServiceLink(String serviceName, ArgRunnable handler)
          Find or make a connection to an external service.
 String getMetadataContextName(String contextRef)
          Obtain the name metadata for a context, as most recently reported by the presence server.
 String getMetadataUserName(String userRef)
          Obtain the name metadata for a user, as most recently reported by the presence server.
 Object getStaticObject(String ref)
          Lookup an object in the static object table.
 ObjDB odb()
          Return a reference to the attached object store.
 void queryObjects(JSONObject template, String collectionName, int maxResults, ArgRunnable handler)
          Query the attached object store.
 long randomLong()
          Generate a high-quality random number.
 Server server()
          Obtain the server object for this Context Server.
 String uniqueID(String root)
          Generate a unique object ID.
 
Methods inherited from class org.elkoserver.foundation.actor.RefTable
addClass, addRef, addRef, clones, dispatchMessage, dispatchMessage, get, iterator, remove, remove, rootRef
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

appTrace

public Trace appTrace()
Obtain the application trace object for this context server.

Returns:
the context server's trace object.

createItem

public Item createItem(String name,
                       boolean isPossibleContainer,
                       boolean isDeletable)
Return a newly minted Item (i.e., one created at runtime rather than loaded from the object database). The new item will be born with no contents, no mods, and no container.

Parameters:
name - The name for the new item, or null if the name doesn't matter.
isPossibleContainer - Flag that is true if the new item may itself be used as a container.
isDeletable - Flag that is true if the new item may be deleted by users.

createGeoItem

public Item createGeoItem(String name,
                          boolean isPossibleContainer,
                          boolean isDeletable,
                          double lat,
                          double lon)
Return a newly minted geo-positioned Item (i.e., one created at runtime rather than loaded from the object database). The new item will be born with no contents, no mods, and no container.

Parameters:
name - The name for the new item, or null if the name doesn't matter.
isPossibleContainer - Flag that is true if the new item may itself be used as a container.
isDeletable - Flag that is true if the new item may be deleted by users.
lat - Position latitude, in decimal degrees.
lon - Position longitude, in decimal degrees.

createObjectRecord

public void createObjectRecord(String ref,
                               String contRef,
                               BasicObject obj)
Create a new (offline) object and store its description in the object database.

Parameters:
ref - Reference string for the new object, or null to have one generated automatically.
contRef - Reference string for the new object's container, or null to not have it put into a container.
obj - The new object.

findServiceLink

public void findServiceLink(String serviceName,
                            ArgRunnable handler)
Find or make a connection to an external service.

Parameters:
serviceName - Name of the service being sought.
handler - A runnable that will be invoked with the relevant service link once the connection is located or created. The handler will be passed a null if no connection was possible.

getStaticObject

public Object getStaticObject(String ref)
Lookup an object in the static object table.

Parameters:
ref - Reference string denoting the object of interest.
Returns:
the object named 'ref' from the static object table, or null if there is no such object.

getMetadataContextName

public String getMetadataContextName(String contextRef)
Obtain the name metadata for a context, as most recently reported by the presence server.

Parameters:
contextRef - The context for which the name metadata is sought.
Returns:
the name for the given context, or null if none has ever been reported.

getMetadataUserName

public String getMetadataUserName(String userRef)
Obtain the name metadata for a user, as most recently reported by the presence server.

Parameters:
userRef - The user for whom metadata is sought.
Returns:
the name for the given user, or null if none has ever been reported.

odb

public ObjDB odb()
Return a reference to the attached object store. XXX Is this a POLA violation??


queryObjects

public void queryObjects(JSONObject template,
                         String collectionName,
                         int maxResults,
                         ArgRunnable handler)
Query the attached object store.

Parameters:
template - Query template indicating the object(s) desired.
collectionName - Name of collection to query, or null to take the configured default.
maxResults - Maximum number of result objects to return, or 0 to indicate no fixed limit.
handler - Handler to be called with the results. The results will be an array of the object(s) requested, or null if no objects could be retrieved. XXX Is this a POLA violation??

randomLong

public long randomLong()
Generate a high-quality random number.

Returns:
a random long.

server

public Server server()
Obtain the server object for this Context Server.

Returns:
this Context Server's server object.

uniqueID

public String uniqueID(String root)
Generate a unique object ID.

Parameters:
root -
Returns:
a reference string for a new object with the given root.