use of com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder 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;
}
use of com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder 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());
}
Aggregations