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

java.lang.Object
  extended by com.sun.sgs.impl.service.session.ClientSessionHandler
All Implemented Interfaces:
SessionProtocolHandler

 class ClientSessionHandler
extends Object
implements SessionProtocolHandler

Handles sending/receiving messages to/from a client session and disconnecting a client session.


Nested Class Summary
(package private)  class ClientSessionHandler.DisconnectAction
          An action to disconnect the client session.
(package private)  class ClientSessionHandler.MoveAction
          An action to start the process of moving the associated client session from this node to another node (the newNode specified during construction).
(package private)  class ClientSessionHandler.SendMessageAction
          An action to send a message.
(package private) static class ClientSessionHandler.SetupCompletionFuture
          This future is constructed with the RequestCompletionHandler passed to one of the ProtocolListener's methods: newLogin or relocatedSession.
 
Field Summary
(package private)  Identity identity
          The identity for this session.
(package private) static String RELOCATE_REFUSED_REASON
          Message indicating relocation was refused for a non-specific reason.
(package private)  BigInteger sessionRefId
          The session ID as a BigInteger.
 
Constructor Summary
ClientSessionHandler(ClientSessionServiceImpl sessionService, DataService dataService, SessionProtocol sessionProtocol, Identity identity, RequestCompletionHandler<SessionProtocolHandler> completionHandler)
          Constructs an handler for a client session that is logging in.
ClientSessionHandler(ClientSessionServiceImpl sessionService, DataService dataService, SessionProtocol sessionProtocol, Identity identity, RequestCompletionHandler<SessionProtocolHandler> completionHandler, BigInteger sessionRefId)
          Constructs an handler for a client session.
 
Method Summary
 void channelMessage(BigInteger channelId, ByteBuffer message, RequestCompletionHandler<Void> completionHandler)
          Processes a channel message sent by the associated client on the channel with the specified channelId, and invokes the completed method on the given completionHandler when this handler has completed processing the channel message.
 void disconnect(RequestCompletionHandler<Void> completionHandler)
          Notifies this handler that a non-graceful client disconnection has occurred, and invokes the completed method on the given completionHandler when this handler has completed processing the disconnection.
(package private)  SessionProtocol getSessionProtocol()
          Returns the protocol for the associated client session, or null if the session is relocating.
(package private)  void handleDisconnect(boolean graceful, boolean closeConnection)
          Handles disconnecting the associated client session (if not already handled) by doing the following: notifies the client session service to clean up the client session's handler and login information, notifies the node mapping service to deativate the client's identity if the identity is no longer active on this node, if closeConnection is true, closes this session's connection, if the session is terminating (not relocating), schedules a transactional task to invoke, on this session's ClientSessionListener, the disconnected callback with graceful as its argument and then clean up the session's persistent data, and also schedules a task to notify the identity that its corresponding session has logged out.
(package private)  boolean isConnected()
          Returns true if this handler is connected, otherwise returns false.
(package private)  boolean isRelocating()
          Returns true if this client session has begun preparing to relocate, or has relocated to another node.
(package private)  boolean loginHandled()
          Returns true if the login for this session has been handled, otherwise returns false.
 void logoutRequest(RequestCompletionHandler<Void> completionHandler)
          Processes a logout request from the associated client, and invokes the completed method on the given completionHandler when this handler has completed processing the logout request.
 void sessionMessage(ByteBuffer message, RequestCompletionHandler<Void> completionHandler)
          Processes a message sent by the associated client, and invokes the completed method on the given completionHandler when this handler has completed processing the message.
(package private)  void setRelocatePreparationComplete()
          Indicates that all parties are done with relocation preparation, and notifies the client that it should suspend messages (before notifying the client to relocate to another node).
(package private)  void shutdown()
          Flags this session as shut down, and closes the connection.
(package private)  boolean supportsRelocation()
          Returns true if this session's protocol handler supports relocation (i.e., implements the SessionRelocationProtocol interface; otherwise returns false.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RELOCATE_REFUSED_REASON

static final String RELOCATE_REFUSED_REASON
Message indicating relocation was refused for a non-specific reason.

See Also:
Constant Field Values

sessionRefId

volatile BigInteger sessionRefId
The session ID as a BigInteger.


identity

final Identity identity
The identity for this session.

Constructor Detail

ClientSessionHandler

ClientSessionHandler(ClientSessionServiceImpl sessionService,
                     DataService dataService,
                     SessionProtocol sessionProtocol,
                     Identity identity,
                     RequestCompletionHandler<SessionProtocolHandler> completionHandler)
Constructs an handler for a client session that is logging in.

Parameters:
sessionService - the ClientSessionService instance
dataService - the DataService instance
sessionProtocol - a session protocol
identity - an identity
completionHandler - a completion handler for the associated request

ClientSessionHandler

ClientSessionHandler(ClientSessionServiceImpl sessionService,
                     DataService dataService,
                     SessionProtocol sessionProtocol,
                     Identity identity,
                     RequestCompletionHandler<SessionProtocolHandler> completionHandler,
                     BigInteger sessionRefId)
Constructs an handler for a client session. If sessionRefId is non-null, then the associated client session is relocating from another node, otherwise it is considered a new client session logging in.

Parameters:
sessionService - the ClientSessionService instance
dataService - the DataService instance
sessionProtocol - a session protocol
identity - an identity
completionHandler - a completion handler for the associated request
sessionRefId - the client session ID, or null
Method Detail

sessionMessage

public void sessionMessage(ByteBuffer message,
                           RequestCompletionHandler<Void> completionHandler)
Processes a message sent by the associated client, and invokes the completed method on the given completionHandler when this handler has completed processing the message. 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 supplied to this method.

Specified by:
sessionMessage in interface SessionProtocolHandler
Parameters:
message - a message
completionHandler - a completion handler

channelMessage

public void channelMessage(BigInteger channelId,
                           ByteBuffer message,
                           RequestCompletionHandler<Void> completionHandler)
Processes a channel message sent by the associated client on the channel with the specified channelId, and invokes the completed method on the given completionHandler when this handler has completed processing the channel message. 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 supplied to this method.

Specified by:
channelMessage in interface SessionProtocolHandler
Parameters:
channelId - a channel ID
message - a message
completionHandler - a completion handler

logoutRequest

public void logoutRequest(RequestCompletionHandler<Void> completionHandler)
Processes a logout request from the associated client, and invokes the completed method on the given completionHandler when this handler has completed processing the logout request.

Specified by:
logoutRequest in interface SessionProtocolHandler
Parameters:
completionHandler - a completion handler

disconnect

public void disconnect(RequestCompletionHandler<Void> completionHandler)
Notifies this handler that a non-graceful client disconnection has occurred, and invokes the completed method on the given completionHandler when this handler has completed processing the disconnection.

Specified by:
disconnect in interface SessionProtocolHandler
Parameters:
completionHandler - a completion handler

toString

public String toString()

Overrides:
toString in class Object

isConnected

boolean isConnected()
Returns true if this handler is connected, otherwise returns false.

Returns:
true if this handler is connected

supportsRelocation

boolean supportsRelocation()
Returns true if this session's protocol handler supports relocation (i.e., implements the SessionRelocationProtocol interface; otherwise returns false.


isRelocating

boolean isRelocating()
Returns true if this client session has begun preparing to relocate, or has relocated to another node.


setRelocatePreparationComplete

void setRelocatePreparationComplete()
Indicates that all parties are done with relocation preparation, and notifies the client that it should suspend messages (before notifying the client to relocate to another node).


getSessionProtocol

SessionProtocol getSessionProtocol()
Returns the protocol for the associated client session, or null if the session is relocating.

Returns:
a protocol, or null if the session is relocating

loginHandled

boolean loginHandled()
Returns true if the login for this session has been handled, otherwise returns false.

Returns:
true if the login for this session has been handled

handleDisconnect

void handleDisconnect(boolean graceful,
                      boolean closeConnection)
Handles disconnecting the associated client session (if not already handled) by doing the following:
  1. notifies the client session service to clean up the client session's handler and login information,
  2. notifies the node mapping service to deativate the client's identity if the identity is no longer active on this node,
  3. if closeConnection is true, closes this session's connection,
  4. if the session is terminating (not relocating), schedules a transactional task to invoke, on this session's ClientSessionListener, the disconnected callback with graceful as its argument and then clean up the session's persistent data, and also schedules a task to notify the identity that its corresponding session has logged out.

Note:if graceful is true, then closeConnection must be false so that the client's SessionProtocol can send a notification of logout success to the client. The client may not receive such a notification if the connection is disconnected immediately.

In the cases of login redirection, session relocation, and graceful logout, it is the responsibility of the client's SessionProtocol to close the client's connection in a timely manner after notifying the client.

Parameters:
graceful - if true, indicates that disconnection is due to a (graceful) logout request
closeConnection - if true, close this session's connection immediately

shutdown

void shutdown()
Flags this session as shut down, and closes the connection.


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