net.gleamynode.netty2
Interface Message


public interface Message

An interface that represents a message read from/written into channels. It should know how to read/write itself from/into the channel.

Please use instanceof operator to determine the type of the message.

Version:
$Rev: 4 $, $Date: 2005-04-18 12:04:09 +0900 $
Author:
Trustin Lee (http://gleamynode.net/dev/)

Method Summary
 boolean read(ByteBuffer buffer)
          Reads the message from the specified buffer.
 boolean write(ByteBuffer buffer)
          Writes this message into the specified buffer.
 

Method Detail

read

public boolean read(ByteBuffer buffer)
             throws MessageParseException
Reads the message from the specified buffer. I/O worker thread reads incoming data from the channel into the buffer, flips it, and passes it as an argument; the position will be 0 and limit will be the number of bytes read.

Returns:
true if the message is read fully. false if the buffer is exhausted and more bytes are left to read, or if more bytes are required to complete the message.
Throws:
MessageParseException - if the bytes in the buffer is not understandable.

write

public boolean write(ByteBuffer buffer)
Writes this message into the specified buffer. I/O worker thread will flip the buffer and write it into the channel until this method returns true. the position will be 0 and limit will be the same as capacity.

Returns:
true if the message is written fully. false if the buffer is full and more bytes are left to write, or the message wants to write the remainder at next invocation.


Copyright © 2004-2007 Trustin Lee. All Rights Reserved.