use of com.navercorp.pinpoint.rpc.ResponseMessage in project pinpoint by naver.
the class ReconnectTest method serverCloseAndWrite.
@Test
public void serverCloseAndWrite() throws IOException, InterruptedException {
// when abnormal case in which server has been closed first, confirm that a client socket should be closed properly.
PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort);
PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
// just close server and request
PinpointRPCTestUtils.close(serverAcceptor);
byte[] randomByte = TestByteUtils.createRandomByte(10);
Future<ResponseMessage> response = client.request(randomByte);
response.await();
try {
response.getResult();
Assert.fail("expected exception");
} catch (Exception e) {
}
assertClientDisconnected(client);
PinpointRPCTestUtils.close(client);
}
use of com.navercorp.pinpoint.rpc.ResponseMessage in project pinpoint by naver.
the class ReconnectTest method serverFirstClose.
@Test
public void serverFirstClose() throws IOException, InterruptedException {
// when abnormal case in which server has been closed first, confirm that a socket should be closed properly.
PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort);
PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
byte[] randomByte = TestByteUtils.createRandomByte(10);
Future<ResponseMessage> response = client.request(randomByte);
response.await();
try {
response.getResult();
} catch (Exception e) {
logger.debug("timeout.", e);
}
// close server by force
PinpointRPCTestUtils.close(serverAcceptor);
assertClientDisconnected(client);
PinpointRPCTestUtils.close(client);
}
use of com.navercorp.pinpoint.rpc.ResponseMessage in project pinpoint by naver.
the class DefaultRouteHandler method onRoute0.
private TCommandTransferResponse onRoute0(RequestEvent event) {
TBase<?, ?> requestObject = event.getRequestObject();
if (requestObject == null) {
return createResponse(TRouteResult.EMPTY_REQUEST);
}
TargetClusterPoint clusterPoint = findClusterPoint(event.getDeliveryCommand());
if (clusterPoint == null) {
return createResponse(TRouteResult.NOT_FOUND);
}
if (!clusterPoint.isSupportCommand(requestObject)) {
return createResponse(TRouteResult.NOT_SUPPORTED_REQUEST);
}
Future<ResponseMessage> future = clusterPoint.request(event.getDeliveryCommand().getPayload());
boolean isCompleted = future.await();
if (!isCompleted) {
return createResponse(TRouteResult.TIMEOUT);
}
ResponseMessage responseMessage = future.getResult();
if (responseMessage == null) {
return createResponse(TRouteResult.EMPTY_RESPONSE);
}
byte[] responsePayload = responseMessage.getMessage();
if (responsePayload == null || responsePayload.length == 0) {
return createResponse(TRouteResult.EMPTY_RESPONSE, new byte[0]);
}
return createResponse(TRouteResult.OK, responsePayload);
}
use of com.navercorp.pinpoint.rpc.ResponseMessage in project pinpoint by naver.
the class AgentServiceImpl method invoke.
@Override
public PinpointRouteResponse invoke(AgentInfo agentInfo, byte[] payload, long timeout) throws TException {
TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
PinpointSocket socket = clusterManager.getSocket(agentInfo);
Future<ResponseMessage> future = null;
if (socket != null) {
future = socket.request(serializeRequest(transferObject));
}
PinpointRouteResponse response = getResponse(future, timeout);
return response;
}
use of com.navercorp.pinpoint.rpc.ResponseMessage in project pinpoint by naver.
the class AgentServiceImpl method invoke.
@Override
public Map<AgentInfo, PinpointRouteResponse> invoke(List<AgentInfo> agentInfoList, byte[] payload, long timeout) throws TException {
Map<AgentInfo, Future<ResponseMessage>> futureMap = new HashMap<>();
for (AgentInfo agentInfo : agentInfoList) {
TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
PinpointSocket socket = clusterManager.getSocket(agentInfo);
if (socket != null) {
Future<ResponseMessage> future = socket.request(serializeRequest(transferObject));
futureMap.put(agentInfo, future);
} else {
futureMap.put(agentInfo, null);
}
}
long startTime = System.currentTimeMillis();
Map<AgentInfo, PinpointRouteResponse> result = new HashMap<>();
for (Map.Entry<AgentInfo, Future<ResponseMessage>> futureEntry : futureMap.entrySet()) {
AgentInfo agentInfo = futureEntry.getKey();
Future<ResponseMessage> future = futureEntry.getValue();
PinpointRouteResponse response = getResponse(future, getTimeoutMillis(startTime, timeout));
result.put(agentInfo, response);
}
return result;
}
Aggregations