Search in sources :

Example 1 with PingSimplePacket

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

the class HealthCheckTest method healthCheckSimplePingTest.

@Test
public void healthCheckSimplePingTest() throws Exception {
    TestServerMessageListenerFactory testServerMessageListenerFactory = new TestServerMessageListenerFactory(TestServerMessageListenerFactory.HandshakeType.DUPLEX, true);
    TestServerMessageListenerFactory.TestServerMessageListener serverMessageListener = testServerMessageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    TestRawSocket testRawSocket = new TestRawSocket();
    try {
        testRawSocket.connect(bindPort);
        sendPingAndReceivePongPacket(testRawSocket, new PingSimplePacket());
        Assert.fail();
    } catch (Exception e) {
    } finally {
        testRawSocket.close();
        testPinpointServerAcceptor.close();
    }
    Assert.assertFalse(serverMessageListener.hasReceivedPing());
}
Also used : TestRawSocket(com.navercorp.pinpoint.test.client.TestRawSocket) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) TestServerMessageListenerFactory(com.navercorp.pinpoint.test.server.TestServerMessageListenerFactory) PingSimplePacket(com.navercorp.pinpoint.rpc.packet.PingSimplePacket) ProtocolException(com.navercorp.pinpoint.rpc.control.ProtocolException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with PingSimplePacket

use of com.navercorp.pinpoint.rpc.packet.PingSimplePacket 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_SIMPLE:
            PingSimplePacket pingPacket = (PingSimplePacket) readPing(packetType, buffer);
            if (pingPacket == PingSimplePacket.PING_PACKET) {
                sendPong(channel);
                return null;
            }
        case PacketType.CONTROL_PING_PAYLOAD:
            return readPayloadPing(packetType, buffer);
        case PacketType.CONTROL_PING:
            PingPacket legacyPingPacket = (PingPacket) readLegacyPing(packetType, buffer);
            if (legacyPingPacket == PingPacket.PING_PACKET) {
                sendPong(channel);
                // just drop ping
                return null;
            }
            return legacyPingPacket;
        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) PingSimplePacket(com.navercorp.pinpoint.rpc.packet.PingSimplePacket)

Aggregations

PingSimplePacket (com.navercorp.pinpoint.rpc.packet.PingSimplePacket)2 ProtocolException (com.navercorp.pinpoint.rpc.control.ProtocolException)1 PingPacket (com.navercorp.pinpoint.rpc.packet.PingPacket)1 StreamPingPacket (com.navercorp.pinpoint.rpc.packet.stream.StreamPingPacket)1 TestRawSocket (com.navercorp.pinpoint.test.client.TestRawSocket)1 TestPinpointServerAcceptor (com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)1 TestServerMessageListenerFactory (com.navercorp.pinpoint.test.server.TestServerMessageListenerFactory)1 IOException (java.io.IOException)1 Test (org.junit.Test)1