All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.up.unity.UxPool Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
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.exception.web._500PoolInternalException;
import io.vertx.up.log.Annal;
import io.vertx.up.uca.container.Kv;

/**
 * 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);
    }

    // Put Operation
    public  Future> put(final K key, final V value) {
        return Ux.>thenGeneric(future -> this.client.put(key, value, res -> {
            LOGGER.debug(Info.POOL_PUT, key, value, this.name);
            Ux.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "put"));
        }));
    }

    public  Future> put(final K key, final V value, int expiredSecs) {
        return Ux.>thenGeneric(future -> this.client.put(key, value, expiredSecs, res -> {
            LOGGER.debug(Info.POOL_PUT_TIMER, key, value, this.name, String.valueOf(expiredSecs));
            Ux.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "put"));
        }));
    }

    // Remove
    public  Future> remove(final K key) {
        return Ux.>thenGeneric(future -> this.client.remove(key, res -> {
            LOGGER.debug(Info.POOL_REMOVE, key, this.name);
            Ux.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "remove"));
        }));
    }

    // Get
    public  Future get(final K key) {
        return Ux.thenGeneric(future -> this.client.get(key, res -> {
            LOGGER.debug(Info.POOL_GET, key, this.name, false);
            Ux.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "remove"));
        }));
    }

    public  Future get(final K key, final boolean once) {
        return Ux.thenGeneric(future -> this.client.get(key, once, res -> {
            LOGGER.debug(Info.POOL_GET, key, this.name, once);
            Ux.thenGeneric(res, future, To.toError(_500PoolInternalException.class, this.getClass(), this.name, "remove"));
        }));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy