All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.andyshao.io.UnblockingMessageFactory Maven / Gradle / Ivy

The newest version!
package com.github.andyshao.io;

import java.nio.ByteBuffer;

import com.github.andyshao.nio.ByteBufferOperation;

/**
 * 
 * Title:
* Descript:
* Copyright: Copryright(c) Nov 9, 2015
* Encoding:UNIX UTF-8 * * @author Andy.Shao * */ public interface UnblockingMessageFactory extends MessageFactory { @Override public default MessageWritable buildMessageWritable(MessageContext context) { return (channel , ctxt) -> { final byte[] writeBytes = (byte[]) ctxt.get(MessageContext.OUTPUT_MESSAGE_BYTES); if (writeBytes.length == 0) { ctxt.put(MessageContext.IS_WAITING_FOR_SENDING , false); return; } final ByteBuffer writeBuffer = ByteBuffer.wrap(writeBytes); channel.write(writeBuffer); if (writeBuffer.hasRemaining()) ctxt.put(MessageContext.OUTPUT_MESSAGE_BYTES , ByteBufferOperation.usedArray(writeBuffer)); else ctxt.put(MessageContext.IS_WAITING_FOR_SENDING , false); }; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy