|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.sgs.impl.protocol.simple.AsynchronousMessageChannel
public class AsynchronousMessageChannel
A wrapper channel 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.
| Field Summary | |
|---|---|
(package private) AsynchronousByteChannel |
channel
The underlying channel (possibly another layer of abstraction, e.g. |
(package private) static LoggerWrapper |
logger
The logger for this class. |
static int |
PREFIX_LENGTH
The number of bytes used to represent the message length. |
(package private) ByteBuffer |
readBuffer
The read buffer. |
(package private) AtomicBoolean |
readPending
Whether there is a read underway. |
(package private) AtomicBoolean |
writePending
Whether there is a write underway. |
| Constructor Summary | |
|---|---|
AsynchronousMessageChannel(AsynchronousByteChannel channel,
int readBufferSize)
Creates a new instance of this class with the given channel and read buffer size. |
|
| Method Summary | |
|---|---|
void |
close()
|
(package private) int |
getMessageLength()
Returns the length of the complete message, including the length prefix, based on the data read into the buffer between position 0 and the current position, or -1 if the length cannot be determined. |
boolean |
isOpen()
|
IoFuture<ByteBuffer,Void> |
read(CompletionHandler<ByteBuffer,Void> handler)
Initiates reading a complete message from this channel. |
IoFuture<Void,Void> |
write(ByteBuffer src,
CompletionHandler<Void,Void> handler)
Initiates writing a complete message from the given buffer to the underlying channel, and returns a future for controlling the operation. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int PREFIX_LENGTH
static final LoggerWrapper logger
final AsynchronousByteChannel channel
final AtomicBoolean readPending
final AtomicBoolean writePending
final ByteBuffer readBuffer
| Constructor Detail |
|---|
public AsynchronousMessageChannel(AsynchronousByteChannel channel,
int readBufferSize)
channel - a channelreadBufferSize - the number of bytes in the read buffer
IllegalArgumentException - if readBufferSize is smaller
than 2| Method Detail |
|---|
public IoFuture<ByteBuffer,Void> read(CompletionHandler<ByteBuffer,Void> handler)
handler when the read operation has
completed, if handler is not null. The buffer's
position will be set to 0 and it's limit will be set to the
length of the complete message. The contents of the buffer will remain
valid until the next call to read.
handler - the completion handler object; can be null
BufferOverflowException - if the buffer does not contain enough
space to read the next message
ReadPendingException - if a read is in progress
public IoFuture<Void,Void> write(ByteBuffer src,
CompletionHandler<Void,Void> handler)
src - the buffer from which bytes are to be retrievedhandler - the completion handler object; can be null
WritePendingException - if a write is in progress
public void close()
throws IOException
close in interface Closeableclose in interface ChannelIOExceptionpublic boolean isOpen()
isOpen in interface Channelint getMessageLength()
-1 if the length cannot be determined.
-1
|
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 | |||||||||