本文整理汇总了Java中com.google.common.util.concurrent.SettableFuture.create方法的典型用法代码示例。如果您正苦于以下问题:Java SettableFuture.create方法的具体用法?Java SettableFuture.create怎么用?Java SettableFuture.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.util.concurrent.SettableFuture
的用法示例。
在下文中一共展示了SettableFuture.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createResource
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public BatchAccount createResource(BatchAccounts resources) throws Exception {
final String batchAccountName = "batch" + this.testId;
final BatchAccount[] batchAccounts = new BatchAccount[1];
final SettableFuture<BatchAccount> future = SettableFuture.create();
Observable<Indexable> resourceStream = resources.define(batchAccountName)
.withRegion(Region.INDIA_CENTRAL)
.withNewResourceGroup()
.withTag("mytag", "testtag")
.createAsync();
Utils.<BatchAccount>rootResource(resourceStream)
.subscribe(new Action1<BatchAccount>() {
@Override
public void call(BatchAccount batchAccount) {
future.set(batchAccount);
}
});
batchAccounts[0] = future.get();
Assert.assertNull(batchAccounts[0].autoStorage());
return batchAccounts[0];
}
示例2: ESClusterUpdateSettingsTask
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
public ESClusterUpdateSettingsTask(UUID jobId,
TransportClusterUpdateSettingsAction transport,
ESClusterUpdateSettingsNode node) {
super(jobId);
this.transport = transport;
final SettableFuture<TaskResult> result = SettableFuture.create();
results = Collections.<ListenableFuture<TaskResult>>singletonList(result);
request = new ClusterUpdateSettingsRequest();
request.persistentSettings(node.persistentSettings());
request.transientSettings(node.transientSettings());
if (node.persistentSettingsToRemove() != null) {
request.persistentSettingsToRemove(node.persistentSettingsToRemove());
}
if (node.transientSettingsToRemove() != null) {
request.transientSettingsToRemove(node.transientSettingsToRemove());
}
listener = ActionListeners.wrap(result, Functions.constant(TaskResult.ONE_ROW));
}
示例3: dispatch
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
public ListenableFuture<Long> dispatch(final RestoreSnapshotAnalyzedStatement analysis) {
final SettableFuture<Long> resultFuture = SettableFuture.create();
boolean waitForCompletion = analysis.settings().getAsBoolean(WAIT_FOR_COMPLETION.settingName(), WAIT_FOR_COMPLETION.defaultValue());
boolean ignoreUnavailable = analysis.settings().getAsBoolean(IGNORE_UNAVAILABLE.settingName(), IGNORE_UNAVAILABLE.defaultValue());
// ignore_unavailable as set by statement
IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen());
RestoreSnapshotRequest request = new RestoreSnapshotRequest(analysis.repositoryName(), analysis.snapshotName())
.indices(analysis.indices())
.indicesOptions(indicesOptions)
.settings(analysis.settings())
.waitForCompletion(waitForCompletion)
.includeGlobalState(false)
.includeAliases(true);
ActionListener<RestoreSnapshotResponse> listener = ActionListeners.wrap(resultFuture, Functions.constant(1L));
transportActionProvider.transportRestoreSnapshotAction().execute(request, listener);
return resultFuture;
}
示例4: lookupConfigShard
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
private ListenableFuture<Void> lookupConfigShard(final LogicalDatastoreType type) {
final SettableFuture<Void> future = SettableFuture.create();
final Future<Object> ask =
Patterns.ask(shardedDataTreeActor, new StartConfigShardLookup(type), SHARD_FUTURE_TIMEOUT);
ask.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable throwable, final Object result) throws Throwable {
if (throwable != null) {
future.setException(throwable);
} else {
future.set(null);
}
}
}, actorSystem.dispatcher());
return future;
}
示例5: commitOperation
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Nonnull
@Override
public ListenableFuture<Boolean> commitOperation(@Nonnull RaftStateContext ctx, @Nonnull byte[] operation) throws RaftException {
resetTimeout(ctx);
long index = log.append(operation);
SettableFuture<Boolean> f = SettableFuture.create();
requests.put(index, f);
return commit(ctx);
}
示例6: transact
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public ListenableFuture<List<JsonNode>> transact(DatabaseSchema dbSchema,
List<Operation> operations) {
String id = java.util.UUID.randomUUID().toString();
String transactString = JsonRpcWriterUtil.transactStr(id, dbSchema,
operations);
SettableFuture<List<JsonNode>> sf = SettableFuture.create();
requestResult.put(id, sf);
requestMethod.put(id, "transact");
channel.writeAndFlush(transactString);
return sf;
}
示例7: createResource
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
final String vmName = "vm" + this.testId;
final VirtualMachine[] vms = new VirtualMachine[1];
final SettableFuture<VirtualMachine> future = SettableFuture.create();
Observable<Indexable> resourceStream = virtualMachines.define(vmName)
.withRegion(Region.US_EAST)
.withNewResourceGroup()
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIPAddressDynamic()
.withoutPrimaryPublicIPAddress()
.withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER)
.withAdminUsername("testuser")
.withAdminPassword("12NewPA$$w0rd!")
.withNewDataDisk(150)
.withSize(VirtualMachineSizeTypes.STANDARD_D1_V2)
.createAsync();
Utils.<VirtualMachine>rootResource(resourceStream)
.subscribe(new Action1<VirtualMachine>() {
@Override
public void call(VirtualMachine virtualMachine) {
future.set(virtualMachine);
}
});
vms[0] = future.get();
Assert.assertEquals(1, vms[0].dataDisks().size());
VirtualMachineDataDisk dataDisk = vms[0].dataDisks().values().iterator().next();
Assert.assertEquals(150, dataDisk.size());
Assert.assertEquals(128, vms[0].osDiskSize());
Disk osDisk = virtualMachines.manager().disks().getById(vms[0].osDiskId());
Assert.assertNotNull(osDisk);
Assert.assertEquals(128, osDisk.sizeInGB());
return vms[0];
}
示例8: sendGetBlockBodies
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public synchronized ListenableFuture<List<Block>> sendGetBlockBodies(List<BlockHeaderWrapper> headers) {
if (peerState != IDLE) return null;
peerState = BLOCK_RETRIEVING;
sentHeaders.clear();
sentHeaders.addAll(headers);
if(logger.isTraceEnabled()) logger.trace(
"Peer {}: send GetBlockBodies, hashes.count [{}]",
channel.getPeerIdShort(),
sentHeaders.size()
);
List<byte[]> hashes = new ArrayList<>(headers.size());
for (BlockHeaderWrapper header : headers) {
hashes.add(header.getHash());
}
GetBlockBodiesMessage msg = new GetBlockBodiesMessage(hashes);
sendMessage(msg);
lastReqSentTime = System.currentTimeMillis();
futureBlocks = SettableFuture.create();
return futureBlocks;
}
示例9: requestReceipts
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
public synchronized ListenableFuture<List<List<TransactionReceipt>>> requestReceipts(List<byte[]> hashes) {
if (peerState != PeerState.IDLE) return null;
GetReceiptsMessage msg = new GetReceiptsMessage(hashes);
requestedReceipts = hashes;
peerState = PeerState.RECEIPT_RETRIEVING;
requestReceiptsFuture = SettableFuture.create();
sendMessage(msg);
lastReqSentTime = System.currentTimeMillis();
return requestReceiptsFuture;
}
示例10: setUp
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
Utils.setMockClock(); // Use mock clock
super.setUp();
Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false));
wallet.addExtension(new StoredPaymentChannelClientStates(wallet, new TransactionBroadcaster() {
@Override
public TransactionBroadcast broadcastTransaction(Transaction tx) {
fail();
return null;
}
}));
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN);
chain = new BlockChain(PARAMS, wallet, blockStore); // Recreate chain as sendMoneyToWallet will confuse it
serverWallet = new Wallet(PARAMS);
serverKey = serverWallet.freshReceiveKey();
chain.addWallet(serverWallet);
broadcasts = new LinkedBlockingQueue<>();
mockBroadcaster = new TransactionBroadcaster() {
@Override
public TransactionBroadcast broadcastTransaction(Transaction tx) {
SettableFuture<Transaction> future = SettableFuture.create();
broadcasts.add(new TxFuturePair(tx, future));
return TransactionBroadcast.createMockBroadcast(tx, future);
}
};
}
示例11: sendSingleGetData
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
/** Sends a getdata with a single item in it. */
private ListenableFuture sendSingleGetData(GetDataMessage getdata) {
// This does not need to be locked.
Preconditions.checkArgument(getdata.getItems().size() == 1);
GetDataRequest req = new GetDataRequest(getdata.getItems().get(0).hash, SettableFuture.create());
getDataFutures.add(req);
sendMessage(getdata);
return req.future;
}
示例12: listDbs
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public ListenableFuture<List<String>> listDbs() {
String id = java.util.UUID.randomUUID().toString();
String listDbsString = JsonRpcWriterUtil.listDbsStr(id);
SettableFuture<List<String>> sf = SettableFuture.create();
requestResult.put(id, sf);
requestMethod.put(id, "listDbs");
channel.writeAndFlush(listDbsString);
return sf;
}
示例13: testCautiousAdoptProvidePreResolveSuccess
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
/**
* Test the completion and callback invocation of {@link RedFutureHub}
* cautious union of provided and adopted futures that previously were successfully resolved
*/
@Test
public void testCautiousAdoptProvidePreResolveSuccess() throws Throwable {
AtomicBoolean reachedSuccessBlock = new AtomicBoolean(false);
AtomicBoolean reachedFailureBlock = new AtomicBoolean(false);
AtomicBoolean reachedFinallyBlock = new AtomicBoolean(false);
RedFutureHub hub = RedFuture.hub();
OpenRedFuture future1 = RedFuture.future();
OpenRedFuture future2 = RedFuture.future();
OpenRedFuture future3 = RedFuture.future();
OpenRedFuture future4 = hub.provideFuture();
OpenRedFutureOf<Object> futureOf1 = hub.provideFutureOf();
OpenRedFutureOf<Object> futureOf2 = hub.provideFutureOf();
SettableFuture<Object> settableFuture1 = SettableFuture.create();
SettableFuture<Object> settableFuture2 = SettableFuture.create();
SettableFuture<Object> settableFuture3 = SettableFuture.create();
SettableFuture<Object> settableFuture4 = SettableFuture.create();
SettableFuture<Object> settableFuture5 = SettableFuture.create();
List<RedFuture> redFutureCollection = new LinkedList<>();
redFutureCollection.add(future2);
redFutureCollection.add(futureOf1);
List<ListenableFuture> listenableFutureCollection = new LinkedList<>();
listenableFutureCollection.add(settableFuture1);
listenableFutureCollection.add(settableFuture2);
hub.adoptFuture(future1);
hub.adoptFutures(redFutureCollection);
hub.adoptFutures(future3, futureOf2);
hub.adoptListenableFuture(settableFuture3);
hub.adoptListenableFutures(listenableFutureCollection);
hub.adoptListenableFutures(settableFuture4, settableFuture5);
future1.resolve();
future2.resolve();
future3.resolve();
future4.resolve();
futureOf1.resolve(new Object());
futureOf2.resolve(new Object());
settableFuture1.set(new Object());
settableFuture2.set(new Object());
settableFuture3.set(new Object());
settableFuture4.set(new Object());
settableFuture5.set(new Object());
RedFuture union = hub.uniteCautiously();
union.addSuccessCallback(() -> reachedSuccessBlock.set(true));
union.addFailureCallback(throwable -> reachedFailureBlock.set(true));
union.addFinallyCallback(() -> reachedFinallyBlock.set(true));
Assert.assertTrue(reachedFinallyBlock.get());
Assert.assertTrue(reachedSuccessBlock.get());
Assert.assertFalse(reachedFailureBlock.get());
}
示例14: emitEvent
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
public GenericOutcome emitEvent(Message message) {
SettableFuture<GenericOutcome> future = SettableFuture.create();
Ack ack = createAckFunction(future);
return emitEvent(message, ack, future, GENERIC_ERROR);
}
示例15: testCautiousAdoptProvidePostResolveFailure
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
/**
* Test the completion and callback invocation of {@link RedFutureHub}
* cautious union of provided and adopted futures that later were failed
*/
@Test
public void testCautiousAdoptProvidePostResolveFailure() throws Throwable {
AtomicBoolean reachedSuccessBlock = new AtomicBoolean(false);
AtomicBoolean reachedFailureBlock = new AtomicBoolean(false);
AtomicBoolean reachedFinallyBlock = new AtomicBoolean(false);
RedFutureHub hub = RedFuture.hub();
OpenRedFuture future1 = RedFuture.future();
OpenRedFuture future2 = RedFuture.future();
OpenRedFuture future3 = RedFuture.future();
OpenRedFuture future4 = hub.provideFuture();
OpenRedFutureOf<Object> futureOf1 = hub.provideFutureOf();
OpenRedFutureOf<Object> futureOf2 = hub.provideFutureOf();
SettableFuture<Object> settableFuture1 = SettableFuture.create();
SettableFuture<Object> settableFuture2 = SettableFuture.create();
SettableFuture<Object> settableFuture3 = SettableFuture.create();
SettableFuture<Object> settableFuture4 = SettableFuture.create();
SettableFuture<Object> settableFuture5 = SettableFuture.create();
List<RedFuture> redFutureCollection = new LinkedList<>();
redFutureCollection.add(future2);
redFutureCollection.add(futureOf1);
List<ListenableFuture> listenableFutureCollection = new LinkedList<>();
listenableFutureCollection.add(settableFuture1);
listenableFutureCollection.add(settableFuture2);
hub.adoptFuture(future1);
hub.adoptFutures(redFutureCollection);
hub.adoptFutures(future3, futureOf2);
hub.adoptListenableFuture(settableFuture3);
hub.adoptListenableFutures(listenableFutureCollection);
hub.adoptListenableFutures(settableFuture4, settableFuture5);
RedFuture union = hub.uniteCautiously();
union.addSuccessCallback(() -> reachedSuccessBlock.set(true));
union.addFailureCallback(throwable -> reachedFailureBlock.set(true));
union.addFinallyCallback(() -> reachedFinallyBlock.set(true));
future1.resolve();
future2.resolve();
future3.resolve();
future4.resolve();
futureOf1.resolve(new Object());
futureOf2.resolve(new Object());
settableFuture1.setException(new TestException());
settableFuture2.set(new Object());
settableFuture3.set(new Object());
settableFuture4.set(new Object());
Assert.assertFalse(reachedFinallyBlock.get());
Assert.assertFalse(reachedSuccessBlock.get());
Assert.assertFalse(reachedFailureBlock.get());
settableFuture5.set(new Object());
Assert.assertTrue(reachedFinallyBlock.get());
Assert.assertFalse(reachedSuccessBlock.get());
Assert.assertTrue(reachedFailureBlock.get());
}