Search in sources :

Example 1 with RecommendTask

use of org.apache.eventmesh.runtime.core.protocol.tcp.client.task.RecommendTask in project incubator-eventmesh by apache.

the class EventMeshTcpMessageDispatcher method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, Package pkg) throws Exception {
    long startTime = System.currentTimeMillis();
    validateMsg(pkg);
    eventMeshTCPServer.getEventMeshTcpMonitor().getTcpSummaryMetrics().getClient2eventMeshMsgNum().incrementAndGet();
    Command cmd = null;
    try {
        Runnable task;
        cmd = pkg.getHeader().getCmd();
        if (cmd.equals(Command.RECOMMEND_REQUEST)) {
            messageLogger.info("pkg|c2eventMesh|cmd={}|pkg={}", cmd, pkg);
            task = new RecommendTask(pkg, ctx, startTime, eventMeshTCPServer);
            eventMeshTCPServer.getTaskHandleExecutorService().submit(task);
            return;
        }
        if (cmd.equals(Command.HELLO_REQUEST)) {
            messageLogger.info("pkg|c2eventMesh|cmd={}|pkg={}", cmd, pkg);
            task = new HelloTask(pkg, ctx, startTime, eventMeshTCPServer);
            eventMeshTCPServer.getTaskHandleExecutorService().submit(task);
            return;
        }
        if (eventMeshTCPServer.getClientSessionGroupMapping().getSession(ctx) == null) {
            messageLogger.info("pkg|c2eventMesh|cmd={}|pkg={},no session is found", cmd, pkg);
            throw new Exception("no session is found");
        }
        logMessageFlow(ctx, pkg, cmd);
        if (eventMeshTCPServer.getClientSessionGroupMapping().getSession(ctx).getSessionState() == SessionState.CLOSED) {
            throw new Exception("this eventMesh tcp session will be closed, may be reboot or version change!");
        }
        dispatch(ctx, pkg, startTime, cmd);
    } catch (Exception e) {
        logger.error("exception occurred while pkg|cmd={}|pkg={}", cmd, pkg, e);
        writeToClient(cmd, pkg, ctx, e);
    }
}
Also used : HelloTask(org.apache.eventmesh.runtime.core.protocol.tcp.client.task.HelloTask) Command(org.apache.eventmesh.common.protocol.tcp.Command) RecommendTask(org.apache.eventmesh.runtime.core.protocol.tcp.client.task.RecommendTask)

Aggregations

Command (org.apache.eventmesh.common.protocol.tcp.Command)1 HelloTask (org.apache.eventmesh.runtime.core.protocol.tcp.client.task.HelloTask)1 RecommendTask (org.apache.eventmesh.runtime.core.protocol.tcp.client.task.RecommendTask)1