private void blockUntilRunningAndAssignElasticIpsToInstancesOrPutIntoBadMap(
     Set<RunningInstance> input, Map<NodeMetadata, Exception> badNodes) {
   Map<RegionAndName, RunningInstance> instancesById =
       Maps.uniqueIndex(input, instanceToRegionAndName);
   for (Map.Entry<RegionAndName, RunningInstance> entry : instancesById.entrySet()) {
     RegionAndName id = entry.getKey();
     RunningInstance instance = entry.getValue();
     try {
       logger.debug("<< allocating elastic IP instance(%s)", id);
       String ip = client.getElasticIPAddressServices().allocateAddressInRegion(id.getRegion());
       // block until instance is running
       logger.debug(">> awaiting status running instance(%s)", id);
       AtomicReference<NodeMetadata> node =
           newReference(runningInstanceToNodeMetadata.apply(instance));
       nodeRunning.apply(node);
       logger.trace("<< running instance(%s)", id);
       logger.debug(">> associating elastic IP %s to instance %s", ip, id);
       client
           .getElasticIPAddressServices()
           .associateAddressInRegion(id.getRegion(), ip, id.getName());
       logger.trace("<< associated elastic IP %s to instance %s", ip, id);
       // add mapping of instance to ip into the cache
       elasticIpCache.put(id, ip);
     } catch (RuntimeException e) {
       badNodes.put(runningInstanceToNodeMetadata.apply(instancesById.get(id)), e);
     }
   }
 }
 @Override
 public void update(final User user) {
   if (user == null) {
     throw new IllegalArgumentException("User can't null");
   }
   if (Strings.isNullOrEmpty(user.getUsername())) {
     throw new IllegalArgumentException("Username of the user can't be null or empty");
   }
   User old = find(user.getUsername());
   String newEncryptPassword = generateEncryptPassword(user);
   if (!old.getPassword().equals(newEncryptPassword)) {
     user.setPassword(newEncryptPassword);
   }
   mongoDBUtil.keepConnect(
       userCollectionName,
       new CollectionCallback<Void>() {
         @Override
         public Void process(MongoCollection<Document> collection) {
           collection.updateOne(
               new Document(usernameKey, user.getUsername()),
               new Document("$set", new Document(usernameKey, user.getPassword())));
           return null;
         }
       });
   cache.put(user.getUsername(), user);
 }
 @Override
 public void delete(final String username) {
   mongoDBUtil.keepConnect(
       userCollectionName,
       new CollectionCallback<Void>() {
         @Override
         public Void process(MongoCollection<Document> collection) {
           collection.deleteOne(new Document(usernameKey, username));
           return null;
         }
       });
   cache.put(username, new User());
 }
 public static void updateRates(String type, long rate) {
   LOGGER.debug("updateRates : type={}, rate={}", type, rate);
   Iterator<RateLimiterDescriptor> iterator = rateLimiterMap.asMap().keySet().iterator();
   while (iterator.hasNext()) {
     RateLimiterDescriptor oldRateDesc = iterator.next();
     if (type.equals(oldRateDesc.getType())) {
       LOGGER.trace("updateRates : invalidated rate={}", oldRateDesc);
       rateLimiterMap.invalidate(oldRateDesc);
       RateLimiterDescriptor newRateDesc =
           new RateLimiterDescriptor(oldRateDesc.getType(), oldRateDesc.getAppId(), rate);
       LOGGER.trace("updateRates : updating rate desc={}, rate={}", newRateDesc, rate);
       rateLimiterMap.put(newRateDesc, RateLimiter.create(rate));
       rateLimiterMap.refresh(newRateDesc);
     }
   }
 }
 void put(LazyTopLevelItem.Key key, TopLevelItem item) {
   cache.put(key, item);
 }
 @Override
 public boolean put(DefinitionKey key, Resource value) {
   localCache.put(key, value);
   return false;
 }
  private Mustache compileIfChanged(String filename, boolean partial) {
    Mustache template = mustacheCache.getIfPresent(filename);

    if (template == null) {

      String desc = partial ? "partial" : "template";
      Log.debug("Compiling Mustache " + desc, "name", filename);

      Res res = getResource(filename, partial);
      template = customCompile(filename, res);

      res.onChange(
              "mustache",
              new Runnable() {
                @Override
                public void run() {
                  invalidateCache();
                }
              })
          .trackChanges();

      mustacheCache.put(filename, template);
    }

    return template;
  }