Class NioSocketChannel
- java.lang.Object
-
- org.jboss.netty.channel.AbstractChannel
-
- org.jboss.netty.channel.socket.nio.AbstractNioChannel<java.nio.channels.SocketChannel>
-
- org.jboss.netty.channel.socket.nio.NioSocketChannel
-
- All Implemented Interfaces:
java.lang.Comparable<Channel>
,Channel
,SocketChannel
- Direct Known Subclasses:
NioAcceptedSocketChannel
,NioClientSocketChannel
public class NioSocketChannel extends AbstractNioChannel<java.nio.channels.SocketChannel> implements SocketChannel
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jboss.netty.channel.socket.nio.AbstractNioChannel
AbstractNioChannel.WriteRequestQueue
-
-
Field Summary
Fields Modifier and Type Field Description private NioSocketChannelConfig
config
private static int
ST_BOUND
private static int
ST_CLOSED
private static int
ST_CONNECTED
private static int
ST_OPEN
(package private) int
state
-
Fields inherited from class org.jboss.netty.channel.socket.nio.AbstractNioChannel
channel, currentWriteBuffer, currentWriteEvent, highWaterMarkCounter, inWriteNowLoop, remoteAddress, worker, writeBufferQueue, writeBufferSize, writeLock, writeSuspended, writeTask, writeTaskInTaskQueue
-
Fields inherited from interface org.jboss.netty.channel.Channel
OP_NONE, OP_READ, OP_READ_WRITE, OP_WRITE
-
-
Constructor Summary
Constructors Constructor Description NioSocketChannel(Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, java.nio.channels.SocketChannel socket, NioWorker worker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NioSocketChannelConfig
getConfig()
Returns the configuration of this channel.(package private) java.net.InetSocketAddress
getLocalSocketAddress()
(package private) java.net.InetSocketAddress
getRemoteSocketAddress()
NioWorker
getWorker()
Return theAbstractNioWorker
that handle the IO of theAbstractNioChannel
boolean
isBound()
Returnstrue
if and only if this channel is bound to a local address.boolean
isConnected()
Returnstrue
if and only if this channel is connected to a remote address.boolean
isOpen()
Returnstrue
if and only if this channel is open.(package private) void
setBound()
protected boolean
setClosed()
Marks this channel as closed.(package private) void
setConnected()
ChannelFuture
write(java.lang.Object message, java.net.SocketAddress remoteAddress)
Sends a message to this channel asynchronously.-
Methods inherited from class org.jboss.netty.channel.socket.nio.AbstractNioChannel
getInternalInterestOps, getLocalAddress, getRemoteAddress, setInternalInterestOps
-
Methods inherited from class org.jboss.netty.channel.AbstractChannel
bind, close, compareTo, connect, disconnect, equals, getAttachment, getCloseFuture, getFactory, getId, getInterestOps, getParent, getPipeline, getSucceededFuture, getUnsupportedOperationFuture, getUserDefinedWritability, hashCode, isReadable, isWritable, setAttachment, setInterestOps, setReadable, setUnwritable, setUserDefinedWritability, setWritable, toString, unbind, write
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jboss.netty.channel.Channel
bind, close, connect, disconnect, getAttachment, getCloseFuture, getFactory, getId, getInterestOps, getParent, getPipeline, getUserDefinedWritability, isReadable, isWritable, setAttachment, setInterestOps, setReadable, setUserDefinedWritability, unbind, write
-
Methods inherited from interface org.jboss.netty.channel.socket.SocketChannel
getLocalAddress, getRemoteAddress
-
-
-
-
Field Detail
-
ST_OPEN
private static final int ST_OPEN
- See Also:
- Constant Field Values
-
ST_BOUND
private static final int ST_BOUND
- See Also:
- Constant Field Values
-
ST_CONNECTED
private static final int ST_CONNECTED
- See Also:
- Constant Field Values
-
ST_CLOSED
private static final int ST_CLOSED
- See Also:
- Constant Field Values
-
state
volatile int state
-
config
private final NioSocketChannelConfig config
-
-
Constructor Detail
-
NioSocketChannel
public NioSocketChannel(Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, java.nio.channels.SocketChannel socket, NioWorker worker)
-
-
Method Detail
-
getWorker
public NioWorker getWorker()
Description copied from class:AbstractNioChannel
Return theAbstractNioWorker
that handle the IO of theAbstractNioChannel
- Overrides:
getWorker
in classAbstractNioChannel<java.nio.channels.SocketChannel>
- Returns:
- worker
-
getConfig
public NioSocketChannelConfig getConfig()
Description copied from interface:Channel
Returns the configuration of this channel.- Specified by:
getConfig
in interfaceChannel
- Specified by:
getConfig
in interfaceSocketChannel
- Specified by:
getConfig
in classAbstractNioChannel<java.nio.channels.SocketChannel>
-
isOpen
public boolean isOpen()
Description copied from interface:Channel
Returnstrue
if and only if this channel is open.- Specified by:
isOpen
in interfaceChannel
- Overrides:
isOpen
in classAbstractChannel
-
isBound
public boolean isBound()
Description copied from interface:Channel
Returnstrue
if and only if this channel is bound to a local address.
-
isConnected
public boolean isConnected()
Description copied from interface:Channel
Returnstrue
if and only if this channel is connected to a remote address.- Specified by:
isConnected
in interfaceChannel
-
setBound
final void setBound()
-
setConnected
final void setConnected()
-
setClosed
protected boolean setClosed()
Description copied from class:AbstractChannel
Marks this channel as closed. This method is intended to be called by an internal component - please do not call it unless you know what you are doing.- Overrides:
setClosed
in classAbstractNioChannel<java.nio.channels.SocketChannel>
- Returns:
true
if and only if this channel was not marked as closed yet
-
getLocalSocketAddress
java.net.InetSocketAddress getLocalSocketAddress() throws java.lang.Exception
- Specified by:
getLocalSocketAddress
in classAbstractNioChannel<java.nio.channels.SocketChannel>
- Throws:
java.lang.Exception
-
getRemoteSocketAddress
java.net.InetSocketAddress getRemoteSocketAddress() throws java.lang.Exception
- Specified by:
getRemoteSocketAddress
in classAbstractNioChannel<java.nio.channels.SocketChannel>
- Throws:
java.lang.Exception
-
write
public ChannelFuture write(java.lang.Object message, java.net.SocketAddress remoteAddress)
Description copied from interface:Channel
Sends a message to this channel asynchronously. It has an additional parameter that allows a user to specify where to send the specified message instead of this channel's current remote address. If this channel was created by a connectionless transport (e.g.DatagramChannel
) and is not connected yet, you must specify non-null address. Otherwise, the write request will fail withNotYetConnectedException
and an'exceptionCaught'
event will be triggered.- Specified by:
write
in interfaceChannel
- Overrides:
write
in classAbstractChannel
- Parameters:
message
- the message to writeremoteAddress
- where to send the specified message. This method is identical toChannel.write(Object)
ifnull
is specified here.- Returns:
- the
ChannelFuture
which will be notified when the write request succeeds or fails
-
-