Fix a weird compilation error in DefaultChannelPipeline

probably a compiler bug - working around
This commit is contained in:
Trustin Lee 2012-06-08 10:57:38 +09:00
parent 748de5ea83
commit 8970ee751c

View File

@ -93,14 +93,12 @@ public class DefaultChannelPipeline implements ChannelPipeline {
addFirst0(name, nextCtx, newCtx); addFirst0(name, nextCtx, newCtx);
return this; return this;
} }
future = newCtx.executor().submit(new AsyncPipelineModification() { future = newCtx.executor().submit(new AsyncPipelineModification(this) {
@Override @Override
void doCall() { void doCall() {
checkDuplicateName(name); checkDuplicateName(name);
addFirst0(name, nextCtx, newCtx); addFirst0(name, nextCtx, newCtx);
} }
}); });
} }
// Call Future.get() outside of the synchronized block to prevent dead-lock // Call Future.get() outside of the synchronized block to prevent dead-lock
@ -153,8 +151,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
addLast0(name, oldTail, newTail); addLast0(name, oldTail, newTail);
return this; return this;
} else { } else {
future = newTail.executor().submit(new AsyncPipelineModification() { future = newTail.executor().submit(new AsyncPipelineModification(this) {
@Override @Override
void doCall() { void doCall() {
checkDuplicateName(name); checkDuplicateName(name);
@ -210,15 +207,13 @@ public class DefaultChannelPipeline implements ChannelPipeline {
addBefore0(name, ctx, newCtx); addBefore0(name, ctx, newCtx);
return this; return this;
} else { } else {
future = newCtx.executor().submit(new AsyncPipelineModification() { future = newCtx.executor().submit(new AsyncPipelineModification(this) {
@Override @Override
void doCall() { void doCall() {
checkDuplicateName(name); checkDuplicateName(name);
addBefore0(name, ctx, newCtx); addBefore0(name, ctx, newCtx);
} }
}); });
} }
} }
@ -273,8 +268,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
addAfter0(name, ctx, newCtx); addAfter0(name, ctx, newCtx);
return this; return this;
} else { } else {
future = newCtx.executor().submit(new AsyncPipelineModification() { future = newCtx.executor().submit(new AsyncPipelineModification(this) {
@Override @Override
void doCall() { void doCall() {
checkDuplicateName(name); checkDuplicateName(name);
@ -407,8 +401,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
removeLast0(oldTail); removeLast0(oldTail);
return oldTail; return oldTail;
} else { } else {
future = oldTail.executor().submit(new AsyncPipelineModification() { future = oldTail.executor().submit(new AsyncPipelineModification(this) {
@Override @Override
void doCall() { void doCall() {
removeLast0(oldTail); removeLast0(oldTail);
@ -422,13 +415,11 @@ public class DefaultChannelPipeline implements ChannelPipeline {
remove0(ctx); remove0(ctx);
return ctx; return ctx;
} else { } else {
future = ctx.executor().submit(new AsyncPipelineModification() { future = ctx.executor().submit(new AsyncPipelineModification(this) {
@Override @Override
void doCall() { void doCall() {
remove0(ctx); remove0(ctx);
} }
}); });
context = ctx; context = ctx;
} }
@ -487,13 +478,12 @@ public class DefaultChannelPipeline implements ChannelPipeline {
removeLast0(oldTail); removeLast0(oldTail);
return oldTail.handler(); return oldTail.handler();
} else { } else {
future = oldTail.executor().submit(new AsyncPipelineModification() { future = oldTail.executor().submit(new AsyncPipelineModification(this) {
@Override @Override
void doCall() { void doCall() {
removeLast0(oldTail); removeLast0(oldTail);
} }
}); });
} }
} }
// Call Future.get() outside of synchronized block to prevent dead-lock // Call Future.get() outside of synchronized block to prevent dead-lock
@ -562,8 +552,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
return ctx.handler(); return ctx.handler();
} else { } else {
future = oldTail.executor().submit(new AsyncPipelineModification() { future = oldTail.executor().submit(new AsyncPipelineModification(this) {
@Override @Override
void doCall() { void doCall() {
removeLast0(oldTail); removeLast0(oldTail);
@ -588,13 +577,11 @@ public class DefaultChannelPipeline implements ChannelPipeline {
replace0(ctx, newName, newCtx); replace0(ctx, newName, newCtx);
return ctx.handler(); return ctx.handler();
} else { } else {
future = newCtx.executor().submit(new AsyncPipelineModification() { future = newCtx.executor().submit(new AsyncPipelineModification(this) {
@Override @Override
void doCall() { void doCall() {
replace0(ctx, newName, newCtx); replace0(ctx, newName, newCtx);
} }
}); });
} }
} }
@ -1705,20 +1692,31 @@ public class DefaultChannelPipeline implements ChannelPipeline {
ctx.fireUserEventTriggered(evt); ctx.fireUserEventTriggered(evt);
} }
} }
}
/** /**
* Custom {@link Callable} implementation which will catch all {@link Throwable} which happens during execution of {@link AsyncPipelineModification#doCall()} * Custom {@link Callable} implementation which will catch all {@link Throwable} which happens
* and return them in the {@link Future}. This allows to re-throw them later. * during execution of {@link AsyncPipelineModification#doCall()} and return them in the
* {@link Future}. This allows to re-throw them later.
* *
* It also handles the right synchronization of the {@link AsyncPipelineModification#doCall()} method. * It also handles the right synchronization of the {@link AsyncPipelineModification#doCall()}
* method.
* *
* It was originally an inner class of {@link DefaultChannelPipeline}, but moved to a top level
* type to work around a compiler bug.
*/ */
private abstract class AsyncPipelineModification implements Callable<Throwable> { abstract class AsyncPipelineModification implements Callable<Throwable> {
private final ChannelPipeline lock;
AsyncPipelineModification(ChannelPipeline lock) {
this.lock = lock;
}
@Override @Override
public Throwable call() { public Throwable call() {
try { try {
synchronized (DefaultChannelPipeline.this) { synchronized (lock) {
doCall(); doCall();
} }
} catch (Throwable t) { } catch (Throwable t) {
@ -1733,4 +1731,3 @@ public class DefaultChannelPipeline implements ChannelPipeline {
abstract void doCall(); abstract void doCall();
} }
}