當前位置: 首頁>>代碼示例>>Java>>正文


Java SettableFuture.create方法代碼示例

本文整理匯總了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];
}
 
開發者ID:Azure,項目名稱:azure-libraries-for-java,代碼行數:27,代碼來源:TestBatch.java

示例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));
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:21,代碼來源:ESClusterUpdateSettingsTask.java

示例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;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:21,代碼來源:SnapshotRestoreDDLDispatcher.java

示例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;
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:20,代碼來源:DistributedShardedDOMDataTree.java

示例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);

}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:12,代碼來源:Leader.java

示例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;

}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:16,代碼來源:DefaultOvsdbClient.java

示例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];
}
 
開發者ID:Azure,項目名稱:azure-libraries-for-java,代碼行數:39,代碼來源:TestVirtualMachine.java

示例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;
}
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:28,代碼來源:Eth62.java

示例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;
}
 
開發者ID:Aptoide,項目名稱:AppCoins-ethereumj,代碼行數:14,代碼來源:Eth63.java

示例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);
        }
    };
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:30,代碼來源:PaymentChannelStateTest.java

示例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;
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:10,代碼來源:Peer.java

示例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;

}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:14,代碼來源:DefaultOvsdbClient.java

示例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());
}
 
開發者ID:avivcarmis,項目名稱:java-red,代碼行數:53,代碼來源:TestRedFuture.java

示例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);
}
 
開發者ID:BoxtrotStudio,項目名稱:amazon-gamelift-serversdk-java,代碼行數:6,代碼來源:AuxProxyMessageSender.java

示例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());
}
 
開發者ID:avivcarmis,項目名稱:java-red,代碼行數:56,代碼來源:TestRedFuture.java


注:本文中的com.google.common.util.concurrent.SettableFuture.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。