Fix a weird compilation error in DefaultChannelPipeline
probably a compiler bug - working around
This commit is contained in:
parent
748de5ea83
commit
8970ee751c
@ -93,14 +93,12 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
addFirst0(name, nextCtx, newCtx);
|
||||
return this;
|
||||
}
|
||||
future = newCtx.executor().submit(new AsyncPipelineModification() {
|
||||
|
||||
future = newCtx.executor().submit(new AsyncPipelineModification(this) {
|
||||
@Override
|
||||
void doCall() {
|
||||
checkDuplicateName(name);
|
||||
addFirst0(name, nextCtx, newCtx);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
// 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);
|
||||
return this;
|
||||
} else {
|
||||
future = newTail.executor().submit(new AsyncPipelineModification() {
|
||||
|
||||
future = newTail.executor().submit(new AsyncPipelineModification(this) {
|
||||
@Override
|
||||
void doCall() {
|
||||
checkDuplicateName(name);
|
||||
@ -210,15 +207,13 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
addBefore0(name, ctx, newCtx);
|
||||
return this;
|
||||
} else {
|
||||
future = newCtx.executor().submit(new AsyncPipelineModification() {
|
||||
|
||||
future = newCtx.executor().submit(new AsyncPipelineModification(this) {
|
||||
@Override
|
||||
void doCall() {
|
||||
checkDuplicateName(name);
|
||||
addBefore0(name, ctx, newCtx);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,8 +268,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
addAfter0(name, ctx, newCtx);
|
||||
return this;
|
||||
} else {
|
||||
future = newCtx.executor().submit(new AsyncPipelineModification() {
|
||||
|
||||
future = newCtx.executor().submit(new AsyncPipelineModification(this) {
|
||||
@Override
|
||||
void doCall() {
|
||||
checkDuplicateName(name);
|
||||
@ -407,8 +401,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
removeLast0(oldTail);
|
||||
return oldTail;
|
||||
} else {
|
||||
future = oldTail.executor().submit(new AsyncPipelineModification() {
|
||||
|
||||
future = oldTail.executor().submit(new AsyncPipelineModification(this) {
|
||||
@Override
|
||||
void doCall() {
|
||||
removeLast0(oldTail);
|
||||
@ -422,14 +415,12 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
remove0(ctx);
|
||||
return ctx;
|
||||
} else {
|
||||
future = ctx.executor().submit(new AsyncPipelineModification() {
|
||||
|
||||
@Override
|
||||
void doCall() {
|
||||
remove0(ctx);
|
||||
}
|
||||
|
||||
});
|
||||
future = ctx.executor().submit(new AsyncPipelineModification(this) {
|
||||
@Override
|
||||
void doCall() {
|
||||
remove0(ctx);
|
||||
}
|
||||
});
|
||||
context = ctx;
|
||||
}
|
||||
}
|
||||
@ -487,13 +478,12 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
removeLast0(oldTail);
|
||||
return oldTail.handler();
|
||||
} else {
|
||||
future = oldTail.executor().submit(new AsyncPipelineModification() {
|
||||
future = oldTail.executor().submit(new AsyncPipelineModification(this) {
|
||||
@Override
|
||||
void doCall() {
|
||||
removeLast0(oldTail);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
// Call Future.get() outside of synchronized block to prevent dead-lock
|
||||
@ -562,15 +552,14 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
return ctx.handler();
|
||||
|
||||
} else {
|
||||
future = oldTail.executor().submit(new AsyncPipelineModification() {
|
||||
|
||||
@Override
|
||||
void doCall() {
|
||||
removeLast0(oldTail);
|
||||
checkDuplicateName(newName);
|
||||
addLast0(newName, tail, newTail);
|
||||
}
|
||||
});
|
||||
future = oldTail.executor().submit(new AsyncPipelineModification(this) {
|
||||
@Override
|
||||
void doCall() {
|
||||
removeLast0(oldTail);
|
||||
checkDuplicateName(newName);
|
||||
addLast0(newName, tail, newTail);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -588,13 +577,11 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
replace0(ctx, newName, newCtx);
|
||||
return ctx.handler();
|
||||
} else {
|
||||
future = newCtx.executor().submit(new AsyncPipelineModification() {
|
||||
|
||||
future = newCtx.executor().submit(new AsyncPipelineModification(this) {
|
||||
@Override
|
||||
void doCall() {
|
||||
replace0(ctx, newName, newCtx);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1705,32 +1692,42 @@ public class DefaultChannelPipeline implements ChannelPipeline {
|
||||
ctx.fireUserEventTriggered(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom {@link Callable} implementation which will catch all {@link Throwable} which happens
|
||||
* 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 was originally an inner class of {@link DefaultChannelPipeline}, but moved to a top level
|
||||
* type to work around a compiler bug.
|
||||
*/
|
||||
abstract class AsyncPipelineModification implements Callable<Throwable> {
|
||||
|
||||
private final ChannelPipeline lock;
|
||||
|
||||
AsyncPipelineModification(ChannelPipeline lock) {
|
||||
this.lock = lock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable call() {
|
||||
try {
|
||||
synchronized (lock) {
|
||||
doCall();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
return t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom {@link Callable} implementation which will catch all {@link Throwable} which happens 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.
|
||||
*
|
||||
* Execute the modification
|
||||
*/
|
||||
private abstract class AsyncPipelineModification implements Callable<Throwable> {
|
||||
abstract void doCall();
|
||||
|
||||
@Override
|
||||
public Throwable call() {
|
||||
try {
|
||||
synchronized (DefaultChannelPipeline.this) {
|
||||
doCall();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
return t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the modification
|
||||
*/
|
||||
abstract void doCall();
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user