示例#1
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;
 }