This commit is contained in:
Trustin Lee 2010-02-02 02:00:04 +00:00
parent 4a3495b1c8
commit a61d5b2e6b
41 changed files with 281 additions and 207 deletions

View File

@ -37,7 +37,7 @@ import org.jboss.netty.channel.Channels;
* {@link #setOption(String, Object) Options} are used to configure a channel:
*
* <pre>
* ClientBootstrap b = ...;
* {@link ClientBootstrap} b = ...;
*
* // Options for a new channel
* b.setOption("remoteAddress", new {@link InetSocketAddress}("example.com", 8080));
@ -57,11 +57,11 @@ import org.jboss.netty.channel.Channels;
* calling {@link #setPipelineFactory(ChannelPipelineFactory)}.
*
* <pre>
* ConnectionlessBootstrap b = ...;
* {@link ClientBootstrap} b = ...;
* b.setPipelineFactory(new MyPipelineFactory());
*
* public class MyPipelineFactory implements {@link ChannelPipelineFactory} {
* public ChannelPipeline getPipeline() throws Exception {
* public {@link ChannelPipeline} getPipeline() throws Exception {
* // Create and configure a new pipeline for a new channel.
* {@link ChannelPipeline} p = {@link Channels}.pipeline();
* p.addLast("encoder", new EncodingHandler());
@ -78,7 +78,7 @@ import org.jboss.netty.channel.Channels;
* pipeline for each new channel:
*
* <pre>
* ConnectionlessBootstrap b = ...;
* {@link ClientBootstrap} b = ...;
* {@link ChannelPipeline} p = b.getPipeline();
*
* // Add handlers to the default pipeline.
@ -135,7 +135,7 @@ public class ClientBootstrap extends Bootstrap {
* This method is similar to the following code:
*
* <pre>
* ClientBootstrap b = ...;
* {@link ClientBootstrap} b = ...;
* b.connect(b.getOption("remoteAddress"), b.getOption("localAddress"));
* </pre>
*
@ -166,7 +166,7 @@ public class ClientBootstrap extends Bootstrap {
* automatically. This method is identical with the following code:
*
* <pre>
* ClientBootstrap b = ...;
* {@link ClientBootstrap} b = ...;
* b.connect(remoteAddress, b.getOption("localAddress"));
* </pre>
*

View File

@ -46,7 +46,7 @@ import org.jboss.netty.channel.Channels;
* {@link #setOption(String, Object) Options} are used to configure a channel:
*
* <pre>
* ConnectionlessBootstrap b = ...;
* {@link ConnectionlessBootstrap} b = ...;
*
* // Options for a new channel
* b.setOption("localAddress", new {@link InetSocketAddress}(8080));
@ -66,11 +66,11 @@ import org.jboss.netty.channel.Channels;
* calling {@link #setPipelineFactory(ChannelPipelineFactory)}.
*
* <pre>
* ConnectionlessBootstrap b = ...;
* {@link ConnectionlessBootstrap} b = ...;
* b.setPipelineFactory(new MyPipelineFactory());
*
* public class MyPipelineFactory implements {@link ChannelPipelineFactory} {
* public ChannelPipeline getPipeline() throws Exception {
* public {@link ChannelPipeline} getPipeline() throws Exception {
* // Create and configure a new pipeline for a new channel.
* {@link ChannelPipeline} p = {@link Channels}.pipeline();
* p.addLast("encoder", new EncodingHandler());
@ -87,7 +87,7 @@ import org.jboss.netty.channel.Channels;
* pipeline for each new channel:
*
* <pre>
* ConnectionlessBootstrap b = ...;
* {@link ConnectionlessBootstrap} b = ...;
* {@link ChannelPipeline} p = b.getPipeline();
*
* // Add handlers to the default pipeline.
@ -143,7 +143,7 @@ public class ConnectionlessBootstrap extends Bootstrap {
* similar to the following code:
*
* <pre>
* ServerBootstrap b = ...;
* {@link ConnectionlessBootstrap} b = ...;
* b.connect(b.getOption("localAddress"));
* </pre>
*
@ -213,7 +213,7 @@ public class ConnectionlessBootstrap extends Bootstrap {
* automatically. This method is similar to the following code:
*
* <pre>
* ConnectionlessBootstrap b = ...;
* {@link ConnectionlessBootstrap} b = ...;
* b.connect(b.getOption("remoteAddress"), b.getOption("localAddress"));
* </pre>
*
@ -245,7 +245,7 @@ public class ConnectionlessBootstrap extends Bootstrap {
* with the following code:
*
* <pre>
* ClientBootstrap b = ...;
* {@link ConnectionlessBootstrap} b = ...;
* b.connect(remoteAddress, b.getOption("localAddress"));
* </pre>
*

View File

@ -73,7 +73,7 @@ import org.jboss.netty.channel.StaticChannelPipeline;
* channel:
*
* <pre>
* ServerBootstrap b = ...;
* {@link ServerBootstrap} b = ...;
*
* // Options for a parent channel
* b.setOption("localAddress", new {@link InetSocketAddress}(8080));
@ -108,11 +108,11 @@ import org.jboss.netty.channel.StaticChannelPipeline;
* calling {@link #setPipelineFactory(ChannelPipelineFactory)}.
*
* <pre>
* ConnectionlessBootstrap b = ...;
* {@link ServerBootstrap} b = ...;
* b.setPipelineFactory(new MyPipelineFactory());
*
* public class MyPipelineFactory implements {@link ChannelPipelineFactory} {
* public ChannelPipeline getPipeline() throws Exception {
* public {@link ChannelPipeline} getPipeline() throws Exception {
* // Create and configure a new pipeline for a new channel.
* {@link ChannelPipeline} p = {@link Channels}.pipeline();
* p.addLast("encoder", new EncodingHandler());
@ -129,7 +129,7 @@ import org.jboss.netty.channel.StaticChannelPipeline;
* pipeline for each new channel:
*
* <pre>
* ConnectionlessBootstrap b = ...;
* {@link ServerBootstrap} b = ...;
* {@link ChannelPipeline} p = b.getPipeline();
*
* // Add handlers to the default pipeline.
@ -231,7 +231,7 @@ public class ServerBootstrap extends Bootstrap {
* similar to the following code:
*
* <pre>
* ServerBootstrap b = ...;
* {@link ServerBootstrap} b = ...;
* b.connect(b.getOption("localAddress"));
* </pre>
*

View File

@ -46,7 +46,7 @@ import java.nio.charset.UnsupportedCharsetException;
* its internal implementation:
*
* <pre>
* ChannelBuffer buffer = ...;
* {@link ChannelBuffer} buffer = ...;
* for (int i = 0; i &lt; buffer.capacity(); i ++</strong>) {
* byte b = array.getByte(i);
* System.out.println((char) b);
@ -85,7 +85,7 @@ import java.nio.charset.UnsupportedCharsetException;
*
* <pre>
* // Iterates the readable bytes of a buffer.
* ChannelBuffer buffer = ...;
* {@link ChannelBuffer} buffer = ...;
* while (buffer.readable()) {
* System.out.println(buffer.readByte());
* }
@ -108,7 +108,7 @@ import java.nio.charset.UnsupportedCharsetException;
*
* <pre>
* // Fills the writable bytes of a buffer with random integers.
* ChannelBuffer buffer = ...;
* {@link ChannelBuffer} buffer = ...;
* while (buffer.writableBytes() >= 4) {
* buffer.writeInt(random.nextInt());
* }
@ -296,7 +296,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* <pre>
* // Create a buffer whose readerIndex, writerIndex and capacity are
* // 0, 0 and 8 respectively.
* ChannelBuffer buf = ChannelBuffers.buffer(8);
* {@link ChannelBuffer} buf = {@link ChannelBuffers}.buffer(8);
*
* // IndexOutOfBoundsException is thrown because the specified
* // readerIndex (2) cannot be greater than the current writerIndex (0).
@ -309,7 +309,7 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* <pre>
* // Create a buffer whose readerIndex, writerIndex and capacity are
* // 0, 8 and 8 respectively.
* ChannelBuffer buf = ChannelBuffers.wrappedBuffer(new byte[8]);
* {@link ChannelBuffer} buf = {@link ChannelBuffers}.wrappedBuffer(new byte[8]);
*
* // readerIndex becomes 8.
* buf.readLong();

View File

@ -37,13 +37,13 @@ import org.jboss.netty.util.CharsetUtil;
* This classes is intended to be used with Java 5 static import statement:
*
* <pre>
* import static org.jboss.netty.buffer.ChannelBuffers.*;
* import static org.jboss.netty.buffer.{@link ChannelBuffers}.*;
*
* ChannelBuffer heapBuffer = buffer(128);
* ChannelBuffer directBuffer = directBuffer(256);
* ChannelBuffer dynamicBuffer = dynamicBuffer(512);
* ChannelBuffer wrappedBuffer = wrappedBuffer(new byte[128], new byte[256]);
* ChannelBuffer copiedBuffer = copiedBuffer(ByteBuffer.allocate(128));
* {@link ChannelBuffer} heapBuffer = buffer(128);
* {@link ChannelBuffer} directBuffer = directBuffer(256);
* {@link ChannelBuffer} dynamicBuffer = dynamicBuffer(512);
* {@link ChannelBuffer} wrappedBuffer = wrappedBuffer(new byte[128], new byte[256]);
* {@link ChannelBuffer} copiedBuffe r = copiedBuffer({@link ByteBuffer}.allocate(128));
* </pre>
*
* <h3>Allocating a new buffer</h3>

View File

@ -31,8 +31,8 @@ import org.jboss.netty.channel.socket.nio.NioSocketChannelConfig;
* {@link SocketChannelConfig} or use {@link #setOptions(Map)} to set the
* transport-specific properties:
* <pre>
* Channel ch = ...;
* SocketChannelConfig cfg = <strong>(SocketChannelConfig) ch.getConfig();</strong>
* {@link Channel} ch = ...;
* {@link SocketChannelConfig} cfg = <strong>({@link SocketChannelConfig}) ch.getConfig();</strong>
* cfg.setTcpNoDelay(false);
* </pre>
*

View File

@ -47,7 +47,7 @@ package org.jboss.netty.channel;
* // Sending the event upstream (inbound)
* void handleDownstream({@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {
* ...
* ctx.sendUpstream(new DefaultChannelStateEvent(...));
* ctx.sendUpstream(new {@link UpstreamChannelStateEvent}(...));
* ...
* }
* </pre>

View File

@ -64,9 +64,10 @@ import org.jboss.netty.handler.execution.ExecutionHandler;
* operation it is waiting for, which is a dead lock.
* <pre>
* // BAD - NEVER DO THIS
* public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* {@code @Override}
* public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* if (e.getMessage() instanceof GoodByeMessage) {
* ChannelFuture future = e.getChannel().close();
* {@link ChannelFuture} future = e.getChannel().close();
* future.awaitUninterruptibly();
* // Perform post-closure operation
* // ...
@ -74,11 +75,12 @@ import org.jboss.netty.handler.execution.ExecutionHandler;
* }
*
* // GOOD
* public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* {@code @Override}
* public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* if (e.getMessage() instanceof GoodByeMessage) {
* ChannelFuture future = e.getChannel().close();
* future.addListener(new ChannelFutureListener() {
* public void operationComplete(ChannelFuture future) {
* {@link ChannelFuture} future = e.getChannel().close();
* future.addListener(new {@link ChannelFutureListener}() {
* public void operationComplete({@link ChannelFuture} future) {
* // Perform post-closure operation
* // ...
* }

View File

@ -23,6 +23,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.jboss.netty.bootstrap.Bootstrap;
import org.jboss.netty.channel.group.ChannelGroup;
/**
* Handles or intercepts a {@link ChannelEvent}, and sends a
@ -57,12 +58,13 @@ import org.jboss.netty.bootstrap.Bootstrap;
* A {@link ChannelHandler} often needs to store some stateful information.
* The simplest and recommended approach is to use member variables:
* <pre>
* public class DataServerHandler extends SimpleChannelHandler {
* public class DataServerHandler extends {@link SimpleChannelHandler} {
*
* <b>private boolean loggedIn;</b>
*
* public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* Channel ch = e.getChannel();
* {@code @Override}
* public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* {@link Channel} ch = e.getChannel();
* Object o = e.getMessage();
* if (o instanceof LoginMessage) {
* authenticate((LoginMessage) o);
@ -85,9 +87,9 @@ import org.jboss.netty.bootstrap.Bootstrap;
* <pre>
* // Create a new handler instance per channel.
* // See {@link Bootstrap#setPipelineFactory(ChannelPipelineFactory)}.
* public class DataServerPipelineFactory implements ChannelPipelineFactory {
* public ChannelPipeline getPipeline() {
* return Channels.pipeline(<b>new DataServerHandler()</b>);
* public class DataServerPipelineFactory implements {@link ChannelPipelineFactory} {
* public {@link ChannelPipeline} getPipeline() {
* return {@link Channels}.pipeline(<b>new DataServerHandler()</b>);
* }
* }
* </pre>
@ -99,11 +101,12 @@ import org.jboss.netty.bootstrap.Bootstrap;
* In such a case, you can use an <em>attachment</em> which is provided by
* {@link ChannelHandlerContext}:
* <pre>
* {@literal @Sharable}
* public class DataServerHandler extends SimpleChannelHandler {
* {@code @Sharable}
* public class DataServerHandler extends {@link SimpleChannelHandler} {
*
* public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* Channel ch = e.getChannel();
* {@code @Override}
* public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* {@link Channel} ch = e.getChannel();
* Object o = e.getMessage();
* if (o instanceof LoginMessage) {
* authenticate((LoginMessage) o);
@ -122,10 +125,12 @@ import org.jboss.netty.bootstrap.Bootstrap;
* Now that the state of the handler is stored as an attachment, you can add the
* same handler instance to different pipelines:
* <pre>
* public class DataServerPipelineFactory implements ChannelPipelineFactory {
* private static final StatefulHandler SINGLETON = new DataServerHandler();
* public ChannelPipeline getPipeline() {
* return Channels.pipeline(<b>SINGLETON</b>);
* public class DataServerPipelineFactory implements {@link ChannelPipelineFactory} {
*
* private static final DataServerHandler <b>SHARED</b> = new DataServerHandler();
*
* public {@link ChannelPipeline} getPipeline() {
* return {@link Channels}.pipeline(<b>SHARED</b>);
* }
* }
* </pre>
@ -137,7 +142,7 @@ import org.jboss.netty.bootstrap.Bootstrap;
* <pre>
* public final class DataServerState {
*
* <b>public static final ChannelLocal&lt;Boolean&gt; loggedIn = new ChannelLocal&lt;Boolean&gt;() {
* <b>public static final {@link ChannelLocal}&lt;Boolean&gt; loggedIn = new {@link ChannelLocal}&lt;Boolean&gt;() {
* protected Boolean initialValue(Channel channel) {
* return false;
* }
@ -145,9 +150,11 @@ import org.jboss.netty.bootstrap.Bootstrap;
* ...
* }
*
* {@literal @Sharable}
* public class DataServerHandler extends SimpleChannelHandler {
* public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* {@code @Sharable}
* public class DataServerHandler extends {@link SimpleChannelHandler} {
*
* {@code @Override}
* public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* Channel ch = e.getChannel();
* Object o = e.getMessage();
* if (o instanceof LoginMessage) {
@ -165,24 +172,25 @@ import org.jboss.netty.bootstrap.Bootstrap;
* }
*
* // Print the remote addresses of the authenticated clients:
* for (Channel ch: allClientChannels) {
* {@link ChannelGroup} allClientChannels = ...;
* for ({@link Channel} ch: allClientChannels) {
* if (<b>DataServerState.loggedIn.get(ch)</b>) {
* System.out.println(ch.getRemoteAddress());
* }
* }
* </pre>
*
* <h4>The {@literal @Sharable} annotation</h4>
* <h4>The {@code @Sharable} annotation</h4>
* <p>
* In the examples above which used an attachment or a {@link ChannelLocal},
* you might have noticed the {@literal @Sharable} annotation.
* you might have noticed the {@code @Sharable} annotation.
* <p>
* If a {@link ChannelHandler} is annotated with the {@literal @Sharable}
* If a {@link ChannelHandler} is annotated with the {@code @Sharable}
* annotation, it means you can create an instance of the handler just once and
* add it to one or more {@link ChannelPipeline}s multiple times without
* a race condition.
* <p>
* If this annotation is not specified, it is safe to create a new handler
* If this annotation is not specified, you have to create a new handler
* instance every time you add it to a pipeline because it has unshared state
* such as member variables.
* <p>
@ -210,7 +218,7 @@ public interface ChannelHandler {
* can be added to one or more {@link ChannelPipeline}s multiple times
* without a race condition.
* <p>
* If this annotation is not specified, it is safe to create a new handler
* If this annotation is not specified, you have to create a new handler
* instance every time you add it to a pipeline because it has unshared
* state such as member variables.
* <p>

View File

@ -45,11 +45,12 @@ package org.jboss.netty.channel;
* as how many times it is added to pipelines, regardless if it is added to the
* same pipeline multiple times or added to different pipelines multiple times:
* <pre>
* public class FactorialHandler extends SimpleUpstreamChannelHandler {
* public class FactorialHandler extends {@link SimpleChannelHandler} {
*
* // This handler will receive a sequence of increasing integers starting
* // from 1.
* public void messageReceived(ChannelHandlerContext ctx, MessageEvent evt) {
* {@code @Override}
* public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} evt) {
* Integer a = (Integer) ctx.getAttachment();
* Integer b = (Integer) evt.getMessage();
*
@ -67,11 +68,11 @@ package org.jboss.netty.channel;
* // calculated correctly 4 times once the two pipelines (p1 and p2) are active.
* FactorialHandler fh = new FactorialHandler();
*
* ChannelPipeline p1 = Channels.pipeline();
* {@link ChannelPipeline} p1 = {@link Channels}.pipeline();
* p1.addLast("f1", fh);
* p1.addLast("f2", fh);
*
* ChannelPipeline p2 = Channels.pipeline();
* {@link ChannelPipeline} p2 = {@link Channels}.pipeline();
* p2.addLast("f3", fh);
* p2.addLast("f4", fh);
* </pre>
@ -81,16 +82,17 @@ package org.jboss.netty.channel;
* You can keep the {@link ChannelHandlerContext} for later use, such as
* triggering an event outside the handler methods, even from a different thread.
* <pre>
* public class MyHandler extends SimpleChannelHandler
* implements LifeCycleAwareChannelHandler {
* public class MyHandler extends {@link SimpleChannelHandler}
* implements {@link LifeCycleAwareChannelHandler} {
*
* private ChannelHandlerContex ctx;
* private {@link ChannelHandlerContext} ctx;
*
* public void beforeAdd(ChannelHandlerContext ctx) {
* public void beforeAdd({@link ChannelHandlerContext} ctx) {
* this.ctx = ctx;
* }
*
* public void messageReceived(ChannelHandlerContext ctx, MessageEvent evt) {
* {@code @Override}
* public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} evt) {
* ctx.setAttachment(evt.getMessage());
* }
*

View File

@ -40,8 +40,8 @@ import org.jboss.netty.handler.ssl.SslHandler;
* {@link Channels} rather than calling an individual implementation's
* constructor:
* <pre>
* import static org.jboss.netty.channel.Channels.*;
* ChannelPipeline pipeline = pipeline(); // same with Channels.pipeline()
* import static org.jboss.netty.channel.{@link Channels}.*;
* {@link ChannelPipeline} pipeline = pipeline(); // same with Channels.pipeline()
* </pre>
*
* <h3>How an event flows in a pipeline</h3>
@ -112,7 +112,7 @@ import org.jboss.netty.handler.ssl.SslHandler;
* <p>
* For example, let us assume that we created the following pipeline:
* <pre>
* ChannelPipeline p = Channels.pipeline();
* {@link ChannelPipeline} p = {@link Channels}.pipeline();
* p.addLast("1", new UpstreamHandlerA());
* p.addLast("2", new UpstreamHandlerB());
* p.addLast("3", new DownstreamHandlerA());
@ -159,7 +159,7 @@ import org.jboss.netty.handler.ssl.SslHandler;
* and it could be represented as shown in the following example:
*
* <pre>
* ChannelPipeline pipeline = {@link Channels#pipeline() Channels.pipeline()};
* {@link ChannelPipeline} pipeline = {@link Channels#pipeline() Channels.pipeline()};
* pipeline.addLast("decoder", new MyProtocolDecoder());
* pipeline.addLast("encoder", new MyProtocolEncoder());
* pipeline.addLast("executor", new {@link ExecutionHandler}(new {@link OrderedMemoryAwareThreadPoolExecutor}(16, 1048576, 1048576)));
@ -179,8 +179,10 @@ import org.jboss.netty.handler.ssl.SslHandler;
* {@link ChannelPipeline}, the following code does not work as expected if
* <tt>FirstHandler</tt> is the last handler in the pipeline:
* <pre>
* public class FirstHandler extends SimpleChannelUpstreamHandler {
* public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* public class FirstHandler extends {@link SimpleChannelUpstreamHandler} {
*
* {@code @Override}
* public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* // Remove this handler from the pipeline,
* ctx.getPipeline().remove(this);
* // And let SecondHandler handle the current event.

View File

@ -31,8 +31,6 @@ import org.jboss.netty.channel.ChannelHandler.Sharable;
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
*
* @version $Rev$, $Date$
*
* @apiviz.landmark
*/
@Inherited
@Documented

View File

@ -53,7 +53,7 @@ import org.jboss.netty.handler.execution.ExecutionHandler;
* // Sending the event downstream (outbound)
* void handleDownstream({@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {
* ...
* ctx.sendDownstream(new MessageEvent(...));
* ctx.sendDownstream(new {@link DownstreamMessageEvent}(...));
* ...
* }
* </pre>

View File

@ -36,12 +36,13 @@ import java.net.SocketAddress;
* call {@code super.handleDownstream()} so that other handler methods are
* invoked properly:
* </p>
* <pre>public class MyChannelHandler extends SimpleChannelDownstreamHandler {
* <pre>public class MyChannelHandler extends {@link SimpleChannelDownstreamHandler} {
*
* {@code @Override}
* public void handleDownstream({@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {
*
* // Log all channel state changes.
* if (e instanceof MessageEvent) {
* if (e instanceof {@link MessageEvent}) {
* logger.info("Writing:: " + e);
* }
*

View File

@ -46,22 +46,24 @@ import org.jboss.netty.logging.InternalLoggerFactory;
* call {@code super.handleUpstream()} or {@code super.handleDownstream()} so
* that other handler methods are invoked properly:
* </p>
* <pre>public class MyChannelHandler extends SimpleChannelHandler {
* <pre>public class MyChannelHandler extends {@link SimpleChannelHandler} {
*
* {@code @Override}
* public void handleUpstream({@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {
*
* // Log all channel state changes.
* if (e instanceof ChannelStateEvent) {
* if (e instanceof {@link ChannelStateEvent}) {
* logger.info("Channel state changed: " + e);
* }
*
* <strong>super.handleUpstream(ctx, e);</strong>
* }
*
* {@code @Override}
* public void handleDownstream({@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {
*
* // Log all channel state changes.
* if (e instanceof MessageEvent) {
* if (e instanceof {@link MessageEvent}) {
* logger.info("Writing:: " + e);
* }
*

View File

@ -37,12 +37,13 @@ import org.jboss.netty.logging.InternalLoggerFactory;
* call {@code super.handleUpstream()} so that other handler methods are invoked
* properly:
* </p>
* <pre>public class MyChannelHandler extends SimpleChannelUpstreamHandler {
* <pre>public class MyChannelHandler extends {@link SimpleChannelUpstreamHandler} {
*
* {@code @Override}
* public void handleUpstream({@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {
*
* // Log all channel state changes.
* if (e instanceof ChannelStateEvent) {
* if (e instanceof {@link ChannelStateEvent}) {
* logger.info("Channel state changed: " + e);
* }
*

View File

@ -18,9 +18,15 @@ package org.jboss.netty.channel.group;
import java.net.SocketAddress;
import java.util.Set;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ServerChannel;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.jboss.netty.util.CharsetUtil;
/**
* A thread-safe {@link Set} that contains open {@link Channel}s and provides
@ -36,13 +42,13 @@ import org.jboss.netty.channel.ServerChannel;
* If you need to broadcast a message to more than one {@link Channel}, you can
* add the {@link Channel}s associated with the recipients and call {@link ChannelGroup#write(Object)}:
* <pre>
* <strong>ChannelGroup recipients = new DefaultChannelGroup();</strong>
* <strong>{@link ChannelGroup} recipients = new {@link DefaultChannelGroup}();</strong>
* recipients.add(channelA);
* recipients.add(channelB);
* ..
* <strong>recipients.write(ChannelBuffers.copiedBuffer(
* <strong>recipients.write({@link ChannelBuffers}.copiedBuffer(
* "Service will shut down for maintenance in 5 minutes.",
* CharsetUtil.UTF_8));</strong>
* {@link CharsetUtil}.UTF_8));</strong>
* </pre>
*
* <h3>Simplify shutdown process with {@link ChannelGroup}</h3>
@ -54,15 +60,15 @@ import org.jboss.netty.channel.ServerChannel;
* This rule is very useful when you shut down a server in one shot:
*
* <pre>
* <strong>ChannelGroup allChannels = new DefaultChannelGroup();</strong>
* <strong>{@link ChannelGroup} allChannels = new {@link DefaultChannelGroup}();</strong>
*
* public static void main(String[] args) throws Exception {
* ServerBootstrap b = new ServerBootstrap(..);
* {@link ServerBootstrap} b = new {@link ServerBootstrap}(..);
* ...
*
* // Start the server
* b.getPipeline().addLast("handler", new MyHandler());
* Channel serverChannel = b.bind(..);
* {@link Channel} serverChannel = b.bind(..);
* <strong>allChannels.add(serverChannel);</strong>
*
* ... Wait until the shutdown signal reception ...
@ -72,8 +78,9 @@ import org.jboss.netty.channel.ServerChannel;
* b.releaseExternalResources();
* }
*
* public class MyHandler extends SimpleChannelUpstreamHandler {
* public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) {
* public class MyHandler extends {@link SimpleChannelUpstreamHandler} {
* {@code @Override}
* public void channelOpen({@link ChannelHandlerContext} ctx, {@link ChannelStateEvent} e) {
* // Add all open channels to the global group so that they are
* // closed on shutdown.
* <strong>allChannels.add(e.getChannel());</strong>

View File

@ -21,7 +21,9 @@ import java.util.concurrent.TimeUnit;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.execution.ExecutionHandler;
/**
@ -74,10 +76,11 @@ import org.jboss.netty.handler.execution.ExecutionHandler;
* operation it is waiting for, which is a dead lock.
* <pre>
* // BAD - NEVER DO THIS
* public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* {@code @Override}
* public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* if (e.getMessage() instanceof ShutdownMessage) {
* ChannelGroup allChannels = MyServer.getAllChannels();
* ChannelGroupFuture future = allChannels.close();
* {@link ChannelGroup} allChannels = MyServer.getAllChannels();
* {@link ChannelGroupFuture} future = allChannels.close();
* future.awaitUninterruptibly();
* // Perform post-shutdown operation
* // ...
@ -85,12 +88,13 @@ import org.jboss.netty.handler.execution.ExecutionHandler;
* }
*
* // GOOD
* {@code @Override}
* public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* if (e.getMessage() instanceof ShutdownMessage) {
* ChannelGroup allChannels = MyServer.getAllChannels();
* ChannelGroupFuture future = allChannels.close();
* future.addListener(new ChannelGroupFutureListener() {
* public void operationComplete(ChannelGroupFuture future) {
* {@link ChannelGroup} allChannels = MyServer.getAllChannels();
* {@link ChannelGroupFuture} future = allChannels.close();
* future.addListener(new {@link ChannelGroupFutureListener}() {
* public void operationComplete({@link ChannelGroupFuture} future) {
* // Perform post-closure operation
* // ...
* }

View File

@ -19,6 +19,7 @@ import static org.jboss.netty.channel.Channels.*;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBufferFactory;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelUpstreamHandler;
import org.jboss.netty.handler.codec.base64.Base64Decoder;
@ -31,10 +32,10 @@ import org.jboss.netty.handler.codec.string.StringDecoder;
* {@link StringDecoder} without setting up the {@link ChannelPipeline} and
* other mock objects by yourself:
* <pre>
* ChannelBuffer base64Data = ChannelBuffer.copiedBuffer("Zm9vYmFy", CharsetUtil.US_ASCII);
* {@link ChannelBuffer} base64Data = {@link ChannelBuffers}.copiedBuffer("Zm9vYmFy", CharsetUtil.US_ASCII);
*
* DecoderEmbedder&lt;String&gt; embedder = new DecoderEmbedder&lt;String&gt;(
* new Base64Decoder(), new StringDecoder());
* {@link DecoderEmbedder}&lt;String&gt; embedder = new {@link DecoderEmbedder}&lt;String&gt;(
* new {@link Base64Decoder}(), new {@link StringDecoder}());
*
* embedded.offer(base64Data);
*

View File

@ -23,6 +23,7 @@ import org.jboss.netty.channel.ChannelDownstreamHandler;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.handler.codec.base64.Base64Encoder;
import org.jboss.netty.handler.codec.string.StringEncoder;
import org.jboss.netty.util.CharsetUtil;
/**
* A helper that wraps an encoder so that it can be used without doing actual
@ -33,13 +34,13 @@ import org.jboss.netty.handler.codec.string.StringEncoder;
* <pre>
* String data = "foobar";
*
* EncoderEmbedder&lt;ChannelBuffer&gt; embedder = new EncoderEmbedder&lt;ChannelBuffer&gt;(
* new Base64Encoder(), new StringEncoder());
* {@link EncoderEmbedder}&lt;{@link ChannelBuffer}&gt; embedder = new {@link EncoderEmbedder}&lt;{@link ChannelBuffer}&gt;(
* new {@link Base64Encoder}(), new {@link StringEncoder}());
*
* embedded.offer(data);
*
* ChannelBuffer encoded = embedded.poll();
* assert encoded.toString(CharsetUtil.US_ASCII).equals("Zm9vYmFy");
* {@link ChannelBuffer} encoded = embedded.poll();
* assert encoded.toString({@link CharsetUtil}.US_ASCII).equals("Zm9vYmFy");
* </pre>
*
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>

View File

@ -75,11 +75,12 @@ import org.jboss.netty.handler.codec.replay.ReplayingDecoder;
* DECODER IMPLEMENTATION
* ======================
*
* public class IntegerHeaderFrameDecoder extends FrameDecoder {
* public class IntegerHeaderFrameDecoder extends {@link FrameDecoder} {
*
* protected Object decode(ChannelHandlerContext ctx,
* Channel channel,
* ChannelBuffer buf) throws Exception {
* {@code @Override}
* protected Object decode({@link ChannelHandlerContext} ctx,
* {@link Channel channel},
* {@link ChannelBuffer} buf) throws Exception {
*
* // Make sure if the length field was received.
* if (buf.readableBytes() &lt; 4) {
@ -114,7 +115,7 @@ import org.jboss.netty.handler.codec.replay.ReplayingDecoder;
* }
*
* // There's enough bytes in the buffer. Read it.
* ChannelBuffer frame = buf.readBytes(length);
* {@link ChannelBuffer} frame = buf.readBytes(length);
*
* // Successfully decoded a frame. Return the decoded frame.
* return <strong>frame</strong>;
@ -140,13 +141,16 @@ import org.jboss.netty.handler.codec.replay.ReplayingDecoder;
* {@link ChannelPipeline#replace(ChannelHandler, String, ChannelHandler)}, but
* some additional steps are required:
* <pre>
* public class FirstDecoder extends FrameDecoder {
* public class FirstDecoder extends {@link FrameDecoder} {
*
* public FirstDecoder() {
* super(true); // Enable unfold
* }
*
* protected Object decode(ChannelHandlerContext ctx, Channel ch, ChannelBuffer buf) {
* {@code @Override}
* protected Object decode({@link ChannelHandlerContext} ctx,
* {@link Channel} channel,
* {@link ChannelBuffer} buf) {
* ...
* // Decode the first message
* Object firstMessage = ...;

View File

@ -29,9 +29,9 @@ import java.util.regex.Pattern;
* the HTTP cookie version 0, 1, and 2.
*
* <pre>
* HttpRequest req = ...;
* {@link HttpRequest} req = ...;
* String value = req.getHeader("Cookie");
* Set&lt;Cookie&gt; cookies = new CookieDecoder().decode(value);
* Set&lt;{@link Cookie}&gt; cookies = new {@link CookieDecoder}().decode(value);
* </pre>
*
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>

View File

@ -30,14 +30,14 @@ import java.util.TreeSet;
* data structure are removed so that the encoder can start over.
* <pre>
* // Client-side example
* HttpRequest req = ...;
* CookieEncoder encoder = new CookieEncoder(false);
* {@link HttpRequest} req = ...;
* {@link CookieEncoder} encoder = new {@link CookieEncoder}(false);
* encoder.addCookie("JSESSIONID", "1234");
* res.setHeader("Cookie", encoder.encode());
*
* // Server-side example
* HttpResponse res = ...;
* CookieEncoder encoder = new CookieEncoder(true);
* {@link HttpResponse} res = ...;
* {@link CookieEncoder} encoder = new {@link CookieEncoder}(true);
* encoder.addCookie("JSESSIONID", "1234");
* res.setHeader("Set-Cookie", encoder.encode());
* </pre>

View File

@ -34,12 +34,12 @@ import org.jboss.netty.handler.codec.frame.TooLongFrameException;
* care of HTTP messages whose transfer encoding is 'chunked'. Insert this
* handler after {@link HttpMessageDecoder} in the {@link ChannelPipeline}:
* <pre>
* ChannelPipeline p = ...;
* {@link ChannelPipeline} p = ...;
* ...
* p.addLast("decoder", new HttpRequestDecoder());
* p.addLast("aggregator", <b>new HttpChunkAggregator(1048576)</b>);
* p.addLast("decoder", new {@link HttpRequestDecoder}());
* p.addLast("aggregator", <b>new {@link HttpChunkAggregator}(1048576)</b>);
* ...
* p.addLast("encoder", new HttpResponseEncoder());
* p.addLast("encoder", new {@link HttpResponseEncoder}());
* p.addLast("handler", new HttpRequestHandler());
* </pre>
*

View File

@ -31,7 +31,7 @@ import java.util.regex.Pattern;
* Splits an HTTP query string into a path string and key-value parameter pairs.
* This decoder is for one time use only. Create a new instance for each URI:
* <pre>
* QueryStringDecoder decoder = new QueryStringDecoder("/hello?recipient=world");
* {@link QueryStringDecoder} decoder = new {@link QueryStringDecoder}("/hello?recipient=world");
* assert decoder.getPath().equals("/hello");
* assert decoder.getParameters().get("recipient").equals("world");
* </pre>

View File

@ -29,7 +29,7 @@ import java.util.List;
* This encoder is for one time use only. Create a new instance for each URI.
*
* <pre>
* QueryStringEncoder encoder = new QueryStringDecoder("/hello");
* {@link QueryStringEncoder} encoder = new {@link QueryStringDecoder}("/hello");
* encoder.addParam("recipient", "world");
* assert encoder.toString().equals("/hello?recipient=world");
* </pre>

View File

@ -20,6 +20,7 @@ import org.jboss.netty.buffer.ChannelBufferInputStream;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.ChannelHandler.Sharable;
import org.jboss.netty.handler.codec.frame.FrameDecoder;
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
@ -52,7 +53,7 @@ import com.google.protobuf.Message;
* and then you can use a {@code MyMessage} instead of a {@link ChannelBuffer}
* as a message:
* <pre>
* void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* MyMessage req = (MyMessage) e.getMessage();
* MyMessage res = MyMessage.newBuilder().setText(
* "Did you say '" + req.getText() + "'?").build();

View File

@ -21,6 +21,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.ChannelHandler.Sharable;
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
import org.jboss.netty.handler.codec.frame.LengthFieldPrepender;
@ -48,7 +49,7 @@ import com.google.protobuf.Message;
* and then you can use a {@code MyMessage} instead of a {@link ChannelBuffer}
* as a message:
* <pre>
* void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* MyMessage req = (MyMessage) e.getMessage();
* MyMessage res = MyMessage.newBuilder().setText(
* "Did you say '" + req.getText() + "'?").build();

View File

@ -42,11 +42,12 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
* availability of the required bytes. For example, the following
* {@link FrameDecoder} implementation:
* <pre>
* public class IntegerHeaderFrameDecoder extends FrameDecoder {
* public class IntegerHeaderFrameDecoder extends {@link FrameDecoder} {
*
* protected Object decode(ChannelHandlerContext ctx,
* Channel channel,
* ChannelBuffer buf) throws Exception {
* {@code @Override}
* protected Object decode({@link ChannelHandlerContext} ctx,
* {@link Channel} channel,
* {@link ChannelBuffer} buf) throws Exception {
*
* if (buf.readableBytes() &lt; 4) {
* return <strong>null</strong>;
@ -67,12 +68,12 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
* is simplified like the following with {@link ReplayingDecoder}:
* <pre>
* public class IntegerHeaderFrameDecoder
* extends ReplayingDecoder&lt;VoidEnum&gt; {
* extends {@link ReplayingDecoder}&lt;{@link VoidEnum}&gt; {
*
* protected Object decode(ChannelHandlerContext ctx,
* Channel channel,
* ChannelBuffer buf,
* VoidEnum state) throws Exception {
* protected Object decode({@link ChannelHandlerContext} ctx,
* {@link Channel} channel,
* {@link ChannelBuffer} buf,
* {@link VoidEnum} state) throws Exception {
*
* return buf.readBytes(buf.readInt());
* }
@ -112,11 +113,12 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
* <li>You must keep in mind that {@code decode(..)} method can be called many
* times to decode a single message. For example, the following code will
* not work:
* <pre> public class MyDecoder extends ReplayingDecoder&lt;VoidEnum&gt; {
* <pre> public class MyDecoder extends {@link ReplayingDecoder}&lt;{@link VoidEnum}&gt; {
*
* private final Queue&lt;Integer&gt; values = new LinkedList&lt;Integer&gt;();
*
* public Object decode(.., ChannelBuffer buffer, ..) throws Exception {
* {@code @Override}
* public Object decode(.., {@link ChannelBuffer} buffer, ..) throws Exception {
*
* // A message contains 2 integers.
* values.offer(buffer.readInt());
@ -131,11 +133,12 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
* The correct implementation looks like the following, and you can also
* utilize the 'checkpoint' feature which is explained in detail in the
* next section.
* <pre> public class MyDecoder extends ReplayingDecoder&lt;VoidEnum&gt; {
* <pre> public class MyDecoder extends {@link ReplayingDecoder}&lt;{@link VoidEnum}&gt; {
*
* private final Queue&lt;Integer&gt; values = new LinkedList&lt;Integer&gt;();
*
* public Object decode(.., ChannelBuffer buffer, ..) throws Exception {
* {@code @Override}
* public Object decode(.., {@link ChannelBuffer} buffer, ..) throws Exception {
*
* // Revert the state of the variable that might have been changed
* // since the last partial decode.
@ -177,7 +180,7 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
* }
*
* public class IntegerHeaderFrameDecoder
* extends ReplayingDecoder&lt;<strong>MyDecoderState</strong>&gt; {
* extends {@link ReplayingDecoder}&lt;<strong>MyDecoderState</strong>&gt; {
*
* private int length;
*
@ -186,10 +189,11 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
* <strong>super(MyDecoderState.READ_LENGTH);</strong>
* }
*
* protected Object decode(ChannelHandlerContext ctx,
* Channel channel,
* ChannelBuffer buf,
* MyDecoderState state) throws Exception {
* {@code @Override}
* protected Object decode({@link ChannelHandlerContext} ctx,
* {@link Channel} channel,
* {@link ChannelBuffer} buf,
* <b>MyDecoderState</b> state) throws Exception {
* switch (state) {
* case READ_LENGTH:
* length = buf.readInt();
@ -210,15 +214,16 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
* An alternative way to manage the decoder state is to manage it by yourself.
* <pre>
* public class IntegerHeaderFrameDecoder
* extends ReplayingDecoder&lt;<strong>VoidEnum</strong>&gt; {
* extends {@link ReplayingDecoder}&lt;<strong>{@link VoidEnum}</strong>&gt; {
*
* <strong>private boolean readLength;</strong>
* private int length;
*
* protected Object decode(ChannelHandlerContext ctx,
* Channel channel,
* ChannelBuffer buf,
* MyDecoderState state) throws Exception {
* {@code @Override}
* protected Object decode({@link ChannelHandlerContext} ctx,
* {@link Channel} channel,
* {@link ChannelBuffer} buf,
* {@link VoidEnum} state) throws Exception {
* if (!readLength) {
* length = buf.readInt();
* <strong>readLength = true;</strong>
@ -244,13 +249,17 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
* {@link ChannelPipeline#replace(ChannelHandler, String, ChannelHandler)}, but
* some additional steps are required:
* <pre>
* public class FirstDecoder extends ReplayingDecoder&lt;VoidEnum&gt; {
* public class FirstDecoder extends {@link ReplayingDecoder}&lt;{@link VoidEnum}&gt; {
*
* public FirstDecoder() {
* super(true); // Enable unfold
* }
*
* protected Object decode(ChannelHandlerContext ctx, Channel ch, ChannelBuffer buf, VoidEnum state) {
* {@code @Override}
* protected Object decode({@link ChannelHandlerContext} ctx,
* {@link Channel} ch,
* {@link ChannelBuffer} buf,
* {@link VoidEnum} state) {
* ...
* // Decode the first message
* Object firstMessage = ...;

View File

@ -21,6 +21,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.ChannelHandler.Sharable;
import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
import org.jboss.netty.handler.codec.frame.Delimiters;
@ -46,7 +47,7 @@ import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
* and then you can use a {@link String} instead of a {@link ChannelBuffer}
* as a message:
* <pre>
* void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* String msg = (String) e.getMessage();
* ch.write("Did you say '" + msg + "'?\n");
* }

View File

@ -23,6 +23,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.ChannelHandler.Sharable;
import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
import org.jboss.netty.handler.codec.frame.Delimiters;
@ -44,7 +45,7 @@ import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
* and then you can use a {@link String} instead of a {@link ChannelBuffer}
* as a message:
* <pre>
* void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
* void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* String msg = (String) e.getMessage();
* ch.write("Did you say '" + msg + "'?\n");
* }

View File

@ -17,11 +17,14 @@ package org.jboss.netty.handler.execution;
import java.util.concurrent.Executor;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelDownstreamHandler;
import org.jboss.netty.channel.ChannelEvent;
import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.ChannelState;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ChannelUpstreamHandler;
@ -44,16 +47,16 @@ import org.jboss.netty.util.internal.ExecutorUtil;
* correct event execution order and prevents an {@link OutOfMemoryError}
* under load:
* <pre>
* public class DatabaseGatewayPipelineFactory implements ChannelPipelineFactory {
* public class DatabaseGatewayPipelineFactory implements {@link ChannelPipelineFactory} {
*
* <b>private final ExecutionHandler executionHandler;</b>
* <b>private final {@link ExecutionHandler} executionHandler;</b>
*
* public DatabaseGatewayPipelineFactory(ExecutionHandler executionHandler) {
* public DatabaseGatewayPipelineFactory({@link ExecutionHandler} executionHandler) {
* this.executionHandler = executionHandler;
* }
*
* public ChannelPipeline getPipeline() {
* return Channels.pipeline(
* public {@link ChannelPipeline} getPipeline() {
* return {@link Channels}.pipeline(
* new DatabaseGatewayProtocolEncoder(),
* new DatabaseGatewayProtocolDecoder(),
* <b>executionHandler, // Must be shared</b>
@ -63,9 +66,9 @@ import org.jboss.netty.util.internal.ExecutorUtil;
* ...
*
* public static void main(String[] args) {
* ServerBootstrap bootstrap = ...;
* {@link ServerBootstrap} bootstrap = ...;
* ...
* <b>ExecutionHandler executionHandler = new ExecutionHandler(
* <b>{@link ExecutionHandler} executionHandler = new {@link ExecutionHandler}(
* new {@link OrderedMemoryAwareThreadPoolExecutor}(16, 1048576, 1048576))
* bootstrap.setPipelineFactory(
* new DatabaseGatewayPipelineFactory(executionHandler));</b>
@ -78,7 +81,7 @@ import org.jboss.netty.util.internal.ExecutorUtil;
* }
*
* bootstrap.releaseExternalResources();
* <b>executionHandler.releaseEXternalResources();</b>
* <b>executionHandler.releaseExternalResources();</b>
* }
* </pre>
*

View File

@ -69,11 +69,12 @@ import org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap;
* For example, you can change the key to the remote IP of the peer:
*
* <pre>
* public class RemoteAddressBasedOMATPE extends OrderedMemoryAwareThreadPoolExecutor {
* public class RemoteAddressBasedOMATPE extends {@link OrderedMemoryAwareThreadPoolExecutor} {
*
* ... Constructors ...
*
* protected ConcurrentMap&lt;Object, Executor&gt; new ChildExecutorMap() {
* {@code @Override}
* protected ConcurrentMap&lt;Object, Executor&gt; newChildExecutorMap() {
* // The default implementation returns a special ConcurrentMap that
* // uses identity comparison only (see {@link IdentityHashMap}).
* // Because SocketAddress does not work with identity comparison,
@ -81,7 +82,7 @@ import org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap;
* return new ConcurrentHashMap&lt;Object, Executor&gt;
* }
*
* protected Object getChildExecutorKey(ChannelEvent e) {
* protected Object getChildExecutorKey({@link ChannelEvent} e) {
* // Use the IP of the remote peer as a key.
* return ((InetSocketAddress) e.getChannel().getRemoteAddress()).getAddress();
* }

View File

@ -19,6 +19,7 @@ import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelEvent;
import org.jboss.netty.channel.ChannelHandlerContext;
@ -46,22 +47,22 @@ import org.jboss.netty.util.internal.LinkedTransferQueue;
* <p>
* Here is an example that demonstrates the usage:
* <pre>
* BlockingReadHandler&lt;ChannelBuffer&gt; reader =
* new BlockingReadHandler&lt;ChannelBuffer&gt;();
* ChannelPipeline p = ...;
* {@link BlockingReadHandler}&lt;{@link ChannelBuffer}&gt; reader =
* new {@link BlockingReadHandler}&lt;{@link ChannelBuffer}&gt;();
* {@link ChannelPipeline} p = ...;
* p.addLast("reader", reader);
*
* ...
*
* // Read a message from a channel in a blocking manner.
* try {
* ChannelBuffer buf = reader.read(60, TimeUnit.SECONDS);
* {@link ChannelBuffer} buf = reader.read(60, TimeUnit.SECONDS);
* if (buf == null) {
* // Connection closed.
* } else {
* // Handle the received message here.
* }
* } catch (BlockingReadTimeoutException e) {
* } catch ({@link BlockingReadTimeoutException} e) {
* // Read timed out.
* } catch (IOException e) {
* // Other read errors

View File

@ -18,6 +18,7 @@ package org.jboss.netty.handler.queue;
import java.util.Queue;
import java.util.concurrent.BlockingQueue;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
@ -56,14 +57,14 @@ import org.jboss.netty.util.internal.LinkedTransferQueue;
* queue when the size of the queue increases. You can implement your own
* auto-flush strategy by extending this handler:
* <pre>
* public class AutoFlusher extends BufferedWriteHandler {
* public class AutoFlusher extends {@link BufferedWriteHandler} {
*
* private final AtomicLong bufferSize = new AtomicLong();
*
* public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) {
* public void writeRequested({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* super.writeRequested(ctx, e);
*
* ChannelBuffer data = (ChannelBuffer) e.getMessage();
* {@link ChannelBuffer} data = ({@link ChannelBuffer}) e.getMessage();
* int newBufferSize = bufferSize.addAndGet(data.readableBytes());
*
* // Flush the queue if it gets larger than 8KiB.

View File

@ -27,6 +27,7 @@ import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ChannelUpstreamHandler;
import org.jboss.netty.channel.Channels;
@ -46,16 +47,16 @@ import org.jboss.netty.util.internal.LinkedTransferQueue;
* To use {@link ChunkedWriteHandler} in your application, you have to insert
* a new {@link ChunkedWriteHandler} instance:
* <pre>
* ChannelPipeline p = ...;
* p.addLast("streamer", <b>new ChunkedWriteHandler()</b>);
* {@link ChannelPipeline} p = ...;
* p.addLast("streamer", <b>new {@link ChunkedWriteHandler}()</b>);
* p.addLast("handler", new MyHandler());
* </pre>
* Once inserted, you can write a {@link ChunkedInput} so that the
* {@link ChunkedWriteHandler} can pick it up and fetch the content of the
* stream chunk by chunk and write the fetched chunk downstream:
* <pre>
* Channel ch = ...;
* ch.write(new ChunkedFile(new File("video.mkv"));
* {@link Channel} ch = ...;
* ch.write(new {@link ChunkedFile}(new File("video.mkv"));
* </pre>
*
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>

View File

@ -19,9 +19,13 @@ import static org.jboss.netty.channel.Channels.*;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.LifeCycleAwareChannelHandler;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
@ -65,28 +69,32 @@ import org.jboss.netty.util.TimerTask;
* // An example that sends a ping message when there is no traffic
* // (either inbound or outbound) for 30 seconds.
*
* public class MyPipelineFactory implements ChannelPipelineFactory {
* public class MyPipelineFactory implements {@link ChannelPipelineFactory} {
*
* public MyPipelineFactory(Timer timer) {
* private final {@link Timer} timer;
*
* public MyPipelineFactory({@link Timer} timer) {
* this.timer = timer;
* }
*
* public ChannelPipeline getPipeline() {
* return Channels.pipeline(
* new IdleStateHandler(timer, 30, 30, 0),
* public {@link ChannelPipeline} getPipeline() {
* return {@link Channels}.pipeline(
* new {@link IdleStateHandler}(timer, 30, 30, 0),
* new MyHandler());
* }
* }
*
* // Handler should handle the IdleStateEvent triggered by IdleStateHandler.
* public class MyHandler extends IdleStateAwareChannelHandler {
* public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
* public class MyHandler extends {@link IdleStateAwareChannelHandler} {
*
* {@code @Override}
* public void channelIdle({@link ChannelHandlerContext} ctx, {@link IdleStateEvent} e) {
* ctx.getChannel().write(new PingMessage());
* }
* }
*
* ServerBootstrap bootstrap = ...;
* Timer timer = new HashedWheelTimer();
* {@link ServerBootstrap} bootstrap = ...;
* {@link Timer} timer = new {@link HashedWheelTimer}();
* ...
* bootstrap.setPipelineFactory(new MyPipelineFactory(timer));
* ...

View File

@ -19,7 +19,10 @@ import static org.jboss.netty.channel.Channels.*;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.LifeCycleAwareChannelHandler;
@ -36,22 +39,24 @@ import org.jboss.netty.util.TimerTask;
* period of time.
*
* <pre>
* public class MyPipelineFactory implements ChannelPipelineFactory {
* public class MyPipelineFactory implements {@link ChannelPipelineFactory} {
*
* public MyPipelineFactory(Timer timer) {
* private final {@link Timer} timer;
*
* public MyPipelineFactory({@link Timer} timer) {
* this.timer = timer;
* }
*
* public ChannelPipeline getPipeline() {
* public {@link ChannelPipeline} getPipeline() {
* // An example configuration that implements 30-second read timeout:
* return Channels.pipeline(
* new ReadTimeoutHandler(timer, 30),
* return {@link Channels}.pipeline(
* new {@link ReadTimeoutHandler}(timer, 30),
* new MyHandler());
* }
* }
*
* ServerBootstrap bootstrap = ...;
* Timer timer = new HashedWheelTimer();
* {@link ServerBootstrap} bootstrap = ...;
* {@link Timer} timer = new {@link HashedWheelTimer}();
* ...
* bootstrap.setPipelineFactory(new MyPipelineFactory(timer));
* ...

View File

@ -19,9 +19,12 @@ import static org.jboss.netty.channel.Channels.*;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelDownstreamHandler;
@ -37,22 +40,24 @@ import org.jboss.netty.util.TimerTask;
* certain period of time.
*
* <pre>
* public class MyPipelineFactory implements ChannelPipelineFactory {
* public class MyPipelineFactory implements {@link ChannelPipelineFactory} {
*
* public MyPipelineFactory(Timer timer) {
* private final {@link Timer} timer;
*
* public MyPipelineFactory({@link Timer} timer) {
* this.timer = timer;
* }
*
* public ChannelPipeline getPipeline() {
* public {@link ChannelPipeline} getPipeline() {
* // An example configuration that implements 30-second write timeout:
* return Channels.pipeline(
* new WriteTimeoutHandler(timer, 30),
* return {@link Channels}.pipeline(
* new {@link WriteTimeoutHandler}(timer, 30),
* new MyHandler());
* }
* }
*
* ServerBootstrap bootstrap = ...;
* Timer timer = new HashedWheelTimer();
* {@link ServerBootstrap} bootstrap = ...;
* {@link Timer} timer = new {@link HashedWheelTimer}();
* ...
* bootstrap.setPipelineFactory(new MyPipelineFactory(timer));
* ...

View File

@ -24,7 +24,7 @@ import org.jboss.netty.util.internal.StackTraceSimplifier;
* You can change it to your preferred logging framework before other Netty
* classes are loaded:
* <pre>
* InternalLoggerFactory.setDefaultFactory(new {@link Log4JLoggerFactory}());
* {@link InternalLoggerFactory}.setDefaultFactory(new {@link Log4JLoggerFactory}());
* </pre>
* Please note that the new default factory is effective only for the classes
* which were loaded after the default factory is changed. Therefore,

View File

@ -25,6 +25,9 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
/**
* A delegating {@link ExecutorService} with its own termination management.
@ -38,10 +41,10 @@ import java.util.concurrent.TimeUnit;
*
* <pre>
* ExecutorService globalExecutor = ...;
* ExecutorService virtualExecutor = new VirtualExecutorService(globalExecutor);
* ExecutorService virtualExecutor = new {@link VirtualExecutorService}(globalExecutor);
*
* ChannelFactory factory =
* new NioServerSocketChannelFactory(virtualExecutor, virtualExecutor);
* {@link ChannelFactory} factory =
* new {@link NioServerSocketChannelFactory}(virtualExecutor, virtualExecutor);
* ...
*
* // ChannelFactory.releaseExternalResources() shuts down the executor and