protected void addOperation(final String key, final Operation o) {
    MemcachedNode placeIn = null;
    MemcachedNode primary = locator.getPrimary(key);

    if (primary.isActive() || failureMode == FailureMode.Retry) {
      placeIn = primary;
    } else if (failureMode == FailureMode.Cancel) {
      o.cancel();
    } else {
      Iterator<MemcachedNode> i = locator.getSequence(key);
      while (placeIn == null && i.hasNext()) {
        MemcachedNode n = i.next();
        if (n.isActive()) {
          placeIn = n;
        }
      }

      if (placeIn == null) {
        placeIn = primary;
        this.getLogger().warn("Could not redistribute to another node, "
          + "retrying primary node for %s.", key);
      }
    }

    assert o.isCancelled() || placeIn != null : "No node found for key " + key;
    if (placeIn != null) {
      addOperation(placeIn, o);
    } else {
      assert o.isCancelled() : "No node found for " + key + " (and not "
        + "immediately cancelled)";
    }
  }
protected void addOperation ( final String key , final Operation o ) { MemcachedNode placeIn = null ; MemcachedNode primary = locator . getPrimary ( key ) ; if ( primary . isActive ( ) || failureMode == FailureMode . Retry ) { placeIn = primary ; } else if ( failureMode == FailureMode . Cancel ) { o . cancel ( ) ; } else { Iterator < MemcachedNode > i = locator . getSequence ( key ) ; while ( placeIn == null && i . hasNext ( ) ) { MemcachedNode n = i . next ( ) ; if ( n . isActive ( ) ) { placeIn = n ; } } if ( placeIn == null ) { placeIn = primary ; this . getLogger ( ) . warn ( "Could not redistribute to another node, " + "retrying primary node for %s." , key ) ; } } assert o . isCancelled ( ) || placeIn != null : "No node found for key " + key ; if ( placeIn != null ) { addOperation ( placeIn , o ) ; } else { assert o . isCancelled ( ) : "No node found for " + key + " (and not " + "immediately cancelled)" ; } }
Add an operation to a connection identified by the given key.

If the {@link MemcachedNode} is active or the {@link FailureMode} is set
to retry, the primary node will be used for that key. If the primary
node is not available and the {@link FailureMode} cancel is used, the
operation will be cancelled without further retry.

For any other {@link FailureMode} mechanisms (Redistribute), another
possible node is used (only if its active as well). If no other active
node could be identified, the original primary node is used and retried.

@param key the key the operation is operating upon.
@param o the operation to add.