コード例 #1
0
  public List<Pair<String, Object>> queryStates(String query) {
    List<Pair<String, Object>> list = Lists.newArrayList();
    synchronized (_state) {
      for (Entry<String, byte[]> e : new HashSet<Entry<String, byte[]>>(_state.entrySet())) {
        if (Utils.matchGlob(e.getKey(), query)) {
          list.add(new Pair<String, Object>(e.getKey(), Utils.deserialize(e.getValue())));
        }
      }
    }

    return list;
  }
コード例 #2
0
  @Override
  public <T> void setState(final String key, final T val) {
    // _log.debug("set state: " + key + " " + val);

    synchronized (_state) {
      _state.put(key, Utils.serialize(val));
    }
  }
コード例 #3
0
 public MockStateService(Map<String, Object> config) {
   this();
   synchronized (_state) {
     for (Entry<String, Object> e : config.entrySet()) {
       _state.put(e.getKey(), Utils.serialize(e.getValue()));
     }
   }
 }
コード例 #4
0
 @SuppressWarnings("unchecked")
 @Override
 public <T> T getState(String key, T defaultValue) {
   // _log.debug("get state: " + key);
   if (_state.containsKey(key)) {
     return (T) Utils.deserialize(_state.get(key));
   }
   return defaultValue;
 }
コード例 #5
0
 @Override
 public void removeStateWithPrefix(String pattern) {
   synchronized (_state) {
     for (Entry<String, byte[]> e : new HashSet<Entry<String, byte[]>>(_state.entrySet())) {
       if (Utils.matchGlob(e.getKey(), pattern)) {
         // _log.debug("removing state : " + e.getKey());
         _state.remove(e.getKey());
       }
     }
   }
 }
コード例 #6
0
 /**
  * * Used to select patterns based on globs
  *
  * @param key
  * @param list
  * @return
  */
 private <T> List<Pair<String, T>> globSelect(String key, List<Pair<String, T>> list) {
   List<Pair<String, T>> retList = Lists.newArrayList();
   synchronized (list) {
     for (Pair<String, T> p : list) {
       if (Utils.matchGlob(key, p.getValue0())) {
         retList.add(p);
       }
     }
   }
   return retList;
 }
コード例 #7
0
 /**
  * * Use to (optionally) defer all callbacks
  *
  * @param fn
  */
 private void maybeDefer(final Runnable fn) {
   Utils.schedule(_defer, fn);
 }