|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.sgs.impl.protocol.simple.SimpleSgsProtocolImpl
com.sun.sgs.impl.protocol.simple.SimpleSgsRelocationProtocolImpl
public class SimpleSgsRelocationProtocolImpl
Implements the protocol specified in SimpleSgsProtocol. The
implementation uses a wrapper channel, AsynchronousMessageChannel,
that reads and writes complete messages by framing messages with a 2-byte
message length, and masking (and re-issuing) partial I/O operations. Also
enforces a fixed buffer size when reading.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.sun.sgs.protocol.SessionProtocol |
|---|
SessionProtocol.DisconnectReason |
| Field Summary |
|---|
| Fields inherited from class com.sun.sgs.impl.protocol.simple.SimpleSgsProtocolImpl |
|---|
acceptor, deliverySet, listener, logger, protocolHandler, reconnectKey |
| Constructor Summary | |
|---|---|
(package private) |
SimpleSgsRelocationProtocolImpl(ProtocolListener listener,
SimpleSgsProtocolAcceptor acceptor,
AsynchronousByteChannel byteChannel,
int readBufferSize)
Creates a new instance of this class. |
protected |
SimpleSgsRelocationProtocolImpl(ProtocolListener listener,
SimpleSgsProtocolAcceptor acceptor,
AsynchronousByteChannel byteChannel,
int readBufferSize,
LoggerWrapper logger)
Constructs a new instance of this class. |
| Method Summary | |
|---|---|
void |
channelJoin(String name,
BigInteger channelId,
Delivery delivery)
Notifies the associated client that it is joined to the channel with the specified name and channelId. |
void |
channelLeave(BigInteger channelId)
Notifies the associated client that it is no longer a member of the channel with the specified channelId. |
void |
channelMessage(BigInteger channelId,
ByteBuffer message,
Delivery delivery)
Sends the associated client the specified channel message
for the channel with the specified channelId in a manner
that satisfies the specified delivery guarantee. |
protected byte |
getProtocolVersion()
Returns the SimpleSgsProtocol version supported by this
implementation. |
protected void |
handleMessageReceived(byte opcode,
MessageBuffer msg)
Handles v5 protocol messages (relocate and suspend), and delegates to the super class to handle the v4 protocol messages. |
void |
relocate(Set<ProtocolDescriptor> descriptors,
ByteBuffer relocationKey,
RequestCompletionHandler<Void> completionHandler)
Notifies the associated client to relocate its session to the node specified by the descriptors using the given relocationKey. |
void |
resume()
Notifies the associated client to resume sending messages to the server. |
void |
sessionMessage(ByteBuffer message,
Delivery delivery)
Sends the associated client the specified message in a
manner that satisfies the specified delivery guarantee. |
void |
suspend(RequestCompletionHandler<Void> completionHandler)
Notifies the associated client to suspend sending messages to the server until resume is invoked. |
| Methods inherited from class com.sun.sgs.impl.protocol.simple.SimpleSgsProtocolImpl |
|---|
close, disconnect, getDeliveries, getIdentity, getMaxMessageLength, isOpen, loginSuccess, monitorDisconnection, readNow, scheduleRead, toString, write, writeBuffer, writeNow |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.sun.sgs.protocol.SessionProtocol |
|---|
disconnect, getDeliveries, getMaxMessageLength |
| Methods inherited from interface java.nio.channels.Channel |
|---|
close, isOpen |
| Constructor Detail |
|---|
SimpleSgsRelocationProtocolImpl(ProtocolListener listener,
SimpleSgsProtocolAcceptor acceptor,
AsynchronousByteChannel byteChannel,
int readBufferSize)
listener - a protocol listeneracceptor - the SimpleSgsProtocol acceptorbyteChannel - a byte channel for the underlying connectionreadBufferSize - the read buffer size
protected SimpleSgsRelocationProtocolImpl(ProtocolListener listener,
SimpleSgsProtocolAcceptor acceptor,
AsynchronousByteChannel byteChannel,
int readBufferSize,
LoggerWrapper logger)
SimpleSgsProtocolImpl.scheduleRead() after constructing the
instance to commence reading.
listener - a protocol listeneracceptor - the SimpleSgsProtocol acceptorbyteChannel - a byte channel for the underlying connectionreadBufferSize - the read buffer sizelogger - a logger for this instance| Method Detail |
|---|
protected byte getProtocolVersion()
SimpleSgsProtocol version supported by this
implementation.
This implementation returns the latest SimpleSgsProtocol
version.
getProtocolVersion in class SimpleSgsProtocolImplSimpleSgsProtocol version supported by this
implementation
public void sessionMessage(ByteBuffer message,
Delivery delivery)
message in a
manner that satisfies the specified delivery guarantee.
When possible, the message should be delivered using the most
efficient means (e.g., protocol and transport) to satisfy the
delivery guarantee. However, a stronger delivery guarantee may be
used to deliver the message if this protocol only supports
stronger delivery guarantees. If this 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 is not modified and 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.
sessionMessage in interface SessionProtocolsessionMessage in class SimpleSgsProtocolImplmessage - a messagedelivery - the delivery guarantee
public void channelJoin(String name,
BigInteger channelId,
Delivery delivery)
name and channelId. This
notification to the client must be delivered reliably.
channelJoin in interface SessionProtocolchannelJoin in class SimpleSgsProtocolImplname - a channel namechannelId - the channel's IDdelivery - the channel's delivery guaranteepublic void channelLeave(BigInteger channelId)
channelId. This
notification to the client must be delivered reliably.
channelLeave in interface SessionProtocolchannelLeave in class SimpleSgsProtocolImplchannelId - a channel ID
public void channelMessage(BigInteger channelId,
ByteBuffer message,
Delivery delivery)
message
for the channel with the specified channelId in a manner
that satisfies the specified delivery guarantee.
When possible, the message should be delivered using the most
efficient means (e.g., protocol and transport) to satisfy the
delivery guarantee. However, a stronger delivery guarantee may be
used to deliver the message if this protocol only supports
stronger delivery guarantees. If this 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 is not modified and 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 implementation invokes the protected method writeBuffer with the channel protocol message (a
ByteBuffer) and the specified delivery requirement. A
subclass can override the writeBuffer method if it supports
other delivery guarantees and can make use of alternate transports
for those other delivery requirements.
channelMessage in interface SessionProtocolchannelMessage in class SimpleSgsProtocolImplchannelId - a channel IDmessage - a channel messagedelivery - the channel's delivery guaranteepublic void suspend(RequestCompletionHandler<Void> completionHandler)
resume is invoked. This method must
notify the completionHandler when messages have been
suspended. Messages received by the SessionProtocolHandler
will be received and processed until the completionHandler's
completed method is
invoked. If messages are not suspended in a timely fashion (i.e,
the completionHandler is not notified), then the server may
disconnect this session.
Only session messages that have their completion handlers notified
before the specified completionHandler is notified are
guaranteed to be processed by the server.
Once this method is invoked, an invocation on a method that sends a
message to the client should throw IllegalStateException
until messages are resumed.
suspend in interface SessionRelocationProtocolcompletionHandler - a completion handlerpublic void resume()
resume in interface SessionRelocationProtocol
public void relocate(Set<ProtocolDescriptor> descriptors,
ByteBuffer relocationKey,
RequestCompletionHandler<Void> completionHandler)
descriptors using the given relocationKey.
The associated client session can be reestablished on the new node
by notifying the ProtocolListener of this protocol's
corresponding ProtocolAcceptor on the new node. The ProtocolListener.relocatedSession
method can be invoked on the new node with the given relocation key
to reestablish the client session without having to log in again.
Once this method is invoked, an invocation on a method that sends a
message to the client should throw IllegalStateException.
Additionally, the client should close any underlying local
connection(s) in a timely fashion.
relocate in interface SessionRelocationProtocoldescriptors - protocol descriptors for newNoderelocationKey - the key to be supplied to the new nodecompletionHandler - a completion handler
protected void handleMessageReceived(byte opcode,
MessageBuffer msg)
handleMessageReceived in class SimpleSgsProtocolImplopcode - the message opcodemsg - a message buffer containing the entire message, but
with the position advanced to the payload (just after the
opcode)
|
RedDwarf, Version 0.10.1 2010-03-14 10:56:12 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||