Search in sources :

Example 6 with DefaultFuture

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

the class RequestManager method register.

public ChannelWriteFailListenableFuture<ResponseMessage> register(int requestId, long timeoutMillis) {
    // shutdown check
    final ChannelWriteFailListenableFuture<ResponseMessage> responseFuture = new ChannelWriteFailListenableFuture<>(timeoutMillis);
    final DefaultFuture old = this.requestMap.put(requestId, responseFuture);
    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);
    responseFuture.setFailureEventHandler(removeTable);
    addTimeoutTask(responseFuture, timeoutMillis);
    return responseFuture;
}
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 7 with DefaultFuture

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

the class RequestManager method close.

// public ChannelWriteFailListenableFuture<ResponseMessage> register(final int requestId, final long timeoutMillis) {
// // shutdown check
// final ChannelWriteFailListenableFuture<ResponseMessage> responseFuture = new ChannelWriteFailListenableFuture<ResponseMessage>(timeoutMillis) {
// @Override
// public void operationComplete(ChannelFuture future) throws Exception {
// fireWriteComplete(requestId, future, this, timeoutMillis);
// }
// };
// return responseFuture;
// }
// 
// private void fireWriteComplete(int requestId, ChannelFuture ioWriteFuture, DefaultFuture<ResponseMessage> responseFuture, long timeoutMillis) {
// if (ioWriteFuture.isSuccess()) {
// final DefaultFuture old = requestMap.put(requestId, responseFuture);
// if (old != null) {
// PinpointSocketException pinpointSocketException = new PinpointSocketException("unexpected error. old responseFuture exist:" + old + " id:" + requestId);
// responseFuture.setFailure(pinpointSocketException);
// return;
// } else {
// FailureEventHandler removeTable = createFailureEventHandler(requestId);
// responseFuture.setFailureEventHandler(removeTable);
// addTimeoutTask(responseFuture, timeoutMillis);
// }
// } else {
// responseFuture.setFailure(ioWriteFuture.getCause());
// }
// }
public void close() {
    logger.debug("close()");
    final PinpointSocketException closed = new PinpointSocketException("socket closed");
    // Could you handle race conditions of "close" more precisely?
    // final Timer timer = this.timer;
    // if (timer != null) {
    // Set<Timeout> stop = timer.stop();
    // for (Timeout timeout : stop) {
    // DefaultFuture future = (DefaultFuture)timeout.getTask();
    // future.setFailure(closed);
    // }
    // }
    int requestFailCount = 0;
    for (Map.Entry<Integer, DefaultFuture<ResponseMessage>> entry : requestMap.entrySet()) {
        if (entry.getValue().setFailure(closed)) {
            requestFailCount++;
        }
    }
    this.requestMap.clear();
    if (requestFailCount > 0) {
        logger.info("requestManager failCount:{}", requestFailCount);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) 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