Example usage for io.vertx.core.spi.cluster ClusterManager getSyncMap

List of usage examples for io.vertx.core.spi.cluster ClusterManager getSyncMap

Introduction

In this page you can find the example usage for io.vertx.core.spi.cluster ClusterManager getSyncMap.

Prototype

<K, V> Map<K, V> getSyncMap(String name);

Source Link

Document

Return a synchronous map for the given name

Usage

From source file:com.github.edgar615.util.vertx.sharedata.SyncMap.java

License:Open Source License

/**
 * Creates a new async map./*w w  w .  j a  va2  s  . co m*/
 *
 * @param vertx the vert.x instance
 * @param name  the name of the underlying structure (either a local map for non-clustered
 *              vert.x, or a sync map for clustered vert.x)
 */
public SyncMap(Vertx vertx, String name) {
    this.vertx = vertx;
    ClusterManager clusterManager = ((VertxInternal) vertx).getClusterManager();
    if (clusterManager == null) {
        delegateMap = new LocalMapWrapper<>(vertx.sharedData().<K, V>getLocalMap(name));
    } else {
        delegateMap = clusterManager.getSyncMap(name);
    }
}

From source file:eu.rethink.mn.pipeline.PipeRegistry.java

License:Apache License

public PipeRegistry(Vertx vertx, ClusterManager mgr, String domain) {
    this.domain = domain;
    this.mgr = mgr;

    this.eb = vertx.eventBus();
    this.eb.registerDefaultCodec(PipeContext.class, new MessageCodec<PipeContext, PipeContext>() {

        @Override/*from  w  w  w.j  a v  a  2  s.  c o  m*/
        public byte systemCodecID() {
            return -1;
        }

        @Override
        public String name() {
            return PipeContext.class.getName();
        }

        @Override
        public PipeContext transform(PipeContext ctx) {
            return ctx;
        }

        @Override
        public void encodeToWire(Buffer buffer, PipeContext ctx) {
            final String msg = ctx.getMessage().toString();
            logger.info("encodeToWire: " + msg);
            buffer.appendString(msg);
        }

        @Override
        public PipeContext decodeFromWire(int pos, Buffer buffer) {
            final String msg = buffer.getString(0, buffer.length() - 1);
            logger.info("decodeFromWire: " + msg);
            return null; //not needed in this architecture
        }
    });

    this.components = new HashMap<String, IComponent>();
    this.sessions = new HashMap<String, PipeSession>();

    this.urlSpace = mgr.getSyncMap("urlSpace");
}

From source file:org.entcore.common.utils.MapFactory.java

License:Open Source License

@Deprecated
public static <K, V> Map<K, V> getSyncClusterMap(String name, Vertx vertx, boolean elseLocalMap) {
    LocalMap<Object, Object> server = vertx.sharedData().getLocalMap("server");
    Boolean cluster = (Boolean) server.get("cluster");
    final Map<K, V> map;
    if (Boolean.TRUE.equals(cluster)) {
        ClusterManager cm = ((VertxInternal) vertx).getClusterManager();
        map = cm.getSyncMap(name);
    } else if (elseLocalMap) {
        map = vertx.sharedData().getLocalMap(name);
    } else {//  w  ww. j  av  a 2 s.  co m
        map = new HashMap<>();
    }
    return map;
}

From source file:org.entcore.session.AuthManager.java

License:Open Source License

public void start() {
    super.start();
    LocalMap<Object, Object> server = vertx.sharedData().getLocalMap("server");
    String neo4jConfig = (String) server.get("neo4jConfig");
    neo4j = Neo4j.getInstance();//from  w  w  w .j  a va2s  .  c  om
    neo4j.init(vertx, new JsonObject(neo4jConfig));
    Boolean cluster = (Boolean) server.get("cluster");
    String node = (String) server.get("node");
    mongo = MongoDb.getInstance();
    mongo.init(vertx.eventBus(), node + config.getString("mongo-address", "wse.mongodb.persistor"));
    if (Boolean.TRUE.equals(cluster)) {
        ClusterManager cm = ((VertxInternal) vertx).getClusterManager();
        sessions = cm.getSyncMap("sessions");
        logins = cm.getSyncMap("logins");
        if (getOrElse(config.getBoolean("inactivy"), false)) {
            inactivity = cm.getSyncMap("inactivity");
            logger.info("inactivity ha map : " + inactivity.getClass().getName());
        }
        logger.info("Initialize session cluster maps.");
    } else {
        sessions = new HashMap<>();
        logins = new HashMap<>();
        if (getOrElse(config.getBoolean("inactivy"), false)) {
            inactivity = new HashMap<>();
        }
        logger.info("Initialize session hash maps.");
    }
    final String address = getOptionalStringConfig("address", "wse.session");
    Object timeout = config.getValue("session_timeout");
    if (timeout != null) {
        if (timeout instanceof Long) {
            this.sessionTimeout = (Long) timeout;
        } else if (timeout instanceof Integer) {
            this.sessionTimeout = (Integer) timeout;
        }
    } else {
        this.sessionTimeout = DEFAULT_SESSION_TIMEOUT;
    }

    eb.localConsumer(address, this);
}