예제 #1
0
  /**
   * Add an operation to the given connection.
   *
   * @param which the connection offset
   * @param o the operation
   */
  public void addOperation(final String key, final Operation o) {
    MemcachedNode placeIn = null;
    MemcachedNode primary = locator.getPrimary(key);
    if (primary.isActive()) {
      placeIn = primary;
    } else {
      // Look for another node in sequence that is ready.
      for (Iterator<MemcachedNode> i = locator.getSequence(key); placeIn == null && i.hasNext(); ) {
        MemcachedNode n = i.next();
        if (n.isActive()) {
          placeIn = n;
        }
      }
      // If we didn't find an active node, queue it in the primary node
      // and wait for it to come back online.
      if (placeIn == null) {
        placeIn = primary;
      }
    }

    assert placeIn != null : "No node found for key " + key;
    addOperation(placeIn, o);
  }