context.arch.server
Class Server

java.lang.Object
  extended bycontext.arch.BaseObject
      extended bycontext.arch.widget.Widget
          extended bycontext.arch.server.Server
All Implemented Interfaces:
CommunicationsHandler, Handler, MessageHandler

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.
static java.lang.String SERVER_TYPE
          The tag for the type of this object
protected  WidgetHandles widgets
          The set of widgets this server is monitoring.
 
Fields inherited from class context.arch.widget.Widget
attributes, attributeTypes, callbacks, CLASS, constantAttributes, constantAttributesTypes, CurrentOffset, PUT_DATA, PUT_DATA_REPLY, QUERY, QUERY_ATTRIBUTES, QUERY_ATTRIBUTES_REPLY, QUERY_CALLBACKS, QUERY_CALLBACKS_REPLY, QUERY_CONSTANT_ATTRIBUTES, QUERY_CONSTANT_ATTRIBUTES_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, WIDGET_TYPE
 
Fields inherited from class context.arch.BaseObject
BASEOBJECT_TYPE, communications, DISABLE_PORT, discoverer, EXIT_OK, gFrame, handlers, ID, parser, PING, PING_REPLY, QUERY_DESCRIPTION, QUERY_DESCRIPTION_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
protected  void addCallback(WidgetHandle handle)
          This method allows to subscribe to a new widget
 DataObject getServerDescription()
          Returns the server description that should be overloaded
 java.lang.String getType()
          Returns the type of the object This method should be overridden
 DataObject getWidgetDescription()
          This method overloads the widget method It returns the server specific description
 DataObject handle(java.lang.String callback, DataObject data)
          This method implements the handle method in the Handler interface.
protected  Attributes initAttributes()
          This method is called to aggregate the list of non cosntant attributes that the widgets relevant to this server provide.
protected  Callbacks initCallbacks()
          This method is called to subscribe to the widgets this server is interested in.
protected  Attributes initConstantAttributes()
          This method is called to aggregate the list of constant attributes that the widgets relevant to this server provide.
protected  Services initServices()
          This method is called to aggregate the list of services that the widgets relevant to this widget provide.
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 abstract  Attributes setServerAttributes()
          This abstract method set the non constant 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  Attributes setServerConstantAttributes()
          This abstract method set the constant attributes 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.
 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(Attributes 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, executeService, getAttributeType, getCurrentTime, getNewOffset, getNewOffsetNoDelay, getSubscribersDescription, getUserDescription, handleIndependentReply, isAttribute, isCallback, notify, processCallbackReply, putData, queryAttributes, queryCallbacks, queryConstantAttributes, queryGenerator, queryServices, removeSubscriber, retrieveData, runUserMethod, runWidgetMethod, sendToSubscribers, setAttribute, setAttributes, setCallbacks, setConstantAttributes, setId, setNonConstantAttributes, setServices, setSubscribers, store, store, updateWidgetInformation
 
Methods inherited from class context.arch.BaseObject
activateDisplay, askInterpreter, deactivateDisplay, debugprintln, decodeData, discovererQuery, discovererQuery, discovererRegistration, discovererRegistration, discovererSendSubscription, discovererSubscribe, discovererSubscriptionNotification, discovererUnregistration, discovererUpdate, encodeData, executeAsynchronousWidgetService, executeSynchronousWidgetService, findDiscoverer, findDiscoverer, findDiscoverer, getComponentDescription, getDescription, getHostAddress, getHostName, getId, getId, getLease, getListOfHandlers, getLocationAddress, getPort, getVersion, getVersion, getWidgetAttributes, getWidgetCallbacks, getWidgetConstantAttributes, getWidgetServices, independentUserRequest, leaseEndNotified, pingComponent, pingComponent, pollWidget, println, putDataInWidget, queryVersion, quit, retrieveDataFrom, retrieveDataFrom, returnPing, runComponentMethod, runMethod, serviceResult, setAllDebug, setDiscoverer, setDisplay, setDisplay, setDisplayName, setDisplayTitle, setLease, setLocationAddress, setVersion, subscribeTo, unsubscribeFrom, updateAndPollWidget, userCallback, userRequest, userRequest, userRequest, userRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface context.arch.handler.Handler
handleIndependentReply
 

Field Detail

SERVER_TYPE

public static final java.lang.String SERVER_TYPE
The tag for the type of this object

See Also:
Constant Field Values

DEFAULT_PORT

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

See Also:
Constant Field Values

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

getType

public java.lang.String getType()
Returns the type of the object This method should be overridden

Overrides:
getType in class Widget
Returns:
String

serverSetup

protected void serverSetup()
This method sets up the server for use. This includes getting the attributes and services information from relevant widgets. Modification made by Agathe

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()

initAttributes

protected Attributes initAttributes()
This method is called to aggregate the list of non cosntant 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.

Specified by:
initAttributes in class Widget
Returns:
the server attributes

initConstantAttributes

protected Attributes initConstantAttributes()
This method is called to aggregate the list of constant 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.

Specified by:
initConstantAttributes in class Widget
Returns:
AttributeNameValues the server constant attributes

setServerAttributes

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

Returns:
Attributes The Attributes

setServerConstantAttributes

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

Returns:
Attributes The constant Attributes

initServices

protected Services initServices()
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.

Specified by:
initServices 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

initCallbacks

protected Callbacks initCallbacks()
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.

Specified by:
initCallbacks in class Widget
See Also:
#setCallbacks()

addCallback

protected void addCallback(WidgetHandle handle)
This method allows to subscribe to a new widget

Parameters:
handle - The widget to subscribe to

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

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(Attributes atts)
This method stores the attribute name values, both in persistent storage and in local storage.

Parameters:
atts - AttributeNameValues to store

getWidgetDescription

public DataObject getWidgetDescription()
This method overloads the widget method It returns the server specific description

Overrides:
getWidgetDescription in class Widget
Returns:
DataObject The information common to all servers
See Also:
Widget.getUserDescription()

getServerDescription

public DataObject getServerDescription()
Returns the server description that should be overloaded