no.ubicollab.osgi
Class DiscoveryManagerImpl

java.lang.Object
  extended by no.ubicollab.osgi.DiscoveryManagerImpl
All Implemented Interfaces:
ServiceDiscovery

public class DiscoveryManagerImpl
extends java.lang.Object
implements ServiceDiscovery

This class provides Service Discovery (SD) access for UbiCollab applications and tools. In addition this module is general enough to also be used by other applications which is able to connect through the soap interface.

The principal functionality for the SDM is to be the broker between Service Discovery (SD) client applications (consumers) and SD plugins (producers). Client applications register their interests with the SDM and this information is passed on to the SD plugins which will search for matching services. The SD plugins will then register matching services in the queue that is assigned to the SD client, and he will retrive them from here.

Both clients and plugins must register with the SDM, before they can enter or retrieve any requests/interests. To maintain the principle of loose coupling, there is no unregister methods. Instead, sessions will be terminated by timeout.

Since:
0.1
Version:
0.6
Author:
Kim-Steve Johansen

Constructor Summary
DiscoveryManagerImpl()
          The Constructor for this class.
 
Method Summary
 java.lang.String getClientRequest(int pluginID)
          Gets a xml-string containing the client request list.
 java.lang.String getLogItems(int logLevel, int numItems)
          Read from the log and return selected log items in a XML-document, stored in a String.
 java.lang.String getSDPlugins()
          Method to return a list of the SD plugins which are registered with the SDM.
 java.lang.String getServices(int clientID)
          Return the result queue identified by the provided search request ID.
 int registerClient()
          This method allows any authenticated user (consumer/client app) to register as a client with the Service Discovery Manager (SDM).
 boolean registerClientRequest(int clientID, java.lang.String name, java.lang.String type, java.lang.String location, java.lang.String owner, java.lang.String description)
          This method allows any authenticated user (client) to register a search request with the Service Discovery Manager.
 int registerSDPlugin(java.lang.String protocolName)
          Register a Service Discovery plugin with the Service Discovery Manager.
 boolean registerService(int searchRequestorID, int protocolID, java.lang.String descriptionURI, java.lang.String serviceURI, java.lang.String friendlyName, java.lang.String type, java.lang.String description, java.lang.String owner, java.lang.String location)
          This method is provided for service discovery plugins to register services which matches client requests, with the Service Discovery Manager.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiscoveryManagerImpl

public DiscoveryManagerImpl()
The Constructor for this class. Instanciates the ClientList and PluginList, and starts the housekeeping thread.

Method Detail

getClientRequest

public java.lang.String getClientRequest(int pluginID)
Gets a xml-string containing the client request list.

The returned string is a well formed XML-document with a structure as defined in ServiceDiscovery#getClientRequest

Specified by:
getClientRequest in interface ServiceDiscovery
Parameters:
pluginID - the plugin ID
Returns:
the String with the client request list.
See Also:
ServiceDiscovery.getClientRequest(int)

getSDPlugins

public java.lang.String getSDPlugins()
Method to return a list of the SD plugins which are registered with the SDM. Usefull for client who wishes to know which SD protocols they have support for.

Specified by:
getSDPlugins in interface ServiceDiscovery
Returns:
a list of the SD plugins, formattet in XML. The following format is used: <Pluginlist> <Plugin Name='' Id='' /> </Pluginlist>

getServices

public java.lang.String getServices(int clientID)
Return the result queue identified by the provided search request ID. After the results are returned they will be removed from the queue.

Specified by:
getServices in interface ServiceDiscovery
Parameters:
clientID - the client ID which point to the correct queue
Returns:
The method returns "No matching services" if none are found (queue empty). "No such ID" if unknown or timed out ID. Otherwise a XML-formatted list of services is returned.

registerClient

public int registerClient()
This method allows any authenticated user (consumer/client app) to register as a client with the Service Discovery Manager (SDM). When a client is registered a service queue is created and assigned to him. In this queue all services matching requests from the client will be placed, as well as services discovered by user initiated physical SD plugins like RFID.

Upon registration the client will also be assigned a unique ID which will be used for identification when sending messages/communicating with the SDM. The client will also be assigned a time-to-live which initially is set to 1 minute. Every time the client invokes getServices() this time will be reset. If a client fails to connect to SDM for 1 minute, his session will be garbage collected (by the housekeeper thread).

Specified by:
registerClient in interface ServiceDiscovery
Returns:
the unique ID to be used for identification when communicating with the SDM.

registerClientRequest

public boolean registerClientRequest(int clientID,
                                     java.lang.String name,
                                     java.lang.String type,
                                     java.lang.String location,
                                     java.lang.String owner,
                                     java.lang.String description)
This method allows any authenticated user (client) to register a search request with the Service Discovery Manager. The manager will then make this request available to all registered service discovery plugins

After the request is placed, the client will get an ID which points to the queue of services found. This ID can then be used to poll for, and retrieve matching services using getServices.

When a request is placed the queue spawned will have a lifetime of 1 minute, and when the queue is queried a fresh minute is awarded.

Specified by:
registerClientRequest in interface ServiceDiscovery
Parameters:
owner - the Owner of the service
type - the service type to search for
description - the description of the service
location - the location of the service
clientID - the unique client ID
name - the name of the service to search for
Returns:
true, if client request is registered successfully, false otherwise.

registerSDPlugin

public int registerSDPlugin(java.lang.String protocolName)
Register a Service Discovery plugin with the Service Discovery Manager. When a plugin is registered it will get a unique ID which will be used for further communication.

The registration will have a lifespan of 30 seconds, and will be reset to 30 second every time getClientRequest() or registerService() is invoked. When this time runs out the plugin session will be garbage collected (by the housekeeper thread).

Specified by:
registerSDPlugin in interface ServiceDiscovery
Parameters:
protocolName - the name of the protocol, e.g. UPnP or RFID
Returns:
the ID for identifying the plugin
See Also:
ServiceDiscovery.registerSDPlugin(String)

registerService

public boolean registerService(int searchRequestorID,
                               int protocolID,
                               java.lang.String descriptionURI,
                               java.lang.String serviceURI,
                               java.lang.String friendlyName,
                               java.lang.String type,
                               java.lang.String description,
                               java.lang.String owner,
                               java.lang.String location)
This method is provided for service discovery plugins to register services which matches client requests, with the Service Discovery Manager. The service will be added to the queue identified by the provided searchRequestID.

This method provides many options as parameters and all of these will not be applicable for each plugin. The ones not used should simply contain an empty string.

Specified by:
registerService in interface ServiceDiscovery
Parameters:
friendlyName - The user-friendly name of the service
descriptionURI - URI for service description (e.g. the URL to a WSDL-file).
type - The service type (classification)
owner - The person/company/responsible for the service.
description - Tags (words or short sentences) describing the service.
location - Location where the service can be found
searchRequestorID - the ID for the search request queue to add this service to
protocolID - The id for the service discovery protocol plugin.
serviceURI - The URI to invoke the service
Returns:
True if the service is successfully registered, false if the client id or protocol id does not exist.
See Also:
ServiceDiscovery.registerService(int, int, String, String, String, String, String, String, String)

getLogItems

public java.lang.String getLogItems(int logLevel,
                                    int numItems)
Read from the log and return selected log items in a XML-document, stored in a String.

Specified by:
getLogItems in interface ServiceDiscovery
Parameters:
logLevel - The log level to include in the report.
numItems - The number of log items to include in the report
Returns:
the String containg the resulting XML
See Also:
ServiceDiscovery.getLogItems(int, int)