public class JoinState extends LogHandler implements SubStore
JoinManager
with persistence.Modifier and Type | Field and Description |
---|---|
private Entry[] |
attributes
Pass through to get attribute array from the log recovery method
to the code that creates the
JoinManager |
private Configuration |
config
Configuration, to supply initial attributes, groups, and locators
|
private DiscoveryManagement |
dm
The
DiscoveryManagement we are using to find lookups, which
must also implement DiscoveryGroupManagement and
DiscoveryLocatorManagement . |
private String[] |
groups
Pass through to get lookup group array from the log
recovery method to the code that creates the
JoinManager |
private JoinManager |
joinMgr
Our join manager
|
private LookupLocator[] |
locators
Pass through to get lookup locator array from the log
recovery method to the code that creates the
JoinManager |
private ReliableLog |
log
Log we are using to persist our state to disk, or null if not
persistent.
|
private static Logger |
logger
Logger for logging messages
|
private LeaseRenewalManager |
lrm
Lease renewal manager (if any) that the client wants our
JoinManager to use. |
private static String |
NORM
Logger and configuration component name for Norm
|
private boolean |
recoveredData
Set to true if there was existing persistent data that was recovered --
used to determine if the JoinState is being created for the first time.
|
private ProxyPreparer |
recoveredLookupLocatorPreparer
Proxy preparer for recovered lookup locators
|
(package private) Object |
service
Service we are registering with lookup services
|
private Entry[] |
serviceAttributes
Attributes supplied by the service
|
private ServiceID |
serviceID
The service ID, derived from the service's UUID.
|
Constructor and Description |
---|
JoinState(Object service,
LeaseRenewalManager lrm,
Configuration config,
Entry[] serviceAttributes,
ProxyPreparer recoveredLookupLocatorPreparer,
ServiceID serviceID)
Simple constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttributes(Entry[] attrSets,
boolean checkSC)
Add attribute sets for the service.
|
void |
addGroups(String[] groups)
Add new groups to the set to join.
|
void |
addLocators(LookupLocator[] locators)
Add locators for specific new lookup services to join.
|
void |
applyUpdate(Object update)
This method always throws
UnsupportedOperationException
since JoinState should never update a log. |
private void |
createDiscoveryManager()
Creates the discovery manager.
|
private Object[] |
getArrayEntry(String name,
Class type,
Object defaultValue)
Returns a configuration entry that is an array of objects, checking that
all the elements of the array are non-null.
|
Entry[] |
getAttributes()
Get the current attribute sets for the service.
|
String[] |
getGroups()
Get the list of groups to join.
|
private void |
getInitialEntries()
Retrieves the initial values for attributes, groups, and locators from
the configuration.
|
LookupLocator[] |
getLocators()
Get the list of locators of specific lookup services to join.
|
private static void |
logThrow(Level level,
String method,
String msg,
Object[] msgParams,
Throwable t)
Logs a throw
|
void |
modifyAttributes(Entry[] attrSetTemplates,
Entry[] attrSets,
boolean checkSC)
Modify the current attribute sets, using the same semantics as
ServiceRegistration.modifyAttributes.
|
void |
prepareDestroy()
Informs the
SubStore that the service is being destroyed
and it should perform any necessary cleanup (closing files for example). |
private static Entry[] |
readAttributes(ObjectInputStream in)
Utility method to read in an array of entities from a
ObjectInputStream . |
void |
recover(InputStream in)
Read the snapshot from a stream.
|
void |
removeGroups(String[] groups)
Remove groups from the set to join.
|
void |
removeLocators(LookupLocator[] locators)
Remove locators for specific lookup services from the set to join.
|
void |
setDirectory(File dir)
Gives the
SubStore a piece of the file system to
use for its store. |
void |
setGroups(String[] groups)
Replace the list of groups to join with a new list.
|
void |
setLocators(LookupLocator[] locators)
Replace the list of locators of specific lookup services to join
with a new list.
|
void |
snapshot(OutputStream out)
Writes the snapshot to a stream.
|
String |
subDirectory()
If this components wants its own sub-directory, it should return
a non-
null string that will be its sub-directory's name. |
private void |
takeSnapshot()
Used by all the methods that change persistent state to
commit the change to disk
|
void |
terminateJoin()
Terminate our participation in the Join and discovery
Protocols.
|
private static void |
writeAttributes(Entry[] attributes,
ObjectOutputStream out)
Utility method to write out an array of entities to an
ObjectOutputStream . |
readUpdate, writeUpdate
private static final String NORM
private static final Logger logger
final Object service
private final LeaseRenewalManager lrm
JoinManager
to use.private final Configuration config
private final Entry[] serviceAttributes
private final ProxyPreparer recoveredLookupLocatorPreparer
private final ServiceID serviceID
private ReliableLog log
private boolean recoveredData
private Entry[] attributes
JoinManager
private String[] groups
JoinManager
private LookupLocator[] locators
JoinManager
private DiscoveryManagement dm
DiscoveryManagement
we are using to find lookups, which
must also implement DiscoveryGroupManagement
and
DiscoveryLocatorManagement
.private JoinManager joinMgr
public JoinState(Object service, LeaseRenewalManager lrm, Configuration config, Entry[] serviceAttributes, ProxyPreparer recoveredLookupLocatorPreparer, ServiceID serviceID) throws IOException
service
- the object to register with lookuplrm
- a LeaseRenewalManager
to pass to the
JoinManager
. May be null
.config
- a configuration that supplies initial attributes, groups,
and locatorsserviceAttributes
- attributes supplied by the servicerecoveredLookupLocatorPreparer
- proxy preparer for recovered
lookup locatorsserviceID
- the service ID for the serviceIOException
public String subDirectory()
SubStore
null
string that will be its sub-directory's name.
If it does not need its own sub-directory this method should return
null
.subDirectory
in interface SubStore
public void setDirectory(File dir) throws IOException, ConfigurationException
SubStore
SubStore
a piece of the file system to
use for its store.setDirectory
in interface SubStore
dir
- the directory to useIOException
- if there is a problem initializing its store
or recovering its stateConfigurationException
- if this is a problem configuring this
objectprivate static void logThrow(Level level, String method, String msg, Object[] msgParams, Throwable t)
private Object[] getArrayEntry(String name, Class type, Object defaultValue) throws ConfigurationException
ConfigurationException
private void getInitialEntries() throws ConfigurationException
ConfigurationException
private void createDiscoveryManager() throws ConfigurationException, IOException
ConfigurationException
IOException
public void prepareDestroy()
SubStore
SubStore
that the service is being destroyed
and it should perform any necessary cleanup (closing files for example).
The store does not need to delete it's data.prepareDestroy
in interface SubStore
public void terminateJoin()
public void snapshot(OutputStream out) throws IOException
LogHandler
snapshot
in class LogHandler
out
- the output streamIOException
public void recover(InputStream in) throws Exception
LogHandler
recover
in class LogHandler
in
- the input streamException
- can raise any exceptionpublic void applyUpdate(Object update) throws Exception
UnsupportedOperationException
since JoinState
should never update a log.applyUpdate
in class LogHandler
update
- the update objectException
- can raise any exceptionprivate 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 (though they will be lost when the next snapshot is taken).
IOException
ClassNotFoundException
private void takeSnapshot() throws IOException
IOException
public String[] getGroups()
public void addGroups(String[] groups)
groups
- groups to joinpublic void removeGroups(String[] groups)
groups
- groups to leavepublic void setGroups(String[] groups)
groups
- groups to joinpublic LookupLocator[] getLocators()
public void addLocators(LookupLocator[] locators)
locators
- locators of specific lookup services to joinpublic void removeLocators(LookupLocator[] locators)
locators
- locators of specific lookup services to leavepublic void setLocators(LookupLocator[] locators)
locators
- locators of specific lookup services to joinpublic Entry[] getAttributes()
public void addAttributes(Entry[] attrSets, boolean checkSC)
attrSets
- the attribute sets to addcheckSC
- boolean
flag indicating whether the
elements of the set of attributes to add should be
checked to determine if they are service controlledSecurityException
- when the checkSC
parameter is
true
, and at least one of the attributes to be
added is an instance of the ServiceControlled
marker interfacepublic void modifyAttributes(Entry[] attrSetTemplates, Entry[] attrSets, boolean checkSC)
attrSetTemplates
- the templates for matching attribute setsattrSets
- the modifications to make to matching setscheckSC
- boolean
flag indicating whether
elements of the set of attributes to add should be checked
to determine if they are service controlledSecurityException
- when the checkSC
parameter
is true
, and at least one of the attributes
to be added is an instance of the
ServiceControlled
marker interfaceServiceRegistration.modifyAttributes(net.jini.core.entry.Entry[], net.jini.core.entry.Entry[])
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.