private List<String> getCurrentServerIds(boolean nag, boolean lagged) {
   try (Jedis jedis = pool.getResource()) {
     long time = getRedisTime(jedis.time());
     int nagTime = 0;
     if (nag) {
       nagTime = nagAboutServers.decrementAndGet();
       if (nagTime <= 0) {
         nagAboutServers.set(10);
       }
     }
     ImmutableList.Builder<String> servers = ImmutableList.builder();
     Map<String, String> heartbeats = jedis.hgetAll("heartbeats");
     for (Map.Entry<String, String> entry : heartbeats.entrySet()) {
       try {
         long stamp = Long.parseLong(entry.getValue());
         if (lagged ? time >= stamp + 30 : time <= stamp + 30) servers.add(entry.getKey());
         else if (nag && nagTime <= 0) {
           getLogger()
               .severe(
                   entry.getKey()
                       + " is "
                       + (time - stamp)
                       + " seconds behind! (Time not synchronized or server down?)");
         }
       } catch (NumberFormatException ignored) {
       }
     }
     return servers.build();
   } catch (JedisConnectionException e) {
     getLogger().log(Level.SEVERE, "Unable to fetch server IDs", e);
     return Collections.singletonList(configuration.getServerId());
   }
 }
Exemple #2
0
 public void onStart(Application app) {
   JedisPool p = app.plugin(RedisPlugin.class).jedisPool();
   // uncomment to test sentinel setup
   // JedisSentinelPool p = app.plugin(RedisPlugin.class).jedisSentinelPool();
   Jedis j = p.getResource();
   j.set("foo", "yay");
   p.returnResource(j);
   Cache.set("foo2", 5);
   Map<String, String> m = new HashMap<String, String>();
   m.put("test", "value");
   Cache.set("foo3", m);
 }