ptolemy.distributed.client
Class ClientServerInteractionManager

java.lang.Object
  extended by ptolemy.distributed.client.ClientServerInteractionManager
All Implemented Interfaces:
java.util.EventListener, net.jini.discovery.DiscoveryListener, net.jini.lookup.ServiceDiscoveryListener

public class ClientServerInteractionManager
extends java.lang.Object
implements net.jini.discovery.DiscoveryListener, net.jini.lookup.ServiceDiscoveryListener

Manager that handles and eases the discovery of services using JINI. Helps the client service discovery. It discovers the lookup service. A configuration file can be provided in the constructor to specify unicast locators, groups to join and the service to be located. After discovering a lookup service it queries for the given service and filters the dead services.

Since:
Ptolemy II 5.1
Version:
$Id: ClientServerInteractionManager.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Daniel Lázaro Cuadrado (kapokasa@kom.aau.dk)
See Also:
"Jini Documentation"
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (kapokasa)

Field Summary
private  java.util.LinkedList aliveServices
          List of alive services discovered and filtered.
private  net.jini.lookup.LookupCache cache
          Cache of registrars.
private static java.lang.String CLIENT
          Key to be loaded from the configuration file.
private  net.jini.core.entry.Entry[] entries
          Information entries.
private  java.lang.String[] groups
          Groups.
private  int requiredServices
          Number of required services.
private  java.rmi.Remote service
          Service that we look for.
private  net.jini.core.discovery.LookupLocator[] unicastLocators
          Array of unicastLocators.
private  boolean VERBOSE
          Shows debug messages when true.
private static long WAITFOR
          Waiting time to receive responses when finding services.
 
Constructor Summary
ClientServerInteractionManager(boolean verbose)
          Construct a ClientServerInteractionManager initializing it with a given VERBOSE option.
 
Method Summary
 void discarded(net.jini.discovery.DiscoveryEvent evt)
          Required by DiscoveryListener interface.
 void discovered(net.jini.discovery.DiscoveryEvent evt)
          Required by DiscoveryListener interface.
private  void filterCacheServices()
          Construct the list of aliveServices.
private  void getConfiguration(java.lang.String configFileName)
          Loads the configuration file.
 java.util.LinkedList getServices()
          Returns the list of alive services.
 void init(java.lang.String configFileName)
          Initializes the ClientServerInteractionManager.
 void serviceAdded(net.jini.lookup.ServiceDiscoveryEvent evt)
          Required by ServiceDiscoveryListener interface.
 void serviceChanged(net.jini.lookup.ServiceDiscoveryEvent evt)
          Required by ServiceDiscoveryListener interface.
 void serviceRemoved(net.jini.lookup.ServiceDiscoveryEvent evt)
          Required by ServiceDiscoveryListener interface.
 void setRequiredServices(int requiredServices)
          Specify the number of required services.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requiredServices

private int requiredServices
Number of required services.


CLIENT

private static final java.lang.String CLIENT
Key to be loaded from the configuration file.

See Also:
Constant Field Values

WAITFOR

private static final long WAITFOR
Waiting time to receive responses when finding services.

See Also:
Constant Field Values

service

private java.rmi.Remote service
Service that we look for.


unicastLocators

private net.jini.core.discovery.LookupLocator[] unicastLocators
Array of unicastLocators.


entries

private net.jini.core.entry.Entry[] entries
Information entries.


groups

private java.lang.String[] groups
Groups.


cache

private net.jini.lookup.LookupCache cache
Cache of registrars.


aliveServices

private java.util.LinkedList aliveServices
List of alive services discovered and filtered.


VERBOSE

private boolean VERBOSE
Shows debug messages when true.

Constructor Detail

ClientServerInteractionManager

public ClientServerInteractionManager(boolean verbose)
Construct a ClientServerInteractionManager initializing it with a given VERBOSE option.

Parameters:
verbose - If true, flag messages will be printed in the standard output.
Method Detail

discarded

public void discarded(net.jini.discovery.DiscoveryEvent evt)
Required by DiscoveryListener interface. Called when one or more lookup service registrars has been discarded. The method should return quickly; e.g., it should not make remote calls.

Specified by:
discarded in interface net.jini.discovery.DiscoveryListener
Parameters:
evt - The event that describes the discarded registrars

discovered

public void discovered(net.jini.discovery.DiscoveryEvent evt)
Required by DiscoveryListener interface. Called when one or more lookup service registrars has been discovered. The method should return quickly; e.g., it should not make remote calls. It prints the locator of the found Registrars.

Specified by:
discovered in interface net.jini.discovery.DiscoveryListener
Parameters:
evt - The event that describes the discovered registrars

getServices

public java.util.LinkedList getServices()
Returns the list of alive services.

Returns:
LinkedList of registrars containing the alive services.

init

public void init(java.lang.String configFileName)
Initializes the ClientServerInteractionManager. It loads the configuration file and creates a ServiceDiscoveryManager in order to help locate the service. It searches for the service specified in the configuration file and it filters the dead services.

Parameters:
configFileName - String containing the name and/or path of the configuration file to be loaded.

serviceAdded

public void serviceAdded(net.jini.lookup.ServiceDiscoveryEvent evt)
Required by ServiceDiscoveryListener interface. When the cache receives from one of the managed lookup services, an event signaling the registration of a service of interest for the first time (or for the first time since the service has been discarded), the cache invokes the serviceAdded method on all instances of ServiceDiscoveryListener that are registered with the cache; doing so notifies the entity that a service of interest has been discovered. It just notifies of the event in the standard output.

Specified by:
serviceAdded in interface net.jini.lookup.ServiceDiscoveryListener
Parameters:
evt - a ServiceDiscoveryEvent object containing references to the service item corresponding to the event, including representations of the service's state both before and after the event.

serviceChanged

public void serviceChanged(net.jini.lookup.ServiceDiscoveryEvent evt)
Required by ServiceDiscoveryListener interface. When the cache receives, from a managed lookup service, an event signaling the unique modification of the attributes of a service of interest (across the attribute sets of all references to the service), the cache invokes the serviceChanged method on all instances of ServiceDiscoveryListener that are registered with the cache; doing so notifies the entity that the state of a service of interest has changed. It just notifies of the event in the standard output.

Specified by:
serviceChanged in interface net.jini.lookup.ServiceDiscoveryListener
Parameters:
evt - a ServiceDiscoveryEvent object containing references to the service item corresponding to the event, including representations of the service's state both before and after the event.

serviceRemoved

public void serviceRemoved(net.jini.lookup.ServiceDiscoveryEvent evt)
Required by ServiceDiscoveryListener interface. When the cache receives, from a managed lookup service, an event signaling the removal of a service of interest from the last such lookup service with which it was registered, the cache invokes the serviceRemoved method on all instances of ServiceDiscoveryListener that are registered with the cache; doing so notifies the entity that a service of interest has been discarded. It just notifies of the event in the standard output.

Specified by:
serviceRemoved in interface net.jini.lookup.ServiceDiscoveryListener
Parameters:
evt - a ServiceDiscoveryEvent object containing references to the service item corresponding to the event, including representations of the service's state both before and after the event.

setRequiredServices

public void setRequiredServices(int requiredServices)
Specify the number of required services.

Parameters:
requiredServices - The number of requiredServices.

filterCacheServices

private void filterCacheServices()
Construct the list of aliveServices.


getConfiguration

private void getConfiguration(java.lang.String configFileName)
Loads the configuration file. This file contains information about: codebase: location of the code. exporter: export to be used. groups: groups to join. unicast locators: Know service locators can be specified here. entries: Other info e.g. name and comments service: The service to be located.

Parameters:
configFileName - A string containing the name and/or path of the configuration file.