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.JoinManager
Modifier and Type | Field and Description |
---|---|
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
LookupLocator s 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 and Description |
---|
JoinStateManager()
Simple constructor.
|
Modifier and Type | Method and Description |
---|---|
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 . |
private ProxyPreparer lookupLocatorPreparer
ProxyPreparer
for LookupLocators
private DiscoveryGroupManagement dgm
private JoinManager mgr
JoinManager
that is handling the details of binding
into Jini lookup services.private LogOps log
private Entry[] attributes
restore
method to the
startManager
method. The current set of attributes
is kept by mgr
. This field is nulled out by
startManager
.private LookupLocator[] locators
LookupLocator
s 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
.private String[] groups
restore
method to the
startManager
method. The current set of attributes
is kept by mgr
. This field is nulled out by
startManager
.private boolean initial
private static final Logger logger
void startManager(Configuration config, LogOps log, Object service, ServiceID serviceID, Entry[] baseAttributes) throws IOException, ConfigurationException
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.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
.public void destroy()
public Entry[] getLookupAttributes()
public void addLookupAttributes(Entry[] attrSets)
attrSets
- the attribute sets to addjava.rmi.RuntimeException
- if the change can not be persisted.public void modifyLookupAttributes(Entry[] attrSetTemplates, Entry[] attrSets)
attrSetTemplates
- the templates for matching attribute setsattrSets
- the modifications to make to matching setsjava.rmi.RuntimeException
- if the change can not be persisted.ServiceRegistration.modifyAttributes(net.jini.core.entry.Entry[], net.jini.core.entry.Entry[])
public String[] getLookupGroups()
setLookupGroups(java.lang.String[])
public void addLookupGroups(String[] groups)
groups
- groups to joinjava.rmi.RuntimeException
- if the change can not be persisted.removeLookupGroups(java.lang.String[])
public void removeLookupGroups(String[] groups)
groups
- groups to leavejava.rmi.RuntimeException
- if the change can not be persisted.addLookupGroups(java.lang.String[])
public void setLookupGroups(String[] groups)
groups
- groups to joinjava.rmi.RuntimeException
- if the change can not be persisted.getLookupGroups()
public LookupLocator[] getLookupLocators()
setLookupLocators(net.jini.core.discovery.LookupLocator[])
public void addLookupLocators(LookupLocator[] locators) throws RemoteException
locators
- locators of specific lookup services to joinjava.rmi.RuntimeException
- if the change can not be persisted.RemoteException
removeLookupLocators(net.jini.core.discovery.LookupLocator[])
public void removeLookupLocators(LookupLocator[] locators) throws RemoteException
locators
- locators of specific lookup services to leavejava.rmi.RuntimeException
- if the change can not be persisted.RemoteException
addLookupLocators(net.jini.core.discovery.LookupLocator[])
public void setLookupLocators(LookupLocator[] locators) throws RemoteException
locators
- locators of specific lookup services to joinjava.rmi.RuntimeException
- if the change can not be persisted.RemoteException
getLookupLocators()
private void update()
private void prepareLocators(LookupLocator[] locators) throws RemoteException
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.locators
- the LookupLocator
s to be prepared.RemoteException
- if preparation of any of the locators
does.SecurityException
- if preparation of any of the locators
does.private static void writeAttributes(Entry[] attributes, ObjectOutputStream out) throws IOException
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.
IOException
private static Entry[] readAttributes(ObjectInputStream in) throws IOException, ClassNotFoundException
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.
IOException
ClassNotFoundException
public void store(ObjectOutputStream out) throws IOException
StorableObject
store
in interface StorableObject
IOException
public void restore(ObjectInputStream in) throws IOException, ClassNotFoundException
StorableObject
restore
in interface StorableObject
IOException
ClassNotFoundException
private static ConfigurationException throwNewConfigurationException(String msg) throws ConfigurationException
ConfigurationException
private static RuntimeException propagateIOException(String msg, IOException nested)
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.