Remove unnecessary reference to AbstractChannel from AbstractChannelHandlerContext

Motivation:

We not need to store another reference to AbstractChannel as we can access it through DefaultChannelHandlerContext.

Modifications:

Remove reference.

Result:

Cleaner code.
This commit is contained in:
Norman Maurer 2015-11-16 11:49:45 -08:00
parent d6c23d0af9
commit 19950f89e4

View File

@ -46,7 +46,6 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap impleme
private final boolean inbound; private final boolean inbound;
private final boolean outbound; private final boolean outbound;
private final AbstractChannel channel;
private final DefaultChannelPipeline pipeline; private final DefaultChannelPipeline pipeline;
private final String name; private final String name;
private boolean removed; private boolean removed;
@ -71,7 +70,6 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap impleme
throw new NullPointerException("name"); throw new NullPointerException("name");
} }
channel = pipeline.channel;
this.pipeline = pipeline; this.pipeline = pipeline;
this.name = name; this.name = name;
@ -94,7 +92,7 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap impleme
@Override @Override
public Channel channel() { public Channel channel() {
return channel; return pipeline.channel();
} }
@Override @Override
@ -662,7 +660,7 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap impleme
} }
}; };
} }
safeExecute(executor, task, channel.voidPromise(), null); safeExecute(executor, task, channel().voidPromise(), null);
} }
return this; return this;
@ -837,7 +835,7 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap impleme
@Override @Override
public ChannelPromise voidPromise() { public ChannelPromise voidPromise() {
return channel.voidPromise(); return channel().voidPromise();
} }
void setRemoved() { void setRemoved() {
@ -965,9 +963,9 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap impleme
task.ctx = ctx; task.ctx = ctx;
task.msg = msg; task.msg = msg;
task.promise = promise; task.promise = promise;
task.size = ctx.channel.estimatorHandle().size(msg) + estimateSize(task, CLASS_SIZES.get()); task.size = ctx.pipeline.channel.estimatorHandle().size(msg) + estimateSize(task, CLASS_SIZES.get());
ChannelOutboundBuffer buffer = ctx.channel.unsafe().outboundBuffer(); ChannelOutboundBuffer buffer = ctx.channel().unsafe().outboundBuffer();
// Check for null as it may be set to null if the channel is closed already // Check for null as it may be set to null if the channel is closed already
if (buffer != null) { if (buffer != null) {
buffer.incrementPendingOutboundBytes(task.size); buffer.incrementPendingOutboundBytes(task.size);
@ -978,7 +976,7 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap impleme
public final void run() { public final void run() {
try { try {
if (size > 0) { if (size > 0) {
ChannelOutboundBuffer buffer = ctx.channel.unsafe().outboundBuffer(); ChannelOutboundBuffer buffer = ctx.channel().unsafe().outboundBuffer();
// Check for null as it may be set to null if the channel is closed already // Check for null as it may be set to null if the channel is closed already
if (buffer != null) { if (buffer != null) {
buffer.decrementPendingOutboundBytes(size); buffer.decrementPendingOutboundBytes(size);