Search in sources :

Example 11 with PinpointClient

use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.

the class TcpDataSenderTest method connectAndSend.

@Test
public void connectAndSend() throws InterruptedException {
    this.sendLatch = new CountDownLatch(2);
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    PinpointClient client = ClientFactoryUtils.createPinpointClient(HOST, PORT, clientFactory);
    TcpDataSender sender = new TcpDataSender(client);
    try {
        sender.send(new TApiMetaData("test", System.currentTimeMillis(), 1, "TestApi"));
        sender.send(new TApiMetaData("test", System.currentTimeMillis(), 1, "TestApi"));
        boolean received = sendLatch.await(1000, TimeUnit.MILLISECONDS);
        Assert.assertTrue(received);
    } finally {
        sender.stop();
        if (client != null) {
            client.close();
        }
        if (clientFactory != null) {
            clientFactory.release();
        }
    }
}
Also used : TApiMetaData(com.navercorp.pinpoint.thrift.dto.TApiMetaData) PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 12 with PinpointClient

use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.

the class TcpDataSenderReconnectTest method connectAndSend.

@Test
public void connectAndSend() throws InterruptedException {
    PinpointServerAcceptor oldAcceptor = serverAcceptorStart();
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    PinpointClient client = ClientFactoryUtils.createPinpointClient(HOST, PORT, clientFactory);
    TcpDataSender sender = new TcpDataSender(client);
    waitClientConnected(oldAcceptor);
    oldAcceptor.close();
    waitClientDisconnected(client);
    logger.debug("Server start------------------");
    PinpointServerAcceptor serverAcceptor = serverAcceptorStart();
    waitClientConnected(serverAcceptor);
    logger.debug("sendMessage------------------");
    sender.send(new TApiMetaData("test", System.currentTimeMillis(), 1, "TestApi"));
    Thread.sleep(500);
    logger.debug("sender stop------------------");
    sender.stop();
    serverAcceptor.close();
    client.close();
    clientFactory.release();
}
Also used : TApiMetaData(com.navercorp.pinpoint.thrift.dto.TApiMetaData) PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) Test(org.junit.Test)

Example 13 with PinpointClient

use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldInitiallyRetryIndefinitely.

@Test
public void agentInfoShouldInitiallyRetryIndefinitely() throws InterruptedException {
    final AtomicInteger requestCount = new AtomicInteger();
    final AtomicInteger successCount = new AtomicInteger();
    final long agentInfoSendRetryIntervalMs = 100L;
    final int expectedTriesUntilSuccess = AgentInfoSender.DEFAULT_MAX_TRY_COUNT_PER_ATTEMPT * 5;
    ResponseServerMessageListener serverListener = new ResponseServerMessageListener(requestCount, successCount, expectedTriesUntilSuccess);
    PinpointServerAcceptor serverAcceptor = createServerAcceptor(serverListener);
    PinpointClientFactory socketFactory = createPinpointClientFactory();
    PinpointClient pinpointClient = ClientFactoryUtils.createPinpointClient(HOST, PORT, socketFactory);
    TcpDataSender dataSender = new TcpDataSender(pinpointClient);
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, getAgentInfo()).sendInterval(agentInfoSendRetryIntervalMs).build();
    try {
        agentInfoSender.start();
        waitExpectedRequestCount(requestCount, expectedTriesUntilSuccess);
    } finally {
        closeAll(serverAcceptor, agentInfoSender, pinpointClient, socketFactory);
    }
    assertEquals(expectedTriesUntilSuccess, requestCount.get());
    assertEquals(1, successCount.get());
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) TcpDataSender(com.navercorp.pinpoint.profiler.sender.TcpDataSender) Test(org.junit.Test)

Example 14 with PinpointClient

use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.

the class ClassPreLoader method preload.

public static void preload(int port) {
    PinpointServerAcceptor serverAcceptor = null;
    PinpointClient client = null;
    PinpointClientFactory clientFactory = null;
    try {
        serverAcceptor = new PinpointServerAcceptor();
        serverAcceptor.bind("127.0.0.1", port);
        clientFactory = new DefaultPinpointClientFactory();
        client = clientFactory.connect("127.0.0.1", port);
        client.sendSync(new byte[0]);
    } catch (Exception ex) {
        System.err.print("preLoad error Caused:" + ex.getMessage());
        ex.printStackTrace();
        final Logger logger = LoggerFactory.getLogger(ClassPreLoader.class);
        logger.warn("preLoad error Caused:{}", ex.getMessage(), ex);
        if (ex instanceof PinpointSocketException) {
            throw (PinpointSocketException) ex;
        } else {
            throw new PinpointSocketException(ex.getMessage(), ex);
        }
    } finally {
        if (client != null) {
            try {
                client.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (clientFactory != null) {
            try {
                clientFactory.release();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (serverAcceptor != null) {
            try {
                serverAcceptor.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) Logger(org.slf4j.Logger)

Example 15 with PinpointClient

use of com.navercorp.pinpoint.rpc.client.PinpointClient in project pinpoint by naver.

the class ClientFactoryUtils method createPinpointClient.

public static PinpointClient createPinpointClient(InetSocketAddress connectAddress, PinpointClientFactory clientFactory) {
    PinpointClient pinpointClient = null;
    for (int i = 0; i < 3; i++) {
        try {
            pinpointClient = clientFactory.connect(connectAddress);
            LOGGER.info("tcp connect success. remote:{}", connectAddress);
            return pinpointClient;
        } catch (PinpointSocketException e) {
            LOGGER.warn("tcp connect fail. remote:{} try reconnect, retryCount:{}", connectAddress, i);
        }
    }
    LOGGER.warn("change background tcp connect mode remote:{} ", connectAddress);
    pinpointClient = clientFactory.scheduledConnect(connectAddress);
    return pinpointClient;
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException)

Aggregations

PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)29 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)28 Test (org.junit.Test)22 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)19 PinpointServerAcceptor (com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)16 TcpDataSender (com.navercorp.pinpoint.profiler.sender.TcpDataSender)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)5 ServerMetaDataHolder (com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder)3 EnhancedDataSender (com.navercorp.pinpoint.profiler.sender.EnhancedDataSender)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 SpanDataSender (com.navercorp.pinpoint.profiler.context.module.SpanDataSender)2 StatDataSender (com.navercorp.pinpoint.profiler.context.module.StatDataSender)2 StorageFactory (com.navercorp.pinpoint.profiler.context.storage.StorageFactory)2 DataSender (com.navercorp.pinpoint.profiler.sender.DataSender)2 TestAwaitTaskUtils (com.navercorp.pinpoint.rpc.TestAwaitTaskUtils)2 PinpointClientReconnectEventListener (com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener)2 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)2 TApiMetaData (com.navercorp.pinpoint.thrift.dto.TApiMetaData)2