List of usage examples for com.google.common.util.concurrent SettableFuture notifyAll
@HotSpotIntrinsicCandidate public final native void notifyAll();
From source file:org.opendaylight.distributed.tx.impl.DTXTestTransaction.java
@Override public CheckedFuture<Void, TransactionCommitFailedException> submit() { final SettableFuture<Void> retFuture = SettableFuture.create(); final Runnable submitResult = new Runnable() { @Override//from w w w . jav a2s .com public void run() { try { Thread.sleep(delayTime); } catch (InterruptedException e) { e.printStackTrace(); } if (!submitException) { retFuture.set(null); } else { setSubmitException(false); retFuture.setException(new RuntimeException("Submit error")); } retFuture.notifyAll(); } }; new Thread(submitResult).start(); Function<Exception, TransactionCommitFailedException> f = new Function<Exception, TransactionCommitFailedException>() { @Nullable @Override public TransactionCommitFailedException apply(@Nullable Exception e) { return new TransactionCommitFailedException("Submit failed", e); } }; return Futures.makeChecked(retFuture, f); }
From source file:org.opendaylight.distributed.tx.impl.DTXTestTransaction.java
@Override public <T extends DataObject> CheckedFuture<Optional<T>, ReadFailedException> read( LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<T> instanceIdentifier) { T obj = null;/*from w w w .ja v a 2 s . c om*/ if (txDataMap.get(instanceIdentifier).size() > 0) obj = (T) txDataMap.get(instanceIdentifier).getFirst(); final Optional<T> retOpt = Optional.fromNullable(obj); final SettableFuture<Optional<T>> retFuture = SettableFuture.create(); Runnable readResult = new Runnable() { @Override public void run() { try { Thread.sleep(delayTime); } catch (InterruptedException e) { e.printStackTrace(); } boolean readException = getAndResetExceptionWithInstanceIdentifier(readExceptionMap, instanceIdentifier); if (readException == false) { retFuture.set(retOpt); } else { retFuture.setException(new Throwable("Read error")); } retFuture.notifyAll(); } }; new Thread(readResult).start(); Function<Exception, ReadFailedException> f = new Function<Exception, ReadFailedException>() { @Nullable @Override public ReadFailedException apply(@Nullable Exception e) { return new ReadFailedException("Read failed", e); } }; return Futures.makeChecked(retFuture, f); }