org.activeio.net
Class NIOSynchChannel
java.lang.Object
org.activeio.net.NIOBaseChannel
org.activeio.net.NIOSynchChannel
- All Implemented Interfaces:
- Channel, Disposable, InputSynchChannel, OutputChannel, Service, SocketMetadata, SynchChannel
- public final class NIOSynchChannel
- extends NIOBaseChannel
- implements SynchChannel
A 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$
Constructor Summary |
protected |
NIOSynchChannel(java.nio.channels.SocketChannel socketChannel)
|
protected |
NIOSynchChannel(java.nio.channels.SocketChannel socketChannel,
boolean useDirect)
|
Method Summary |
Packet |
read(long timeout)
Used to synchonously 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 |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
NIOSynchChannel
protected NIOSynchChannel(java.nio.channels.SocketChannel socketChannel)
throws java.io.IOException
NIOSynchChannel
protected NIOSynchChannel(java.nio.channels.SocketChannel socketChannel,
boolean useDirect)
throws java.io.IOException
read
public Packet read(long timeout)
throws java.io.IOException
- Description copied from interface:
InputSynchChannel
- Used to synchonously 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 InputSynchChannel
- Parameters:
timeout
-
- Returns:
- the packet recived or null if the timeout occured.
- Throws:
java.io.IOException
write
public void write(Packet packet)
throws java.io.IOException
- Description copied from interface:
OutputChannel
- Sends a packet down the channel towards the media.
- Specified by:
write
in interface OutputChannel
- Parameters:
packet
-
- Throws:
java.io.IOException
start
public void start()
throws java.io.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:
java.io.IOException
stop
public void stop(long timeout)
throws java.io.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:
java.io.IOException
Copyright © -2005 The ActiveIO Project. All Rights Reserved.