|
||||||||||
| 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
public class SimpleSgsProtocolImpl
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 | |
|---|---|
protected SimpleSgsProtocolAcceptor |
acceptor
This protocol's acceptor. |
protected Set<Delivery> |
deliverySet
The set of supported delivery requirements. |
protected ProtocolListener |
listener
The protocol listener. |
protected LoggerWrapper |
logger
The logger for this instance. |
protected SessionProtocolHandler |
protocolHandler
The protocol handler. |
protected byte[] |
reconnectKey
The reconnect key. |
| Constructor Summary | |
|---|---|
(package private) |
SimpleSgsProtocolImpl(ProtocolListener listener,
SimpleSgsProtocolAcceptor acceptor,
AsynchronousByteChannel byteChannel,
int readBufferSize)
Creates a new instance of this class. |
protected |
SimpleSgsProtocolImpl(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. |
void |
close()
|
void |
disconnect(SessionProtocol.DisconnectReason reason)
Disconnects the associated session for the specified reason. |
Set<Delivery> |
getDeliveries()
Returns a set containing the delivery guarantees supported by this protocol. |
protected Identity |
getIdentity()
Returns the associated identity, or null if the client has
not yet authenticated. |
int |
getMaxMessageLength()
Returns the maximum length, in bytes, of the buffers passed as the message parameters to the
sessionMessage and
channelMessage methods. |
protected byte |
getProtocolVersion()
Returns the SimpleSgsProtocol version supported by this
implementation. |
protected void |
handleMessageReceived(byte opcode,
MessageBuffer msg)
Processes the received message. |
boolean |
isOpen()
|
protected void |
loginSuccess()
Notifies the associated client that the previous login attempt was successful. |
protected void |
monitorDisconnection()
Monitors the client's disconnection and closes this instance's underlying connection if the client hasn't closed the connection in a timely fashion. |
protected void |
readNow()
Resumes reading from the underlying connection. |
protected void |
scheduleRead()
Schedules an asynchronous task to resume reading. |
void |
sessionMessage(ByteBuffer message,
Delivery delivery)
Sends the associated client the specified message in a
manner that satisfies the specified delivery guarantee. |
String |
toString()
|
protected void |
write(ByteBuffer buf)
Writes a message to the underlying connection if login has been handled, otherwise enqueues the message to be sent when the login has not yet been handled. |
protected void |
writeBuffer(ByteBuffer buf,
Delivery delivery)
Writes the specified buffer, satisfying the specified delivery requirement. |
protected void |
writeNow(ByteBuffer message,
boolean flush)
Writes a message to the underlying connection. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected volatile SessionProtocolHandler protocolHandler
protected final SimpleSgsProtocolAcceptor acceptor
protected final LoggerWrapper logger
protected final ProtocolListener listener
protected final byte[] reconnectKey
protected final Set<Delivery> deliverySet
| Constructor Detail |
|---|
SimpleSgsProtocolImpl(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 SimpleSgsProtocolImpl(ProtocolListener listener,
SimpleSgsProtocolAcceptor acceptor,
AsynchronousByteChannel byteChannel,
int readBufferSize,
LoggerWrapper logger)
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.
SimpleSgsProtocol version supported by this
implementationprotected Identity getIdentity()
null if the client has
not yet authenticated.
nullpublic Set<Delivery> getDeliveries()
getDeliveries in interface SessionProtocolpublic int getMaxMessageLength()
message parameters to the
sessionMessage and
channelMessage methods.
getMaxMessageLength in interface SessionProtocol
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 SessionProtocolmessage - 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 SessionProtocolname - 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 SessionProtocolchannelId - 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 SessionProtocolchannelId - a channel IDmessage - a channel messagedelivery - the channel's delivery guarantee
public void disconnect(SessionProtocol.DisconnectReason reason)
throws IOException
reason.
The protocol may send a message to the associated client indicating
the reason for the disconnection, or the protocol may close the
connection immediately. Any underlying connection(s) should be
closed in a timely fashion.
disconnect in interface SessionProtocolreason - the reason for disconnection
IOException - if an I/O error occursprotected void loginSuccess()
public boolean isOpen()
isOpen in interface Channelpublic void close()
close in interface Closeableclose in interface Channelpublic String toString()
toString in class Objectprotected final void scheduleRead()
protected final void readNow()
protected final void write(ByteBuffer buf)
buf - a buffer containing a complete protocol message
protected final void writeNow(ByteBuffer message,
boolean flush)
message - a buffer containing a complete protocol messageflush - if true, then set the loginHandled
flag to true and flush the message queue
protected void writeBuffer(ByteBuffer buf,
Delivery delivery)
This implementation writes the buffer reliably, because this protocol only supports reliable delivery.
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.
buf - a byte buffer containing a protocol messagedelivery - a delivery requirement
protected void handleMessageReceived(byte opcode,
MessageBuffer msg)
SimpleSgsProtocol version 0x04. A
subclass can override this implementation to process additional
opcodes, and then delegate to this implementation to process the
version 0x04 opcodes.
opcode - the message opcodemsg - a message buffer containing the entire message, but
with the position advanced to the payload (just after the
opcode)protected void monitorDisconnection()
|
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 | |||||||||