Esempio n. 1
0
 public List<Long> getScheduled(long start, long end, int size)
     throws InterruptedException, KeeperException {
   List<Long> result = new ArrayList<Long>(size);
   List<QueueItem> scheduled = dq.getScheduled();
   for (QueueItem i : scheduled) {
     // handle timeout:
     if (i.getTimeout() > start && i.getTimeout() < end) {
       result.add(i.getId());
       // handle max-size:
       if (size == result.size()) {
         break;
       }
     }
   }
   return result;
 }
Esempio n. 2
0
 /**
  * Returns the next task-id when available of the task that needs to be executed, it will wait for
  * <tt>timeout</tt> milliseconds
  *
  * @param timeout milliseconds to wait.
  * @return task id or -1 if failed
  * @throws InterruptedException
  */
 public long poll(long timeout) throws InterruptedException {
   long time = System.currentTimeMillis();
   try {
     QueueItem item = dq.take(timeout);
     time = System.currentTimeMillis() - time;
     if (item != null) {
       LOG.debug("found: {} in {}ms", item.getId(), time);
       return item.getId();
     }
   } catch (KeeperException e) {
     LOG.error("failed to poll item", e);
   } catch (IOException e) {
     LOG.error("failed to poll item", e);
   }
   return -1;
 }