Package net.spy.memcached.ops

Examples of net.spy.memcached.ops.Operation


    final CountDownLatch latch=new CountDownLatch(1);
    final OperationFuture<CASValue<T>> rv=
      new OperationFuture<CASValue<T>>(latch, operationTimeout);

    Operation op=opFact.gets(key,
        new GetsOperation.Callback() {
      private CASValue<T> val=null;
      public void receivedStatus(OperationStatus status) {
        rv.set(val);
      }
View Full Code Here


    final Map<MemcachedNode, Operation> mops=
      new HashMap<MemcachedNode, Operation>();

    for(Map.Entry<MemcachedNode, Collection<String>> me
        : chunks.entrySet()) {
      Operation op=opFact.get(me.getValue(), cb);
      mops.put(me.getKey(), op);
      ops.add(op);
    }
    assert mops.size() == chunks.size();
    checkState();
View Full Code Here

  private Future<Long> asyncMutate(Mutator m, String key, int by, long def,
      int exp) {
    final CountDownLatch latch = new CountDownLatch(1);
    final OperationFuture<Long> rv = new OperationFuture<Long>(
        latch, operationTimeout);
    Operation op = addOp(key, opFact.mutate(m, key, by, def, exp,
        new OperationCallback() {
      public void receivedStatus(OperationStatus s) {
        rv.set(new Long(s.isSuccess() ? s.getMessage() : "-1"));
      }
      public void complete() {
View Full Code Here

    final ConcurrentLinkedQueue<Operation> ops=
      new ConcurrentLinkedQueue<Operation>();
    CountDownLatch blatch = broadcastOp(new BroadcastOpFactory(){
      public Operation newOp(final MemcachedNode n,
          final CountDownLatch latch) {
        Operation op=opFact.flush(delay, new OperationCallback(){
          public void receivedStatus(OperationStatus s) {
            flushResult.set(s.isSuccess());
          }
          public void complete() {
            latch.countDown();
          }});
        ops.add(op);
        return op;
      }});
    return new OperationFuture<Boolean>(blatch, flushResult,
        operationTimeout) {
      @Override
      public boolean cancel(boolean ign) {
        boolean rv=false;
        for(Operation op : ops) {
          op.cancel();
          rv |= op.getState() == OperationState.WRITING;
        }
        return rv;
      }
      @Override
      public boolean isCancelled() {
        boolean rv=false;
        for(Operation op : ops) {
          rv |= op.isCancelled();
        }
        return rv;
      }
      @Override
      public boolean isDone() {
        boolean rv=true;
        for(Operation op : ops) {
          rv &= op.getState() == OperationState.COMPLETE;
        }
        return rv || isCancelled();
      }
    };
  }
View Full Code Here

          latch.countDown();
        }
      };

      // Get the prior status to create the correct operation.
      final Operation op = buildOperation(priorStatus, cb);

      conn.insertOperation(node, op);

      try {
        latch.await();
        Thread.sleep(100);
      } catch(InterruptedException e) {
        // we can be interrupted if we were in the
        // process of auth'ing and the connection is
        // lost or dropped due to bad auth
        Thread.currentThread().interrupt();
        if (op != null) {
          op.cancel();
        }
        done.set(true); // If we were interrupted, tear down.
      }

      // Get the new status to inspect it.
View Full Code Here

    final CountDownLatch latch = new CountDownLatch(1);
    final OperationFuture<CASValue<T>> rv =
        new OperationFuture<CASValue<T>>(key, latch, operationTimeout,
          executorService);

    Operation op = opFact.getl(key, exp, new GetlOperation.Callback() {
      private CASValue<T> val = null;

      public void receivedStatus(OperationStatus status) {
        if (!status.isSuccess()) {
          val = new CASValue<T>(-1, null);
View Full Code Here

    for(int index=0; index < replicaCount; index++) {
      final CountDownLatch latch = new CountDownLatch(1);
      final GetFuture<T> rv =
        new GetFuture<T>(latch, operationTimeout, key, executorService);
      Operation op = opFact.replicaGet(key, index,
        new ReplicaGetOperation.Callback() {
          private Future<T> val = null;

          @Override
          public void receivedStatus(OperationStatus status) {
            rv.set(val, status);
            if (!replicaFuture.isDone()) {
              replicaFuture.setCompletedFuture(rv);
            }
          }

          @Override
          public void gotData(String k, int flags, byte[] data) {
            assert key.equals(k) : "Wrong key returned";
            val = tcService.decode(tc, new CachedData(flags, data,
              tc.getMaxSize()));
          }

          @Override
          public void complete() {
            latch.countDown();
          }
        });

      rv.setOperation(op);
      mconn.enqueueOperation(key, op);

      if (op.isCancelled()) {
        discardedOps++;
        getLogger().debug("Silently discarding replica get for key \""
          + key + "\" (cancelled).");
      } else {
        replicaFuture.addFutureToMonitor(rv);
View Full Code Here

  public <T> OperationFuture<Boolean> asyncUnlock(final String key,
          long casId, final Transcoder<T> tc) {
    final CountDownLatch latch = new CountDownLatch(1);
    final OperationFuture<Boolean> rv = new OperationFuture<Boolean>(key,
            latch, operationTimeout, executorService);
    Operation op = opFact.unlock(key, casId, new OperationCallback() {

      @Override
      public void receivedStatus(OperationStatus s) {
        rv.set(s.isSuccess(), s);
      }
View Full Code Here

  public OperationFuture<Map<String, String>> getKeyStats(String key) {
    final CountDownLatch latch = new CountDownLatch(1);
    final OperationFuture<Map<String, String>> rv =
        new OperationFuture<Map<String, String>>(key, latch, operationTimeout,
          executorService);
    Operation op = opFact.keyStats(key, new StatsOperation.Callback() {
      private Map<String, String> stats = new HashMap<String, String>();
      public void gotStat(String name, String val) {
        stats.put(name, val);
      }
View Full Code Here

  }

  public void addOperations(final Map<MemcachedNode, Operation> ops) {
    for (Map.Entry<MemcachedNode, Operation> me : ops.entrySet()) {
      final MemcachedNode node = me.getKey();
      Operation o = me.getValue();
      // add the vbucketIndex to the operation
      if (locator instanceof VBucketNodeLocator) {
        if (o instanceof KeyedOperation && o instanceof VBucketAware) {
          Collection<String> keys = ((KeyedOperation) o).getKeys();
          VBucketNodeLocator vbucketLocator = (VBucketNodeLocator) locator;
          for (String key : keys) {
            short vbucketIndex = (short) vbucketLocator.getVBucketIndex(key);
            VBucketAware vbucketAwareOp = (VBucketAware) o;
            vbucketAwareOp.setVBucket(key, vbucketIndex);
          }
        }
      }
      o.setHandlingNode(node);
      o.initialize();
      node.addOp(o);
      addedQueue.offer(node);
    }
    Selector s = selector.wakeup();
    assert s == selector : "Wakeup returned the wrong selector.";
View Full Code Here

TOP

Related Classes of net.spy.memcached.ops.Operation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.