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


Java Future.compose方法代碼示例

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


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

示例1: redeployVerticles

import io.vertx.core.Future; //導入方法依賴的package包/類
private void redeployVerticles(DeploymentOptions options){
	Future<String> future1 = undeployVerticles();
	future1.compose(s1 -> {
		  
		Future<String> future2 = deployVerticles(options);
		future2.setHandler(handler -> {
			if (handler.succeeded()) {
			
				System.out.println("Redployment successful!");
				
			} else {
				System.err.println("Redeployment failed: " + handler.cause().getMessage());
				
			}
		});
	}, Future.future().setHandler(handler -> {
		System.err.println("Redeployment failed: " + handler.cause().getMessage());
		
	}));
}
 
開發者ID:AlxGDev,項目名稱:BittrexGatherer,代碼行數:21,代碼來源:BittrexVerticle.java

示例2: deployVerticles

import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<String> deployVerticles(DeploymentOptions options){
	Future<String> future = Future.future();
	
	
	Future<String> future1 = deployOrderBookVerticle(options);
	
	future1.compose(s1 -> {
		  
		Future<String> future2 = deployPriceVerticle(options);
		// Define future2 composition
		future2.compose(s2 -> {
				// Because the future3 is the last, we define here a handler
				Future<String> future3 = deployWebSocketVerticle(options);
				  future3.setHandler(handler -> {
						if (handler.succeeded()) {
						
							System.out.println("Deployment successful!");
							future.complete("Deployment successful!");
						} else {
							System.err.println("Deployment failed: " + handler.cause().getMessage());
							future.fail(handler.cause().getMessage());
						}
					});
			} , Future.future().setHandler(handler -> {
				System.err.println("Deployment failed: " + handler.cause().getMessage());
				future.fail(handler.cause().getMessage());
			}));
	}, Future.future().setHandler(handler -> {
		System.err.println("Deployment failed: " + handler.cause().getMessage());
		future.fail(handler.cause().getMessage());
	}));
	
	return future;
	
}
 
開發者ID:AlxGDev,項目名稱:BittrexGatherer,代碼行數:36,代碼來源:BittrexVerticle.java

示例3: undeployVerticles

import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<String> undeployVerticles(){
	Future<String> future = Future.future();
	
	Future<String> future1 = undeployOrderBookVerticle();
	
	future1.compose(s1 -> {
		  
		Future<String> future2 = undeployPriceVerticle();
		// Define future2 composition
		future2.compose(s2 -> {
				// Because the future3 is the last, we define here a handler
				Future<String> future3 = undeployWebSocketVerticle();
				  future3.setHandler(handler -> {
						if (handler.succeeded()) {
						
							System.out.println("Undeployment successful!");
							future.complete("Undeployment successful!");
						} else {
							System.err.println("Undeployment failed: " + handler.cause().getMessage());
							future.fail(handler.cause().getMessage());
						}
					});
			} , Future.future().setHandler(handler -> {
				System.err.println("Undeployment failed: " + handler.cause().getMessage());
				future.fail(handler.cause().getMessage());
			}));
	}, Future.future().setHandler(handler -> {
		System.err.println("Undeployment failed: " + handler.cause().getMessage());
		future.fail(handler.cause().getMessage());
	}));
	return future;
}
 
開發者ID:AlxGDev,項目名稱:BittrexGatherer,代碼行數:33,代碼來源:BittrexVerticle.java

示例4: consumeWeatherData

import io.vertx.core.Future; //導入方法依賴的package包/類
/**
 * consumeWeatherData connects the WeatherDataConsumer to the hono server to read from TENANT_ID.
 * @throws Exception N/A
 */
private void consumeWeatherData() throws Exception {
    final Future<MessageConsumer> consumerFuture = Future.future();

    consumerFuture.setHandler(result -> {
        if (!result.succeeded()) {
            System.err.println("honoClient could not create telemetry consumer : " + result.cause());
        }
        latch.countDown();
    });

    final Future<HonoClient> connectionTracker = Future.future();

    honoClient.connect(new ProtonClientOptions(), connectionTracker.completer());

    connectionTracker.compose(honoClient -> {
                honoClient.createTelemetryConsumer(TENANT_ID,
                        msg -> handleWeatherMessage(msg), consumerFuture.completer());
            },
            consumerFuture);

    latch.await();
    //If consumer connects, then reads information.
    if (consumerFuture.succeeded())
        System.in.read();
    //Closes AMQP connection with hono server.
    vertx.close();
}
 
開發者ID:rhiot,項目名稱:hono-weather-demo,代碼行數:32,代碼來源:WeatherDataConsumer.java

示例5: thenParallel

import io.vertx.core.Future; //導入方法依賴的package包/類
/**
 * Source -> List<F> -> List<Future<S>>
 */
static <F, S, T> Future<List<T>> thenParallel(
        final Future<List<F>> source,
        final Function<F, Future<S>> generateFun,
        final BiFunction<F, S, T> mergeFun
) {
    return source.compose(first -> {
        final List<Future> secondFutures = new ArrayList<>();
        Observable.fromIterable(first)
                .map(generateFun::apply)
                .filter(Objects::nonNull)
                .subscribe(secondFutures::add);
        final Future<List<T>> result = Future.future();
        CompositeFuture.all(secondFutures).setHandler(res -> {
            final List<S> secondary = res.result().list();
            // Zipper Operation, the base list is first.
            final List<T> completed = Statute.zipper(first, secondary, mergeFun);
            result.complete(completed);
        });
        return result;
    });
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:25,代碼來源:Fluctuate.java

示例6: thenScatterJson

import io.vertx.core.Future; //導入方法依賴的package包/類
static Future<JsonArray> thenScatterJson(
        final Future<JsonArray> source,
        final Function<JsonObject, Future<JsonArray>> generateFun,
        final BiFunction<JsonObject, JsonArray, JsonObject> mergeFun
) {
    return source.compose(first -> {
        final List secondFutures = new ArrayList<>();
        Observable.fromIterable(first)
                .map(item -> (JsonObject) item)
                .map(generateFun::apply)
                .subscribe(secondFutures::add);
        final Future<JsonArray> result = Future.future();
        CompositeFuture.all(secondFutures).setHandler(res -> {
            final List<JsonArray> secondary = res.result().list();
            // Zipper Operation, the base list is first
            final List<JsonObject> completed = Statute.zipper(first.getList(), secondary, mergeFun);
            result.complete(new JsonArray(completed));
        });
        return result;
    });
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:22,代碼來源:Fluctuate.java

示例7: thenParallelJson

import io.vertx.core.Future; //導入方法依賴的package包/類
static Future<JsonArray> thenParallelJson(
        final Future<JsonArray> source,
        final Function<JsonObject, Future<JsonObject>> generateFun,
        final BinaryOperator<JsonObject> operatorFun
) {
    return source.compose(first -> {
        final List secondFutures = new ArrayList<>();
        Observable.fromIterable(first)
                .map(item -> (JsonObject) item)
                .map(generateFun::apply)
                .subscribe(secondFutures::add);
        final Future<JsonArray> result = Future.future();
        CompositeFuture.all(secondFutures).setHandler(res -> {
            final List<JsonObject> secondary = res.result().list();
            // Zipper Operation, the base list is first
            final List<JsonObject> completed = Statute.zipper(first.getList(), secondary, operatorFun);
            result.complete(new JsonArray(completed));
        });
        return result;
    });
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:22,代碼來源:Fluctuate.java

示例8: thenComposite

import io.vertx.core.Future; //導入方法依賴的package包/類
/**
 * Source ->
 * Target1
 * Target2
 */
static <F, S, T> Future<T> thenComposite(
        final Future<F> source,
        final BiFunction<F, List<S>, T> mergeFun,
        final Supplier<Future<S>>... suppliers) {
    return source.compose(first -> {
        final List<Future> secondFutures = new ArrayList<>();
        Observable.fromArray(suppliers)
                .map(Supplier::get)
                .subscribe(secondFutures::add);
        final Future<T> result = Future.future();
        CompositeFuture.all(secondFutures).setHandler(res -> {
            final List<S> secondary = res.result().list();
            final T completed = mergeFun.apply(first, secondary);
            result.complete(completed);
        });
        return result;
    });
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:24,代碼來源:Fluctuate.java

示例9: play_with_api

import io.vertx.core.Future; //導入方法依賴的package包/類
@Test
public void play_with_api(TestContext context) {
  Async async = context.async();

  JsonObject page = new JsonObject()
    .put("name", "Sample")
    .put("markdown", "# A page");

  Future<JsonObject> postRequest = Future.future();
  webClient.post("/api/pages")
    .as(BodyCodec.jsonObject())
    .sendJsonObject(page, ar -> {
      if (ar.succeeded()) {
        HttpResponse<JsonObject> postResponse = ar.result();
        postRequest.complete(postResponse.body());
      } else {
        context.fail(ar.cause());
      }
    });

  Future<JsonObject> getRequest = Future.future();
  postRequest.compose(h -> {
    webClient.get("/api/pages")
      .as(BodyCodec.jsonObject())
      .send(ar -> {
        if (ar.succeeded()) {
          HttpResponse<JsonObject> getResponse = ar.result();
          getRequest.complete(getResponse.body());
        } else {
          context.fail(ar.cause());
        }
      });
  }, getRequest);

  Future<JsonObject> putRequest = Future.future();
  getRequest.compose(response -> {
    JsonArray array = response.getJsonArray("pages");
    context.assertEquals(1, array.size());
    context.assertEquals(0, array.getJsonObject(0).getInteger("id"));
    webClient.put("/api/pages/0")
      .as(BodyCodec.jsonObject())
      .sendJsonObject(new JsonObject()
        .put("id", 0)
        .put("markdown", "Oh Yeah!"), ar -> {
        if (ar.succeeded()) {
          HttpResponse<JsonObject> putResponse = ar.result();
          putRequest.complete(putResponse.body());
        } else {
          context.fail(ar.cause());
        }
      });
  }, putRequest);

  Future<JsonObject> deleteRequest = Future.future();
  putRequest.compose(response -> {
    context.assertTrue(response.getBoolean("success"));
    webClient.delete("/api/pages/0")
      .as(BodyCodec.jsonObject())
      .send(ar -> {
        if (ar.succeeded()) {
          HttpResponse<JsonObject> delResponse = ar.result();
          deleteRequest.complete(delResponse.body());
        } else {
          context.fail(ar.cause());
        }
      });
  }, deleteRequest);

  deleteRequest.compose(response -> {
    context.assertTrue(response.getBoolean("success"));
    async.complete();
  }, Future.failedFuture("Oh?"));
}
 
開發者ID:vert-x3,項目名稱:vertx-guide-for-java-devs,代碼行數:74,代碼來源:ApiTest.java


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