com.github.andyshao.io.UnblockingMessageFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Gear Show documentation
Show all versions of Gear Show documentation
Enhance and formating the coding of JDK
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