Exemplo n.º 1
0
 private static void printQueueEventsListElementIds(ArrayList<QueueEvent> topN) {
   if (LOG.isDebugEnabled() && !topN.isEmpty()) {
     StringBuilder sb = new StringBuilder("[");
     for (QueueEvent queueEvent : topN) {
       sb.append(queueEvent.getId()).append(", ");
     }
     sb.append("]");
     LOG.debug("Returning topN elements: {}", sb.toString());
   }
 }
Exemplo n.º 2
0
  /** Gets last element of the Queue without removing it. */
  public String getTailId() throws KeeperException, InterruptedException {
    // TODO: could we use getChildren here?  Unsure what freshness guarantee the caller needs.
    TreeSet<String> orderedChildren = fetchZkChildren(null);

    for (String headNode : orderedChildren.descendingSet())
      if (headNode != null) {
        try {
          QueueEvent queueEvent =
              new QueueEvent(
                  dir + "/" + headNode,
                  zookeeper.getData(dir + "/" + headNode, null, null, true),
                  null);
          return queueEvent.getId();
        } catch (KeeperException.NoNodeException e) {
          // Another client removed the node first, try next
        }
      }
    return null;
  }
Exemplo n.º 3
0
 /** Remove the event and save the response into the other path. */
 public byte[] remove(QueueEvent event) throws KeeperException, InterruptedException {
   TimerContext time = stats.time(dir + "_remove_event");
   try {
     String path = event.getId();
     String responsePath = dir + "/" + response_prefix + path.substring(path.lastIndexOf("-") + 1);
     if (zookeeper.exists(responsePath, true)) {
       zookeeper.setData(responsePath, event.getBytes(), true);
     } else {
       LOG.info(
           "Response ZK path: "
               + responsePath
               + " doesn't exist."
               + "  Requestor may have disconnected from ZooKeeper");
     }
     byte[] data = zookeeper.getData(path, null, null, true);
     zookeeper.delete(path, -1, true);
     return data;
   } finally {
     time.stop();
   }
 }