abstract class NormServerBaseImpl extends Object implements NormServer, LocalLandlord, ServerProxyTrust, ProxyAccessor
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) 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.
|
private class |
NormServerBaseImpl.RenewLogThread |
private class |
NormServerBaseImpl.SendMonitorImpl
The implementation of
SendMonitor we use to track
event delivery threads. |
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 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 |
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 PersistentStore |
store
Our persistant store
|
NO_LISTENER
Constructor and Description |
---|
NormServerBaseImpl(boolean persistent)
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.
|
(package private) Exporter |
getExporter(Configuration config)
Returns the exporter to use to export this server.
|
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) void |
init(String[] configOptions,
LifeCycle lifeCycle)
Portion of construction that is common between the activatable and not
activatable cases.
|
(package private) void |
initAsSubject(Configuration config)
Common construction for activatable and non-activatable cases, run
under the proper Subject.
|
(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.
|
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
LoginContext loginContext
String persistenceDirectory
private ProxyPreparer leasePreparer
private ProxyPreparer recoveredLeasePreparer
private ProxyPreparer listenerPreparer
private ProxyPreparer recoveredListenerPreparer
private ProxyPreparer locatorPreparer
private ProxyPreparer recoveredLocatorPreparer
Exporter exporter
private LifeCycle lifeCycle
private Uuid serverUuid
private JoinState joinState
private Map setTable
private LeaseRenewalManager lrm
private LeaseExpirationMgr expMgr
private LeaseFactory leaseFactory
private LeasePeriodPolicy setLeasePolicy
private boolean isolateSets
private PersistentStore store
private UIDGenerator idGen
private List renewedList
private NormServerBaseImpl.RenewLogThread renewLogger
private EventTypeGenerator generator
private LRMEventListener lrmEventListener
private int logToSnapshotThresh
private float snapshotWt
NormServer serverProxy
LeaseRenewalService normProxy
private AdminProxy adminProxy
private NormServerBaseImpl.SnapshotThread snapshotter
private final NormServerBaseImpl.ReadyState ready
private final NormServerBaseImpl.CountLeases countLeases
NormServerBaseImpl(boolean persistent)
persistent
- whether this server is persistentpublic void renewFor(Uuid id, Lease leaseToRenew, long membershipDuration, long renewDuration) throws RemoteException, ThrowThis
NormServer
renewFor
in interface NormServer
id
- 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
NormServer
remove
in interface NormServer
id
- 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
NormServer
null
or a zero-length array if there are no leases in the set.getLeases
in interface NormServer
id
- of set being operated onMarshalledInstance
s,
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
NormServer
setExpirationWarningListener
in interface NormServer
id
- 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
NormServer
setRenewalFailureListener
in interface NormServer
id
- 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
ThrowThis
private static boolean isCurrent(LeaseSet set)
private LeaseSet getSet(Uuid id) throws ThrowThis
ThrowThis
public LeaseRenewalSet createLeaseRenewalSet(long leaseDuration)
LeaseRenewalService
LeaseRenewalSet
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 LeaseRenewalService
leaseDuration
- 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)
SendMonitorImpl
public TrustVerifier getProxyVerifier()
ServerProxyTrust
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. The verifier
should be able to verify all proxies for the service, including
proxies for resources (such as leases and registrations).getProxyVerifier
in interface ServerProxyTrust
TrustVerifier
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 TrustEquivalence
public long renew(Uuid cookie, long extension) throws UnknownLeaseException, LeaseDeniedException
Landlord
renew
method is called.
Renews the lease that is associated with the given cookie
.renew
in interface Landlord
renew
in interface LocalLandlord
cookie
- 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 cookie
LeaseDeniedException
- if the landlord is unwilling to
renew the leasepublic void cancel(Uuid cookie) throws UnknownLeaseException
Landlord
cancel
method is
called. Cancels the lease that is associated with the given
cookie
.cancel
in interface Landlord
cancel
in interface LocalLandlord
cookie
- the Uuid
associated with the lease who's
renew
method was calledUnknownLeaseException
- if landlord does not know about
a lease with the specified cookie
private void removeSet(LeaseSet set)
public Landlord.RenewResults renewAll(Uuid[] cookies, long[] extensions)
Landlord
renewAll
method is called. Should renew the lease that is
associated with each element of cookies
renewAll
in interface Landlord
cookies
- an array of Uuid
s, each universally and
uniquely identifying a lease granted by this
Landlord
extensions
- 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)
Landlord
cancelAll
method is called. Should cancel the lease that is
associated with each element of cookies
cancelAll
in interface Landlord
cookies
- an array of Uuid
s, each universally and
uniquely identifying a lease granted by this
Landlord
cookies
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()
Administrable
getAdmin
in interface Administrable
JoinAdmin
public Entry[] getLookupAttributes()
JoinAdmin
getLookupAttributes
in interface JoinAdmin
public void addLookupAttributes(Entry[] attrSets)
JoinAdmin
addLookupAttributes
in interface JoinAdmin
attrSets
- the attribute sets to addpublic void modifyLookupAttributes(Entry[] attrSetTemplates, Entry[] attrSets)
JoinAdmin
modifyLookupAttributes
in interface JoinAdmin
attrSetTemplates
- 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()
JoinAdmin
getLookupGroups
in interface JoinAdmin
JoinAdmin.setLookupGroups(java.lang.String[])
public void addLookupGroups(String[] groups)
JoinAdmin
addLookupGroups
in interface JoinAdmin
groups
- groups to joinJoinAdmin.removeLookupGroups(java.lang.String[])
public void removeLookupGroups(String[] groups)
JoinAdmin
removeLookupGroups
in interface JoinAdmin
groups
- groups to leaveJoinAdmin.addLookupGroups(java.lang.String[])
public void setLookupGroups(String[] groups)
JoinAdmin
setLookupGroups
in interface JoinAdmin
groups
- groups to joinJoinAdmin.getLookupGroups()
public LookupLocator[] getLookupLocators()
JoinAdmin
getLookupLocators
in interface JoinAdmin
JoinAdmin.setLookupLocators(net.jini.core.discovery.LookupLocator[])
public void addLookupLocators(LookupLocator[] locators) throws RemoteException
JoinAdmin
addLookupLocators
in interface JoinAdmin
locators
- locators of specific lookup services to joinRemoteException
JoinAdmin.removeLookupLocators(net.jini.core.discovery.LookupLocator[])
public void removeLookupLocators(LookupLocator[] locators) throws RemoteException
JoinAdmin
removeLookupLocators
in interface JoinAdmin
locators
- locators of specific lookup services to leaveRemoteException
JoinAdmin.addLookupLocators(net.jini.core.discovery.LookupLocator[])
public void setLookupLocators(LookupLocator[] locators) throws RemoteException
JoinAdmin
setLookupLocators
in interface JoinAdmin
locators
- locators of specific lookup services to joinRemoteException
JoinAdmin.getLookupLocators()
private static String toString(Object[] array)
public void destroy() throws RemoteException
DestroyAdmin
destroy
in interface DestroyAdmin
RemoteException
boolean unexport(boolean force) throws NoSuchObjectException
force
- terminate in progress calls if necessaryNoSuchObjectException
void postDestroy()
public Object getServiceProxy()
null
.getServiceProxy
in interface ServiceProxyAccessor
public Object getProxy()
null
is returned.getProxy
in interface ProxyAccessor
null
public String toString()
void init(String[] configOptions, LifeCycle lifeCycle) throws Exception
Exception
static void initFailed(Throwable e) throws Exception
e
- the exception produced by the failureException
private static void logThrow(Level level, String method, String msg, Object[] msgParams, Throwable t)
void initAsSubject(Configuration config) throws Exception
Exception
boolean isolateSets()
Exporter getExporter(Configuration config) throws ConfigurationException
config
- the configuration to use for supplying the exporterConfigurationException
- if a problem occurs retrieving entries
from the configurationCopyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.