org.eclipse.net4j.channel
Interface IChannel

All Superinterfaces:
IBufferHandler, INotifier
All Known Subinterfaces:
InternalChannel

public interface IChannel
extends IBufferHandler, INotifier

A bidirectional communications channel for the asynchronous exchange of IBuffers. A channel is lightweight and virtual in the sense that it does not necessarily represent a single physical connection like a TCP socket connection. The underlying physical connection is represented by a IConnector.

This interface is not intended to be implemented by clients. Providers of channels (for example for new physical connection types) have to extend/subclass InternalChannel.

Class Diagram:

Sequence Diagram: Communication Process

An example for opening a channel on an IConnector and sending an IBuffer:

 // Open a channel
 IChannel channel = connector.openChannel(); short channelIndex = channel.getChannelIndex(); // Fill a buffer Buffer
 buffer = bufferProvider.getBuffer(); ByteBuffer byteBuffer = buffer.startPutting(channelIndex);
 byteBuffer.putDouble(15.47); // Let the channel send the buffer without blocking channel.sendBuffer(buffer); 

An example for receiving IBuffers from channels on an IConnector:

 // Create a receive
 handler final IBufferHandler receiveHandler = new IBufferHandler() { public void handleBuffer(IBuffer buffer) {
 ByteBuffer byteBuffer = buffer.getByteBuffer(); IOUtil.OUT().println("Received " + byteBuffer.getDouble());
 buffer.release(); } }; // Set the receive handler to all new channels connector.addListener(new
 ContainerEventAdapter() { protected void onAdded(IContainer container, Object element) { IChannel channel =
 (IChannel)element; channel.setReceiveHandler(receiveHandler); } }); 


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.eclipse.net4j.util.event.INotifier
INotifier.Introspection
 
Method Summary
 void close()
          Closes this channel and removes it from its IConnector.
 int getChannelID()
          Returns the ID of this channel that is unique among all channels that the connector of this channel has ever created or will ever create.
 short getChannelIndex()
          Returns the index of this channel within the array of channels returned from the getChannels() method of the connector of this channel.
 IBufferHandler getReceiveHandler()
          Returns the IBufferHandler that handles buffers received from the peer channel.
 void sendBuffer(IBuffer buffer)
          Asynchronously sends the given buffer to the receive handler of the peer channel.
 void setReceiveHandler(IBufferHandler receiveHandler)
          Sets the IBufferHandler to handle buffers received from the peer channel.
 
Methods inherited from interface org.eclipse.net4j.buffer.IBufferHandler
handleBuffer
 
Methods inherited from interface org.eclipse.net4j.util.event.INotifier
addListener, removeListener
 

Method Detail

getChannelID

int getChannelID()
Returns the ID of this channel that is unique among all channels that the connector of this channel has ever created or will ever create.


getChannelIndex

short getChannelIndex()
Returns the index of this channel within the array of channels returned from the getChannels() method of the connector of this channel.


sendBuffer

void sendBuffer(IBuffer buffer)
Asynchronously sends the given buffer to the receive handler of the peer channel.


getReceiveHandler

IBufferHandler getReceiveHandler()
Returns the IBufferHandler that handles buffers received from the peer channel.


setReceiveHandler

void setReceiveHandler(IBufferHandler receiveHandler)
Sets the IBufferHandler to handle buffers received from the peer channel.


close

void close()
Closes this channel and removes it from its IConnector.

Once a channel has been closed it is not allowed anymore to call its sendBuffer(IBuffer) method.


Copyright (c) 2004 - 2008 Eike Stepper, Germany.
All Rights Reserved.