context.arch.discoverer
Class Discoverer

java.lang.Object
  extended bycontext.arch.BaseObject
      extended bycontext.arch.widget.Widget
          extended bycontext.arch.discoverer.Discoverer
All Implemented Interfaces:
CommunicationsHandler, MessageHandler

public class Discoverer
extends Widget

This class allows to add a discovery system to the context toolkit.

The discoverer is found by context components thanks to multicast communications. The discoverer allow them to register to it (to send their complete description), to query to it (to retrieve the description of components that fit several characteristics), to subscribe to notification (the subscriber wants to be notified when the discoverer registers a new component that fit some characteristics), to lease it (when a component registers to the discoverer, it registers for a given period that is identified by a lease), to unregister (when the component lease ends or when the components wants).

When a context component is created, it does not know the other components. And it can subscribes to another component only if it knows the component's name, port and hostname. The discoverer registers all context components when they are created, it stores for each of them their description. So that a component is able to do a request to the discoverer to get one or more context components that fit some characteristics (for example : I want all widgets that has information about Anind in the CRB)

Author:
Agathe
See Also:
context.arch.discoverer.SearchEngine, ComponentDescription, DiscovererDescription, context.arch.discoverer.query.Query, Lease, LeasesWatcher

Field Summary
static java.lang.String ALL_RESULTS
          Type of query reply : returns no query id and all results (with a maximum set by
static java.lang.String APPLICATION
          Component type : for application
static java.lang.String CALLER
          Tag used in LOOKUP_DISCOVERER to contain the description of the caller component
static java.lang.String CALLER_ID
          Tag used in LOOKUP_DISCOVERER inside CALLER tags for the component id Also used in LOOKUP_DISCOVERER_REPLY by discoverers
static java.lang.String CASE_SENSITIVE
          Type of matching for the query
static java.lang.String CLASSNAME
          Classname tag
static java.lang.String COMPONENT_CLASSNAME
          Tag used in DISCOVERER_REGISTRATION for component classname Tag also used in DISCOVERER_QUERY
static java.lang.String COMPONENT_ID
          Tag used in DISCOVERER_QUERY_REPLY to give the resulting component id
static java.lang.String CONSTANT_ATTRIBUTE_NAME
          Tag used in QueryElement to query the discoverer.
static java.lang.String CONSTANT_ATTRIBUTE_NAME_VALUES
          Tag used in DISCOVERER_REGISTRATION to contain the constant attributes of the component Tag also used in DISCOVERER_QUERY This tag is also used in QueryElement to query the discoverer.
static java.lang.String CONSTANT_ATTRIBUTE_VALUE
          Tag used in QueryElement to query the discoverer.
static boolean DEBUG
          Debug flag.
static int DEFAULT_MAX_RESULTS
          Default number of responses sent in replyt to a DISOVERER_QUERY message with a ALL_RESULTS type
static int DEFAULT_PORT
          Default port for discoverer to use
static java.lang.String DISCOVERER
          Tag used in LOOKUP_DISCOVERER_REPLY to contain the discoverer description
static java.lang.String DISCOVERER_DESCRIPTION_FULL_RESPONSE
          Tag used to determine level of detail of component description in response to subscribers
static java.lang.String DISCOVERER_ID
          Tag used in LOOKUP_DISCOVERER_REPLY for the discoverer id Also used in DISCOVERER_REGISTRATION
static java.lang.String DISCOVERER_QUERY
          Tag used for query messages to the discoverer
static java.lang.String DISCOVERER_QUERY_CONTENT
          Tag used in DISCOVERER_QUERY messages to the discoverer
static java.lang.String DISCOVERER_QUERY_REPLY
          Tag used for query reply messages to the discoverer
static java.lang.String DISCOVERER_QUERY_REPLY_CONTENT
          Tag used in DISCOVERER_QUERY_REPLY_CONTENTS messages
static java.lang.String DISCOVERER_QUERY_REPLY_CONTENTS
          Tag used in DISCOVERER_QUERY_REPLY messages to the discoverer
static java.lang.String DISCOVERER_QUERY_TYPE
          Tag used in DISCOVERER_QUERY_CONTENT to indicate the type of query reply
static java.lang.String DISCOVERER_REGISTRATION
          Message tag used by components to send to the discoverer their description
static java.lang.String DISCOVERER_SUBSCRIBE
          Message tag used by components to send to the discoverer a subscription
static java.lang.String DISCOVERER_TYPE
           
static java.lang.String DISCOVERER_UNREGISTRATION
          Message tag used by components to unregister from the discoverer
static java.lang.String DISCOVERER_UNREGISTRATION_REPLY
          Message tag used by the discoverer to reply to a DISCOVERER_UNREGISTRATION message
static java.lang.String DISCOVERER_UPDATE
          Message tag used by components to send to the discoverer an update
static java.lang.String ERROR_EMPTY_QUERY
          This tag is used when there is no response to the received query
static java.lang.String ERROR_QUERY_NOT_FOUND
          This tag is used when a NEXT_RESULT query is received and the queryId is not reckognized
static java.lang.String ERROR_REGISTRATION_NOT_FOUND
          This tag is used in error object for DISCOVERER_UNREGISTRATION_REPLY messages when the context component that want to be unregistered is not found.
static java.lang.String FIELD_SEPARATOR
          Separator used to separate fields (as for constant attribute name and value)
static java.lang.String FIRST_RESULT
          Type of query reply : returns the first element
static java.lang.String HOSTADDRESS
          Tag used in LOOKUP_DISCOVERER inside CALLER tags for the component IP address
static java.lang.String HOSTNAME
          Tag used in LOOKUP_DISCOVERER inside CALLER tags for the component hostname Also used in LOOKUP_DISCOVERER_REPLY, DISCOVERER_REGISTRATION
static java.lang.String IGNORE_CASE
          Type of matching for the query
static java.lang.String INCOMING_ATTRIBUTE_NAME_VALUES
          Tag used in DISCOVERER_REGISTRATION to contain the incoming attribute name values Tag also used in DISCOVERER_QUERY
static java.lang.String INTERPRETER
          Component type : for interpreter
static java.lang.String LOCATION_ADDRESS
          Tag used in DISOCVERER_REGISTRATION for the component location address Tag also used in DISCOVERER_QUERY
static java.lang.String LOOKUP_DISCOVERER
          Message tag used by components to send a multicast message to lookup a discoverer
static java.lang.String LOOKUP_DISCOVERER_OK
          Message tag used by discoverers to reply to a lookup message
static java.lang.String LOOKUP_DISCOVERER_REPLY
          Message tag used by discoverers to reply to a lookup message
static java.lang.String MAXIMUM_RESULTS
          Tag used if DISCOVERER_QUERY to set the maximum number of responses wanted
protected  DiscovererMediator mediator
           
static java.lang.String NEW_COMPONENT
          This tag is the callback name used to notify subscriber of a new component
static java.lang.String NEXT_RESULT
          Type of query reply : returns the next result
static java.lang.String NON_CONSTANT_ATTRIBUTE_NAME
          Tag used in QueryElement to query the discoverer.
static java.lang.String NON_CONSTANT_ATTRIBUTE_NAME_VALUES
          Tag used in DISCOVERER_REGISTRATION to contain the non constant attributes of the component Tag also used in DISCOVERER_QUERY
static java.lang.String OUTGOING_ATTRIBUTE_NAME_VALUES
          Tag used in DISCOVERER_REGISTRATION to contain the outgoing attribute name values Tag also used in DISCOVERER_QUERY
static java.lang.String PORT
          Tag used in LOOKUP_DISCOVERER inside CALLER tags for the component port Also used in LOOKUP_DISCOVERER_REPLY, DISCOVERER_REGISTRATION
static java.lang.String PRIORITY
          Attribute tag used in the DISCOVERER_QUERY_CONTENT
static int PRIORITY_1
          First or weakest priority for the query element
static int PRIORITY_2
          Second or middle priority for the query element
static int PRIORITY_3
          Last or stronger priority for the query element
static java.lang.String QUERY_ID
          Tag used in the DISCOVERER_QUERY_REPLY_CONTENT to give the query id
static java.lang.String QUERY_ORDER
          Tag used inside the DISCOVERER_QUERY_REPLY_CONTENT to give the order of the response
static java.lang.String QUERY_TOTAL_ANSWERS
          Tag used inside the DISCOVERER_QUERY_REPLY_CONTENT to give the total number of answers to the query
static java.lang.String REGISTERER
          Tag used in DISCOVERER_REGISTRATION to contain the description of the component registring
static java.lang.String REGISTERER_ID
          Tag used in DISCOVERER_REGISTRATION for the component id
static java.lang.String SERVER
          Component type : for servers
static java.lang.String SERVER_CALLBACKS
          Tag used in DISCOVERER_REGISTRATION to contain the server callback names
static java.lang.String SERVER_CONSTANT_ATTRIBUTES
          Tag used in DISCOVERER_REGISTRATION to contain the server constant attributes of the component
static java.lang.String SERVER_NON_CONSTANT_ATTRIBUTES
          Tag used in DISCOVERER_REGISTRATION to contain the server non constant attributes of the component
static java.lang.String SERVER_SERVICES
          Tag used in DISCOVERER_REGISTRATION to contain the server service names
static java.lang.String TEMP_DEST
          Tag used by communicationsObject to retrieve the destination address
static java.lang.String TYPE
          Tag used in LOOKUP_DISCOVERER inside CALLER tags for the component type (baseobject(applications), widget, server, interpreter)
static java.lang.String UPDATE_ADD_TYPE
          Tag used in UPDATE_TYPE message to specify the method used to update information.
static java.lang.String UPDATE_REPLACE_TYPE
          Tag used in UPDATE_TYPE message to specify the method used to update information Replace type is used to remove old information before adding new one.
static java.lang.String UPDATE_TYPE
          Message tag used by components to specify the update's type
static java.lang.String WIDGET
          Component type : for widget
static java.lang.String WIDGET_CALLBACKS
          Tag used in DISCOVERER_REGISTRATION to contain the widget callback names Tag also used in DISCOVERER_QUERY
static java.lang.String WIDGET_SERVICES
          Tag used in DISCOVERER_REGISTRATION to contain the widget service names Tag also used in DISCOVERER_QUERY
 
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
Discoverer()
          Constructor that sets up internal variables for maintaining the list of widget attributes, callbacks and services.
Discoverer(int port)
          Constructor that sets up internal variables for maintaining the list of discoverer attributes, callbacks and services.
Discoverer(int port, boolean storageFlag)
          Constructor that sets up internal variables for maintaining the list of discoverer attributes, callbacks and services.
Discoverer(java.lang.String id, boolean storageFlag)
          Constructor that sets up internal variables for maintaining the list of discoverer attributes, callbacks and services.
Discoverer(java.lang.String clientClass, java.lang.String serverClass, int serverPort, java.lang.String encoderClass, java.lang.String decoderClass, boolean storageFlag)
          Constructor that sets up internal variables for maintaining the list of discoverer attributes, callbacks, and services and setting up the BaseObject info.
Discoverer(java.lang.String clientClass, java.lang.String serverClass, int serverPort, java.lang.String encoderClass, java.lang.String decoderClass, java.lang.String storageClass)
          Constructor that sets up internal variables for maintaining the list of discoverer attributes, callbacks, and services and setting up the BaseObject info.
 
Method Summary
 int checkSubscribers(Callback callback, ComponentDescription comp)
          This method allows to send a message to all subscribers whose interests are for the new registered component.
protected  DataObject componentRegistration(DataObject data)
          This method handles a DISCOVERER_REGISTRATION message.
 DataObject componentSubscription(DataObject dataObject)
          This method is handling the subscription of a context component that wants to subscribe to be notified of the registration of context components of its interest.
protected  DataObject componentUnregistration(DataObject dataObject)
          This method is used to unregister a context component from the discoverer.
 DataObject componentUpdate(DataObject dataObject)
          This method handles the UPDATE_DISCOVERER messages.
 DataObject getDiscovererDescription(DataObject data)
          ?? TO DO : add errors control This method returns the DataObject replying to the LOOKUP_DISCOVERER message from a component.
 java.lang.String getSearchEngineContent()
          Returns the content of the search engine
 java.lang.String getType()
          Returns the type of the object This method should be overridden
 void handleIndependentReply(IndependentCommunication independentCommunication)
          This method is called after the independentUserRequest has been called.
 DataObject handleQuery(DataObject data)
          Handles a DISCOVERER_QUUERY message from components and returns a DataObject containing the identification of the response and the first response.
protected  Attributes initAttributes()
          Sets the attributes for the discoverer: they specify the information the discoverer is storing about the registered context components.
protected  Callbacks initCallbacks()
          Sets the callbacks for the discoverer
protected  Attributes initConstantAttributes()
          Sets the constant attributes for the discoverer
protected  Services initServices()
          Sets the services for the discoverer
static void main(java.lang.String[] argv)
          Main method to create a discoverer with location and port specified by command line arguments
protected  Attributes queryGenerator()
          This abstract method is called when the discoverer wants to get the latest generator info.
protected  void removeComponentDescription(java.lang.Integer componentToRemoveIndex)
          This method allows to remove a ComponentDescription from the discoverer
protected  DataObject runDiscovererMethod(DataObject dataObject, java.lang.String error)
          This method should be overriden by inheriting classes to handle other messages.
protected  DataObject runWidgetMethod(DataObject dataObject, java.lang.String error)
          This method is meant to handle any internal methods that the baseObject doesn't handle.
 void sendLeaseEndNotificationTo(java.util.ArrayList listOfComponents)
          This method allows to send a lease end notification to each component whose lease ends.
protected  boolean sendLeaseEndNotificationTo(IndependentCommunication comm)
          This method allows to send the Lease.LEASE_END_NOTIFICATION to a context component.
 java.lang.String subscribersToString()
          Returns a printable version of the list of discoverer subscribers
 
Methods inherited from class context.arch.widget.Widget
addSubscriber, canHandle, canHandle, executeService, getAttributeType, getCurrentTime, getNewOffset, getNewOffsetNoDelay, getSubscribersDescription, getUserDescription, getWidgetDescription, isAttribute, isCallback, notify, processCallbackReply, putData, queryAttributes, queryCallbacks, queryConstantAttributes, queryServices, queryWidget, removeSubscriber, retrieveData, runUserMethod, 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
 

Field Detail

DEBUG

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

See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
Default port for discoverer to use

See Also:
Constant Field Values

CLASSNAME

public static final java.lang.String CLASSNAME
Classname tag

See Also:
Constant Field Values

LOOKUP_DISCOVERER

public static final java.lang.String LOOKUP_DISCOVERER
Message tag used by components to send a multicast message to lookup a discoverer

See Also:
Constant Field Values

CALLER

public static final java.lang.String CALLER
Tag used in LOOKUP_DISCOVERER to contain the description of the caller component

See Also:
Constant Field Values

CALLER_ID

public static final java.lang.String CALLER_ID
Tag used in LOOKUP_DISCOVERER inside CALLER tags for the component id Also used in LOOKUP_DISCOVERER_REPLY by discoverers

See Also:
Constant Field Values

TYPE

public static final java.lang.String TYPE
Tag used in LOOKUP_DISCOVERER inside CALLER tags for the component type (baseobject(applications), widget, server, interpreter)

See Also:
Constant Field Values

HOSTNAME

public static final java.lang.String HOSTNAME
Tag used in LOOKUP_DISCOVERER inside CALLER tags for the component hostname Also used in LOOKUP_DISCOVERER_REPLY, DISCOVERER_REGISTRATION

See Also:
Constant Field Values

HOSTADDRESS

public static final java.lang.String HOSTADDRESS
Tag used in LOOKUP_DISCOVERER inside CALLER tags for the component IP address

See Also:
Constant Field Values

PORT

public static final java.lang.String PORT
Tag used in LOOKUP_DISCOVERER inside CALLER tags for the component port Also used in LOOKUP_DISCOVERER_REPLY, DISCOVERER_REGISTRATION

See Also:
Constant Field Values

LOOKUP_DISCOVERER_REPLY

public static final java.lang.String LOOKUP_DISCOVERER_REPLY
Message tag used by discoverers to reply to a lookup message

See Also:
Constant Field Values

DISCOVERER

public static final java.lang.String DISCOVERER
Tag used in LOOKUP_DISCOVERER_REPLY to contain the discoverer description

See Also:
Constant Field Values

DISCOVERER_TYPE

public static final java.lang.String DISCOVERER_TYPE
See Also:
Constant Field Values

DISCOVERER_ID

public static final java.lang.String DISCOVERER_ID
Tag used in LOOKUP_DISCOVERER_REPLY for the discoverer id Also used in DISCOVERER_REGISTRATION

See Also:
Constant Field Values

COMPONENT_ID

public static final java.lang.String COMPONENT_ID
Tag used in DISCOVERER_QUERY_REPLY to give the resulting component id

See Also:
Constant Field Values

LOOKUP_DISCOVERER_OK

public static final java.lang.String LOOKUP_DISCOVERER_OK
Message tag used by discoverers to reply to a lookup message

See Also:
Constant Field Values

DISCOVERER_REGISTRATION

public static final java.lang.String DISCOVERER_REGISTRATION
Message tag used by components to send to the discoverer their description

See Also:
Constant Field Values

DISCOVERER_UNREGISTRATION

public static final java.lang.String DISCOVERER_UNREGISTRATION
Message tag used by components to unregister from the discoverer

See Also:
Constant Field Values

DISCOVERER_UNREGISTRATION_REPLY

public static final java.lang.String DISCOVERER_UNREGISTRATION_REPLY
Message tag used by the discoverer to reply to a DISCOVERER_UNREGISTRATION message

See Also:
Constant Field Values

DISCOVERER_UPDATE

public static final java.lang.String DISCOVERER_UPDATE
Message tag used by components to send to the discoverer an update

See Also:
Constant Field Values

DISCOVERER_SUBSCRIBE

public static final java.lang.String DISCOVERER_SUBSCRIBE
Message tag used by components to send to the discoverer a subscription

See Also:
Constant Field Values

UPDATE_TYPE

public static final java.lang.String UPDATE_TYPE
Message tag used by components to specify the update's type

See Also:
Constant Field Values

UPDATE_ADD_TYPE

public static final java.lang.String UPDATE_ADD_TYPE
Tag used in UPDATE_TYPE message to specify the method used to update information. Add type is used to add information.

See Also:
Constant Field Values

UPDATE_REPLACE_TYPE

public static final java.lang.String UPDATE_REPLACE_TYPE
Tag used in UPDATE_TYPE message to specify the method used to update information Replace type is used to remove old information before adding new one.

See Also:
Constant Field Values

REGISTERER

public static final java.lang.String REGISTERER
Tag used in DISCOVERER_REGISTRATION to contain the description of the component registring

See Also:
Constant Field Values

REGISTERER_ID

public static final java.lang.String REGISTERER_ID
Tag used in DISCOVERER_REGISTRATION for the component id

See Also:
Constant Field Values

COMPONENT_CLASSNAME

public static final java.lang.String COMPONENT_CLASSNAME
Tag used in DISCOVERER_REGISTRATION for component classname Tag also used in DISCOVERER_QUERY

See Also:
Constant Field Values

LOCATION_ADDRESS

public static final java.lang.String LOCATION_ADDRESS
Tag used in DISOCVERER_REGISTRATION for the component location address Tag also used in DISCOVERER_QUERY

See Also:
Constant Field Values

CONSTANT_ATTRIBUTE_NAME_VALUES

public static final java.lang.String CONSTANT_ATTRIBUTE_NAME_VALUES
Tag used in DISCOVERER_REGISTRATION to contain the constant attributes of the component Tag also used in DISCOVERER_QUERY This tag is also used in QueryElement to query the discoverer. Then it is used to match the name AND the value of a constant attribute. The match will be successful if the combination of the name&value exists for a component description

See Also:
context.arch.discoverer.query.QueryElement, context.arch.discoverer.query.Query, Constant Field Values

NON_CONSTANT_ATTRIBUTE_NAME_VALUES

public static final java.lang.String NON_CONSTANT_ATTRIBUTE_NAME_VALUES
Tag used in DISCOVERER_REGISTRATION to contain the non constant attributes of the component Tag also used in DISCOVERER_QUERY

See Also:
Constant Field Values

CONSTANT_ATTRIBUTE_NAME

public static final java.lang.String CONSTANT_ATTRIBUTE_NAME
Tag used in QueryElement to query the discoverer. It is used to match just the name of a constant attribute

See Also:
context.arch.discoverer.query.QueryElement, context.arch.discoverer.query.Query, Constant Field Values

NON_CONSTANT_ATTRIBUTE_NAME

public static final java.lang.String NON_CONSTANT_ATTRIBUTE_NAME
Tag used in QueryElement to query the discoverer. It is used to match just the name of a non constant attribute

See Also:
context.arch.discoverer.query.QueryElement, context.arch.discoverer.query.Query, Constant Field Values

CONSTANT_ATTRIBUTE_VALUE

public static final java.lang.String CONSTANT_ATTRIBUTE_VALUE
Tag used in QueryElement to query the discoverer. It is used to match just the value of a constant attribute

See Also:
context.arch.discoverer.query.QueryElement, context.arch.discoverer.query.Query, Constant Field Values

SERVER_CONSTANT_ATTRIBUTES

public static final java.lang.String SERVER_CONSTANT_ATTRIBUTES
Tag used in DISCOVERER_REGISTRATION to contain the server constant attributes of the component

See Also:
Constant Field Values

SERVER_NON_CONSTANT_ATTRIBUTES

public static final java.lang.String SERVER_NON_CONSTANT_ATTRIBUTES
Tag used in DISCOVERER_REGISTRATION to contain the server non constant attributes of the component

See Also:
Constant Field Values

INCOMING_ATTRIBUTE_NAME_VALUES

public static final java.lang.String INCOMING_ATTRIBUTE_NAME_VALUES
Tag used in DISCOVERER_REGISTRATION to contain the incoming attribute name values Tag also used in DISCOVERER_QUERY

See Also:
Constant Field Values

OUTGOING_ATTRIBUTE_NAME_VALUES

public static final java.lang.String OUTGOING_ATTRIBUTE_NAME_VALUES
Tag used in DISCOVERER_REGISTRATION to contain the outgoing attribute name values Tag also used in DISCOVERER_QUERY

See Also:
Constant Field Values

WIDGET_CALLBACKS

public static final java.lang.String WIDGET_CALLBACKS
Tag used in DISCOVERER_REGISTRATION to contain the widget callback names Tag also used in DISCOVERER_QUERY

See Also:
Constant Field Values

SERVER_CALLBACKS

public static final java.lang.String SERVER_CALLBACKS
Tag used in DISCOVERER_REGISTRATION to contain the server callback names

See Also:
Constant Field Values

WIDGET_SERVICES

public static final java.lang.String WIDGET_SERVICES
Tag used in DISCOVERER_REGISTRATION to contain the widget service names Tag also used in DISCOVERER_QUERY

See Also:
Constant Field Values

SERVER_SERVICES

public static final java.lang.String SERVER_SERVICES
Tag used in DISCOVERER_REGISTRATION to contain the server service names

See Also:
Constant Field Values

TEMP_DEST

public static final java.lang.String TEMP_DEST
Tag used by communicationsObject to retrieve the destination address

See Also:
Constant Field Values

DISCOVERER_QUERY

public static final java.lang.String DISCOVERER_QUERY
Tag used for query messages to the discoverer

See Also:
Constant Field Values

DISCOVERER_QUERY_CONTENT

public static final java.lang.String DISCOVERER_QUERY_CONTENT
Tag used in DISCOVERER_QUERY messages to the discoverer

See Also:
Constant Field Values

DISCOVERER_DESCRIPTION_FULL_RESPONSE

public static final java.lang.String DISCOVERER_DESCRIPTION_FULL_RESPONSE
Tag used to determine level of detail of component description in response to subscribers

See Also:
Constant Field Values

DISCOVERER_QUERY_REPLY

public static final java.lang.String DISCOVERER_QUERY_REPLY
Tag used for query reply messages to the discoverer

See Also:
Constant Field Values

DISCOVERER_QUERY_REPLY_CONTENTS

public static final java.lang.String DISCOVERER_QUERY_REPLY_CONTENTS
Tag used in DISCOVERER_QUERY_REPLY messages to the discoverer

See Also:
Constant Field Values

DISCOVERER_QUERY_REPLY_CONTENT

public static final java.lang.String DISCOVERER_QUERY_REPLY_CONTENT
Tag used in DISCOVERER_QUERY_REPLY_CONTENTS messages

See Also:
Constant Field Values

DISCOVERER_QUERY_TYPE

public static final java.lang.String DISCOVERER_QUERY_TYPE
Tag used in DISCOVERER_QUERY_CONTENT to indicate the type of query reply

See Also:
Constant Field Values

QUERY_ID

public static final java.lang.String QUERY_ID
Tag used in the DISCOVERER_QUERY_REPLY_CONTENT to give the query id

See Also:
Constant Field Values

QUERY_ORDER

public static final java.lang.String QUERY_ORDER
Tag used inside the DISCOVERER_QUERY_REPLY_CONTENT to give the order of the response

See Also:
Constant Field Values

QUERY_TOTAL_ANSWERS

public static final java.lang.String QUERY_TOTAL_ANSWERS
Tag used inside the DISCOVERER_QUERY_REPLY_CONTENT to give the total number of answers to the query

See Also:
Constant Field Values

FIRST_RESULT

public static final java.lang.String FIRST_RESULT
Type of query reply : returns the first element

See Also:
Constant Field Values

ALL_RESULTS

public static final java.lang.String ALL_RESULTS
Type of query reply : returns no query id and all results (with a maximum set by

See Also:
Constant Field Values

DEFAULT_MAX_RESULTS

public static final int DEFAULT_MAX_RESULTS
Default number of responses sent in replyt to a DISOVERER_QUERY message with a ALL_RESULTS type

See Also:
Constant Field Values

NEXT_RESULT

public static final java.lang.String NEXT_RESULT
Type of query reply : returns the next result

See Also:
Constant Field Values

MAXIMUM_RESULTS

public static final java.lang.String MAXIMUM_RESULTS
Tag used if DISCOVERER_QUERY to set the maximum number of responses wanted

See Also:
Constant Field Values

IGNORE_CASE

public static final java.lang.String IGNORE_CASE
Type of matching for the query

See Also:
Constant Field Values

CASE_SENSITIVE

public static final java.lang.String CASE_SENSITIVE
Type of matching for the query

See Also:
Constant Field Values

PRIORITY

public static final java.lang.String PRIORITY
Attribute tag used in the DISCOVERER_QUERY_CONTENT

See Also:
Constant Field Values

PRIORITY_1

public static final int PRIORITY_1
First or weakest priority for the query element

See Also:
Constant Field Values

PRIORITY_2

public static final int PRIORITY_2
Second or middle priority for the query element

See Also:
Constant Field Values

PRIORITY_3

public static final int PRIORITY_3
Last or stronger priority for the query element

See Also:
Constant Field Values

APPLICATION

public static final java.lang.String APPLICATION
Component type : for application

See Also:
Constant Field Values

WIDGET

public static final java.lang.String WIDGET
Component type : for widget

See Also:
Constant Field Values

SERVER

public static final java.lang.String SERVER
Component type : for servers

See Also:
Constant Field Values

INTERPRETER

public static final java.lang.String INTERPRETER
Component type : for interpreter

See Also:
Constant Field Values

FIELD_SEPARATOR

public static final java.lang.String FIELD_SEPARATOR
Separator used to separate fields (as for constant attribute name and value)

See Also:
Constant Field Values

ERROR_REGISTRATION_NOT_FOUND

public static final java.lang.String ERROR_REGISTRATION_NOT_FOUND
This tag is used in error object for DISCOVERER_UNREGISTRATION_REPLY messages when the context component that want to be unregistered is not found.

See Also:
Constant Field Values

ERROR_QUERY_NOT_FOUND

public static final java.lang.String ERROR_QUERY_NOT_FOUND
This tag is used when a NEXT_RESULT query is received and the queryId is not reckognized

See Also:
Constant Field Values

ERROR_EMPTY_QUERY

public static final java.lang.String ERROR_EMPTY_QUERY
This tag is used when there is no response to the received query

See Also:
Constant Field Values

NEW_COMPONENT

public static final java.lang.String NEW_COMPONENT
This tag is the callback name used to notify subscriber of a new component

See Also:
Constant Field Values

mediator

protected DiscovererMediator mediator
Constructor Detail

Discoverer

public Discoverer(java.lang.String clientClass,
                  java.lang.String serverClass,
                  int serverPort,
                  java.lang.String encoderClass,
                  java.lang.String decoderClass,
                  java.lang.String storageClass)
Constructor that sets up internal variables for maintaining the list of discoverer attributes, callbacks, and services and setting up the BaseObject 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
See Also:
StorageObject

Discoverer

public Discoverer(java.lang.String clientClass,
                  java.lang.String serverClass,
                  int serverPort,
                  java.lang.String encoderClass,
                  java.lang.String decoderClass,
                  boolean storageFlag)
Constructor that sets up internal variables for maintaining the list of discoverer attributes, callbacks, and services and setting up the BaseObject info. This version takes a boolean to indicate whether the default storage class should be used or whether no 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
See Also:
StorageObject

Discoverer

public Discoverer(int port,
                  boolean storageFlag)
Constructor that sets up internal variables for maintaining the list of discoverer attributes, callbacks and services. It takes a port number as a parameter to indicate which port to listen for messages/connections, the id to use for the widget, and a flag to indicate whether storage functionality should be turned on or off.

Parameters:
port - Port to listen to for incoming messages
storageFlag - Boolean flag to indicate whether storage should be turned on

Discoverer

public Discoverer(int port)
Constructor that sets up internal variables for maintaining the list of discoverer attributes, callbacks and services. 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

Discoverer

public Discoverer(java.lang.String id,
                  boolean storageFlag)
Constructor that sets up internal variables for maintaining the list of discoverer attributes, callbacks and services. It takes the id to use for the widget, and a flag to indicate whether storage functionality should be turned on or off.

Parameters:
id - Discoverer id
storageFlag - Boolean flag to indicate whether storage should be turned on

Discoverer

public Discoverer()
Constructor that sets up internal variables for maintaining the list of widget attributes, callbacks and services. It takes the widget id as a parameter

Method Detail

initAttributes

protected Attributes initAttributes()
Sets the attributes for the discoverer: they specify the information the discoverer is storing about the registered context components.

Specified by:
initAttributes in class Widget
Returns:
Attributes The attributes of the discoverer

initConstantAttributes

protected Attributes initConstantAttributes()
Sets the constant attributes for the discoverer

Specified by:
initConstantAttributes in class Widget
Returns:
Attributes The constant attributes of the discoverer

initCallbacks

protected Callbacks initCallbacks()
Sets the callbacks for the discoverer

Specified by:
initCallbacks in class Widget
Returns:
Callbacks The callbacks of the discoverer

initServices

protected Services initServices()
Sets the services for the discoverer

Specified by:
initServices in class Widget
Returns:
Services The services provides by the discoverer

queryGenerator

protected Attributes queryGenerator()
This abstract method is called when the discoverer wants to get the latest generator info.

Specified by:
queryGenerator in class Widget
Returns:
AttributeNameValues containing the latest generator information

runWidgetMethod

protected DataObject runWidgetMethod(DataObject dataObject,
                                     java.lang.String error)
This method is meant to handle any internal methods that the baseObject doesn't handle. In particular, this method handles the common details for query requests, update and query requests, and version requests that each widget should provide. If the method is not one of these queries, then it calls runWidgetMethod which each widget should provide.

Overrides:
runWidgetMethod in class Widget
Parameters:
dataObject - DataObject containing the method to run and parameters
error - Error object
Returns:
DataObject containing the results of the executed method
See Also:
LOOKUP_DISCOVERER, DISCOVERER_REGISTRATION, DISCOVERER_UNREGISTRATION, DISCOVERER_UPDATE, DISCOVERER_QUERY, DISCOVERER_SUBSCRIBE

runDiscovererMethod

protected DataObject runDiscovererMethod(DataObject dataObject,
                                         java.lang.String error)
This method should be overriden by inheriting classes to handle other messages.

Parameters:
dataObject - The data object containing the message
error - The Error object
Returns:
DataObject The result

getDiscovererDescription

public DataObject getDiscovererDescription(DataObject data)
?? TO DO : add errors control This method returns the DataObject replying to the LOOKUP_DISCOVERER message from a component. The reply contains the description of the discoverer and add the id, address and port of the component to reply to.

Parameters:
data - The DataObject containing the identification of the caller component
Returns:
DataObject It contains the LOOKUP_DISCOVERER_REPLY message
See Also:
DiscovererDescription

componentRegistration

protected DataObject componentRegistration(DataObject data)
This method handles a DISCOVERER_REGISTRATION message. It registers a component by storing its description and replies with an error code.

Parameters:
data - The DataObject containing the description on the caller component
Returns:
DataObject An error code
See Also:
ComponentDescription

checkSubscribers

public int checkSubscribers(Callback callback,
                            ComponentDescription comp)
This method allows to send a message to all subscribers whose interests are for the new registered component.

Parameters:
comp - The component newly registered
Returns:
int The number of subscribers a message has been sent to

componentUnregistration

protected DataObject componentUnregistration(DataObject dataObject)
This method is used to unregister a context component from the discoverer. After the unregistration, the context component description will not be referenced in the discoverer.

Parameters:
dataObject - The content of the DISCOVERER_UNREGISTRATION message
Returns:
DataObject The result of the unregistration
See Also:
DISCOVERER_UNREGISTRATION, #ERROR_COMPONENT_NOT_FOUND

removeComponentDescription

protected void removeComponentDescription(java.lang.Integer componentToRemoveIndex)
This method allows to remove a ComponentDescription from the discoverer

Parameters:
componentToRemoveIndex - The index of the component to remove

componentUpdate

public DataObject componentUpdate(DataObject dataObject)
This method handles the UPDATE_DISCOVERER messages. It gets the modified fields and update the component description and returns an error code.

Returns:
DataObject The data containing an error code
See Also:
ComponentDescription

componentSubscription

public DataObject componentSubscription(DataObject dataObject)
This method is handling the subscription of a context component that wants to subscribe to be notified of the registration of context components of its interest. The content of the message is like a query message. The subscriber sends a query containing the description of the components of its interest. The discoverer adds this subscriber, and replies with the corresponding components that have already registered.

Returns:
DataObject contains the reply to the subscriber

handleQuery

public DataObject handleQuery(DataObject data)
Handles a DISCOVERER_QUUERY message from components and returns a DataObject containing the identification of the response and the first response. To complete ...

Parameters:
data - The DataObject containing the query
Returns:
DataObject The first result of the query
See Also:
context.arch.discoverer.Query, context.arch.discoverer.QueryElement, context.arch.discoverer.Response, context.arch.discoverer.ResponseElement, context.arch.discoverer.SearchEngine

getSearchEngineContent

public java.lang.String getSearchEngineContent()
Returns the content of the search engine

Returns:
String The content of the search engine

sendLeaseEndNotificationTo

public void sendLeaseEndNotificationTo(java.util.ArrayList listOfComponents)
This method allows to send a lease end notification to each component whose lease ends. The reply received by the component either renew the lease or confirms it.

Parameters:
listOfComponents - The components index

sendLeaseEndNotificationTo

protected boolean sendLeaseEndNotificationTo(IndependentCommunication comm)
This method allows to send the Lease.LEASE_END_NOTIFICATION to a context component. TO complete to handle the lease_renewal

Returns:
Lease The lease object if the reply from the component is to renew the lease, or null if it confirms the lease end.

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
Overrides:
handleIndependentReply in class Widget
Parameters:
independentCommunication - The object sent back by the thread
See Also:
ClientsPool, Client, context.arch.util.RequestObject, DataObject

getType

public java.lang.String getType()
Description copied from class: Widget
Returns the type of the object This method should be overridden

Overrides:
getType in class Widget
Returns:
String

subscribersToString

public java.lang.String subscribersToString()
Returns a printable version of the list of discoverer subscribers

Returns:
String

main

public static void main(java.lang.String[] argv)
Main method to create a discoverer with location and port specified by command line arguments