private Futures.WriteFuture write(NioChannel channel, Object msg, boolean flush) {

        Futures.WriteFuture future = Futures.newWriteFuture();

        if (msg == null) {
            future.setSuccess(true);
            future.setMsg("msg is null");
            future.notifyListeners();
            return future;
        }
        ByteBuffer buf = null;
        try {
            buf = channel.getEncoder().encode(channel, msg);
            if (buf == null) {
                future.setSuccess(false);
                future.setMsg("encode msg error");
                future.notifyListeners();
                return future;
            }
            QUEUE_MAP.get(channel).offer(new WriteRequest(buf, future));
        } catch (Exception e) {
            throw new NioException("encode msg " + msg + " error", e);
        }
        if (flush) {
            doFlush(channel);
        }
        return future;
    }
@author Robert HG (254963746@qq.com) on 1/24/16.
lts-core/src/main/java/com/github/ltsopensource/nio/processor/AbstractNioProcessor.java