Package org.apache.catalina.tribes.io
Class ObjectReader
- java.lang.Object
-
- org.apache.catalina.tribes.io.ObjectReader
-
public class ObjectReader extends java.lang.Object
The object reader object is an object used in conjunction with java.nio TCP messages. This object stores the message bytes in aXByteBuffer
until a full package has been received. This object uses an XByteBuffer which is an extendable object buffer that also allows for message encoding and decoding.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
accessed
protected long
lastAccess
protected static StringManager
sm
-
Constructor Summary
Constructors Constructor Description ObjectReader(int packetSize)
ObjectReader(java.net.Socket socket)
Creates anObjectReader
for a TCP socketObjectReader(java.nio.channels.SocketChannel channel)
Creates anObjectReader
for a TCP NIO socket channel
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
access()
int
append(byte[] data, int off, int len, boolean count)
int
append(java.nio.ByteBuffer data, int len, boolean count)
Append new bytes to buffer.int
bufferSize()
void
close()
int
count()
Returns the number of packages that the reader has readChannelMessage[]
execute()
Send buffer to cluster listener (callback).void
finish()
long
getLastAccess()
boolean
hasPackage()
boolean
isAccessed()
boolean
isCancelled()
void
setCancelled(boolean cancelled)
void
setLastAccess(long lastAccess)
-
-
-
Field Detail
-
sm
protected static final StringManager sm
-
lastAccess
protected long lastAccess
-
accessed
protected boolean accessed
-
-
Constructor Detail
-
ObjectReader
public ObjectReader(int packetSize)
-
ObjectReader
public ObjectReader(java.nio.channels.SocketChannel channel)
Creates anObjectReader
for a TCP NIO socket channel- Parameters:
channel
- - the channel to be read.
-
ObjectReader
public ObjectReader(java.net.Socket socket)
Creates anObjectReader
for a TCP socket- Parameters:
socket
- Socket
-
-
Method Detail
-
access
public void access()
-
finish
public void finish()
-
isAccessed
public boolean isAccessed()
-
append
public int append(java.nio.ByteBuffer data, int len, boolean count)
Append new bytes to buffer.- Parameters:
data
- new transfer bufferlen
- length in buffercount
- whether to return the count- Returns:
- number of messages that was sent to callback (or -1 if count == false)
- See Also:
XByteBuffer.countPackages()
-
append
public int append(byte[] data, int off, int len, boolean count)
-
execute
public ChannelMessage[] execute()
Send buffer to cluster listener (callback). Is message complete receiver send message to callback?- Returns:
- number of received packages/messages
- See Also:
ReceiverBase.messageDataReceived(ChannelMessage)
,XByteBuffer.doesPackageExist()
,XByteBuffer.extractPackage(boolean)
-
bufferSize
public int bufferSize()
-
hasPackage
public boolean hasPackage()
-
count
public int count()
Returns the number of packages that the reader has read- Returns:
- int
-
close
public void close()
-
getLastAccess
public long getLastAccess()
-
isCancelled
public boolean isCancelled()
-
setLastAccess
public void setLastAccess(long lastAccess)
-
setCancelled
public void setCancelled(boolean cancelled)
-
-