Search in sources :

Example 1 with Message

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);
}
Also used : StartMessage(com.baidu.hugegraph.computer.core.network.message.StartMessage) PongMessage(com.baidu.hugegraph.computer.core.network.message.PongMessage) AckMessage(com.baidu.hugegraph.computer.core.network.message.AckMessage) PingMessage(com.baidu.hugegraph.computer.core.network.message.PingMessage) FinishMessage(com.baidu.hugegraph.computer.core.network.message.FinishMessage) DataMessage(com.baidu.hugegraph.computer.core.network.message.DataMessage) Message(com.baidu.hugegraph.computer.core.network.message.Message) ByteBuf(io.netty.buffer.ByteBuf) MessageType(com.baidu.hugegraph.computer.core.network.message.MessageType)

Example 2 with 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);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ComputerOptions(com.baidu.hugegraph.computer.core.config.ComputerOptions) NetworkBuffer(com.baidu.hugegraph.computer.core.network.buffer.NetworkBuffer) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) Future(java.util.concurrent.Future) Whitebox(com.baidu.hugegraph.testutil.Whitebox) FileRegionBuffer(com.baidu.hugegraph.computer.core.network.buffer.FileRegionBuffer) UnitTestBase(com.baidu.hugegraph.computer.suite.unit.UnitTestBase) StringEncoding(com.baidu.hugegraph.computer.core.util.StringEncoding) TransportException(com.baidu.hugegraph.computer.core.common.exception.TransportException) Message(com.baidu.hugegraph.computer.core.network.message.Message) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) File(java.io.File) TransportConf(com.baidu.hugegraph.computer.core.network.TransportConf) ChannelFuture(io.netty.channel.ChannelFuture) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Channel(io.netty.channel.Channel) Mockito(org.mockito.Mockito) Bytes(com.baidu.hugegraph.util.Bytes) MessageType(com.baidu.hugegraph.computer.core.network.message.MessageType) Assert(com.baidu.hugegraph.testutil.Assert) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) Message(com.baidu.hugegraph.computer.core.network.message.Message) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with Message

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);
}
Also used : PageRankParams(com.baidu.hugegraph.computer.algorithm.centrality.pagerank.PageRankParams) ComputerOptions(com.baidu.hugegraph.computer.core.config.ComputerOptions) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) BeforeClass(org.junit.BeforeClass) Managers(com.baidu.hugegraph.computer.core.manager.Managers) RpcOptions(com.baidu.hugegraph.config.RpcOptions) Function(java.util.function.Function) MasterService(com.baidu.hugegraph.computer.core.master.MasterService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Whitebox(com.baidu.hugegraph.testutil.Whitebox) TransportException(com.baidu.hugegraph.computer.core.common.exception.TransportException) ComputerContextUtil(com.baidu.hugegraph.computer.core.util.ComputerContextUtil) Message(com.baidu.hugegraph.computer.core.network.message.Message) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) ConnectionManager(com.baidu.hugegraph.computer.core.network.connection.ConnectionManager) Test(org.junit.Test) NettyTransportClient(com.baidu.hugegraph.computer.core.network.netty.NettyTransportClient) ClientSession(com.baidu.hugegraph.computer.core.network.session.ClientSession) Config(com.baidu.hugegraph.computer.core.config.Config) DataClientManager(com.baidu.hugegraph.computer.core.network.DataClientManager) List(java.util.List) Log(com.baidu.hugegraph.util.Log) WorkerService(com.baidu.hugegraph.computer.core.worker.WorkerService) Assert(com.baidu.hugegraph.testutil.Assert) ConnectionManager(com.baidu.hugegraph.computer.core.network.connection.ConnectionManager) Message(com.baidu.hugegraph.computer.core.network.message.Message) Managers(com.baidu.hugegraph.computer.core.manager.Managers) DataClientManager(com.baidu.hugegraph.computer.core.network.DataClientManager) NettyTransportClient(com.baidu.hugegraph.computer.core.network.netty.NettyTransportClient) ClientSession(com.baidu.hugegraph.computer.core.network.session.ClientSession) Future(java.util.concurrent.Future)

Example 4 with Message

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);
    }
}
Also used : AbstractMessage(com.baidu.hugegraph.computer.core.network.message.AbstractMessage) Message(com.baidu.hugegraph.computer.core.network.message.Message)

Aggregations

Message (com.baidu.hugegraph.computer.core.network.message.Message)4 TransportException (com.baidu.hugegraph.computer.core.common.exception.TransportException)2 ComputerOptions (com.baidu.hugegraph.computer.core.config.ComputerOptions)2 MessageType (com.baidu.hugegraph.computer.core.network.message.MessageType)2 Assert (com.baidu.hugegraph.testutil.Assert)2 Whitebox (com.baidu.hugegraph.testutil.Whitebox)2 Future (java.util.concurrent.Future)2 Function (java.util.function.Function)2 Test (org.junit.Test)2 PageRankParams (com.baidu.hugegraph.computer.algorithm.centrality.pagerank.PageRankParams)1 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)1 Config (com.baidu.hugegraph.computer.core.config.Config)1 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)1 Managers (com.baidu.hugegraph.computer.core.manager.Managers)1 MasterService (com.baidu.hugegraph.computer.core.master.MasterService)1 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)1 DataClientManager (com.baidu.hugegraph.computer.core.network.DataClientManager)1 TransportConf (com.baidu.hugegraph.computer.core.network.TransportConf)1 FileRegionBuffer (com.baidu.hugegraph.computer.core.network.buffer.FileRegionBuffer)1 NetworkBuffer (com.baidu.hugegraph.computer.core.network.buffer.NetworkBuffer)1