Example usage for com.google.common.util.concurrent Futures get

List of usage examples for com.google.common.util.concurrent Futures get

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Futures get.

Prototype

@Deprecated
@GwtIncompatible("reflection")
public static <V, X extends Exception> V get(Future<V> future, long timeout, TimeUnit unit,
        Class<X> exceptionClass) throws X 

Source Link

Document

Returns the result of Future#get(long,TimeUnit) , converting most exceptions to a new instance of the given checked exception type.

Usage

From source file:com.facebook.presto.util.Threads.java

public static boolean isSameThreadExecutor(Executor executor) {
    requireNonNull(executor, "executor is null");
    if (executor.getClass() == GUAVA_SAME_THREAD_EXECUTOR_CLASS) {
        return true;
    }/*  w  w w . j ava2 s .c om*/

    final Thread thisThread = Thread.currentThread();
    final SettableFuture<Boolean> isSameThreadExecutor = SettableFuture.create();
    executor.execute(new Runnable() {
        @Override
        public void run() {
            isSameThreadExecutor.set(thisThread == Thread.currentThread());
        }
    });
    try {
        return Futures.get(isSameThreadExecutor, 10, TimeUnit.SECONDS, Exception.class);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw Throwables.propagate(e);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.robotninjas.concurrent.FluentFutureTask.java

@Override
public <X extends Exception> V get(long l, TimeUnit timeUnit, Class<X> exceptionClass) throws X {
    return Futures.get(this, l, timeUnit, exceptionClass);
}

From source file:co.cask.hydrator.plugin.realtime.Kafka08SimpleApiConsumer.java

@Override
public void initialize(RealtimeContext context) throws Exception {
    super.initialize(context);

    // Setting up ZK for 08 version of Apache Kafka
    String kafkaZKConnect = getKafkaConfig().getZookeeper();
    if (kafkaZKConnect != null) {
        zkClient = ZKClientServices.delegate(ZKClients
                .reWatchOnExpire(ZKClients.retryOnFailure(ZKClientService.Builder.of(kafkaZKConnect).build(),
                        RetryStrategies.fixDelay(2, TimeUnit.SECONDS))));
        brokerService = new ZKBrokerService(zkClient);

        try {/*  ww w  .  j  ava  2 s  .  co m*/
            Futures.get(zkClient.start(), 3, TimeUnit.SECONDS, TimeoutException.class);
            Futures.get(brokerService.start(), 3, TimeUnit.SECONDS, TimeoutException.class);
        } catch (TimeoutException e) {
            Futures.get(brokerService.stop(), 3, TimeUnit.SECONDS, TimeoutException.class);
            Futures.get(zkClient.stop(), 3, TimeUnit.SECONDS, TimeoutException.class);
            throw new IllegalArgumentException(
                    String.format(
                            "Timeout while trying to start ZookeeperClient/Broker Service. "
                                    + "Check if the zookeeper connection string %s is correct.",
                            kafkaZKConnect),
                    e);
        }
    }

    kafkaConsumers = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterAccess(60, TimeUnit.SECONDS)
            .removalListener(consumerCacheRemovalListener()).build();
}

From source file:org.hawkular.metrics.api.jaxrs.MetricsServiceLifecycle.java

@PreDestroy
void destroy() {/*  w  w  w  .j  av a2  s.  c o  m*/
    Future<?> stopFuture = lifecycleExecutor.submit(this::stopServices);
    try {
        Futures.get(stopFuture, 1, MINUTES, Exception.class);
    } catch (Exception e) {
        log.errorShutdownProblem(e);
    }
    lifecycleExecutor.shutdown();
}

From source file:org.onosproject.store.flow.impl.NewDistributedFlowRuleStore.java

@Override
public FlowRuleEvent removeFlowRule(FlowEntry rule) {
    final DeviceId deviceId = rule.deviceId();
    NodeId master = mastershipService.getMasterFor(deviceId);

    if (Objects.equal(local, master)) {
        // bypass and handle it locally
        return removeFlowRuleInternal(rule);
    }//w w  w  .j a  v  a 2  s. co m

    if (master == null) {
        log.warn("Failed to removeFlowRule: No master for {}", deviceId);
        // TODO: revisit if this should be null (="no-op") or Exception
        return null;
    }

    log.trace("Forwarding removeFlowRule to {}, which is the master for device {}", master, deviceId);

    return Futures.get(clusterCommunicator.sendAndReceive(rule, REMOVE_FLOW_ENTRY, SERIALIZER::encode,
            SERIALIZER::decode, master), FLOW_RULE_STORE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS,
            RuntimeException.class);
}