com.sun.jini.mahalo
Class JoinStateManager

java.lang.Object
  extended by com.sun.jini.reliableLog.LogHandler
      extended by com.sun.jini.mahalo.JoinStateManager

 class JoinStateManager
extends LogHandler

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:
ServiceIDListener, LogHandler

Field Summary
private  Entry[] attributes
          The join state, this data needs to be persisted between restarts
private  DiscoveryManagement dm
          Object used to find lookups.
private  String[] groups
           
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 static Logger initlogger
          Logger for logging initialization related messages
private  LookupLocator[] locators
           
private  ReliableLog log
          The object coordinating our persistent state.
private  ProxyPreparer lookupLocatorPreparer
          ProxyPreparer for LookupLocators
private  JoinManager mgr
          JoinManager that is handling the details of binding into Jini lookup services.
private static Logger operationsLogger
          Logger for logging operations related messages
private static Logger persistenceLogger
          Logger for transaction persistence related messages
private  Uuid serviceUuid
          Service's internal Uuid which needs to be persisted
 
Constructor Summary
JoinStateManager(String logPath)
          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 applyUpdate(Object update)
          This method always throws UnsupportedOperationException since FileJoinAdminState should never update a log.
 void destroy()
           
 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.
 Uuid getServiceUuid()
           
 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 Entry[] readAttributes(ObjectInput in)
          Utility method to read in an array of entities from a ObjectInputStream.
(package private)  void recover()
           
 void recover(InputStream in)
          Read the snapshot from a stream.
 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 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.
 void setServiceUuid(Uuid serviceUuid)
           
 void snapshot(OutputStream out)
          Writes the snapshot to a stream.
(package private)  void startManager(Configuration config, Object service, ServiceID serviceID, Entry[] baseAttributes)
          Start the manager.
 void stop()
          Make a good faith attempt to terminate discovery, and cancel any lookup registrations.
private  void update()
           
private static void writeAttributes(Entry[] attributes, ObjectOutput out)
          Utility method to write out an array of entities to an ObjectOutputStream.
 
Methods inherited from class com.sun.jini.reliableLog.LogHandler
readUpdate, writeUpdate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

initlogger

private static final Logger initlogger
Logger for logging initialization related messages


operationsLogger

private static final Logger operationsLogger
Logger for logging operations related messages


persistenceLogger

private static final Logger persistenceLogger
Logger for transaction persistence related messages


lookupLocatorPreparer

private ProxyPreparer lookupLocatorPreparer
ProxyPreparer for LookupLocators


dm

private DiscoveryManagement dm
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 ReliableLog log
The object coordinating our persistent state.


attributes

private Entry[] attributes
The join state, this data needs to be persisted between restarts


locators

private LookupLocator[] locators

groups

private String[] groups

serviceUuid

private Uuid serviceUuid
Service's internal Uuid which needs to be persisted


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.

Constructor Detail

JoinStateManager

JoinStateManager(String logPath)
           throws IOException
Simple constructor.

Throws:
IOException
Method Detail

recover

void recover()
       throws IOException
Throws:
IOException

startManager

void startManager(Configuration config,
                  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.
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.

setServiceUuid

public void setServiceUuid(Uuid serviceUuid)

getServiceUuid

public Uuid getServiceUuid()

stop

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


destroy

public void destroy()

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()

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.

update

private void update()

writeAttributes

private static void writeAttributes(Entry[] attributes,
                                    ObjectOutput 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(ObjectInput 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

snapshot

public void snapshot(OutputStream out)
              throws IOException
Description copied from class: LogHandler
Writes the snapshot to a stream. This callback is invoked when the client calls the snaphot method of ReliableLog.

Specified by:
snapshot in class LogHandler
Parameters:
out - the output stream
Throws:
IOException

recover

public void recover(InputStream in)
             throws Exception
Description copied from class: LogHandler
Read the snapshot from a stream. This callback is invoked when the client calls the recover method of ReliableLog.

Specified by:
recover in class LogHandler
Parameters:
in - the input stream
Throws:
Exception - can raise any exception

applyUpdate

public void applyUpdate(Object update)
                 throws Exception
This method always throws UnsupportedOperationException since FileJoinAdminState should never update a log.

Specified by:
applyUpdate in class LogHandler
Parameters:
update - the update object
Throws:
Exception - can raise any exception


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