
io.vertx.up.unity.UxPool Maven / Gradle / Ivy
package io.vertx.up.unity;
import io.vertx.core.Future;
import io.vertx.tp.plugin.shared.MapInfix;
import io.vertx.tp.plugin.shared.SharedClient;
import io.vertx.up.atom.Kv;
import io.vertx.up.exception.web._500PoolInternalException;
import io.vertx.up.fn.Fn;
import io.vertx.up.log.Annal;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* Shared Data for pool usage in utility X
*/
@SuppressWarnings("all")
public class UxPool {
private static final Annal LOGGER = Annal.get(UxPool.class);
private transient final String name;
private transient final SharedClient client;
UxPool() {
this.name = MapInfix.getDefaultName();
this.client = MapInfix.getClient();
}
UxPool(final String name) {
this.name = name;
this.client = MapInfix.getClient().switchClient(name);
}
public String name() {
return this.name;
}
// Put Operation
public Future> put(final K key, final V value) {
return Fn.>thenGeneric(future -> this.client.put(key, value, res -> {
LOGGER.debug(Info.POOL_PUT, key, value, this.name);
Fn.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "put"));
}));
}
public Future> put(final K key, final V value, int expiredSecs) {
return Fn.>thenGeneric(future -> this.client.put(key, value, expiredSecs, res -> {
LOGGER.debug(Info.POOL_PUT_TIMER, key, value, this.name, String.valueOf(expiredSecs));
Fn.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "put"));
}));
}
// Remove
public Future> remove(final K key) {
return Fn.>thenGeneric(future -> this.client.remove(key, res -> {
LOGGER.debug(Info.POOL_REMOVE, key, this.name);
Fn.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "remove"));
}));
}
// Get
public Future get(final K key) {
return Fn.thenGeneric(future -> this.client.get(key, res -> {
LOGGER.debug(Info.POOL_GET, key, this.name, false);
Fn.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "get"));
}));
}
public Future> get(final Set keys) {
final ConcurrentMap> futureMap = new ConcurrentHashMap<>();
keys.forEach(key -> futureMap.put(key, this.get(key)));
return Combine.thenCombine(futureMap);
}
public Future get(final K key, final boolean once) {
return Fn.thenGeneric(future -> this.client.get(key, once, res -> {
LOGGER.debug(Info.POOL_GET, key, this.name, once);
Fn.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "get"));
}));
}
public Future clear() {
return Fn.thenGeneric(future -> this.client.clear(res -> {
LOGGER.debug(Info.POOL_CLEAR, this.name);
Fn.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "clear"));
}));
}
// Count
public Future size() {
return Fn.thenGeneric(future -> this.client.size(res -> {
Fn.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "size"));
}));
}
public Future> keys() {
return Fn.>thenGeneric(future -> this.client.keys(res -> {
Fn.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "keys"));
}));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy