Search in sources :

Example 1 with PinpointClientFactory

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

the class PinpointClientFactoryProvider method get.

public PinpointClientFactory get() {
    PinpointClientFactory pinpointClientFactory = new DefaultPinpointClientFactory();
    pinpointClientFactory.setTimeoutMillis(1000 * 5);
    AgentInformation agentInformation = this.agentInformation.get();
    Map<String, Object> properties = toMap(agentInformation);
    boolean isSupportServerMode = profilerConfig.isTcpDataSenderCommandAcceptEnable();
    if (isSupportServerMode) {
        pinpointClientFactory.setMessageListener(commandDispatcher);
        pinpointClientFactory.setServerStreamChannelMessageListener(commandDispatcher);
        properties.put(HandshakePropertyType.SUPPORT_SERVER.getName(), true);
        properties.put(HandshakePropertyType.SUPPORT_COMMAND_LIST.getName(), commandDispatcher.getRegisteredCommandServiceCodes());
    } else {
        properties.put(HandshakePropertyType.SUPPORT_SERVER.getName(), false);
    }
    pinpointClientFactory.setProperties(properties);
    return pinpointClientFactory;
}
Also used : DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) AgentInformation(com.navercorp.pinpoint.profiler.AgentInformation)

Example 2 with PinpointClientFactory

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

the class DataReceiverGroupTest method receiverGroupTest1.

@Test
public void receiverGroupTest1() throws Exception {
    DataReceiverGroupConfiguration mockConfig = createMockConfig(true, true);
    TestDispatchHandler dispatchHandler = new TestDispatchHandler(2, 1);
    UDPReceiverBean udpReceiverBean = createUdpReceiverBean(mockConfig, dispatchHandler);
    TCPReceiverBean tcpReceiverBean = createTcpReceiverBean(mockConfig, dispatchHandler);
    DataSender<TBase<?, ?>> udpDataSender = null;
    TcpDataSender<TBase<?, ?>> tcpDataSender = null;
    PinpointClientFactory pinpointClientFactory = null;
    try {
        udpReceiverBean.afterPropertiesSet();
        tcpReceiverBean.afterPropertiesSet();
        udpDataSender = newUdpDataSender(mockConfig);
        pinpointClientFactory = createPinpointClientFactory();
        tcpDataSender = new TcpDataSender<>(this.getClass().getName(), "127.0.0.1", mockConfig.getTcpBindPort(), pinpointClientFactory);
        udpDataSender.send(new TResult());
        tcpDataSender.send(new TResult());
        tcpDataSender.request(new TResult());
        Assert.assertTrue(tcpDataSender.isConnected());
        Assert.assertTrue(dispatchHandler.getSendLatch().await(1000, TimeUnit.MILLISECONDS));
        Assert.assertTrue(dispatchHandler.getRequestLatch().await(1000, TimeUnit.MILLISECONDS));
    } finally {
        closeDataSender(udpDataSender);
        closeDataSender(tcpDataSender);
        closeClientFactory(pinpointClientFactory);
        closeBean(udpReceiverBean);
        closeBean(tcpReceiverBean);
    }
}
Also used : PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) DataReceiverGroupConfiguration(com.navercorp.pinpoint.collector.thrift.config.DataReceiverGroupConfiguration) UDPReceiverBean(com.navercorp.pinpoint.collector.receiver.thrift.UDPReceiverBean) TBase(org.apache.thrift.TBase) TCPReceiverBean(com.navercorp.pinpoint.collector.receiver.thrift.TCPReceiverBean) TResult(com.navercorp.pinpoint.thrift.dto.TResult) Test(org.junit.Test)

Example 3 with PinpointClientFactory

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

the class DataReceiverGroupTest method createPinpointClientFactory.

private PinpointClientFactory createPinpointClientFactory() {
    PinpointClientFactory clientFactory = new DefaultPinpointClientFactory();
    clientFactory.setWriteTimeoutMillis(1000 * 3);
    clientFactory.setRequestTimeoutMillis(1000 * 5);
    clientFactory.setProperties(Collections.emptyMap());
    return clientFactory;
}
Also used : DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)

Example 4 with PinpointClientFactory

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

the class DataReceiverGroupTest method receiverGroupTest3.

@Test
public void receiverGroupTest3() throws Exception {
    DataReceiverGroupConfiguration mockConfig = createMockConfig(false, true);
    TestDispatchHandler testDispatchHandler = new TestDispatchHandler(1, 1);
    UDPReceiverBean receiver = createUdpReceiverBean(mockConfig, testDispatchHandler);
    DataSender<TBase<?, ?>> udpDataSender = null;
    TcpDataSender<TBase<?, ?>> tcpDataSender = null;
    PinpointClientFactory pinpointClientFactory = null;
    try {
        receiver.afterPropertiesSet();
        udpDataSender = newUdpDataSender(mockConfig);
        udpDataSender.send(new TResult());
        Assert.assertTrue(testDispatchHandler.getSendLatch().await(1000, TimeUnit.MILLISECONDS));
        pinpointClientFactory = createPinpointClientFactory();
        tcpDataSender = new TcpDataSender<>(this.getClass().getName(), "127.0.0.1", mockConfig.getTcpBindPort(), pinpointClientFactory);
        Assert.assertFalse(tcpDataSender.isConnected());
    } finally {
        closeDataSender(udpDataSender);
        closeDataSender(tcpDataSender);
        closeClientFactory(pinpointClientFactory);
        closeBean(receiver);
    }
}
Also used : PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) DataReceiverGroupConfiguration(com.navercorp.pinpoint.collector.thrift.config.DataReceiverGroupConfiguration) UDPReceiverBean(com.navercorp.pinpoint.collector.receiver.thrift.UDPReceiverBean) TBase(org.apache.thrift.TBase) TResult(com.navercorp.pinpoint.thrift.dto.TResult) Test(org.junit.Test)

Example 5 with PinpointClientFactory

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

the class AgentInfoSenderTest method agentInfoShouldBeRefreshedOnServerMetaDataChangeFromMultipleThreads.

@Test
public void agentInfoShouldBeRefreshedOnServerMetaDataChangeFromMultipleThreads() {
    // Given
    final long agentInfoSendRetryIntervalMs = 1000L;
    final int threadCount = 50;
    final CountDownLatch initLatch = new CountDownLatch(threadCount);
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch endLatch = new CountDownLatch(threadCount);
    final ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
    final Queue<Throwable> exceptions = new ConcurrentLinkedQueue<>();
    final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory();
    ResponseServerMessageListener messageListener = messageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(clientFactory, bindPort);
    final AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
    serverMetaDataRegistryService.addListener(new ServerMetaDataRegistryService.OnChangeListener() {

        @Override
        public void onServerMetaDataChange() {
            agentInfoSender.refresh();
        }
    });
    // When
    for (int i = 0; i < threadCount; i++) {
        final String serviceName = "/name" + i;
        executorService.submit(new Runnable() {

            @Override
            public void run() {
                initLatch.countDown();
                try {
                    startLatch.await();
                    ServiceInfo serviceInfo = new DefaultServiceInfo(serviceName, Collections.<String>emptyList());
                    serverMetaDataRegistryService.addServiceInfo(serviceInfo);
                    serverMetaDataRegistryService.notifyListeners();
                } catch (final Throwable t) {
                    exceptions.add(t);
                } finally {
                    endLatch.countDown();
                }
            }
        });
    }
    await(initLatch, 3000);
    startLatch.countDown();
    await(endLatch, 3000);
    executorService.shutdown();
    try {
        waitExpectedRequestCount(threadCount, messageListener);
        waitExpectedSuccessCount(threadCount, messageListener);
    } finally {
        closeAll(agentInfoSender, clientFactory);
        testPinpointServerAcceptor.close();
    }
    // Then
    assertTrue("Failed with exceptions : " + exceptions, exceptions.isEmpty());
    assertEquals(threadCount, messageListener.getRequestCount());
    assertEquals(threadCount, messageListener.getSuccessCount());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ServiceInfo(com.navercorp.pinpoint.bootstrap.context.ServiceInfo) DefaultServiceInfo(com.navercorp.pinpoint.profiler.context.DefaultServiceInfo) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) ExecutorService(java.util.concurrent.ExecutorService) ServerMetaDataRegistryService(com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) DefaultServiceInfo(com.navercorp.pinpoint.profiler.context.DefaultServiceInfo) Test(org.junit.Test)

Aggregations

PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)34 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)27 Test (org.junit.Test)15 MetaDataType (com.navercorp.pinpoint.profiler.metadata.MetaDataType)12 TestPinpointServerAcceptor (com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)10 PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)6 TcpDataSender (com.navercorp.pinpoint.profiler.sender.TcpDataSender)4 TBase (org.apache.thrift.TBase)4 DataReceiverGroupConfiguration (com.navercorp.pinpoint.collector.thrift.config.DataReceiverGroupConfiguration)3 ServerMetaDataRegistryService (com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService)3 SpanType (com.navercorp.pinpoint.profiler.context.SpanType)3 MetricType (com.navercorp.pinpoint.profiler.monitor.metric.MetricType)3 EnhancedDataSender (com.navercorp.pinpoint.profiler.sender.EnhancedDataSender)3 TResult (com.navercorp.pinpoint.thrift.dto.TResult)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 TypeLiteral (com.google.inject.TypeLiteral)2 ServiceInfo (com.navercorp.pinpoint.bootstrap.context.ServiceInfo)2 TCPReceiverBean (com.navercorp.pinpoint.collector.receiver.thrift.TCPReceiverBean)2 UDPReceiverBean (com.navercorp.pinpoint.collector.receiver.thrift.UDPReceiverBean)2 AgentInformation (com.navercorp.pinpoint.profiler.AgentInformation)2