use of com.baidu.hugegraph.computer.core.network.message.Message in project hugegraph-computer by hugegraph.
the class MessageDecoder method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ByteBuf buf = (ByteBuf) msg;
Message message;
try {
MessageType msgType = MessageType.decode(buf);
message = this.decode(ctx, msgType, buf);
if (message == null) {
return;
}
} finally {
buf.release();
}
ctx.fireChannelRead(message);
}
use of com.baidu.hugegraph.computer.core.network.message.Message in project hugegraph-computer by hugegraph.
the class NettyTransportClientTest method testFlowControl.
@Test
public void testFlowControl() throws IOException {
ByteBuffer buffer = ByteBuffer.wrap(StringEncoding.encode("test data"));
NettyTransportClient client = (NettyTransportClient) this.oneClient();
client.startSession();
Object sendFuncBak = Whitebox.getInternalState(client.clientSession(), "sendFunction");
Function<Message, ChannelFuture> sendFunc = message -> null;
Whitebox.setInternalState(client.clientSession(), "sendFunction", sendFunc);
for (int i = 1; i <= conf.maxPendingRequests() * 2; i++) {
boolean send = client.send(MessageType.MSG, 1, buffer);
if (i <= conf.maxPendingRequests()) {
Assert.assertTrue(send);
} else {
Assert.assertFalse(send);
}
}
int maxRequestId = Whitebox.getInternalState(client.clientSession(), "maxRequestId");
int maxAckId = Whitebox.getInternalState(client.clientSession(), "maxAckId");
Assert.assertEquals(conf.maxPendingRequests(), maxRequestId);
Assert.assertEquals(0, maxAckId);
int pendings = conf.maxPendingRequests() - conf.minPendingRequests();
for (int i = 1; i <= pendings + 1; i++) {
Assert.assertFalse(client.checkSendAvailable());
client.clientSession().onRecvAck(i);
}
Assert.assertTrue(client.checkSendAvailable());
maxAckId = Whitebox.getInternalState(client.clientSession(), "maxAckId");
Assert.assertEquals(pendings + 1, maxAckId);
Whitebox.setInternalState(client.clientSession(), "sendFunction", sendFuncBak);
}
use of com.baidu.hugegraph.computer.core.network.message.Message in project hugegraph-computer by hugegraph.
the class SenderIntegrateTest method slowSendFunc.
private void slowSendFunc(WorkerService service) throws TransportException {
Managers managers = Whitebox.getInternalState(service, "managers");
DataClientManager clientManager = managers.get(DataClientManager.NAME);
ConnectionManager connManager = Whitebox.getInternalState(clientManager, "connManager");
NettyTransportClient client = (NettyTransportClient) connManager.getOrCreateClient("127.0.0.1", 8091);
ClientSession clientSession = Whitebox.invoke(client.getClass(), "clientSession", client);
Function<Message, Future<Void>> sendFuncBak = Whitebox.getInternalState(clientSession, "sendFunction");
Function<Message, Future<Void>> sendFunc = message -> {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
return sendFuncBak.apply(message);
};
Whitebox.setInternalState(clientSession, "sendFunction", sendFunc);
}
use of com.baidu.hugegraph.computer.core.network.message.Message in project hugegraph-computer by hugegraph.
the class MessageEncoder method write.
@Override
public void write(ChannelHandlerContext ctx, Object obj, ChannelPromise promise) throws Exception {
if (obj instanceof Message) {
Message message = (Message) obj;
this.writeMessage(ctx, message, promise, ctx.alloc());
} else {
ctx.write(obj, promise);
}
}
Aggregations