context.arch.server
Class Server

java.lang.Object
  |
  +--context.arch.BaseObject
        |
        +--context.arch.widget.Widget
              |
              +--context.arch.server.Server
Direct Known Subclasses:
SId, STourId, SUser

public abstract class Server
extends Widget
implements Handler

This class is the basic context server, with attributes and methods that should apply to all context servers. A server is a widget with added gathering and storage facilities. Servers are attached to people (incl. groups), places and things. Basically, a server subscribes to a set of widgets, stores and updates the attribute values from the widgets. A server has a "key" attribute that identifies the entity it is attached to. For example, a user server's key may be USERNAME. The server will only request and store information that pertains to a give value of USERNAME.

See Also:
Widget

Field Summary
static int DEFAULT_PORT
          Default port to use for communications.
protected  WidgetHandles widgets
          The set of widgets this server is monitoring.
 
Fields inherited from class context.arch.widget.Widget
attributes, attributeTypes, callbacks, CLASS, CurrentOffset, DEFAULT_PORT, id, PUT_DATA, PUT_DATA_REPLY, QUERY, QUERY_ATTRIBUTES, QUERY_ATTRIBUTES_REPLY, QUERY_CALLBACKS, QUERY_CALLBACKS_REPLY, QUERY_REPLY, QUERY_SERVICES, QUERY_SERVICES_REPLY, QUERY_VERSION, QUERY_VERSION_REPLY, services, SPACER, storage, subscribers, TIMESTAMP, UPDATE, UPDATE_AND_QUERY, UPDATE_AND_QUERY_REPLY, VERSION, VERSION_NUMBER
 
Fields inherited from class context.arch.BaseObject
communications, EXIT_OK, handlers, ID, parser, PING, PING_REPLY, serviceHandlers
 
Constructor Summary
Server(int port, java.lang.String id, boolean storageFlag, WidgetHandles widgets)
          Constructor that sets up internal variables for maintaining the list of server attributes and callbacks.
Server(int port, java.lang.String id, WidgetHandles widgets)
          Constructor that sets up internal variables for maintaining the list of server attributes and callbacks.
Server(java.lang.String id, boolean storageFlag, WidgetHandles widgets)
          Constructor that sets up internal variables for maintaining the list of server attributes and callbacks.
Server(java.lang.String clientClass, java.lang.String serverClass, int serverPort, java.lang.String encoderClass, java.lang.String decoderClass, boolean storageFlag, java.lang.String id, WidgetHandles widgets)
          Constructor that sets up internal variables for maintaining the list of server attributes and callbacks, and setting up the Widget info.
Server(java.lang.String clientClass, java.lang.String serverClass, int serverPort, java.lang.String encoderClass, java.lang.String decoderClass, java.lang.String storageClass, java.lang.String id, WidgetHandles widgets)
          Constructor that sets up internal variables for maintaining the list of server attributes and callbacks, and setting up the Widget info.
Server(java.lang.String id, WidgetHandles widgets)
          Constructor that sets up internal variables for maintaining the list of server attributes and callbacks.
 
Method Summary
 DataObject handle(java.lang.String callback, DataObject data)
          This method implements the handle method in the Handler interface.
protected  DataObject queryWidget(DataObject query, boolean update, java.lang.String error)
          This method runs a query on a widget, asking for either it's latest acquired data (QUERY) or asking for the widget to acquire and return new data (UPDATE_AND_QUERY).
protected  void serverSetup()
          This method sets up the server for use.
protected  Attributes setAttributes()
          This method is called to aggregate the list of attributes that the widgets relevant to this server provide.
protected  Callbacks setCallbacks()
          This method is called to subscribe to the widgets this server is interested in.
protected abstract  Conditions setConditions()
          This abstract method sets the conditions to apply to the server's subscriptions.
protected abstract  Attributes setServerAttributes()
          This abstract method set the attributes for a server - those that are specific to the server, and not contained in the widgets it subscribes to.
protected abstract  Callbacks setServerCallbacks()
          This abstract method set the callbacks for a server - those that are specific to the server, and not contained in the widgets it subscribes to.
protected abstract  Services setServerServices()
          This abstract method set the services for a server - those that are specific to the server, and not contained in the widgets it subscribes to.
protected  Services setServices()
          This method is called to aggregate the list of services that the widgets relevant to this widget provide.
 void setWidgets(WidgetHandles widgets)
          This method sets the widgets that this server should subscribe to.
 void startSubscriptions()
          This method is called to subscribe to the widgets this server is interested in.
 void storeAttributeNameValues(AttributeNameValues atts)
          This method stores the attribute name values, both in persistent storage and in local storage.
 
Methods inherited from class context.arch.widget.Widget
addSubscriber, canHandle, canHandle, canHandle, canHandle, executeService, getAttributeType, getCurrentTime, getNewOffset, getNewOffsetNoDelay, isAttribute, isCallback, notify, processCallbackReply, putData, queryAttributes, queryCallbacks, queryGenerator, queryServices, removeSubscriber, retrieveData, runUserMethod, runWidgetMethod, sendToSubscribers, setAttribute, store, store, updateWidgetInformation
 
Methods inherited from class context.arch.BaseObject
askInterpreter, decodeData, encodeData, executeAsynchronousWidgetService, executeSynchronousWidgetService, getHostAddress, getId, getVersion, getVersion, getWidgetAttributes, getWidgetCallbacks, getWidgetServices, main, pingComponent, pollWidget, putDataInWidget, queryVersion, quit, retrieveDataFrom, retrieveDataFrom, retrieveDataFrom, retrieveDataFrom, retrieveDataFrom, retrieveDataFrom, retrieveDataFrom, returnPing, runComponentMethod, runMethod, serviceResult, setId, setVersion, subscribeTo, subscribeTo, subscribeTo, subscribeTo, unsubscribeFrom, updateAndPollWidget, userCallback, userRequest, userRequest, userRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
Default port to use for communications.

widgets

protected WidgetHandles widgets
The set of widgets this server is monitoring.
Constructor Detail

Server

public Server(java.lang.String clientClass,
              java.lang.String serverClass,
              int serverPort,
              java.lang.String encoderClass,
              java.lang.String decoderClass,
              java.lang.String storageClass,
              java.lang.String id,
              WidgetHandles widgets)
Constructor that sets up internal variables for maintaining the list of server attributes and callbacks, and setting up the Widget info.
Parameters:
clientClass - Class to use for client communications
serverClass - Class to use for server communications
serverPort - Port to use for server communications
encoderClass - Class to use for communications encoding
decoderClass - Class to use for communications decoding
storageClass - Class to use for storage
id - String to use for widget id and persistent storage
widgets - The set of widgets this server will subscribe to

Server

public Server(java.lang.String clientClass,
              java.lang.String serverClass,
              int serverPort,
              java.lang.String encoderClass,
              java.lang.String decoderClass,
              boolean storageFlag,
              java.lang.String id,
              WidgetHandles widgets)
Constructor that sets up internal variables for maintaining the list of server attributes and callbacks, and setting up the Widget info. This version takes a boolean to indicate whether the default storage class should be used or whether not storage should be provided.
Parameters:
clientClass - Class to use for client communications
serverClass - Class to use for server communications
serverPort - Port to use for server communications
encoderClass - Class to use for communications encoding
decoderClass - Class to use for communications decoding
storageFlag - Flag to determine whether storage should be used or not
id - String to use for widget id and persistent storage
widgets - The set of widgets this server will subscribe to

Server

public Server(int port,
              java.lang.String id,
              WidgetHandles widgets)
Constructor that sets up internal variables for maintaining the list of server attributes and callbacks. It takes a port number as a parameter to indicate which port to listen for messages/connections.
Parameters:
port - Port to listen to for incoming messages
id - Widget id
widgets - The set of widgets this server will subscribe to

Server

public Server(int port,
              java.lang.String id,
              boolean storageFlag,
              WidgetHandles widgets)
Constructor that sets up internal variables for maintaining the list of server attributes and callbacks. It takes a port number as a parameter to indicate which port to listen for messages/connections.
Parameters:
port - Port to listen to for incoming messages
id - Widget id
storageFlag - Flag to determine whether storage should be used or not
widgets - The set of widgets this server will subscribe to

Server

public Server(java.lang.String id,
              WidgetHandles widgets)
Constructor that sets up internal variables for maintaining the list of server attributes and callbacks. It takes the widget id as a parameter
Parameters:
id - ID of the widget
widgets - The set of widgets this server will subscribe to

Server

public Server(java.lang.String id,
              boolean storageFlag,
              WidgetHandles widgets)
Constructor that sets up internal variables for maintaining the list of server attributes and callbacks. It takes the widget id as a parameter with storage functionality set to storageFlag
Parameters:
id - ID of the widget
widgets - The set of widgets this server will subscribe to
storageFlag - Flag to determine whether storage should be used or not
Method Detail

serverSetup

protected void serverSetup()
This method sets up the server for use. This includes getting the attributes and services information from relevant widgets.
See Also:
setAttributes(), setServices()

setWidgets

public void setWidgets(WidgetHandles widgets)
This method sets the widgets that this server should subscribe to. Either the constructor should include a widgets parameter or this method should be called before startSubscriptions() is called
Parameters:
widgets - Handles of widgets to subscribe to

startSubscriptions

public void startSubscriptions()
This method is called to subscribe to the widgets this server is interested in. The reason this is not part of the constructor is that the individual server's conditions will not be set yet. This should be called after a constructor sets the widget handles to use or after setWidgets() has been called.
See Also:
setCallbacks()

setAttributes

protected Attributes setAttributes()
This method is called to aggregate the list of attributes that the widgets relevant to this server provide. This should be called after a constructor sets the widget handles to use or after setWidgets() has been called.
Overrides:
setAttributes in class Widget
Returns:
the server attributes

setServerAttributes

protected abstract Attributes setServerAttributes()
This abstract method set the attributes for a server - those that are specific to the server, and not contained in the widgets it subscribes to.
Returns:
Attributes specific to the server

setServices

protected Services setServices()
This method is called to aggregate the list of services that the widgets relevant to this widget provide. This allows the server to act as a proxy to the individual widgets' services. This should be called after a constructor sets the widget handles to use or after setWidgets() has been called.
Overrides:
setServices in class Widget
Returns:
the server services

setServerServices

protected abstract Services setServerServices()
This abstract method set the services for a server - those that are specific to the server, and not contained in the widgets it subscribes to.
Returns:
Services specific to the server

setCallbacks

protected Callbacks setCallbacks()
This method is called to subscribe to the widgets this server is interested in. It allows the server to act as a proxy to the callbacks provided by each individual widget. This should be called after a constructor sets the widget handles to use or after setWidgets() has been called.
Overrides:
setCallbacks in class Widget
See Also:
setCallbacks()

setServerCallbacks

protected abstract Callbacks setServerCallbacks()
This abstract method set the callbacks for a server - those that are specific to the server, and not contained in the widgets it subscribes to.
Returns:
Callbacks containing callbacks specific to the server

setConditions

protected abstract Conditions setConditions()
This abstract method sets the conditions to apply to the server's subscriptions.
Returns:
Conditions containing condition info for server subscriptions

handle

public DataObject handle(java.lang.String callback,
                         DataObject data)
                  throws InvalidMethodException,
                         MethodException
This method implements the handle method in the Handler interface. It handles the subscription information supplied by widgets this server has subscribed to.
Specified by:
handle in interface Handler
Parameters:
callback - The name of the widget callback (on the subscriber side) triggered
data - DataObject containing the data for the widget callback
Returns:
DataObject containing any directives to the widget that created the callback
Throws:
InvalidMethodException - if the callback specified isn't recognized
MethodException - if the callback specified can't be handled successfully

queryWidget

protected DataObject queryWidget(DataObject query,
                                 boolean update,
                                 java.lang.String error)
This method runs a query on a widget, asking for either it's latest acquired data (QUERY) or asking for the widget to acquire and return new data (UPDATE_AND_QUERY). Currently, it deals with QUERY and UPDATE_AND_QUERY in exactly the same way.
Overrides:
queryWidget in class Widget
Parameters:
query - DataObject containing the query request
update - Whether or not to acquire new data
error - String containing the incoming error value
Returns:
DataObject containing the reply to the query

storeAttributeNameValues

public void storeAttributeNameValues(AttributeNameValues atts)
This method stores the attribute name values, both in persistent storage and in local storage.
Parameters:
atts - AttributeNameValues to store