org.fusesource.hawtdispatch.transport
Class AbstractProtocolCodec

java.lang.Object
  extended by org.fusesource.hawtdispatch.transport.AbstractProtocolCodec
All Implemented Interfaces:
ProtocolCodec

public abstract class AbstractProtocolCodec
extends Object
implements ProtocolCodec

Provides an abstract base class to make implementing the ProtocolCodec interface easier.

Author:
Hiram Chirino

Nested Class Summary
static interface AbstractProtocolCodec.Action
           
 
Nested classes/interfaces inherited from interface org.fusesource.hawtdispatch.transport.ProtocolCodec
ProtocolCodec.BufferState
 
Field Summary
protected  BufferPools bufferPools
           
protected  ByteBuffer directReadBuffer
           
protected  int lastReadIoSize
           
protected  long lastWriteIoSize
           
protected  AbstractProtocolCodec.Action nextDecodeAction
           
protected  org.fusesource.hawtbuf.DataByteArrayOutputStream nextWriteBuffer
           
protected  ByteBuffer readBuffer
           
protected  BufferPool readBufferPool
           
protected  int readBufferSize
           
protected  ReadableByteChannel readChannel
           
protected  long readCounter
           
protected  int readEnd
           
protected  int readStart
           
protected  LinkedList<ByteBuffer> writeBuffer
           
protected  BufferPool writeBufferPool
           
protected  int writeBufferSize
           
protected  GatheringByteChannel writeChannel
           
protected  long writeCounter
           
 
Constructor Summary
AbstractProtocolCodec()
           
 
Method Summary
protected abstract  void encode(Object value)
           
 ProtocolCodec.BufferState flush()
          Attempts to complete the previous write which did not complete.
protected  void flushNextWriteBuffer()
           
 boolean full()
          Is the codec's buffer full?
 BufferPools getBufferPools()
           
 long getLastReadSize()
           
 long getLastWriteSize()
           
 int getReadBufferSize()
           
 long getReadCounter()
           
 int getWriteBufferSize()
           
 long getWriteCounter()
           
protected abstract  AbstractProtocolCodec.Action initialDecodeAction()
           
 boolean isEmpty()
           
protected  void onBufferFlushed(ByteBuffer byteBuffer)
          Called when a buffer is flushed out.
protected  org.fusesource.hawtbuf.Buffer peekBytes(int length)
           
 Object read()
          Non-blocking channel based decoding.
protected  org.fusesource.hawtbuf.Buffer readBytes(int length)
           
protected  Boolean readDirect(ByteBuffer buffer)
           
protected  org.fusesource.hawtbuf.Buffer readUntil(Byte octet)
           
protected  org.fusesource.hawtbuf.Buffer readUntil(Byte octet, int max)
           
protected  org.fusesource.hawtbuf.Buffer readUntil(Byte octet, int max, String msg)
           
 void setBufferPools(BufferPools bufferPools)
           
 void setTransport(Transport transport)
           
 void unread(byte[] buffer)
          Pushes back a buffer as being unread.
 ProtocolCodec.BufferState write(Object value)
          Non-blocking channel based encoding.
protected  void writeDirect(ByteBuffer value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bufferPools

protected BufferPools bufferPools

writeBufferPool

protected BufferPool writeBufferPool

readBufferPool

protected BufferPool readBufferPool

writeBufferSize

protected int writeBufferSize

writeCounter

protected long writeCounter

writeChannel

protected GatheringByteChannel writeChannel

nextWriteBuffer

protected org.fusesource.hawtbuf.DataByteArrayOutputStream nextWriteBuffer

lastWriteIoSize

protected long lastWriteIoSize

writeBuffer

protected LinkedList<ByteBuffer> writeBuffer

readCounter

protected long readCounter

readBufferSize

protected int readBufferSize

readChannel

protected ReadableByteChannel readChannel

readBuffer

protected ByteBuffer readBuffer

directReadBuffer

protected ByteBuffer directReadBuffer

readEnd

protected int readEnd

readStart

protected int readStart

lastReadIoSize

protected int lastReadIoSize

nextDecodeAction

protected AbstractProtocolCodec.Action nextDecodeAction
Constructor Detail

AbstractProtocolCodec

public AbstractProtocolCodec()
Method Detail

setTransport

public void setTransport(Transport transport)
Specified by:
setTransport in interface ProtocolCodec

getReadBufferSize

public int getReadBufferSize()
Specified by:
getReadBufferSize in interface ProtocolCodec

getWriteBufferSize

public int getWriteBufferSize()
Specified by:
getWriteBufferSize in interface ProtocolCodec

full

public boolean full()
Description copied from interface: ProtocolCodec
Is the codec's buffer full?

Specified by:
full in interface ProtocolCodec
Returns:

isEmpty

public boolean isEmpty()

getWriteCounter

public long getWriteCounter()
Specified by:
getWriteCounter in interface ProtocolCodec
Returns:
The number of bytes written.

getLastWriteSize

public long getLastWriteSize()
Specified by:
getLastWriteSize in interface ProtocolCodec
Returns:
The number of bytes read in the last write io performed.

encode

protected abstract void encode(Object value)
                        throws IOException
Throws:
IOException

write

public ProtocolCodec.BufferState write(Object value)
                                throws IOException
Description copied from interface: ProtocolCodec
Non-blocking channel based encoding.

Specified by:
write in interface ProtocolCodec
Returns:
true if the write completed.
Throws:
IOException

writeDirect

protected void writeDirect(ByteBuffer value)
                    throws IOException
Throws:
IOException

flushNextWriteBuffer

protected void flushNextWriteBuffer()

flush

public ProtocolCodec.BufferState flush()
                                throws IOException
Description copied from interface: ProtocolCodec
Attempts to complete the previous write which did not complete.

Specified by:
flush in interface ProtocolCodec
Returns:
Throws:
IOException

onBufferFlushed

protected void onBufferFlushed(ByteBuffer byteBuffer)
Called when a buffer is flushed out. Subclasses can implement in case they want to recycle the buffer.

Parameters:
byteBuffer -

initialDecodeAction

protected abstract AbstractProtocolCodec.Action initialDecodeAction()

unread

public void unread(byte[] buffer)
Description copied from interface: ProtocolCodec
Pushes back a buffer as being unread.

Specified by:
unread in interface ProtocolCodec

getReadCounter

public long getReadCounter()
Specified by:
getReadCounter in interface ProtocolCodec
Returns:
The number of bytes received.

getLastReadSize

public long getLastReadSize()
Specified by:
getLastReadSize in interface ProtocolCodec
Returns:
The number of bytes read in the last read io performed.

read

public Object read()
            throws IOException
Description copied from interface: ProtocolCodec
Non-blocking channel based decoding.

Specified by:
read in interface ProtocolCodec
Returns:
Throws:
IOException

readUntil

protected org.fusesource.hawtbuf.Buffer readUntil(Byte octet)
                                           throws ProtocolException
Throws:
ProtocolException

readUntil

protected org.fusesource.hawtbuf.Buffer readUntil(Byte octet,
                                                  int max)
                                           throws ProtocolException
Throws:
ProtocolException

readUntil

protected org.fusesource.hawtbuf.Buffer readUntil(Byte octet,
                                                  int max,
                                                  String msg)
                                           throws ProtocolException
Throws:
ProtocolException

readBytes

protected org.fusesource.hawtbuf.Buffer readBytes(int length)

peekBytes

protected org.fusesource.hawtbuf.Buffer peekBytes(int length)

readDirect

protected Boolean readDirect(ByteBuffer buffer)

getBufferPools

public BufferPools getBufferPools()

setBufferPools

public void setBufferPools(BufferPools bufferPools)


Copyright © 2010-2014 FuseSource, Corp.. All Rights Reserved.