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;
  }
  @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));
    }
  }
 public MockStateService(Map<String, Object> config) {
   this();
   synchronized (_state) {
     for (Entry<String, Object> e : config.entrySet()) {
       _state.put(e.getKey(), Utils.serialize(e.getValue()));
     }
   }
 }
 @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;
 }
 @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());
       }
     }
   }
 }
 /**
  * * 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;
 }
 /**
  * * Use to (optionally) defer all callbacks
  *
  * @param fn
  */
 private void maybeDefer(final Runnable fn) {
   Utils.schedule(_defer, fn);
 }