Java Code Examples for io.vertx.core.Future#succeeded()

The following examples show how to use io.vertx.core.Future#succeeded() . 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 vote down vote up
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: MockKafka.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Override
public Future<Void> createTopic(Topic t) {
    NewTopic newTopic = TopicSerialization.toNewTopic(t, null);
    Future<Void> event = createTopicResponse.apply(newTopic.name());
    if (event.succeeded()) {
        Topic.Builder topicBuilder = new Topic.Builder()
                .withTopicName(newTopic.name())
                .withNumPartitions(newTopic.numPartitions())
                .withNumReplicas(newTopic.replicationFactor())
                .withMetadata(t.getMetadata());
        try {
            Field field = NewTopic.class.getDeclaredField("configs");
            field.setAccessible(true);
            topicBuilder.withConfig((Map) field.get(newTopic));
        } catch (ReflectiveOperationException e) {
            throw new RuntimeException(e);
        }
        Topic topic = topicBuilder.build();
        topics.put(topic.getTopicName(), topic);
    }
    return event;
}
 
Example 3
Source File: MockTopicStore.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public Future<Void> create(Topic topic) {
    Future<Void> response = createTopicResponse.apply(topic.getTopicName());
    if (response.succeeded()) {
        Topic old = topics.put(topic.getTopicName(), topic);
        if (old != null) {
            return Future.failedFuture(new TopicStore.EntityExistsException());
        }
    }
    return response;
}
 
Example 4
Source File: MockTopicStore.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public Future<Void> delete(TopicName topicName) {
    Future<Void> response = deleteTopicResponse.apply(topicName);
    if (response.succeeded()) {
        Topic topic = topics.remove(topicName);
        if (topic == null) {
            return Future.failedFuture(new TopicStore.NoSuchEntityExistsException());
        }
    }
    return response;
}
 
Example 5
Source File: MockKafka.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public Future<Void> deleteTopic(TopicName topicName) {
    Future<Void> event = deleteTopicResponse.apply(topicName);
    if (event.succeeded()) {
        topics.remove(topicName);
    }
    return event;
}
 
Example 6
Source File: MockKafka.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public Future<Void> updateTopicConfig(Topic topic) {
    Future<Void> event = updateTopicResponse.apply(topic.getTopicName());
    if (event.succeeded()) {
        Topic t = topics.get(topic.getTopicName());
        if (t == null) {
            event = failedFuture("No such topic " + topic.getTopicName());
        }
        t = new Topic.Builder(t).withConfig(topic.getConfig()).build();
        topics.put(topic.getTopicName(), t);
    }
    return event;
}
 
Example 7
Source File: MockKafka.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public Future<Void> increasePartitions(Topic topic) {
    Future<Void> event = updateTopicResponse.apply(topic.getTopicName());
    if (event.succeeded()) {
        Topic t = topics.get(topic.getTopicName());
        if (t == null) {
            event = failedFuture("No such topic " + topic.getTopicName());
        }
        t = new Topic.Builder(t).withNumPartitions(topic.getNumPartitions()).build();
        topics.put(topic.getTopicName(), t);
    }
    return event;
}