Java Code Examples for io.vertx.core.Future#isComplete()
The following examples show how to use
io.vertx.core.Future#isComplete() .
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: ValidationHandlerImpl.java From vertx-web with Apache License 2.0 | 7 votes |
private Future<Map<String, RequestParameter>> processParams(Map<String, RequestParameter> parsedParams, Map<String, List<String>> params, ParameterProcessor[] processors) { Future<Map<String, RequestParameter>> waitingFutureChain = Future.succeededFuture(parsedParams); for (ParameterProcessor processor : processors) { try { Future<RequestParameter> fut = processor.process(params); if (fut.isComplete()) { if (fut.succeeded()) { parsedParams.put(processor.getName(), fut.result()); } else if (fut.failed()) { return Future.failedFuture(fut.cause()); } } else { waitingFutureChain = waitingFutureChain.compose(m -> fut.map(rp -> { parsedParams.put(processor.getName(), rp); return parsedParams; })); } } catch (BadRequestException e) { return Future.failedFuture(e); } } return waitingFutureChain; }
Example 2
Source File: TopicOperatorTopicDeletionDisabledIT.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
@Test public void testKafkaTopicDeletionDisabled() throws InterruptedException, ExecutionException, TimeoutException { // create the Topic Resource String topicName = "test-topic-deletion-disabled"; // The creation method will wait for the topic to be ready in K8s KafkaTopic topicResource = createKafkaTopicResource(topicName); // Wait for the topic to be ready on the Kafka Broker waitForTopicInKafka(topicName, true); // Delete the k8 KafkaTopic and wait for that to be deleted deleteInKube(topicResource.getMetadata().getName()); // trigger an immediate reconcile where, with with delete.topic.enable=false, the K8s KafkaTopic should be recreated Future<?> result = session.topicOperator.reconcileAllTopics("periodic"); do { if (result.isComplete()) { break; } } while (true); // Wait for the KafkaTopic to be recreated waitForTopicInKube(topicName, true); }
Example 3
Source File: VxmsEndpoint.java From vxms with Apache License 2.0 | 6 votes |
/** * Executes the postConstruct using Reflection. This solves the issue that you can extend from a * VxmsEndpoint or use the static invocation of an AbstractVerticle. * * @param router the http router handler * @param startFuture the vert.x start future * @param registrationObject the object to execute postConstruct */ private static void executePostConstruct(AbstractVerticle registrationObject, Router router, final Future<Void> startFuture) { final Stream<ReflectionExecutionWrapper> reflectionExecutionWrapperStream = Stream .of(new ReflectionExecutionWrapper("postConstruct", registrationObject, new Object[]{router, startFuture}, startFuture), new ReflectionExecutionWrapper("postConstruct", registrationObject, new Object[]{startFuture, router}, startFuture), new ReflectionExecutionWrapper("postConstruct", registrationObject, new Object[]{startFuture}, startFuture)); final Optional<ReflectionExecutionWrapper> methodWrapperToInvoke = reflectionExecutionWrapperStream .filter(ReflectionExecutionWrapper::isPresent).findFirst(); methodWrapperToInvoke.ifPresent(ReflectionExecutionWrapper::invoke); if (!methodWrapperToInvoke.isPresent() && !startFuture.isComplete()) { startFuture.complete(); } }
Example 4
Source File: TenantLoading.java From raml-module-builder with Apache License 2.0 | 5 votes |
private static void handleException(Throwable ex, String lead, Future<Void> f) { String diag = lead + ": " + ex.getMessage(); log.error(diag, ex); if (!f.isComplete()) { f.handle(Future.failedFuture(diag)); } }
Example 5
Source File: HonoSender.java From hono with Eclipse Public License 2.0 | 4 votes |
/** * Publishes a message to Hono. * * @param sampleResult The result object representing the outcome of the sample. * @param deviceId The identifier if the device to send a message for. * @param waitForDeliveryResult A flag indicating whether to wait for the result of the send operation. */ public void send(final SampleResult sampleResult, final String deviceId, final boolean waitForDeliveryResult) { final String endpoint = sampler.getEndpoint(); final String tenant = sampler.getTenant(); final Future<DownstreamSender> senderFuture = getSender(endpoint, tenant); final CompletableFuture<SampleResult> tracker = new CompletableFuture<>(); final Promise<ProtonDelivery> deliveryTracker = Promise.promise(); deliveryTracker.future() .onComplete(s -> { if (s.succeeded()) { sampleResult.setResponseMessage(MessageFormat.format("{0}/{1}/{2}", endpoint, tenant, deviceId)); sampleResult.setSentBytes(payload.length); sampleResult.setSampleCount(1); tracker.complete(sampleResult); } else { tracker.completeExceptionally(s.cause()); } }); // start sample sampleResult.sampleStart(); senderFuture.map(sender -> { final Message msg = ProtonHelper.message(); msg.setAddress(sender.getEndpoint() + "/" + tenant); MessageHelper.setPayload(msg, sampler.getContentType(), Buffer.buffer(sampler.getData())); MessageHelper.addDeviceId(msg, deviceId); if (sampler.isSetSenderTime()) { MessageHelper.addProperty(msg, TIME_STAMP_VARIABLE, System.currentTimeMillis()); } LOGGER.trace("sending message for device [{}]; credit: {}", deviceId, sender.getCredit()); final Handler<Void> sendHandler = s -> { if (waitForDeliveryResult) { sender.sendAndWaitForOutcome(msg).onComplete(deliveryTracker); } else { sender.send(msg).onComplete(ar -> { if (ar.succeeded()) { LOGGER.debug("{}: got delivery result for message sent for device [{}]: remoteState={}, localState={}", sampler.getThreadName(), deviceId, ar.result().getRemoteState(), ar.result().getLocalState()); } else { LOGGER.warn("{}: error getting delivery result for message sent for device [{}]", sampler.getThreadName(), deviceId, ar.cause()); } }); deliveryTracker.complete(); } }; ctx.runOnContext(send -> { if (sender.getCredit() > 0) { sendHandler.handle(null); } else { sender.sendQueueDrainHandler(sendHandler); } }); return null; }).otherwise(t -> { tracker.completeExceptionally(t); return null; }); try { tracker.get(sampler.getSendTimeoutOrDefaultAsInt(), TimeUnit.MILLISECONDS); LOGGER.debug("{}: sent message for device [{}]", sampler.getThreadName(), deviceId); } catch (InterruptedException | CancellationException | ExecutionException | TimeoutException e) { sampleResult.setSuccessful(false); if (e.getCause() instanceof ServiceInvocationException) { final ServiceInvocationException sie = (ServiceInvocationException) e.getCause(); sampleResult.setResponseMessage(sie.getMessage()); sampleResult.setResponseCode(String.valueOf(sie.getErrorCode())); } else { String uncompletedFutureHint = ""; if (e instanceof TimeoutException) { uncompletedFutureHint = !senderFuture.isComplete() ? " - timeout waiting for sender link" : !deliveryTracker.future().isComplete() ? " - timeout waiting for message delivery" : ""; } sampleResult.setResponseMessage((e.getCause() != null ? e.getCause().getMessage() : e.getClass().getSimpleName()) + uncompletedFutureHint); sampleResult.setResponseCode(String.valueOf(HttpURLConnection.HTTP_INTERNAL_ERROR)); } LOGGER.debug("{}: error sending message for device [{}]: {}", sampler.getThreadName(), deviceId, sampleResult.getResponseMessage()); if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } } sampleResult.sampleEnd(); }
Example 6
Source File: VxmsEndpoint.java From vxms with Apache License 2.0 | 2 votes |
/** * Stop the service.<p> This is called by Vert.x when the service instance is un-deployed. * Don'failure call it yourself.<p> If your verticle does things in it's shut-down which take some * time then you can override this method and call the stopFuture some time later when clean-up is * complete. * * @param stopFuture a future which should be called when verticle clean-up is complete. */ public final void stop(Future<Void> stopFuture) { if (!stopFuture.isComplete()) { stopFuture.complete(); } }