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


Java Future.future方法代碼示例

本文整理匯總了Java中io.vertx.core.Future.future方法的典型用法代碼示例。如果您正苦於以下問題:Java Future.future方法的具體用法?Java Future.future怎麽用?Java Future.future使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.core.Future的用法示例。


在下文中一共展示了Future.future方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: delete

import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<Void> delete(SQLConnection connection, String id) {
    Future<Void> future = Future.future();
    String sql = "DELETE FROM Articles WHERE id = ?";
    connection.updateWithParams(sql,
        new JsonArray().add(Integer.valueOf(id)),
        ar -> {
            connection.close();
            if (ar.failed()) {
                future.fail(ar.cause());
            } else {
                if (ar.result().getUpdated() == 0) {
                    future.fail(new NoSuchElementException("Unknown article " + id));
                } else {
                    future.complete();
                }
            }
        }
    );
    return future;
}
 
開發者ID:cescoffier,項目名稱:introduction-to-vert.x,代碼行數:21,代碼來源:MyFirstVerticle.java

示例2: storage

import io.vertx.core.Future; //導入方法依賴的package包/類
private <E extends Storable> Future<AsyncStorage<E>> storage(Class<E> storable, String index) {
    Future<AsyncStorage<E>> future = Future.future();

    logger.event("onStorageLoad", STARTUP)
            .put("storage", config.getStorage().name())
            .put("plugin", storable.getSimpleName())
            .put("index", index).send();

    new StorageLoader<E>(context)
            .withDB(index, index)
            .withValue(storable)
            .withPlugin(config.getStoragePlugin())
            .build((storage) -> {
                if (storage.succeeded()) {
                    future.complete(storage.result());
                } else {
                    logger.log("Failed to load storage " + config.getStoragePlugin().getSimpleName() +
                            " using index" + index);
                    future.fail(storage.cause());
                }
            });

    return future;
}
 
開發者ID:codingchili,項目名稱:ethereum-ingest,代碼行數:25,代碼來源:ApplicationContext.java

示例3: start

import io.vertx.core.Future; //導入方法依賴的package包/類
@Override
public void start(Future<Void> startFuture) throws Exception {

  Future<String> dbVerticleDeployment = Future.future();
  vertx.deployVerticle(new WikiDatabaseVerticle(), dbVerticleDeployment.completer());

  dbVerticleDeployment.compose(id -> {

    Future<String> httpVerticleDeployment = Future.future();
    vertx.deployVerticle(
      "io.vertx.guides.wiki.http.HttpServerVerticle",
      new DeploymentOptions().setInstances(2),
      httpVerticleDeployment.completer());

    return httpVerticleDeployment;

  }).setHandler(ar -> {
    if (ar.succeeded()) {
      startFuture.complete();
    } else {
      startFuture.fail(ar.cause());
    }
  });
}
 
開發者ID:vert-x3,項目名稱:vertx-guide-for-java-devs,代碼行數:25,代碼來源:MainVerticle.java

示例4: deployWebSocketVerticle

import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<String> deployWebSocketVerticle(DeploymentOptions options) {
	
	Future<String> future = Future.future();
	vertx.deployVerticle(new BittrexRemoteVerticle(), options, res -> {
		  if (res.succeeded()) {
			  ws_id = res.result();
			  System.out.println("WebsocketVerticle Deployment id is: " + res.result());
			  future.complete();

		  } else {
			  System.err.println("WebsocketVerticle Deployment failed: " + res.cause().getMessage()); 
			  future.fail(res.cause());
			     
		  }
	});
	
	return future;
}
 
開發者ID:AlxGDev,項目名稱:BittrexGatherer,代碼行數:19,代碼來源:BittrexVerticle.java

示例5: importBlocks

import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<Void> importBlocks(StorableBlock block) {
    Future<Void> future = Future.future();

    if (config.isTxImport()) {
        listener.onQueueChanged(queue.incrementAndGet());

        storage.put(block, done -> {
            if (done.succeeded()) {
                if (!config.isTxImport()) {
                    listener.onImported(block.getHash(), block.getNumber());
                }
                future.complete();
            } else {
                future.fail(done.cause());
            }
            listener.onQueueChanged(queue.decrementAndGet());
        });
    } else {
        future.complete();
    }
    return future;
}
 
開發者ID:codingchili,項目名稱:ethereum-ingest,代碼行數:23,代碼來源:BlockService.java

示例6: registerReceiver

import io.vertx.core.Future; //導入方法依賴的package包/類
/**
 * Same as {@link #getReceiverRegistrator} but tries to register receiver and returns future with it
 * @param <I> Interface
 * @param vertx Vertx instance
 * @param interfaceType Class for which receiver should be generated
 * @param receiver Interface implementation that should be registered
 * @return Future that on completion returns successfully registered {@link VxRifaReceiver} and fails otherwise
 */
public static <I> Future<VxRifaReceiver<I>> registerReceiver(Vertx vertx, Class<I> interfaceType, I receiver) {
    Future<VxRifaReceiver<I>> future = Future.future();
    
    VxRifaReceiver<I> receiverRegistrator = getReceiverRegistrator(vertx, interfaceType);
    receiverRegistrator.registerReceiver(receiver).setHandler(complete -> {
        if (complete.succeeded()) {
            future.complete(receiverRegistrator);
        } else {
            future.fail(complete.cause());
        }
    });
    
    return future;
}
 
開發者ID:nsforth,項目名稱:vxrifa,代碼行數:23,代碼來源:VxRifaUtil.java

示例7: testDeployInvalidConfig

import io.vertx.core.Future; //導入方法依賴的package包/類
@Test
public void testDeployInvalidConfig(TestContext testContext) throws Exception {
	Future<Void> future = Future.future();

	future.setHandler(testContext.asyncAssertFailure(res -> {
		Assert.assertFalse(vtxDeployer.isVertxSetup());
		Assert.assertTrue("Non-existing configuration", Exception.class.isInstance(res));
	}));

	vtxDeployer.setup("sample/non-existing.json", future);
}
 
開發者ID:mustertech,項目名稱:rms-deployer,代碼行數:12,代碼來源:VtxDeployerTest.java

示例8: createTempDir

import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<Void> createTempDir(JsonObject metadata) {
    Future future = Future.future();
    String dir = metadata.getString("baseDir");
    vertx.fileSystem().mkdirs(dir, ar -> {
        if (ar.failed()) {
            log.error("Impossible to create temp directory {}: {}", dir, ar.cause().getMessage());
            future.fail(ar.cause());
        } else {
            future.complete();
        }
    });
    return future;
}
 
開發者ID:danielpetisme,項目名稱:vertx-forge,代碼行數:14,代碼來源:ForgeService.java

示例9: close

import io.vertx.core.Future; //導入方法依賴的package包/類
void close(Handler<AsyncResult<Void>> completionHandler) {
  synchronized (vertx) {
    if (--refCount == 0) {
      Future<Void> f1 = Future.future();
      Future<Void> f2 = Future.future();
      if (completionHandler != null) {
        CompositeFuture.all(f1, f2).<Void>map(f -> null).setHandler(completionHandler);
      }
      if (emf != null) {
        vertx.executeBlocking(future -> {
          emf.close();
          future.complete();
        }, f2.completer());
      } else {
        f2.complete();
      }
      try {
        if (exec != null) {
          exec.shutdown();
        }
        if (map != null) {
          map.remove(name);
          if (map.isEmpty()) {
            map.close();
          }
        }
        f1.complete();
      } catch (Throwable t) {
        f1.fail(t);
      }
    } else {
      if (completionHandler != null) {
        completionHandler.handle(Future.succeededFuture());
      }
    }
  }
}
 
開發者ID:pflima92,項目名稱:vertx-jpa,代碼行數:38,代碼來源:EntityManagerProviderImpl.java

示例10: start

import io.vertx.core.Future; //導入方法依賴的package包/類
@Override
public void start(Future<Void> fut) throws Exception {

    LOG.info("Starting KafkaStreams and Webserver");
    Future runtimeVerticleCompleter = Future.future();
    vertx.deployVerticle(runtimeVerticle, runtimeVerticleCompleter.completer());

    // Create a router object.
    Router router = Router.router(vertx);

    addRouteForMultiValuedKVQueries(router);
    addRouteForScalarKVQueries(router);

    addRouteForWindowQueries(router);
    addRouteForKVCountQueries(router);
    addRouteForSessionQueries(router);

    Future serverListener = Future.future();

    int port = vertx
            .createHttpServer(serverOptions)
            .requestHandler(router::accept)
            .listen(serverListener.completer())
            .actualPort();


    CompositeFuture.all(runtimeVerticleCompleter, serverListener).setHandler(handler -> {
        if (handler.succeeded()) {
            LOG.info("Started KafkaStreams and Webserver, listening on port " + port);
            fut.complete();
        } else {
            LOG.error("Failure during startup", handler.cause());
            fut.fail(handler.cause());
        }
    });
}
 
開發者ID:ftrossbach,項目名稱:kiqr,代碼行數:37,代碼來源:RestKiqrServerVerticle.java

示例11: tearDown

import io.vertx.core.Future; //導入方法依賴的package包/類
@AfterClass
public static void tearDown(TestContext testContext) throws Exception {
	Future<Void> future = Future.future();

	future.setHandler(testContext.asyncAssertSuccess(res -> {
		Assert.assertFalse(vtxDeployer.isVertxSetup());
	}));

	vtxDeployer.teardown(future);
}
 
開發者ID:mustertech,項目名稱:rms-deployer,代碼行數:11,代碼來源:VtxDeployerIgniteTest.java

示例12: prepareDatabase

import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<Void> prepareDatabase() {
  Future<Void> future = Future.future();

  dbClient = JDBCClient.createShared(vertx, new JsonObject()  // <1>
    .put("url", "jdbc:hsqldb:file:db/wiki")   // <2>
    .put("driver_class", "org.hsqldb.jdbcDriver")   // <3>
    .put("max_pool_size", 30));   // <4>

  dbClient.getConnection(ar -> {    // <5>
    if (ar.failed()) {
      LOGGER.error("Could not open a database connection", ar.cause());
      future.fail(ar.cause());    // <6>
    } else {
      SQLConnection connection = ar.result();   // <7>
      connection.execute(SQL_CREATE_PAGES_TABLE, create -> {
        connection.close();   // <8>
        if (create.failed()) {
          LOGGER.error("Database preparation error", create.cause());
          future.fail(create.cause());
        } else {
          future.complete();  // <9>
        }
      });
    }
  });

  return future;
}
 
開發者ID:vert-x3,項目名稱:vertx-guide-for-java-devs,代碼行數:29,代碼來源:MainVerticle.java

示例13: connect

import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<SQLConnection> connect() {
    Future<SQLConnection> future = Future.future();
    jdbc.getConnection(ar ->
        future.handle(ar.map(c ->
                c.setOptions(new SQLOptions().setAutoGeneratedKeys(true))
            )
        )
    );
    return future;
}
 
開發者ID:cescoffier,項目名稱:introduction-to-vert.x,代碼行數:11,代碼來源:MyFirstVerticle.java

示例14: toArrayFuture

import io.vertx.core.Future; //導入方法依賴的package包/類
static <T> Future<JsonArray> toArrayFuture(
        final String pojo,
        final CompletableFuture<List<T>> completableFuture
) {
    final Future<JsonArray> future = Future.future();
    Fn.safeSemi(null == completableFuture, null,
            () -> future.complete(new JsonArray()),
            () -> completableFuture.thenAcceptAsync((item) -> Fn.safeSemi(
                    null == item, null,
                    () -> future.complete(new JsonArray()),
                    () -> future.complete(To.toArray(item, pojo))
            )));
    return future;
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:15,代碼來源:Async.java

示例15: createHttpServer

import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<Void> createHttpServer(JsonObject config, Router router) {
    Future<Void> future = Future.future();
    vertx
        .createHttpServer()
        .requestHandler(router::accept)
        .listen(
            config.getInteger("HTTP_PORT", 8080),
            res -> future.handle(res.mapEmpty())
        );
    return future;
}
 
開發者ID:cescoffier,項目名稱:introduction-to-vert.x,代碼行數:12,代碼來源:MyFirstVerticle.java


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