List of usage examples for com.google.common.util.concurrent SettableFuture set
@Override public boolean set(@Nullable V value)
From source file:org.opendaylight.netconf.topology.pipeline.tx.ProxyWriteOnlyTransaction.java
@Override public ListenableFuture<RpcResult<TransactionStatus>> commit() { final Future<RpcResult<TransactionStatus>> commit = delegate.commit(); final SettableFuture<RpcResult<TransactionStatus>> settableFuture = SettableFuture.create(); commit.onComplete(new OnComplete<RpcResult<TransactionStatus>>() { @Override/*from w w w.j av a 2s .c o m*/ public void onComplete(Throwable throwable, RpcResult<TransactionStatus> transactionStatusRpcResult) throws Throwable { if (throwable == null) { settableFuture.set(transactionStatusRpcResult); } else { settableFuture.setException(throwable); } } }, actorSystem.dispatcher()); return settableFuture; }
From source file:org.apache.helix.provisioning.yarn.GenericApplicationMaster.java
public ListenableFuture<ContainerReleaseResponse> releaseContainer(Container container) { LOG.info("Requesting container RELEASE:" + container); SettableFuture<ContainerReleaseResponse> future = SettableFuture.create(); synchronized (allocatedContainerSet) { if (!allocatedContainerSet.contains(container.getId())) { future.set(new ContainerReleaseResponse()); } else {/*from w w w . j av a2 s .c o m*/ containerReleaseMap.put(container.getId(), future); amRMClient.releaseAssignedContainer(container.getId()); } } return future; }
From source file:edu.umich.si.inteco.minuku.dao.ImageDataRecordDAO.java
private final void getLastNValues(final int N, final String userEmail, final Date someDate, final List<ImageDataRecord> synchronizedListOfRecords, final SettableFuture settableFuture) { Firebase firebaseRef = new Firebase(Constants.getInstance().getFirebaseUrlForImages()).child(userEmail) .child(new SimpleDateFormat("MMddyyyy").format(someDate).toString()); Log.d(TAG, "Checking the value of N " + N); if (N <= 0) { settableFuture.set(synchronizedListOfRecords); return;//from www . ja va 2 s. c om } firebaseRef.limitToLast(N).addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { int newN = N; // dataSnapshot.exists returns false when the // <root>/<datarecord>/<userEmail>/<date> location does not exist. // What it means is that no entries were added for this date, i.e. // all the historic information has been exhausted. if (!dataSnapshot.exists()) { settableFuture.set(synchronizedListOfRecords); return; } for (DataSnapshot snapshot : dataSnapshot.getChildren()) { synchronizedListOfRecords.add(snapshot.getValue(ImageDataRecord.class)); newN--; } Date newDate = new Date(someDate.getTime() - 26 * 60 * 60 * 1000); /* -1 Day */ getLastNValues(newN, userEmail, newDate, synchronizedListOfRecords, settableFuture); } @Override public void onCancelled(FirebaseError firebaseError) { // This would mean that the firebase ref does not exist thereby meaning that // the number of entries for all dates are over before we could get the last N // results settableFuture.set(synchronizedListOfRecords); } }); }
From source file:io.v.v23.syncbase.nosql.NoSql.java
private static ListenableFuture<Boolean> tryBatch(final VContext ctx, final Database db, final BatchOptions opts, final BatchOperation op) { final SettableFuture<Boolean> ret = SettableFuture.create(); Futures.addCallback(db.beginBatch(ctx, opts), new FutureCallback<BatchDatabase>() { @Override/*from ww w . j a v a 2 s. c om*/ public void onFailure(Throwable t) { ret.setException(t); } @Override public void onSuccess(final BatchDatabase batch) { Futures.addCallback(op.run(batch), new FutureCallback<Void>() { @Override public void onFailure(final Throwable t) { Futures.addCallback(batch.abort(ctx), new FutureCallback<Void>() { @Override public void onSuccess(Void result) { ret.setException(t); } @Override public void onFailure(Throwable newT) { ret.setException(t); } }); } @Override public void onSuccess(Void result) { Futures.addCallback(batch.commit(ctx), new FutureCallback<Void>() { @Override public void onSuccess(Void result) { ret.set(true); // success } @Override public void onFailure(Throwable t) { if (t instanceof ConcurrentBatchException) { // retry ret.set(false); } else { ret.setException(t); } } }); } }); } }); return ret; }
From source file:org.apache.twill.internal.zookeeper.LeaderElection.java
private void doDeleteNode(final SettableFuture<String> completion) { if (zkNodePath == null) { completion.set(null); return;/*from w w w. j a v a 2s . c o m*/ } try { Futures.addCallback(zkClient.delete(zkNodePath), new FutureCallback<String>() { @Override public void onSuccess(String result) { LOG.debug("Node deleted: {}", result); completion.set(result); } @Override public void onFailure(Throwable t) { LOG.warn("Fail to delete node: {}", zkNodePath); if (!(t instanceof KeeperException.NoNodeException)) { LOG.debug("Retry delete node: {}", zkNodePath); doDeleteNode(completion); } else { completion.setException(t); } } }, executor); } catch (Throwable t) { // If any exception happens when calling delete, treats it as completed with failure. completion.setException(t); } }
From source file:org.apache.druid.server.coordination.BatchDataSegmentAnnouncer.java
/** * Returns Future that lists the segment load/drop requests since given counter. *///from w ww . j a v a2 s.c om public ListenableFuture<ChangeRequestsSnapshot<DataSegmentChangeRequest>> getSegmentChangesSince( ChangeRequestHistory.Counter counter) { if (counter.getCounter() < 0) { synchronized (lock) { Iterable<DataSegmentChangeRequest> segments = Iterables.transform(segmentLookup.keySet(), new Function<DataSegment, DataSegmentChangeRequest>() { @Nullable @Override public SegmentChangeRequestLoad apply(DataSegment input) { return new SegmentChangeRequestLoad(input); } }); SettableFuture<ChangeRequestsSnapshot<DataSegmentChangeRequest>> future = SettableFuture.create(); future.set(ChangeRequestsSnapshot.success(changes.getLastCounter(), Lists.newArrayList(segments))); return future; } } else { return changes.getRequestsSince(counter); } }
From source file:c5db.discovery.BeaconService.java
@Override public ListenableFuture<ImmutableMap<Long, NodeInfo>> getState() { final SettableFuture<ImmutableMap<Long, NodeInfo>> future = SettableFuture.create(); fiber.execute(() -> {/*from ww w.j a v a 2s. com*/ future.set(getCopyOfState()); }); return future; }
From source file:org.opendaylight.aaa.cert.impl.AaaCertRpcServiceImpl.java
@Override public Future<RpcResult<GetNodeCertifcateOutput>> getNodeCertifcate(GetNodeCertifcateInput input) { final SettableFuture<RpcResult<GetNodeCertifcateOutput>> futureResult = SettableFuture.create(); final String cert = aaaCertProvider.getCertificateTrustStore(input.getNodeAlias(), false); if (cert != null && !cert.isEmpty()) { final GetNodeCertifcateOutput nodeCertOutput = new GetNodeCertifcateOutputBuilder().setNodeCert(cert) .build();//from w ww .j a v a 2s .co m futureResult.set(RpcResultBuilder.<GetNodeCertifcateOutput>success(nodeCertOutput).build()); } else { futureResult.set(RpcResultBuilder.<GetNodeCertifcateOutput>failed().build()); } return futureResult; }
From source file:org.apache.bookkeeper.stream.io.Entry.java
/** * Complete record futures.//from w ww . ja v a2 s. c o m */ public SSN completeRecordFutures(long entryId) { if (!recordFutureList.isPresent()) { return SSN.INVALID_SSN; } long slotId = 0L; SSN ssn = SSN.INVALID_SSN; for (SettableFuture<SSN> future : recordFutureList.get()) { ssn = SSN.of(segmentId, entryId, slotId); future.set(ssn); ++slotId; } return ssn; }
From source file:org.opendaylight.aaa.cert.impl.AaaCertRpcServiceImpl.java
@Override public Future<RpcResult<GetODLCertificateReqOutput>> getODLCertificateReq() { final SettableFuture<RpcResult<GetODLCertificateReqOutput>> futureResult = SettableFuture.create(); final String certReq = aaaCertProvider.genODLKeyStoreCertificateReq(false); if (certReq != null && !certReq.isEmpty()) { final GetODLCertificateReqOutput odlCertReqOutput = new GetODLCertificateReqOutputBuilder() .setOdlCertReq(certReq).build(); futureResult.set(RpcResultBuilder.<GetODLCertificateReqOutput>success(odlCertReqOutput).build()); } else {/*from w w w.j a va 2s .c o m*/ futureResult.set(RpcResultBuilder.<GetODLCertificateReqOutput>failed().build()); } return futureResult; }