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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final ConcurrentMap<Integer, Channel> private Objectprivate final AbstractChannel.ChannelCloseFutureprivate final ChannelFactoryprivate final Integerprivate intprivate final Channelprivate final ChannelPipelineprivate static final Randomprivate Stringprivate booleanCache for the string representation of this channelprivate final ChannelFutureprivate intprivate static final AtomicIntegerFieldUpdater<AbstractChannel> Fields inherited from interface Channel
OP_NONE, OP_READ, OP_READ_WRITE, OP_WRITE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractChannel(Integer id, Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink) (Internal use only) Creates a new temporary instance with the specified ID.protectedAbstractChannel(Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate static IntegerallocateId(Channel channel) bind(SocketAddress localAddress) Binds this channel to the specified local address asynchronously.private voidclearUserDefinedWritability(int index) close()Closes this channel asynchronously.final intCompares 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 booleanReturnstrueif and only if the specified object is identical with this channel (i.e:this == o).Returns theChannelFuturewhich will be notified when this channel is closed.Returns theChannelFactorywhich created this channel.final IntegergetId()Returns the unique integer ID of this channel.private StringintReturns the currentinterestOpsof this channel.protected intReturns the parent of this channel.Returns theChannelPipelinewhich handlesChannelEvents associated with this channel.protected ChannelFutureReturns the cachedSucceededChannelFutureinstance.protected ChannelFutureReturns theFailedChannelFuturewhose cause is anUnsupportedOperationException.final booleangetUserDefinedWritability(int index) Returnstrueif and only if the user-defined writability flag at the specified index is set totrue.final inthashCode()Returns the ID of this channel.booleanisOpen()Returnstrueif and only if this channel is open.booleanReturnstrueif and only if the I/O thread will read a message from this channel.booleanReturnstrueif and only if the I/O thread will perform the requested write operation immediately.voidsetAttachment(Object attachment) Attaches an object to thisChannelto store a stateful informationprotected booleanMarks this channel as closed.setInterestOps(int interestOps) Changes theinterestOpsof this channel asynchronously.protected voidsetInternalInterestOps(int interestOps) Sets theinterestOpsproperty of this channel immediately.setReadable(boolean readable) Suspends or resumes the read operation of the I/O thread asynchronously.protected booleanprivate voidsetUserDefinedWritability(int index) final voidsetUserDefinedWritability(int index, boolean writable) Sets a user-defined writability flag at the specified index.protected booleantoString()Returns theStringrepresentation of this channel.unbind()Unbinds this channel from the current local address asynchronously.private static intwritabilityMask(int index) Sends a message to this channel asynchronously.write(Object message, SocketAddress remoteAddress) Sends a message to this channel asynchronously.Methods inherited from interface 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.nullif 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.nullif 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
-
getParent
-
getFactory
Description copied from interface:ChannelReturns theChannelFactorywhich created this channel.- Specified by:
getFactoryin interfaceChannel
-
getPipeline
Description copied from interface:ChannelReturns theChannelPipelinewhich handlesChannelEvents associated with this channel.- Specified by:
getPipelinein interfaceChannel
-
getSucceededFuture
Returns the cachedSucceededChannelFutureinstance. -
getUnsupportedOperationFuture
Returns theFailedChannelFuturewhose cause is anUnsupportedOperationException. -
hashCode
-
equals
-
compareTo
Compares the ID of the two channels.- Specified by:
compareToin interfaceComparable<Channel>
-
isOpen
-
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:
trueif and only if this channel was not marked as closed yet
-
bind
Description copied from interface:ChannelBinds this channel to the specified local address asynchronously.- Specified by:
bindin interfaceChannel- Parameters:
localAddress- where to bind- Returns:
- the
ChannelFuturewhich will be notified when the bind request succeeds or fails
-
unbind
Description copied from interface:ChannelUnbinds this channel from the current local address asynchronously.- Specified by:
unbindin interfaceChannel- Returns:
- the
ChannelFuturewhich will be notified when the unbind request succeeds or fails
-
close
Description copied from interface:ChannelCloses 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:
closein interfaceChannel- Returns:
- the
ChannelFuturewhich will be notified when the close request succeeds or fails
-
getCloseFuture
Description copied from interface:ChannelReturns theChannelFuturewhich will be notified when this channel is closed. This method always returns the same future instance.- Specified by:
getCloseFuturein interfaceChannel
-
connect
Description copied from interface:ChannelConnects this channel to the specified remote address asynchronously.- Specified by:
connectin interfaceChannel- Parameters:
remoteAddress- where to connect- Returns:
- the
ChannelFuturewhich will be notified when the connection request succeeds or fails
-
disconnect
Description copied from interface:ChannelDisconnects this channel from the current remote address asynchronously.- Specified by:
disconnectin interfaceChannel- Returns:
- the
ChannelFuturewhich will be notified when the disconnection request succeeds or fails
-
getInterestOps
public int getInterestOps()Description copied from interface:ChannelReturns the currentinterestOpsof this channel.- Specified by:
getInterestOpsin interfaceChannel- Returns:
Channel.OP_NONE,Channel.OP_READ,Channel.OP_WRITE, orChannel.OP_READ_WRITE
-
setInterestOps
Description copied from interface:ChannelChanges theinterestOpsof this channel asynchronously.- Specified by:
setInterestOpsin interfaceChannel- Parameters:
interestOps- the newinterestOps- Returns:
- the
ChannelFuturewhich will be notified when theinterestOpschange request succeeds or fails
-
getInternalInterestOps
protected int getInternalInterestOps() -
setInternalInterestOps
protected void setInternalInterestOps(int interestOps) Sets theinterestOpsproperty 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:ChannelReturnstrueif 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() invalid input: '&' OP_READ) != 0;- Specified by:
isReadablein interfaceChannel
-
isWritable
public boolean isWritable()Description copied from interface:ChannelReturnstrueif and only if the I/O thread will perform the requested write operation immediately. Any write requests made when this method returnsfalseare 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() invalid input: '&' OP_WRITE) == 0;- Specified by:
isWritablein interfaceChannel
-
getUserDefinedWritability
public final boolean getUserDefinedWritability(int index) Description copied from interface:ChannelReturnstrueif and only if the user-defined writability flag at the specified index is set totrue.- Specified by:
getUserDefinedWritabilityin interfaceChannel
-
setUserDefinedWritability
public final void setUserDefinedWritability(int index, boolean writable) Description copied from interface:ChannelSets a user-defined writability flag at the specified index.- Specified by:
setUserDefinedWritabilityin 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:ChannelSuspends 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 invalid input: '&' ~OP_READ); }- Specified by:
setReadablein interfaceChannel- Parameters:
readable-trueto resume the read operation andfalseto suspend the read operation- Returns:
- the
ChannelFuturewhich will be notified when theinterestOpschange request succeeds or fails
-
write
Description copied from interface:ChannelSends 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 withNotYetConnectedExceptionand an'exceptionCaught'event will be triggered.- Specified by:
writein interfaceChannel- Parameters:
message- the message to write- Returns:
- the
ChannelFuturewhich will be notified when the write request succeeds or fails
-
write
Description copied from interface:ChannelSends 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 withNotYetConnectedExceptionand an'exceptionCaught'event will be triggered.- Specified by:
writein interfaceChannel- Parameters:
message- the message to writeremoteAddress- where to send the specified message. This method is identical toChannel.write(Object)ifnullis specified here.- Returns:
- the
ChannelFuturewhich will be notified when the write request succeeds or fails
-
getAttachment
-
setAttachment
Description copied from interface:ChannelAttaches an object to thisChannelto store a stateful information- Specified by:
setAttachmentin interfaceChannel
-
toString
Returns theStringrepresentation of this channel. The returned string contains the ID, local address, and remote address of this channel for easier identification. -
getIdString
-