Esempio n. 1
0
 @Override
 public synchronized void push(Request request, Task task) {
   Jedis jedis = pool.getResource();
   // 使用SortedSet进行url去重
   if (jedis.zrank(SET_PREFIX + task.getUUID(), request.getUrl()) == null) {
     // 使用List保存队列
     jedis.rpush(QUEUE_PREFIX + task.getUUID(), request.getUrl());
     jedis.zadd(SET_PREFIX + task.getUUID(), System.currentTimeMillis(), request.getUrl());
   }
   pool.returnResource(jedis);
 }
Esempio n. 2
0
 @Override
 public synchronized Request poll(Task task) {
   Jedis jedis = pool.getResource();
   String url = jedis.lpop(QUEUE_PREFIX + task.getUUID());
   pool.returnResource(jedis);
   if (url == null) {
     return null;
   }
   return new Request(url);
 }
 @Override
 public void process(Object o, Task task) {
   String path = this.path + "/" + task.getUUID() + "/";
   try {
     String filename;
     if (o instanceof HasKey) {
       filename = path + ((HasKey) o).key() + ".json";
     } else {
       filename = path + DigestUtils.md5Hex(ToStringBuilder.reflectionToString(o)) + ".json";
     }
     PrintWriter printWriter = new PrintWriter(new FileWriter(getFile(filename)));
     printWriter.write(JSON.toJSONString(o));
     printWriter.close();
   } catch (IOException e) {
     logger.warn("write file error", e);
   }
 }
 private String getFileName(String filename) {
   return filePath + task.getUUID() + filename;
 }