use of com.baidu.hugegraph.computer.core.network.message.MessageType in project hugegraph-computer by hugegraph.
the class AbstractNettyHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
Channel channel = ctx.channel();
if (LOG.isDebugEnabled()) {
LOG.debug("Receive remote message from '{}', message: {}", TransportUtil.remoteAddress(channel), msg);
}
MessageType msgType = msg.type();
if (msgType.category() == MessageType.Category.DATA) {
this.processDataMessage(ctx, channel, (DataMessage) msg);
return;
}
switch(msgType) {
case START:
this.processStartMessage(ctx, channel, (StartMessage) msg);
break;
case FAIL:
this.processFailMessage(ctx, channel, (FailMessage) msg);
break;
case ACK:
this.processAckMessage(ctx, channel, (AckMessage) msg);
break;
case FINISH:
this.processFinishMessage(ctx, channel, (FinishMessage) msg);
break;
case PING:
this.processPingMessage(ctx, channel, (PingMessage) msg);
break;
case PONG:
this.processPongMessage(ctx, channel, (PongMessage) msg);
break;
default:
throw new IllegalArgException("Unknown message type: %s", msgType);
}
}
use of com.baidu.hugegraph.computer.core.network.message.MessageType 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.MessageType in project hugegraph-computer by hugegraph.
the class NettyTransportClientTest method testDataUniformity.
@Test
public void testDataUniformity() throws IOException {
NettyTransportClient client = (NettyTransportClient) this.oneClient();
byte[] sourceBytes1 = StringEncoding.encode("test data message");
byte[] sourceBytes2 = StringEncoding.encode("test data edge");
byte[] sourceBytes3 = StringEncoding.encode("test data vertex");
Mockito.doAnswer(invocationOnMock -> {
MessageType type = invocationOnMock.getArgument(0);
NetworkBuffer buffer = invocationOnMock.getArgument(2);
byte[] sourceBytes = null;
switch(type) {
case MSG:
sourceBytes = sourceBytes1;
break;
case EDGE:
sourceBytes = sourceBytes2;
break;
case VERTEX:
sourceBytes = sourceBytes3;
break;
default:
}
byte[] bytes;
if (buffer instanceof FileRegionBuffer) {
String path = ((FileRegionBuffer) buffer).path();
File file = new File(path);
bytes = FileUtils.readFileToByteArray(file);
FileUtils.deleteQuietly(file);
} else {
bytes = buffer.copyToByteArray();
}
Assert.assertArrayEquals(sourceBytes, bytes);
Assert.assertNotSame(sourceBytes, bytes);
return null;
}).when(serverHandler).handle(Mockito.any(), Mockito.eq(1), Mockito.any());
client.startSession();
client.send(MessageType.MSG, 1, ByteBuffer.wrap(sourceBytes1));
client.send(MessageType.EDGE, 1, ByteBuffer.wrap(sourceBytes2));
client.send(MessageType.VERTEX, 1, ByteBuffer.wrap(sourceBytes3));
client.finishSession();
}
Aggregations