abstract class NormServerBaseImpl extends Object implements NormServer, LocalLandlord, ServerProxyTrust, ProxyAccessor, Startable
| Modifier and Type | Class and Description |
|---|---|
private static class |
NormServerBaseImpl.CountLeases
Keeps track of the number of leases.
|
private class |
NormServerBaseImpl.DestroyThread
Termination thread code.
|
(package private) static class |
NormServerBaseImpl.InitException
Simple container for an alternative return a value so we
can provide more detailed diagnostics.
|
private class |
NormServerBaseImpl.OurLogHandler
Implementation of
LogHandler used by NormServerBaseImpl |
private static class |
NormServerBaseImpl.ReadyState
Prevents access to the service before it is ready or after it starts to
shutdown.
|
(package private) static class |
NormServerBaseImpl.RenewLogThread |
private class |
NormServerBaseImpl.SendMonitorImpl
The implementation of
SendMonitor we use to track
event delivery threads. |
(package private) class |
NormServerBaseImpl.SnapshotThread
Thread that performs the actual snapshots, done in a separate thread
so it will not hang up in-progress remote calls
|
Landlord.RenewResults| Modifier and Type | Field and Description |
|---|---|
private AdminProxy |
adminProxy
Admin proxy
|
private Configuration |
config |
private AccessControlContext |
context
Fields access only by thread that called constructor, then called start()
set to null at completion of start()
|
private NormServerBaseImpl.CountLeases |
countLeases
Keep track of the number of leases.
|
private static int |
CURRENT_LOG_VERSION
Current version of log format
|
private LeaseExpirationMgr |
expMgr
Object that expires sets and generates expiration warning events
|
(package private) Exporter |
exporter
The exporter for exporting and unexporting
|
private EventTypeGenerator |
generator
Object used to generate new event types
|
private UIDGenerator |
idGen
Factory we use to create ClientLeaseWrapper IDs
|
private boolean |
isolateSets
Whether to isolate leases in their own renewal sets as opposed to
batching leases across sets.
|
private JoinState |
joinState
Our JoinManager
|
private LeaseFactory |
leaseFactory
Factory for creating leases
|
private ProxyPreparer |
leasePreparer
Proxy preparer for leases supplied through the API
|
private LifeCycle |
lifeCycle
Object to notify when this service is destroyed, or null
|
private ProxyPreparer |
listenerPreparer
Proxy preparer for listeners supplied through the API
|
private ProxyPreparer |
locatorPreparer
Proxy preparer for lookup locators supplied through the API, and not
including initial lookup locators.
|
(package private) static Logger |
logger
Logger for logging information about this instance
|
(package private) LoginContext |
loginContext
The login context, for logging out
|
private int |
logToSnapshotThresh
Log file must contain this many records before snapshot allowed
|
private LeaseRenewalManager |
lrm
Lease renewal manager that actually renews the leases
|
private LRMEventListener |
lrmEventListener
Object that transfers events from the renewal manager to
us so we can remove dead leases and send events
|
(package private) static String |
NORM
Logger and configuration component name for Norm
|
(package private) LeaseRenewalService |
normProxy
Outer service proxy
|
(package private) String |
persistenceDirectory
The location of our persistent storage, or null if not persistent.
|
(package private) boolean |
persistent
Whether this server is persistent.
|
private NormServerBaseImpl.ReadyState |
ready
Lock protecting startup and shutdown
|
private ProxyPreparer |
recoveredLeasePreparer
Proxy preparer for leases recovered from persistent storage, or null if
not persistent.
|
private ProxyPreparer |
recoveredListenerPreparer
Proxy preparer for listeners recovered from persistent storage, or null
if not persistent.
|
private ProxyPreparer |
recoveredLocatorPreparer
Proxy preparer for lookup locators recovered from persistent storage, or
null if not persistent.
|
private List |
renewedList
List of leases that have been renewed but not persisted
|
private NormServerBaseImpl.RenewLogThread |
renewLogger
Thread that pulls wrapped client leases off the renewedList and logs
them to disk
|
(package private) NormServer |
serverProxy
Inner server proxy
|
private Uuid |
serverUuid
The unique ID for this server.
|
private LeasePeriodPolicy |
setLeasePolicy
Policy we use for granting and renewing renewal set leases
|
private Map<Uuid,LeaseSet> |
setTable
Map of Uuids to LeaseSets
|
private NormServerBaseImpl.SnapshotThread |
snapshotter
Thread that performs snapshots when signaled
|
private float |
snapshotWt
Weight factor applied to snapshotSize when deciding to take snapshot
|
private boolean |
started |
private PersistentStore |
store
Our persistant store
|
NO_LISTENER| Constructor and Description |
|---|
NormServerBaseImpl(NormServerInitializer init)
Creates an instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
add(LeaseSet set,
Lease leaseToRenew,
long membershipDuration,
long renewDuration)
Add the lease to the set.
|
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 |
cancel(Uuid cookie)
Called by the lease when its
cancel method is
called. |
Map |
cancelAll(Uuid[] cookies)
Called by the lease map when its
cancelAll method is called. |
LeaseRenewalSet |
createLeaseRenewalSet(long leaseDuration)
Create a new
LeaseRenewalSet that the client can
populate with leases to be renewed. |
(package private) void |
desiredExpirationReached(ClientLeaseWrapper clw)
Remove a lease that has reached its desired expiration.
|
void |
destroy()
Destroy the service, if possible, including its persistent storage.
|
private static void |
ensureCurrent(LeaseSet set)
Throw a NoSuchObjectException, wrapped in a ThrowThis, if the
passed set has expired.
|
(package private) void |
expireIfTime(LeaseSet set)
Remote a set if its expiration time has been reached.
|
Object |
getAdmin()
Returns an object that implements whatever administration interfaces
are appropriate for the particular service.
|
GetLeasesResult |
getLeases(Uuid id)
Return all the leases in the set.
|
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.
|
Object |
getProxy()
Returns a proxy object for this remote object.
|
TrustVerifier |
getProxyVerifier()
Returns a
TrustVerifier that can be used to verify that
a proxy can be trusted as a proxy for the service; that is, the
isTrustedObject method of the
returned verifier can be called with a candidate proxy. |
Object |
getServiceProxy()
Returns a proxy object for this object.
|
private LeaseSet |
getSet(Uuid id)
Return the set with the specified id, or throw a
NoSuchObjectException, wrapped in a ThrowThis if the set can't be found
|
(package private) static NormServerInitializer |
init(String[] configOptions,
NormServerInitializer init)
Portion of construction that is common between the activatable and not
activatable cases.
|
(package private) static void |
initFailed(Throwable e)
Log information about failing to initialize the service and rethrow the
appropriate exception.
|
private String |
inventory()
Return a string summarizing the inventory of the server
|
private static boolean |
isCurrent(LeaseSet set)
Returns true if the lease on the lease set is still current, else
false.
|
(package private) boolean |
isolateSets()
Returns whether to isolate renewal sets or batch lease across sets.
|
private static void |
logThrow(Level level,
String method,
String msg,
Object[] msgParams,
Throwable t)
Logs a throw
|
void |
modifyLookupAttributes(Entry[] attrSetTemplates,
Entry[] attrSets)
Modify the current attribute sets, using the same semantics as
ServiceRegistration.modifyAttributes.
|
(package private) SendMonitor |
newSendMonitor(LeaseSet set)
Create a new
SendMonitorImpl |
(package private) SetProxy |
newSetProxy(LeaseSet set)
Method used by
LeaseSet when it needs to cons up
a SetProxy with an up-to-date Lease. |
(package private) void |
postDestroy()
Method subclasses can override to perform any necessary post
log destruction cleanup.
|
Lease |
remove(Uuid id,
Lease leaseToRemove)
Remove a lease from a set.
|
private void |
removeClientLeases(Iterator deadLeases)
Method used to remove membership expired leases from the server.
|
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.
|
private void |
removeSet(LeaseSet set)
Do the heavy lifting on removing a set, assumes the locks on the
set and store have been acquired.
|
long |
renew(Uuid cookie,
long extension)
Called by the lease when its
renew method is called. |
(package private) void |
renewalFailure(ClientLeaseWrapper clw)
Handle failures to renew a lease by removing the lease from its set
and if needed schedule sending an event.
|
Landlord.RenewResults |
renewAll(Uuid[] cookies,
long[] extensions)
Called by the lease map when its
renewAll method is called. |
void |
renewFor(Uuid id,
Lease leaseToRenew,
long membershipDuration,
long renewDuration)
Add a lease to a set.
|
(package private) void |
restoreTransientState()
Perform the 3rd stage of log recovery, restoring the various pieces of
transient state (populating the LRM, restoring various transient
fields).
|
(package private) void |
sendWarningEvent(LeaseSet set)
Schedule the sending of an expiration warning event.
|
EventRegistration |
setExpirationWarningListener(Uuid id,
RemoteEventListener listener,
long minWarning,
MarshalledObject handback)
Set the expiration warning listener for a set.
|
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.
|
EventRegistration |
setRenewalFailureListener(Uuid id,
RemoteEventListener listener,
MarshalledObject handback)
Set the renewal failure listener for a set.
|
void |
start()
Called after construction, this method enables objects to delay
starting threads or exporting until after construction is complete,
to allow safe publication of the service in accordance with the JMM.
|
String |
toString()
Returns a string representation of this object.
|
private static String |
toString(Object[] array)
Returns the contents of an array as a string.
|
(package private) boolean |
unexport(boolean force)
Unexport our stub appropriately.
|
(package private) void |
updateLeaseCount(int change)
Update the number of leases being managed by this server.
|
(package private) void |
updatePerformed(int updateCount)
Called by
PersistentStore after every update to give
server a chance to trigger a snapshot. |
private static final int CURRENT_LOG_VERSION
static final String NORM
static final Logger logger
final boolean persistent
final LoginContext loginContext
final String persistenceDirectory
private final ProxyPreparer leasePreparer
private final ProxyPreparer recoveredLeasePreparer
private final ProxyPreparer listenerPreparer
private final ProxyPreparer recoveredListenerPreparer
private final ProxyPreparer locatorPreparer
private final ProxyPreparer recoveredLocatorPreparer
final Exporter exporter
private final LifeCycle lifeCycle
private volatile Uuid serverUuid
private volatile JoinState joinState
private final LeaseRenewalManager lrm
private final LeaseExpirationMgr expMgr
private volatile LeaseFactory leaseFactory
private final LeasePeriodPolicy setLeasePolicy
private final boolean isolateSets
private volatile PersistentStore store
private final UIDGenerator idGen
private final List renewedList
private final NormServerBaseImpl.RenewLogThread renewLogger
private volatile EventTypeGenerator generator
private final LRMEventListener lrmEventListener
private final int logToSnapshotThresh
private final float snapshotWt
volatile NormServer serverProxy
volatile LeaseRenewalService normProxy
private volatile AdminProxy adminProxy
private volatile NormServerBaseImpl.SnapshotThread snapshotter
private final NormServerBaseImpl.ReadyState ready
private final NormServerBaseImpl.CountLeases countLeases
private AccessControlContext context
private Configuration config
private boolean started
NormServerBaseImpl(NormServerInitializer init)
public void renewFor(Uuid id, Lease leaseToRenew, long membershipDuration, long renewDuration) throws RemoteException, ThrowThis
NormServerrenewFor in interface NormServerid - what set the lease should be added toleaseToRenew - the lease to be added to the setmembershipDuration - how long the lease should be in the setrenewDuration - how long the lease should be renewed for
each time it is renewedRemoteException - if a communication-related exception occursThrowThis - when another exception has to be thrown by the proxyvoid updateLeaseCount(int change)
private void add(LeaseSet set, Lease leaseToRenew, long membershipDuration, long renewDuration) throws ThrowThis
set - the LeaseSet to add the leaseToRenew toleaseToRenew - the lease the client wants managedmembershipDuration - the length of time the client
wants the lease managed forrenewDuration - the length of time the client want the
lease renewed for each time it is renewedThrowThis - if the set no longer existspublic Lease remove(Uuid id, Lease leaseToRemove) throws RemoteException, ThrowThis
NormServerremove in interface NormServerid - of set being operated onleaseToRemove - the lease to be removed from the setRemoteException - if a communication-related exception occursThrowThis - when another exception has to be thrown by the proxypublic GetLeasesResult getLeases(Uuid id) throws ThrowThis
NormServernull
or a zero-length array if there are no leases in the set.getLeases in interface NormServerid - of set being operated onMarshalledInstances,
one for each leaseThrowThis - when another exception has to be thrown by the proxypublic EventRegistration setExpirationWarningListener(Uuid id, RemoteEventListener listener, long minWarning, MarshalledObject handback) throws RemoteException, ThrowThis
NormServersetExpirationWarningListener in interface NormServerid - of set being operated onlistener - listener to be notified when this event occurs.
Pass null to clear the registration.minWarning - how long be for the lease on the set expires
should the event be sent. Ignored if listener
is null.handback - an object to be handed back to the listener when
the warning event occurs. Ignored if listener
is null.EventRegistration object for the new
registration if listener is
non-null and null otherwiseRemoteException - if a communication-related exception occursThrowThis - when another exception has to be thrown by the proxyvoid expireIfTime(LeaseSet set)
void sendWarningEvent(LeaseSet set)
public EventRegistration setRenewalFailureListener(Uuid id, RemoteEventListener listener, MarshalledObject handback) throws RemoteException, ThrowThis
NormServersetRenewalFailureListener in interface NormServerid - of set being operated onlistener - listener to be notified when this event occurs.
Pass null to clear the registration.handback - an object to be handed back to the listener when
the failure event occurs. Ignored if
listener is null.EventRegistration object for the new
registration if listener is
non-null and null otherwise.RemoteException - if a communication-related exception occursThrowThis - when another exception has to be thrown by the proxyvoid renewalFailure(ClientLeaseWrapper clw)
clw - the wrapped client lease for the lease that could not
be renewed. clw.isDeformed must be
false.void desiredExpirationReached(ClientLeaseWrapper clw)
clw - the wrapped client lease for the lease that we are done withprivate void removeClientLeases(Iterator deadLeases)
deadLeases - an iterator with the leases that have to be
removedprivate static void ensureCurrent(LeaseSet set) throws ThrowThis
ThrowThisprivate static boolean isCurrent(LeaseSet set)
private LeaseSet getSet(Uuid id) throws ThrowThis
ThrowThispublic LeaseRenewalSet createLeaseRenewalSet(long leaseDuration)
LeaseRenewalServiceLeaseRenewalSet that the client can
populate with leases to be renewed. The initial duration of the
lease granted on this set will be less than or equal to
leaseDuration.
Two calls to this method should never return objects that are equal.
createLeaseRenewalSet in interface LeaseRenewalServiceleaseDuration - requested lease duration in millisecondsLeaseRenewalSet in the renewal serviceSetProxy newSetProxy(LeaseSet set)
LeaseSet when it needs to cons up
a SetProxy with an up-to-date Lease. Assumes the appropriate
locks have been obtained.SendMonitor newSendMonitor(LeaseSet set)
SendMonitorImplpublic TrustVerifier getProxyVerifier()
ServerProxyTrustTrustVerifier that can be used to verify that
a proxy can be trusted as a proxy for the service; that is, the
isTrustedObject method of the
returned verifier can be called with a candidate proxy. The verifier
should be able to verify all proxies for the service, including
proxies for resources (such as leases and registrations).getProxyVerifier in interface ServerProxyTrustTrustVerifier that can be used to verify that
a proxy can be trusted as a proxy for the serviceUnsupportedOperationException - if the server proxy does not
implement both RemoteMethodControl and TrustEquivalencepublic long renew(Uuid cookie, long extension) throws UnknownLeaseException, LeaseDeniedException
Landlordrenew method is called.
Renews the lease that is associated with the given cookie.renew in interface Landlordrenew in interface LocalLandlordcookie - the Uuid associated with the lease who's
renew method was calledextension - argument passed to the renew callUnknownLeaseException - if landlord does not know about
a lease with the specified cookieLeaseDeniedException - if the landlord is unwilling to
renew the leasepublic void cancel(Uuid cookie) throws UnknownLeaseException
Landlordcancel method is
called. Cancels the lease that is associated with the given
cookie.cancel in interface Landlordcancel in interface LocalLandlordcookie - the Uuid associated with the lease who's
renew method was calledUnknownLeaseException - if landlord does not know about
a lease with the specified cookieprivate void removeSet(LeaseSet set)
public Landlord.RenewResults renewAll(Uuid[] cookies, long[] extensions)
LandlordrenewAll method is called. Should renew the lease that is
associated with each element of cookiesrenewAll in interface Landlordcookies - an array of Uuids, each universally and
uniquely identifying a lease granted by this
Landlordextensions - an array of longs, each representing an a
duration in milliseconds that the client
wants the lease associated with the Uuid
from the corresponding element of
cookies renewed forpublic Map cancelAll(Uuid[] cookies)
LandlordcancelAll method is called. Should cancel the lease that is
associated with each element of cookiescancelAll in interface Landlordcookies - an array of Uuids, each universally and
uniquely identifying a lease granted by this
Landlordcookies
could be cancelled return null. Otherwise,
return a Map that for each failed cancel
attempt maps the corresponding cookie object to an
exception describing the failure.void updatePerformed(int updateCount)
PersistentStore after every update to give
server a chance to trigger a snapshot.updateCount - number of updates since last snapshotvoid restoreTransientState()
private String inventory()
public Object getAdmin()
AdministrablegetAdmin in interface AdministrableJoinAdminpublic Entry[] getLookupAttributes()
JoinAdmingetLookupAttributes in interface JoinAdminpublic void addLookupAttributes(Entry[] attrSets)
JoinAdminaddLookupAttributes in interface JoinAdminattrSets - the attribute sets to addpublic void modifyLookupAttributes(Entry[] attrSetTemplates, Entry[] attrSets)
JoinAdminmodifyLookupAttributes in interface JoinAdminattrSetTemplates - the templates for matching attribute setsattrSets - the modifications to make to matching setsServiceRegistration.modifyAttributes(net.jini.core.entry.Entry[], net.jini.core.entry.Entry[])public String[] getLookupGroups()
JoinAdmingetLookupGroups in interface JoinAdminJoinAdmin.setLookupGroups(java.lang.String[])public void addLookupGroups(String[] groups)
JoinAdminaddLookupGroups in interface JoinAdmingroups - groups to joinJoinAdmin.removeLookupGroups(java.lang.String[])public void removeLookupGroups(String[] groups)
JoinAdminremoveLookupGroups in interface JoinAdmingroups - groups to leaveJoinAdmin.addLookupGroups(java.lang.String[])public void setLookupGroups(String[] groups)
JoinAdminsetLookupGroups in interface JoinAdmingroups - groups to joinJoinAdmin.getLookupGroups()public LookupLocator[] getLookupLocators()
JoinAdmingetLookupLocators in interface JoinAdminJoinAdmin.setLookupLocators(net.jini.core.discovery.LookupLocator[])public void addLookupLocators(LookupLocator[] locators) throws RemoteException
JoinAdminaddLookupLocators in interface JoinAdminlocators - locators of specific lookup services to joinRemoteExceptionJoinAdmin.removeLookupLocators(net.jini.core.discovery.LookupLocator[])public void removeLookupLocators(LookupLocator[] locators) throws RemoteException
JoinAdminremoveLookupLocators in interface JoinAdminlocators - locators of specific lookup services to leaveRemoteExceptionJoinAdmin.addLookupLocators(net.jini.core.discovery.LookupLocator[])public void setLookupLocators(LookupLocator[] locators) throws RemoteException
JoinAdminsetLookupLocators in interface JoinAdminlocators - locators of specific lookup services to joinRemoteExceptionJoinAdmin.getLookupLocators()private static String toString(Object[] array)
public void destroy()
throws RemoteException
DestroyAdmindestroy in interface DestroyAdminRemoteExceptionboolean unexport(boolean force)
throws NoSuchObjectException
force - terminate in progress calls if necessaryNoSuchObjectExceptionvoid postDestroy()
public Object getServiceProxy()
null.getServiceProxy in interface ServiceProxyAccessorpublic Object getProxy()
null is returned.getProxy in interface ProxyAccessornullpublic String toString()
static NormServerInitializer init(String[] configOptions, NormServerInitializer init) throws Exception
Exceptionstatic void initFailed(Throwable e) throws Exception
e - the exception produced by the failureExceptionprivate static void logThrow(Level level, String method, String msg, Object[] msgParams, Throwable t)
public void start()
throws Exception
StartableIn addition to starting threads after construction, it also allows objects to avoid throwing an exception during construction to avoid finalizer attacks.
The implementation is required to ensure start() is idempotent (only executed once, additional invocations must return immediately).
boolean isolateSets()
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.