io.vertx.rxjava.core.Vertx Java Examples
The following examples show how to use
io.vertx.rxjava.core.Vertx.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestResourceRxJava1.java From redpipe with Apache License 2.0 | 6 votes |
@Path("inject") @GET public String inject(@Context Vertx vertx, @Context RoutingContext routingContext, @Context HttpServerRequest request, @Context HttpServerResponse response, @Context AuthProvider authProvider, @Context User user, @Context Session session) { if(vertx == null || routingContext == null || request == null || response == null || session == null) throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); return "ok"; }
Example #2
Source File: VertxParameterProvider.java From vertx-rx with Apache License 2.0 | 6 votes |
@Override public ParameterClosingConsumer<Vertx> parameterClosingConsumer() { return vertx -> { try { if (!vertx.rxClose().toCompletable().await(DEFAULT_TIMEOUT_DURATION, DEFAULT_TIMEOUT_UNIT)) { throw new TimeoutException("Closing the Vertx context timed out"); } } catch (Throwable err) { if (err instanceof RuntimeException) { throw new VertxException(err.getCause()); } else if (err instanceof Exception) { throw err; } else { throw new VertxException(err); } } }; }
Example #3
Source File: CoreRxifiedApiTest.java From vertx-rx with Apache License 2.0 | 6 votes |
@Test public void testObservablePeriodic() throws Exception { Vertx vertx = new Vertx(this.vertx); Observable<Long> stream = vertx.periodicStream(1).toObservable(); stream.subscribe(new Subscriber<Long>() { @Override public void onNext(Long aLong) { unsubscribe(); testComplete(); } @Override public void onCompleted() { fail(); } @Override public void onError(Throwable e) { fail(e.getMessage()); } }); await(); }
Example #4
Source File: CoreApiTest.java From vertx-rx with Apache License 2.0 | 6 votes |
@Test public void testScheduledTimer() { vertx.runOnContext(v -> { long startTime = System.currentTimeMillis(); Context initCtx = Vertx.currentContext(); Observable.timer(100, 100, TimeUnit.MILLISECONDS, io.vertx.rxjava.core.RxHelper.scheduler(vertx)).take(10).subscribe(new Observer<Long>() { public void onNext(Long value) { assertEquals(initCtx.getDelegate(), Vertx.currentContext().getDelegate()); } public void onError(Throwable e) { fail("unexpected failure"); } public void onCompleted() { long timeTaken = System.currentTimeMillis() - startTime; assertTrue("Was expecting to have time taken | " + timeTaken + " - 1000 | < 200", Math.abs(timeTaken - 1000) < 1000); testComplete(); } }); }); await(); }
Example #5
Source File: RxifiedExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void websocketClient(Vertx vertx) { HttpClient client = vertx.createHttpClient(new HttpClientOptions()); client.rxWebSocket(8080, "localhost", "/the_uri").subscribe( ws -> { // Use the websocket }, error -> { // Could not connect } ); }
Example #6
Source File: RxifiedExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void periodicUnsubscribe(Vertx vertx) { vertx.periodicStream(1000). toObservable(). subscribe(new Subscriber<Long>() { public void onNext(Long aLong) { // Callback unsubscribe(); } public void onError(Throwable e) {} public void onCompleted() {} }); }
Example #7
Source File: RxifiedExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void httpClientRequest(Vertx vertx) { HttpClient client = vertx.createHttpClient(new HttpClientOptions()); Single<HttpClientResponse> request = client.rxGet(8080, "localhost", "/the_uri"); request.subscribe( response -> { // Process the response }, error -> { // Could not connect } ); }
Example #8
Source File: RxifiedExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void timer(Vertx vertx) { vertx.timerStream(1000). toObservable(). subscribe( id -> { System.out.println("Callback after 1 second"); } ); }
Example #9
Source File: RxifiedExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void periodic(Vertx vertx) { vertx.periodicStream(1000). toObservable(). subscribe( id -> { System.out.println("Callback every second"); } ); }
Example #10
Source File: ReactiveSystemDemo.java From Learn-Java-12-Programming with MIT License | 5 votes |
public static void main(String... args) { String address = "One"; Vertx vertx = Vertx.vertx(); RxHelper.deployVerticle(vertx, new MessageRcvVert("1", address)); RxHelper.deployVerticle(vertx, new MessageRcvVert("2", address)); RxHelper.deployVerticle(vertx, new MessageRcvVert("3", "Two")); RxHelper.deployVerticle(vertx, new HttpServerVert(8082)); }
Example #11
Source File: VerticleTest.java From vertx-rx with Apache License 2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); vertx = new Vertx(super.vertx); startedCount = 0; stoppedCount = 0; }
Example #12
Source File: CoreApiTest.java From vertx-rx with Apache License 2.0 | 5 votes |
@Test public void testScheduledBuffer() { vertx.runOnContext(v -> { long startTime = System.currentTimeMillis(); Context initCtx = Vertx.currentContext(); Observable .timer(10, 10, TimeUnit.MILLISECONDS, io.vertx.rxjava.core.RxHelper.scheduler(vertx)) .buffer(100, TimeUnit.MILLISECONDS, io.vertx.rxjava.core.RxHelper.scheduler(vertx)) .take(10) .subscribe(new Observer<List<Long>>() { private int eventCount = 0; public void onNext(List<Long> value) { eventCount++; assertEquals(initCtx.getDelegate(), Vertx.currentContext().getDelegate()); } public void onError(Throwable e) { fail("unexpected failure"); } public void onCompleted() { long timeTaken = System.currentTimeMillis() - startTime; assertEquals(10, eventCount); assertTrue("Was expecting to have time taken | " + timeTaken + " - 1000 | < 200", Math.abs(timeTaken - 1000) < 1000); testComplete(); } }); }); await(); }
Example #13
Source File: CoreApiTest.java From vertx-rx with Apache License 2.0 | 5 votes |
@Test public void testTimeMap() { vertx.runOnContext(v -> { Context initCtx = Vertx.currentContext(); EventBus eb = vertx.eventBus(); ReadStream<String> consumer = eb.<String>localConsumer("the-address").bodyStream(); Observer<String> observer = new Subscriber<String>() { boolean first = true; @Override public void onNext(String s) { if (first) { first = false; assertEquals(initCtx.getDelegate(), Vertx.currentContext().getDelegate()); assertEquals("msg1msg2msg3", s); testComplete(); } } @Override public void onError(Throwable e) { fail(e.getMessage()); } @Override public void onCompleted() { } }; Observable<String> observable = consumer.toObservable(); observable. buffer(500, TimeUnit.MILLISECONDS, io.vertx.rxjava.core.RxHelper.scheduler(vertx)). map(samples -> samples.stream().reduce("", (a, b) -> a + b)). subscribe(observer); eb.send("the-address", "msg1"); eb.send("the-address", "msg2"); eb.send("the-address", "msg3"); }); await(); }
Example #14
Source File: RxJava1Test.java From vertx-rx with Apache License 2.0 | 5 votes |
@Test @DisplayName("Check the injection of a /io.vertx.rxjava.core.Vertx/ instance") void check_injection(Vertx vertx, VertxTestContext testContext) { testContext.verify(() -> { assertThat(vertx).isNotNull(); testContext.completeNow(); }); }
Example #15
Source File: RxJava1Test.java From vertx-rx with Apache License 2.0 | 5 votes |
@Test @DisplayName("Check the deployment and interaction of a Rx1 verticle") void check_deployment_and_message_send(Vertx vertx, VertxTestContext testContext) { RxHelper .deployVerticle(vertx, new RxVerticle()) .toSingle() .flatMap(id -> vertx.eventBus().rxRequest("check", "Ok?")) .subscribe( message -> testContext.verify(() -> { assertThat(message.body()).isEqualTo("Check!"); testContext.completeNow(); }), testContext::failNow); }
Example #16
Source File: AwsPollingAsStateObservable.java From vertx-deploy-tools with Apache License 2.0 | 5 votes |
public AwsPollingAsStateObservable(io.vertx.core.Vertx vertx, AwsAutoScalingUtil awsAsUtil, LocalDateTime timeout, long pollInterval, AwsState... acceptedStates) { this.rxVertx = new Vertx(vertx); this.awsAsUtil = awsAsUtil; this.timeout = timeout; this.pollInterval = pollInterval; this.acceptedStates = Arrays.asList(acceptedStates); }
Example #17
Source File: AwsPollingElbStateObservable.java From vertx-deploy-tools with Apache License 2.0 | 5 votes |
public AwsPollingElbStateObservable(io.vertx.core.Vertx vertx, String deployId, AwsElbUtil awsElbUtil, LocalDateTime timeout,long pollInterval, Function<String, Boolean> requestStillActive, AwsState... acceptedStates) { this.deployId = deployId; this.requestStillActive = requestStillActive; this.rxVertx = new Vertx(vertx); this.awsElbUtil = awsElbUtil; this.timeout = timeout; this.acceptedStates = Arrays.asList(acceptedStates); this.pollInterval = pollInterval; }
Example #18
Source File: RxifiedExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void eventBusMessages(Vertx vertx) { EventBus eb = vertx.eventBus(); MessageConsumer<String> consumer = eb.<String>consumer("the-address"); Observable<Message<String>> observable = consumer.toObservable(); Subscription sub = observable.subscribe(msg -> { // Got message }); // Unregisters the stream after 10 seconds vertx.setTimer(10000, id -> { sub.unsubscribe(); }); }
Example #19
Source File: RxifiedExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void deployVerticle(Vertx vertx, Verticle verticle) { Observable<String> deployment = RxHelper.deployVerticle(vertx, verticle); deployment.subscribe(id -> { // Deployed }, err -> { // Could not deploy }); }
Example #20
Source File: RxifiedExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void toObservable(Vertx vertx) { FileSystem fs = vertx.fileSystem(); fs.open("/data.txt", new OpenOptions(), result -> { AsyncFile file = result.result(); Observable<Buffer> observable = file.toObservable(); observable.forEach(data -> System.out.println("Read data: " + data.toString("UTF-8"))); }); }
Example #21
Source File: CartEventDataSourceImpl.java From vertx-blueprint-microservice with Apache License 2.0 | 5 votes |
public CartEventDataSourceImpl(io.vertx.core.Vertx vertx, JsonObject json) { this.client = JDBCClient.createNonShared(Vertx.newInstance(vertx), json); // TODO: Should not init the table here. client.rxGetConnection() .flatMap(connection -> connection.rxExecute(INIT_STATEMENT) .doAfterTerminate(connection::close) ) .subscribe(); }
Example #22
Source File: RxifiedExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void eventBusMapReduce(Vertx vertx) { Observable<Double> observable = vertx.eventBus(). <Double>consumer("heat-sensor"). bodyStream(). toObservable(); observable. buffer(1, TimeUnit.SECONDS). map(samples -> samples. stream(). collect(Collectors.averagingDouble(d -> d))). subscribe(heat -> { vertx.eventBus().send("news-feed", "Current heat is " + heat); }); }
Example #23
Source File: VertxParameterProvider.java From vertx-rx with Apache License 2.0 | 4 votes |
@Override public Class<Vertx> type() { return Vertx.class; }
Example #24
Source File: ResolveSnapshotVersion.java From vertx-deploy-tools with Apache License 2.0 | 4 votes |
public ResolveSnapshotVersion(DeployConfig config, io.vertx.core.Vertx vertx) { this.rxVertx = new Vertx(vertx); this.config = config; }
Example #25
Source File: ExtractArtifact.java From vertx-deploy-tools with Apache License 2.0 | 4 votes |
public ExtractArtifact(io.vertx.core.Vertx vertx, DeployConfig config, Path basePath) { this.vertx = new Vertx(vertx); this.config = config; this.basePath = basePath; this.fileDigestUtil = new FileDigestUtil(); }
Example #26
Source File: StopApplication.java From vertx-deploy-tools with Apache License 2.0 | 4 votes |
public StopApplication(io.vertx.core.Vertx vertx, DeployConfig config) { this.config = config; this.processUtils = new ProcessUtils(config); this.rxVertx = new Vertx(vertx); this.timeout = LocalDateTime.now().plusMinutes(config.getAwsMaxRegistrationDuration()); }
Example #27
Source File: RunApplication.java From vertx-deploy-tools with Apache License 2.0 | 4 votes |
public RunApplication(final io.vertx.core.Vertx vertx, final DeployConfig deployConfig) { this.rxVertx = new Vertx(vertx); this.deployConfig = deployConfig; }
Example #28
Source File: RunConsoleCommand.java From vertx-deploy-tools with Apache License 2.0 | 4 votes |
public RunConsoleCommand(io.vertx.core.Vertx vertx, String command) { this.command = command; this.rxVertx = new Vertx(vertx); }
Example #29
Source File: ObservableCommand.java From vertx-deploy-tools with Apache License 2.0 | 4 votes |
public ObservableCommand(R request, Integer expectedResultCode, Vertx vertx) { this.request = request; this.expectedResultCode = expectedResultCode; this.rxVertx = vertx; }
Example #30
Source File: CallbackKue.java From vertx-kue with Apache License 2.0 | 4 votes |
public static CallbackKue createKue(Vertx vertx, JsonObject config) { CallbackKue ret = CallbackKue.newInstance(io.vertx.blueprint.kue.CallbackKue.createKue(vertx.getDelegate(), config)); return ret; }