Add more javadocs and replace some abstract methods with noops as we often implemented them as noops
This commit is contained in:
parent
3e31af68e4
commit
ef555d268c
@ -195,6 +195,9 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
return remoteAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the stored remoteAddress
|
||||
*/
|
||||
protected void invalidateRemoteAddress() {
|
||||
remoteAddress = null;
|
||||
}
|
||||
@ -330,7 +333,10 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
return pipeline.sendFile(region, future);
|
||||
}
|
||||
|
||||
protected abstract Unsafe newUnsafe();
|
||||
/**
|
||||
* Create a new {@link AbstractUnsafe} instance which will be used for the life-time of the {@link Channel}
|
||||
*/
|
||||
protected abstract AbstractUnsafe newUnsafe();
|
||||
|
||||
/**
|
||||
* Returns the ID of this channel.
|
||||
@ -393,6 +399,9 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
return strVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Unsafe} implementation which sub-classes must extend and use.
|
||||
*/
|
||||
protected abstract class AbstractUnsafe implements Unsafe {
|
||||
|
||||
private final class FlushTask {
|
||||
@ -865,27 +874,86 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if the given {@link EventLoop} is compatible with this instance.
|
||||
*/
|
||||
protected abstract boolean isCompatible(EventLoop loop);
|
||||
|
||||
/**
|
||||
* Returns the {@link SocketAddress} which is bound locally.
|
||||
*/
|
||||
protected abstract SocketAddress localAddress0();
|
||||
|
||||
/**
|
||||
* Return the {@link SocketAddress} which the {@link Channel} is connected to.
|
||||
*/
|
||||
protected abstract SocketAddress remoteAddress0();
|
||||
|
||||
protected abstract Runnable doRegister() throws Exception;
|
||||
/**
|
||||
* Is called after the {@link Channel} is registered with its {@link EventLoop} as part of the register process.
|
||||
* You can return a {@link Runnable} which will be run as post-task of the registration process.
|
||||
*
|
||||
* Sub-classes may override this method as it will just return {@code null}
|
||||
*/
|
||||
protected Runnable doRegister() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the {@link Channel} to the {@link SocketAddress}
|
||||
*/
|
||||
protected abstract void doBind(SocketAddress localAddress) throws Exception;
|
||||
|
||||
/**
|
||||
* Disconnect this {@link Channel} from its remote peer
|
||||
*/
|
||||
protected abstract void doDisconnect() throws Exception;
|
||||
|
||||
/**
|
||||
* Will be called before the actual close operation will be performed. Sub-classes may override this as the default
|
||||
* is to do nothing.
|
||||
*/
|
||||
protected void doPreClose() throws Exception {
|
||||
// NOOP by default
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the {@link Channel}
|
||||
*/
|
||||
protected abstract void doClose() throws Exception;
|
||||
protected abstract void doDeregister() throws Exception;
|
||||
|
||||
/**
|
||||
* Deregister the {@link Channel} from its {@link EventLoop}.
|
||||
*
|
||||
* Sub-classes may override this method
|
||||
*/
|
||||
protected void doDeregister() throws Exception {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the content of the given {@link ByteBuf} to the remote peer.
|
||||
*
|
||||
* Sub-classes may override this as this implementation will just thrown an {@link UnsupportedOperationException}
|
||||
*/
|
||||
protected void doFlushByteBuffer(ByteBuf buf) throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the content of the given {@link MessageBuf} to the remote peer.
|
||||
*
|
||||
* Sub-classes may override this as this implementation will just thrown an {@link UnsupportedOperationException}
|
||||
*/
|
||||
protected void doFlushMessageBuffer(MessageBuf<Object> buf) throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the content of the given {@link FileRegion} to the remote peer.
|
||||
*
|
||||
* Sub-classes may override this as this implementation will just thrown an {@link UnsupportedOperationException}
|
||||
*/
|
||||
protected void doFlushFileRegion(FileRegion region, ChannelFuture future) throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@ -898,6 +966,9 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if a flush to the {@link Channel} is currently pending.
|
||||
*/
|
||||
protected abstract boolean isFlushPending();
|
||||
|
||||
private final class CloseFuture extends DefaultChannelFuture implements ChannelFuture.Unsafe {
|
||||
|
@ -74,16 +74,6 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFlushByteBuffer(ByteBuf buf) throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFlushMessageBuffer(MessageBuf<Object> buf) throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFlushPending() {
|
||||
return false;
|
||||
|
@ -118,7 +118,20 @@ public interface Channel extends AttributeMap, ChannelOutboundInvoker, ChannelPr
|
||||
*/
|
||||
ChannelMetadata metadata();
|
||||
|
||||
/**
|
||||
* Return the last {@link ByteBuf} of the {@link ChannelPipeline} which belongs to this {@link Channel}.
|
||||
*
|
||||
* This method may throw an {@link NoSuchBufferException} if you try to access this buffer and the
|
||||
* {@link ChannelPipeline} does not contain any {@link ByteBuf}.
|
||||
*/
|
||||
ByteBuf outboundByteBuffer();
|
||||
|
||||
/**
|
||||
* Return the last {@link MessageBuf} of the {@link ChannelPipeline} which belongs to this {@link Channel}.
|
||||
*
|
||||
* This method may throw an {@link NoSuchBufferException} if you try to access this buffer and the
|
||||
* {@link ChannelPipeline} does not contain any {@link MessageBuf}.
|
||||
*/
|
||||
<T> MessageBuf<T> outboundMessageBuffer();
|
||||
|
||||
/**
|
||||
|
@ -152,6 +152,11 @@ public interface ChannelHandlerContext
|
||||
* The {@link ChannelHandler} that is bound this {@link ChannelHandlerContext}.
|
||||
*/
|
||||
ChannelHandler handler();
|
||||
|
||||
/**
|
||||
* Return an unmodifiable {@link Set} that contains all the {@link ChannelHandlerType}s which are handled by this
|
||||
* context and the {@link ChannelHandler} it belongs to.
|
||||
*/
|
||||
Set<ChannelHandlerType> types();
|
||||
|
||||
/**
|
||||
|
@ -21,10 +21,25 @@ package io.netty.channel;
|
||||
*/
|
||||
public interface ChannelStateHandler extends ChannelHandler {
|
||||
|
||||
/**
|
||||
* The {@link Channel} of the {@link ChannelHandlerContext} was registered with its {@link EventLoop}
|
||||
*/
|
||||
void channelRegistered(ChannelHandlerContext ctx) throws Exception;
|
||||
|
||||
/**
|
||||
* The {@link Channel} of the {@link ChannelHandlerContext} was unregistered from its {@link EventLoop}
|
||||
*/
|
||||
void channelUnregistered(ChannelHandlerContext ctx) throws Exception;
|
||||
|
||||
/**
|
||||
* The {@link Channel} of the {@link ChannelHandlerContext} is now active
|
||||
*/
|
||||
void channelActive(ChannelHandlerContext ctx) throws Exception;
|
||||
|
||||
/**
|
||||
* The {@link Channel} of the {@link ChannelHandlerContext} was registered is now inactive and reached its
|
||||
* end of lifetime.
|
||||
*/
|
||||
void channelInactive(ChannelHandlerContext ctx) throws Exception;
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ import java.util.concurrent.TimeoutException;
|
||||
* recommended to use {@link Channel#newSucceededFuture()} instead of
|
||||
* calling the constructor of this future.
|
||||
*/
|
||||
class SucceededChannelFuture extends CompleteChannelFuture {
|
||||
class SucceededChannelFuture extends CompleteChannelFuture {
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
|
@ -234,7 +234,7 @@ public abstract class AbstractEmbeddedChannel<O> extends AbstractChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Unsafe newUnsafe() {
|
||||
protected AbstractUnsafe newUnsafe() {
|
||||
return new DefaultUnsafe();
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ public class LocalChannel extends AbstractChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Unsafe newUnsafe() {
|
||||
protected AbstractUnsafe newUnsafe() {
|
||||
return new LocalUnsafe();
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ public class LocalServerChannel extends AbstractServerChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Unsafe newUnsafe() {
|
||||
protected AbstractUnsafe newUnsafe() {
|
||||
return new LocalServerUnsafe();
|
||||
}
|
||||
|
||||
|
@ -89,16 +89,6 @@ abstract class AbstractAioChannel extends AbstractChannel {
|
||||
return ch.isOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Runnable doRegister() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doDeregister() throws Exception {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCompatible(EventLoop loop) {
|
||||
return loop instanceof AioEventLoop;
|
||||
|
@ -15,6 +15,9 @@
|
||||
*/
|
||||
package io.netty.channel.socket.aio;
|
||||
|
||||
/**
|
||||
* Allow to fine the {@link AbstractAioChannel} for a task.
|
||||
*/
|
||||
interface AioChannelFinder {
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ import java.nio.channels.AsynchronousSocketChannel;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* {@link io.netty.channel.socket.ServerSocketChannel} implementation which uses NIO2.
|
||||
* {@link ServerSocketChannel} implementation which uses NIO2.
|
||||
*
|
||||
* NIO2 is only supported on Java 7+.
|
||||
*/
|
||||
@ -202,7 +202,7 @@ public class AioServerSocketChannel extends AbstractAioChannel implements Server
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Unsafe newUnsafe() {
|
||||
protected AbstractUnsafe newUnsafe() {
|
||||
return new AioServerSocketUnsafe();
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
|
||||
/**
|
||||
* {@link io.netty.channel.socket.SocketChannel} implementation which uses NIO2.
|
||||
* {@link SocketChannel} implementation which uses NIO2.
|
||||
*
|
||||
* NIO2 is only supported on Java 7+.
|
||||
*/
|
||||
@ -544,7 +544,7 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Unsafe newUnsafe() {
|
||||
protected AbstractUnsafe newUnsafe() {
|
||||
return new AioSocketChannelAsyncUnsafe();
|
||||
}
|
||||
|
||||
|
@ -105,17 +105,6 @@ abstract class AbstractOioChannel extends AbstractChannel {
|
||||
return loop instanceof OioEventLoop;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Runnable doRegister() throws Exception {
|
||||
// NOOP
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doDeregister() throws Exception {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFlushPending() {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user