use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.
the class TCPReceiver method start.
@PostConstruct
public void start() {
afterPropertiesSet();
// take care when attaching message handlers as events are generated from the IO thread.
// pass them to a separate queue and handle them in a different thread.
this.serverAcceptor.setMessageListener(new ServerMessageListener() {
@Override
public HandshakeResponseCode handleHandshake(Map properties) {
if (properties == null) {
return HandshakeResponseType.ProtocolError.PROTOCOL_ERROR;
}
boolean hasRequiredKeys = HandshakePropertyType.hasRequiredKeys(properties);
if (!hasRequiredKeys) {
return HandshakeResponseType.PropertyError.PROPERTY_ERROR;
}
boolean supportServer = MapUtils.getBoolean(properties, HandshakePropertyType.SUPPORT_SERVER.getName(), true);
if (supportServer) {
return HandshakeResponseType.Success.DUPLEX_COMMUNICATION;
} else {
return HandshakeResponseType.Success.SIMPLEX_COMMUNICATION;
}
}
@Override
public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) {
receive(sendPacket, pinpointSocket);
}
@Override
public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) {
requestResponse(requestPacket, pinpointSocket);
}
@Override
public void handlePing(PingPacket pingPacket, PinpointServer pinpointServer) {
recordPing(pingPacket, pinpointServer);
}
});
this.serverAcceptor.bind(configuration.getTcpListenIp(), configuration.getTcpListenPort());
}
use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.
the class ZookeeperJobWorkerTest method test1.
@Test
public void test1() throws Exception {
MockZookeeperClient zookeeperClient = new MockZookeeperClient();
zookeeperClient.connect();
ZookeeperJobWorker zookeeperWorker = new ZookeeperJobWorker(zookeeperClient, IDENTIFIER);
zookeeperWorker.start();
// To check for handling when multiple started. (goal: nothing happen)
zookeeperWorker.start();
try {
int random = ThreadLocalRandom.current().nextInt(1, 10);
for (int i = 0; i < random; i++) {
PinpointServer mockServer = createMockPinpointServer("app" + i, "agent" + i, System.currentTimeMillis());
zookeeperWorker.addPinpointServer(mockServer);
}
waitZookeeperServerData(random, zookeeperClient);
Assert.assertEquals(random, decodeServerData(zookeeperWorker.getClusterData()).size());
} finally {
zookeeperWorker.stop();
}
}
use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.
the class ZookeeperJobWorkerTest method test4.
@Test
public void test4() throws Exception {
MockZookeeperClient zookeeperClient = new MockZookeeperClient();
zookeeperClient.connect();
ZookeeperJobWorker zookeeperWorker = new ZookeeperJobWorker(zookeeperClient, IDENTIFIER);
zookeeperWorker.start();
try {
PinpointServer mockServer1 = createMockPinpointServer("app", "agent", System.currentTimeMillis());
zookeeperWorker.addPinpointServer(mockServer1);
PinpointServer mockServer2 = createMockPinpointServer("app", "agent", System.currentTimeMillis() + 1000);
zookeeperWorker.addPinpointServer(mockServer2);
waitZookeeperServerData(2, zookeeperClient);
Assert.assertEquals(2, decodeServerData(zookeeperWorker.getClusterData()).size());
zookeeperWorker.removePinpointServer(mockServer1);
waitZookeeperServerData(1, zookeeperClient);
Assert.assertEquals(1, decodeServerData(zookeeperWorker.getClusterData()).size());
} finally {
zookeeperWorker.stop();
}
}
use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.
the class ZookeeperJobWorkerTest method createMockPinpointServer.
private PinpointServer createMockPinpointServer(String applicationName, String agentId, long startTimeStamp) {
Map<Object, Object> properties = new HashMap<>();
properties.put(HandshakePropertyType.APPLICATION_NAME.getName(), applicationName);
properties.put(HandshakePropertyType.AGENT_ID.getName(), agentId);
properties.put(HandshakePropertyType.START_TIMESTAMP.getName(), startTimeStamp);
PinpointServer mockServer = mock(PinpointServer.class);
when(mockServer.getChannelProperties()).thenReturn(properties);
return mockServer;
}
use of com.navercorp.pinpoint.rpc.server.PinpointServer in project pinpoint by naver.
the class ZookeeperJobWorkerTest method test3.
@Test
public void test3() throws Exception {
MockZookeeperClient zookeeperClient = new MockZookeeperClient();
zookeeperClient.connect();
ZookeeperJobWorker zookeeperWorker = new ZookeeperJobWorker(zookeeperClient, IDENTIFIER);
zookeeperWorker.start();
try {
PinpointServer mockServer = createMockPinpointServer("app", "agent", System.currentTimeMillis());
zookeeperWorker.addPinpointServer(mockServer);
waitZookeeperServerData(1, zookeeperClient);
Assert.assertEquals(1, decodeServerData(zookeeperWorker.getClusterData()).size());
zookeeperWorker.clear();
waitZookeeperServerData(0, zookeeperClient);
Assert.assertEquals(0, decodeServerData(zookeeperWorker.getClusterData()).size());
zookeeperWorker.addPinpointServer(mockServer);
waitZookeeperServerData(1, zookeeperClient);
Assert.assertEquals(1, decodeServerData(zookeeperWorker.getClusterData()).size());
} finally {
zookeeperWorker.stop();
}
}
Aggregations