Last active
June 2, 2021 15:06
-
-
Save normanmaurer/e3065fa033cfcea30c3b12782750428d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IoResultCallback { | |
void onSuccess(); | |
void onError(Throwable cause); | |
default ChannelFutureListener asChannelFutureListener() { | |
// Implement me | |
} | |
static IoResultCallback noop() { | |
return ...; | |
} | |
} | |
public interface ChannelPromise { | |
... | |
IoResultCallback asIoResultCallback(); | |
} | |
public interface ChannelHandlerContext { | |
.... | |
ChannelHandlerContext write(Object msg, IoResultCallback callback); | |
ChannellFuture write(Object msg); | |
ChannelHandlerContext flush(IoResultCallback callback); | |
ChannellFuture flush(); | |
ChannelHandlerContext read(IoResultCallback callback); | |
ChannellFuture read(); | |
} | |
public interface ChannelHandler { | |
default void write(ChannelHandlerContext ctx, Object msg, IoResultCallback callback) { | |
ctx.write(msg, callback); | |
} | |
default void flush(ChannelHandlerContext ctx, IoResultCallback callback) { | |
ctx.flush(callback); | |
} | |
default void read(ChannelHandlerContext ctx, IoResultCallback callback) { | |
ctx.read(callback); | |
} | |
} | |
public class NoListenerNeededExample implements ChannelHandler { | |
@Override | |
public void write(ChannelHandlerContext ctx, Object msg, IoResultCallback callback) { | |
... | |
ctx.write(msg, callback); | |
} | |
} | |
public class ListenerNeededExample implements ChannelHandler { | |
@Override | |
public void write(ChannelHandlerContext ctx, Object msg, IoResultCallback callback) { | |
ctx.write(msg).addListener(callback.asChannelFutureListener()); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment