Refine search
@Override public void start(Future<Void> startFuture) throws Exception { vertx.executeBlocking(fut -> { try { SECONDS.sleep(5); fut.complete(); } catch (InterruptedException e) { fut.fail(e); } }, startFuture); } }, deploymentOptions, onSuccess(did -> {
vertx.<String>executeBlocking(future -> { future.complete(result);
private Handler<Message<String>> allProductsHandler(ProductService service) { // It is important to use an executeBlocking construct here // as the service calls are blocking (dealing with a database) return msg -> vertx.<String>executeBlocking(future -> { try { future.complete(mapper.writeValueAsString(service.getAllProducts())); } catch (JsonProcessingException e) { System.out.println("Failed to serialize result"); future.fail(e); } }, result -> { if (result.succeeded()) { msg.reply(result.result()); } else { msg.reply(result.cause().toString()); } }); }
@Override public void start() throws Exception { vertx.executeBlocking(fut -> { thread.set(Thread.currentThread()); assertTrue(Context.isOnVertxThread()); assertTrue(Context.isOnWorkerThread()); assertFalse(Context.isOnEventLoopThread()); assertTrue(Thread.currentThread().getName().startsWith(poolName + "-")); fut.complete(); }, onSuccess(v -> { vertx.undeploy(context.deploymentID()); })); } }, new DeploymentOptions().setWorkerPoolName(poolName), onSuccess(v -> {}));
@Test public void testExecuteBlockingTTCL() throws Exception { ClassLoader cl = Thread.currentThread().getContextClassLoader(); assertNotNull(cl); CountDownLatch latch = new CountDownLatch(1); AtomicReference<ClassLoader> blockingTCCL = new AtomicReference<>(); vertx.<String>executeBlocking(future -> { future.complete("whatever"); blockingTCCL.set(Thread.currentThread().getContextClassLoader()); }, ar -> { assertTrue(ar.succeeded()); assertEquals("whatever", ar.result()); latch.countDown(); }); assertSame(cl, Thread.currentThread().getContextClassLoader()); awaitLatch(latch); assertSame(cl, blockingTCCL.get()); }
@Test public void testExecuteBlockingSuccess() { vertx.executeBlocking(future -> { try { Thread.sleep(1000); } catch (Exception ignore) { } future.complete("done!"); }, onSuccess(res -> { assertEquals("done!", res); testComplete(); })); await(); }
SharedData sharedData = vertx.sharedData(); AtomicReference<Long> start = new AtomicReference<>(); vertx.<Lock>executeBlocking(future -> { CountDownLatch acquireLatch = new CountDownLatch(1); AtomicReference<AsyncResult<Lock>> lockReference = new AtomicReference<>(); AsyncResult<Lock> ar = lockReference.get(); if (ar.succeeded()) { future.complete(ar.result()); } else { future.fail(ar.cause()); ar.result().release(); }); vertx.executeBlocking(future -> { CountDownLatch acquireLatch = new CountDownLatch(1); AtomicReference<AsyncResult<Lock>> lockReference = new AtomicReference<>(); AsyncResult<Lock> ar3 = lockReference.get(); if (ar3.succeeded()) { future.complete(ar3.result()); } else { future.fail(ar3.cause());
@Test public void testSendFromExecuteBlocking() throws Exception { String expectedBody = TestUtils.randomAlphaString(20); CountDownLatch receivedLatch = new CountDownLatch(1); startNodes(2); vertices[1].eventBus().<String>consumer(ADDRESS1, msg -> { assertEquals(expectedBody, msg.body()); receivedLatch.countDown(); }).completionHandler(ar -> { assertTrue(ar.succeeded()); vertices[0].executeBlocking(fut -> { vertices[0].eventBus().send(ADDRESS1, expectedBody); try { awaitLatch(receivedLatch); // Make sure message is sent even if we're busy } catch (InterruptedException e) { Thread.interrupted(); fut.fail(e); } fut.complete(); }, ar2 -> { if (ar2.succeeded()) { testComplete(); } else { fail(ar2.cause()); } }); }); await(); }
vertx.executeBlocking(future -> { assertSame(ctx, vertx.getOrCreateContext()); assertTrue(Thread.currentThread().getName().startsWith("vert.x-worker-thread")); } catch (Exception ignore) { future.complete("done!"); }, false, onSuccess(res -> { assertSame(ctx, vertx.getOrCreateContext());
assertEquals(expected.creationTime(), actual.creationTime()); assertEquals(expected.lastModifiedTime(), actual.lastModifiedTime()); vertx.<Set<PosixFilePermission>>executeBlocking(fut -> { try { fut.complete(Files.getPosixFilePermissions(new File(testDir, target).toPath(), LinkOption.NOFOLLOW_LINKS)); } catch (IOException e) { fut.fail(e);
Context ctx = vertx.getOrCreateContext(); assertTrue(ctx.isEventLoopContext()); vertx.executeBlocking(future -> { assertSame(ctx, vertx.getOrCreateContext()); assertTrue(Thread.currentThread().getName().startsWith("vert.x-worker-thread")); assertFalse(Context.isOnWorkerThread()); assertTrue(Context.isOnEventLoopThread()); future.complete("done!"); }); }, onSuccess(res -> {
vertices[0].executeBlocking(fut -> { vertices[0].eventBus().send("blah", "blah", ar -> { assertTrue(ar.failed()); complete(); }); fut.complete(); }, false, null);
@Override public void start(Future<Void> startFuture) throws Exception { vertx.executeBlocking(fut -> { try { SECONDS.sleep(5); fut.complete(); } catch (InterruptedException e) { fut.fail(e); } }, startFuture); } }, deploymentOptions, onSuccess(did -> {
@Override public void handle(RoutingContext context) { Route currentRoute = context.currentRoute(); context.vertx().executeBlocking(fut -> { decoratedHandler.handle(new RoutingContextDecorator(currentRoute, context)); fut.complete(); }, ordered, res -> { if (res.failed()) { // This means an exception was thrown from the blocking handler context.fail(res.cause()); } }); }
@Override public void start() throws Exception { vertx.executeBlocking(fut -> { thread.set(Thread.currentThread()); assertTrue(Context.isOnVertxThread()); assertTrue(Context.isOnWorkerThread()); assertFalse(Context.isOnEventLoopThread()); assertTrue(Thread.currentThread().getName().startsWith(poolName + "-")); fut.complete(); }, onSuccess(v -> { vertx.undeploy(context.deploymentID()); })); } }, new DeploymentOptions().setWorkerPoolName(poolName), onSuccess(v -> {}));
@Test public void testExecuteBlockingTTCL() throws Exception { ClassLoader cl = Thread.currentThread().getContextClassLoader(); assertNotNull(cl); CountDownLatch latch = new CountDownLatch(1); AtomicReference<ClassLoader> blockingTCCL = new AtomicReference<>(); vertx.<String>executeBlocking(future -> { future.complete("whatever"); blockingTCCL.set(Thread.currentThread().getContextClassLoader()); }, ar -> { assertTrue(ar.succeeded()); assertEquals("whatever", ar.result()); latch.countDown(); }); assertSame(cl, Thread.currentThread().getContextClassLoader()); awaitLatch(latch); assertSame(cl, blockingTCCL.get()); }
@Test public void testExecuteBlockingSuccess() { vertx.executeBlocking(future -> { try { Thread.sleep(1000); } catch (Exception ignore) { } future.complete("done!"); }, onSuccess(res -> { assertEquals("done!", res); testComplete(); })); await(); }
SharedData sharedData = vertx.sharedData(); AtomicReference<Long> start = new AtomicReference<>(); vertx.<Lock>executeBlocking(future -> { CountDownLatch acquireLatch = new CountDownLatch(1); AtomicReference<AsyncResult<Lock>> lockReference = new AtomicReference<>(); AsyncResult<Lock> ar = lockReference.get(); if (ar.succeeded()) { future.complete(ar.result()); } else { future.fail(ar.cause()); ar.result().release(); }); vertx.executeBlocking(future -> { CountDownLatch acquireLatch = new CountDownLatch(1); AtomicReference<AsyncResult<Lock>> lockReference = new AtomicReference<>(); AsyncResult<Lock> ar3 = lockReference.get(); if (ar3.succeeded()) { future.complete(ar3.result()); } else { future.fail(ar3.cause());
vertx.executeBlocking(future -> { event.next(); future.complete(); }, asyncResult -> {}); vertx.executeBlocking(future -> { HttpServerRequest request = mock(HttpServerRequest.class); HttpServerResponse response = mock(HttpServerResponse.class); when(response.ended()).thenReturn(true); router.handle(request); future.complete(); }, asyncResult -> { assertFalse(asyncResult.failed());
vertx.executeBlocking(future -> { try { Thread.sleep((int) (1 + Math.random() * 10)); testSyncRequest("GET", "/path", 200, "OK", sum.toString()); future.complete(); } catch (Exception e) { future.fail(e);