Esempio n. 1
0
 /**
  * Description: <br>
  *
  * @author 王伟<br>
  * @taskId <br>
  * @param nodeName
  * @param key
  * @throws CacheException <br>
  */
 @Override
 public void removeValue(String nodeName, String key) throws CacheException {
   try {
     cluster.hdel(nodeName, key);
   } catch (Exception e) {
     throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e);
   }
 }
Esempio n. 2
0
 /**
  * Description: <br>
  *
  * @author 王伟<br>
  * @taskId <br>
  * @param nodeName
  * @return
  * @throws CacheException <br>
  */
 @Override
 public boolean removeNode(String nodeName) throws CacheException {
   try {
     cluster.del(nodeName);
   } catch (Exception e) {
     throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e);
   }
   return true;
 }
Esempio n. 3
0
 /**
  * Description: <br>
  *
  * @author 王伟<br>
  * @taskId <br>
  * @param nodeName
  * @param key
  * @param t
  * @throws CacheException <br>
  */
 @Override
 public <T> void putValue(String nodeName, String key, T t) throws CacheException {
   if (t != null) {
     try {
       cluster.hset(nodeName, key, SerializationUtil.serial(t));
     } catch (UtilException e) {
       throw new CacheException(e);
     } catch (Exception e) {
       throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e);
     }
   }
 }
Esempio n. 4
0
 /**
  * Description: <br>
  *
  * @author 王伟<br>
  * @taskId <br>
  * @param clazz
  * @param nodeName
  * @param key
  * @return
  * @throws CacheException <br>
  */
 @Override
 public <T> T getValue(Class<T> clazz, String nodeName, String key) throws CacheException {
   T value = null;
   try {
     value = SerializationUtil.unserial(clazz, cluster.hgetBytes(nodeName, key));
   } catch (UtilException e) {
     throw new CacheException(e);
   } catch (Exception e) {
     throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e);
   }
   return value;
 }
Esempio n. 5
0
  /**
   * Description: <br>
   *
   * @author 王伟<br>
   * @taskId <br>
   * @param clazz
   * @param nodeName
   * @return
   * @throws CacheException <br>
   */
  @Override
  public <T> Map<String, T> getNode(Class<T> clazz, String nodeName) throws CacheException {
    Map<String, T> map = null;
    try {
      Map<byte[], byte[]> hmap = cluster.hgetAllBytes(nodeName);
      if (CommonUtil.isNotEmpty(hmap)) {
        map = new HashMap<String, T>();
        for (Entry<byte[], byte[]> entry : hmap.entrySet()) {
          map.put(new String(entry.getKey()), SerializationUtil.unserial(clazz, entry.getValue()));
        }
      }
    } catch (UtilException e) {
      throw new CacheException(e);
    } catch (Exception e) {
      throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e);
    }

    return map;
  }
Esempio n. 6
0
 /**
  * Description: <br>
  *
  * @author 王伟<br>
  * @taskId <br>
  * @param nodeName
  * @param node
  * @throws CacheException <br>
  */
 @Override
 public <T> void putNode(String nodeName, Map<String, T> node) throws CacheException {
   if (CommonUtil.isNotEmpty(node)) {
     Map<byte[], byte[]> hmap = new HashMap<byte[], byte[]>();
     try {
       for (Entry<String, T> entry : node.entrySet()) {
         byte[] value = SerializationUtil.serial(entry.getValue());
         if (value != null) {
           hmap.put(entry.getKey().getBytes(), value);
         }
       }
       cluster.hmsetBytes(nodeName, hmap);
     } catch (UtilException e) {
       throw new CacheException(e);
     } catch (Exception e) {
       throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e);
     }
   }
 }