org.apache.catalina.cluster.io
public class: ObjectReader [javadoc |
source]
java.lang.Object
org.apache.catalina.cluster.io.ObjectReader
The object reader object is an object used in conjunction with
java.nio TCP messages. This object stores the message bytes in a
XByteBuffer until a full package has been received.
When a full package has been received, the append method will call messageDataReceived
on the callback object associated with this object reader.
This object uses an XByteBuffer which is an extendable object buffer that also allows
for message encoding and decoding.
- author:
Filip - Hanik
- author:
Peter - Rossbach
- version:
$ - Revision: 304032 $, $Date: 2005-07-27 11:11:55 -0400 (Wed, 27 Jul 2005) $
| Constructor: |
public ObjectReader(SocketChannel channel,
Selector selector,
ListenCallback callback) {
this.channel = channel;
this.selector = selector;
this.callback = callback;
this.buffer = new XByteBuffer();
}
Create XByteBuffer and store parameter Parameters:
channel -
selector -
callback -
|
| Method from org.apache.catalina.cluster.io.ObjectReader Detail: |
public int append(byte[] data,
int off,
int len) throws IOException {
buffer.append(data,off,len);
int pkgCnt = buffer.countPackages();
return pkgCnt;
}
Append new bytes to buffer. |
public int execute() throws IOException {
int pkgCnt = 0;
boolean pkgExists = buffer.doesPackageExist();
while ( pkgExists ) {
ClusterData data = buffer.extractPackage(true);
getCallback().messageDataReceived(data);
pkgCnt++;
pkgExists = buffer.doesPackageExist();
}
return pkgCnt;
}
Send buffer to cluster listener (callback).
Is message complete receiver send message to callback? |
public ListenCallback getCallback() {
return callback;
}
get the current SimpleTcpCluster |
public SocketChannel getChannel() {
return this.channel;
}
Get underlying NIO channel |
public int write(ByteBuffer buf) throws IOException {
return getChannel().write(buf);
}
|