ChannelFuture (@NotNull ByteBuf message) { if (channel.isOpen()) { ByteBuf lengthBuffer = channel.alloc().ioBuffer(4); lengthBuffer.writeInt(message.readableBytes()); channel.write(lengthBuffer); return channel.writeAndFlush(message); } else { return channel.newFailedFuture(new ClosedChannelException()); } }