io.vertx.rxjava.ext.consul.Watch Maven / Gradle / Ivy
/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.vertx.rxjava.ext.consul;
import rx.Observable;
import rx.Single;
import io.vertx.rx.java.RxHelper;
import io.vertx.rx.java.WriteStreamSubscriber;
import io.vertx.rx.java.SingleOnSubscribeAdapter;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;
/**
 * Watches are a way of specifying a view of data (e.g. list of nodes, KV pairs, health checks)
 * which is monitored for updates. When an update is detected, an Handler with WatchResult is invoked.
 * All errors, except java.util.concurrent.TimeoutException, will be handled, with resubscribing with a progressive delay.
 * All timeout errors will be ignored, with resubscribing without any delay.
 * As an example, you could watch the status of health checks and notify when a check is critical.
 *
 * 
 * NOTE: This class has been automatically generated from the {@link io.vertx.ext.consul.Watch original} non RX-ified interface using Vert.x codegen.
 */
@RxGen(io.vertx.ext.consul.Watch.class)
public class Watch {
  @Override
  public String toString() {
    return delegate.toString();
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Watch that = (Watch) o;
    return delegate.equals(that.delegate);
  }
  
  @Override
  public int hashCode() {
    return delegate.hashCode();
  }
  public static final TypeArg __TYPE_ARG = new TypeArg<>(    obj -> new Watch((io.vertx.ext.consul.Watch) obj),
    Watch::getDelegate
  );
  private final io.vertx.ext.consul.Watch delegate;
  public final TypeArg __typeArg_0;
  
  public Watch(io.vertx.ext.consul.Watch delegate) {
    this.delegate = delegate;
    this.__typeArg_0 = TypeArg.unknown();  }
  public Watch(Object delegate, TypeArg typeArg_0) {
    this.delegate = (io.vertx.ext.consul.Watch)delegate;
    this.__typeArg_0 = typeArg_0;
  }
  public io.vertx.ext.consul.Watch getDelegate() {
    return delegate;
  }
  /**
   * Creates Watch to monitoring a specific key in the KV store.
   * The underlying Consul client will be created with default options.
   * This maps to the /v1/kv/ API internally.
   * @param key the key
   * @param vertx the Vertx instance
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch key(java.lang.String key, io.vertx.rxjava.core.Vertx vertx) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.key(key, vertx.getDelegate()), TypeArg.unknown());
    return ret;
  }
  /**
   * Creates Watch to monitoring a specific key in the KV store.
   * This maps to the /v1/kv/ API internally.
   * @param key the key
   * @param vertx the Vertx instance
   * @param options the options to create underlying Consul client
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch key(java.lang.String key, io.vertx.rxjava.core.Vertx vertx, io.vertx.ext.consul.ConsulClientOptions options) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.key(key, vertx.getDelegate(), options), TypeArg.unknown());
    return ret;
  }
  /**
   * Creates Watch to monitoring a prefix of keys in the KV store.
   * The underlying Consul client will be created with default options.
   * This maps to the /v1/kv/ API internally.
   * @param keyPrefix the key
   * @param vertx the Vertx instance
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch keyPrefix(java.lang.String keyPrefix, io.vertx.rxjava.core.Vertx vertx) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.keyPrefix(keyPrefix, vertx.getDelegate()), TypeArg.unknown());
    return ret;
  }
  /**
   * Creates Watch to monitoring a prefix of keys in the KV store.
   * This maps to the /v1/kv/ API internally.
   * @param keyPrefix the key
   * @param vertx the Vertx instance
   * @param options the options to create underlying Consul client
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch keyPrefix(java.lang.String keyPrefix, io.vertx.rxjava.core.Vertx vertx, io.vertx.ext.consul.ConsulClientOptions options) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.keyPrefix(keyPrefix, vertx.getDelegate(), options), TypeArg.unknown());
    return ret;
  }
  /**
   * Creates Watch to monitoring the list of available services.
   * The underlying Consul client will be created with default options.
   * This maps to the /v1/catalog/services API internally.
   * @param vertx the Vertx instance
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch services(io.vertx.rxjava.core.Vertx vertx) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.services(vertx.getDelegate()), TypeArg.unknown());
    return ret;
  }
  /**
   * Creates Watch to monitoring the list of available services.
   * This maps to the /v1/catalog/services API internally.
   * @param vertx the Vertx instance
   * @param options the options to create underlying Consul client
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch services(io.vertx.rxjava.core.Vertx vertx, io.vertx.ext.consul.ConsulClientOptions options) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.services(vertx.getDelegate(), options), TypeArg.unknown());
    return ret;
  }
  /**
   * Creates Watch to monitoring the nodes providing the service.
   * Nodes will be sorted by distance from the consul agent.
   * The underlying Consul client will be created with default options.
   * This maps to the /v1/health/service/<service> API internally.
   * @param service the service name
   * @param vertx the Vertx instance
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch service(java.lang.String service, io.vertx.rxjava.core.Vertx vertx) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.service(service, vertx.getDelegate()), TypeArg.unknown());
    return ret;
  }
  /**
   * Creates Watch to monitoring the nodes providing the service.
   * Nodes will be sorted by distance from the consul agent.
   * This maps to the /v1/health/service/<service> API internally.
   * @param service the service name
   * @param vertx the Vertx instance
   * @param options the options to create underlying Consul client
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch service(java.lang.String service, io.vertx.rxjava.core.Vertx vertx, io.vertx.ext.consul.ConsulClientOptions options) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.service(service, vertx.getDelegate(), options), TypeArg.unknown());
    return ret;
  }
  /**
   * Creates Watch to monitoring the custom user events.
   * The underlying Consul client will be created with default options.
   * This maps to the /v1/event/list API internally.
   * @param event the event name
   * @param vertx the Vertx instance
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch events(java.lang.String event, io.vertx.rxjava.core.Vertx vertx) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.events(event, vertx.getDelegate()), TypeArg.unknown());
    return ret;
  }
  /**
   * Creates Watch to monitoring the custom user events.
   * This maps to the /v1/event/list API internally.
   * @param event the event name
   * @param vertx the Vertx instance
   * @param options the options to create underlying Consul client
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch events(java.lang.String event, io.vertx.rxjava.core.Vertx vertx, io.vertx.ext.consul.ConsulClientOptions options) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.events(event, vertx.getDelegate(), options), TypeArg.unknown());
    return ret;
  }
  /**
   * Creates Watch to monitoring the list of available nodes.
   * The underlying Consul client will be created with default options.
   * This maps to the /v1/catalog/nodes API internally.
   * @param vertx the Vertx instance
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch nodes(io.vertx.rxjava.core.Vertx vertx) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.nodes(vertx.getDelegate()), TypeArg.unknown());
    return ret;
  }
  /**
   * Creates Watch to monitoring the list of available nodes.
   * This maps to the /v1/catalog/nodes API internally.
   * @param vertx the Vertx instance
   * @param options the options to create underlying Consul client
   * @return the Watch instance
   */
  public static io.vertx.rxjava.ext.consul.Watch nodes(io.vertx.rxjava.core.Vertx vertx, io.vertx.ext.consul.ConsulClientOptions options) { 
    io.vertx.rxjava.ext.consul.Watch ret = io.vertx.rxjava.ext.consul.Watch.newInstance((io.vertx.ext.consul.Watch)io.vertx.ext.consul.Watch.nodes(vertx.getDelegate(), options), TypeArg.unknown());
    return ret;
  }
  /**
   * Set the result handler. As data is changed, the handler will be called with the result.
   * @param handler the result handler
   * @return reference to this, for fluency
   */
  public io.vertx.rxjava.ext.consul.Watch setHandler(io.vertx.core.Handler> handler) { 
    delegate.setHandler(new Handler>() {
      public void handle(io.vertx.ext.consul.WatchResult event) {
        handler.handle(io.vertx.rxjava.ext.consul.WatchResult.newInstance((io.vertx.ext.consul.WatchResult)event, __typeArg_0));
      }
    });
    return this;
  }
  /**
   * Start this Watch
   * @return reference to this, for fluency
   */
  public io.vertx.rxjava.ext.consul.Watch start() { 
    delegate.start();
    return this;
  }
  /**
   * Stop the watch and release its resources
   */
  public void stop() { 
    delegate.stop();
  }
  public static  Watch newInstance(io.vertx.ext.consul.Watch arg) {
    return arg != null ? new Watch(arg) : null;
  }
  public static  Watch newInstance(io.vertx.ext.consul.Watch arg, TypeArg __typeArg_T) {
    return arg != null ? new Watch(arg, __typeArg_T) : null;
  }
}
                                             © 2015 - 2025 Weber Informatics LLC | Privacy Policy