context.arch
Class BaseObject

java.lang.Object
  extended bycontext.arch.BaseObject
All Implemented Interfaces:
CommunicationsHandler, MessageHandler
Direct Known Subclasses:
Interpreter, Widget

public class BaseObject
extends java.lang.Object
implements MessageHandler, CommunicationsHandler

This class is the base object for the context-aware infrastructure. It is able to poll and subscribe to other components and can be polled and subscribed to by other components. It also can generate and handle RPC-style requests. It consists of 2 main objects, the CommunicationsObject and ParserObject. It also maintains a list of subscribers and a list of handlers.

Author:
Anind
See Also:
CommunicationsObject, ParserObject, Handler

Field Summary
static java.lang.String BASEOBJECT_TYPE
          The tag for the type of this object
 CommunicationsObject communications
          Object to handle communications between components
static boolean DEBUG
          Debug flag.
static int DISABLE_PORT
          Disables the communications
 DiscovererDescription discoverer
          The description of the discoverer that the base object has found
static int EXIT_OK
          Indicates that the exit condition is normal
 GenericFrame gFrame
           
 Handlers handlers
          Object to keep track of context widget handlers
static java.lang.String ID
          Tag for id of this component
 ParserObject parser
          Object to handle the encoding and decoding of communications
static java.lang.String PING
          Tag for a ping
static java.lang.String PING_REPLY
          Tag for a ping reply
static java.lang.String QUERY_DESCRIPTION
          Tag for getting the description
static java.lang.String QUERY_DESCRIPTION_REPLY
          Tag for reply to a query_description
 AsyncServiceHandlers serviceHandlers
          Object to keep track of asynchronous service handlers
 
Constructor Summary
BaseObject()
          Basic constructor that creates a CommunicationsObject, ParserObject and Handlers object.
BaseObject(int localServerPort)
          Constructor that just creates a CommunicationsObject with the given port and ParserObject.
BaseObject(int localServerPort, java.lang.String protocolHandlerClass)
          Constructor that just creates a CommunicationsObject with the given port and protocol handler class, and ParserObject.
BaseObject(java.lang.String protocolHandlerClass)
          Constructor that just creates a CommunicationsObject with the given protocol handler class, and a ParserObject.
BaseObject(java.lang.String communicationClientClass, java.lang.String communicationServerClass, int localServerPort, java.lang.String encoderClass, java.lang.String decoderClass)
          Basic constructor that creates a CommunicationsObject with the given port and protocol, and creates a ParserObject with the given encoder and decoder.
BaseObject(java.lang.String communicationClientClass, java.lang.String communicationServerClass, int localServerPort, java.lang.String encoderClass, java.lang.String decoderClass, int threadPoolNumber)
          Basic constructor that creates a CommunicationsObject with the given port and protocol, and creates a ParserObject with the given encoder and decoder.
 
Method Summary
 void activateDisplay()
          Activate the display
 DataObject askInterpreter(java.lang.String remoteHost, int remotePort, java.lang.String remoteId, Attributes data)
          This method asks an interpreter to interpret some data.
 void deactivateDisplay()
          Deactivate the display
static void debugprintln(boolean DEBUG_flag, java.lang.Object s)
          Print a message if the DEBUG mode is active
 DataObject decodeData(java.io.Reader communicationData)
          Stub method that decodes the given string using ParserObject
 java.util.Vector discovererQuery(AbstractQueryItem query)
          This method allows to send a query to the discoverer.
protected  DataObject discovererQuery(DataObject data)
          This method allows to send a query to the discoverer containing the description of the context component the object would like to know.
 Error discovererRegistration()
          This method is used to send the component description to the discoverer.
 Error discovererRegistration(Lease registrationLease)
          This method is used to send the component description to the discoverer.
protected  DataObject discovererSendSubscription(Handler handler, DiscovererSubscriber discoSub)
          to improve
 void discovererSubscribe(Handler handler, DiscovererSubscriber discoSub)
          This method is used to subscribe to the discoverer.
 DataObject discovererSubscriptionNotification(DataObject data)
           
 Error discovererUnregistration()
          This method allows to unregister from the discoverer
 Error discovererUpdate()
          This method allows to send a message to the discoverer to update its own description stored in the discoverer.
 java.lang.String encodeData(DataObject communicationData)
          Stub method that encodes the given string using ParserObject
 DataObject executeAsynchronousWidgetService(AsyncServiceHandler handler, java.lang.String serviceHost, int servicePort, java.lang.String serviceId, java.lang.String service, java.lang.String function, Attributes input, java.lang.String requestTag)
          This method requests that a widget execute an asynchronous service
 DataObject executeSynchronousWidgetService(java.lang.String remoteHost, int remotePort, java.lang.String remoteId, java.lang.String service, java.lang.String function, Attributes input)
          This method requests that a widget execute a synchronous service
 Error findDiscoverer()
          This method allows to find a discoverer.
 Error findDiscoverer(boolean registration)
          This method allows to find a discoverer.
 Error findDiscoverer(boolean registration, Lease registrationLease, boolean automaticRenewal)
          This method allows to find a discoverer.
 ComponentDescription getComponentDescription()
           
 DataObject getDescription()
          Returns the common description of the component.
 java.lang.String getHostAddress()
          This method gets the address of the machine this component is running on.
 java.lang.String getHostName()
          This method gets the name of the machine this component is running on.
 java.lang.String getId()
          This method returns the id of the class that subclass this object, for use in sending messages.
static java.lang.String getId(java.lang.String className, int port)
          Returns a uniq id constructed as classname_hostname_port_givenUserLocation, or if there is an error, returns the user location given by the user.
 Lease getLease()
          This method allows to specify a lease used to register the discoverer.
 java.lang.String getListOfHandlers()
          Returns the list of handlers this object made.
 java.lang.String getLocationAddress()
          Returns the location address
 int getPort()
           
 java.lang.String getType()
          Returns the type of the object This method should be overridden
 DataObject getUserDescription()
          Returns the added description of the component That method should be overriden.
 java.lang.String getVersion()
          This method returns the version number of this object.
 DataObject getVersion(java.lang.String remoteHost, int remotePort, java.lang.String remoteId)
          This method gets the version of the given component (remoteHostname, widget, interpreter).
 DataObject getWidgetAttributes(java.lang.String widgetHost, int widgetPort, java.lang.String widgetId)
          This method gets the attributes of the given widget
 DataObject getWidgetCallbacks(java.lang.String widgetHost, int widgetPort, java.lang.String widgetId)
          This method gets the callbacks of the given widget
 DataObject getWidgetConstantAttributes(java.lang.String widgetHost, int widgetPort, java.lang.String widgetId)
          This method gets the attributes of the given widget
 DataObject getWidgetServices(java.lang.String widgetHost, int widgetPort, java.lang.String widgetId)
          This method gets the services of the given widget
 void handleIndependentReply(IndependentCommunication independentCommunication)
          This method is called after the independentUserRequest has been called.
 void independentUserRequest(IndependentCommunication request)
          This method is used to send a message through a threaded communication.
protected  DataObject leaseEndNotified(DataObject data)
          This method sends a lease end confirmation if necessary.
 void pingComponent(IndependentCommunication independentCommunication)
           
 DataObject pingComponent(java.lang.String remoteHost, int remotePort, java.lang.String remoteId, boolean independentCom)
          This method pings a component (widget,remoteHostname, or interpreter) to make sure that it is functioning ok.
 DataObject pollWidget(java.lang.String widgetHost, int widgetPort, java.lang.String widgetId, Attributes attributes)
          This method allows a component to poll a remote widget for its attribute values.
 void println(java.lang.String s)
          Print a string, on the displayed frame if it is activated or on the default output stream.
 DataObject putDataInWidget(java.lang.String widgetHost, int widgetPort, java.lang.String widgetId, java.lang.String callback, Attributes attributes)
          This method allows a component to put context data in a remote widget.
 DataObject queryVersion(DataObject query)
          This method returns the version number of this component.
 void quit()
          This method should be called when the object is going to exit under normal conditions.
 DataObject retrieveDataFrom(java.lang.String remoteHost, int remotePort, java.lang.String remoteId, Retrieval retrieval)
          This method allows a component to retrieve data from other components.
 DataObject retrieveDataFrom(java.lang.String remoteHost, int remotePort, java.lang.String remoteId, java.lang.String myId, Retrieval retrieval)
          This method allows a component to retrieve data from other components.
 DataObject returnPing(DataObject ping)
          This method returns an error message as an answer to a ping.
 DataObject runComponentMethod(java.lang.String remoteHost, int remotePort, java.lang.String remoteId, java.lang.String methodName, Attributes parameters, Attributes attributes)
          This method asks an component to run some non-standard method.
 DataObject runMethod(java.lang.String methodType, DataObject data)
          This method handles both the system-defined, callbacks and user-defined RPCs.
 DataObject runUserMethod(DataObject data)
          This is an empty method that should be overridden by the object that extends this class.
 DataObject serviceResult(DataObject result)
          This method handles the results of an asynchronous service request.
 void setAllDebug(boolean baseObjectDebug, boolean communicationDebug, boolean componentDebug)
          Set the CTK classes in the DEBUG status
 DataObject setDiscoverer(DataObject data)
          This method handles the lookup response from the discoverer.
 void setDisplay()
          Create the display and activate it
 void setDisplay(GenericFrame frame)
           
 void setDisplayName(java.lang.String objName)
          Set the title displayed on the frame
 void setDisplayTitle(java.lang.String title)
          Set the title of the frame
 void setId(java.lang.String id)
          This method sets the id of classes that subclass this object, for use in sending messages.
 void setLease(Lease lease)
          Set the lease used to register the discoverer
 void setLocationAddress(java.lang.String location)
          Sets the location address (structured as for example GT/CRB/Floor1/Hall2/room4
 void setVersion(java.lang.String version)
          This method sets the version number of this object.
 Error subscribeTo(Handler handler, java.lang.String remoteId, java.lang.String remoteHost, int remotePort, ClientSideSubscriber subscriber)
          This method allows a component to subscribe to changes in other components.
 Error unsubscribeFrom(java.lang.String subscriptionId)
          This method allows a component to unsubscribe from another component.
 DataObject updateAndPollWidget(java.lang.String widgetHost, int widgetPort, java.lang.String widgetId, Attributes attributes)
          This method allows a component to force a remote widget to update its data and return it.
 DataObject userCallback(DataObject data)
          This method is called when a callback message is received.
 DataObject userRequest(DataObject data, java.lang.String requestType)
          Deprecated.  
 DataObject userRequest(DataObject data, java.lang.String requestType, java.lang.String remoteHostname)
          Deprecated.  
 DataObject userRequest(DataObject data, java.lang.String requestType, java.lang.String remoteHostname, int remotePort)
          Method that submits a user request for polling/subscription.
 DataObject userRequest(RequestObject request)
          Sends a message to a remote component
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG
Debug flag. Set to true to see debug messages.


EXIT_OK

public static final int EXIT_OK
Indicates that the exit condition is normal

See Also:
Constant Field Values

DISABLE_PORT

public static final int DISABLE_PORT
Disables the communications

See Also:
Constant Field Values

ID

public static final java.lang.String ID
Tag for id of this component

See Also:
Constant Field Values

PING

public static final java.lang.String PING
Tag for a ping

See Also:
Constant Field Values

PING_REPLY

public static final java.lang.String PING_REPLY
Tag for a ping reply

See Also:
Constant Field Values

QUERY_DESCRIPTION

public static final java.lang.String QUERY_DESCRIPTION
Tag for getting the description

See Also:
Constant Field Values

QUERY_DESCRIPTION_REPLY

public static final java.lang.String QUERY_DESCRIPTION_REPLY
Tag for reply to a query_description

See Also:
Constant Field Values

BASEOBJECT_TYPE

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

See Also:
Constant Field Values

communications

public CommunicationsObject communications
Object to handle communications between components

See Also:
CommunicationsObject

parser

public ParserObject parser
Object to handle the encoding and decoding of communications

See Also:
ParserObject

handlers

public Handlers handlers
Object to keep track of context widget handlers

See Also:
Handlers, Handler

serviceHandlers

public AsyncServiceHandlers serviceHandlers
Object to keep track of asynchronous service handlers

See Also:
AsyncServiceHandlers, AsyncServiceHandler

gFrame

public GenericFrame gFrame

discoverer

public DiscovererDescription discoverer
The description of the discoverer that the base object has found

See Also:
Discoverer
Constructor Detail

BaseObject

public BaseObject(java.lang.String communicationClientClass,
                  java.lang.String communicationServerClass,
                  int localServerPort,
                  java.lang.String encoderClass,
                  java.lang.String decoderClass,
                  int threadPoolNumber)
Basic constructor that creates a CommunicationsObject with the given port and protocol, and creates a ParserObject with the given encoder and decoder. It also creates a Handlers object to keep track of context widget handlers.

Parameters:
communicationClientClass - Class to use for client communications
communicationServerClass - Class to use for server communications
localServerPort - Port to use for server communications
encoderClass - Class to use for communications encoding
decoderClass - Class to use for communications decoding
threadPoolNumber - The number of client threads in the clients pool
See Also:
CommunicationsObject, CommunicationsObject.start(), ParserObject, Handlers

BaseObject

public BaseObject(java.lang.String communicationClientClass,
                  java.lang.String communicationServerClass,
                  int localServerPort,
                  java.lang.String encoderClass,
                  java.lang.String decoderClass)
Basic constructor that creates a CommunicationsObject with the given port and protocol, and creates a ParserObject with the given encoder and decoder. It also creates a Handlers object to keep track of context widget handlers.

Parameters:
communicationClientClass - Class to use for client communications
communicationServerClass - Class to use for server communications
localServerPort - Port to use for server communications
encoderClass - Class to use for communications encoding
decoderClass - Class to use for communications decoding
See Also:
CommunicationsObject, CommunicationsObject.start(), ParserObject, Handlers

BaseObject

public BaseObject()
Basic constructor that creates a CommunicationsObject, ParserObject and Handlers object.

See Also:
CommunicationsObject, CommunicationsObject.start(), ParserObject, Handlers

BaseObject

public BaseObject(int localServerPort)
Constructor that just creates a CommunicationsObject with the given port and ParserObject. It also creates a Handlers object to keep track of context widget handlers.

Parameters:
localServerPort - Port number to communicate on
See Also:
CommunicationsObject, CommunicationsObject.start(), ParserObject, Handlers

BaseObject

public BaseObject(java.lang.String protocolHandlerClass)
Constructor that just creates a CommunicationsObject with the given protocol handler class, and a ParserObject. It also creates a Handlers object to keep track of context widget handlers.

Parameters:
protocolHandlerClass - Protocol handler class to communicate with
See Also:
CommunicationsObject, CommunicationsObject.start(), ParserObject, Handlers

BaseObject

public BaseObject(int localServerPort,
                  java.lang.String protocolHandlerClass)
Constructor that just creates a CommunicationsObject with the given port and protocol handler class, and ParserObject. It also creates a Handlers object to keep track of context widget handlers.

Parameters:
localServerPort - Port number to communicate on
protocolHandlerClass - Protocol handler class name to communicate with
See Also:
CommunicationsObject, CommunicationsObject.start(), ParserObject, Handlers
Method Detail

decodeData

public DataObject decodeData(java.io.Reader communicationData)
                      throws DecodeException,
                             InvalidDecoderException
Stub method that decodes the given string using ParserObject

Specified by:
decodeData in interface MessageHandler
Parameters:
communicationData - String to be decoded
Returns:
the decoded data
Throws:
DecodeException - thrown if the parser can't decode the given string
InvalidDecoderException - thrown if the parser can't create the necessary decoder
See Also:
ParserObject.decodeData(java.io.Reader)

encodeData

public java.lang.String encodeData(DataObject communicationData)
                            throws EncodeException,
                                   InvalidEncoderException
Stub method that encodes the given string using ParserObject

Specified by:
encodeData in interface MessageHandler
Parameters:
communicationData - String to be decoded
Returns:
the encoded data
Throws:
EncodeException - thrown if the parser can't encode the given string
InvalidEncoderException - thrown if the parser can't create the necessary encoder
See Also:
ParserObject.encodeData(context.arch.comm.DataObject)

userRequest

public DataObject userRequest(DataObject data,
                              java.lang.String requestType)
                       throws EncodeException,
                              InvalidProtocolException,
                              ProtocolException,
                              DecodeException,
                              InvalidDecoderException,
                              InvalidEncoderException,
                              java.io.IOException
Deprecated.  

Method that submits a user request for polling/subscription. The request is in the form of a DataObject. It is encoded, sent out and the reply is decoded, if necessary, and returned.

Specified by:
userRequest in interface CommunicationsHandler
Parameters:
data - DataObject that contains the request
requestType - RPC tag that indicates the type of request
Returns:
DataObject containing the reply to the request
Throws:
EncodeException - when the encoding can't be completed successfully
DecodeException - when the decoding can't be completed successfully
InvalidEncoderException - when the encoder can't be created
InvalidDecoderException - when the decoder can't be created
ProtocolException - when the request can't be sent successfully
InvalidProtocolException - when the request can't be sent successfully due to invalid protocol use
java.io.IOException

userRequest

public DataObject userRequest(RequestObject request)
                       throws EncodeException,
                              InvalidProtocolException,
                              ProtocolException,
                              DecodeException,
                              InvalidDecoderException,
                              InvalidEncoderException,
                              java.io.IOException
Sends a message to a remote component

Specified by:
userRequest in interface CommunicationsHandler
Parameters:
request - The RequestObject that contains all information about the remote component and the data to send
Returns:
DataObject The reply
Throws:
InvalidProtocolException - when the request can't be sent successfully due to invalid protocol use
DecodeException - when the decoding can't be completed successfully
EncodeException - when the encoding can't be completed successfully
ProtocolException - when the request can't be sent successfully
InvalidEncoderException - when the encoder can't be created
InvalidDecoderException - when the decoder can't be created
java.io.IOException

userRequest

public DataObject userRequest(DataObject data,
                              java.lang.String requestType,
                              java.lang.String remoteHostname)
                       throws EncodeException,
                              InvalidProtocolException,
                              ProtocolException,
                              DecodeException,
                              InvalidDecoderException,
                              InvalidEncoderException,
                              java.io.IOException
Deprecated.  

Method that submits a user request for polling/subscription. The request is in the form of a DataObject. It is encoded, sent out and the reply is decoded, if necessary, and returned.

Specified by:
userRequest in interface CommunicationsHandler
Parameters:
data - DataObject that contains the request
requestType - RPC tag that indicates the type of request
remoteHostname - Hostname of the component the request is being sent to
Returns:
DataObject containing the reply to the request
Throws:
EncodeException - when the encoding can't be completed successfully
DecodeException - when the decoding can't be completed successfully
InvalidEncoderException - when the encoder can't be created
InvalidDecoderException - when the decoder can't be created
ProtocolException - when the request can't be sent successfully
InvalidProtocolException - when the request can't be sent successfully due to invalid protocol use
java.io.IOException

userRequest

public DataObject userRequest(DataObject data,
                              java.lang.String requestType,
                              java.lang.String remoteHostname,
                              int remotePort)
                       throws EncodeException,
                              ProtocolException,
                              InvalidProtocolException,
                              DecodeException,
                              InvalidDecoderException,
                              InvalidEncoderException,
                              java.io.IOException
Method that submits a user request for polling/subscription. The request is in the form of a DataObject. It is encoded, sent out and the reply is decoded, if necessary, and returned.

Specified by:
userRequest in interface CommunicationsHandler
Parameters:
data - DataObject that contains the request
requestType - RPC tag that indicates the type of request
remoteHostname - Hostname of the component the request is being sent to
remotePort - Port number of the component the request is being sent to
Returns:
DataObject containing the reply to the request
Throws:
EncodeException - when the encoding can't be completed successfully
DecodeException - when the decoding can't be completed successfully
InvalidEncoderException - when the encoder can't be created
InvalidDecoderException - when the decoder can't be created
ProtocolException - when the request can't be sent successfully
InvalidProtocolException - when the request can't be sent successfully due to invalid protocol use
java.io.IOException

independentUserRequest

public void independentUserRequest(IndependentCommunication request)
                            throws EncodeException,
                                   InvalidEncoderException
This method is used to send a message through a threaded communication. The request is sent by a thread in charge of the communication. The request is encapsulated in a IndependentCommunication that contains a RequestObject (data to send and the recipient of the data) and the reply message and the exceptions that occured during the communication. If the communication result is null, the baseObject won't be notified about how the communication ended. Actually, the thread in charge of the communication won't notify the baseObject, but update the request object. If the result is not null, result is the IndependentCommunications object that will contain the original request and the reply. At the end of the communication, the thread updates request with the reply message and the exception, and adds it into result. The base object is notified of the end of the threaded communication when the handleIndependentReply is called by the thread.

Specified by:
independentUserRequest in interface CommunicationsHandler
Parameters:
request - The IndependentCommunication object that contain the RequestObject, and will contain after the communication the reply dataObject and the vector of exception
Throws:
EncodeException
InvalidEncoderException
See Also:
handleIndependentReply(context.arch.comm.clients.IndependentCommunication), IndependentCommunication, context.arch.comm.clients.IndependentCommunications, context.arch.util.RequesObject

handleIndependentReply

public void handleIndependentReply(IndependentCommunication independentCommunication)
This method is called after the independentUserRequest has been called. The thread in charge of the communication sends the results to this method. This method should be overridden by classes that need to handle the responses.

Specified by:
handleIndependentReply in interface MessageHandler
See Also:
ClientsPool, Client, context.arch.util.RequestObject, DataObject

subscribeTo

public Error subscribeTo(Handler handler,
                         java.lang.String remoteId,
                         java.lang.String remoteHost,
                         int remotePort,
                         ClientSideSubscriber subscriber)
This method allows a component to subscribe to changes in other components. The subscription includes the handler that will handle the callbacks, the subscriber's hostname and port, the subscription id, the remote component's hostname, port, and id, the remote component's callback, and the name of the subscriber's method that will handle the callback.

Parameters:
handler - Object that handles context widget callbacks
remoteId - Id of the context widget being subscribed to
remoteHost - Hostname of the widget being subscribed to
remotePort - Port number of the widget being subscribed to
subscriber - Subscriber object holding the subscription info
Returns:
Error to indicate success of subscription
See Also:
Handlers, Handlers.addHandler(context.arch.handler.HandlerInfo), userRequest(context.arch.comm.DataObject, String, String, int)

unsubscribeFrom

public Error unsubscribeFrom(java.lang.String subscriptionId)
This method allows a component to unsubscribe from another component.

Returns:
Error to indicate success of unsubscription
See Also:
Handlers, Handlers.removeHandler(context.arch.handler.HandlerInfo), userRequest(context.arch.comm.DataObject, String, String, int)

pollWidget

public DataObject pollWidget(java.lang.String widgetHost,
                             int widgetPort,
                             java.lang.String widgetId,
                             Attributes attributes)
This method allows a component to poll a remote widget for its attribute values. A list of attributes is provided to dictate which attribute values are wanted.

Parameters:
widgetHost - Hostname of the context widget being polled
widgetPort - Port number of the context widget being polled
widgetId - Id of the context widget being polled
attributes - Attributes being requested
Returns:
DataObject containing results of poll
See Also:
userRequest(context.arch.comm.DataObject, String, String, int)

updateAndPollWidget

public DataObject updateAndPollWidget(java.lang.String widgetHost,
                                      int widgetPort,
                                      java.lang.String widgetId,
                                      Attributes attributes)
This method allows a component to force a remote widget to update its data and return it. A list of attributes is provided to dictate which attribute values are wanted.

Parameters:
widgetHost - Hostname of the context widget being polled
widgetPort - Port number of the context widget being polled
widgetId - Id of the context widget being polled
attributes - Attributes being requested
Returns:
DataObject containing results of poll
See Also:
userRequest(context.arch.comm.DataObject, String, String, int)

putDataInWidget

public DataObject putDataInWidget(java.lang.String widgetHost,
                                  int widgetPort,
                                  java.lang.String widgetId,
                                  java.lang.String callback,
                                  Attributes attributes)
This method allows a component to put context data in a remote widget. It is really intended for components that don't use the context toolkit, but is being included here for possible future use. The method takes a callback and an AttributeNameValues object. The callback is not necessary (can have a null value), and is only used by the remote widget to determine which of the widget's subscribers need to be updated.

Parameters:
widgetHost - Hostname of the context widget to use
widgetPort - Port number of the context widget to use
widgetId - Id of the context widget to use
callback - Callback of the context widget to associate the data with
attributes - AttributeNameValues to put in the widget
Returns:
DataObject containing results of put data
See Also:
userRequest(context.arch.comm.DataObject, String, String, int)

getVersion

public DataObject getVersion(java.lang.String remoteHost,
                             int remotePort,
                             java.lang.String remoteId)
This method gets the version of the given component (remoteHostname, widget, interpreter).

Parameters:
remoteHost - Hostname of the component being queried
remotePort - Port number of the component being queried
remoteId - Id of the component being queried
Returns:
DataObject containing version
See Also:
userRequest(context.arch.comm.DataObject, String, String, int)

getWidgetCallbacks

public DataObject getWidgetCallbacks(java.lang.String widgetHost,
                                     int widgetPort,
                                     java.lang.String widgetId)
This method gets the callbacks of the given widget

Parameters:
widgetHost - Hostname of the widget being queried
widgetPort - Port number of the widget being queried
widgetId - Id of the widget being queried
Returns:
DataObject containing callbacks
See Also:
userRequest(context.arch.comm.DataObject, String, String, int)

getWidgetServices

public DataObject getWidgetServices(java.lang.String widgetHost,
                                    int widgetPort,
                                    java.lang.String widgetId)
This method gets the services of the given widget

Parameters:
widgetHost - Hostname of the widget being queried
widgetPort - Port number of the widget being queried
widgetId - Id of the widget being queried
Returns:
DataObject containing services of the widget
See Also:
userRequest(context.arch.comm.DataObject, String, String, int)

getWidgetAttributes

public DataObject getWidgetAttributes(java.lang.String widgetHost,
                                      int widgetPort,
                                      java.lang.String widgetId)
This method gets the attributes of the given widget

Parameters:
widgetHost - Hostname of the widget being queried
widgetPort - Port number of the widget being queried
widgetId - Id of the widget being queried
Returns:
DataObject containing callbacks
See Also:
userRequest(context.arch.comm.DataObject, String, String, int)

getWidgetConstantAttributes

public DataObject getWidgetConstantAttributes(java.lang.String widgetHost,
                                              int widgetPort,
                                              java.lang.String widgetId)
This method gets the attributes of the given widget

Parameters:
widgetHost - Hostname of the widget being queried
widgetPort - Port number of the widget being queried
widgetId - Id of the widget being queried
Returns:
DataObject containing callbacks
See Also:
userRequest(context.arch.comm.DataObject, String, String, int)

retrieveDataFrom

public DataObject retrieveDataFrom(java.lang.String remoteHost,
                                   int remotePort,
                                   java.lang.String remoteId,
                                   Retrieval retrieval)
This method allows a component to retrieve data from other components.

Parameters:
remoteHost - Hostname of the component being asked for data
remotePort - Port number of the component being asked for data
remoteId - Id of the component being asked for data
retrieval - Description of data to retrieve with any conditions
Returns:
DataObject containing data requested
See Also:
userRequest(context.arch.comm.DataObject, String, String, int)

retrieveDataFrom

public DataObject retrieveDataFrom(java.lang.String remoteHost,
                                   int remotePort,
                                   java.lang.String remoteId,
                                   java.lang.String myId,
                                   Retrieval retrieval)
This method allows a component to retrieve data from other components.

Parameters:
remoteHost - Hostname of the component being asked for data
remotePort - Port number of the component being asked for data
remoteId - Id of the component being asked for data
myId - Id of the "user" trying to access the data
retrieval - Description of data to retrieve with any conditions
Returns:
DataObject containing data requested
See Also:
userRequest(context.arch.comm.DataObject, String, String, int)

askInterpreter

public DataObject askInterpreter(java.lang.String remoteHost,
                                 int remotePort,
                                 java.lang.String remoteId,
                                 Attributes data)
This method asks an interpreter to interpret some data. It passes the data to be interpreted and gets back the interpreted data.

Parameters:
remoteHost - Hostname of the component being asked for data
remotePort - Port number of the component being asked for data
remoteId - Id of the component being asked for data
data - AttributeNameValues object containing the data to be interpreted
Returns:
DataObject containing the interpreted data

runComponentMethod

public DataObject runComponentMethod(java.lang.String remoteHost,
                                     int remotePort,
                                     java.lang.String remoteId,
                                     java.lang.String methodName,
                                     Attributes parameters,
                                     Attributes attributes)
This method asks an component to run some non-standard method. It passes id of the component, attributes, and parameters and gets back the result of the method.

Parameters:
remoteHost - Hostname of the component
remotePort - Port number of the component
remoteId - Id of the component
methodName - Name of the method to run
parameters - AttributeNameValues object that is parameters with values
attributes - Attributes object that is parameters with values
Returns:
DataObject containing the interpreted data

executeAsynchronousWidgetService

public DataObject executeAsynchronousWidgetService(AsyncServiceHandler handler,
                                                   java.lang.String serviceHost,
                                                   int servicePort,
                                                   java.lang.String serviceId,
                                                   java.lang.String service,
                                                   java.lang.String function,
                                                   Attributes input,
                                                   java.lang.String requestTag)
This method requests that a widget execute an asynchronous service

Specified by:
executeAsynchronousWidgetService in interface CommunicationsHandler
Parameters:
handler - Handler to handle the results of the service
serviceHost - Hostname of the widget with the service
servicePort - Port number of the widget with the service
serviceId - Id of the widget with the service
service - Name of the widget service to run
function - Name of the particular service function to run
input - AttributeNameValues object to use to execute the service
requestTag - Unique tag provided by caller to identify result
Returns:
DataObject containing the results of the execution request

executeSynchronousWidgetService

public DataObject executeSynchronousWidgetService(java.lang.String remoteHost,
                                                  int remotePort,
                                                  java.lang.String remoteId,
                                                  java.lang.String service,
                                                  java.lang.String function,
                                                  Attributes input)
This method requests that a widget execute a synchronous service

Specified by:
executeSynchronousWidgetService in interface CommunicationsHandler
Parameters:
remoteHost - Hostname of the widget
remotePort - Port number of the widget
remoteId - Id of the widget
service - Name of the widget service to run
function - Name of the particular service function to run
input - AttributeNameValues object to use to execute the service
Returns:
DataObject containing the results of the execution request

pingComponent

public DataObject pingComponent(java.lang.String remoteHost,
                                int remotePort,
                                java.lang.String remoteId,
                                boolean independentCom)
This method pings a component (widget,remoteHostname, or interpreter) to make sure that it is functioning ok.

Parameters:
remoteHost - Hostname of the component being asked for data
remotePort - Port number of the component being asked for data
remoteId - Id of the component being asked for data
Returns:
DataObject containing the results of the ping

pingComponent

public void pingComponent(IndependentCommunication independentCommunication)

quit

public void quit()
This method should be called when the object is going to exit under normal conditions. It stops the CommunicationsObject from receiving any more requests and exits.

See Also:
CommunicationsObject.quit()

runUserMethod

public DataObject runUserMethod(DataObject data)
                         throws InvalidMethodException,
                                MethodException
This is an empty method that should be overridden by the object that extends this class. It will contain the user-defined RPCs.

Parameters:
data - DataObject containing data for user-defined RPC
Returns:
result of RPC
Throws:
InvalidMethodException - thrown if specified RPC couldn't be found
MethodException - thrown if specified RPC had an error
See Also:
runMethod(String, DataObject)

runMethod

public DataObject runMethod(java.lang.String methodType,
                            DataObject data)
                     throws InvalidMethodException,
                            MethodException
This method handles both the system-defined, callbacks and user-defined RPCs. If a user-defined RPC is called, this method calls runUserMethods. If a callback is specified, this method runs userCallback. Currently, the only system-defined methods are queryVersion, and userCallback.

Specified by:
runMethod in interface MessageHandler
Parameters:
methodType - Name of method to run
data - DataObject containing data for the method call
Throws:
InvalidMethodException - thrown if specified RPC couldn't be found
MethodException - thrown if specified RPC had an error
See Also:
userCallback(context.arch.comm.DataObject), runUserMethod(context.arch.comm.DataObject), queryVersion(context.arch.comm.DataObject), setDiscoverer(context.arch.comm.DataObject)

userCallback

public DataObject userCallback(DataObject data)
This method is called when a callback message is received. It determines which of its registered handlers should receive the callback message and passes it on accordingly. It creates a reply message to the callback request in the form of a DataObject. It handles all error checking.

Parameters:
data - DataObject containing the callback request
Returns:
DataObject containing the callback reply
See Also:
Handlers.getHandler(String), Handler.handle(String, context.arch.comm.DataObject)

getListOfHandlers

public java.lang.String getListOfHandlers()
Returns the list of handlers this object made. A handler is defined for a subscription to a widget, or the discoverer


queryVersion

public DataObject queryVersion(DataObject query)
This method returns the version number of this component.

Parameters:
query - DataObject containing the query
Returns:
DataObject containing the results of the query

returnPing

public DataObject returnPing(DataObject ping)
This method returns an error message as an answer to a ping.

Parameters:
ping - DataObject containing the ping request
Returns:
DataObject containing the results of the ping

serviceResult

public DataObject serviceResult(DataObject result)
This method handles the results of an asynchronous service request.

Parameters:
result - DataObject containing the results of the aysnchronous service request
Returns:
DataObject containing a reply to the results message

getVersion

public java.lang.String getVersion()
This method returns the version number of this object.

Returns:
version number

setVersion

public void setVersion(java.lang.String version)
This method sets the version number of this object.

Parameters:
version - of the object

setId

public void setId(java.lang.String id)
This method sets the id of classes that subclass this object, for use in sending messages.

Parameters:
id - ID of the class

getId

public java.lang.String getId()
This method returns the id of the class that subclass this object, for use in sending messages.

Returns:
id of the class

getId

public static java.lang.String getId(java.lang.String className,
                                     int port)
Returns a uniq id constructed as classname_hostname_port_givenUserLocation, or if there is an error, returns the user location given by the user.

Parameters:
className - The classname of the object
port - The port of the object
Returns:
String The uniq identification

getType

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

Returns:
String

getHostAddress

public java.lang.String getHostAddress()
This method gets the address of the machine this component is running on.

Returns:
the address of the machine this component is running on

getHostName

public java.lang.String getHostName()
This method gets the name of the machine this component is running on.

Returns:
the name of the machine this component is running on

getPort

public int getPort()

setDiscoverer

public DataObject setDiscoverer(DataObject data)
This method handles the lookup response from the discoverer. It sets the discoverer description. And returns an error code

Returns:
DataObject En error code
See Also:
DiscovererDescription

discovererRegistration

public Error discovererRegistration()
This method is used to send the component description to the discoverer. It sends a DISCOVERER_REGISTRATION message to the discoverer with the object description. It

Returns:
Error The error code of the registration
See Also:
ComponentDescription

discovererRegistration

public Error discovererRegistration(Lease registrationLease)
This method is used to send the component description to the discoverer. It sends a DISCOVERER_REGISTRATION message to the discoverer with the object description

Returns:
Error The error code of the registration
See Also:
ComponentDescription

getComponentDescription

public ComponentDescription getComponentDescription()

getDescription

public DataObject getDescription()
Returns the common description of the component.

Returns:
DataObject It contains the component description
See Also:
ComponentDescription, getUserDescription()

setLocationAddress

public void setLocationAddress(java.lang.String location)
Sets the location address (structured as for example GT/CRB/Floor1/Hall2/room4

Parameters:
location - The location address

getLocationAddress

public java.lang.String getLocationAddress()
Returns the location address

Returns:
String The object's location address

getUserDescription

public DataObject getUserDescription()
Returns the added description of the component That method should be overriden. If not, we deduct that the current object is an application

Returns:
DataObject The description
See Also:
Discoverer

findDiscoverer

public Error findDiscoverer()
This method allows to find a discoverer. The component sends a multicast message containing its id, port, hostname. The response of the existing discoverer is handled by another method. It sends a LOOOKUP_DISCOVERER message. By default, the component registers the discoverer and the end of the lease is confirmed automatically.

Returns:
Error The error object

findDiscoverer

public Error findDiscoverer(boolean registration)
This method allows to find a discoverer. The component sends a multicast message containing its id, port, hostname. The response of the existing discoverer is handled by another method. It sends a LOOOKUP_DISCOVERER message. The component register the discoverer if registration is set true. It sends a default lease

Parameters:
registration - True if the component registers the discoverer
Returns:
Error The error object
See Also:
Lease

findDiscoverer

public Error findDiscoverer(boolean registration,
                            Lease registrationLease,
                            boolean automaticRenewal)
This method allows to find a discoverer. The component sends a multicast message containing its id, port, hostname. The response of the existing discoverer is handled by another method. It sends a LOOOKUP_DISCOVERER message. /lookup caller callerId type hostname port /caller /lookup

Returns:
Error An error code
See Also:
setDiscoverer(context.arch.comm.DataObject), Discoverer

discovererUpdate

public Error discovererUpdate()
This method allows to send a message to the discoverer to update its own description stored in the discoverer. It sends a DISCOVERER_UPDATE message.

Returns:
Error The error code received from the discoverer
See Also:
Discoverer

discovererSubscribe

public void discovererSubscribe(Handler handler,
                                DiscovererSubscriber discoSub)
This method is used to subscribe to the discoverer.


discovererSendSubscription

protected DataObject discovererSendSubscription(Handler handler,
                                                DiscovererSubscriber discoSub)
to improve


discovererQuery

public java.util.Vector discovererQuery(AbstractQueryItem query)
This method allows to send a query to the discoverer.

Parameters:
query - The Query object containing the request for the discoverer
Returns:
ComponentDescription When the discoverer has found a context object corresponding to the request, the ComponentDescription object contains information about it, else it is null
See Also:
discovererQuery(DataObject)

discovererQuery

protected DataObject discovererQuery(DataObject data)
This method allows to send a query to the discoverer containing the description of the context component the object would like to know. It sends a DISCOVERER_QUERY message

Returns:
DataObject The result from the discoverer containing the first component description fitting the request
See Also:
Discoverer

discovererUnregistration

public Error discovererUnregistration()
This method allows to unregister from the discoverer

Returns:
Error The error message
See Also:
Discoverer

discovererSubscriptionNotification

public DataObject discovererSubscriptionNotification(DataObject data)

leaseEndNotified

protected DataObject leaseEndNotified(DataObject data)
This method sends a lease end confirmation if necessary.

Parameters:
data - The data object specifying the lease end
Returns:
DataObject The reply to the notification

getLease

public Lease getLease()
This method allows to specify a lease used to register the discoverer. Each time the component has to register or to renew its registration, it uses this lease. This method has to be overridden by inheriting classes. If not, it returns the default lease ??? : is it useful after all???

Returns:
Lease The specified lease

setLease

public void setLease(Lease lease)
Set the lease used to register the discoverer


activateDisplay

public void activateDisplay()
Activate the display


deactivateDisplay

public void deactivateDisplay()
Deactivate the display


setDisplay

public void setDisplay()
Create the display and activate it


setDisplay

public void setDisplay(GenericFrame frame)

setDisplayName

public void setDisplayName(java.lang.String objName)
Set the title displayed on the frame


setDisplayTitle

public void setDisplayTitle(java.lang.String title)
Set the title of the frame


println

public void println(java.lang.String s)
Print a string, on the displayed frame if it is activated or on the default output stream. Flushes the output stream


debugprintln

public static void debugprintln(boolean DEBUG_flag,
                                java.lang.Object s)
Print a message if the DEBUG mode is active

Parameters:
s - Any object, even null

setAllDebug

public void setAllDebug(boolean baseObjectDebug,
                        boolean communicationDebug,
                        boolean componentDebug)
Set the CTK classes in the DEBUG status