com.buildforge.services.client.api
Class APIClientBuffer

java.lang.Object
  extended by com.buildforge.services.client.api.APIClientBuffer
All Implemented Interfaces:
IBufferedConnection
Direct Known Subclasses:
SecureAPIClientBuffer

public class APIClientBuffer
extends java.lang.Object
implements IBufferedConnection

This class wraps a socket channel with the IBufferedConnection interface so that it can be used by the API protocol.


Method Summary
 void close()
          Shuts down the connection, after which time it should no longer be used.
 int fill(int want)
          Requests that the read buffer be refilled.
 void flush()
          Finishes off the current write buffer and tries to send it.
 java.nio.ByteBuffer getReadBuffer()
          Provides direct access to the connection's read buffer.
 boolean getStrict()
          Returns whether or not this client buffer is strict.
 java.nio.ByteBuffer getWriteBuffer()
          Provides direct access to the connection's write buffer.
 void setCallback(IBufferedConnectionCallback callback)
          Sets the callback for activity on the connection and initializes the request dispatching mechanism (optional).
 void setStrict(boolean strict)
          Controls whether or not this client buffer will be strict.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getStrict

public boolean getStrict()
Returns whether or not this client buffer is strict.

Returns:
true if the buffer is strict
See Also:
setStrict(boolean)

setStrict

public void setStrict(boolean strict)
Controls whether or not this client buffer will be strict. If a client buffer is in strict mode, then fill(int) will never return more bytes than are requested. This will generally be neither necessary nor as efficient as allowing the buffer to be filled with whatever is available, so stict mode is off by default.

Parameters:
strict - true to enable strict mode

getReadBuffer

public java.nio.ByteBuffer getReadBuffer()
Description copied from interface: IBufferedConnection
Provides direct access to the connection's read buffer.

Specified by:
getReadBuffer in interface IBufferedConnection
Returns:
the read buffer

getWriteBuffer

public java.nio.ByteBuffer getWriteBuffer()
Description copied from interface: IBufferedConnection
Provides direct access to the connection's write buffer.

Specified by:
getWriteBuffer in interface IBufferedConnection
Returns:
the write buffer

fill

public int fill(int want)
         throws java.io.IOException
Description copied from interface: IBufferedConnection
Requests that the read buffer be refilled. The caller is guaranteed that either the requested number of bytes will be read or the buffer will be filled to its maximum capacity.

Specified by:
fill in interface IBufferedConnection
Parameters:
want - the number of bytes that the caller would like to be read into the buffer before returning control to the caller
Returns:
the number of bytes actually read, which may be less than want if the buffer is not large enough to hold that much information, or greater than want if additional bytes of information were available without blocking
Throws:
java.io.IOException - if an I/O error occurs or the connection closes before the requested number of bytes have been read

flush

public void flush()
           throws java.io.IOException
Description copied from interface: IBufferedConnection
Finishes off the current write buffer and tries to send it. If writes are busy, then we delegate the write activity to the dispatcher, which will let us know when it's done.

Specified by:
flush in interface IBufferedConnection
Throws:
java.io.IOException - if an I/O error occurs

setCallback

public void setCallback(IBufferedConnectionCallback callback)
Description copied from interface: IBufferedConnection
Sets the callback for activity on the connection and initializes the request dispatching mechanism (optional). Not all buffered connections will need a callback mechanism.

Specified by:
setCallback in interface IBufferedConnection
Parameters:
callback - the callback to use for activity

close

public void close()
           throws java.io.IOException
Description copied from interface: IBufferedConnection
Shuts down the connection, after which time it should no longer be used.

Specified by:
close in interface IBufferedConnection
Throws:
java.io.IOException - if an I/O error occurs