* and DiscoveryLocatorManagement, and should be initially configured
* to discover NO_GROUPS and NO LOCATORS. This discovery manager is
* retrieved from the configuration after recovery of any persistent
* state, and after retrieval of any initial configuration items.
*/
discoveryMgr = new LookupDiscoveryManager
(DiscoveryGroupManagement.NO_GROUPS,
new LookupLocator[0],
null,
config);
/* Get the proxy preparers for the remote event listeners */
listenerPreparer = (ProxyPreparer)Config.getNonNullEntry
(config,
COMPONENT_NAME,
"listenerPreparer",
ProxyPreparer.class,
new BasicProxyPreparer());
/* Get the proxy preparers for the lookup locators to join */
locatorToJoinPreparer = (ProxyPreparer)Config.getNonNullEntry
(config,
COMPONENT_NAME,
"locatorToJoinPreparer",
ProxyPreparer.class,
new BasicProxyPreparer());
/* Get the proxy preparers for the lookup locators to discover */
locatorToDiscoverPreparer = (ProxyPreparer)Config.getNonNullEntry
(config,
COMPONENT_NAME,
"locatorToDiscoverPreparer",
ProxyPreparer.class,
new BasicProxyPreparer());
if(persistent) {
/* Retrieve the proxy preparers that will only be applied during
* the state recovery process below, when any previously stored
* listeners or locators are recovered from persistent storage.
*/
recoveredListenerPreparer =
(ProxyPreparer)Config.getNonNullEntry(config,
COMPONENT_NAME,
"recoveredListenerPreparer",
ProxyPreparer.class,
new BasicProxyPreparer());
recoveredLocatorToJoinPreparer =
(ProxyPreparer)Config.getNonNullEntry
(config,
COMPONENT_NAME,
"recoveredLocatorToJoinPreparer",
ProxyPreparer.class,
new BasicProxyPreparer());
recoveredLocatorToDiscoverPreparer =
(ProxyPreparer)Config.getNonNullEntry
(config,
COMPONENT_NAME,
"recoveredLocatorToDiscoverPreparer",
ProxyPreparer.class,
new BasicProxyPreparer());
/* Get the log directory for persisting this service's state */
persistDir = (String)Config.getNonNullEntry(config,
COMPONENT_NAME,
"persistenceDirectory",
String.class);
/* Recover the state that was persisted on prior runs (if any) */
log = new ReliableLog(persistDir, new LocalLogHandler());
inRecovery = true;
log.recover();
inRecovery = false;
}//endif(persistent)
/* For the two persistent versions of this service (activatable and
* non-activatable), state recovery is complete. For the non-persistent
* version of this service, no state recovery occurred (because it
* wasn't necessary).
*
* For the two persistent versions, there is a circumstance in which
* 'one time', initial items must be retrieved from the configuration:
* when the service is started for the very first time. For the
* non-persistent version, those items will be retrieved every time
* the service is started.
*
* The flag 'initialStartup' is used below to determine whether
* or not to retrieve the initial configuration items. This is the
* only purpose for that flag.
*
* For either persistent version of the service, the flag's value
* will be changed to false during the startup process only when
* there already exists a 'snapshot' of the service's state from
* a previous run. This is because the flag's value is only
* changed during the recovery of the snapshot (see the method
* recoverSnapshot()). Note that the only time such a snapshot
* should NOT already exist at startup, is when the service is
* being started for the very first time. Thus, when either
* persistent version of the service is started for the first
* time, the service's configuration is consulted for the initial
* values of the items below; otherwise, when the service is being
* re-started (after a crash for example), the values used for
* those items will be the values retrieved above during recovery
* of the service's persistent state.
*
* With respect to the non-persistent version of the service, the
* values of the items below will always be retrieved at startup.
* This is because the non-persistent version of the service never
* attempts to recover previously stored state; thus, the flag's
* value will never change. Note that this will be true even if a
* snapshot exists from a previous run of one of the persistent
* versions of the service.
*
* The service's Uuid is also handled here.
*/
if(initialStartup) {
if(log != null) {
snapshotWt = ((Float)config.getEntry
(COMPONENT_NAME,
"initialPersistenceSnapshotWeight",
float.class,
new Float(snapshotWt))).floatValue();
snapshotThresh =
Config.getIntEntry
(config,
COMPONENT_NAME,
"initialPersistenceSnapshotThreshold",
snapshotThresh, 0, Integer.MAX_VALUE);
}//endif(log != null)
leaseBound = Config.getLongEntry(config,
COMPONENT_NAME,
"initialLeaseBound",
leaseBound, 0, Long.MAX_VALUE);
/* Get any additional attributes with which to associate this
* service when registering it with any lookup services.
*/
Entry[] initAttrs = (Entry[])config.getEntry
(COMPONENT_NAME,
"initialLookupAttributes",
Entry[].class,
null );
if(initAttrs != null) {
ArrayList attrsList
= new ArrayList(thisServicesAttrs.length+initAttrs.length);
for(int i=0;i<thisServicesAttrs.length;i++) {
attrsList.add(thisServicesAttrs[i]);
}//end loop
for(int i=0;i<initAttrs.length;i++) {
attrsList.add(initAttrs[i]);
}//end loop
thisServicesAttrs = (Entry[])attrsList.toArray
(new Entry[attrsList.size()]);
}//endif(initAttrs != null)
/* Get the initial groups this service should join. */
thisServicesGroups =
(String[])config.getEntry(COMPONENT_NAME,
"initialLookupGroups",
String[].class,
thisServicesGroups);
/* Get the initial locators this service should join. */
thisServicesLocators =
(LookupLocator[])config.getEntry(COMPONENT_NAME,
"initialLookupLocators",
LookupLocator[].class,
new LookupLocator[0]);
if(thisServicesLocators == null) {
thisServicesLocators = new LookupLocator[0];
}//endif
/* Generate the private, universally unique (over space and time)
* ID that will be used by the outer proxy to test for equality
* with other proxies.
*/
proxyID = UuidFactory.generate();
}//endif(initialStartup)
/* The proxyID should never be null at this point. It should have
* been either recovered from the persisted state, or generated above.
*/
if(proxyID == null) throw new NullPointerException("proxyID == null");
/* Get the various configurable constants */
leaseMax = Config.getLongEntry(config,
COMPONENT_NAME,
"leaseMax",
leaseMax, 0, Long.MAX_VALUE);
/* Take a snapshot of the current state to "clean up" the log file,
* and to record the items set above.
*/
if(log != null) log.snapshot();
/* The service ID used to register this service with lookup services
* is always derived from the proxyID that is associated with the
* service for the lifetime of the service.
*/
serviceID = new ServiceID(proxyID.getMostSignificantBits(),
proxyID.getLeastSignificantBits());
/* Get a general-purpose task manager for this service */
taskMgr = (TaskManager)Config.getNonNullEntry
(config,
COMPONENT_NAME,
"taskManager",
TaskManager.class,
new TaskManager(10,1000*15,1.0f) );
/* Get the discovery manager to pass to this service's join manager. */
try {
joinMgrLDM =
(DiscoveryManagement)Config.getNonNullEntry
(config,
COMPONENT_NAME,
"discoveryManager",
DiscoveryManagement.class);
if( joinMgrLDM instanceof DiscoveryGroupManagement ) {
String[] groups0 =
((DiscoveryGroupManagement)joinMgrLDM).getGroups();
if( (groups0 == DiscoveryGroupManagement.ALL_GROUPS)
|| (groups0.length != 0) )
{
throw new ConfigurationException
("discoveryManager entry must be configured "
+"to initially discover/join NO_GROUPS");
}//endif
} else {// !(joinMgrLDM instanceof DiscoveryGroupManagement)
throw new ConfigurationException
("discoveryManager entry must "
+"implement DiscoveryGroupManagement");
}//endif
if( joinMgrLDM instanceof DiscoveryLocatorManagement ) {
LookupLocator[] locs0 =
((DiscoveryLocatorManagement)joinMgrLDM).getLocators();
if( (locs0 != null) && (locs0.length != 0) ) {
throw new ConfigurationException
("discoveryManager entry must be configured "
+"to initially discover/join no locators");
}//endif
} else {// !(joinMgrLDM instanceof DiscoveryLocatorManagement)
throw new ConfigurationException
("discoveryManager entry must "
+"implement DiscoveryLocatorManagement");
}//endif
} catch (NoSuchEntryException e) {
joinMgrLDM
= new LookupDiscoveryManager(DiscoveryGroupManagement.NO_GROUPS,
new LookupLocator[0], null,config);
}
/* Handle items and duties related to exporting this service. */
ServerEndpoint endpoint = TcpServerEndpoint.getInstance(0);