Search in sources :

Example 1 with RequestPacket

use of com.navercorp.pinpoint.rpc.packet.RequestPacket 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 RequestPacket

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

the class RequestManagerTest method testRegisterRequest.

@Test
public void testRegisterRequest() throws Exception {
    HashedWheelTimer timer = getTimer();
    RequestManager requestManager = new RequestManager(timer, 3000);
    try {
        RequestPacket packet = new RequestPacket(new byte[0]);
        final Future future = requestManager.register(packet, 50);
        TestAwaitUtils.await(new TestAwaitTaskUtils() {

            @Override
            public boolean checkCompleted() {
                return future.isReady();
            }
        }, 10, 200);
        Assert.assertTrue(future.isReady());
        Assert.assertFalse(future.isSuccess());
        Assert.assertTrue(future.getCause().getMessage().contains("timeout"));
        logger.debug(future.getCause().getMessage());
    } finally {
        requestManager.close();
        timer.stop();
    }
}
Also used : RequestPacket(com.navercorp.pinpoint.rpc.packet.RequestPacket) TestAwaitTaskUtils(com.navercorp.pinpoint.rpc.TestAwaitTaskUtils) Future(com.navercorp.pinpoint.rpc.Future) DefaultFuture(com.navercorp.pinpoint.rpc.DefaultFuture) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) Test(org.junit.Test)

Example 3 with RequestPacket

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

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

the class RequestManagerTest method testRemoveMessageFuture.

@Test
public void testRemoveMessageFuture() throws Exception {
    HashedWheelTimer timer = getTimer();
    RequestManager requestManager = new RequestManager(timer, 3000);
    try {
        RequestPacket packet = new RequestPacket(1, new byte[0]);
        DefaultFuture future = requestManager.register(packet, 2000);
        future.setFailure(new RuntimeException());
        Future nullFuture = requestManager.removeMessageFuture(packet.getRequestId());
        Assert.assertNull(nullFuture);
    } finally {
        requestManager.close();
        timer.stop();
    }
}
Also used : RequestPacket(com.navercorp.pinpoint.rpc.packet.RequestPacket) Future(com.navercorp.pinpoint.rpc.Future) DefaultFuture(com.navercorp.pinpoint.rpc.DefaultFuture) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) DefaultFuture(com.navercorp.pinpoint.rpc.DefaultFuture) Test(org.junit.Test)

Example 5 with RequestPacket

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

the class ControlPacketServerTest method sendSimpleRequestPacket.

private void sendSimpleRequestPacket(OutputStream outputStream) throws ProtocolException, IOException {
    RequestPacket packet = new RequestPacket(new byte[0]);
    packet.setRequestId(10);
    ByteBuffer bb = packet.toBuffer().toByteBuffer(0, packet.toBuffer().writerIndex());
    sendData(outputStream, bb.array());
}
Also used : RequestPacket(com.navercorp.pinpoint.rpc.packet.RequestPacket) ByteBuffer(java.nio.ByteBuffer)

Aggregations

RequestPacket (com.navercorp.pinpoint.rpc.packet.RequestPacket)5 DefaultFuture (com.navercorp.pinpoint.rpc.DefaultFuture)2 Future (com.navercorp.pinpoint.rpc.Future)2 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)2 HandshakeResponseCode (com.navercorp.pinpoint.rpc.packet.HandshakeResponseCode)2 PingPacket (com.navercorp.pinpoint.rpc.packet.PingPacket)2 SendPacket (com.navercorp.pinpoint.rpc.packet.SendPacket)2 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)2 ServerMessageListener (com.navercorp.pinpoint.rpc.server.ServerMessageListener)2 Map (java.util.Map)2 HashedWheelTimer (org.jboss.netty.util.HashedWheelTimer)2 Test (org.junit.Test)2 TestAwaitTaskUtils (com.navercorp.pinpoint.rpc.TestAwaitTaskUtils)1 PinpointServerAcceptor (com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)1 ByteBuffer (java.nio.ByteBuffer)1 PostConstruct (javax.annotation.PostConstruct)1