Search in sources :

Example 1 with DefaultFuture

use of com.navercorp.pinpoint.rpc.DefaultFuture in project pinpoint by naver.

the class RequestManager method register.

public ChannelWriteFailListenableFuture<ResponseMessage> register(RequestPacket requestPacket, long timeoutMillis) {
    // shutdown check
    final int requestId = getNextRequestId();
    requestPacket.setRequestId(requestId);
    final ChannelWriteFailListenableFuture<ResponseMessage> future = new ChannelWriteFailListenableFuture<ResponseMessage>(timeoutMillis);
    final DefaultFuture old = this.requestMap.put(requestId, future);
    if (old != null) {
        throw new PinpointSocketException("unexpected error. old future exist:" + old + " id:" + requestId);
    }
    // when future fails, put a handle in order to remove a failed future in the requestMap.
    FailureEventHandler removeTable = createFailureEventHandler(requestId);
    future.setFailureEventHandler(removeTable);
    addTimeoutTask(timeoutMillis, future);
    return future;
}
Also used : FailureEventHandler(com.navercorp.pinpoint.rpc.FailureEventHandler) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) ChannelWriteFailListenableFuture(com.navercorp.pinpoint.rpc.ChannelWriteFailListenableFuture) DefaultFuture(com.navercorp.pinpoint.rpc.DefaultFuture)

Example 2 with DefaultFuture

use of com.navercorp.pinpoint.rpc.DefaultFuture in project pinpoint by naver.

the class RequestManagerTest method testRemoveMessageFuture.

@Test
public void testRemoveMessageFuture() throws Exception {
    HashedWheelTimer timer = getTimer();
    RequestManager requestManager = new RequestManager(timer, 3000);
    try {
        RequestPacket packet = new RequestPacket(1, new byte[0]);
        DefaultFuture future = requestManager.register(packet, 2000);
        future.setFailure(new RuntimeException());
        Future nullFuture = requestManager.removeMessageFuture(packet.getRequestId());
        Assert.assertNull(nullFuture);
    } finally {
        requestManager.close();
        timer.stop();
    }
}
Also used : RequestPacket(com.navercorp.pinpoint.rpc.packet.RequestPacket) Future(com.navercorp.pinpoint.rpc.Future) DefaultFuture(com.navercorp.pinpoint.rpc.DefaultFuture) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) DefaultFuture(com.navercorp.pinpoint.rpc.DefaultFuture) Test(org.junit.Test)

Example 3 with DefaultFuture

use of com.navercorp.pinpoint.rpc.DefaultFuture in project pinpoint by naver.

the class DefaultPinpointClientHandler method request.

public Future<ResponseMessage> request(byte[] bytes) {
    Objects.requireNonNull(bytes, "bytes");
    final boolean isEnable = state.isEnableCommunication();
    if (!isEnable) {
        DefaultFuture<ResponseMessage> closedException = new DefaultFuture<>();
        closedException.setFailure(new PinpointSocketException("invalid state:" + state.getCurrentStateCode() + " channel:" + channel));
        return closedException;
    }
    final int requestId = this.requestManager.nextRequestId();
    final RequestPacket request = new RequestPacket(requestId, bytes);
    final ChannelWriteFailListenableFuture<ResponseMessage> messageFuture = this.requestManager.register(request.getRequestId(), clientOption.getRequestTimeoutMillis());
    write0(request, messageFuture);
    return messageFuture;
}
Also used : RequestPacket(com.navercorp.pinpoint.rpc.packet.RequestPacket) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) DefaultFuture(com.navercorp.pinpoint.rpc.DefaultFuture)

Example 4 with DefaultFuture

use of com.navercorp.pinpoint.rpc.DefaultFuture in project pinpoint by naver.

the class GrpcAgentConnection method request.

@Override
public Future<ResponseMessage> request(TBase<?, ?> request) {
    GeneratedMessageV3 message = messageConverter.toMessage(request);
    if (message == null) {
        DefaultFuture<ResponseMessage> failedFuture = new DefaultFuture<>();
        failedFuture.setFailure(new PinpointSocketException(TRouteResult.NOT_SUPPORTED_REQUEST.name()));
        return failedFuture;
    }
    return pinpointGrpcServer.request(message);
}
Also used : PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) DefaultFuture(com.navercorp.pinpoint.rpc.DefaultFuture)

Example 5 with DefaultFuture

use of com.navercorp.pinpoint.rpc.DefaultFuture in project pinpoint by naver.

the class DefaultPinpointClient method returnFailureFuture.

private Future<ResponseMessage> returnFailureFuture() {
    DefaultFuture<ResponseMessage> future = new DefaultFuture<>();
    future.setFailure(new PinpointSocketException("pinpointClientHandler is null"));
    return future;
}
Also used : PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) DefaultFuture(com.navercorp.pinpoint.rpc.DefaultFuture)

Aggregations

DefaultFuture (com.navercorp.pinpoint.rpc.DefaultFuture)7 PinpointSocketException (com.navercorp.pinpoint.rpc.PinpointSocketException)6 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)5 ChannelWriteFailListenableFuture (com.navercorp.pinpoint.rpc.ChannelWriteFailListenableFuture)2 FailureEventHandler (com.navercorp.pinpoint.rpc.FailureEventHandler)2 RequestPacket (com.navercorp.pinpoint.rpc.packet.RequestPacket)2 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 Future (com.navercorp.pinpoint.rpc.Future)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 HashedWheelTimer (org.jboss.netty.util.HashedWheelTimer)1 Test (org.junit.Test)1