public class OioSocketChannel extends OioByteStreamChannel implements SocketChannel
SocketChannel
which is using Old-Blocking-IOAbstractChannel.AbstractUnsafe
Channel.Unsafe
SO_TIMEOUT
flushFutureNotifier
Constructor and Description |
---|
OioSocketChannel()
Create a new instance with an new
Socket |
OioSocketChannel(Channel parent,
Integer id,
Socket socket)
Create a new instance from the given
Socket |
OioSocketChannel(Socket socket)
Create a new instance from the given
Socket |
Modifier and Type | Method and Description |
---|---|
ByteBufAllocator |
alloc()
Return the assigned
ByteBufAllocator which will be used for allocate ByteBuf s. |
ChannelFuture |
bind(SocketAddress localAddress)
Request to bind to the given
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error. |
ChannelFuture |
bind(SocketAddress localAddress,
ChannelPromise promise)
Request to bind to the given
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error. |
protected boolean |
checkInputShutdown()
Check if the input was shutdown and if so return
true . |
ChannelFuture |
close()
Request to close this ChannelOutboundInvoker and notify the
ChannelFuture once the operation completes,
either because the operation was successful or because of
an error. |
ChannelFuture |
close(ChannelPromise promise)
Request to close this ChannelOutboundInvoker and notify the
ChannelFuture once the operation completes,
either because the operation was successful or because of
an error. |
OioSocketChannelConfig |
config()
Returns the configuration of this channel.
|
ChannelFuture |
connect(SocketAddress remoteAddress)
Request to connect to the given
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error. |
ChannelFuture |
connect(SocketAddress remoteAddress,
ChannelPromise promise)
Request to connect to the given
SocketAddress and notify the ChannelFuture once the operation
completes, either because the operation was successful or because of an error. |
ChannelFuture |
connect(SocketAddress remoteAddress,
SocketAddress localAddress)
Request to connect to the given
SocketAddress while bind to the localAddress and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error. |
ChannelFuture |
connect(SocketAddress remoteAddress,
SocketAddress localAddress,
ChannelPromise promise)
Request to connect to the given
SocketAddress while bind to the localAddress and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error. |
ChannelFuture |
deregister()
Request to deregister this ChannelOutboundInvoker from the previous assigned
EventExecutor and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error. |
ChannelFuture |
deregister(ChannelPromise promise)
Request to deregister this ChannelOutboundInvoker from the previous assigned
EventExecutor and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error. |
ChannelFuture |
disconnect()
Request to discconect from the remote peer and notify the
ChannelFuture once the operation completes,
either because the operation was successful or because of an error. |
ChannelFuture |
disconnect(ChannelPromise promise)
Request to discconect from the remote peer and notify the
ChannelFuture once the operation completes,
either because the operation was successful or because of an error. |
protected void |
doBind(SocketAddress localAddress)
Bind the
Channel to the SocketAddress |
protected void |
doClose()
Close the
Channel |
protected void |
doConnect(SocketAddress remoteAddress,
SocketAddress localAddress)
Connect to the remote peer using the given localAddress if one is specified or
null otherwise. |
protected void |
doDisconnect()
Disconnect this
Channel from its remote peer |
protected int |
doReadBytes(ByteBuf buf)
Read bytes from the underlying Socket.
|
ChannelFuture |
flush()
Request to flush all pending data which belongs to this ChannelOutboundInvoker and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error. |
ChannelFuture |
flush(ChannelPromise promise)
Request to flush all pending data which belongs to this ChannelOutboundInvoker and notify the
ChannelFuture once the operation completes, either because the operation was successful or because of
an error. |
boolean |
isActive()
Return
true if the Channel is active and so connected. |
boolean |
isInputShutdown()
Returns
true if and only if the remote peer shut down its output so that no more
data is received from this channel. |
boolean |
isOpen()
Returns
true if the Channel is open an may get active later |
boolean |
isOutputShutdown() |
InetSocketAddress |
localAddress()
Returns the local address where this channel is bound to.
|
protected SocketAddress |
localAddress0()
Returns the
SocketAddress which is bound locally. |
ChannelFuture |
newFailedFuture(Throwable cause)
Create a new
Future which is marked as fakued already. |
ChannelPromise |
newPromise()
Return a new
Promise . |
ChannelFuture |
newSucceededFuture()
Create a new
Future which is marked as successes already. |
ServerSocketChannel |
parent()
Returns the parent of this channel.
|
ChannelPipeline |
pipeline()
Return the assigned
ChannelPipeline |
void |
read()
Request to Read data from the
Channel into the first inbound buffer, triggers an
inboundBufferUpdated event if data was
read, and triggers an
channelReadSuspended event so the
handler can decide to continue reading. |
InetSocketAddress |
remoteAddress()
Returns the remote address where this channel is connected to.
|
protected SocketAddress |
remoteAddress0()
Return the
SocketAddress which the Channel is connected to. |
ChannelFuture |
sendFile(FileRegion region)
Request to send a
FileRegion via this ChannelOutboundInvoker and notify the ChannelFuture
once the operation completes, either because the operation was successful or because of an error. |
ChannelFuture |
sendFile(FileRegion region,
ChannelPromise promise)
Request to send a
FileRegion via this ChannelOutboundInvoker and notify the ChannelFuture
once the operation completes, either because the operation was successful or because of an error. |
ChannelFuture |
shutdownOutput() |
ChannelFuture |
shutdownOutput(ChannelPromise future) |
ChannelFuture |
write(Object message)
Request to write a message via this ChannelOutboundInvoker and notify the
ChannelFuture
once the operation completes, either because the operation was successful or because of an error. |
ChannelFuture |
write(Object message,
ChannelPromise promise)
Request to write a message via this ChannelOutboundInvoker and notify the
ChannelFuture
once the operation completes, either because the operation was successful or because of an error. |
activate, available, doFlushFileRegion, doWriteBytes
doFlushByteBuffer, doRead, metadata
doBeginRead, isCompatible, isFlushPending, newUnsafe
alloc, bind, bind, checkEOF, close, close, closeFuture, compareTo, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, doDeregister, doFlushMessageBuffer, doPreClose, doRegister, equals, eventLoop, expandReadBuffer, flush, flush, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, newFailedFuture, newPromise, newSucceededFuture, outboundByteBuffer, outboundMessageBuffer, pipeline, read, sendFile, sendFile, toString, unsafe, write, write
attr
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
closeFuture, eventLoop, id, isRegistered, metadata, outboundByteBuffer, outboundMessageBuffer, unsafe
attr
compareTo
public OioSocketChannel()
Socket
public OioSocketChannel(Socket socket)
Socket
socket
- the Socket
which is used by this instancepublic ServerSocketChannel parent()
Channel
parent
in interface Channel
parent
in interface SocketChannel
parent
in class AbstractChannel
null
if this channel does not have a parent channel.public OioSocketChannelConfig config()
Channel
config
in interface Channel
config
in interface SocketChannel
public boolean isOpen()
Channel
true
if the Channel
is open an may get active laterpublic boolean isActive()
Channel
true
if the Channel
is active and so connected.isActive
in interface Channel
isActive
in class OioByteStreamChannel
public boolean isInputShutdown()
SocketChannel
true
if and only if the remote peer shut down its output so that no more
data is received from this channel. Note that the semantic of this method is different from
that of Socket.shutdownInput()
and Socket.isInputShutdown()
.isInputShutdown
in interface SocketChannel
isInputShutdown
in class AbstractOioByteChannel
public boolean isOutputShutdown()
isOutputShutdown
in interface SocketChannel
Socket.isOutputShutdown()
public ChannelFuture shutdownOutput()
shutdownOutput
in interface SocketChannel
Socket.shutdownOutput()
protected int doReadBytes(ByteBuf buf) throws Exception
AbstractOioByteChannel
doReadBytes
in class OioByteStreamChannel
buf
- the ByteBuf
into which the read bytes will be writtenException
- is thrown if an error accouredpublic ChannelFuture shutdownOutput(ChannelPromise future)
shutdownOutput
in interface SocketChannel
Will notify the given {@link ChannelPromise}
public InetSocketAddress localAddress()
Channel
SocketAddress
is supposed to be down-cast into more concrete
type such as InetSocketAddress
to retrieve the detailed
information.localAddress
in interface Channel
localAddress
in interface SocketChannel
localAddress
in class AbstractChannel
null
if this channel is not bound.public InetSocketAddress remoteAddress()
Channel
SocketAddress
is supposed to be down-cast into more
concrete type such as InetSocketAddress
to retrieve the detailed
information.remoteAddress
in interface Channel
remoteAddress
in interface SocketChannel
remoteAddress
in class AbstractChannel
null
if this channel is not connected.
If this channel is not connected but it can receive messages
from arbitrary remote addresses (e.g. DatagramChannel
,
use DatagramPacket.remoteAddress()
to determine
the origination of the received message as this method will
return null
.protected SocketAddress localAddress0()
AbstractChannel
SocketAddress
which is bound locally.localAddress0
in class AbstractChannel
protected SocketAddress remoteAddress0()
AbstractChannel
SocketAddress
which the Channel
is connected to.remoteAddress0
in class AbstractChannel
protected void doBind(SocketAddress localAddress) throws Exception
AbstractChannel
Channel
to the SocketAddress
doBind
in class AbstractChannel
Exception
protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception
AbstractOioChannel
null
otherwise.doConnect
in class AbstractOioChannel
Exception
protected void doDisconnect() throws Exception
AbstractChannel
Channel
from its remote peerdoDisconnect
in class AbstractChannel
Exception
protected void doClose() throws Exception
AbstractChannel
Channel
doClose
in class OioByteStreamChannel
Exception
protected boolean checkInputShutdown()
AbstractOioByteChannel
true
. The default implementation sleeps also for
AbstractOioChannel.SO_TIMEOUT
milliseconds to simulate some blocking.checkInputShutdown
in class AbstractOioByteChannel
public ChannelFuture bind(SocketAddress localAddress)
SocketAddress
and notify the ChannelFuture
once the operation
completes, either because the operation was successful or because of an error.
This will result in having the
ChannelOperationHandler.bind(ChannelHandlerContext, SocketAddress, ChannelPromise)
method
called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture connect(SocketAddress remoteAddress)
SocketAddress
and notify the ChannelFuture
once the operation
completes, either because the operation was successful or because of an error.
If the connection fails because of a connection timeout, the ChannelFuture
will get failed with
a ConnectTimeoutException
. If it fails because of connection refused a ConnectException
will be used.
This will result in having the
ChannelOperationHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress)
SocketAddress
while bind to the localAddress and notify the
ChannelFuture
once the operation completes, either because the operation was successful or because of
an error.
This will result in having the
ChannelOperationHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture disconnect()
ChannelFuture
once the operation completes,
either because the operation was successful or because of an error.
This will result in having the
ChannelOperationHandler.disconnect(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture close()
ChannelFuture
once the operation completes,
either because the operation was successful or because of
an error.
After it is closed it is not possible to reuse it again.
This will result in having the
ChannelOperationHandler.close(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture deregister()
EventExecutor
and notify the
ChannelFuture
once the operation completes, either because the operation was successful or because of
an error.
This will result in having the
ChannelOperationHandler.deregister(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture flush()
ChannelFuture
once the operation completes, either because the operation was successful or because of
an error.
Be aware that the flush could be only partially successful. In such cases the ChannelFuture
will be
failed with an IncompleteFlushException
. So if you are interested to know if it was partial successful
you need to check if the returned Future.cause()
returns an instance of
IncompleteFlushException
. In such cases you may want to call flush(ChannelPromise)
or
flush()
to flush the rest of the data or just close the connection via close(ChannelPromise)
or
close()
if it is not possible to recover.
This will result in having the
ChannelOperationHandler.flush(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture write(Object message)
ChannelFuture
once the operation completes, either because the operation was successful or because of an error.
If you want to write a FileRegion
use sendFile(FileRegion)
.
Be aware that the write could be only partially successful as the message may need to get encoded before write it
to the remote peer. In such cases the ChannelFuture
will be failed with a
IncompleteFlushException
. In such cases you may want to call flush(ChannelPromise)
or
flush()
to flush the rest of the data or just close the connection via close(ChannelPromise)
or close()
if it is not possible to recover.
This will result in having the message added to the outbound buffer of the next ChannelOutboundHandler
and the ChannelOperationHandler.flush(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture sendFile(FileRegion region)
FileRegion
via this ChannelOutboundInvoker and notify the ChannelFuture
once the operation completes, either because the operation was successful or because of an error.
This will result in having the
ChannelOperationHandler.sendFile(ChannelHandlerContext, FileRegion, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise)
SocketAddress
and notify the ChannelFuture
once the operation
completes, either because the operation was successful or because of an error.
The given ChannelPromise
will be notified.
This will result in having the
ChannelOperationHandler.bind(ChannelHandlerContext, SocketAddress, ChannelPromise)
method
called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise)
SocketAddress
and notify the ChannelFuture
once the operation
completes, either because the operation was successful or because of an error.
The given ChannelFuture
will be notified.
If the connection fails because of a connection timeout, the ChannelFuture
will get failed with
a ConnectTimeoutException
. If it fails because of connection refused a ConnectException
will be used.
This will result in having the
ChannelOperationHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise)
SocketAddress
while bind to the localAddress and notify the
ChannelFuture
once the operation completes, either because the operation was successful or because of
an error.
The given ChannelPromise
will be notified and also returned.
This will result in having the
ChannelOperationHandler.connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture disconnect(ChannelPromise promise)
ChannelFuture
once the operation completes,
either because the operation was successful or because of an error.
The given ChannelPromise
will be notified.
This will result in having the
ChannelOperationHandler.disconnect(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture close(ChannelPromise promise)
ChannelFuture
once the operation completes,
either because the operation was successful or because of
an error.
After it is closed it is not possible to reuse it again.
The given ChannelPromise
will be notified.
This will result in having the
ChannelOperationHandler.close(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture deregister(ChannelPromise promise)
EventExecutor
and notify the
ChannelFuture
once the operation completes, either because the operation was successful or because of
an error.
The given ChannelPromise
will be notified.
This will result in having the
ChannelOperationHandler.deregister(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public void read()
Channel
into the first inbound buffer, triggers an
inboundBufferUpdated
event if data was
read, and triggers an
channelReadSuspended
event so the
handler can decide to continue reading. If there's a pending read operation already, this method does nothing.
This will result in having the
ChannelOperationHandler.read(ChannelHandlerContext)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture flush(ChannelPromise promise)
ChannelFuture
once the operation completes, either because the operation was successful or because of
an error.
Be aware that the flush could be only partially successful. In such cases the ChannelFuture
will be
failed with an IncompleteFlushException
. So if you are interested to know if it was partial successful
you need to check if the returned Future.cause()
returns an instance of
IncompleteFlushException
. In such cases you may want to call flush(ChannelPromise)
or
flush()
to flush the rest of the data or just close the connection via close(ChannelPromise)
or
close()
if it is not possible to recover.
The given ChannelPromise
will be notified.
This will result in having the
ChannelOperationHandler.flush(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture write(Object message, ChannelPromise promise)
ChannelFuture
once the operation completes, either because the operation was successful or because of an error.
If you want to write a FileRegion
use sendFile(FileRegion)
.
Be aware that the write could be only partially successful as the message may need to get encoded before write it
to the remote peer. In such cases the ChannelFuture
will be failed with a
IncompleteFlushException
. In such cases you may want to call flush(ChannelPromise)
or
flush()
to flush the rest of the data or just close the connection via close(ChannelPromise)
or close()
if it is not possible to recover.
The given ChannelPromise
will be notified.
This will result in having the message added to the outbound buffer of the next ChannelOutboundHandler
and the ChannelOperationHandler.flush(ChannelHandlerContext, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelFuture sendFile(FileRegion region, ChannelPromise promise)
FileRegion
via this ChannelOutboundInvoker and notify the ChannelFuture
once the operation completes, either because the operation was successful or because of an error.
The given ChannelPromise
will be notified.
This will result in having the
ChannelOperationHandler.sendFile(ChannelHandlerContext, FileRegion, ChannelPromise)
method called of the next ChannelOperationHandler
contained in the ChannelPipeline
of the
Channel
.
public ChannelPipeline pipeline()
ChannelPipeline
public ByteBufAllocator alloc()
ByteBufAllocator
which will be used for allocate ByteBuf
s.public ChannelPromise newPromise()
FutureFactory
Promise
.newPromise
in interface FutureFactory
public ChannelFuture newSucceededFuture()
FutureFactory
Future
which is marked as successes already. So Future.isSuccess()
will return true
. All FutureListener
added to it will be notified directly. Also
every call of blocking methods will just return without blocking.newSucceededFuture
in interface FutureFactory
public ChannelFuture newFailedFuture(Throwable cause)
FutureFactory
Future
which is marked as fakued already. So Future.isSuccess()
will return false
. All FutureListener
added to it will be notified directly. Also
every call of blocking methods will just return without blocking.newFailedFuture
in interface FutureFactory
Copyright © 2008-2013 The Netty Project. All Rights Reserved.