## org.apache.catalina.cluster.io
Class ObjectReader

    java.lang.Object
      org.apache.catalina.cluster.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 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.

Version:
  $Id: ObjectReader.java 939539 2010-04-30 01:31:33Z kkolinko $
Author:
  Filip Hanik, Peter Rossbach

Constructor Summary
`ObjectReader(java.nio.channels.SocketChannel channel, java.nio.channels.Selector selector, ListenCallback callback)` Create XByteBuffer and store parameter

Method Summary
`int` `append(byte[] data, int off, int len)` Append new bytes to buffer.
`int` `execute()` Send buffer to cluster listener (callback).
`ListenCallback` `getCallback()` get the current SimpleTcpCluster
`java.nio.channels.SocketChannel` `getChannel()` Get underlying NIO channel
`int` `write(java.nio.ByteBuffer buf)` Write Ack to sender

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ObjectReader

    public ObjectReader(java.nio.channels.SocketChannel channel,
                        java.nio.channels.Selector selector,
                        ListenCallback callback)

  Create XByteBuffer and store parameter

Parameters:
  `channel` -
  `selector` -
  `callback` -

Method Detail

### getCallback

    public ListenCallback getCallback()

  get the current SimpleTcpCluster

  Returns:
    Returns the callback.

### getChannel

    public java.nio.channels.SocketChannel getChannel()

  Get underlying NIO channel

  Returns:
    The socket

### append

    public int append(byte[] data,
                      int off,
                      int len)
               throws java.io.IOException

  Append new bytes to buffer.

  Parameters:
    `data` - new transfer buffer
    `off` - offset
    `len` - length in buffer
  Returns:
    number of messages that sended to callback
  Throws:
    `java.io.IOException`
  See Also:
    `XByteBuffer.countPackages()`

### execute

    public int execute()
                throws java.io.IOException

  Send buffer to cluster listener (callback). Is message complete receiver send message to callback?

  Returns:
    number of received packages/messages
  Throws:
    `java.io.IOException`
  See Also:
    `ClusterReceiverBase.messageDataReceived(ClusterData)`, `XByteBuffer.doesPackageExist()`, `XByteBuffer.extractPackage(boolean)`

### write

    public int write(java.nio.ByteBuffer buf)
              throws java.io.IOException

  Write Ack to sender

  Parameters:
    `buf` -
  Returns:
    The bytes written count
  Throws:
    `java.io.IOException`

Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.