Esempio n. 1
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. 2
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);
     }
   }
 }
Esempio n. 3
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 {
    ShardedJedis shardedJedis = null;
    Map<String, T> map = null;
    try {
      shardedJedis = shardedPool.getResource();
      Map<byte[], byte[]> hmap = shardedJedis.hgetAll(nodeName.getBytes());
      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);
    } finally {
      shardedPool.returnResourceObject(shardedJedis);
    }

    return map;
  }
Esempio n. 4
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)) {
     ShardedJedis shardedJedis = null;
     Map<byte[], byte[]> hmap = new HashMap<byte[], byte[]>();
     try {
       shardedJedis = shardedPool.getResource();
       for (Entry<String, T> entry : node.entrySet()) {
         byte[] value = SerializationUtil.serial(entry.getValue());
         if (value != null) {
           hmap.put(entry.getKey().getBytes(), value);
         }
       }
       shardedJedis.hmset(nodeName.getBytes(), hmap);
     } catch (UtilException e) {
       throw new CacheException(e);
     } catch (Exception e) {
       throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e);
     } finally {
       shardedPool.returnResourceObject(shardedJedis);
     }
   }
 }