Java Code Examples for io.vertx.core.shareddata.LocalMap#put()

The following examples show how to use io.vertx.core.shareddata.LocalMap#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RateLimitationHandler.java    From nubes with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext context) {
  Vertx vertx = context.vertx();
  LocalMap<Object, Object> rateLimitations = vertx.sharedData().getLocalMap("mvc.rateLimitation");
  String clientIp = context.request().remoteAddress().host();
  JsonObject json = (JsonObject) rateLimitations.get(clientIp);
  ClientAccesses accesses;
  if (json == null) {
    accesses = new ClientAccesses();
  } else {
    accesses = ClientAccesses.fromJsonObject(json);
  }
  accesses.newAccess();
  rateLimitations.put(clientIp, accesses.toJsonObject());
  if (accesses.isOverLimit(rateLimit)) {
    context.fail(420);
  } else {
    context.next();
  }
}
 
Example 2
Source File: MailClientImpl.java    From vertx-mail-client with Apache License 2.0 5 votes vote down vote up
private MailHolder lookupHolder(String poolName, MailConfig config) {
  synchronized (vertx) {
    LocalMap<String, MailHolder> map = vertx.sharedData().getLocalMap(POOL_LOCAL_MAP_NAME);
    MailHolder theHolder = map.get(poolName);
    if (theHolder == null) {
      theHolder = new MailHolder(vertx, config, () -> removeFromMap(map, poolName));
      map.put(poolName, theHolder);
    } else {
      theHolder.incRefCount();
    }
    return theHolder;
  }
}
 
Example 3
Source File: WSLocalHandler.java    From vert.x-microservice with Apache License 2.0 5 votes vote down vote up
private void replaceOrAddEndpoint(LocalMap<String, byte[]> wsRegistry, WSEndpointHolder holder, WSEndpoint endpoint) {
    if (holder != null) {
        holder.add(endpoint);
        wsRegistry.replace(WS_ENDPOINT_HOLDER, serialize(holder));

    } else {
        final WSEndpointHolder holderTemp = new WSEndpointHolder();
        holderTemp.add(endpoint);
        wsRegistry.put(WS_ENDPOINT_HOLDER, serialize(holderTemp));
    }
}
 
Example 4
Source File: MongoClientImpl.java    From vertx-mongo-client with Apache License 2.0 5 votes vote down vote up
private MongoHolder lookupHolder(String datasourceName, JsonObject config) {
  synchronized (vertx) {
    LocalMap<String, MongoHolder> map = vertx.sharedData().getLocalMap(DS_LOCAL_MAP_NAME);
    MongoHolder theHolder = map.get(datasourceName);
    if (theHolder == null) {
      theHolder = new MongoHolder(config, () -> removeFromMap(map, datasourceName));
      map.put(datasourceName, theHolder);
    } else {
      theHolder.incRefCount();
    }
    return theHolder;
  }
}
 
Example 5
Source File: MQTTStoreManagerAsync.java    From vertx-mqtt-broker with Apache License 2.0 5 votes vote down vote up
private void decrementID(String k) {
    Integer currentID=0;
    LocalMap<String, Integer> seq = seq();
    if(seq.keySet().contains(k)) {
        currentID = seq.get(k);
        if (currentID > 0) {
            seq.put(k, currentID - 1);
        }
    }
}