com.threerings.presents.peer.server
Class PeerNode

java.lang.Object
  extended by com.threerings.presents.peer.server.PeerNode
All Implemented Interfaces:
ClientObserver, SessionObserver, Subscriber<NodeObject>

public class PeerNode
extends Object
implements ClientObserver, Subscriber<NodeObject>

Contains all runtime information for one of our peer nodes.


Nested Class Summary
protected  class PeerNode.NodeObjectListener
          Listens to node object changes.
 
Field Summary
protected  Client _client
           
protected  PresentsConnectionManager _conmgr
           
protected  long _lastConnectStamp
           
protected  PeerNode.NodeObjectListener _listener
           
protected  PresentsDObjectMgr _omgr
           
protected  PeerManager _peermgr
           
protected  NodeRecord _record
           
 NodeObject nodeobj
          This peer's node object.
protected static long STALE_INTERVAL
          The amount of time after which a node record can be considered out of date and invalid.
 
Constructor Summary
PeerNode()
           
 
Method Summary
 void clientConnectionFailed(Client client, Exception cause)
          Called when the connection to the server went away for some unexpected reason.
 void clientDidClear(Client client)
          Called after the client is completely logged off from a successful session and is ready to reconnect to a new server if desired.
 void clientDidLogoff(Client client)
          Called after the client has been logged off of the server and has disconnected.
 void clientDidLogon(Client client)
          Called after the client successfully connected to and authenticated with the server.
 void clientFailedToLogon(Client client, Exception cause)
          Called if anything fails during the logon attempt.
 void clientObjectDidChange(Client client)
          For systems that allow switching screen names after logon, this method is called whenever a screen name change takes place to report that the client object has been replaced to potential client-side subscribers.
 boolean clientWillLogoff(Client client)
          Called when an abortable logoff request is made.
 void clientWillLogon(Client client)
          Called immediately before a logon is attempted.
protected  Communicator createCommunicator(Client client)
           
protected  PeerNode.NodeObjectListener createListener()
          Create the NodeObjectListener to use.
 Client getClient()
          Returns the Client instance that manages our connection to this peer.
 String getInternalHostName()
          Returns the hostname for internal clients to use when connecting to this peer.
 String getNodeName()
          Returns this peer's unique string identifier.
 int getPort()
          Returns the port on which to connect to this peer.
 String getPublicHostName()
          Returns the hostname for external clients to use when connecting to this peer.
 void init(NodeRecord record)
          Initializes this peer node and creates its internal client.
 void objectAvailable(NodeObject object)
          Called when a subscription request has succeeded and the object is available.
 void refresh(NodeRecord record)
           
 void requestFailed(int oid, ObjectAccessException cause)
          Called when a subscription request has failed.
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodeobj

public NodeObject nodeobj
This peer's node object.


_record

protected NodeRecord _record

_listener

protected PeerNode.NodeObjectListener _listener

_client

protected Client _client

_lastConnectStamp

protected long _lastConnectStamp

_peermgr

@Inject
protected PeerManager _peermgr

_omgr

@Inject
protected PresentsDObjectMgr _omgr

_conmgr

@Inject
protected PresentsConnectionManager _conmgr

STALE_INTERVAL

protected static final long STALE_INTERVAL
The amount of time after which a node record can be considered out of date and invalid.

See Also:
Constant Field Values
Constructor Detail

PeerNode

public PeerNode()
Method Detail

init

public void init(NodeRecord record)
Initializes this peer node and creates its internal client.


getClient

public Client getClient()
Returns the Client instance that manages our connection to this peer.


getNodeName

public String getNodeName()
Returns this peer's unique string identifier.


getPublicHostName

public String getPublicHostName()
Returns the hostname for external clients to use when connecting to this peer.


getInternalHostName

public String getInternalHostName()
Returns the hostname for internal clients to use when connecting to this peer.


getPort

public int getPort()
Returns the port on which to connect to this peer.


refresh

public void refresh(NodeRecord record)

shutdown

public void shutdown()

clientFailedToLogon

public void clientFailedToLogon(Client client,
                                Exception cause)
Description copied from interface: ClientObserver
Called if anything fails during the logon attempt. This could be a network failure, authentication failure or otherwise. The exception provided will indicate the cause of the failure.

Specified by:
clientFailedToLogon in interface ClientObserver
cause - an exception indicating the cause of the logon failure. Note: this may be a LogonException and if so, the caller must check LogonException.isStillInProgress() to find out if the logon process has totally failed or if we are simply reporting intermediate status (we might be falling back to an alternative port or delaying our auto-retry attempt due to server overload).

clientConnectionFailed

public void clientConnectionFailed(Client client,
                                   Exception cause)
Description copied from interface: ClientObserver
Called when the connection to the server went away for some unexpected reason. This will be followed by a call to SessionObserver.clientDidLogoff(com.threerings.presents.client.Client).

Specified by:
clientConnectionFailed in interface ClientObserver

clientWillLogon

public void clientWillLogon(Client client)
Description copied from interface: SessionObserver
Called immediately before a logon is attempted.

Specified by:
clientWillLogon in interface SessionObserver

clientDidLogon

public void clientDidLogon(Client client)
Description copied from interface: SessionObserver
Called after the client successfully connected to and authenticated with the server. The entire object system is up and running by the time this method is called.

Specified by:
clientDidLogon in interface SessionObserver

clientObjectDidChange

public void clientObjectDidChange(Client client)
Description copied from interface: SessionObserver
For systems that allow switching screen names after logon, this method is called whenever a screen name change takes place to report that the client object has been replaced to potential client-side subscribers.

Specified by:
clientObjectDidChange in interface SessionObserver

clientWillLogoff

public boolean clientWillLogoff(Client client)
Description copied from interface: ClientObserver
Called when an abortable logoff request is made. If the observer returns false from this method, the client will abort the logoff request.

Specified by:
clientWillLogoff in interface ClientObserver

clientDidLogoff

public void clientDidLogoff(Client client)
Description copied from interface: SessionObserver
Called after the client has been logged off of the server and has disconnected.

Specified by:
clientDidLogoff in interface SessionObserver

clientDidClear

public void clientDidClear(Client client)
Description copied from interface: ClientObserver
Called after the client is completely logged off from a successful session and is ready to reconnect to a new server if desired. This will only be called after an active session was terminated, not after a logon attempt failed as that failure will be reported by ClientObserver.clientFailedToLogon(com.threerings.presents.client.Client, java.lang.Exception).

Specified by:
clientDidClear in interface ClientObserver

objectAvailable

public void objectAvailable(NodeObject object)
Description copied from interface: Subscriber
Called when a subscription request has succeeded and the object is available. If the object was requested for subscription, the subscriber can subsequently receive notifications by registering itself as a listener of some sort (see DObject.addListener(com.threerings.presents.dobj.ChangeListener)).

Specified by:
objectAvailable in interface Subscriber<NodeObject>
See Also:
DObjectManager.subscribeToObject(int, com.threerings.presents.dobj.Subscriber)

requestFailed

public void requestFailed(int oid,
                          ObjectAccessException cause)
Description copied from interface: Subscriber
Called when a subscription request has failed. The nature of the failure will be communicated via the supplied ObjectAccessException.

Specified by:
requestFailed in interface Subscriber<NodeObject>
See Also:
DObjectManager.subscribeToObject(int, com.threerings.presents.dobj.Subscriber)

createCommunicator

protected Communicator createCommunicator(Client client)

createListener

protected PeerNode.NodeObjectListener createListener()
Create the NodeObjectListener to use. Overrideable.