Search in sources :

Example 1 with PingPacket

use of com.navercorp.pinpoint.rpc.packet.PingPacket in project pinpoint by naver.

the class TCPReceiver method start.

@PostConstruct
public void start() {
    afterPropertiesSet();
    // take care when attaching message handlers as events are generated from the IO thread.
    // pass them to a separate queue and handle them in a different thread.
    this.serverAcceptor.setMessageListener(new ServerMessageListener() {

        @Override
        public HandshakeResponseCode handleHandshake(Map properties) {
            if (properties == null) {
                return HandshakeResponseType.ProtocolError.PROTOCOL_ERROR;
            }
            boolean hasRequiredKeys = HandshakePropertyType.hasRequiredKeys(properties);
            if (!hasRequiredKeys) {
                return HandshakeResponseType.PropertyError.PROPERTY_ERROR;
            }
            boolean supportServer = MapUtils.getBoolean(properties, HandshakePropertyType.SUPPORT_SERVER.getName(), true);
            if (supportServer) {
                return HandshakeResponseType.Success.DUPLEX_COMMUNICATION;
            } else {
                return HandshakeResponseType.Success.SIMPLEX_COMMUNICATION;
            }
        }

        @Override
        public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) {
            receive(sendPacket, pinpointSocket);
        }

        @Override
        public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) {
            requestResponse(requestPacket, pinpointSocket);
        }

        @Override
        public void handlePing(PingPacket pingPacket, PinpointServer pinpointServer) {
            recordPing(pingPacket, pinpointServer);
        }
    });
    this.serverAcceptor.bind(configuration.getTcpListenIp(), configuration.getTcpListenPort());
}
Also used : RequestPacket(com.navercorp.pinpoint.rpc.packet.RequestPacket) ServerMessageListener(com.navercorp.pinpoint.rpc.server.ServerMessageListener) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) SendPacket(com.navercorp.pinpoint.rpc.packet.SendPacket) HandshakeResponseCode(com.navercorp.pinpoint.rpc.packet.HandshakeResponseCode) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) PingPacket(com.navercorp.pinpoint.rpc.packet.PingPacket) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct)

Example 2 with PingPacket

use of com.navercorp.pinpoint.rpc.packet.PingPacket in project pinpoint by naver.

the class TcpDataSenderReconnectTest method serverAcceptorStart.

public PinpointServerAcceptor serverAcceptorStart() {
    PinpointServerAcceptor serverAcceptor = new PinpointServerAcceptor();
    serverAcceptor.setMessageListener(new ServerMessageListener() {

        @Override
        public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) {
            logger.debug("handleSend packet:{}, remote:{}", sendPacket, pinpointSocket.getRemoteAddress());
            send++;
        }

        @Override
        public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) {
            logger.debug("handleRequest packet:{}, remote:{}", requestPacket, pinpointSocket.getRemoteAddress());
        }

        @Override
        public HandshakeResponseCode handleHandshake(Map properties) {
            return HandshakeResponseType.Success.DUPLEX_COMMUNICATION;
        }

        @Override
        public void handlePing(PingPacket pingPacket, PinpointServer pinpointServer) {
            logger.debug("ping received {} {} ", pingPacket, pinpointServer);
        }
    });
    serverAcceptor.bind(HOST, PORT);
    return serverAcceptor;
}
Also used : RequestPacket(com.navercorp.pinpoint.rpc.packet.RequestPacket) ServerMessageListener(com.navercorp.pinpoint.rpc.server.ServerMessageListener) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) SendPacket(com.navercorp.pinpoint.rpc.packet.SendPacket) HandshakeResponseCode(com.navercorp.pinpoint.rpc.packet.HandshakeResponseCode) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) PingPacket(com.navercorp.pinpoint.rpc.packet.PingPacket) Map(java.util.Map)

Example 3 with PingPacket

use of com.navercorp.pinpoint.rpc.packet.PingPacket in project pinpoint by naver.

the class PinpointClientFactoryTest method pingInternal.

@Test
public void pingInternal() throws IOException, InterruptedException {
    final CountDownLatch pingLatch = new CountDownLatch(1);
    PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, new PinpointRPCTestUtils.EchoServerListener() {

        @Override
        public void handlePing(PingPacket pingPacket, PinpointServer pinpointServer) {
            pingLatch.countDown();
        }
    });
    try {
        PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
        pingLatch.await();
        PinpointRPCTestUtils.close(client);
    } finally {
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointRPCTestUtils(com.navercorp.pinpoint.rpc.util.PinpointRPCTestUtils) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) PingPacket(com.navercorp.pinpoint.rpc.packet.PingPacket) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with PingPacket

use of com.navercorp.pinpoint.rpc.packet.PingPacket in project pinpoint by naver.

the class PacketDecoder method decode.

@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
    if (buffer.readableBytes() < 2) {
        return null;
    }
    buffer.markReaderIndex();
    final short packetType = buffer.readShort();
    switch(packetType) {
        case PacketType.APPLICATION_SEND:
            return readSend(packetType, buffer);
        case PacketType.APPLICATION_REQUEST:
            return readRequest(packetType, buffer);
        case PacketType.APPLICATION_RESPONSE:
            return readResponse(packetType, buffer);
        case PacketType.APPLICATION_STREAM_CREATE:
            return readStreamCreate(packetType, buffer);
        case PacketType.APPLICATION_STREAM_CLOSE:
            return readStreamClose(packetType, buffer);
        case PacketType.APPLICATION_STREAM_CREATE_SUCCESS:
            return readStreamCreateSuccess(packetType, buffer);
        case PacketType.APPLICATION_STREAM_CREATE_FAIL:
            return readStreamCreateFail(packetType, buffer);
        case PacketType.APPLICATION_STREAM_RESPONSE:
            return readStreamData(packetType, buffer);
        case PacketType.APPLICATION_STREAM_PING:
            return readStreamPing(packetType, buffer);
        case PacketType.APPLICATION_STREAM_PONG:
            return readStreamPong(packetType, buffer);
        case PacketType.CONTROL_CLIENT_CLOSE:
            return readControlClientClose(packetType, buffer);
        case PacketType.CONTROL_SERVER_CLOSE:
            return readControlServerClose(packetType, buffer);
        case PacketType.CONTROL_PING:
            PingPacket pingPacket = (PingPacket) readPing(packetType, buffer);
            if (pingPacket == PingPacket.PING_PACKET) {
                sendPong(channel);
                // just drop ping
                return null;
            }
            return pingPacket;
        case PacketType.CONTROL_PONG:
            logger.debug("receive pong. {}", channel);
            readPong(packetType, buffer);
            // just also drop pong.
            return null;
        case PacketType.CONTROL_HANDSHAKE:
            return readEnableWorker(packetType, buffer);
        case PacketType.CONTROL_HANDSHAKE_RESPONSE:
            return readEnableWorkerConfirm(packetType, buffer);
    }
    logger.error("invalid packetType received. packetType:{}, channel:{}", packetType, channel);
    channel.close();
    return null;
}
Also used : StreamPingPacket(com.navercorp.pinpoint.rpc.packet.stream.StreamPingPacket) PingPacket(com.navercorp.pinpoint.rpc.packet.PingPacket)

Aggregations

PingPacket (com.navercorp.pinpoint.rpc.packet.PingPacket)4 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)3 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)2 HandshakeResponseCode (com.navercorp.pinpoint.rpc.packet.HandshakeResponseCode)2 RequestPacket (com.navercorp.pinpoint.rpc.packet.RequestPacket)2 SendPacket (com.navercorp.pinpoint.rpc.packet.SendPacket)2 PinpointServerAcceptor (com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)2 ServerMessageListener (com.navercorp.pinpoint.rpc.server.ServerMessageListener)2 Map (java.util.Map)2 StreamPingPacket (com.navercorp.pinpoint.rpc.packet.stream.StreamPingPacket)1 PinpointRPCTestUtils (com.navercorp.pinpoint.rpc.util.PinpointRPCTestUtils)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 PostConstruct (javax.annotation.PostConstruct)1 Test (org.junit.Test)1