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();
}
}
}
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();
}
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());
}
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();
}
}
}
}
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;
}
Aggregations