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

io.vertx.tp.plugin.session.SessionInfix Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
package io.vertx.tp.plugin.session;

import io.vertx.core.Vertx;
import io.vertx.up.annotations.Plugin;
import io.vertx.up.eon.Plugins;
import io.vertx.up.fn.Fn;
import io.vertx.up.plugin.Infix;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@Plugin
@SuppressWarnings("unchecked")
public class SessionInfix implements Infix {

    private static final String NAME = "ZERO_SESSION_POOL";
    private static final ConcurrentMap CLIENTS
            = new ConcurrentHashMap<>();

    private static void initInternal(final Vertx vertx,
                                     final String name) {
        Fn.pool(CLIENTS, name,
                () -> Infix.initTp(Plugins.Infix.SESSION,
                        (config) -> SessionClient.createShared(vertx, config),
                        SessionInfix.class));
    }

    public static void init(final Vertx vertx) {
        initInternal(vertx, NAME);
    }

    public static SessionClient getClient() {
        return CLIENTS.get(NAME);
    }

    public static SessionClient getOrCreate(final Vertx vertx) {
        return Fn.pool(CLIENTS, NAME, () -> SessionClient.createShared(vertx));
    }

    @Override
    public SessionClient get() {
        return getClient();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy