Optimized event implementation to reduce memory footprint and improve performance somewhat
This commit is contained in:
parent
ebcf1b84e0
commit
8f92cfb80a
@ -171,7 +171,7 @@ public class Channels {
|
||||
* 'destination' when the event is sent downstream)
|
||||
*/
|
||||
public static MessageEvent messageEvent(Channel channel, ChannelFuture future, Object message, SocketAddress remoteAddress) {
|
||||
return new DefaultMessageEvent(channel, future, message, remoteAddress);
|
||||
return new DownstreamMessageEvent(channel, future, message, remoteAddress);
|
||||
}
|
||||
|
||||
// event emission methods
|
||||
@ -189,9 +189,8 @@ public class Channels {
|
||||
}
|
||||
|
||||
channel.getPipeline().sendUpstream(
|
||||
new DefaultChannelStateEvent(
|
||||
channel, succeededFuture(channel),
|
||||
ChannelState.OPEN, Boolean.TRUE));
|
||||
new UpstreamChannelStateEvent(
|
||||
channel, ChannelState.OPEN, Boolean.TRUE));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,9 +201,8 @@ public class Channels {
|
||||
* {@link #fireChannelOpen(Channel)} method.
|
||||
*/
|
||||
public static void fireChannelOpen(ChannelHandlerContext ctx) {
|
||||
ctx.sendUpstream(new DefaultChannelStateEvent(
|
||||
ctx.getChannel(), succeededFuture(ctx.getChannel()),
|
||||
ChannelState.OPEN, Boolean.TRUE));
|
||||
ctx.sendUpstream(new UpstreamChannelStateEvent(
|
||||
ctx.getChannel(), ChannelState.OPEN, Boolean.TRUE));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,9 +231,8 @@ public class Channels {
|
||||
*/
|
||||
public static void fireChannelBound(Channel channel, SocketAddress localAddress) {
|
||||
channel.getPipeline().sendUpstream(
|
||||
new DefaultChannelStateEvent(
|
||||
channel, succeededFuture(channel),
|
||||
ChannelState.BOUND, localAddress));
|
||||
new UpstreamChannelStateEvent(
|
||||
channel, ChannelState.BOUND, localAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -247,9 +244,8 @@ public class Channels {
|
||||
* the local address where the specified channel is bound
|
||||
*/
|
||||
public static void fireChannelBound(ChannelHandlerContext ctx, SocketAddress localAddress) {
|
||||
ctx.sendUpstream(new DefaultChannelStateEvent(
|
||||
ctx.getChannel(), succeededFuture(ctx.getChannel()),
|
||||
ChannelState.BOUND, localAddress));
|
||||
ctx.sendUpstream(new UpstreamChannelStateEvent(
|
||||
ctx.getChannel(), ChannelState.BOUND, localAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -280,9 +276,8 @@ public class Channels {
|
||||
*/
|
||||
public static void fireChannelConnected(Channel channel, SocketAddress remoteAddress) {
|
||||
channel.getPipeline().sendUpstream(
|
||||
new DefaultChannelStateEvent(
|
||||
channel, succeededFuture(channel),
|
||||
ChannelState.CONNECTED, remoteAddress));
|
||||
new UpstreamChannelStateEvent(
|
||||
channel, ChannelState.CONNECTED, remoteAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -295,9 +290,8 @@ public class Channels {
|
||||
*/
|
||||
public static void fireChannelConnected(ChannelHandlerContext ctx, SocketAddress remoteAddress) {
|
||||
|
||||
ctx.sendUpstream(new DefaultChannelStateEvent(
|
||||
ctx.getChannel(), succeededFuture(ctx.getChannel()),
|
||||
ChannelState.CONNECTED, remoteAddress));
|
||||
ctx.sendUpstream(new UpstreamChannelStateEvent(
|
||||
ctx.getChannel(), ChannelState.CONNECTED, remoteAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -340,9 +334,7 @@ public class Channels {
|
||||
*/
|
||||
public static void fireMessageReceived(Channel channel, Object message, SocketAddress remoteAddress) {
|
||||
channel.getPipeline().sendUpstream(
|
||||
new DefaultMessageEvent(
|
||||
channel, succeededFuture(channel),
|
||||
message, remoteAddress));
|
||||
new UpstreamMessageEvent(channel, message, remoteAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -353,8 +345,7 @@ public class Channels {
|
||||
* @param message the received message
|
||||
*/
|
||||
public static void fireMessageReceived(ChannelHandlerContext ctx, Object message) {
|
||||
ctx.sendUpstream(new DefaultMessageEvent(
|
||||
ctx.getChannel(), succeededFuture(ctx.getChannel()), message, null));
|
||||
ctx.sendUpstream(new UpstreamMessageEvent(ctx.getChannel(), message, null));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -385,8 +376,8 @@ public class Channels {
|
||||
*/
|
||||
public static void fireMessageReceived(
|
||||
ChannelHandlerContext ctx, Object message, SocketAddress remoteAddress) {
|
||||
ctx.sendUpstream(new DefaultMessageEvent(
|
||||
ctx.getChannel(), succeededFuture(ctx.getChannel()), message, remoteAddress));
|
||||
ctx.sendUpstream(new UpstreamMessageEvent(
|
||||
ctx.getChannel(), message, remoteAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -419,8 +410,7 @@ public class Channels {
|
||||
}
|
||||
|
||||
channel.getPipeline().sendUpstream(
|
||||
new DefaultWriteCompletionEvent(
|
||||
channel, succeededFuture(channel), amount));
|
||||
new DefaultWriteCompletionEvent(channel, amount));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -429,8 +419,7 @@ public class Channels {
|
||||
* the specified {@link ChannelHandlerContext} belongs.
|
||||
*/
|
||||
public static void fireWriteCompleted(ChannelHandlerContext ctx, int amount) {
|
||||
ctx.sendUpstream(new DefaultWriteCompletionEvent(
|
||||
ctx.getChannel(), succeededFuture(ctx.getChannel()), amount));
|
||||
ctx.sendUpstream(new DefaultWriteCompletionEvent(ctx.getChannel(), amount));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -440,9 +429,8 @@ public class Channels {
|
||||
*/
|
||||
public static void fireChannelInterestChanged(Channel channel) {
|
||||
channel.getPipeline().sendUpstream(
|
||||
new DefaultChannelStateEvent(
|
||||
channel, succeededFuture(channel),
|
||||
ChannelState.INTEREST_OPS, Channel.OP_READ));
|
||||
new UpstreamChannelStateEvent(
|
||||
channel, ChannelState.INTEREST_OPS, Channel.OP_READ));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -469,9 +457,8 @@ public class Channels {
|
||||
ChannelHandlerContext ctx) {
|
||||
|
||||
ctx.sendUpstream(
|
||||
new DefaultChannelStateEvent(
|
||||
ctx.getChannel(), succeededFuture(ctx.getChannel()),
|
||||
ChannelState.INTEREST_OPS, Channel.OP_READ));
|
||||
new UpstreamChannelStateEvent(
|
||||
ctx.getChannel(), ChannelState.INTEREST_OPS, Channel.OP_READ));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -499,9 +486,8 @@ public class Channels {
|
||||
*/
|
||||
public static void fireChannelDisconnected(Channel channel) {
|
||||
channel.getPipeline().sendUpstream(
|
||||
new DefaultChannelStateEvent(
|
||||
channel, succeededFuture(channel),
|
||||
ChannelState.CONNECTED, null));
|
||||
new UpstreamChannelStateEvent(
|
||||
channel, ChannelState.CONNECTED, null));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -510,9 +496,8 @@ public class Channels {
|
||||
* the specified {@link ChannelHandlerContext} belongs.
|
||||
*/
|
||||
public static void fireChannelDisconnected(ChannelHandlerContext ctx) {
|
||||
ctx.sendUpstream(new DefaultChannelStateEvent(
|
||||
ctx.getChannel(), succeededFuture(ctx.getChannel()),
|
||||
ChannelState.CONNECTED, null));
|
||||
ctx.sendUpstream(new UpstreamChannelStateEvent(
|
||||
ctx.getChannel(), ChannelState.CONNECTED, null));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -535,8 +520,8 @@ public class Channels {
|
||||
* the specified {@link Channel}.
|
||||
*/
|
||||
public static void fireChannelUnbound(Channel channel) {
|
||||
channel.getPipeline().sendUpstream(new DefaultChannelStateEvent(
|
||||
channel, succeededFuture(channel), ChannelState.BOUND, null));
|
||||
channel.getPipeline().sendUpstream(new UpstreamChannelStateEvent(
|
||||
channel, ChannelState.BOUND, null));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -546,8 +531,8 @@ public class Channels {
|
||||
*/
|
||||
public static void fireChannelUnbound(ChannelHandlerContext ctx) {
|
||||
|
||||
ctx.sendUpstream(new DefaultChannelStateEvent(
|
||||
ctx.getChannel(), succeededFuture(ctx.getChannel()), ChannelState.BOUND, null));
|
||||
ctx.sendUpstream(new UpstreamChannelStateEvent(
|
||||
ctx.getChannel(), ChannelState.BOUND, null));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -571,9 +556,8 @@ public class Channels {
|
||||
*/
|
||||
public static void fireChannelClosed(Channel channel) {
|
||||
channel.getPipeline().sendUpstream(
|
||||
new DefaultChannelStateEvent(
|
||||
channel, succeededFuture(channel),
|
||||
ChannelState.OPEN, Boolean.FALSE));
|
||||
new UpstreamChannelStateEvent(
|
||||
channel, ChannelState.OPEN, Boolean.FALSE));
|
||||
|
||||
// Notify the parent handler.
|
||||
if (channel.getParent() != null) {
|
||||
@ -588,9 +572,8 @@ public class Channels {
|
||||
*/
|
||||
public static void fireChannelClosed(ChannelHandlerContext ctx) {
|
||||
ctx.sendUpstream(
|
||||
new DefaultChannelStateEvent(
|
||||
ctx.getChannel(), succeededFuture(ctx.getChannel()),
|
||||
ChannelState.OPEN, Boolean.FALSE));
|
||||
new UpstreamChannelStateEvent(
|
||||
ctx.getChannel(), ChannelState.OPEN, Boolean.FALSE));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -614,8 +597,7 @@ public class Channels {
|
||||
*/
|
||||
public static void fireExceptionCaught(Channel channel, Throwable cause) {
|
||||
channel.getPipeline().sendUpstream(
|
||||
new DefaultExceptionEvent(
|
||||
channel, succeededFuture(channel), cause));
|
||||
new DefaultExceptionEvent(channel, cause));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -624,8 +606,7 @@ public class Channels {
|
||||
* the specified {@link ChannelHandlerContext} belongs.
|
||||
*/
|
||||
public static void fireExceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
ctx.sendUpstream(new DefaultExceptionEvent(
|
||||
ctx.getChannel(), succeededFuture(ctx.getChannel()), cause));
|
||||
ctx.sendUpstream(new DefaultExceptionEvent(ctx.getChannel(), cause));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -646,8 +627,7 @@ public class Channels {
|
||||
private static void fireChildChannelStateChanged(
|
||||
Channel channel, Channel childChannel) {
|
||||
channel.getPipeline().sendUpstream(
|
||||
new DefaultChildChannelStateEvent(
|
||||
channel, succeededFuture(channel), childChannel));
|
||||
new DefaultChildChannelStateEvent(channel, childChannel));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -666,7 +646,7 @@ public class Channels {
|
||||
throw new NullPointerException("localAddress");
|
||||
}
|
||||
ChannelFuture future = future(channel);
|
||||
channel.getPipeline().sendDownstream(new DefaultChannelStateEvent(
|
||||
channel.getPipeline().sendDownstream(new DownstreamChannelStateEvent(
|
||||
channel, future, ChannelState.BOUND, localAddress));
|
||||
return future;
|
||||
}
|
||||
@ -686,7 +666,7 @@ public class Channels {
|
||||
if (localAddress == null) {
|
||||
throw new NullPointerException("localAddress");
|
||||
}
|
||||
ctx.sendDownstream(new DefaultChannelStateEvent(
|
||||
ctx.sendDownstream(new DownstreamChannelStateEvent(
|
||||
ctx.getChannel(), future, ChannelState.BOUND, localAddress));
|
||||
}
|
||||
|
||||
@ -721,7 +701,7 @@ public class Channels {
|
||||
* operation is done
|
||||
*/
|
||||
public static void unbind(ChannelHandlerContext ctx, ChannelFuture future) {
|
||||
ctx.sendDownstream(new DefaultChannelStateEvent(
|
||||
ctx.sendDownstream(new DownstreamChannelStateEvent(
|
||||
ctx.getChannel(), future, ChannelState.BOUND, null));
|
||||
}
|
||||
|
||||
@ -757,7 +737,7 @@ public class Channels {
|
||||
*/
|
||||
public static ChannelFuture unbind(Channel channel) {
|
||||
ChannelFuture future = future(channel);
|
||||
channel.getPipeline().sendDownstream(new DefaultChannelStateEvent(
|
||||
channel.getPipeline().sendDownstream(new DownstreamChannelStateEvent(
|
||||
channel, future, ChannelState.BOUND, null));
|
||||
return future;
|
||||
}
|
||||
@ -778,7 +758,7 @@ public class Channels {
|
||||
throw new NullPointerException("remoteAddress");
|
||||
}
|
||||
ChannelFuture future = future(channel, true);
|
||||
channel.getPipeline().sendDownstream(new DefaultChannelStateEvent(
|
||||
channel.getPipeline().sendDownstream(new DownstreamChannelStateEvent(
|
||||
channel, future, ChannelState.CONNECTED, remoteAddress));
|
||||
return future;
|
||||
}
|
||||
@ -798,7 +778,7 @@ public class Channels {
|
||||
if (remoteAddress == null) {
|
||||
throw new NullPointerException("remoteAddress");
|
||||
}
|
||||
ctx.sendDownstream(new DefaultChannelStateEvent(
|
||||
ctx.sendDownstream(new DownstreamChannelStateEvent(
|
||||
ctx.getChannel(), future, ChannelState.CONNECTED, remoteAddress));
|
||||
}
|
||||
|
||||
@ -888,7 +868,7 @@ public class Channels {
|
||||
public static ChannelFuture write(Channel channel, Object message, SocketAddress remoteAddress) {
|
||||
ChannelFuture future = future(channel);
|
||||
channel.getPipeline().sendDownstream(
|
||||
new DefaultMessageEvent(channel, future, message, remoteAddress));
|
||||
new DownstreamMessageEvent(channel, future, message, remoteAddress));
|
||||
return future;
|
||||
}
|
||||
|
||||
@ -908,7 +888,7 @@ public class Channels {
|
||||
ChannelHandlerContext ctx, ChannelFuture future,
|
||||
Object message, SocketAddress remoteAddress) {
|
||||
ctx.sendDownstream(
|
||||
new DefaultMessageEvent(ctx.getChannel(), future, message, remoteAddress));
|
||||
new DownstreamMessageEvent(ctx.getChannel(), future, message, remoteAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -950,7 +930,7 @@ public class Channels {
|
||||
interestOps = filterDownstreamInterestOps(interestOps);
|
||||
|
||||
ChannelFuture future = future(channel);
|
||||
channel.getPipeline().sendDownstream(new DefaultChannelStateEvent(
|
||||
channel.getPipeline().sendDownstream(new DownstreamChannelStateEvent(
|
||||
channel, future, ChannelState.INTEREST_OPS, Integer.valueOf(interestOps)));
|
||||
return future;
|
||||
}
|
||||
@ -970,7 +950,7 @@ public class Channels {
|
||||
interestOps = filterDownstreamInterestOps(interestOps);
|
||||
|
||||
ctx.sendDownstream(
|
||||
new DefaultChannelStateEvent(
|
||||
new DownstreamChannelStateEvent(
|
||||
ctx.getChannel(), future, ChannelState.INTEREST_OPS,
|
||||
Integer.valueOf(interestOps)));
|
||||
}
|
||||
@ -1006,7 +986,7 @@ public class Channels {
|
||||
*/
|
||||
public static ChannelFuture disconnect(Channel channel) {
|
||||
ChannelFuture future = future(channel);
|
||||
channel.getPipeline().sendDownstream(new DefaultChannelStateEvent(
|
||||
channel.getPipeline().sendDownstream(new DownstreamChannelStateEvent(
|
||||
channel, future, ChannelState.CONNECTED, null));
|
||||
return future;
|
||||
}
|
||||
@ -1021,7 +1001,7 @@ public class Channels {
|
||||
*/
|
||||
public static void disconnect(
|
||||
ChannelHandlerContext ctx, ChannelFuture future) {
|
||||
ctx.sendDownstream(new DefaultChannelStateEvent(
|
||||
ctx.sendDownstream(new DownstreamChannelStateEvent(
|
||||
ctx.getChannel(), future, ChannelState.CONNECTED, null));
|
||||
}
|
||||
|
||||
@ -1054,7 +1034,7 @@ public class Channels {
|
||||
*/
|
||||
public static ChannelFuture close(Channel channel) {
|
||||
ChannelFuture future = channel.getCloseFuture();
|
||||
channel.getPipeline().sendDownstream(new DefaultChannelStateEvent(
|
||||
channel.getPipeline().sendDownstream(new DownstreamChannelStateEvent(
|
||||
channel, future, ChannelState.OPEN, Boolean.FALSE));
|
||||
return future;
|
||||
}
|
||||
@ -1069,7 +1049,7 @@ public class Channels {
|
||||
*/
|
||||
public static void close(
|
||||
ChannelHandlerContext ctx, ChannelFuture future) {
|
||||
ctx.sendDownstream(new DefaultChannelStateEvent(
|
||||
ctx.sendDownstream(new DownstreamChannelStateEvent(
|
||||
ctx.getChannel(), future, ChannelState.OPEN, Boolean.FALSE));
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
*/
|
||||
package org.jboss.netty.channel;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
/**
|
||||
* The default {@link ChildChannelStateEvent} implementation.
|
||||
*
|
||||
@ -31,37 +33,46 @@ package org.jboss.netty.channel;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
public class DefaultChildChannelStateEvent extends DefaultChannelEvent implements
|
||||
ChildChannelStateEvent {
|
||||
public final class DefaultChildChannelStateEvent implements ChildChannelStateEvent {
|
||||
|
||||
private final Channel parentChannel;
|
||||
private final Channel childChannel;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
public DefaultChildChannelStateEvent(
|
||||
Channel channel, ChannelFuture future, Channel childChannel) {
|
||||
|
||||
super(channel, future);
|
||||
public DefaultChildChannelStateEvent(Channel parentChannel, Channel childChannel) {
|
||||
if (parentChannel == null) {
|
||||
throw new NullPointerException("parentChannel");
|
||||
}
|
||||
if (childChannel == null) {
|
||||
throw new NullPointerException("childChannel");
|
||||
}
|
||||
this.parentChannel = parentChannel;
|
||||
this.childChannel = childChannel;
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return parentChannel;
|
||||
}
|
||||
|
||||
public ChannelFuture getFuture() {
|
||||
return succeededFuture(getChannel());
|
||||
}
|
||||
|
||||
public Channel getChildChannel() {
|
||||
return childChannel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String parentString = super.toString();
|
||||
StringBuilder buf = new StringBuilder(parentString.length() + 32);
|
||||
buf.append(parentString);
|
||||
String channelString = getChannel().toString();
|
||||
StringBuilder buf = new StringBuilder(channelString.length() + 32);
|
||||
buf.append(channelString);
|
||||
buf.append(" - (childId: ");
|
||||
buf.append(getChildChannel().getId().toString());
|
||||
buf.append(", childState: ");
|
||||
buf.append(getChildChannel().isOpen()? "OPEN" : "CLOSE");
|
||||
buf.append(getChildChannel().isOpen()? "OPEN" : "CLOSED");
|
||||
buf.append(')');
|
||||
return buf.toString();
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
*/
|
||||
package org.jboss.netty.channel;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import org.jboss.netty.util.StackTraceSimplifier;
|
||||
|
||||
/**
|
||||
@ -33,29 +35,40 @@ import org.jboss.netty.util.StackTraceSimplifier;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
public class DefaultExceptionEvent extends DefaultChannelEvent implements
|
||||
ExceptionEvent {
|
||||
public final class DefaultExceptionEvent implements ExceptionEvent {
|
||||
|
||||
private final Channel channel;
|
||||
private final Throwable cause;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
public DefaultExceptionEvent(Channel channel, ChannelFuture future, Throwable cause) {
|
||||
super(channel, future);
|
||||
public DefaultExceptionEvent(Channel channel, Throwable cause) {
|
||||
if (channel == null) {
|
||||
throw new NullPointerException("channel");
|
||||
}
|
||||
if (cause == null) {
|
||||
throw new NullPointerException("cause");
|
||||
}
|
||||
this.channel = channel;
|
||||
this.cause = cause;
|
||||
StackTraceSimplifier.simplify(cause);
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public ChannelFuture getFuture() {
|
||||
return succeededFuture(getChannel());
|
||||
}
|
||||
|
||||
public Throwable getCause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " - (cause: " + cause.getClass().getSimpleName() + ')';
|
||||
return getChannel().toString() + " - (cause: " + cause.getClass().getSimpleName() + ')';
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
*/
|
||||
package org.jboss.netty.channel;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
/**
|
||||
* The default {@link WriteCompletionEvent} implementation.
|
||||
*
|
||||
@ -30,26 +32,35 @@ package org.jboss.netty.channel;
|
||||
*
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class DefaultWriteCompletionEvent extends DefaultChannelEvent implements
|
||||
WriteCompletionEvent {
|
||||
public final class DefaultWriteCompletionEvent implements WriteCompletionEvent {
|
||||
|
||||
private final Channel channel;
|
||||
private final int writtenAmount;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
public DefaultWriteCompletionEvent(
|
||||
Channel channel, ChannelFuture future, int writtenAmount) {
|
||||
|
||||
super(channel, future);
|
||||
public DefaultWriteCompletionEvent(Channel channel, int writtenAmount) {
|
||||
if (channel == null) {
|
||||
throw new NullPointerException("channel");
|
||||
}
|
||||
if (writtenAmount <= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"writtenAmount must be a positive integer: " + writtenAmount);
|
||||
}
|
||||
|
||||
this.channel = channel;
|
||||
this.writtenAmount = writtenAmount;
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public ChannelFuture getFuture() {
|
||||
return succeededFuture(getChannel());
|
||||
}
|
||||
|
||||
public int getWrittenAmount() {
|
||||
return writtenAmount;
|
||||
}
|
||||
|
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
*
|
||||
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
||||
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jboss.netty.channel;
|
||||
|
||||
/**
|
||||
* The default {@link ChannelStateEvent} implementation.
|
||||
*
|
||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
*
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
public final class DownstreamChannelStateEvent implements ChannelStateEvent {
|
||||
|
||||
private final Channel channel;
|
||||
private final ChannelFuture future;
|
||||
private final ChannelState state;
|
||||
private final Object value;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
public DownstreamChannelStateEvent(
|
||||
Channel channel, ChannelFuture future,
|
||||
ChannelState state, Object value) {
|
||||
|
||||
if (channel == null) {
|
||||
throw new NullPointerException("channel");
|
||||
}
|
||||
if (future == null) {
|
||||
throw new NullPointerException("future");
|
||||
}
|
||||
if (state == null) {
|
||||
throw new NullPointerException("state");
|
||||
}
|
||||
this.channel = channel;
|
||||
this.future = future;
|
||||
this.state = state;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public ChannelFuture getFuture() {
|
||||
return future;
|
||||
}
|
||||
|
||||
public ChannelState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String channelString = getChannel().toString();
|
||||
StringBuilder buf = new StringBuilder(channelString.length() + 64);
|
||||
buf.append(channelString);
|
||||
buf.append(" - (request: ");
|
||||
switch (getState()) {
|
||||
case OPEN:
|
||||
if (Boolean.TRUE.equals(getValue())) {
|
||||
buf.append("OPEN");
|
||||
} else {
|
||||
buf.append("CLOSE");
|
||||
}
|
||||
break;
|
||||
case BOUND:
|
||||
if (getValue() != null) {
|
||||
buf.append("BIND");
|
||||
} else {
|
||||
buf.append("UNBIND");
|
||||
}
|
||||
break;
|
||||
case CONNECTED:
|
||||
if (getValue() != null) {
|
||||
buf.append("CONNECT");
|
||||
} else {
|
||||
buf.append("DISCONNECT");
|
||||
}
|
||||
break;
|
||||
case INTEREST_OPS:
|
||||
buf.append("CHANGE_INTEREST");
|
||||
break;
|
||||
default:
|
||||
buf.append(getState().name());
|
||||
buf.append(": ");
|
||||
buf.append(getValue());
|
||||
}
|
||||
buf.append(')');
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
@ -37,27 +37,43 @@ import java.net.SocketAddress;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
public class DefaultMessageEvent extends DefaultChannelEvent implements
|
||||
MessageEvent {
|
||||
public final class DownstreamMessageEvent implements MessageEvent {
|
||||
|
||||
private final Channel channel;
|
||||
private final ChannelFuture future;
|
||||
private final Object message;
|
||||
private final SocketAddress remoteAddress;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
public DefaultMessageEvent(
|
||||
public DownstreamMessageEvent(
|
||||
Channel channel, ChannelFuture future,
|
||||
Object message, SocketAddress remoteAddress) {
|
||||
|
||||
super(channel, future);
|
||||
if (channel == null) {
|
||||
throw new NullPointerException("channel");
|
||||
}
|
||||
if (future == null) {
|
||||
throw new NullPointerException("future");
|
||||
}
|
||||
if (message == null) {
|
||||
throw new NullPointerException("message");
|
||||
}
|
||||
this.channel = channel;
|
||||
this.future = future;
|
||||
this.message = message;
|
||||
this.remoteAddress = remoteAddress;
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public ChannelFuture getFuture() {
|
||||
return future;
|
||||
}
|
||||
|
||||
public Object getMessage() {
|
||||
return message;
|
||||
}
|
||||
@ -69,9 +85,9 @@ public class DefaultMessageEvent extends DefaultChannelEvent implements
|
||||
@Override
|
||||
public String toString() {
|
||||
if (remoteAddress == null) {
|
||||
return super.toString() + " - (message: " + message + ')';
|
||||
return super.toString() + " - (write: " + message + ')';
|
||||
} else {
|
||||
return super.toString() + " - (message: " + message + ", " + remoteAddress + ')';
|
||||
return super.toString() + " - (write: " + message + ", " + remoteAddress + ')';
|
||||
}
|
||||
}
|
||||
}
|
@ -22,6 +22,8 @@
|
||||
*/
|
||||
package org.jboss.netty.channel;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
/**
|
||||
* The default {@link ChannelStateEvent} implementation.
|
||||
*
|
||||
@ -31,27 +33,38 @@ package org.jboss.netty.channel;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
public class DefaultChannelStateEvent extends DefaultChannelEvent implements
|
||||
ChannelStateEvent {
|
||||
public final class UpstreamChannelStateEvent implements ChannelStateEvent {
|
||||
|
||||
private final Channel channel;
|
||||
private final ChannelState state;
|
||||
private final Object value;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
public DefaultChannelStateEvent(
|
||||
Channel channel, ChannelFuture future,
|
||||
ChannelState state, Object value) {
|
||||
public UpstreamChannelStateEvent(
|
||||
Channel channel, ChannelState state, Object value) {
|
||||
|
||||
super(channel, future);
|
||||
if (channel == null) {
|
||||
throw new NullPointerException("channel");
|
||||
}
|
||||
if (state == null) {
|
||||
throw new NullPointerException("state");
|
||||
}
|
||||
|
||||
this.channel = channel;
|
||||
this.state = state;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public ChannelFuture getFuture() {
|
||||
return succeededFuture(getChannel());
|
||||
}
|
||||
|
||||
public ChannelState getState() {
|
||||
return state;
|
||||
}
|
||||
@ -62,9 +75,9 @@ public class DefaultChannelStateEvent extends DefaultChannelEvent implements
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String parentString = super.toString();
|
||||
StringBuilder buf = new StringBuilder(parentString.length() + 64);
|
||||
buf.append(parentString);
|
||||
String channelString = getChannel().toString();
|
||||
StringBuilder buf = new StringBuilder(channelString.length() + 64);
|
||||
buf.append(channelString);
|
||||
buf.append(" - (state: ");
|
||||
switch (getState()) {
|
||||
case OPEN:
|
@ -22,8 +22,16 @@
|
||||
*/
|
||||
package org.jboss.netty.channel;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
/**
|
||||
* The default {@link ChannelEvent} implementation.
|
||||
* The default {@link MessageEvent} implementation. It is recommended to
|
||||
* use {@link Channels#messageEvent(Channel, ChannelFuture, Object)} and
|
||||
* {@link Channels#messageEvent(Channel, ChannelFuture, Object, SocketAddress)}
|
||||
* to create a new {@link MessageEvent} instance rather than calling the
|
||||
* constructor explicitly.
|
||||
*
|
||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
@ -31,38 +39,51 @@ package org.jboss.netty.channel;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
public class DefaultChannelEvent implements ChannelEvent {
|
||||
public final class UpstreamMessageEvent implements MessageEvent {
|
||||
|
||||
private final Channel channel;
|
||||
private final ChannelFuture future;
|
||||
private final Object message;
|
||||
private final SocketAddress remoteAddress;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
public DefaultChannelEvent(Channel channel, ChannelFuture future) {
|
||||
public UpstreamMessageEvent(
|
||||
Channel channel, Object message, SocketAddress remoteAddress) {
|
||||
|
||||
if (channel == null) {
|
||||
throw new NullPointerException("channel");
|
||||
}
|
||||
if (future == null) {
|
||||
throw new NullPointerException("future");
|
||||
if (message == null) {
|
||||
throw new NullPointerException("message");
|
||||
}
|
||||
this.channel = channel;
|
||||
this.future = future;
|
||||
this.message = message;
|
||||
this.remoteAddress = remoteAddress;
|
||||
}
|
||||
|
||||
public final Channel getChannel() {
|
||||
public Channel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public final ChannelFuture getFuture() {
|
||||
return future;
|
||||
public ChannelFuture getFuture() {
|
||||
return succeededFuture(getChannel());
|
||||
}
|
||||
|
||||
public Object getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public SocketAddress getRemoteAddress() {
|
||||
return remoteAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link String} representation of this event.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return channel.toString();
|
||||
if (remoteAddress == null) {
|
||||
return super.toString() + " - (received: " + message + ')';
|
||||
} else {
|
||||
return super.toString() + " - (received: " + message + ", " + remoteAddress + ')';
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user