Package org.jboss.netty.channel
Class AbstractChannel
java.lang.Object
org.jboss.netty.channel.AbstractChannel
- All Implemented Interfaces:
Comparable<Channel>
,Channel
- Direct Known Subclasses:
AbstractNioChannel
,AbstractOioChannel
,AbstractServerChannel
,DefaultLocalChannel
,EmbeddedChannel
,HttpTunnelingClientSocketChannel
A skeletal
Channel
implementation.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final ConcurrentMap<Integer,
Channel> private Object
private final AbstractChannel.ChannelCloseFuture
private final ChannelFactory
private final Integer
private int
private final Channel
private final ChannelPipeline
private static final Random
private String
private boolean
Cache for the string representation of this channelprivate final ChannelFuture
private int
private static final AtomicIntegerFieldUpdater<AbstractChannel>
Fields inherited from interface org.jboss.netty.channel.Channel
OP_NONE, OP_READ, OP_READ_WRITE, OP_WRITE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractChannel
(Integer id, Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink) (Internal use only) Creates a new temporary instance with the specified ID.protected
AbstractChannel
(Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate static Integer
allocateId
(Channel channel) bind
(SocketAddress localAddress) Binds this channel to the specified local address asynchronously.private void
clearUserDefinedWritability
(int index) close()
Closes this channel asynchronously.final int
Compares the ID of the two channels.connect
(SocketAddress remoteAddress) Connects this channel to the specified remote address asynchronously.Disconnects this channel from the current remote address asynchronously.final boolean
Returnstrue
if and only if the specified object is identical with this channel (i.e:this == o
).Returns theChannelFuture
which will be notified when this channel is closed.Returns theChannelFactory
which created this channel.final Integer
getId()
Returns the unique integer ID of this channel.private String
int
Returns the currentinterestOps
of this channel.protected int
Returns the parent of this channel.Returns theChannelPipeline
which handlesChannelEvent
s associated with this channel.protected ChannelFuture
Returns the cachedSucceededChannelFuture
instance.protected ChannelFuture
Returns theFailedChannelFuture
whose cause is anUnsupportedOperationException
.final boolean
getUserDefinedWritability
(int index) Returnstrue
if and only if the user-defined writability flag at the specified index is set totrue
.final int
hashCode()
Returns the ID of this channel.boolean
isOpen()
Returnstrue
if and only if this channel is open.boolean
Returnstrue
if and only if the I/O thread will read a message from this channel.boolean
Returnstrue
if and only if the I/O thread will perform the requested write operation immediately.void
setAttachment
(Object attachment) Attaches an object to thisChannel
to store a stateful informationprotected boolean
Marks this channel as closed.setInterestOps
(int interestOps) Changes theinterestOps
of this channel asynchronously.protected void
setInternalInterestOps
(int interestOps) Sets theinterestOps
property of this channel immediately.setReadable
(boolean readable) Suspends or resumes the read operation of the I/O thread asynchronously.protected boolean
private void
setUserDefinedWritability
(int index) final void
setUserDefinedWritability
(int index, boolean writable) Sets a user-defined writability flag at the specified index.protected boolean
toString()
Returns theString
representation of this channel.unbind()
Unbinds this channel from the current local address asynchronously.private static int
writabilityMask
(int index) Sends a message to this channel asynchronously.write
(Object message, SocketAddress remoteAddress) Sends a message to this channel asynchronously.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.jboss.netty.channel.Channel
getConfig, getLocalAddress, getRemoteAddress, isBound, isConnected
-
Field Details
-
allChannels
-
random
-
id
-
parent
-
factory
-
pipeline
-
succeededFuture
-
closeFuture
-
interestOps
private volatile int interestOps -
strValConnected
private boolean strValConnectedCache for the string representation of this channel -
strVal
-
attachment
-
UNWRITABLE_UPDATER
-
unwritable
private volatile int unwritable
-
-
Constructor Details
-
AbstractChannel
protected AbstractChannel(Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink) Creates a new instance.- Parameters:
parent
- the parent of this channel.null
if there's no parent.factory
- the factory which created this channelpipeline
- the pipeline which is going to be attached to this channelsink
- the sink which will receive downstream events from the pipeline and send upstream events to the pipeline
-
AbstractChannel
protected AbstractChannel(Integer id, Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink) (Internal use only) Creates a new temporary instance with the specified ID.- Parameters:
parent
- the parent of this channel.null
if there's no parent.factory
- the factory which created this channelpipeline
- the pipeline which is going to be attached to this channelsink
- the sink which will receive downstream events from the pipeline and send upstream events to the pipeline
-
-
Method Details
-
allocateId
-
getId
Description copied from interface:Channel
Returns the unique integer ID of this channel. -
getParent
Description copied from interface:Channel
Returns the parent of this channel. -
getFactory
Description copied from interface:Channel
Returns theChannelFactory
which created this channel.- Specified by:
getFactory
in interfaceChannel
-
getPipeline
Description copied from interface:Channel
Returns theChannelPipeline
which handlesChannelEvent
s associated with this channel.- Specified by:
getPipeline
in interfaceChannel
-
getSucceededFuture
Returns the cachedSucceededChannelFuture
instance. -
getUnsupportedOperationFuture
Returns theFailedChannelFuture
whose cause is anUnsupportedOperationException
. -
hashCode
public final int hashCode()Returns the ID of this channel. -
equals
Returnstrue
if and only if the specified object is identical with this channel (i.e:this == o
). -
compareTo
Compares the ID of the two channels.- Specified by:
compareTo
in interfaceComparable<Channel>
-
isOpen
public boolean isOpen()Description copied from interface:Channel
Returnstrue
if and only if this channel is open. -
setClosed
protected boolean setClosed()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.- Returns:
true
if and only if this channel was not marked as closed yet
-
bind
Description copied from interface:Channel
Binds this channel to the specified local address asynchronously.- Specified by:
bind
in interfaceChannel
- Parameters:
localAddress
- where to bind- Returns:
- the
ChannelFuture
which will be notified when the bind request succeeds or fails
-
unbind
Description copied from interface:Channel
Unbinds this channel from the current local address asynchronously.- Specified by:
unbind
in interfaceChannel
- Returns:
- the
ChannelFuture
which will be notified when the unbind request succeeds or fails
-
close
Description copied from interface:Channel
Closes this channel asynchronously. If this channel is bound or connected, it will be disconnected and unbound first. Once a channel is closed, it can not be open again. Calling this method on a closed channel has no effect. Please note that this method always returns the same future instance.- Specified by:
close
in interfaceChannel
- Returns:
- the
ChannelFuture
which will be notified when the close request succeeds or fails
-
getCloseFuture
Description copied from interface:Channel
Returns theChannelFuture
which will be notified when this channel is closed. This method always returns the same future instance.- Specified by:
getCloseFuture
in interfaceChannel
-
connect
Description copied from interface:Channel
Connects this channel to the specified remote address asynchronously.- Specified by:
connect
in interfaceChannel
- Parameters:
remoteAddress
- where to connect- Returns:
- the
ChannelFuture
which will be notified when the connection request succeeds or fails
-
disconnect
Description copied from interface:Channel
Disconnects this channel from the current remote address asynchronously.- Specified by:
disconnect
in interfaceChannel
- Returns:
- the
ChannelFuture
which will be notified when the disconnection request succeeds or fails
-
getInterestOps
public int getInterestOps()Description copied from interface:Channel
Returns the currentinterestOps
of this channel.- Specified by:
getInterestOps
in interfaceChannel
- Returns:
Channel.OP_NONE
,Channel.OP_READ
,Channel.OP_WRITE
, orChannel.OP_READ_WRITE
-
setInterestOps
Description copied from interface:Channel
Changes theinterestOps
of this channel asynchronously.- Specified by:
setInterestOps
in interfaceChannel
- Parameters:
interestOps
- the newinterestOps
- Returns:
- the
ChannelFuture
which will be notified when theinterestOps
change request succeeds or fails
-
getInternalInterestOps
protected int getInternalInterestOps() -
setInternalInterestOps
protected void setInternalInterestOps(int interestOps) Sets theinterestOps
property of this channel immediately. This method is intended to be called by an internal component - please do not call it unless you know what you are doing. -
isReadable
public boolean isReadable()Description copied from interface:Channel
Returnstrue
if and only if the I/O thread will read a message from this channel. This method is a shortcut to the following code:return (getInterestOps() & OP_READ) != 0;
- Specified by:
isReadable
in interfaceChannel
-
isWritable
public boolean isWritable()Description copied from interface:Channel
Returnstrue
if and only if the I/O thread will perform the requested write operation immediately. Any write requests made when this method returnsfalse
are queued until the I/O thread is ready to process the queued write requests. This method is a shortcut to the following code:return (getInterestOps() & OP_WRITE) == 0;
- Specified by:
isWritable
in interfaceChannel
-
getUserDefinedWritability
public final boolean getUserDefinedWritability(int index) Description copied from interface:Channel
Returnstrue
if and only if the user-defined writability flag at the specified index is set totrue
.- Specified by:
getUserDefinedWritability
in interfaceChannel
-
setUserDefinedWritability
public final void setUserDefinedWritability(int index, boolean writable) Description copied from interface:Channel
Sets a user-defined writability flag at the specified index.- Specified by:
setUserDefinedWritability
in interfaceChannel
-
setUserDefinedWritability
private void setUserDefinedWritability(int index) -
clearUserDefinedWritability
private void clearUserDefinedWritability(int index) -
writabilityMask
private static int writabilityMask(int index) -
setWritable
protected boolean setWritable() -
setUnwritable
protected boolean setUnwritable() -
setReadable
Description copied from interface:Channel
Suspends or resumes the read operation of the I/O thread asynchronously. This method is a shortcut to the following code:int interestOps = getInterestOps(); if (readable) { setInterestOps(interestOps | OP_READ); } else { setInterestOps(interestOps & ~OP_READ); }
- Specified by:
setReadable
in interfaceChannel
- Parameters:
readable
-true
to resume the read operation andfalse
to suspend the read operation- Returns:
- the
ChannelFuture
which will be notified when theinterestOps
change request succeeds or fails
-
write
Description copied from interface:Channel
Sends a message to this channel asynchronously. If this channel was created by a connectionless transport (e.g.DatagramChannel
) and is not connected yet, you have to callChannel.write(Object, SocketAddress)
instead. Otherwise, the write request will fail withNotYetConnectedException
and an'exceptionCaught'
event will be triggered.- Specified by:
write
in interfaceChannel
- Parameters:
message
- the message to write- Returns:
- the
ChannelFuture
which will be notified when the write request succeeds or fails
-
write
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
- 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
-
getAttachment
Description copied from interface:Channel
- Specified by:
getAttachment
in interfaceChannel
- Returns:
null
if no object was attached ornull
was attached
-
setAttachment
Description copied from interface:Channel
Attaches an object to thisChannel
to store a stateful information- Specified by:
setAttachment
in interfaceChannel
-
toString
Returns theString
representation of this channel. The returned string contains the ID, local address, and remote address of this channel for easier identification. -
getIdString
-