All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.navercorp.pinpoint.grpc.channelz.ChannelzUtils Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package com.navercorp.pinpoint.grpc.channelz;

import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import io.grpc.InternalInstrumented;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public final class ChannelzUtils {
    private static final Logger logger = LoggerFactory.getLogger(ChannelzUtils.class);

    private static final long timeout = 3000L;

    private ChannelzUtils() {
    }

    public static  T getResult(String name, InternalInstrumented instrumented) {
        final ListenableFuture future = instrumented.getStats();
        try {
            return future.get(timeout, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (ExecutionException e) {
            logger.info("ExecutionError {} {}", name, e.getMessage());
        } catch (TimeoutException e) {
            logger.info("Timeout {} {}", name, e.getMessage());
        }
        return null;
    }

    public static  List getResults(String name, List> instrumentedList) {
        Objects.requireNonNull(instrumentedList, "instrumentedList");

        final List> listenableFutures = new ArrayList<>(instrumentedList.size());
        for (InternalInstrumented each : instrumentedList) {
            listenableFutures.add(each.getStats());
        }
        ListenableFuture> listListenableFuture = Futures.allAsList(listenableFutures);
        try {
            return listListenableFuture.get(timeout, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (ExecutionException e) {
            logger.info("ExecutionError {} {}", name, e.getMessage());
        } catch (TimeoutException e) {
            logger.info("Timeout {} {}", name, e.getMessage());
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy