}
};
@Override
public final void completed(final V result, final A channel) {
EventLoop loop = channel.eventLoop();
if (loop.inEventLoop()) {
Integer d = STACK_DEPTH.get();
if (d < MAX_STACK_DEPTH) {
STACK_DEPTH.set(d + 1);
try {
completed0(result, channel);
} finally {
STACK_DEPTH.set(d);
}
} else {
// schedule it with a special runnable to make sure we keep the right
// order and exist the recursive call to prevent stackoverflow
loop.execute(new AioEventLoop.RecursionBreakingRunnable() {
@Override
public void run() {
completed0(result, channel);
}
});
}
} else {
loop.execute(new Runnable() {
@Override
public void run() {
completed0(result, channel);
}
});