|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.presents.peer.server.PeerManager
public abstract class PeerManager
Manages connections to the other nodes in a Presents server cluster. Each server maintains a
client connection to the other servers and subscribes to the NodeObject of all peer
servers and uses those objects to communicate cross-node information.
| Nested Class Summary | |
|---|---|
static interface |
PeerManager.DroppedLockObserver
Used by entities that wish to know when this peer has been forced into immediately releasing a lock. |
static interface |
PeerManager.LockedOperation
Wraps an operation that needs a shared resource lock to be acquired before it can be performed, and released after it completes. |
protected class |
PeerManager.LockHandler
Handles a lock in a state of resolution. |
static class |
PeerManager.NodeAction
Encapsulates code that is meant to be executed one or more servers. |
static interface |
PeerManager.NodeApplicant
|
static class |
PeerManager.NodeRequest
Encapsulates code that is meant to be executed one or more servers and return a result. |
protected static class |
PeerManager.NodeRequestsResultImpl<T>
|
static interface |
PeerManager.StaleCacheObserver
Used by entities that wish to know when cached data has become stale due to a change on one of our peer servers. |
static class |
PeerManager.Stats
Returned by getStats(). |
| Field Summary | |
|---|---|
protected Map<String,ObserverList<PeerManager.StaleCacheObserver>> |
_cacheobs
Our stale cache observers. |
protected ClientManager |
_clmgr
|
protected PresentsConnectionManager |
_conmgr
|
protected ObserverList<PeerManager.DroppedLockObserver> |
_dropobs
Listeners for dropped locks. |
protected com.google.inject.Injector |
_injector
|
protected InvocationManager |
_invmgr
|
protected Invoker |
_invoker
|
protected Map<NodeObject.Lock,PeerManager.LockHandler> |
_locks
Locks in the process of resolution. |
protected String |
_nodeName
|
protected String |
_nodeNamespace
|
protected NodeObject |
_nodeobj
|
protected NodeRepository |
_noderepo
|
protected PresentsDObjectMgr |
_omgr
|
protected Map<String,PeerNode> |
_peers
|
protected Map<DObjectAddress,Tuple<Subscriber<?>,DObject>> |
_proxies
Contains a mapping of proxied objects to subscriber instances. |
protected ReportManager |
_repmgr
|
protected NodeRecord |
_self
|
protected String |
_sharedSecret
|
protected PeerManager.Stats |
_stats
Used to track runtime statistics. |
protected ArrayIntSet |
_suboids
The client oids of all peers subscribed to the node object. |
protected static long |
DEFAULT_LOCK_TIMEOUT
The default lock timeout. |
protected static Function<PeerNode,NodeObject> |
GET_NODE_OBJECT
Extracts the node object from the supplied peer. |
| Constructor Summary | |
|---|---|
PeerManager(Lifecycle cycle)
Creates an uninitialized peer manager. |
|
| Method Summary | ||
|---|---|---|
void |
acquireLock(NodeObject.Lock lock,
ResultListener<String> listener)
Acquires a lock on a resource shared amongst this node's peers. |
|
void |
addDroppedLockObserver(PeerManager.DroppedLockObserver observer)
Adds an observer to notify when this peer has been forced to drop a lock immediately. |
|
void |
addStaleCacheObserver(String cache,
PeerManager.StaleCacheObserver observer)
Registers a stale cache observer. |
|
void |
broadcastStaleCacheData(String cache,
Streamable data)
Called when cached data has changed on the local server and needs to inform our peers. |
|
protected void |
changedCacheData(String cache,
Streamable data)
Called when possibly cached data has changed on one of our peer servers. |
|
protected void |
clearClientInfo(PresentsSession client,
ClientInfo info)
Called when a client ends their session to clear their information from our node object. |
|
protected void |
clientLoggedOff(String nodeName,
ClientInfo clinfo)
Called when we hear about a client logging off of another node. |
|
protected void |
clientLoggedOn(String nodeName,
ClientInfo clinfo)
Called when we hear about a client logging on to another node. |
|
void |
clientSessionDidEnd(PresentsSession client)
Called when a client has logged off or been forcibly logged off due to inactivity and has thus ended their session. |
|
void |
clientSessionDidStart(PresentsSession client)
Called when a client has authenticated and been resolved and has started their session. |
|
void |
clientSubscribedToNode(int cloid)
Called by PeerSessions when clients subscribe to the NodeObject. |
|
void |
clientUnsubscribedFromNode(int cloid)
Called by PeerSessions when clients unsubscribe from the NodeObject. |
|
protected void |
connectedToPeer(PeerNode peer)
Called when we have established a connection to the supplied peer. |
|
protected ClientInfo |
createClientInfo()
Creates a ClientInfo record which will subsequently be initialized by a call to
initClientInfo(com.threerings.presents.server.PresentsSession, com.threerings.presents.peer.data.ClientInfo). |
|
protected PeerCreds |
createCreds()
Creates credentials that a PeerNode can use to authenticate with another node. |
|
protected PeerManager.LockHandler |
createLockHandler(PeerNode peer,
NodeObject.Lock lock,
boolean acquire)
|
|
protected NodeObject |
createNodeObject()
Creates the appropriate derived class of NodeObject which will be registered with
the distributed object system. |
|
protected void |
didInit()
Called after we have finished our initialization. |
|
protected void |
disconnectedFromPeer(PeerNode peer)
Called when a ended our session with the supplied peer. |
|
protected void |
droppedLock(NodeObject.Lock lock)
Called when we have been forced to drop a lock. |
|
Set<String> |
findApplicableNodes(PeerManager.NodeApplicant applicant)
Returns all nodes for which applicant.isApplicable returns true. |
|
protected byte[] |
flattenAction(PeerManager.NodeAction action)
Flattens the supplied node action into bytes. |
|
protected byte[] |
flattenRequest(PeerManager.NodeRequest request)
Flattens the supplied node request into bytes. |
|
void |
generateReport(ClientObject caller,
String type,
InvocationService.ResultListener listener)
Handles a PeerService.generateReport(java.lang.String, com.threerings.presents.client.InvocationService.ResultListener) request. |
|
protected PeerManager.LockHandler |
getLockHandler(NodeObject.Lock lock)
Returns the lock handler for the specified lock. |
|
protected long |
getLockTimeout()
Returns the amount of time to wait for peer ratification to complete before acquiring/releasing a lock. |
|
NodeObject |
getNodeObject()
Returns the distributed object that represents this node to its peers. |
|
Iterable<NodeObject> |
getNodeObjects()
Returns an iterable over our node object and that of our peers. |
|
Client |
getPeerClient(String nodeName)
Returns the client object representing the connection to the named peer, or null if we are not currently connected to it. |
|
String |
getPeerInternalHostName(String nodeName)
Returns the internal hostname to use when connecting to the specified peer or null if the peer is not currently connected to this server. |
|
protected Class<? extends PeerNode> |
getPeerNodeClass()
Creates a PeerNode to manage our connection to the specified peer. |
|
NodeObject |
getPeerNodeObject(String nodeName)
Returns the NodeObject of the named peer, or null if null if the peer is not
currently connected to this server. |
|
int |
getPeerPort(String nodeName)
Returns the port on which to connect to the specified peer or -1 if the peer is not currently connected to this server. |
|
String |
getPeerPublicHostName(String nodeName)
Returns the public hostname to use when connecting to the specified peer or null if the peer is not currently connected to this server. |
|
protected String |
getRegion()
Returns the region in which the local node exists. |
|
PeerManager.Stats |
getStats()
Returns a snapshot of runtime statistics tracked by the peer manager. |
|
protected static boolean |
hasPriority(String nodeName1,
String nodeName2)
Determines whether the first node named has priority over the second when resolving lock disputes. |
|
protected boolean |
ignoreClient(PresentsSession client)
Returns true if we should ignore the supplied client, false if we should let our other peers know that this client is authenticated with this server. |
|
void |
init(String nodeName,
String sharedSecret,
String hostName,
String publicHostName,
int port)
Initializes this peer manager to connect to all other nodes in the NODES table. |
|
void |
init(String nodeName,
String sharedSecret,
String hostName,
String publicHostName,
int port,
String nodeNamespace)
Initializes this peer manager and initiates the process of connecting to its peer nodes. |
|
void |
init(String nodeName,
String sharedSecret,
String hostName,
String publicHostName,
String region,
int port,
String nodeNamespace)
Initializes this peer manager and initiates the process of connecting to its peer nodes. |
|
protected void |
initClientInfo(PresentsSession client,
ClientInfo info)
Initializes the supplied client info for the supplied client. |
|
void |
invokeAction(ClientObject caller,
byte[] serializedAction)
Handles a PeerService.invokeAction(byte[]) request. |
|
void |
invokeNodeAction(PeerManager.NodeAction action)
Invokes the supplied action on this and any other server that it indicates is appropriate. |
|
void |
invokeNodeAction(PeerManager.NodeAction action,
Runnable onDropped)
Invokes the supplied action on this and any other server that it indicates is appropriate. |
|
void |
invokeNodeAction(String nodeName,
PeerManager.NodeAction action)
Invokes a node action on a specific node without executing PeerManager.NodeApplicant.isApplicable(com.threerings.presents.peer.data.NodeObject) to determine whether the action is applicable. |
|
|
invokeNodeRequest(PeerManager.NodeRequest request,
NodeRequestsListener<T> listener)
Invokes the supplied request on all servers in parallel. |
|
protected void |
invokeNodeRequest(String nodeName,
byte[] requestBytes,
InvocationService.ResultListener listener)
|
|
void |
invokeNodeRequest(String nodeName,
PeerManager.NodeRequest request,
InvocationService.ResultListener listener)
Invokes a node request on a specific node and returns the result through the listener. |
|
int |
invokeOnNodes(Function<Tuple<Client,NodeObject>,Boolean> func)
Invokes the supplied function on all node objects (except the local node). |
|
void |
invokeRequest(ClientObject caller,
byte[] serializedAction,
InvocationService.ResultListener listener)
Handles a PeerService.invokeRequest(byte[], com.threerings.presents.client.InvocationService.ResultListener) request. |
|
boolean |
isAuthenticPeer(PeerCreds creds)
Returns true if the supplied peer credentials match our shared secret. |
|
ClientInfo |
locateClient(Name key)
Locates the client with the specified name. |
|
protected void |
lockAcquired(NodeObject.Lock lock,
long wait,
ResultListener<String> listener)
|
|
protected void |
lockReleased(NodeObject.Lock lock,
ResultListener<String> listener)
|
|
|
lookupNodeDatum(Function<NodeObject,T> op)
Locates a datum from among the set of peer NodeObjects. |
|
protected void |
peerAcquiringLock(PeerNode peer,
NodeObject.Lock lock)
Called when a peer announces its intention to acquire a lock. |
|
protected void |
peerAddedLock(String nodeName,
NodeObject.Lock lock)
Called when a peer adds a lock. |
|
protected void |
peerEndedSession(PeerSession session)
Called when a peer's session with this server ends. |
|
protected void |
peerReleasingLock(PeerNode peer,
NodeObject.Lock lock)
Called when a peer announces its intention to release a lock. |
|
protected void |
peerRemovedLock(String nodeName,
NodeObject.Lock lock)
Called when a peer removes a lock. |
|
protected void |
peerStartedSession(PeerSession session)
Called when a peer connects to this server. |
|
protected void |
peerUpdatedLock(String nodeName,
NodeObject.Lock lock)
Called when a peer updates a lock. |
|
void |
performWithLock(NodeObject.Lock lock,
PeerManager.LockedOperation operation)
Tries to acquire the resource lock and, if successful, performs the operation and releases the lock; if unsuccessful, calls the operation's failure handler. |
|
|
proxyRemoteObject(DObjectAddress remote,
ResultListener<Integer> listener)
|
|
|
proxyRemoteObject(String nodeName,
int remoteOid,
ResultListener<Integer> listener)
Initiates a proxy on an object that is managed by the specified peer. |
|
String |
queryLock(NodeObject.Lock lock)
Finds the owner of the specified lock (if any) among this node and its peers. |
|
void |
queryLock(NodeObject.Lock lock,
ResultListener<String> listener)
Determines the owner of the specified lock, waiting for any resolution to complete before notifying the supplied listener. |
|
void |
ratifyLockAction(ClientObject caller,
NodeObject.Lock lock,
boolean acquire)
Handles a PeerService.ratifyLockAction(com.threerings.presents.peer.data.NodeObject.Lock, boolean) request. |
|
void |
reacquireLock(NodeObject.Lock lock)
Reacquires a lock after a call to releaseLock(com.threerings.presents.peer.data.NodeObject.Lock, com.samskivert.util.ResultListener but before the result listener
supplied to that method has been notified with the result of the action. |
|
protected void |
refreshPeer(NodeRecord record)
Ensures that we have a connection to the specified node if it has checked in since we last failed to connect. |
|
protected void |
refreshPeers()
Reloads the list of peer nodes from our table and refreshes each with a call to refreshPeer(com.threerings.presents.peer.server.persist.NodeRecord). |
|
void |
releaseLock(NodeObject.Lock lock,
ResultListener<String> listener)
Releases a lock. |
|
void |
removeDroppedLockObserver(PeerManager.DroppedLockObserver observer)
Removes a dropped lock observer from the list. |
|
void |
removeStaleCacheObserver(String cache,
PeerManager.StaleCacheObserver observer)
Removes a stale cache observer registration. |
|
void |
shutdown()
|
|
void |
unproxyRemoteObject(DObjectAddress addr)
Unsubscribes from and clears a proxied object. |
|
void |
unproxyRemoteObject(String nodeName,
int remoteOid)
Unsubscribes from and clears a proxied object. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final Function<PeerNode,NodeObject> GET_NODE_OBJECT
protected String _nodeName
protected String _sharedSecret
protected NodeRecord _self
protected NodeObject _nodeobj
protected String _nodeNamespace
protected Map<String,PeerNode> _peers
protected ArrayIntSet _suboids
protected Map<DObjectAddress,Tuple<Subscriber<?>,DObject>> _proxies
protected Map<String,ObserverList<PeerManager.StaleCacheObserver>> _cacheobs
protected ObserverList<PeerManager.DroppedLockObserver> _dropobs
protected Map<NodeObject.Lock,PeerManager.LockHandler> _locks
protected PeerManager.Stats _stats
@Inject protected Invoker _invoker
@Inject protected ClientManager _clmgr
@Inject protected PresentsConnectionManager _conmgr
@Inject protected com.google.inject.Injector _injector
@Inject protected InvocationManager _invmgr
@Inject protected NodeRepository _noderepo
@Inject protected PresentsDObjectMgr _omgr
@Inject protected ReportManager _repmgr
protected static final long DEFAULT_LOCK_TIMEOUT
| Constructor Detail |
|---|
@Inject public PeerManager(Lifecycle cycle)
| Method Detail |
|---|
public NodeObject getNodeObject()
public Iterable<NodeObject> getNodeObjects()
public void init(String nodeName,
String sharedSecret,
String hostName,
String publicHostName,
int port)
init(String, String, String, String, int, String) for the behavior of the method
and the meaning of its parameters.
public void init(String nodeName,
String sharedSecret,
String hostName,
String publicHostName,
int port,
String nodeNamespace)
nodeName - this node's unique name.sharedSecret - a shared secret used to allow the peers to authenticate with one
another.hostName - the DNS name of the server running this node.publicHostName - if non-null, a separate public DNS hostname by which the node is to
be known to normal clients (we may want inter-peer communication to take place over a
different network than the communication between real clients and the various peer
servers).port - the port on which other nodes should connect to us.nodeNamespace - The namespace for nodes to peer with. This node will connect to other
nodes with the same prefix from the NODES table.
public void init(String nodeName,
String sharedSecret,
String hostName,
String publicHostName,
String region,
int port,
String nodeNamespace)
nodeName - this node's unique name.sharedSecret - a shared secret used to allow the peers to authenticate with one
another.hostName - the DNS name of the server running this node.publicHostName - if non-null, a separate public DNS hostname by which the node is to
be known to normal clients (we may want inter-peer communication to take place over a
different network than the communication between real clients and the various peer
servers).region - the region in which the node lives, which may be null. Nodes in different
regions must connect to each other through the public host name.port - the port on which other nodes should connect to us.nodeNamespace - The namespace for nodes to peer with. This node will connect to other
nodes with the same prefix from the NODES table.public boolean isAuthenticPeer(PeerCreds creds)
public ClientInfo locateClient(Name key)
public <T> T lookupNodeDatum(Function<NodeObject,T> op)
NodeObjects. Objects are searched in
arbitrary order and the first non-null value returned by the supplied lookup operation is
returned to the caller. Null if all lookup operations returned null.
public int invokeOnNodes(Function<Tuple<Client,NodeObject>,Boolean> func)
public void invokeNodeAction(PeerManager.NodeAction action)
public void invokeNodeAction(PeerManager.NodeAction action,
Runnable onDropped)
onDropped - a runnable to be executed if the action was not invoked on the local server
or any peer node due to failing to match any of the nodes. The runnable will be executed on
the dobj event thread.
public void invokeNodeAction(String nodeName,
PeerManager.NodeAction action)
PeerManager.NodeApplicant.isApplicable(com.threerings.presents.peer.data.NodeObject) to determine whether the action is applicable.
public <T> void invokeNodeRequest(PeerManager.NodeRequest request,
NodeRequestsListener<T> listener)
public Set<String> findApplicableNodes(PeerManager.NodeApplicant applicant)
applicant.isApplicable returns true.
public void invokeNodeRequest(String nodeName,
PeerManager.NodeRequest request,
InvocationService.ResultListener listener)
public <T extends DObject> void proxyRemoteObject(String nodeName,
int remoteOid,
ResultListener<Integer> listener)
Note that proxy requests do not stack like subscription requests. Only one entity must issue a request to proxy an object and that entity must be responsible for releasing the proxy when it knows that there are no longer any local subscribers to the object.
public <T extends DObject> void proxyRemoteObject(DObjectAddress remote,
ResultListener<Integer> listener)
public void unproxyRemoteObject(String nodeName,
int remoteOid)
public void unproxyRemoteObject(DObjectAddress addr)
public NodeObject getPeerNodeObject(String nodeName)
null if null if the peer is not
currently connected to this server.
public Client getPeerClient(String nodeName)
null if we are not currently connected to it.
public String getPeerPublicHostName(String nodeName)
public String getPeerInternalHostName(String nodeName)
public int getPeerPort(String nodeName)
public void acquireLock(NodeObject.Lock lock,
ResultListener<String> listener)
public void releaseLock(NodeObject.Lock lock,
ResultListener<String> listener)
reacquireLock(com.threerings.presents.peer.data.NodeObject.Lock), in which case the
passed listener will receive this node's name as opposed to null, which
signifies that the lock has been successfully released.
public void reacquireLock(NodeObject.Lock lock)
releaseLock(com.threerings.presents.peer.data.NodeObject.Lock, com.samskivert.util.ResultListener) but before the result listener
supplied to that method has been notified with the result of the action. The result
listener will receive the name of this node to indicate that the lock is still held. If a
node requests to release a lock, then receives a lock-related request from another peer, it
can use this method to cancel the release reliably, since the lock-related request will have
been sent before the peer's ratification of the release.
public void queryLock(NodeObject.Lock lock,
ResultListener<String> listener)
public String queryLock(NodeObject.Lock lock)
public void performWithLock(NodeObject.Lock lock,
PeerManager.LockedOperation operation)
public void addDroppedLockObserver(PeerManager.DroppedLockObserver observer)
public void removeDroppedLockObserver(PeerManager.DroppedLockObserver observer)
public void clientSubscribedToNode(int cloid)
PeerSessions when clients subscribe to the NodeObject.
public void clientUnsubscribedFromNode(int cloid)
PeerSessions when clients unsubscribe from the NodeObject.
public void addStaleCacheObserver(String cache,
PeerManager.StaleCacheObserver observer)
public void removeStaleCacheObserver(String cache,
PeerManager.StaleCacheObserver observer)
public void broadcastStaleCacheData(String cache,
Streamable data)
public PeerManager.Stats getStats()
public void shutdown()
shutdown in interface Lifecycle.ShutdownComponent
public void ratifyLockAction(ClientObject caller,
NodeObject.Lock lock,
boolean acquire)
PeerProviderPeerService.ratifyLockAction(com.threerings.presents.peer.data.NodeObject.Lock, boolean) request.
ratifyLockAction in interface PeerProvider
public void invokeAction(ClientObject caller,
byte[] serializedAction)
PeerProviderPeerService.invokeAction(byte[]) request.
invokeAction in interface PeerProvider
public void invokeRequest(ClientObject caller,
byte[] serializedAction,
InvocationService.ResultListener listener)
PeerProviderPeerService.invokeRequest(byte[], com.threerings.presents.client.InvocationService.ResultListener) request.
invokeRequest in interface PeerProvider
public void generateReport(ClientObject caller,
String type,
InvocationService.ResultListener listener)
throws InvocationException
PeerProviderPeerService.generateReport(java.lang.String, com.threerings.presents.client.InvocationService.ResultListener) request.
generateReport in interface PeerProviderInvocationExceptionpublic void clientSessionDidStart(PresentsSession client)
ClientManager.ClientObserver
clientSessionDidStart in interface ClientManager.ClientObserverpublic void clientSessionDidEnd(PresentsSession client)
ClientManager.ClientObserver
clientSessionDidEnd in interface ClientManager.ClientObserverprotected void didInit()
protected void refreshPeers()
refreshPeer(com.threerings.presents.peer.server.persist.NodeRecord).
protected void refreshPeer(NodeRecord record)
protected boolean ignoreClient(PresentsSession client)
protected NodeObject createNodeObject()
NodeObject which will be registered with
the distributed object system.
protected ClientInfo createClientInfo()
ClientInfo record which will subsequently be initialized by a call to
initClientInfo(com.threerings.presents.server.PresentsSession, com.threerings.presents.peer.data.ClientInfo).
protected PeerManager.LockHandler getLockHandler(NodeObject.Lock lock)
protected PeerManager.LockHandler createLockHandler(PeerNode peer,
NodeObject.Lock lock,
boolean acquire)
protected void changedCacheData(String cache,
Streamable data)
protected void droppedLock(NodeObject.Lock lock)
protected void initClientInfo(PresentsSession client,
ClientInfo info)
protected void clearClientInfo(PresentsSession client,
ClientInfo info)
protected Class<? extends PeerNode> getPeerNodeClass()
PeerNode to manage our connection to the specified peer.
protected PeerCreds createCreds()
PeerNode can use to authenticate with another node.
protected String getRegion()
protected void clientLoggedOn(String nodeName,
ClientInfo clinfo)
protected void clientLoggedOff(String nodeName,
ClientInfo clinfo)
protected void peerStartedSession(PeerSession session)
protected void peerEndedSession(PeerSession session)
protected void connectedToPeer(PeerNode peer)
protected void disconnectedFromPeer(PeerNode peer)
protected void peerAcquiringLock(PeerNode peer,
NodeObject.Lock lock)
protected void peerReleasingLock(PeerNode peer,
NodeObject.Lock lock)
protected void peerAddedLock(String nodeName,
NodeObject.Lock lock)
protected void peerUpdatedLock(String nodeName,
NodeObject.Lock lock)
protected void peerRemovedLock(String nodeName,
NodeObject.Lock lock)
protected byte[] flattenAction(PeerManager.NodeAction action)
protected byte[] flattenRequest(PeerManager.NodeRequest request)
protected void invokeNodeRequest(String nodeName,
byte[] requestBytes,
InvocationService.ResultListener listener)
protected void lockAcquired(NodeObject.Lock lock,
long wait,
ResultListener<String> listener)
protected void lockReleased(NodeObject.Lock lock,
ResultListener<String> listener)
protected long getLockTimeout()
protected static boolean hasPriority(String nodeName1,
String nodeName2)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||