Class 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. 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
      Whether this reader is currently being accessed.
      protected long lastAccess
      Timestamp of the last access.
      protected static StringManager sm
      String manager for internationalization.
    • Constructor Summary

      Constructors 
      Constructor Description
      ObjectReader​(int packetSize)
      Creates an ObjectReader with the specified packet size.
      ObjectReader​(java.net.Socket socket)
      Creates an ObjectReader for a TCP socket
      ObjectReader​(java.nio.channels.SocketChannel channel)
      Creates an ObjectReader for a TCP NIO socket channel
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void access()
      Marks this reader as being accessed.
      int append​(byte[] data, int off, int len, boolean count)
      Appends new bytes to the buffer.
      int append​(java.nio.ByteBuffer data, int len, boolean count)
      Append new bytes to buffer.
      int bufferSize()
      Returns the current buffer size.
      void close()
      Closes this reader and releases the buffer.
      int count()
      Returns the number of packages that the reader has read
      ChannelMessage[] execute()
      Send buffer to cluster listener (callback).
      void finish()
      Marks this reader as no longer being accessed.
      long getLastAccess()
      Returns the timestamp of the last access.
      boolean hasPackage()
      Checks if there is a complete package available.
      boolean isAccessed()
      Checks if this reader is currently being accessed.
      boolean isCancelled()
      Checks if this reader has been cancelled.
      void setCancelled​(boolean cancelled)
      Sets the cancelled state of this reader.
      void setLastAccess​(long lastAccess)
      Sets the timestamp of the last access.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • sm

        protected static final StringManager sm
        String manager for internationalization.
      • lastAccess

        protected long lastAccess
        Timestamp of the last access.
      • accessed

        protected boolean accessed
        Whether this reader is currently being accessed.
    • Constructor Detail

      • ObjectReader

        public ObjectReader​(int packetSize)
        Creates an ObjectReader with the specified packet size.
        Parameters:
        packetSize - The initial packet buffer size
      • ObjectReader

        public ObjectReader​(java.nio.channels.SocketChannel channel)
        Creates an ObjectReader for a TCP NIO socket channel
        Parameters:
        channel - - the channel to be read.
      • ObjectReader

        public ObjectReader​(java.net.Socket socket)
        Creates an ObjectReader for a TCP socket
        Parameters:
        socket - Socket
    • Method Detail

      • access

        public void access()
        Marks this reader as being accessed.
      • finish

        public void finish()
        Marks this reader as no longer being accessed.
      • isAccessed

        public boolean isAccessed()
        Checks if this reader is currently being accessed.
        Returns:
        true if the reader is being accessed
      • append

        public int append​(java.nio.ByteBuffer data,
                          int len,
                          boolean count)
        Append new bytes to buffer.
        Parameters:
        data - new transfer buffer
        len - length in buffer
        count - 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)
        Appends new bytes to the buffer.
        Parameters:
        data - The byte array
        off - The offset in the array
        len - The length of data
        count - Whether to count packages
        Returns:
        Number of messages sent to callback, or -1 if count is false
      • bufferSize

        public int bufferSize()
        Returns the current buffer size.
        Returns:
        The buffer length
      • hasPackage

        public boolean hasPackage()
        Checks if there is a complete package available.
        Returns:
        true if a complete package exists
      • count

        public int count()
        Returns the number of packages that the reader has read
        Returns:
        int
      • close

        public void close()
        Closes this reader and releases the buffer.
      • getLastAccess

        public long getLastAccess()
        Returns the timestamp of the last access.
        Returns:
        The last access timestamp
      • isCancelled

        public boolean isCancelled()
        Checks if this reader has been cancelled.
        Returns:
        true if cancelled
      • setLastAccess

        public void setLastAccess​(long lastAccess)
        Sets the timestamp of the last access.
        Parameters:
        lastAccess - The last access timestamp
      • setCancelled

        public void setCancelled​(boolean cancelled)
        Sets the cancelled state of this reader.
        Parameters:
        cancelled - The cancelled state