io.vertx.reactivex.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.reactivex.core.shareddata;
import java.util.Map;
import io.reactivex.Observable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
/**
* Shared data allows you to share data safely between different parts of your application in a safe way.
*
* Shared data provides:
*
* - Cluster wide maps which can be accessed from any node of the cluster
* - Cluster wide locks which can be used to give exclusive access to resources across the cluster
* - Cluster wide counters used to maintain counts consistently across the cluster
* - Local maps for sharing data safely in the same Vert.x instance
*
*
* 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.
*/
@io.vertx.lang.reactivex.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 io.vertx.lang.reactivex.TypeArg __TYPE_ARG = new io.vertx.lang.reactivex.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 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(String name, Handler>> resultHandler) {
delegate.getClusterWideMap(name, new Handler>>() {
public void handle(AsyncResult> ar) {
if (ar.succeeded()) {
resultHandler.handle(io.vertx.core.Future.succeededFuture(AsyncMap.newInstance(ar.result(), io.vertx.lang.reactivex.TypeArg.unknown(), io.vertx.lang.reactivex.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
* @return
*/
public Single> rxGetClusterWideMap(String name) {
return new io.vertx.reactivex.core.impl.AsyncResultSingle>(handler -> {
getClusterWideMap(name, handler);
});
}
/**
* Get a cluster wide lock with the specified name. The lock will be passed to the handler when it is available.
* @param name the name of the lock
* @param resultHandler the handler
*/
public void getLock(String name, Handler> resultHandler) {
delegate.getLock(name, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
resultHandler.handle(io.vertx.core.Future.succeededFuture(Lock.newInstance(ar.result())));
} else {
resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Get a cluster wide lock with the specified name. The lock will be passed to the handler when it is available.
* @param name the name of the lock
* @return
*/
public Single rxGetLock(String name) {
return new io.vertx.reactivex.core.impl.AsyncResultSingle(handler -> {
getLock(name, handler);
});
}
/**
* Like {@link io.vertx.reactivex.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
* @param name the name of the lock
* @param timeout the timeout in ms
* @param resultHandler the handler
*/
public void getLockWithTimeout(String name, long timeout, Handler> resultHandler) {
delegate.getLockWithTimeout(name, timeout, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
resultHandler.handle(io.vertx.core.Future.succeededFuture(Lock.newInstance(ar.result())));
} else {
resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Like {@link io.vertx.reactivex.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
* @param name the name of the lock
* @param timeout the timeout in ms
* @return
*/
public Single rxGetLockWithTimeout(String name, long timeout) {
return new io.vertx.reactivex.core.impl.AsyncResultSingle(handler -> {
getLockWithTimeout(name, timeout, handler);
});
}
/**
* Get a cluster wide counter. The counter will be passed to the handler.
* @param name the name of the counter.
* @param resultHandler the handler
*/
public void getCounter(String name, Handler> resultHandler) {
delegate.getCounter(name, new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
resultHandler.handle(io.vertx.core.Future.succeededFuture(Counter.newInstance(ar.result())));
} else {
resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
}
/**
* Get a cluster wide counter. The counter will be passed to the handler.
* @param name the name of the counter.
* @return
*/
public Single rxGetCounter(String name) {
return new io.vertx.reactivex.core.impl.AsyncResultSingle(handler -> {
getCounter(name, handler);
});
}
/**
* Return a LocalMap
with the specific name
.
* @param name the name of the map
* @return the msp
*/
public LocalMap getLocalMap(String name) {
LocalMap ret = LocalMap.newInstance(delegate.getLocalMap(name), io.vertx.lang.reactivex.TypeArg.unknown(), io.vertx.lang.reactivex.TypeArg.unknown());
return ret;
}
public static SharedData newInstance(io.vertx.core.shareddata.SharedData arg) {
return arg != null ? new SharedData(arg) : null;
}
}