com.sun.jini.outrigger
Class JoinStateManager

java.lang.Object
  extended by com.sun.jini.outrigger.JoinStateManager
All Implemented Interfaces:
StorableObject

 class JoinStateManager
extends Object
implements StorableObject

JoinStateManager provides a utility that manages a service's join state (optionally persisting that state) and manages the join protocol protocol on behalf of the service.

Author:
Sun Microsystems, Inc.
See Also:
JoinManager

Field Summary
private  Entry[] attributes
          The list of attributes to start with.
private  DiscoveryGroupManagement dgm
          Object used to find lookups.
private  String[] groups
          The list of group names to start with.
private  boolean initial
          Conceptually, true if this is the first time this service has come up, implemented as if there was no previous state then this is the first time.
private  LookupLocator[] locators
          The list of LookupLocators to start with.
private  LogOps log
          The object that is coordinating our persistent state.
private static Logger logger
          Logger for logging join related information
private  ProxyPreparer lookupLocatorPreparer
          ProxyPreparer for LookupLocators
private  JoinManager mgr
          JoinManager that is handling the details of binding into Jini lookup services.
 
Constructor Summary
JoinStateManager()
          Simple constructor.
 
Method Summary
 void addLookupAttributes(Entry[] attrSets)
          Add attribute sets for the service.
 void addLookupGroups(String[] groups)
          Add new groups to the set to join.
 void addLookupLocators(LookupLocator[] locators)
          Add locators for specific new lookup services to join.
 void destroy()
          Make a good faith attempt to terminate discovery, and cancel any lookup registrations.
 Entry[] getLookupAttributes()
          Get the current attribute sets for the service.
 String[] getLookupGroups()
          Get the list of groups to join.
 LookupLocator[] getLookupLocators()
          Get the list of locators of specific lookup services to join.
 void modifyLookupAttributes(Entry[] attrSetTemplates, Entry[] attrSets)
          Modify the current attribute sets, using the same semantics as ServiceRegistration.modifyAttributes.
private  void prepareLocators(LookupLocator[] locators)
          Apply lookupLocatorPreparer to each locator in the array, replacing the original locator with the result of the prepareProxy call.
private static RuntimeException propagateIOException(String msg, IOException nested)
          Propagate an IOException by wrapping it in a RuntimeException.
private static Entry[] readAttributes(ObjectInputStream in)
          Utility method to read in an array of entities from a ObjectInputStream.
 void removeLookupGroups(String[] groups)
          Remove groups from the set to join.
 void removeLookupLocators(LookupLocator[] locators)
          Remove locators for specific lookup services from the set to join.
 void restore(ObjectInputStream in)
          Restore the persistent fields
 void setLookupGroups(String[] groups)
          Replace the list of groups to join with a new list.
 void setLookupLocators(LookupLocator[] locators)
          Replace the list of locators of specific lookup services to join with a new list.
(package private)  void startManager(Configuration config, LogOps log, Object service, ServiceID serviceID, Entry[] baseAttributes)
          Start the manager.
 void store(ObjectOutputStream out)
          Store the persistent fields
private static ConfigurationException throwNewConfigurationException(String msg)
          Construct, log, and throw a new ConfigurationException with the given message.
private  void update()
           
private static void writeAttributes(Entry[] attributes, ObjectOutputStream out)
          Utility method to write out an array of entities to an ObjectOutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lookupLocatorPreparer

private ProxyPreparer lookupLocatorPreparer
ProxyPreparer for LookupLocators


dgm

private DiscoveryGroupManagement dgm
Object used to find lookups. Has to implement DiscoveryManagement and DiscoveryLocatorManagement as well as DiscoveryGroupManagement.


mgr

private JoinManager mgr
JoinManager that is handling the details of binding into Jini lookup services.


log

private LogOps log
The object that is coordinating our persistent state.


attributes

private Entry[] attributes
The list of attributes to start with. This field is only used to carry data from the restore method to the startManager method. The current set of attributes is kept by mgr. This field is nulled out by startManager.


locators

private LookupLocator[] locators
The list of LookupLocators to start with. This field is only used to carry data from the restore method to the startManager method. The current set of attributes is kept by mgr. This field is nulled out by startManager.


groups

private String[] groups
The list of group names to start with. This field is only used to carry data from the restore method to the startManager method. The current set of attributes is kept by mgr. This field is nulled out by startManager.


initial

private boolean initial
Conceptually, true if this is the first time this service has come up, implemented as if there was no previous state then this is the first time.


logger

private static final Logger logger
Logger for logging join related information

Constructor Detail

JoinStateManager

JoinStateManager()
Simple constructor.

Method Detail

startManager

void startManager(Configuration config,
                  LogOps log,
                  Object service,
                  ServiceID serviceID,
                  Entry[] baseAttributes)
            throws IOException,
                   ConfigurationException
Start the manager. Start looking for lookup and registering with them.

Parameters:
config - object to use to obtain DiscoveryManagement object, and if this is the initial incarnation of this service, the object used to get the initial set of groups, locators, and deployer defined attributes.
log - object used to persist the manager's state, may be null.
serviceID - The ServiceID to register under.
service - The proxy object to register with lookups.
baseAttributes - Any attributes the implementation wants attached, only used if this is the initial incarnation.
Throws:
IOException - if the is problem persisting the initial state or in starting discovery.
ConfigurationException - if the configuration is invalid.
NullPointerException - if config, or serviceID is null.

destroy

public void destroy()
Make a good faith attempt to terminate discovery, and cancel any lookup registrations.


getLookupAttributes

public Entry[] getLookupAttributes()
Get the current attribute sets for the service.

Returns:
the current attribute sets for the service

addLookupAttributes

public void addLookupAttributes(Entry[] attrSets)
Add attribute sets for the service. The resulting set will be used for all future joins. The attribute sets are also added to all currently-joined lookup services.

Parameters:
attrSets - the attribute sets to add
Throws:
java.rmi.RuntimeException - if the change can not be persisted.

modifyLookupAttributes

public void modifyLookupAttributes(Entry[] attrSetTemplates,
                                   Entry[] attrSets)
Modify the current attribute sets, using the same semantics as ServiceRegistration.modifyAttributes. The resulting set will be used for all future joins. The same modifications are also made to all currently-joined lookup services.

Parameters:
attrSetTemplates - the templates for matching attribute sets
attrSets - the modifications to make to matching sets
Throws:
java.rmi.RuntimeException - if the change can not be persisted.
See Also:
ServiceRegistration.modifyAttributes(net.jini.core.entry.Entry[], net.jini.core.entry.Entry[])

getLookupGroups

public String[] getLookupGroups()
Get the list of groups to join. An empty array means the service joins no groups (as opposed to "all" groups).

Returns:
an array of groups to join. An empty array means the service joins no groups (as opposed to "all" groups).
See Also:
setLookupGroups(java.lang.String[])

addLookupGroups

public void addLookupGroups(String[] groups)
Add new groups to the set to join. Lookup services in the new groups will be discovered and joined.

Parameters:
groups - groups to join
Throws:
java.rmi.RuntimeException - if the change can not be persisted.
See Also:
removeLookupGroups(java.lang.String[])

removeLookupGroups

public void removeLookupGroups(String[] groups)
Remove groups from the set to join. Leases are cancelled at lookup services that are not members of any of the remaining groups.

Parameters:
groups - groups to leave
Throws:
java.rmi.RuntimeException - if the change can not be persisted.
See Also:
addLookupGroups(java.lang.String[])

setLookupGroups

public void setLookupGroups(String[] groups)
Replace the list of groups to join with a new list. Leases are cancelled at lookup services that are not members of any of the new groups. Lookup services in the new groups will be discovered and joined.

Parameters:
groups - groups to join
Throws:
java.rmi.RuntimeException - if the change can not be persisted.
See Also:
getLookupGroups()

getLookupLocators

public LookupLocator[] getLookupLocators()
Get the list of locators of specific lookup services to join.

Returns:
the list of locators of specific lookup services to join
See Also:
setLookupLocators(net.jini.core.discovery.LookupLocator[])

addLookupLocators

public void addLookupLocators(LookupLocator[] locators)
                       throws RemoteException
Add locators for specific new lookup services to join. The new lookup services will be discovered and joined.

Parameters:
locators - locators of specific lookup services to join
Throws:
java.rmi.RuntimeException - if the change can not be persisted.
RemoteException
See Also:
removeLookupLocators(net.jini.core.discovery.LookupLocator[])

removeLookupLocators

public void removeLookupLocators(LookupLocator[] locators)
                          throws RemoteException
Remove locators for specific lookup services from the set to join. Any leases held at the lookup services are cancelled.

Parameters:
locators - locators of specific lookup services to leave
Throws:
java.rmi.RuntimeException - if the change can not be persisted.
RemoteException
See Also:
addLookupLocators(net.jini.core.discovery.LookupLocator[])

setLookupLocators

public void setLookupLocators(LookupLocator[] locators)
                       throws RemoteException
Replace the list of locators of specific lookup services to join with a new list. Leases are cancelled at lookup services that were in the old list but are not in the new list. Any new lookup services will be discovered and joined.

Parameters:
locators - locators of specific lookup services to join
Throws:
java.rmi.RuntimeException - if the change can not be persisted.
RemoteException
See Also:
getLookupLocators()

update

private void update()

prepareLocators

private void prepareLocators(LookupLocator[] locators)
                      throws RemoteException
Apply lookupLocatorPreparer to each locator in the array, replacing the original locator with the result of the prepareProxy call. If call fails with an exception throw that exception.

Parameters:
locators - the LookupLocators to be prepared.
Throws:
RemoteException - if preparation of any of the locators does.
SecurityException - if preparation of any of the locators does.

writeAttributes

private static void writeAttributes(Entry[] attributes,
                                    ObjectOutputStream out)
                             throws IOException
Utility method to write out an array of entities to an ObjectOutputStream. Can be recovered by a call to readAttributes()

Packages each attribute in its own MarshalledObject so a bad codebase on an attribute class will not corrupt the whole array.

Throws:
IOException

readAttributes

private static Entry[] readAttributes(ObjectInputStream in)
                               throws IOException,
                                      ClassNotFoundException
Utility method to read in an array of entities from a ObjectInputStream. Array should have been written by a call to writeAttributes()

Will try and recover as many attributes as possible. Attributes which can't be recovered won't be returned but they will remain in the log.

Throws:
IOException
ClassNotFoundException

store

public void store(ObjectOutputStream out)
           throws IOException
Description copied from interface: StorableObject
Store the persistent fields

Specified by:
store in interface StorableObject
Throws:
IOException

restore

public void restore(ObjectInputStream in)
             throws IOException,
                    ClassNotFoundException
Description copied from interface: StorableObject
Restore the persistent fields

Specified by:
restore in interface StorableObject
Throws:
IOException
ClassNotFoundException

throwNewConfigurationException

private static ConfigurationException throwNewConfigurationException(String msg)
                                                              throws ConfigurationException
Construct, log, and throw a new ConfigurationException with the given message.

Throws:
ConfigurationException

propagateIOException

private static RuntimeException propagateIOException(String msg,
                                                     IOException nested)
Propagate an IOException by wrapping it in a RuntimeException. Performs appropriate logging.



Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.