Interface IBuffer

All Known Subinterfaces:
InternalBuffer

public interface IBuffer
Basic unit of transport in Net4j.

A buffer is well prepared for the usage with asynchronous IChannels but can also be used with pure SocketChannels. All methods of IBuffer are non-blocking.

Usually buffers are obtained from a IBufferProvider. Buffers can be accessed, passed around and finally released to their original provider. The capacity of a buffer is determined by its provider.

In addition to its payload data each buffer contains an internal header of four bytes, two of them representing a channel identifier the other two of them denoting the length of the payload data. The payload data may be accessed through a ByteBuffer.

This interface is not intended to be implemented by clients.

An example for putting values into a buffer and writing it to a SocketChannel:

 // Obtain a fresh buffer
 Buffer buffer = bufferProvider.getBuffer(); // Start filling the buffer for channelID 4711 ByteBuffer byteBuffer =
 buffer.startPutting(4711); byteBuffer.putDouble(15.47); // Write the contents of the Buffer to a // SocketChannel
 without blocking while (!buffer.write(socketChannel)) { // Do something else }
 
An example for reading a buffer from a SocketChannel and getting values from it:

 // Obtain a fresh buffer
 Buffer buffer = bufferProvider.getBuffer();

 // Read the contents of the Buffer from a SocketChannel without blocking
 ByteBuffer byteBuffer;
 while ((byteBuffer = buffer.startGetting(socketChannel)) == null)
 {
   // Do something else
 }

 // Access the contents of the buffer and release it to its provider
 double value = byteBuffer.getDouble();
 buffer.release();
 
Author:
Eike Stepper
See Also:
No Implement
This interface is not intended to be implemented by clients.
No Extend
This interface is not intended to be extended by clients.