org.activeio.net
Class NIOSyncChannel
java.lang.Object
org.activeio.net.NIOBaseChannel
org.activeio.net.NIOSyncChannel
- All Implemented Interfaces:
- Channel, Disposable, InputSyncChannel, OutputChannel, Service, SocketMetadata, SyncChannel
- public final class NIOSyncChannel
- extends NIOBaseChannel
- implements SyncChannel
A org.activeio.SynchChannel
implementation that uses a SocketChannel
to talk to the network.
Using a SocketChannelSynchChannel should be more efficient than using a SocketSynchChannel since
direct ByteBuffer can be used to reduce the jvm overhead needed to copy byte[]s.
- Version:
- $Revision$
Method Summary |
Packet |
read(long timeout)
Used to synchronously receive a packet of information going 'up' the channel. |
void |
start()
Starts the channel. |
void |
stop(long timeout)
Stops the channel. |
void |
write(Packet packet)
Sends a packet down the channel towards the media. |
Methods inherited from class org.activeio.net.NIOBaseChannel |
allocateBuffer, dispose, flush, getInetAddress, getKeepAlive, getLocalAddress, getLocalPort, getLocalSocketAddress, getOOBInline, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoLinger, getSoTimeout, getTcpNoDelay, getTrafficClass, isBound, isClosed, isConnected, narrow, setKeepAlive, setOOBInline, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoLinger, setSoTimeout, setTcpNoDelay, setTrafficClass, toString |
NIOSyncChannel
protected NIOSyncChannel(SocketChannel socketChannel)
throws IOException
NIOSyncChannel
protected NIOSyncChannel(SocketChannel socketChannel,
boolean useDirect)
throws IOException
read
public Packet read(long timeout)
throws IOException
- Description copied from interface:
InputSyncChannel
- Used to synchronously receive a packet of information going 'up' the channel.
This method blocks until a packet is received or the operation experiences timeout.
- Specified by:
read
in interface InputSyncChannel
- Parameters:
timeout
-
- Returns:
- the packet received or null if the timeout occurred.
- Throws:
IOException
write
public void write(Packet packet)
throws IOException
- Description copied from interface:
OutputChannel
- Sends a packet down the channel towards the media.
- Specified by:
write
in interface OutputChannel
- Parameters:
packet
-
- Throws:
IOException
start
public void start()
throws IOException
- Description copied from interface:
Service
- Starts the channel. Once started, the channel is in the running state.
- Specified by:
start
in interface Service
- Throws:
IOException
stop
public void stop(long timeout)
throws IOException
- Description copied from interface:
Service
- Stops the channel. Once stopped, the channel is in the stopped state.
- Specified by:
stop
in interface Service
- Parameters:
timeout
- The amount of time the channel is allowed to take to gracefully stop. If the timeout
is exceeded, the channel should do a forcefull stop.
- Throws:
IOException
Copyright © -2007 The ActiveIO Project. All Rights Reserved.