List of usage examples for com.google.common.util.concurrent JdkFutureAdapters listenInPoolThread
public static <V> ListenableFuture<V> listenInPoolThread(Future<V> future)
From source file:org.opendaylight.openflowplugin.openflow.md.util.TaskUtil.java
/** * @param session switch session context * @param cookie connection distinguisher cookie value * @param messageService message dispatch service instance * @return barrier response/*www . java 2 s. c om*/ */ public static RpcInputOutputTuple<BarrierInput, ListenableFuture<RpcResult<BarrierOutput>>> sendBarrier( SessionContext session, SwitchConnectionDistinguisher cookie, IMessageDispatchService messageService) { BarrierInput barrierInput = MessageFactory.createBarrier(session.getFeatures().getVersion(), session.getNextXid()); Future<RpcResult<BarrierOutput>> barrierResult = messageService.barrier(barrierInput, cookie); ListenableFuture<RpcResult<BarrierOutput>> output = JdkFutureAdapters.listenInPoolThread(barrierResult); return new RpcInputOutputTuple<>(barrierInput, output); }
From source file:org.opendaylight.openflowplugin.impl.util.BarrierUtil.java
/** * chain a barrier message - regardless of previous result and use given {@link Function} to combine * original result and barrier result//from www. j a v a 2s.c om * * @param <T> type of input future * @param input future to chain barrier to * @param nodeRef target device * @param transactionService barrier service * @param compositeTransform * @return future holding both results (input and of the barrier) */ public static <T> ListenableFuture<RpcResult<T>> chainBarrier(final ListenableFuture<RpcResult<T>> input, final NodeRef nodeRef, final FlowCapableTransactionService transactionService, final Function<Pair<RpcResult<T>, RpcResult<Void>>, RpcResult<T>> compositeTransform) { final MutablePair<RpcResult<T>, RpcResult<Void>> resultPair = new MutablePair<>(); // store input result and append barrier final ListenableFuture<RpcResult<Void>> barrierResult = Futures.transform(input, new AsyncFunction<RpcResult<T>, RpcResult<Void>>() { @Override public ListenableFuture<RpcResult<Void>> apply(@Nullable final RpcResult<T> interInput) throws Exception { resultPair.setLeft(interInput); final SendBarrierInput barrierInput = createSendBarrierInput(nodeRef); return JdkFutureAdapters.listenInPoolThread(transactionService.sendBarrier(barrierInput)); } }); // store barrier result and return initiated pair final ListenableFuture<Pair<RpcResult<T>, RpcResult<Void>>> compositeResult = Futures .transform(barrierResult, new Function<RpcResult<Void>, Pair<RpcResult<T>, RpcResult<Void>>>() { @Nullable @Override public Pair<RpcResult<T>, RpcResult<Void>> apply(@Nullable final RpcResult<Void> input) { resultPair.setRight(input); return resultPair; } }); // append assembling transform to barrier result return Futures.transform(compositeResult, compositeTransform); }
From source file:org.wisdom.executors.ScheduledTask.java
protected ScheduledTask<V> submittedScheduledTask(ScheduledFuture delegate) { this.submissionDate = System.currentTimeMillis(); this.scheduledFuture = delegate; this.future = JdkFutureAdapters.listenInPoolThread(delegate); return this; }
From source file:org.opendaylight.protocol.bgp.rib.impl.BgpPeerRpc.java
@Override public Future<RpcResult<Void>> routeRefreshRequest(final RouteRefreshRequestInput input) { final ChannelFuture f = sendRRMessage(input); if (f != null) { return Futures.transform(JdkFutureAdapters.listenInPoolThread(f), new Function<Void, RpcResult<Void>>() { @Override/*from w w w .ja v a 2 s .co m*/ public RpcResult<Void> apply(final Void input) { if (f.isSuccess()) { return RpcResultBuilder.<Void>success().build(); } else { return RpcResultBuilder.<Void>failed().withError(ErrorType.RPC, FAILURE_MSG) .build(); } } }); } return RpcResultBuilder.<Void>failed() .withError(ErrorType.RPC, FAILURE_MSG + " due to unsupported address families.").buildFuture(); }
From source file:com.github.avarabyeu.wills.Wills.java
/** * Creates Will object from JKS's {@link java.util.concurrent.Future} * * @param future JKS's Future//ww w. jav a 2s . co m * @param <A> Type of Future and Will to be created * @return Created Will */ public static <A> Will<A> forFuture(Future<A> future) { return new Of<A>(JdkFutureAdapters.listenInPoolThread(future)); }
From source file:com.boundlessgeo.suite.geoserver.cloudwatch.aws.CloudwatchSender.java
/** * Invoked by spring on a timer to get and send from all metric providers *///from www . ja va2 s . c om public void sendAllMetrics() { if (!enabled) { logger.debug("Metrics are disabled...returning"); return; } logger.debug("Sending all metrics"); for (MetricProvider mp : providers) { if (!mp.getEnabled()) continue; for (final MetricDatum md : mp.getMetrics()) { try { PutMetricDataRequest request = new PutMetricDataRequest().withNamespace("geoserver") .withMetricData(md); logger.trace("Sending statistic {}", md.getMetricName()); ListenableFuture<java.lang.Void> f = JdkFutureAdapters .listenInPoolThread(cloudwatch.putMetricDataAsync(request)); Futures.addCallback(f, new FutureCallback<java.lang.Void>() { public void onSuccess(java.lang.Void ignored) { logger.trace("Sent statistic {}", md.getMetricName()); } public void onFailure(Throwable ex) { logger.error("Error sending metric: {}", md.getMetricName(), ex); } }); } catch (AmazonClientException ex) { logger.warn("Error sending AWS metric {}", md.getMetricName()); } } } }
From source file:com.google.wave.api.robot.HttpRobotConnection.java
@Override public ListenableFuture<String> asyncGet(final String url) { return JdkFutureAdapters.listenInPoolThread(executor.submit(new Callable<String>() { @Override/*from w w w . j a v a 2 s .co m*/ public String call() throws RobotConnectionException { return get(url); } })); }
From source file:com.spotify.helios.servicescommon.GooglePubSubSender.java
@Override public void send(final String topic, final byte[] message) { final String combinedTopic = topicPrefix + topic; if (!healthchecker.isHealthy()) { log.warn(/*from w ww. j ava2 s .c o m*/ "will not publish message to pubsub topic={} as the pubsub client " + "appears to be unhealthy", combinedTopic); return; } try { Futures.addCallback( JdkFutureAdapters.listenInPoolThread( pubsub.publishAsync(combinedTopic, Message.of(ByteArray.copyFrom(message)))), new FutureCallback<String>() { @Override public void onSuccess(@Nullable final String ackId) { log.debug("Sent an event to Google PubSub, topic: {}, ack: {}", combinedTopic, ackId); } @Override public void onFailure(final Throwable th) { log.warn("Unable to send an event to Google PubSub, topic: {}", combinedTopic, th); } }); } catch (Exception e) { log.warn("Failed to publish Google PubSub message, topic: {}", combinedTopic, e); } }
From source file:com.google.wave.api.robot.HttpRobotConnection.java
@Override public ListenableFuture<String> asyncPostJson(final String url, final String body) { return JdkFutureAdapters.listenInPoolThread(executor.submit(new Callable<String>() { @Override// w w w . ja v a 2 s. co m public String call() throws RobotConnectionException { return postJson(url, body); } })); }
From source file:org.wisdom.executors.Task.java
protected Task<V> submitted(Future<V> future) { this.submissionDate = System.currentTimeMillis(); this.future = JdkFutureAdapters.listenInPoolThread(future); return this; }