Search in sources :

Example 1 with PinpointServer

use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.

the class TcpDataSenderTest method serverStart.

@Before
public void serverStart() {
    serverAcceptor = new PinpointServerAcceptor();
    serverAcceptor.setMessageListener(new ServerMessageListener() {

        @Override
        public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) {
            logger.debug("handleSend packet:{}, remote:{}", sendPacket, pinpointSocket.getRemoteAddress());
            if (sendLatch != null) {
                sendLatch.countDown();
            }
        }

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

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

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

Example 2 with PinpointServer

use of com.navercorp.pinpoint.rpc.server.PinpointServer 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 PinpointServer

use of com.navercorp.pinpoint.rpc.server.PinpointServer 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 4 with PinpointServer

use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.

the class StreamChannelManagerTest method streamClosedTest3.

// ServerSocket to Client Stream
// ServerStreamChannel first close.
@Test(expected = PinpointSocketException.class)
public void streamClosedTest3() throws IOException, InterruptedException, StreamException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    SimpleStreamBO bo = new SimpleStreamBO();
    ServerListener serverStreamChannelMessageHandler = new ServerListener(bo);
    TestPinpointClient testPinpointClient = new TestPinpointClient(SimpleMessageListener.INSTANCE, serverStreamChannelMessageHandler);
    testPinpointClient.connect(bindPort);
    try {
        testPinpointServerAcceptor.assertAwaitClientConnected(1000);
        List<PinpointSocket> writableServerList = testPinpointServerAcceptor.getConnectedPinpointSocketList();
        Assert.assertEquals(1, writableServerList.size());
        PinpointSocket writableServer = writableServerList.get(0);
        if (writableServer instanceof PinpointServer) {
            RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
            ClientStreamChannel clientStreamChannel = ((PinpointServer) writableServer).openStreamAndAwait(new byte[0], clientListener, 3000);
            StreamChannel streamChannel = serverStreamChannelMessageHandler.bo.serverStreamChannelList.get(0);
            streamChannel.close();
            sendRandomBytes(bo);
            Thread.sleep(100);
            clientStreamChannel.close();
        } else {
            Assert.fail();
        }
    } 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) RecordedStreamChannelMessageListener(com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) Test(org.junit.Test)

Example 5 with PinpointServer

use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.

the class StreamChannelManagerTest method streamSuccessTest3.

@Test
public void streamSuccessTest3() throws IOException, InterruptedException, StreamException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    SimpleStreamBO bo = new SimpleStreamBO();
    TestPinpointClient testPinpointClient = new TestPinpointClient(SimpleMessageListener.INSTANCE, new ServerListener(bo));
    try {
        testPinpointClient.connect(bindPort);
        testPinpointServerAcceptor.assertAwaitClientConnected(1000);
        List<PinpointSocket> writableServerList = testPinpointServerAcceptor.getConnectedPinpointSocketList();
        Assert.assertEquals(1, writableServerList.size());
        PinpointSocket writableServer = writableServerList.get(0);
        RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
        if (writableServer instanceof PinpointServer) {
            ClientStreamChannel clientStreamChannel = ((PinpointServer) writableServer).openStreamAndAwait(new byte[0], clientListener, 3000);
            int sendCount = 4;
            for (int i = 0; i < sendCount; i++) {
                sendRandomBytes(bo);
            }
            clientListener.getLatch().await();
            Assert.assertEquals(sendCount, clientListener.getReceivedMessage().size());
            clientStreamChannel.close();
        } else {
            Assert.fail();
        }
    } 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) RecordedStreamChannelMessageListener(com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) Test(org.junit.Test)

Aggregations

PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)11 Test (org.junit.Test)6 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)5 ClusterPointRepository (com.navercorp.pinpoint.collector.cluster.ClusterPointRepository)4 ClusterPointStateChangedEventHandler (com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler)4 Map (java.util.Map)4 ServerMessageListener (com.navercorp.pinpoint.rpc.server.ServerMessageListener)3 RecordedStreamChannelMessageListener (com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener)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 TestPinpointClient (com.navercorp.pinpoint.test.client.TestPinpointClient)2 TestPinpointServerAcceptor (com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)2 HashMap (java.util.HashMap)2 PinpointGrpcServer (com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer)1 CreateNodeMessage (com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage)1 PinpointZookeeperException (com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException)1 HashSet (java.util.HashSet)1