public interface IChannel extends ILocationAware, IUserAware, IBufferHandler, INotifier, Closeable
buffers. 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 channel
multiplexer.
An example for opening a channel on an IConnector and sending an IBuffer:
// Open a channel IChannel channel = connector.openChannel(); short channelID = channel.getIndex(); // Fill a buffer Buffer buffer = bufferProvider.getBuffer(); ByteBuffer byteBuffer = buffer.startPutting(channelID); 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);
}
});
ILocationAware.Location| Modifier and Type | Method and Description |
|---|---|
short |
getID()
Returns the ID of this channel.
|
IChannelMultiplexer |
getMultiplexer()
Returns the multiplexer this channel is associated with.
|
long |
getReceivedBuffers()
Returns the number of
buffers that are received from the multiplexer of this channel
and are passed on to the receive handler of this channel. |
IBufferHandler |
getReceiveHandler()
Returns the
IBufferHandler that handles buffers received from the peer channel. |
long |
getSentBuffers()
Returns the number of
buffers that are sent to the multiplexer of this 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. |
getLocation, isClient, isServergetUserIDhandleBufferaddListener, getListeners, hasListeners, removeListenershort getID()
multiplexer.IChannelMultiplexer getMultiplexer()
void sendBuffer(IBuffer buffer)
IBufferHandler getReceiveHandler()
IBufferHandler that handles buffers received from the peer channel.void setReceiveHandler(IBufferHandler receiveHandler)
IBufferHandler to handle buffers received from the peer channel.long getSentBuffers()
buffers that are sent to the multiplexer of this channel.long getReceivedBuffers()
buffers that are received from the multiplexer of this channel
and are passed on to the receive handler of this channel.Copyright (c) 2004-2019 Eike Stepper (Loehne, Germany) and others.
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html