public abstract class AbstractChannel extends Object implements Channel
Channel
implementation.OP_NONE, OP_READ, OP_READ_WRITE, OP_WRITE
Modifier | Constructor and Description |
---|---|
protected |
AbstractChannel(Channel parent,
ChannelFactory factory,
ChannelPipeline pipeline,
ChannelSink sink)
Creates a new instance.
|
protected |
AbstractChannel(Integer id,
Channel parent,
ChannelFactory factory,
ChannelPipeline pipeline,
ChannelSink sink)
(Internal use only) Creates a new temporary instance with the specified
ID.
|
Modifier and Type | Method and Description |
---|---|
ChannelFuture |
bind(SocketAddress localAddress)
Binds this channel to the specified local address asynchronously.
|
ChannelFuture |
close()
Closes this channel asynchronously.
|
int |
compareTo(Channel o)
Compares the ID of the two channels.
|
ChannelFuture |
connect(SocketAddress remoteAddress)
Connects this channel to the specified remote address asynchronously.
|
ChannelFuture |
disconnect()
Disconnects this channel from the current remote address asynchronously.
|
boolean |
equals(Object o)
Returns
true if and only if the specified object is identical
with this channel (i.e: this == o ). |
Object |
getAttachment()
|
ChannelFuture |
getCloseFuture()
Returns the
ChannelFuture which will be notified when this
channel is closed. |
ChannelFactory |
getFactory()
Returns the
ChannelFactory which created this channel. |
Integer |
getId()
Returns the unique integer ID of this channel.
|
int |
getInterestOps()
Returns the current
interestOps of this channel. |
Channel |
getParent()
Returns the parent of this channel.
|
ChannelPipeline |
getPipeline()
Returns the
ChannelPipeline which handles ChannelEvent s
associated with this channel. |
protected ChannelFuture |
getSucceededFuture()
Returns the cached
SucceededChannelFuture instance. |
protected ChannelFuture |
getUnsupportedOperationFuture()
Returns the
FailedChannelFuture whose cause is an
UnsupportedOperationException . |
int |
hashCode()
Returns the ID of this channel.
|
boolean |
isOpen()
Returns
true if and only if this channel is open. |
boolean |
isReadable()
Returns
true if and only if the I/O thread will read a message
from this channel. |
boolean |
isWritable()
Returns
true if and only if the I/O thread will perform the
requested write operation immediately. |
void |
setAttachment(Object attachment)
Attaches an object to this
Channel to store a stateful
information |
protected boolean |
setClosed()
Marks this channel as closed.
|
ChannelFuture |
setInterestOps(int interestOps)
Changes the
interestOps of this channel asynchronously. |
protected void |
setInterestOpsNow(int interestOps)
Sets the
interestOps property of this channel
immediately. |
ChannelFuture |
setReadable(boolean readable)
Suspends or resumes the read operation of the I/O thread asynchronously.
|
String |
toString()
Returns the
String representation of this channel. |
ChannelFuture |
unbind()
Unbinds this channel from the current local address asynchronously.
|
ChannelFuture |
write(Object message)
Sends a message to this channel asynchronously.
|
ChannelFuture |
write(Object message,
SocketAddress remoteAddress)
Sends a message to this channel asynchronously.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getConfig, getLocalAddress, getRemoteAddress, isBound, isConnected
protected AbstractChannel(Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink)
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 pipelineprotected AbstractChannel(Integer id, Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink)
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 pipelinepublic final Integer getId()
Channel
public Channel getParent()
Channel
public ChannelFactory getFactory()
Channel
ChannelFactory
which created this channel.getFactory
in interface Channel
public ChannelPipeline getPipeline()
Channel
ChannelPipeline
which handles ChannelEvent
s
associated with this channel.getPipeline
in interface Channel
protected ChannelFuture getSucceededFuture()
SucceededChannelFuture
instance.protected ChannelFuture getUnsupportedOperationFuture()
FailedChannelFuture
whose cause is an
UnsupportedOperationException
.public final int hashCode()
public final boolean equals(Object o)
true
if and only if the specified object is identical
with this channel (i.e: this == o
).public final int compareTo(Channel o)
compareTo
in interface Comparable<Channel>
public boolean isOpen()
Channel
true
if and only if this channel is open.protected boolean setClosed()
true
if and only if this channel was not marked as
closed yetpublic ChannelFuture bind(SocketAddress localAddress)
Channel
bind
in interface Channel
localAddress
- where to bindChannelFuture
which will be notified when the
bind request succeeds or failspublic ChannelFuture unbind()
Channel
unbind
in interface Channel
ChannelFuture
which will be notified when the
unbind request succeeds or failspublic ChannelFuture close()
Channel
close
in interface Channel
ChannelFuture
which will be notified when the
close request succeeds or failspublic ChannelFuture getCloseFuture()
Channel
ChannelFuture
which will be notified when this
channel is closed. This method always returns the same future instance.getCloseFuture
in interface Channel
public ChannelFuture connect(SocketAddress remoteAddress)
Channel
connect
in interface Channel
remoteAddress
- where to connectChannelFuture
which will be notified when the
connection request succeeds or failspublic ChannelFuture disconnect()
Channel
disconnect
in interface Channel
ChannelFuture
which will be notified when the
disconnection request succeeds or failspublic int getInterestOps()
Channel
interestOps
of this channel.getInterestOps
in interface Channel
Channel.OP_NONE
, Channel.OP_READ
, Channel.OP_WRITE
, or
Channel.OP_READ_WRITE
public ChannelFuture setInterestOps(int interestOps)
Channel
interestOps
of this channel asynchronously.setInterestOps
in interface Channel
interestOps
- the new interestOps
ChannelFuture
which will be notified when the
interestOps
change request succeeds or failsprotected void setInterestOpsNow(int interestOps)
interestOps
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.public boolean isReadable()
Channel
true
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;
isReadable
in interface Channel
public boolean isWritable()
Channel
true
if and only if the I/O thread will perform the
requested write operation immediately. Any write requests made when
this method returns false
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;
isWritable
in interface Channel
public ChannelFuture setReadable(boolean readable)
Channel
int interestOps = getInterestOps(); if (readable) { setInterestOps(interestOps | OP_READ); } else { setInterestOps(interestOps & ~OP_READ); }
setReadable
in interface Channel
readable
- true
to resume the read operation and
false
to suspend the read operationChannelFuture
which will be notified when the
interestOps
change request succeeds or failspublic ChannelFuture write(Object message)
Channel
DatagramChannel
)
and is not connected yet, you have to call Channel.write(Object, SocketAddress)
instead. Otherwise, the write request will fail with
NotYetConnectedException
and an 'exceptionCaught'
event
will be triggered.write
in interface Channel
message
- the message to writeChannelFuture
which will be notified when the
write request succeeds or failspublic ChannelFuture write(Object message, SocketAddress remoteAddress)
Channel
DatagramChannel
)
and is not connected yet, you must specify non-null address. Otherwise,
the write request will fail with NotYetConnectedException
and
an 'exceptionCaught'
event will be triggered.write
in interface Channel
message
- the message to writeremoteAddress
- where to send the specified message.
This method is identical to Channel.write(Object)
if null
is specified here.ChannelFuture
which will be notified when the
write request succeeds or failspublic Object getAttachment()
Channel
getAttachment
in interface Channel
null
if no object was attached or null
was
attachedpublic void setAttachment(Object attachment)
Channel
Channel
to store a stateful
informationsetAttachment
in interface Channel
public String toString()
String
representation of this channel. The returned
string contains the ID, local address,
and remote address of this channel for
easier identification.Copyright © 2008-2013 The Netty Project. All Rights Reserved.