Add javadocs and cleanup

This commit is contained in:
Norman Maurer 2012-12-23 19:24:20 +01:00
parent ae859c2de9
commit 71b089cb3b
8 changed files with 127 additions and 8 deletions

View File

@ -271,7 +271,7 @@ public interface Channel extends AttributeMap, ChannelOutboundInvoker, ChannelPr
/** /**
* Send a {@link FileRegion} to the remote peer and notify the {@link ChannelFuture} once it completes * Send a {@link FileRegion} to the remote peer and notify the {@link ChannelFuture} once it completes
* or an error was detected. Once the {@link FileRegion} was transfered or an error was thrown it will * or an error was detected. Once the {@link FileRegion} was transfered or an error was thrown it will
* automaticly closed via {@link io.netty.channel.FileRegion#close()}. * automaticly closed via {@link FileRegion#close()}.
*/ */
void sendFile(FileRegion region, ChannelFuture future); void sendFile(FileRegion region, ChannelFuture future);
} }

View File

@ -19,68 +19,131 @@ import java.net.SocketAddress;
public class ChannelOperationHandlerAdapter implements ChannelOperationHandler { public class ChannelOperationHandlerAdapter implements ChannelOperationHandler {
/**
* Do nothing by default, sub-classes may override this method.
*/
@Override @Override
public void beforeAdd(ChannelHandlerContext ctx) throws Exception { public void beforeAdd(ChannelHandlerContext ctx) throws Exception {
// NOOP // NOOP
} }
/**
* Do nothing by default, sub-classes may override this method.
*/
@Override @Override
public void afterAdd(ChannelHandlerContext ctx) throws Exception { public void afterAdd(ChannelHandlerContext ctx) throws Exception {
// NOOP // NOOP
} }
/**
* Do nothing by default, sub-classes may override this method.
*/
@Override @Override
public void beforeRemove(ChannelHandlerContext ctx) throws Exception { public void beforeRemove(ChannelHandlerContext ctx) throws Exception {
// NOOP // NOOP
} }
/**
* Do nothing by default, sub-classes may override this method.
*/
@Override @Override
public void afterRemove(ChannelHandlerContext ctx) throws Exception { public void afterRemove(ChannelHandlerContext ctx) throws Exception {
// NOOP // NOOP
} }
/**
* Calls {@link ChannelHandlerContext#fireExceptionCaught(Throwable)} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
throws Exception { throws Exception {
ctx.fireExceptionCaught(cause); ctx.fireExceptionCaught(cause);
} }
/**
* Calls {@link ChannelHandlerContext#fireUserEventTriggered(Object)} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override @Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) public void userEventTriggered(ChannelHandlerContext ctx, Object evt)
throws Exception { throws Exception {
ctx.fireUserEventTriggered(evt); ctx.fireUserEventTriggered(evt);
} }
/**
* Calls {@link ChannelHandlerContext#bind(SocketAddress, ChannelFuture)} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override @Override
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
ChannelFuture future) throws Exception { ChannelFuture future) throws Exception {
ctx.bind(localAddress, future); ctx.bind(localAddress, future);
} }
/**
* Calls {@link ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelFuture)} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override @Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,
SocketAddress localAddress, ChannelFuture future) throws Exception { SocketAddress localAddress, ChannelFuture future) throws Exception {
ctx.connect(remoteAddress, localAddress, future); ctx.connect(remoteAddress, localAddress, future);
} }
/**
* Calls {@link ChannelHandlerContext#disconnect(ChannelFuture)} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override @Override
public void disconnect(ChannelHandlerContext ctx, ChannelFuture future) public void disconnect(ChannelHandlerContext ctx, ChannelFuture future)
throws Exception { throws Exception {
ctx.disconnect(future); ctx.disconnect(future);
} }
/**
* Calls {@link ChannelHandlerContext#close(ChannelFuture)} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override @Override
public void close(ChannelHandlerContext ctx, ChannelFuture future) public void close(ChannelHandlerContext ctx, ChannelFuture future)
throws Exception { throws Exception {
ctx.close(future); ctx.close(future);
} }
/**
* Calls {@link ChannelHandlerContext#close(ChannelFuture)} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override @Override
public void deregister(ChannelHandlerContext ctx, ChannelFuture future) public void deregister(ChannelHandlerContext ctx, ChannelFuture future)
throws Exception { throws Exception {
ctx.deregister(future); ctx.deregister(future);
} }
/**
* Calls {@link ChannelHandlerContext#flush(ChannelFuture)} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*
* Be aware that if your class also implement {@link ChannelOutboundHandler} it need to {@code override} this
* method!
*/
@Override @Override
public void flush(ChannelHandlerContext ctx, ChannelFuture future) public void flush(ChannelHandlerContext ctx, ChannelFuture future)
throws Exception { throws Exception {
@ -92,6 +155,12 @@ public class ChannelOperationHandlerAdapter implements ChannelOperationHandler {
ctx.flush(future); ctx.flush(future);
} }
/**
* Calls {@link ChannelHandlerContext#sendFile(FileRegion, ChannelFuture)} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override @Override
public void sendFile(ChannelHandlerContext ctx, FileRegion region, ChannelFuture future) throws Exception { public void sendFile(ChannelHandlerContext ctx, FileRegion region, ChannelFuture future) throws Exception {
ctx.sendFile(region, future); ctx.sendFile(region, future);

View File

@ -17,7 +17,6 @@ package io.netty.channel;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/** /**
* The {@link CompleteChannelFuture} which is failed already. It is * The {@link CompleteChannelFuture} which is failed already. It is
@ -53,7 +52,7 @@ final class FailedChannelFuture extends CompleteChannelFuture {
} }
@Override @Override
public ChannelFuture sync() throws InterruptedException { public ChannelFuture sync() {
return rethrow(); return rethrow();
} }
@ -75,13 +74,12 @@ final class FailedChannelFuture extends CompleteChannelFuture {
} }
@Override @Override
public Void get() throws InterruptedException, ExecutionException { public Void get() throws ExecutionException {
throw new ExecutionException(cause); throw new ExecutionException(cause);
} }
@Override @Override
public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, public Void get(long timeout, TimeUnit unit) throws ExecutionException {
TimeoutException {
throw new ExecutionException(cause); throw new ExecutionException(cause);
} }
} }

View File

@ -40,7 +40,7 @@ public final class SctpMessage {
this.protocolIdentifier = protocolIdentifier; this.protocolIdentifier = protocolIdentifier;
this.streamIdentifier = streamIdentifier; this.streamIdentifier = streamIdentifier;
this.payloadBuffer = payloadBuffer; this.payloadBuffer = payloadBuffer;
this.msgInfo = null; msgInfo = null;
} }
public SctpMessage(MessageInfo msgInfo, ByteBuf payloadBuffer) { public SctpMessage(MessageInfo msgInfo, ByteBuf payloadBuffer) {

View File

@ -44,7 +44,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* Provides an NIO based {@link io.netty.channel.socket.DatagramChannel}. * Provides an NIO based {@link io.netty.channel.socket.DatagramChannel} which can be used
* to send and receive {@link DatagramPacket}'s.
*/ */
public final class NioDatagramChannel public final class NioDatagramChannel
extends AbstractNioMessageChannel implements io.netty.channel.socket.DatagramChannel { extends AbstractNioMessageChannel implements io.netty.channel.socket.DatagramChannel {
@ -79,18 +80,34 @@ public final class NioDatagramChannel
} }
} }
/**
* Create a new instance which will use the Operation Systems default {@link InternetProtocolFamily}.
*/
public NioDatagramChannel() { public NioDatagramChannel() {
this(newSocket()); this(newSocket());
} }
/**
* Create a new instance using the given {@link InternetProtocolFamily}. If {@code null} is used it will depend
* on the Operation Systems default which will be chosen.
*/
public NioDatagramChannel(InternetProtocolFamily ipFamily) { public NioDatagramChannel(InternetProtocolFamily ipFamily) {
this(newSocket(ipFamily)); this(newSocket(ipFamily));
} }
/**
* Create a new instance from the given {@link DatagramChannel}.
*/
public NioDatagramChannel(DatagramChannel socket) { public NioDatagramChannel(DatagramChannel socket) {
this(null, socket); this(null, socket);
} }
/**
* Create a new instance from the given {@link DatagramChannel}.
*
* @param id the id to use for this instance or {@code null} if a new one should be generated.
* @param socket the {@link DatagramChannel} which will be used
*/
public NioDatagramChannel(Integer id, DatagramChannel socket) { public NioDatagramChannel(Integer id, DatagramChannel socket) {
super(null, id, socket, SelectionKey.OP_READ); super(null, id, socket, SelectionKey.OP_READ);
config = new NioDatagramChannelConfig(socket); config = new NioDatagramChannelConfig(socket);

View File

@ -69,14 +69,29 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett
} }
} }
/**
* Create a new instance
*/
public NioSctpChannel() { public NioSctpChannel() {
this(newSctpChannel()); this(newSctpChannel());
} }
/**
* Create a new instance using {@link SctpChannel}
*/
public NioSctpChannel(SctpChannel sctpChannel) { public NioSctpChannel(SctpChannel sctpChannel) {
this(null, null, sctpChannel); this(null, null, sctpChannel);
} }
/**
* Create a new instance
*
* @param parent the {@link Channel} which is the parent of this {@link NioSctpChannel}
* or {@code null}.
* @param id the id to use for this instance or {@code null} if a new once should be
* generated
* @param sctpChannel the underlying {@link SctpChannel}
*/
public NioSctpChannel(Channel parent, Integer id, SctpChannel sctpChannel) { public NioSctpChannel(Channel parent, Integer id, SctpChannel sctpChannel) {
super(parent, id, sctpChannel, SelectionKey.OP_READ); super(parent, id, sctpChannel, SelectionKey.OP_READ);
try { try {

View File

@ -29,6 +29,10 @@ import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel; import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
/**
* A {@link io.netty.channel.socket.ServerSocketChannel} implementation which uses
* NIO selector based implementation to accept new connections.
*/
public class NioServerSocketChannel extends AbstractNioMessageChannel public class NioServerSocketChannel extends AbstractNioMessageChannel
implements io.netty.channel.socket.ServerSocketChannel { implements io.netty.channel.socket.ServerSocketChannel {

View File

@ -32,6 +32,9 @@ import java.net.SocketAddress;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
/**
* {@link io.netty.channel.socket.SocketChannel} which uses NIO selector based implementation.
*/
public class NioSocketChannel extends AbstractNioByteChannel implements io.netty.channel.socket.SocketChannel { public class NioSocketChannel extends AbstractNioByteChannel implements io.netty.channel.socket.SocketChannel {
private static final ChannelMetadata METADATA = new ChannelMetadata(BufType.BYTE, false); private static final ChannelMetadata METADATA = new ChannelMetadata(BufType.BYTE, false);
@ -48,14 +51,27 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
} }
} }
/**
* Create a new instance
*/
public NioSocketChannel() { public NioSocketChannel() {
this(newSocket()); this(newSocket());
} }
/**
* Create a new instance using the given {@link SocketChannel}.
*/
public NioSocketChannel(SocketChannel socket) { public NioSocketChannel(SocketChannel socket) {
this(null, null, socket); this(null, null, socket);
} }
/**
* Create a new instance
*
* @param parent the {@link Channel} which created this instance or {@code null} if it was created by the user
* @param id the id to use for this instance or {@code null} if a new one should be generated
* @param socket the {@link SocketChannel} which will be used
*/
public NioSocketChannel(Channel parent, Integer id, SocketChannel socket) { public NioSocketChannel(Channel parent, Integer id, SocketChannel socket) {
super(parent, id, socket); super(parent, id, socket);
try { try {