List of usage examples for com.google.common.util.concurrent SettableFuture create
public static <V> SettableFuture<V> create()
From source file:se.sics.dozy.DozySyncComp.java
@Override public <E extends KompicsEvent & Identifiable> DozyResult sendReq(E req, long timeout) { SettableFuture<DozyResult> futureResult = SettableFuture.create(); trigger(new DozySyncEvent(req, futureResult, timeout), selfPort.getPair()); DozyResult result;/* ww w .j a va 2 s.c o m*/ try { result = futureResult.get(); } catch (InterruptedException ex) { result = DozyResult.internalError("dozy problem"); } catch (ExecutionException ex) { result = DozyResult.internalError("dozy problem"); } return result; }
From source file:org.robotninjas.barge.log.RaftLog.java
private SettableFuture<Object> storeEntry(final long index, @Nonnull Entry entry) { LOGGER.debug("{}", entry); journal.appendEntry(entry, index);/*from w w w. ja va 2s . c o m*/ log.put(index, entry); SettableFuture<Object> result = SettableFuture.create(); operationResults.put(index, result); return result; }
From source file:com.google.cloud.bigtable.grpc.async.BulkRead.java
/** * Adds the key in the request to a list of to look up in a batch read. * * @param request a {@link com.google.bigtable.v2.ReadRowsRequest} with a single row key. * @return a {@link com.google.common.util.concurrent.ListenableFuture} that will be populated with the {@link com.google.bigtable.v2.Row} that * corresponds to the request//w w w .j a v a2 s . c o m * @throws java.lang.InterruptedException if any. */ public ListenableFuture<List<Row>> add(ReadRowsRequest request) throws InterruptedException { Preconditions.checkNotNull(request); Preconditions.checkArgument(request.getRows().getRowKeysCount() == 1); ByteString rowKey = request.getRows().getRowKeysList().get(0); Preconditions.checkArgument(!rowKey.equals(ByteString.EMPTY)); RowFilter filter = request.getFilter(); if (currentFilter == null) { currentFilter = filter; } else if (!filter.equals(currentFilter)) { // TODO: this should probably also happen if there is some maximum number of flush(); currentFilter = filter; } if (futures == null) { futures = HashMultimap.create(); } SettableFuture<List<Row>> future = SettableFuture.create(); futures.put(rowKey, future); return future; }
From source file:org.opendaylight.controller.cluster.datastore.TransactionProxy.java
private <T> CheckedFuture<T, ReadFailedException> executeRead(String shardName, final AbstractRead<T> readCmd) { Preconditions.checkState(type != TransactionType.WRITE_ONLY, "Reads from write-only transactions are not allowed"); if (LOG.isDebugEnabled()) { LOG.debug("Tx {} {} {}", getIdentifier(), readCmd.getClass().getSimpleName(), readCmd.getPath()); }//from www.ja v a2 s .c o m final SettableFuture<T> proxyFuture = SettableFuture.create(); TransactionContextWrapper contextWrapper = getContextWrapper(shardName); contextWrapper.maybeExecuteTransactionOperation(new TransactionOperation() { @Override public void invoke(TransactionContext transactionContext) { transactionContext.executeRead(readCmd, proxyFuture); } }); return MappingCheckedFuture.create(proxyFuture, ReadFailedException.MAPPER); }
From source file:io.prestosql.plugin.hive.util.AsyncQueue.java
private synchronized List<T> getBatch(int maxSize) { int oldSize = elements.size(); int reduceBy = Math.min(maxSize, oldSize); if (reduceBy == 0) { return ImmutableList.of(); }/* w ww .j av a2s .co m*/ List<T> result = new ArrayList<>(reduceBy); for (int i = 0; i < reduceBy; i++) { result.add(elements.remove()); } // This checks that the queue size changed from above threshold to below. Therefore, writers shall be notified. if (oldSize >= targetQueueSize && oldSize - reduceBy < targetQueueSize) { completeAsync(executor, notFullSignal); notFullSignal = SettableFuture.create(); } return result; }
From source file:io.prestosql.split.MockSplitSource.java
@Override public ListenableFuture<SplitBatch> getNextBatch(ConnectorPartitionHandle partitionHandle, Lifespan lifespan, int maxSize) { if (partitionHandle != NOT_PARTITIONED) { throw new UnsupportedOperationException(); }//from w ww . j a v a2 s.c o m checkArgument(Lifespan.taskWide().equals(lifespan)); checkState(nextBatchFuture.isDone(), "concurrent getNextBatch invocation"); nextBatchFuture = SettableFuture.create(); nextBatchMaxSize = maxSize; nextBatchInvocationCount++; doGetNextBatch(); return Futures.transform(nextBatchFuture, splits -> new SplitBatch(splits, isFinished()), directExecutor()); }
From source file:co.cask.hydrator.plugin.RunExternalProgramExecutor.java
/** * Sends input to the executable threads, and emits the output structured records. * * @param line - Space separated sequence of the inputs that will be passed as STDIN to the executable binary. * @param emitter/* ww w . ja v a2 s .c om*/ * @param structuredRecord * @param outputSchema */ void submit(String line, Emitter<StructuredRecord> emitter, StructuredRecord structuredRecord, Schema outputSchema) { SettableFuture<String> completion = SettableFuture.create(); try { eventQueue.put(new Event(line, completion)); Futures.successfulAsList(completion).get(); // Read the output and emit the structured record. for (String output : outputList) { StructuredRecord.Builder builder = StructuredRecord.builder(outputSchema); for (Schema.Field field : outputSchema.getFields()) { if (structuredRecord.getSchema().getField(field.getName()) != null) { builder.set(field.getName(), structuredRecord.get(field.getName())); } else { if (field.getSchema().getType().equals(Schema.Type.STRING)) { builder.set(field.getName(), output); } else { builder.convertAndSet(field.getName(), output); } } } emitter.emit(builder.build()); outputList.clear(); } } catch (Exception e) { completion.setException(e); } }
From source file:com.navercorp.nbasearc.gcp.GatewayConnectionPool.java
private SettableFuture<?> closeGateways(SettableFuture<?> previousCloseJob) { final SettableFuture<?> future = SettableFuture.create(); previousCloseJob.addListener(new Runnable() { @Override/*from w w w .j av a2 s .c om*/ public void run() { final AtomicInteger closeGwCnt = new AtomicInteger(gwMap.size()); if (gwMap.isEmpty()) { future.set(null); return; } for (Gateway gw : gwMap.values()) { delGw(gw.getId(), gw.getIp(), gw.getPort()).addListener(new Runnable() { @Override public void run() { if (closeGwCnt.decrementAndGet() == 0) { future.set(null); } } }, MoreExecutors.directExecutor()); } } }, MoreExecutors.directExecutor()); return future; }
From source file:org.opendaylight.ocpplugin.impl.services.SalDeviceMgmtServiceImpl.java
@Override public Future<RpcResult<SetTimeOutput>> setTime(final SetTimeInput input) { ListenableFuture<RpcResult<org.opendaylight.yang.gen.v1.urn.opendaylight.ocp.protocol.rev150811.SetTimeOutput>> future = setTime .handleServiceCall(input);/* w ww. ja va2s.co m*/ final SettableFuture<RpcResult<SetTimeOutput>> finalFuture = SettableFuture.create(); Futures.addCallback(future, new FutureCallback<RpcResult<org.opendaylight.yang.gen.v1.urn.opendaylight.ocp.protocol.rev150811.SetTimeOutput>>() { @Override public void onSuccess( final RpcResult<org.opendaylight.yang.gen.v1.urn.opendaylight.ocp.protocol.rev150811.SetTimeOutput> result) { org.opendaylight.yang.gen.v1.urn.opendaylight.ocp.protocol.rev150811.SetTimeOutput output = result .getResult(); SetTimeOutputBuilder builder = new SetTimeOutputBuilder(); builder.setResult(output.getResult()); RpcResultBuilder<SetTimeOutput> rpcResultBuilder = RpcResultBuilder.success(builder); finalFuture.set(rpcResultBuilder.build()); } @Override public void onFailure(final Throwable t) { RpcResultBuilder<SetTimeOutput> rpcResultBuilder = RpcResultBuilder.failed(); finalFuture.set(rpcResultBuilder.build()); } }); return finalFuture; }
From source file:org.opendaylight.aaa.cert.impl.AaaCertRpcServiceImpl.java
@Override public Future<RpcResult<Void>> setODLCertifcate(SetODLCertifcateInput input) { final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create(); if (aaaCertProvider.addCertificateODLKeyStore(input.getOdlCertAlias(), input.getOdlCert())) { futureResult.set(RpcResultBuilder.<Void>success().build()); } else {/*from w w w . j a v a2 s . c om*/ futureResult.set(RpcResultBuilder.<Void>failed().build()); LOG.info("Error while adding ODL certificate"); } return futureResult; }