@Override public Task write(final HandlerContext ctx, final Object msg) throws Exception { if (!(msg instanceof Pair)) { return ctx.write(msg); } Pair<NodeAddress, byte[]> message = (Pair<NodeAddress, byte[]>) msg; clusterPeer.sendMessage(message.getLeft(), message.getRight()); return Task.done(); }
@Override public Task close(final HandlerContext ctx) throws Exception { clusterPeer.leave(); return super.close(ctx); }
@Override public Task connect(final HandlerContext ctx, final Object param) throws Exception { clusterPeer.registerMessageReceiver((n, m) -> ctx.fireRead(Pair.of(n, m))); return clusterPeer.join(clusterName, nodeName).thenRun(() -> ctx.fireActive()); }