Search in sources :

Example 21 with PinpointSocket

use of com.navercorp.pinpoint.rpc.PinpointSocket in project pinpoint by naver.

the class HandshakeTest method getWritableServer.

private PinpointSocket getWritableServer(String applicationName, String agentId, long startTimeMillis, List<PinpointSocket> writableServerList) {
    if (applicationName == null) {
        return null;
    }
    if (agentId == null) {
        return null;
    }
    if (startTimeMillis <= 0) {
        return null;
    }
    List<PinpointSocket> result = new ArrayList<>();
    for (PinpointSocket writableServer : writableServerList) {
        if (writableServer instanceof PinpointServer) {
            Map agentProperties = ((PinpointServer) writableServer).getChannelProperties();
            if (!applicationName.equals(agentProperties.get(HandshakePropertyType.APPLICATION_NAME.getName()))) {
                continue;
            }
            if (!agentId.equals(agentProperties.get(HandshakePropertyType.AGENT_ID.getName()))) {
                continue;
            }
            if (startTimeMillis != (Long) agentProperties.get(HandshakePropertyType.START_TIMESTAMP.getName())) {
                continue;
            }
            result.add(writableServer);
        }
    }
    if (result.isEmpty()) {
        return null;
    }
    if (result.size() == 1) {
        return result.get(0);
    } else {
        logger.warn("Ambiguous Channel Context {}, {}, {} (Valid Agent list={}).", applicationName, agentId, startTimeMillis, result);
        return null;
    }
}
Also used : PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 22 with PinpointSocket

use of com.navercorp.pinpoint.rpc.PinpointSocket in project pinpoint by naver.

the class PinpointServerStateTest method unexpectedCloseByPeerTest.

@Test
public void unexpectedCloseByPeerTest() throws IOException, ProtocolException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    try {
        int bindPort = testPinpointServerAcceptor.bind();
        TestRawSocket testRawSocket = new TestRawSocket();
        testRawSocket.connect(bindPort);
        testRawSocket.sendHandshakePacket(PinpointRPCTestUtils.getParams());
        testPinpointServerAcceptor.assertAwaitClientConnected(1, 1000);
        PinpointSocket pinpointServer = testPinpointServerAcceptor.getConnectedPinpointSocketList().get(0);
        if (!(pinpointServer instanceof PinpointServer)) {
            testRawSocket.close();
            Assert.fail();
        }
        Assert.assertEquals(SocketStateCode.RUN_DUPLEX, ((PinpointServer) pinpointServer).getCurrentStateCode());
        testRawSocket.close();
        assertPinpointServerState(SocketStateCode.UNEXPECTED_CLOSE_BY_CLIENT, (PinpointServer) pinpointServer);
    } finally {
        testPinpointServerAcceptor.close();
    }
}
Also used : TestRawSocket(com.navercorp.pinpoint.test.client.TestRawSocket) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) Test(org.junit.Test)

Example 23 with PinpointSocket

use of com.navercorp.pinpoint.rpc.PinpointSocket in project pinpoint by naver.

the class ClientMessageListenerTest method clientMessageListenerTest1.

@Test
public void clientMessageListenerTest1() {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    EchoClientListener echoMessageListener = new EchoClientListener();
    TestPinpointClient testPinpointClient = new TestPinpointClient(echoMessageListener, PinpointRPCTestUtils.getParams());
    try {
        testPinpointClient.connect(bindPort);
        testPinpointServerAcceptor.assertAwaitClientConnected(1, 1000);
        PinpointSocket writableServer = testPinpointServerAcceptor.getConnectedPinpointSocketList().get(0);
        assertSendMessage(writableServer, "simple", echoMessageListener);
        assertRequestMessage(writableServer, "request", echoMessageListener);
    } finally {
        testPinpointClient.closeAll();
        testPinpointServerAcceptor.close();
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) TestPinpointClient(com.navercorp.pinpoint.test.client.TestPinpointClient) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) EchoClientListener(com.navercorp.pinpoint.rpc.util.PinpointRPCTestUtils.EchoClientListener) Test(org.junit.Test)

Example 24 with PinpointSocket

use of com.navercorp.pinpoint.rpc.PinpointSocket in project pinpoint by naver.

the class CollectorClusterConnectionManager method connectPointIfAbsent.

@Override
public void connectPointIfAbsent(Address address) {
    logger.info("localhost -> {} connect started.", address);
    if (socketRepository.containsKey(address)) {
        logger.info("localhost -> {} already connected.", address);
        return;
    }
    PinpointSocket connect = clusterConnector.connect(address);
    socketRepository.putIfAbsent(address, connect);
    logger.info("localhost -> {} connect completed.", address);
}
Also used : PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket)

Example 25 with PinpointSocket

use of com.navercorp.pinpoint.rpc.PinpointSocket in project pinpoint by naver.

the class CollectorClusterConnectionManager method disconnectPoint.

@Override
public void disconnectPoint(Address address) {
    logger.info("localhost -> {} disconnect started.", address);
    PinpointSocket socket = socketRepository.remove(address);
    if (socket != null) {
        socket.close();
        logger.info("localhost -> {} disconnect completed.", address);
    } else {
        logger.info("localhost -> {} already disconnected.", address);
    }
}
Also used : PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket)

Aggregations

PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)27 TestPinpointServerAcceptor (com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)10 Test (org.junit.Test)10 TestPinpointClient (com.navercorp.pinpoint.test.client.TestPinpointClient)8 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)5 TCommandTransfer (com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer)5 Map (java.util.Map)5 ServerMessageListener (com.navercorp.pinpoint.rpc.server.ServerMessageListener)3 RecordedStreamChannelMessageListener (com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener)2 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)2 HandshakeResponseCode (com.navercorp.pinpoint.rpc.packet.HandshakeResponseCode)2 PingPacket (com.navercorp.pinpoint.rpc.packet.PingPacket)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 StreamException (com.navercorp.pinpoint.rpc.stream.StreamException)2 DefaultPinpointRouteResponse (com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse)2 FailedPinpointRouteResponse (com.navercorp.pinpoint.web.cluster.FailedPinpointRouteResponse)2 PinpointRouteResponse (com.navercorp.pinpoint.web.cluster.PinpointRouteResponse)2 ArrayList (java.util.ArrayList)2