public static <K,V>AsyncMap<K,V> newInstance(io.vertx.core.shareddata.AsyncMap arg, io.vertx.lang.rx.TypeArg<K> __typeArg_K, io.vertx.lang.rx.TypeArg<V> __typeArg_V) { return arg != null ? new AsyncMap<K,V>(arg, __typeArg_K, __typeArg_V) : null; } }
@Override public void set(K key, V value) { voidAsyncOpToBlocking(map -> map.putObservable(key, value)); }
/** * Put the entry only if there is no entry with the key already present. If key already present then the existing * value will be returned to the handler, otherwise null. * @param k the key * @param v the value * @return * @deprecated use {@link #rxPutIfAbsent} instead */ @Deprecated() public Observable<V> putIfAbsentObservable(K k, V v) { io.vertx.rx.java.ObservableFuture<V> completionHandler = io.vertx.rx.java.RxHelper.observableFuture(); putIfAbsent(k, v, completionHandler.toHandler()); return completionHandler; }
/** * Put a value in the map, asynchronously. * @param k the key * @param v the value * @return * @deprecated use {@link #rxPut} instead */ @Deprecated() public Observable<Void> putObservable(K k, V v) { io.vertx.rx.java.ObservableFuture<Void> completionHandler = io.vertx.rx.java.RxHelper.observableFuture(); put(k, v, completionHandler.toHandler()); return completionHandler; }
/** * Get an asynchronous lock with the specified name. The lock will be passed to the handler when it is available. * <p> * 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. * </p> * @param name the name of the lock * @param resultHandler the handler */ public void getLock(String name, Handler<AsyncResult<io.vertx.rxjava.core.shareddata.Lock>> resultHandler) { delegate.getLock(name, new Handler<AsyncResult<io.vertx.core.shareddata.Lock>>() { public void handle(AsyncResult<io.vertx.core.shareddata.Lock> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.shareddata.Lock.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Remove a value from the map, only if entry already exists with same value. * @param k the key * @param v the value * @return * @deprecated use {@link #rxRemoveIfPresent} instead */ @Deprecated() public Observable<Boolean> removeIfPresentObservable(K k, V v) { io.vertx.rx.java.ObservableFuture<Boolean> resultHandler = io.vertx.rx.java.RxHelper.observableFuture(); removeIfPresent(k, v, resultHandler.toHandler()); return resultHandler; }
/** * Get a value from the map, asynchronously. * @param k the key * @return * @deprecated use {@link #rxGet} instead */ @Deprecated() public Observable<V> getObservable(K k) { io.vertx.rx.java.ObservableFuture<V> resultHandler = io.vertx.rx.java.RxHelper.observableFuture(); get(k, resultHandler.toHandler()); return resultHandler; }
/** * Remove a value from the map, asynchronously. * @param k the key * @return * @deprecated use {@link #rxRemove} instead */ @Deprecated() public Observable<V> removeObservable(K k) { io.vertx.rx.java.ObservableFuture<V> resultHandler = io.vertx.rx.java.RxHelper.observableFuture(); remove(k, resultHandler.toHandler()); return resultHandler; }
/** * Clear all entries in the map * @return * @deprecated use {@link #rxClear} instead */ @Deprecated() public Observable<Void> clearObservable() { io.vertx.rx.java.ObservableFuture<Void> resultHandler = io.vertx.rx.java.RxHelper.observableFuture(); clear(resultHandler.toHandler()); return resultHandler; }
@Override public V get(K key) { voidAsyncOpToBlocking(map -> map.getObservable((key))); final CompletableFuture<V> valueFuture = new CompletableFuture<>(); rxVertx.sharedData().<K, V>getClusterWideMapObservable(PAC4J_SHARED_DATA_KEY) .flatMap(map -> map.getObservable(key)) .subscribe(valueFuture::complete); try { return valueFuture.get(blockingTimeoutSeconds, TimeUnit.SECONDS); } catch (InterruptedException|ExecutionException|TimeoutException e) { throw new TechnicalException(e); } }
/** * Put the entry only if there is no entry with the key already present. If key already present then the existing * value will be returned to the handler, otherwise null. * @param k the key * @param v the value * @return */ public Single<V> rxPutIfAbsent(K k, V v) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { putIfAbsent(k, v, fut); })); }
/** * Like {@link io.vertx.rxjava.core.shareddata.AsyncMap#put} but specifying a time to live for the entry. Entry will expire and get evicted after the * ttl. * @param k the key * @param v the value * @param ttl The time to live (in ms) for the entry * @return * @deprecated use {@link #rxPut} instead */ @Deprecated() public Observable<Void> putObservable(K k, V v, long ttl) { io.vertx.rx.java.ObservableFuture<Void> completionHandler = io.vertx.rx.java.RxHelper.observableFuture(); put(k, v, ttl, completionHandler.toHandler()); return completionHandler; }
/** * 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. * <p> * 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. * </p> * @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<AsyncResult<io.vertx.rxjava.core.shareddata.Lock>> resultHandler) { delegate.getLockWithTimeout(name, timeout, new Handler<AsyncResult<io.vertx.core.shareddata.Lock>>() { public void handle(AsyncResult<io.vertx.core.shareddata.Lock> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.shareddata.Lock.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Remove a value from the map, only if entry already exists with same value. * @param k the key * @param v the value * @return */ public Single<Boolean> rxRemoveIfPresent(K k, V v) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { removeIfPresent(k, v, fut); })); }
/** * Get a value from the map, asynchronously. * @param k the key * @return */ public Single<V> rxGet(K k) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { get(k, fut); })); }
/** * Remove a value from the map, asynchronously. * @param k the key * @return */ public Single<V> rxRemove(K k) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { remove(k, fut); })); }
/** * Clear all entries in the map * @return */ public Single<Void> rxClear() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { clear(fut); })); }
@Override public V get(K key) { voidAsyncOpToBlocking(map -> map.getObservable((key))); final CompletableFuture<V> valueFuture = new CompletableFuture<>(); rxVertx.sharedData().<K, V>getClusterWideMapObservable(PAC4J_SHARED_DATA_KEY) .flatMap(map -> map.getObservable(key)) .subscribe(valueFuture::complete); try { return valueFuture.get(blockingTimeoutSeconds, TimeUnit.SECONDS); } catch (InterruptedException|ExecutionException|TimeoutException e) { throw new TechnicalException(e); } }
/** * Link {@link io.vertx.rxjava.core.shareddata.AsyncMap#putIfAbsent} but specifying a time to live for the entry. Entry will expire and get evicted * after the ttl. * @param k the key * @param v the value * @param ttl The time to live (in ms) for the entry * @return * @deprecated use {@link #rxPutIfAbsent} instead */ @Deprecated() public Observable<V> putIfAbsentObservable(K k, V v, long ttl) { io.vertx.rx.java.ObservableFuture<V> completionHandler = io.vertx.rx.java.RxHelper.observableFuture(); putIfAbsent(k, v, ttl, completionHandler.toHandler()); return completionHandler; }
/** * Put a value in the map, asynchronously. * @param k the key * @param v the value * @return */ public Single<Void> rxPut(K k, V v) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { put(k, v, fut); })); }