Optimized DefaultChannelPipeline.write(...)

- Also replaced unnecessary function calls with field accesses
This commit is contained in:
Trustin Lee 2012-06-03 04:25:03 -07:00
parent f991a8c7d4
commit 13d7ee1b2f
3 changed files with 50 additions and 48 deletions

View File

@ -202,87 +202,87 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
@Override @Override
public ChannelFuture bind(SocketAddress localAddress) { public ChannelFuture bind(SocketAddress localAddress) {
return pipeline().bind(localAddress); return pipeline.bind(localAddress);
} }
@Override @Override
public ChannelFuture connect(SocketAddress remoteAddress) { public ChannelFuture connect(SocketAddress remoteAddress) {
return pipeline().connect(remoteAddress); return pipeline.connect(remoteAddress);
} }
@Override @Override
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) { public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) {
return pipeline().connect(remoteAddress, localAddress); return pipeline.connect(remoteAddress, localAddress);
} }
@Override @Override
public ChannelFuture disconnect() { public ChannelFuture disconnect() {
return pipeline().disconnect(); return pipeline.disconnect();
} }
@Override @Override
public ChannelFuture close() { public ChannelFuture close() {
return pipeline().close(); return pipeline.close();
} }
@Override @Override
public ChannelFuture deregister() { public ChannelFuture deregister() {
return pipeline().deregister(); return pipeline.deregister();
} }
@Override @Override
public ChannelFuture flush() { public ChannelFuture flush() {
return pipeline().flush(); return pipeline.flush();
} }
@Override @Override
public ChannelFuture write(Object message) { public ChannelFuture write(Object message) {
return pipeline().write(message); return pipeline.write(message);
} }
@Override @Override
public ChannelFuture bind(SocketAddress localAddress, ChannelFuture future) { public ChannelFuture bind(SocketAddress localAddress, ChannelFuture future) {
return pipeline().bind(localAddress, future); return pipeline.bind(localAddress, future);
} }
@Override @Override
public ChannelFuture connect(SocketAddress remoteAddress, ChannelFuture future) { public ChannelFuture connect(SocketAddress remoteAddress, ChannelFuture future) {
return pipeline().connect(remoteAddress, future); return pipeline.connect(remoteAddress, future);
} }
@Override @Override
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelFuture future) { public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelFuture future) {
return pipeline().connect(remoteAddress, localAddress, future); return pipeline.connect(remoteAddress, localAddress, future);
} }
@Override @Override
public ChannelFuture disconnect(ChannelFuture future) { public ChannelFuture disconnect(ChannelFuture future) {
return pipeline().disconnect(future); return pipeline.disconnect(future);
} }
@Override @Override
public ChannelFuture close(ChannelFuture future) { public ChannelFuture close(ChannelFuture future) {
return pipeline().close(future); return pipeline.close(future);
} }
@Override @Override
public ChannelFuture deregister(ChannelFuture future) { public ChannelFuture deregister(ChannelFuture future) {
return pipeline().deregister(future); return pipeline.deregister(future);
} }
@Override @Override
public ChannelBuffer outboundByteBuffer() { public ChannelBuffer outboundByteBuffer() {
return pipeline().outboundByteBuffer(); return pipeline.outboundByteBuffer();
} }
@Override @Override
public Queue<Object> outboundMessageBuffer() { public Queue<Object> outboundMessageBuffer() {
return pipeline().outboundMessageBuffer(); return pipeline.outboundMessageBuffer();
} }
@Override @Override
public ChannelFuture flush(ChannelFuture future) { public ChannelFuture flush(ChannelFuture future) {
return pipeline().flush(future); return pipeline.flush(future);
} }
@Override @Override
@ -427,9 +427,9 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
doRegister(); doRegister();
registered = true; registered = true;
future.setSuccess(); future.setSuccess();
pipeline().fireChannelRegistered(); pipeline.fireChannelRegistered();
if (isActive()) { if (isActive()) {
pipeline().fireChannelActive(); pipeline.fireChannelActive();
} }
} catch (Throwable t) { } catch (Throwable t) {
// Close the channel directly to avoid FD leak. // Close the channel directly to avoid FD leak.
@ -440,7 +440,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
} }
future.setFailure(t); future.setFailure(t);
pipeline().fireExceptionCaught(t); pipeline.fireExceptionCaught(t);
closeFuture().setSuccess(); closeFuture().setSuccess();
} }
} }
@ -457,11 +457,11 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
doBind(localAddress); doBind(localAddress);
future.setSuccess(); future.setSuccess();
if (!wasActive && isActive()) { if (!wasActive && isActive()) {
pipeline().fireChannelActive(); pipeline.fireChannelActive();
} }
} catch (Throwable t) { } catch (Throwable t) {
future.setFailure(t); future.setFailure(t);
pipeline().fireExceptionCaught(t); pipeline.fireExceptionCaught(t);
closeIfClosed(); closeIfClosed();
} }
} else { } else {
@ -482,7 +482,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
doDisconnect(); doDisconnect();
future.setSuccess(); future.setSuccess();
if (wasActive && !isActive()) { if (wasActive && !isActive()) {
pipeline().fireChannelInactive(); pipeline.fireChannelInactive();
} }
} catch (Throwable t) { } catch (Throwable t) {
future.setFailure(t); future.setFailure(t);
@ -517,7 +517,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
notifyFlushFutures(closedChannelException); notifyFlushFutures(closedChannelException);
if (wasActive && !isActive()) { if (wasActive && !isActive()) {
pipeline().fireChannelInactive(); pipeline.fireChannelInactive();
} }
deregister(voidFuture()); deregister(voidFuture());
@ -551,7 +551,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
if (registered) { if (registered) {
registered = false; registered = false;
future.setSuccess(); future.setSuccess();
pipeline().fireChannelUnregistered(); pipeline.fireChannelUnregistered();
} else { } else {
// Some transports like local and AIO does not allow the deregistration of // Some transports like local and AIO does not allow the deregistration of
// an open channel. Their doDeregister() calls close(). Consequently, // an open channel. Their doDeregister() calls close(). Consequently,
@ -593,7 +593,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
} }
} catch (Throwable t) { } catch (Throwable t) {
notifyFlushFutures(t); notifyFlushFutures(t);
pipeline().fireExceptionCaught(t); pipeline.fireExceptionCaught(t);
if (t instanceof IOException) { if (t instanceof IOException) {
close(voidFuture()); close(voidFuture());
} }
@ -645,7 +645,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
notifyFlushFutures(); notifyFlushFutures();
} else { } else {
notifyFlushFutures(cause); notifyFlushFutures(cause);
pipeline().fireExceptionCaught(cause); pipeline.fireExceptionCaught(cause);
if (cause instanceof IOException) { if (cause instanceof IOException) {
close(voidFuture()); close(voidFuture());
} }
@ -662,7 +662,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
Exception e = new ClosedChannelException(); Exception e = new ClosedChannelException();
future.setFailure(e); future.setFailure(e);
pipeline().fireExceptionCaught(e); pipeline.fireExceptionCaught(e);
return false; return false;
} }

View File

@ -357,7 +357,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
@Override @Override
public ChannelFuture write(Object message, ChannelFuture future) { public ChannelFuture write(Object message, ChannelFuture future) {
return pipeline.write(DefaultChannelPipeline.nextOutboundContext(prev), message, future); return pipeline.write(prev, message, future);
} }
@Override @Override

View File

@ -887,42 +887,42 @@ public class DefaultChannelPipeline implements ChannelPipeline {
@Override @Override
public ChannelFuture bind(SocketAddress localAddress) { public ChannelFuture bind(SocketAddress localAddress) {
return bind(localAddress, channel().newFuture()); return bind(localAddress, channel.newFuture());
} }
@Override @Override
public ChannelFuture connect(SocketAddress remoteAddress) { public ChannelFuture connect(SocketAddress remoteAddress) {
return connect(remoteAddress, channel().newFuture()); return connect(remoteAddress, channel.newFuture());
} }
@Override @Override
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) { public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) {
return connect(remoteAddress, localAddress, channel().newFuture()); return connect(remoteAddress, localAddress, channel.newFuture());
} }
@Override @Override
public ChannelFuture disconnect() { public ChannelFuture disconnect() {
return disconnect(channel().newFuture()); return disconnect(channel.newFuture());
} }
@Override @Override
public ChannelFuture close() { public ChannelFuture close() {
return close(channel().newFuture()); return close(channel.newFuture());
} }
@Override @Override
public ChannelFuture deregister() { public ChannelFuture deregister() {
return deregister(channel().newFuture()); return deregister(channel.newFuture());
} }
@Override @Override
public ChannelFuture flush() { public ChannelFuture flush() {
return flush(channel().newFuture()); return flush(channel.newFuture());
} }
@Override @Override
public ChannelFuture write(Object message) { public ChannelFuture write(Object message) {
return write(message, channel().newFuture()); return write(message, channel.newFuture());
} }
@Override @Override
@ -1128,7 +1128,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
@Override @Override
public ChannelFuture write(Object message, ChannelFuture future) { public ChannelFuture write(Object message, ChannelFuture future) {
return write(firstOutboundContext(), message, future); return write(tail, message, future);
} }
ChannelFuture write(DefaultChannelHandlerContext ctx, final Object message, final ChannelFuture future) { ChannelFuture write(DefaultChannelHandlerContext ctx, final Object message, final ChannelFuture future) {
@ -1156,6 +1156,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
break; break;
} }
if (ctx.canHandleOutbound()) {
out = ctx.outbound(); out = ctx.outbound();
if (out.hasMessageBuffer()) { if (out.hasMessageBuffer()) {
msgBuf = true; msgBuf = true;
@ -1165,6 +1166,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
executor = ctx.executor(); executor = ctx.executor();
break; break;
} }
}
ctx = ctx.prev; ctx = ctx.prev;
} }
@ -1199,9 +1201,9 @@ public class DefaultChannelPipeline implements ChannelPipeline {
if (future == null) { if (future == null) {
throw new NullPointerException("future"); throw new NullPointerException("future");
} }
if (future.channel() != channel()) { if (future.channel() != channel) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"future.channel does not match: %s (expected: %s)", future.channel(), channel())); "future.channel does not match: %s (expected: %s)", future.channel(), channel));
} }
if (future.isDone()) { if (future.isDone()) {
throw new IllegalArgumentException("future already done"); throw new IllegalArgumentException("future already done");