Add ChannelInboundInvoker and ChannelOutboundInvoker
Motivation: ChannelHandlerContext, ChannelPipeline and Channel share various method signatures. We should provide an interface to share. Modifications: Add ChannelInboundInvoker and ChannelOutboundInvoker and extend these. Result: Better API abstraction.
This commit is contained in:
parent
01109dd635
commit
27a392b877
@ -56,8 +56,6 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
|||||||
private final ChannelId id;
|
private final ChannelId id;
|
||||||
private final Unsafe unsafe;
|
private final Unsafe unsafe;
|
||||||
private final DefaultChannelPipeline pipeline;
|
private final DefaultChannelPipeline pipeline;
|
||||||
private final ChannelFuture succeededFuture = new SucceededChannelFuture(this, null);
|
|
||||||
private final VoidChannelPromise voidPromise = new VoidChannelPromise(this, true);
|
|
||||||
private final VoidChannelPromise unsafeVoidPromise = new VoidChannelPromise(this, false);
|
private final VoidChannelPromise unsafeVoidPromise = new VoidChannelPromise(this, false);
|
||||||
private final CloseFuture closeFuture = new CloseFuture(this);
|
private final CloseFuture closeFuture = new CloseFuture(this);
|
||||||
|
|
||||||
@ -293,22 +291,22 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelPromise newPromise() {
|
public ChannelPromise newPromise() {
|
||||||
return new DefaultChannelPromise(this);
|
return pipeline.newPromise();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelProgressivePromise newProgressivePromise() {
|
public ChannelProgressivePromise newProgressivePromise() {
|
||||||
return new DefaultChannelProgressivePromise(this);
|
return pipeline.newProgressivePromise();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelFuture newSucceededFuture() {
|
public ChannelFuture newSucceededFuture() {
|
||||||
return succeededFuture;
|
return pipeline.newSucceededFuture();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelFuture newFailedFuture(Throwable cause) {
|
public ChannelFuture newFailedFuture(Throwable cause) {
|
||||||
return new FailedChannelFuture(this, null, cause);
|
return pipeline.newFailedFuture(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -400,7 +398,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ChannelPromise voidPromise() {
|
public final ChannelPromise voidPromise() {
|
||||||
return voidPromise;
|
return pipeline.voidPromise();
|
||||||
}
|
}
|
||||||
|
|
||||||
final MessageSizeEstimator.Handle estimatorHandle() {
|
final MessageSizeEstimator.Handle estimatorHandle() {
|
||||||
|
@ -77,7 +77,7 @@ import java.net.SocketAddress;
|
|||||||
* resources once you are done with the {@link Channel}. This ensures all resources are
|
* resources once you are done with the {@link Channel}. This ensures all resources are
|
||||||
* released in a proper way, i.e. filehandles.
|
* released in a proper way, i.e. filehandles.
|
||||||
*/
|
*/
|
||||||
public interface Channel extends AttributeMap, Comparable<Channel> {
|
public interface Channel extends AttributeMap, ChannelOutboundInvoker, Comparable<Channel> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the globally unique identifier of this {@link Channel}.
|
* Returns the globally unique identifier of this {@link Channel}.
|
||||||
@ -190,252 +190,12 @@ public interface Channel extends AttributeMap, Comparable<Channel> {
|
|||||||
*/
|
*/
|
||||||
ByteBufAllocator alloc();
|
ByteBufAllocator alloc();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Return a new {@link ChannelPromise}.
|
|
||||||
*/
|
|
||||||
ChannelPromise newPromise();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an new {@link ChannelProgressivePromise}.
|
|
||||||
*/
|
|
||||||
ChannelProgressivePromise newProgressivePromise();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link ChannelFuture} which is marked as succeeded already. So {@link ChannelFuture#isSuccess()}
|
|
||||||
* will return {@code true}. All {@link FutureListener} added to it will be notified directly. Also
|
|
||||||
* every call of blocking methods will just return without blocking.
|
|
||||||
*/
|
|
||||||
ChannelFuture newSucceededFuture();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link ChannelFuture} which is marked as failed already. So {@link ChannelFuture#isSuccess()}
|
|
||||||
* will return {@code false}. All {@link FutureListener} added to it will be notified directly. Also
|
|
||||||
* every call of blocking methods will just return without blocking.
|
|
||||||
*/
|
|
||||||
ChannelFuture newFailedFuture(Throwable cause);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a special ChannelPromise which can be reused for different operations.
|
|
||||||
* <p>
|
|
||||||
* It's only supported to use
|
|
||||||
* it for {@link Channel#write(Object, ChannelPromise)}.
|
|
||||||
* </p>
|
|
||||||
* <p>
|
|
||||||
* Be aware that the returned {@link ChannelPromise} will not support most operations and should only be used
|
|
||||||
* if you want to save an object allocation for every write operation. You will not be able to detect if the
|
|
||||||
* operation was complete, only if it failed as the implementation will call
|
|
||||||
* {@link ChannelPipeline#fireExceptionCaught(Throwable)} in this case.
|
|
||||||
* </p>
|
|
||||||
* <strong>Be aware this is an expert feature and should be used with care!</strong>
|
|
||||||
*/
|
|
||||||
ChannelPromise voidPromise();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
|
||||||
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture bind(SocketAddress localAddress);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
* <p>
|
|
||||||
* If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
|
||||||
* a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
|
||||||
* will be used.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
|
|
||||||
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
||||||
* an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,
|
|
||||||
* either because the operation was successful or because of an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture disconnect();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to close this {@link Channel} and notify the {@link 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.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture close();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to deregister this {@link Channel} from the previous assigned {@link EventExecutor} and notify the
|
|
||||||
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
||||||
* an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#deregister(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
ChannelFuture deregister();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
|
||||||
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelFuture} will be notified.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
|
||||||
* a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
|
||||||
* will be used.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
|
|
||||||
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
||||||
* an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified and also returned.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,
|
|
||||||
* either because the operation was successful or because of an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture disconnect(ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to close this {@link Channel} and notify the {@link 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 {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture close(ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to deregister this {@link Channel} from the previous assigned {@link EventExecutor} and notify the
|
|
||||||
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
||||||
* an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#deregister(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture deregister(ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to Read data from the {@link Channel} into the first inbound buffer, triggers an
|
|
||||||
* {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)} event if data was
|
|
||||||
* read, and triggers a
|
|
||||||
* {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the
|
|
||||||
* handler can decide to continue reading. If there's a pending read operation already, this method does nothing.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#read(ChannelHandlerContext)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
Channel read();
|
Channel read();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Request to write a message via this {@link Channel} through the {@link ChannelPipeline}.
|
|
||||||
* This method will not request to actual flush, so be sure to call {@link #flush()}
|
|
||||||
* once you want to request to flush all pending data to the actual transport.
|
|
||||||
*/
|
|
||||||
ChannelFuture write(Object msg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to write a message via this {@link Channel} through the {@link ChannelPipeline}.
|
|
||||||
* This method will not request to actual flush, so be sure to call {@link #flush()}
|
|
||||||
* once you want to request to flush all pending data to the actual transport.
|
|
||||||
*/
|
|
||||||
ChannelFuture write(Object msg, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to flush all pending messages.
|
|
||||||
*/
|
|
||||||
Channel flush();
|
Channel flush();
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut for call {@link #write(Object, ChannelPromise)} and {@link #flush()}.
|
|
||||||
*/
|
|
||||||
ChannelFuture writeAndFlush(Object msg, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut for call {@link #write(Object)} and {@link #flush()}.
|
|
||||||
*/
|
|
||||||
ChannelFuture writeAndFlush(Object msg);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <em>Unsafe</em> operations that should <em>never</em> be called from user-code. These methods
|
* <em>Unsafe</em> operations that should <em>never</em> be called from user-code. These methods
|
||||||
* are only provided to implement the actual transport, and must be invoked from an I/O thread except for the
|
* are only provided to implement the actual transport, and must be invoked from an I/O thread except for the
|
||||||
|
@ -21,10 +21,7 @@ import io.netty.util.Attribute;
|
|||||||
import io.netty.util.AttributeKey;
|
import io.netty.util.AttributeKey;
|
||||||
import io.netty.util.AttributeMap;
|
import io.netty.util.AttributeMap;
|
||||||
import io.netty.util.concurrent.EventExecutor;
|
import io.netty.util.concurrent.EventExecutor;
|
||||||
import io.netty.util.concurrent.FutureListener;
|
|
||||||
|
|
||||||
import java.net.ConnectException;
|
|
||||||
import java.net.SocketAddress;
|
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,7 +122,7 @@ import java.nio.channels.Channels;
|
|||||||
* what fundamental differences they have, how they flow in a pipeline, and how to handle
|
* what fundamental differences they have, how they flow in a pipeline, and how to handle
|
||||||
* the operation in your application.
|
* the operation in your application.
|
||||||
*/
|
*/
|
||||||
public interface ChannelHandlerContext extends AttributeMap {
|
public interface ChannelHandlerContext extends AttributeMap, ChannelInboundInvoker, ChannelOutboundInvoker {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the {@link Channel} which is bound to the {@link ChannelHandlerContext}.
|
* Return the {@link Channel} which is bound to the {@link ChannelHandlerContext}.
|
||||||
@ -164,287 +161,39 @@ public interface ChannelHandlerContext extends AttributeMap {
|
|||||||
*/
|
*/
|
||||||
boolean isRemoved();
|
boolean isRemoved();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} was registered to its {@link EventLoop}.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#channelRegistered(ChannelHandlerContext)} method
|
|
||||||
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelHandlerContext fireChannelRegistered();
|
ChannelHandlerContext fireChannelRegistered();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} was unregistered from its {@link EventLoop}.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#channelUnregistered(ChannelHandlerContext)} method
|
|
||||||
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelHandlerContext fireChannelUnregistered();
|
ChannelHandlerContext fireChannelUnregistered();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} is active now, which means it is connected.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#channelActive(ChannelHandlerContext)} method
|
|
||||||
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelHandlerContext fireChannelActive();
|
ChannelHandlerContext fireChannelActive();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} is inactive now, which means it is closed.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#channelInactive(ChannelHandlerContext)} method
|
|
||||||
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelHandlerContext fireChannelInactive();
|
ChannelHandlerContext fireChannelInactive();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} received an {@link Throwable} in one of its inbound operations.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#exceptionCaught(ChannelHandlerContext, Throwable)}
|
|
||||||
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelHandlerContext fireExceptionCaught(Throwable cause);
|
ChannelHandlerContext fireExceptionCaught(Throwable cause);
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} received an user defined event.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)}
|
|
||||||
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelHandlerContext fireUserEventTriggered(Object event);
|
ChannelHandlerContext fireUserEventTriggered(Object event);
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} received a message.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)}
|
|
||||||
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelHandlerContext fireChannelRead(Object msg);
|
ChannelHandlerContext fireChannelRead(Object msg);
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Triggers an {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext)}
|
|
||||||
* event to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
|
|
||||||
*/
|
|
||||||
ChannelHandlerContext fireChannelReadComplete();
|
ChannelHandlerContext fireChannelReadComplete();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Triggers an {@link ChannelInboundHandler#channelWritabilityChanged(ChannelHandlerContext)}
|
|
||||||
* event to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
|
|
||||||
*/
|
|
||||||
ChannelHandlerContext fireChannelWritabilityChanged();
|
ChannelHandlerContext fireChannelWritabilityChanged();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
|
||||||
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture bind(SocketAddress localAddress);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
* <p>
|
|
||||||
* If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
|
||||||
* a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
|
||||||
* will be used.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
|
|
||||||
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
||||||
* an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,
|
|
||||||
* either because the operation was successful or because of an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture disconnect();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to close the {@link Channel} and notify the {@link 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.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture close();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to deregister from the previous assigned {@link EventExecutor} and notify the
|
|
||||||
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
||||||
* an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#deregister(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
ChannelFuture deregister();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
|
||||||
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelFuture} will be notified.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
|
||||||
* a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
|
||||||
* will be used.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
|
|
||||||
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
||||||
* an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified and also returned.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,
|
|
||||||
* either because the operation was successful or because of an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture disconnect(ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to close the {@link Channel} and notify the {@link 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 {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture close(ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to deregister from the previous assigned {@link EventExecutor} and notify the
|
|
||||||
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
||||||
* an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#deregister(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture deregister(ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to Read data from the {@link Channel} into the first inbound buffer, triggers an
|
|
||||||
* {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)} event if data was
|
|
||||||
* read, and triggers a
|
|
||||||
* {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the
|
|
||||||
* handler can decide to continue reading. If there's a pending read operation already, this method does nothing.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#read(ChannelHandlerContext)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelHandlerContext read();
|
ChannelHandlerContext read();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Request to write a message via this {@link ChannelHandlerContext} through the {@link ChannelPipeline}.
|
|
||||||
* This method will not request to actual flush, so be sure to call {@link #flush()}
|
|
||||||
* once you want to request to flush all pending data to the actual transport.
|
|
||||||
*/
|
|
||||||
ChannelFuture write(Object msg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to write a message via this {@link ChannelHandlerContext} through the {@link ChannelPipeline}.
|
|
||||||
* This method will not request to actual flush, so be sure to call {@link #flush()}
|
|
||||||
* once you want to request to flush all pending data to the actual transport.
|
|
||||||
*/
|
|
||||||
ChannelFuture write(Object msg, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to flush all pending messages via this ChannelOutboundInvoker.
|
|
||||||
*/
|
|
||||||
ChannelHandlerContext flush();
|
ChannelHandlerContext flush();
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut for call {@link #write(Object, ChannelPromise)} and {@link #flush()}.
|
|
||||||
*/
|
|
||||||
ChannelFuture writeAndFlush(Object msg, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut for call {@link #write(Object)} and {@link #flush()}.
|
|
||||||
*/
|
|
||||||
ChannelFuture writeAndFlush(Object msg);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the assigned {@link ChannelPipeline}
|
* Return the assigned {@link ChannelPipeline}
|
||||||
*/
|
*/
|
||||||
@ -455,46 +204,6 @@ public interface ChannelHandlerContext extends AttributeMap {
|
|||||||
*/
|
*/
|
||||||
ByteBufAllocator alloc();
|
ByteBufAllocator alloc();
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a new {@link ChannelPromise}.
|
|
||||||
*/
|
|
||||||
ChannelPromise newPromise();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an new {@link ChannelProgressivePromise}
|
|
||||||
*/
|
|
||||||
ChannelProgressivePromise newProgressivePromise();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link ChannelFuture} which is marked as succeeded already. So {@link ChannelFuture#isSuccess()}
|
|
||||||
* will return {@code true}. All {@link FutureListener} added to it will be notified directly. Also
|
|
||||||
* every call of blocking methods will just return without blocking.
|
|
||||||
*/
|
|
||||||
ChannelFuture newSucceededFuture();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link ChannelFuture} which is marked as failed already. So {@link ChannelFuture#isSuccess()}
|
|
||||||
* will return {@code false}. All {@link FutureListener} added to it will be notified directly. Also
|
|
||||||
* every call of blocking methods will just return without blocking.
|
|
||||||
*/
|
|
||||||
ChannelFuture newFailedFuture(Throwable cause);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a special ChannelPromise which can be reused for different operations.
|
|
||||||
* <p>
|
|
||||||
* It's only supported to use
|
|
||||||
* it for {@link ChannelHandlerContext#write(Object, ChannelPromise)}.
|
|
||||||
* </p>
|
|
||||||
* <p>
|
|
||||||
* Be aware that the returned {@link ChannelPromise} will not support most operations and should only be used
|
|
||||||
* if you want to save an object allocation for every write operation. You will not be able to detect if the
|
|
||||||
* operation was complete, only if it failed as the implementation will call
|
|
||||||
* {@link ChannelPipeline#fireExceptionCaught(Throwable)} in this case.
|
|
||||||
* </p>
|
|
||||||
* <strong>Be aware this is an expert feature and should be used with care!</strong>
|
|
||||||
*/
|
|
||||||
ChannelPromise voidPromise();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link Channel#attr(AttributeKey)}
|
* @deprecated Use {@link Channel#attr(AttributeKey)}
|
||||||
*/
|
*/
|
||||||
@ -508,5 +217,4 @@ public interface ChannelHandlerContext extends AttributeMap {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
<T> boolean hasAttr(AttributeKey<T> key);
|
<T> boolean hasAttr(AttributeKey<T> key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project licenses this file to you under the Apache License,
|
||||||
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at:
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.netty.channel;
|
||||||
|
|
||||||
|
public interface ChannelInboundInvoker {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link Channel} was registered to its {@link EventLoop}.
|
||||||
|
*
|
||||||
|
* This will result in having the {@link ChannelInboundHandler#channelRegistered(ChannelHandlerContext)} method
|
||||||
|
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelInboundInvoker fireChannelRegistered();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link Channel} was unregistered from its {@link EventLoop}.
|
||||||
|
*
|
||||||
|
* This will result in having the {@link ChannelInboundHandler#channelUnregistered(ChannelHandlerContext)} method
|
||||||
|
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelInboundInvoker fireChannelUnregistered();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link Channel} is active now, which means it is connected.
|
||||||
|
*
|
||||||
|
* This will result in having the {@link ChannelInboundHandler#channelActive(ChannelHandlerContext)} method
|
||||||
|
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelInboundInvoker fireChannelActive();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link Channel} is inactive now, which means it is closed.
|
||||||
|
*
|
||||||
|
* This will result in having the {@link ChannelInboundHandler#channelInactive(ChannelHandlerContext)} method
|
||||||
|
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelInboundInvoker fireChannelInactive();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link Channel} received an {@link Throwable} in one of its inbound operations.
|
||||||
|
*
|
||||||
|
* This will result in having the {@link ChannelInboundHandler#exceptionCaught(ChannelHandlerContext, Throwable)}
|
||||||
|
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelInboundInvoker fireExceptionCaught(Throwable cause);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link Channel} received an user defined event.
|
||||||
|
*
|
||||||
|
* This will result in having the {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)}
|
||||||
|
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelInboundInvoker fireUserEventTriggered(Object event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link Channel} received a message.
|
||||||
|
*
|
||||||
|
* This will result in having the {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)}
|
||||||
|
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelInboundInvoker fireChannelRead(Object msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers an {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext)}
|
||||||
|
* event to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
|
||||||
|
*/
|
||||||
|
ChannelInboundInvoker fireChannelReadComplete();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers an {@link ChannelInboundHandler#channelWritabilityChanged(ChannelHandlerContext)}
|
||||||
|
* event to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
|
||||||
|
*/
|
||||||
|
ChannelInboundInvoker fireChannelWritabilityChanged();
|
||||||
|
}
|
@ -0,0 +1,271 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project licenses this file to you under the Apache License,
|
||||||
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at:
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.netty.channel;
|
||||||
|
|
||||||
|
import io.netty.util.concurrent.EventExecutor;
|
||||||
|
import io.netty.util.concurrent.FutureListener;
|
||||||
|
|
||||||
|
import java.net.ConnectException;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
|
||||||
|
public interface ChannelOutboundInvoker {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
||||||
|
* completes, either because the operation was successful or because of an error.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
||||||
|
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelFuture bind(SocketAddress localAddress);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
||||||
|
* completes, either because the operation was successful or because of an error.
|
||||||
|
* <p>
|
||||||
|
* If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
||||||
|
* a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
||||||
|
* will be used.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
||||||
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelFuture connect(SocketAddress remoteAddress);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
|
||||||
|
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
||||||
|
* an error.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
||||||
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,
|
||||||
|
* either because the operation was successful or because of an error.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
||||||
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelFuture disconnect();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to close the {@link Channel} and notify the {@link 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.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)}
|
||||||
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelFuture close();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to deregister from the previous assigned {@link EventExecutor} and notify the
|
||||||
|
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
||||||
|
* an error.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#deregister(ChannelHandlerContext, ChannelPromise)}
|
||||||
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
ChannelFuture deregister();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
||||||
|
* completes, either because the operation was successful or because of an error.
|
||||||
|
*
|
||||||
|
* The given {@link ChannelPromise} will be notified.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
||||||
|
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
||||||
|
* completes, either because the operation was successful or because of an error.
|
||||||
|
*
|
||||||
|
* The given {@link ChannelFuture} will be notified.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
||||||
|
* a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
||||||
|
* will be used.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
||||||
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
|
||||||
|
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
||||||
|
* an error.
|
||||||
|
*
|
||||||
|
* The given {@link ChannelPromise} will be notified and also returned.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
||||||
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,
|
||||||
|
* either because the operation was successful or because of an error.
|
||||||
|
*
|
||||||
|
* The given {@link ChannelPromise} will be notified.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
||||||
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelFuture disconnect(ChannelPromise promise);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to close the {@link Channel} and notify the {@link 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 {@link ChannelPromise} will be notified.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)}
|
||||||
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelFuture close(ChannelPromise promise);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to deregister from the previous assigned {@link EventExecutor} and notify the
|
||||||
|
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
||||||
|
* an error.
|
||||||
|
*
|
||||||
|
* The given {@link ChannelPromise} will be notified.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#deregister(ChannelHandlerContext, ChannelPromise)}
|
||||||
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelFuture deregister(ChannelPromise promise);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to Read data from the {@link Channel} into the first inbound buffer, triggers an
|
||||||
|
* {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)} event if data was
|
||||||
|
* read, and triggers a
|
||||||
|
* {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the
|
||||||
|
* handler can decide to continue reading. If there's a pending read operation already, this method does nothing.
|
||||||
|
* <p>
|
||||||
|
* This will result in having the
|
||||||
|
* {@link ChannelOutboundHandler#read(ChannelHandlerContext)}
|
||||||
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
||||||
|
* {@link Channel}.
|
||||||
|
*/
|
||||||
|
ChannelOutboundInvoker read();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to write a message via this {@link ChannelHandlerContext} through the {@link ChannelPipeline}.
|
||||||
|
* This method will not request to actual flush, so be sure to call {@link #flush()}
|
||||||
|
* once you want to request to flush all pending data to the actual transport.
|
||||||
|
*/
|
||||||
|
ChannelFuture write(Object msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to write a message via this {@link ChannelHandlerContext} through the {@link ChannelPipeline}.
|
||||||
|
* This method will not request to actual flush, so be sure to call {@link #flush()}
|
||||||
|
* once you want to request to flush all pending data to the actual transport.
|
||||||
|
*/
|
||||||
|
ChannelFuture write(Object msg, ChannelPromise promise);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to flush all pending messages via this ChannelOutboundInvoker.
|
||||||
|
*/
|
||||||
|
ChannelOutboundInvoker flush();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut for call {@link #write(Object, ChannelPromise)} and {@link #flush()}.
|
||||||
|
*/
|
||||||
|
ChannelFuture writeAndFlush(Object msg, ChannelPromise promise);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut for call {@link #write(Object)} and {@link #flush()}.
|
||||||
|
*/
|
||||||
|
ChannelFuture writeAndFlush(Object msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a new {@link ChannelPromise}.
|
||||||
|
*/
|
||||||
|
ChannelPromise newPromise();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an new {@link ChannelProgressivePromise}
|
||||||
|
*/
|
||||||
|
ChannelProgressivePromise newProgressivePromise();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link ChannelFuture} which is marked as succeeded already. So {@link ChannelFuture#isSuccess()}
|
||||||
|
* will return {@code true}. All {@link FutureListener} added to it will be notified directly. Also
|
||||||
|
* every call of blocking methods will just return without blocking.
|
||||||
|
*/
|
||||||
|
ChannelFuture newSucceededFuture();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link ChannelFuture} which is marked as failed already. So {@link ChannelFuture#isSuccess()}
|
||||||
|
* will return {@code false}. All {@link FutureListener} added to it will be notified directly. Also
|
||||||
|
* every call of blocking methods will just return without blocking.
|
||||||
|
*/
|
||||||
|
ChannelFuture newFailedFuture(Throwable cause);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a special ChannelPromise which can be reused for different operations.
|
||||||
|
* <p>
|
||||||
|
* It's only supported to use
|
||||||
|
* it for {@link ChannelOutboundInvoker#write(Object, ChannelPromise)}.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Be aware that the returned {@link ChannelPromise} will not support most operations and should only be used
|
||||||
|
* if you want to save an object allocation for every write operation. You will not be able to detect if the
|
||||||
|
* operation was complete, only if it failed as the implementation will call
|
||||||
|
* {@link ChannelPipeline#fireExceptionCaught(Throwable)} in this case.
|
||||||
|
* </p>
|
||||||
|
* <strong>Be aware this is an expert feature and should be used with care!</strong>
|
||||||
|
*/
|
||||||
|
ChannelPromise voidPromise();
|
||||||
|
}
|
@ -17,10 +17,8 @@ package io.netty.channel;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
||||||
import io.netty.util.concurrent.EventExecutor;
|
|
||||||
import io.netty.util.concurrent.EventExecutorGroup;
|
import io.netty.util.concurrent.EventExecutorGroup;
|
||||||
|
|
||||||
import java.net.ConnectException;
|
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
@ -215,7 +213,8 @@ import java.util.NoSuchElementException;
|
|||||||
* For example, you can insert an encryption handler when sensitive information is about to be exchanged, and remove it
|
* For example, you can insert an encryption handler when sensitive information is about to be exchanged, and remove it
|
||||||
* after the exchange.
|
* after the exchange.
|
||||||
*/
|
*/
|
||||||
public interface ChannelPipeline extends Iterable<Entry<String, ChannelHandler>> {
|
public interface ChannelPipeline
|
||||||
|
extends ChannelInboundInvoker, ChannelOutboundInvoker, Iterable<Entry<String, ChannelHandler>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a {@link ChannelHandler} at the first position of this pipeline.
|
* Inserts a {@link ChannelHandler} at the first position of this pipeline.
|
||||||
@ -677,284 +676,33 @@ public interface ChannelPipeline extends Iterable<Entry<String, ChannelHandler>>
|
|||||||
*/
|
*/
|
||||||
Map<String, ChannelHandler> toMap();
|
Map<String, ChannelHandler> toMap();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} was registered to its {@link EventLoop}.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#channelRegistered(ChannelHandlerContext)} method
|
|
||||||
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelPipeline fireChannelRegistered();
|
ChannelPipeline fireChannelRegistered();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} was unregistered from its {@link EventLoop}.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#channelUnregistered(ChannelHandlerContext)} method
|
|
||||||
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelPipeline fireChannelUnregistered();
|
ChannelPipeline fireChannelUnregistered();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} is active now, which means it is connected.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#channelActive(ChannelHandlerContext)} method
|
|
||||||
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelPipeline fireChannelActive();
|
ChannelPipeline fireChannelActive();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} is inactive now, which means it is closed.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#channelInactive(ChannelHandlerContext)} method
|
|
||||||
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelPipeline fireChannelInactive();
|
ChannelPipeline fireChannelInactive();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} received an {@link Throwable} in one of its inbound operations.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#exceptionCaught(ChannelHandlerContext, Throwable)}
|
|
||||||
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelPipeline fireExceptionCaught(Throwable cause);
|
ChannelPipeline fireExceptionCaught(Throwable cause);
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} received an user defined event.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)}
|
|
||||||
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelPipeline fireUserEventTriggered(Object event);
|
ChannelPipeline fireUserEventTriggered(Object event);
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* A {@link Channel} received a message.
|
|
||||||
*
|
|
||||||
* This will result in having the {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)}
|
|
||||||
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelPipeline fireChannelRead(Object msg);
|
ChannelPipeline fireChannelRead(Object msg);
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Triggers an {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext)}
|
|
||||||
* event to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
|
|
||||||
*/
|
|
||||||
ChannelPipeline fireChannelReadComplete();
|
ChannelPipeline fireChannelReadComplete();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Triggers an {@link ChannelInboundHandler#channelWritabilityChanged(ChannelHandlerContext)}
|
|
||||||
* event to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
|
|
||||||
*/
|
|
||||||
ChannelPipeline fireChannelWritabilityChanged();
|
ChannelPipeline fireChannelWritabilityChanged();
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
|
||||||
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture bind(SocketAddress localAddress);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
* <p>
|
|
||||||
* If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
|
||||||
* a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
|
||||||
* will be used.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
|
|
||||||
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
||||||
* an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,
|
|
||||||
* either because the operation was successful or because of an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture disconnect();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to close the {@link Channel} and notify the {@link 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.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture close();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to deregister the {@link Channel} from the previous assigned {@link EventExecutor} and notify the
|
|
||||||
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
||||||
* an error.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#deregister(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
ChannelFuture deregister();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
|
||||||
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
||||||
* completes, either because the operation was successful or because of an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelFuture} will be notified.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
|
||||||
* a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
|
||||||
* will be used.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
|
|
||||||
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
||||||
* an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified and also returned.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,
|
|
||||||
* either because the operation was successful or because of an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture disconnect(ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to close the {@link Channel} bound to this {@link ChannelPipeline} and notify the {@link 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 {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture close(ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to deregister the {@link Channel} bound this {@link ChannelPipeline} from the previous assigned
|
|
||||||
* {@link EventExecutor} and notify the {@link ChannelFuture} once the operation completes, either because the
|
|
||||||
* operation was successful or because of an error.
|
|
||||||
*
|
|
||||||
* The given {@link ChannelPromise} will be notified.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#deregister(ChannelHandlerContext, ChannelPromise)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelFuture deregister(ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to Read data from the {@link Channel} into the first inbound buffer, triggers an
|
|
||||||
* {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)} event if data was
|
|
||||||
* read, and triggers a
|
|
||||||
* {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the
|
|
||||||
* handler can decide to continue reading. If there's a pending read operation already, this method does nothing.
|
|
||||||
* <p>
|
|
||||||
* This will result in having the
|
|
||||||
* {@link ChannelOutboundHandler#read(ChannelHandlerContext)}
|
|
||||||
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
||||||
* {@link Channel}.
|
|
||||||
*/
|
|
||||||
ChannelPipeline read();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to write a message via this {@link ChannelPipeline}.
|
|
||||||
* This method will not request to actual flush, so be sure to call {@link #flush()}
|
|
||||||
* once you want to request to flush all pending data to the actual transport.
|
|
||||||
*/
|
|
||||||
ChannelFuture write(Object msg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to write a message via this {@link ChannelPipeline}.
|
|
||||||
* This method will not request to actual flush, so be sure to call {@link #flush()}
|
|
||||||
* once you want to request to flush all pending data to the actual transport.
|
|
||||||
*/
|
|
||||||
ChannelFuture write(Object msg, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request to flush all pending messages.
|
|
||||||
*/
|
|
||||||
ChannelPipeline flush();
|
ChannelPipeline flush();
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut for call {@link #write(Object, ChannelPromise)} and {@link #flush()}.
|
|
||||||
*/
|
|
||||||
ChannelFuture writeAndFlush(Object msg, ChannelPromise promise);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut for call {@link #write(Object)} and {@link #flush()}.
|
|
||||||
*/
|
|
||||||
ChannelFuture writeAndFlush(Object msg);
|
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,8 @@ final class DefaultChannelPipeline implements ChannelPipeline {
|
|||||||
final AbstractChannelHandlerContext head;
|
final AbstractChannelHandlerContext head;
|
||||||
final AbstractChannelHandlerContext tail;
|
final AbstractChannelHandlerContext tail;
|
||||||
|
|
||||||
|
private final ChannelFuture succeededFuture;
|
||||||
|
private final VoidChannelPromise voidPromise;
|
||||||
private final boolean touch = ResourceLeakDetector.isEnabled();
|
private final boolean touch = ResourceLeakDetector.isEnabled();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,6 +91,8 @@ final class DefaultChannelPipeline implements ChannelPipeline {
|
|||||||
throw new NullPointerException("channel");
|
throw new NullPointerException("channel");
|
||||||
}
|
}
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
succeededFuture = new SucceededChannelFuture(channel, null);
|
||||||
|
voidPromise = new VoidChannelPromise(channel, true);
|
||||||
|
|
||||||
tail = new TailContext(this);
|
tail = new TailContext(this);
|
||||||
head = new HeadContext(this);
|
head = new HeadContext(this);
|
||||||
@ -1186,6 +1190,31 @@ final class DefaultChannelPipeline implements ChannelPipeline {
|
|||||||
return tail.writeAndFlush(msg);
|
return tail.writeAndFlush(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelPromise newPromise() {
|
||||||
|
return new DefaultChannelPromise(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelProgressivePromise newProgressivePromise() {
|
||||||
|
return new DefaultChannelProgressivePromise(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelFuture newSucceededFuture() {
|
||||||
|
return succeededFuture;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelFuture newFailedFuture(Throwable cause) {
|
||||||
|
return new FailedChannelFuture(channel, null, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelPromise voidPromise() {
|
||||||
|
return voidPromise;
|
||||||
|
}
|
||||||
|
|
||||||
private String filterName(String name, ChannelHandler handler) {
|
private String filterName(String name, ChannelHandler handler) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return generateName(handler);
|
return generateName(handler);
|
||||||
|
Loading…
Reference in New Issue
Block a user