com.buildforge.services.common.io
Interface IBufferedConnection

All Known Implementing Classes:
APIClientBuffer, SecureAPIClientBuffer

public interface IBufferedConnection

This functionality must be provided by the underlying communication layer in order to attach the API protocol to it.


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.
 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).
 

Method Detail

getReadBuffer

java.nio.ByteBuffer getReadBuffer()
Provides direct access to the connection's read buffer.

Returns:
the read buffer

getWriteBuffer

java.nio.ByteBuffer getWriteBuffer()
Provides direct access to the connection's write buffer.

Returns:
the write buffer

fill

int fill(int want)
         throws java.io.IOException
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.

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

void flush()
           throws java.io.IOException
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.

Throws:
java.io.IOException - if an I/O error occurs

close

void close()
           throws java.io.IOException
Shuts down the connection, after which time it should no longer be used.

Throws:
java.io.IOException - if an I/O error occurs

setCallback

void setCallback(IBufferedConnectionCallback callback)
                 throws java.io.IOException
Sets the callback for activity on the connection and initializes the request dispatching mechanism (optional). Not all buffered connections will need a callback mechanism.

Parameters:
callback - the callback to use for activity
Throws:
java.lang.UnsupportedOperationException - if callbacks are not implemented
java.io.IOException - if an I/O error occurs