com.sun.sgs.impl.service.session
Class ClientSessionImpl

java.lang.Object
  extended by com.sun.sgs.impl.service.session.ClientSessionImpl
All Implemented Interfaces:
ClientSession, ManagedObject, NodeAssignment, Serializable

public class ClientSessionImpl
extends Object
implements ClientSession, NodeAssignment, Serializable

Implements a client session. The non-static, non-transient fields of an instance of this class are the persistent state of a client session and are only accessed transactionally.

See Also:
Serialized Form

Nested Class Summary
(package private) static class ClientSessionImpl.HandleNextDisconnectedSessionTask
          A persistent task to schedule tasks to notify (in succession) the client session listener of each disconnected session on a given failed node and to clean up the persistent data and bindings of those client sessions.
(package private) static class ClientSessionImpl.SendEvent
          A client session 'send' event, enqueued by a ClientSession.send invocation.
 
Constructor Summary
ClientSessionImpl(ClientSessionServiceImpl sessionService, Identity identity, Set<Delivery> deliveries, int maxMessageLength)
          Constructs an instance of this class with the specified sessionService, identity, and supported deliveries, and stores this instance with the following bindings:
 
Method Summary
(package private)  void addMoveEvent(long newNodeId)
          Initiates a relocation of this client session from the current node to newNodeId.
(package private)  void disconnect()
          If the session is connected, enqueues a disconnect event to this client session's event queue, and marks this session as disconnected.
 boolean equals(Object obj)
          
(package private)  ClientSessionListener getClientSessionListener(DataService dataService)
          Returns the client session listener, obtained from the specified dataService, for this session.
(package private)  BigInteger getId()
          Returns the ID of this instance as a BigInteger.
 int getMaxMessageLength()
          Return the maximum message length supported by this session.
 String getName()
          Returns the login name used to authenticate this session.
 long getNodeId()
          Returns the node ID for this instance.
 long getRelocatingToNodeId()
          Returns the ID of the new node that the client session is relocating to, or -1 if the associated client session is not relocating.
(package private) static ClientSessionImpl getSession(DataService dataService, BigInteger id)
          Returns the ClientSession instance for the given id, retrieved from the specified dataService, or null if the client session isn't bound in the data service.
 ClientSessionWrapper getWrappedClientSession()
          Returns the wrapped client session for this instance.
(package private)  int getWriteBufferCapacity()
          Returns the write buffer capacity for this session.
 int hashCode()
          
 boolean isConnected()
          Returns true if the client is connected, otherwise returns false.
 boolean isRelocating()
          Returns true if the session is relocating, and false otherwise.
(package private)  void move(long newNodeId)
          Updates this client session's node ID and bindings to the client session to reflect its reassignment to newNodeId.
(package private)  void notifyListenerAndRemoveSession(DataService dataService, boolean graceful, boolean notify)
          Invokes the disconnected callback on this session's ClientSessionListener (if present and notify is true), removes the listener and its binding (if present), and then removes this session and its bindings from the specified dataService.
(package private)  void putClientSessionListener(DataService dataService, ClientSessionListener listener)
          Stores the specified client session listener in the specified dataService with following binding:
(package private)  void relocationComplete()
          Marks this client session as having completed relocation, and then services this session's event queue.
 ClientSession send(ByteBuffer message)
          Sends a message contained in the specified ByteBuffer to this session's client with the delivery guarantee of Delivery.RELIABLE.
 ClientSession send(ByteBuffer message, Delivery delivery)
          Sends a message contained in the specified ByteBuffer to this session's client in a manner that satisfies the specified delivery guarantee.
(package private) static void serviceEventQueue(byte[] sessionId)
          Services the event queue for the session with the specified sessionId.
 Set<Delivery> supportedDeliveries()
          Returns a set containing the delivery guarantees supported by this session.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClientSessionImpl

ClientSessionImpl(ClientSessionServiceImpl sessionService,
                  Identity identity,
                  Set<Delivery> deliveries,
                  int maxMessageLength)
Constructs an instance of this class with the specified sessionService, identity, and supported deliveries, and stores this instance with the following bindings:

 com.sun.sgs.impl.service.session.impl.<idBytes>
 com.sun.sgs.impl.service.session.node.<nodeId>.impl.<idBytes>
This method should only be called within a transaction.

Parameters:
sessionService - a client session service
identity - the session's identity
deliveries - the session's supported delivery requirements
maxMessageLength - the maximum session message length
Throws:
TransactionException - if there is a problem with the current transaction
Method Detail

getName

public String getName()
Returns the login name used to authenticate this session.

Specified by:
getName in interface ClientSession
Returns:
the name used to authenticate this session

supportedDeliveries

public Set<Delivery> supportedDeliveries()
Returns a set containing the delivery guarantees supported by this session. The returned set is serializable.

Specified by:
supportedDeliveries in interface ClientSession
Returns:
a set containing the supported delivery guarantees

getMaxMessageLength

public int getMaxMessageLength()
Return the maximum message length supported by this session.

Specified by:
getMaxMessageLength in interface ClientSession
Returns:
the maximum message length.

isConnected

public boolean isConnected()
Returns true if the client is connected, otherwise returns false.

Specified by:
isConnected in interface ClientSession
Returns:
true if the client is connected, otherwise returns false

send

public ClientSession send(ByteBuffer message)
Sends a message contained in the specified ByteBuffer to this session's client with the delivery guarantee of Delivery.RELIABLE. The message starts at the buffer's current position and ends at the buffer's limit. The buffer's position is not modified by this operation.

The ByteBuffer may be reused immediately after this method returns. Changes made to the buffer after this method returns will have no effect on the message sent to the client by this invocation.

This method is equivalent to invoking send with the specified message and Delivery.RELIABLE. Enqueues a send event to this client session's event queue for servicing.

Specified by:
send in interface ClientSession
Parameters:
message - a message
Returns:
this client session

send

public ClientSession send(ByteBuffer message,
                          Delivery delivery)
Sends a message contained in the specified ByteBuffer to this session's client in a manner that satisfies the specified delivery guarantee. The message starts at the buffer's current position and ends at the buffer's limit. The buffer's position is not modified by this operation.

When possible, the message should be delivered using the most efficient means to satisfy the delivery guarantee. However, a stronger delivery guarantee may be used to deliver the message if the underlying protocol only supports stronger delivery guarantees. If the protocol is not able to satisfy the specified delivery guarantee (e.g., only supports weaker delivery guarantees than the one specified), then a DeliveryNotSupportedException will be thrown.

The ByteBuffer may be reused immediately after this method returns. Changes made to the buffer after this method returns will have no effect on the message sent to the client by this invocation. Enqueues a send event to this client session's event queue for servicing.

Specified by:
send in interface ClientSession
Parameters:
message - a message
delivery - a delivery guarantee
Returns:
this client session

addMoveEvent

void addMoveEvent(long newNodeId)
Initiates a relocation of this client session from the current node to newNodeId. If the client session is no longer connected or the session is already relocating then this request is ignored.

Parameters:
newNodeId - the ID of the node this session is relocating to

relocationComplete

void relocationComplete()
Marks this client session as having completed relocation, and then services this session's event queue. This method is invoked when the associated client connects to the new node to re-establish the client session.

Throws:
IllegalStateException - if this method is invoked from a node other than the session's local node

isRelocating

public boolean isRelocating()
Returns true if the session is relocating, and false otherwise.

Returns:
true if the session is relocating, and false otherwise

move

void move(long newNodeId)
Updates this client session's node ID and bindings to the client session to reflect its reassignment to newNodeId.

Parameters:
newNodeId - the node this session is relocating to
Throws:
IllegalArgumentException - if newNodeId does not match the local node ID

disconnect

void disconnect()
If the session is connected, enqueues a disconnect event to this client session's event queue, and marks this session as disconnected.


getNodeId

public long getNodeId()
Returns the node ID for this instance.

Specified by:
getNodeId in interface NodeAssignment
Returns:
the node ID for this instance

getRelocatingToNodeId

public long getRelocatingToNodeId()
Returns the ID of the new node that the client session is relocating to, or -1 if the associated client session is not relocating.

Specified by:
getRelocatingToNodeId in interface NodeAssignment
Returns:
the node ID of the new node, or -1 if the session is not relocating

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object

getId

BigInteger getId()
Returns the ID of this instance as a BigInteger.

Returns:
the ID of this instance as a BigInteger

getSession

static ClientSessionImpl getSession(DataService dataService,
                                    BigInteger id)
Returns the ClientSession instance for the given id, retrieved from the specified dataService, or null if the client session isn't bound in the data service. This method should only be called within a transaction.

Parameters:
dataService - a data service
id - a session ID
Returns:
the session for the given session id, or null
Throws:
TransactionException - if there is a problem with the current transaction

getWrappedClientSession

public ClientSessionWrapper getWrappedClientSession()
Returns the wrapped client session for this instance.

Returns:
the wrapped client session

notifyListenerAndRemoveSession

void notifyListenerAndRemoveSession(DataService dataService,
                                    boolean graceful,
                                    boolean notify)
Invokes the disconnected callback on this session's ClientSessionListener (if present and notify is true), removes the listener and its binding (if present), and then removes this session and its bindings from the specified dataService. If the bindings have already been removed from the dataService this method takes no action. This method should only be called within a transaction.

Parameters:
dataService - a data service
graceful - true if disconnection is graceful, and false otherwise
notify - true if the disconnected callback should be invoked
Throws:
TransactionException - if there is a problem with the current transaction

putClientSessionListener

void putClientSessionListener(DataService dataService,
                              ClientSessionListener listener)
Stores the specified client session listener in the specified dataService with following binding:
 com.sun.sgs.impl.service.session.listener.<idBytes>
 
This method should only be called within a transaction.

Parameters:
dataService - a data service
listener - a client session listener
Throws:
TransactionException - if there is a problem with the current transaction

getClientSessionListener

ClientSessionListener getClientSessionListener(DataService dataService)
Returns the client session listener, obtained from the specified dataService, for this session. This method should only be called within a transaction.

Parameters:
dataService - a data service
Returns:
the client session listener for this session
Throws:
TransactionException - if there is a problem with the current transaction

serviceEventQueue

static void serviceEventQueue(byte[] sessionId)
Services the event queue for the session with the specified sessionId.


getWriteBufferCapacity

int getWriteBufferCapacity()
Returns the write buffer capacity for this session.

Returns:
the write buffer capacity

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved