io.vertx.rxjava.core.shareddata.SharedData 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.core.shareddata;
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;
/**
 * Shared data allows you to share data safely between different parts of your application in a safe way.
 * 
 * Shared data provides:
 * 
 *   - synchronous shared maps (local)
 
 *   - asynchronous maps (local or cluster-wide)
 
 *   - asynchronous locks (local or cluster-wide)
 
 *   - asynchronous counters (local or cluster-wide)
 
 * 
 * 
 * 
 *   WARNING: In clustered mode, asynchronous maps/locks/counters rely on distributed data structures provided by the cluster manager.
 *   Beware that the latency relative to asynchronous maps/locks/counters operations can be much higher in clustered than in local mode.
 * 
 * Please see the documentation for more information.
 *
 * 
 * NOTE: This class has been automatically generated from the {@link io.vertx.core.shareddata.SharedData original} non RX-ified interface using Vert.x codegen.
 */
@RxGen(io.vertx.core.shareddata.SharedData.class)
public class SharedData {
  @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;
    SharedData that = (SharedData) o;
    return delegate.equals(that.delegate);
  }
  
  @Override
  public int hashCode() {
    return delegate.hashCode();
  }
  public static final TypeArg __TYPE_ARG = new TypeArg<>(    obj -> new SharedData((io.vertx.core.shareddata.SharedData) obj),
    SharedData::getDelegate
  );
  private final io.vertx.core.shareddata.SharedData delegate;
  
  public SharedData(io.vertx.core.shareddata.SharedData delegate) {
    this.delegate = delegate;
  }
  public SharedData(Object delegate) {
    this.delegate = (io.vertx.core.shareddata.SharedData)delegate;
  }
  public io.vertx.core.shareddata.SharedData getDelegate() {
    return delegate;
  }
  /**
   * Get the cluster wide map with the specified name. The map is accessible to all nodes in the cluster and data
   * put into the map from any node is visible to to any other node.
   * @param name the name of the map
   * @param resultHandler the map will be returned asynchronously in this handler
   */
  public  void getClusterWideMap(java.lang.String name, io.vertx.core.Handler>> resultHandler) { 
    delegate.getClusterWideMap(name, new Handler>>() {
      public void handle(AsyncResult> ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.shareddata.AsyncMap.newInstance((io.vertx.core.shareddata.AsyncMap)ar.result(), TypeArg.unknown(), TypeArg.unknown())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Get the cluster wide map with the specified name. The map is accessible to all nodes in the cluster and data
   * put into the map from any node is visible to to any other node.
   * @param name the name of the map
   */
  public  void getClusterWideMap(java.lang.String name) {
    getClusterWideMap(name, ar -> { });
  }
    /**
   * Get the cluster wide map with the specified name. The map is accessible to all nodes in the cluster and data
   * put into the map from any node is visible to to any other node.
   * @param name the name of the map
   * @return 
   */
  public  rx.Single> rxGetClusterWideMap(java.lang.String name) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      getClusterWideMap(name, fut);
    }));
  }
  /**
   * Get the {@link io.vertx.rxjava.core.shareddata.AsyncMap} with the specified name. When clustered, the map is accessible to all nodes in the cluster
   * and data put into the map from any node is visible to to any other node.
   * 
   *   WARNING: In clustered mode, asynchronous shared maps rely on distributed data structures provided by the cluster manager.
   *   Beware that the latency relative to asynchronous shared maps operations can be much higher in clustered than in local mode.
   * 
   * @param name the name of the map
   * @param resultHandler the map will be returned asynchronously in this handler
   */
  public  void getAsyncMap(java.lang.String name, io.vertx.core.Handler>> resultHandler) { 
    delegate.getAsyncMap(name, new Handler>>() {
      public void handle(AsyncResult> ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.shareddata.AsyncMap.newInstance((io.vertx.core.shareddata.AsyncMap)ar.result(), TypeArg.unknown(), TypeArg.unknown())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Get the {@link io.vertx.rxjava.core.shareddata.AsyncMap} with the specified name. When clustered, the map is accessible to all nodes in the cluster
   * and data put into the map from any node is visible to to any other node.
   * 
   *   WARNING: In clustered mode, asynchronous shared maps rely on distributed data structures provided by the cluster manager.
   *   Beware that the latency relative to asynchronous shared maps operations can be much higher in clustered than in local mode.
   * 
   * @param name the name of the map
   */
  public  void getAsyncMap(java.lang.String name) {
    getAsyncMap(name, ar -> { });
  }
    /**
   * Get the {@link io.vertx.rxjava.core.shareddata.AsyncMap} with the specified name. When clustered, the map is accessible to all nodes in the cluster
   * and data put into the map from any node is visible to to any other node.
   * 
   *   WARNING: In clustered mode, asynchronous shared maps rely on distributed data structures provided by the cluster manager.
   *   Beware that the latency relative to asynchronous shared maps operations can be much higher in clustered than in local mode.
   * 
   * @param name the name of the map
   * @return 
   */
  public  rx.Single> rxGetAsyncMap(java.lang.String name) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      getAsyncMap(name, fut);
    }));
  }
  /**
   * Get the {@link io.vertx.rxjava.core.shareddata.AsyncMap} with the specified name.
   * 
   * When clustered, the map is NOT accessible to all nodes in the cluster.
   * Only the instance which created the map can put and retrieve data from this map.
   * @param name the name of the map
   * @param resultHandler the map will be returned asynchronously in this handler
   */
  public  void getLocalAsyncMap(java.lang.String name, io.vertx.core.Handler>> resultHandler) { 
    delegate.getLocalAsyncMap(name, new Handler>>() {
      public void handle(AsyncResult> ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.shareddata.AsyncMap.newInstance((io.vertx.core.shareddata.AsyncMap)ar.result(), TypeArg.unknown(), TypeArg.unknown())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Get the {@link io.vertx.rxjava.core.shareddata.AsyncMap} with the specified name.
   * 
   * When clustered, the map is NOT accessible to all nodes in the cluster.
   * Only the instance which created the map can put and retrieve data from this map.
   * @param name the name of the map
   */
  public  void getLocalAsyncMap(java.lang.String name) {
    getLocalAsyncMap(name, ar -> { });
  }
    /**
   * Get the {@link io.vertx.rxjava.core.shareddata.AsyncMap} with the specified name.
   * 
   * When clustered, the map is NOT accessible to all nodes in the cluster.
   * Only the instance which created the map can put and retrieve data from this map.
   * @param name the name of the map
   * @return 
   */
  public  rx.Single> rxGetLocalAsyncMap(java.lang.String name) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      getLocalAsyncMap(name, fut);
    }));
  }
  /**
   * Get an asynchronous lock with the specified name. The lock will be passed to the handler when it is available.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   * @param resultHandler the handler
   */
  public void getLock(java.lang.String name, io.vertx.core.Handler> resultHandler) { 
    delegate.getLock(name, new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.shareddata.Lock.newInstance((io.vertx.core.shareddata.Lock)ar.result())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Get an asynchronous lock with the specified name. The lock will be passed to the handler when it is available.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   */
  public void getLock(java.lang.String name) {
    getLock(name, ar -> { });
  }
    /**
   * Get an asynchronous lock with the specified name. The lock will be passed to the handler when it is available.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   * @return 
   */
  public rx.Single rxGetLock(java.lang.String name) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      getLock(name, fut);
    }));
  }
  /**
   * Like {@link io.vertx.rxjava.core.shareddata.SharedData#getLock} but specifying a timeout. If the lock is not obtained within the timeout
   * a failure will be sent to the handler.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   * @param timeout the timeout in ms
   * @param resultHandler the handler
   */
  public void getLockWithTimeout(java.lang.String name, long timeout, io.vertx.core.Handler> resultHandler) { 
    delegate.getLockWithTimeout(name, timeout, new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.shareddata.Lock.newInstance((io.vertx.core.shareddata.Lock)ar.result())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Like {@link io.vertx.rxjava.core.shareddata.SharedData#getLock} but specifying a timeout. If the lock is not obtained within the timeout
   * a failure will be sent to the handler.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   * @param timeout the timeout in ms
   */
  public void getLockWithTimeout(java.lang.String name, long timeout) {
    getLockWithTimeout(name, timeout, ar -> { });
  }
    /**
   * Like {@link io.vertx.rxjava.core.shareddata.SharedData#getLock} but specifying a timeout. If the lock is not obtained within the timeout
   * a failure will be sent to the handler.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   * @param timeout the timeout in ms
   * @return 
   */
  public rx.Single rxGetLockWithTimeout(java.lang.String name, long timeout) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      getLockWithTimeout(name, timeout, fut);
    }));
  }
  /**
   * Get an asynchronous local lock with the specified name. The lock will be passed to the handler when it is available.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   * @param resultHandler the handler
   */
  public void getLocalLock(java.lang.String name, io.vertx.core.Handler> resultHandler) { 
    delegate.getLocalLock(name, new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.shareddata.Lock.newInstance((io.vertx.core.shareddata.Lock)ar.result())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Get an asynchronous local lock with the specified name. The lock will be passed to the handler when it is available.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   */
  public void getLocalLock(java.lang.String name) {
    getLocalLock(name, ar -> { });
  }
    /**
   * Get an asynchronous local lock with the specified name. The lock will be passed to the handler when it is available.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   * @return 
   */
  public rx.Single rxGetLocalLock(java.lang.String name) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      getLocalLock(name, fut);
    }));
  }
  /**
   * Like {@link io.vertx.rxjava.core.shareddata.SharedData#getLocalLock} but specifying a timeout. If the lock is not obtained within the timeout
   * a failure will be sent to the handler.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   * @param timeout the timeout in ms
   * @param resultHandler the handler
   */
  public void getLocalLockWithTimeout(java.lang.String name, long timeout, io.vertx.core.Handler> resultHandler) { 
    delegate.getLocalLockWithTimeout(name, timeout, new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.shareddata.Lock.newInstance((io.vertx.core.shareddata.Lock)ar.result())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Like {@link io.vertx.rxjava.core.shareddata.SharedData#getLocalLock} but specifying a timeout. If the lock is not obtained within the timeout
   * a failure will be sent to the handler.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   * @param timeout the timeout in ms
   */
  public void getLocalLockWithTimeout(java.lang.String name, long timeout) {
    getLocalLockWithTimeout(name, timeout, ar -> { });
  }
    /**
   * Like {@link io.vertx.rxjava.core.shareddata.SharedData#getLocalLock} but specifying a timeout. If the lock is not obtained within the timeout
   * a failure will be sent to the handler.
   * 
   *   In general lock acquision is unordered, so that sequential attempts to acquire a lock,
   *   even from a single thread, can happen in non-sequential order.
   * 
   * @param name the name of the lock
   * @param timeout the timeout in ms
   * @return 
   */
  public rx.Single rxGetLocalLockWithTimeout(java.lang.String name, long timeout) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      getLocalLockWithTimeout(name, timeout, fut);
    }));
  }
  /**
   * Get an asynchronous counter. The counter will be passed to the handler.
   * @param name the name of the counter.
   * @param resultHandler the handler
   */
  public void getCounter(java.lang.String name, io.vertx.core.Handler> resultHandler) { 
    delegate.getCounter(name, new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.shareddata.Counter.newInstance((io.vertx.core.shareddata.Counter)ar.result())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Get an asynchronous counter. The counter will be passed to the handler.
   * @param name the name of the counter.
   */
  public void getCounter(java.lang.String name) {
    getCounter(name, ar -> { });
  }
    /**
   * Get an asynchronous counter. The counter will be passed to the handler.
   * @param name the name of the counter.
   * @return 
   */
  public rx.Single rxGetCounter(java.lang.String name) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      getCounter(name, fut);
    }));
  }
  /**
   * Get an asynchronous local counter. The counter will be passed to the handler.
   * @param name the name of the counter.
   * @param resultHandler the handler
   */
  public void getLocalCounter(java.lang.String name, io.vertx.core.Handler> resultHandler) { 
    delegate.getLocalCounter(name, new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.shareddata.Counter.newInstance((io.vertx.core.shareddata.Counter)ar.result())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Get an asynchronous local counter. The counter will be passed to the handler.
   * @param name the name of the counter.
   */
  public void getLocalCounter(java.lang.String name) {
    getLocalCounter(name, ar -> { });
  }
    /**
   * Get an asynchronous local counter. The counter will be passed to the handler.
   * @param name the name of the counter.
   * @return 
   */
  public rx.Single rxGetLocalCounter(java.lang.String name) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      getLocalCounter(name, fut);
    }));
  }
  /**
   * Return a LocalMap with the specific name.
   * @param name the name of the map
   * @return the msp
   */
  public  io.vertx.rxjava.core.shareddata.LocalMap getLocalMap(java.lang.String name) { 
    io.vertx.rxjava.core.shareddata.LocalMap ret = io.vertx.rxjava.core.shareddata.LocalMap.newInstance((io.vertx.core.shareddata.LocalMap)delegate.getLocalMap(name), TypeArg.unknown(), TypeArg.unknown());
    return ret;
  }
  public static SharedData newInstance(io.vertx.core.shareddata.SharedData arg) {
    return arg != null ? new SharedData(arg) : null;
  }
}