Search in sources :

Example 6 with ResponseMessage

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);
}
Also used : PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) IOException(java.io.IOException) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException)

Example 7 with ResponseMessage

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);
}
Also used : PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) IOException(java.io.IOException) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException)

Example 8 with ResponseMessage

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);
}
Also used : TargetClusterPoint(com.navercorp.pinpoint.collector.cluster.TargetClusterPoint) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage)

Example 9 with ResponseMessage

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;
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) PinpointRouteResponse(com.navercorp.pinpoint.web.cluster.PinpointRouteResponse) FailedPinpointRouteResponse(com.navercorp.pinpoint.web.cluster.FailedPinpointRouteResponse) DefaultPinpointRouteResponse(com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage)

Example 10 with ResponseMessage

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;
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) HashMap(java.util.HashMap) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) Future(com.navercorp.pinpoint.rpc.Future) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) PinpointRouteResponse(com.navercorp.pinpoint.web.cluster.PinpointRouteResponse) FailedPinpointRouteResponse(com.navercorp.pinpoint.web.cluster.FailedPinpointRouteResponse) DefaultPinpointRouteResponse(com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)12 PinpointSocketException (com.navercorp.pinpoint.rpc.PinpointSocketException)4 DefaultFuture (com.navercorp.pinpoint.rpc.DefaultFuture)2 FutureListener (com.navercorp.pinpoint.rpc.FutureListener)2 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)2 PinpointServerAcceptor (com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)2 TResult (com.navercorp.pinpoint.thrift.dto.TResult)2 TCommandTransfer (com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer)2 HeaderTBaseDeserializer (com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer)2 DefaultPinpointRouteResponse (com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse)2 FailedPinpointRouteResponse (com.navercorp.pinpoint.web.cluster.FailedPinpointRouteResponse)2 PinpointRouteResponse (com.navercorp.pinpoint.web.cluster.PinpointRouteResponse)2 IOException (java.io.IOException)2 TBase (org.apache.thrift.TBase)2 TargetClusterPoint (com.navercorp.pinpoint.collector.cluster.TargetClusterPoint)1 ChannelWriteFailListenableFuture (com.navercorp.pinpoint.rpc.ChannelWriteFailListenableFuture)1 FailureEventHandler (com.navercorp.pinpoint.rpc.FailureEventHandler)1 Future (com.navercorp.pinpoint.rpc.Future)1 AgentInfo (com.navercorp.pinpoint.web.vo.AgentInfo)1 HashMap (java.util.HashMap)1