Search in sources :

Example 11 with ServerMetaDataHolder

use of com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder in project pinpoint by naver.

the class PluginApplicationContextModule method newServerMetaDataHolder.

private ServerMetaDataHolder newServerMetaDataHolder() {
    List<String> vmArgs = RuntimeMXBeanUtils.getVmArgs();
    ServerMetaDataHolder serverMetaDataHolder = new ResettableServerMetaDataHolder(vmArgs);
    this.serverMetaDataListener = new TestableServerMetaDataListener();
    this.serverMetaDataHolder = serverMetaDataHolder;
    serverMetaDataHolder.addListener(this.serverMetaDataListener);
    return serverMetaDataHolder;
}
Also used : ServerMetaDataHolder(com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder)

Example 12 with ServerMetaDataHolder

use of com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder in project pinpoint by naver.

the class ServerMetaDataHolderProvider method get.

@Override
public ServerMetaDataHolder get() {
    AgentInfoSender agentInfoSender = this.agentInfoSender.get();
    List<String> vmArgs = RuntimeMXBeanUtils.getVmArgs();
    ServerMetaDataHolder serverMetaDataHolder = new DefaultServerMetaDataHolder(vmArgs);
    serverMetaDataHolder.addListener(agentInfoSender);
    return serverMetaDataHolder;
}
Also used : DefaultServerMetaDataHolder(com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder) ServerMetaDataHolder(com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder) DefaultServerMetaDataHolder(com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder) AgentInfoSender(com.navercorp.pinpoint.profiler.AgentInfoSender)

Example 13 with ServerMetaDataHolder

use of com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder in project pinpoint by naver.

the class AgentInfoSenderTest method serverMetaDataCouldBePublishedFromMultipleThreads.

@Test
public void serverMetaDataCouldBePublishedFromMultipleThreads() throws InterruptedException {
    // Given
    final AtomicInteger requestCount = new AtomicInteger();
    final AtomicInteger successCount = new AtomicInteger();
    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<Throwable>();
    ResponseServerMessageListener delayedServerListener = new ResponseServerMessageListener(requestCount, successCount);
    PinpointServerAcceptor serverAcceptor = createServerAcceptor(delayedServerListener);
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    PinpointClient pinpointClient = ClientFactoryUtils.createPinpointClient(HOST, PORT, clientFactory);
    TcpDataSender dataSender = new TcpDataSender(pinpointClient);
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, getAgentInfo()).sendInterval(agentInfoSendRetryIntervalMs).build();
    final ServerMetaDataHolder metaDataContext = new DefaultServerMetaDataHolder(Collections.<String>emptyList());
    metaDataContext.addListener(agentInfoSender);
    // When
    for (int i = 0; i < threadCount; ++i) {
        final String serviceName = "/name" + i;
        executorService.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                initLatch.countDown();
                try {
                    startLatch.await();
                    metaDataContext.addServiceInfo(serviceName, Collections.<String>emptyList());
                    metaDataContext.notifyListeners();
                } catch (final Throwable t) {
                    exceptions.add(t);
                } finally {
                    endLatch.countDown();
                }
                return null;
            }
        });
    }
    initLatch.await();
    startLatch.countDown();
    endLatch.await();
    executorService.shutdown();
    try {
        waitExpectedRequestCount(requestCount, threadCount);
        waitExpectedRequestCount(successCount, threadCount);
    } finally {
        closeAll(serverAcceptor, agentInfoSender, pinpointClient, clientFactory);
    }
    // Then
    assertTrue("Failed with exceptions : " + exceptions, exceptions.isEmpty());
    assertEquals(threadCount, requestCount.get());
    assertEquals(threadCount, successCount.get());
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) CountDownLatch(java.util.concurrent.CountDownLatch) TException(org.apache.thrift.TException) 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) ExecutorService(java.util.concurrent.ExecutorService) TcpDataSender(com.navercorp.pinpoint.profiler.sender.TcpDataSender) DefaultServerMetaDataHolder(com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder) ServerMetaDataHolder(com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder) DefaultServerMetaDataHolder(com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 14 with ServerMetaDataHolder

use of com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder in project pinpoint by naver.

the class DefaultServerMetaDataHolderTest method testRaceConditionWhenAddingServiceInfo.

@Test
public void testRaceConditionWhenAddingServiceInfo() throws InterruptedException {
    // Given
    final CountDownLatch initLatch = new CountDownLatch(THREAD_COUNT);
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch endLatch = new CountDownLatch(THREAD_COUNT);
    final Queue<Throwable> exceptions = new ConcurrentLinkedQueue<Throwable>();
    final String serviceName = "/test";
    final TestableServerMetaDataListener listener = new TestableServerMetaDataListener();
    final ServerMetaDataHolder metaDataContext = new DefaultServerMetaDataHolder(VM_ARGS);
    metaDataContext.addListener(listener);
    metaDataContext.setServerName(SERVER_INFO);
    // When
    for (int i = 0; i < THREAD_COUNT; ++i) {
        final List<String> serviceLibs = new ArrayList<String>();
        executorService.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                initLatch.countDown();
                try {
                    startLatch.await();
                    metaDataContext.addServiceInfo(serviceName, serviceLibs);
                    metaDataContext.notifyListeners();
                } catch (final Throwable t) {
                    exceptions.add(t);
                } finally {
                    endLatch.countDown();
                }
                return null;
            }
        });
    }
    initLatch.await();
    startLatch.countDown();
    endLatch.await();
    // Then
    assertTrue("Failed with exceptions : " + exceptions, exceptions.isEmpty());
    ServerMetaData metaData = listener.getServerMetaData();
    assertEquals(metaData.getServerInfo(), SERVER_INFO);
    assertEquals(metaData.getVmArgs(), VM_ARGS);
    assertEquals(metaData.getServiceInfos().size(), THREAD_COUNT);
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ServerMetaDataHolder(com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ServerMetaData(com.navercorp.pinpoint.bootstrap.context.ServerMetaData) Test(org.junit.Test)

Aggregations

ServerMetaDataHolder (com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder)14 DataSender (com.navercorp.pinpoint.profiler.sender.DataSender)3 PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)3 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)3 ArrayList (java.util.ArrayList)3 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 ServerMetaData (com.navercorp.pinpoint.bootstrap.context.ServerMetaData)2 DefaultServerMetaDataHolder (com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder)2 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 EnhancedDataSender (com.navercorp.pinpoint.profiler.sender.EnhancedDataSender)2 AgentInfoSender (com.navercorp.pinpoint.profiler.AgentInfoSender)1 TcpDataSender (com.navercorp.pinpoint.profiler.sender.TcpDataSender)1 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)1 PinpointServerAcceptor (com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)1 ListenableDataSender (com.navercorp.pinpoint.test.ListenableDataSender)1 MockApplicationContext (com.navercorp.pinpoint.test.MockApplicationContext)1