Package net.spy.memcached.ops

Examples of net.spy.memcached.ops.Operation


      waitForAuth);
  }

  @Override
  protected void optimize() {
    Operation firstOp = writeQ.peek();
    if(firstOp instanceof GetOperation) {
      optimizeGets();
    } else if(firstOp instanceof CASOperation) {
      optimizeSets();
    }
View Full Code Here


   * @see net.spy.memcached.MemcachedNode#setupResend()
   */
  public final void setupResend() {
    // First, reset the current write op, or cancel it if we should
    // be authenticating
    Operation op=getCurrentWriteOp();
    if(shouldAuth && op != null) {
        op.cancel();
    } else if(op != null) {
      ByteBuffer buf=op.getBuffer();
      if(buf != null) {
        buf.reset();
      } else {
        getLogger().info("No buffer for current write op, removing");
        removeCurrentWriteOp();
      }
    }
    // Now cancel all the pending read operations.  Might be better to
    // to requeue them.
    while(hasReadOp()) {
      op=removeCurrentReadOp();
      if (op != getCurrentWriteOp()) {
        getLogger().warn("Discarding partially completed op: %s", op);
        op.cancel();
      }
    }

    while(shouldAuth && hasWriteOp()) {
      op=removeCurrentWriteOp();
      getLogger().warn("Discarding partially completed op: %s", op);
      op.cancel();
    }


    getWbuf().clear();
    getRbuf().clear();
View Full Code Here

  private boolean preparePending() {
    // Copy the input queue into the write queue.
    copyInputQueue();

    // Now check the ops
    Operation nextOp=getCurrentWriteOp();
    while(nextOp != null && nextOp.isCancelled()) {
      getLogger().info("Removing cancelled operation: %s", nextOp);
      removeCurrentWriteOp();
      nextOp=getCurrentWriteOp();
    }
    return nextOp != null;
View Full Code Here

   * @see net.spy.memcached.MemcachedNode#fillWriteBuffer(boolean)
   */
  public final void fillWriteBuffer(boolean shouldOptimize) {
    if(toWrite == 0 && readQ.remainingCapacity() > 0) {
      getWbuf().clear();
      Operation o=getCurrentWriteOp();
      while(o != null && toWrite < getWbuf().capacity()) {
        assert o.getState() == OperationState.WRITING;
        // This isn't the most optimal way to do this, but it hints
        // at a larger design problem that may need to be taken care
        // if in the bowels of the client.
        // In practice, readQ should be small, however.
        if(!readQ.contains(o)) {
          readQ.add(o);
        }

        ByteBuffer obuf=o.getBuffer();
        assert obuf != null : "Didn't get a write buffer from " + o;
        int bytesToCopy=Math.min(getWbuf().remaining(),
            obuf.remaining());
        byte b[]=new byte[bytesToCopy];
        obuf.get(b);
        getWbuf().put(b);
        getLogger().debug("After copying stuff from %s: %s",
            o, getWbuf());
        if(!o.getBuffer().hasRemaining()) {
          o.writeComplete();
          transitionWriteItem();

          preparePending();
          if(shouldOptimize) {
            optimize();
View Full Code Here

  /* (non-Javadoc)
   * @see net.spy.memcached.MemcachedNode#transitionWriteItem()
   */
  public final void transitionWriteItem() {
    Operation op=removeCurrentWriteOp();
    assert op != null : "There is no write item to transition";
    getLogger().debug("Finished writing %s", op);
  }
View Full Code Here

  /* (non-Javadoc)
   * @see net.spy.memcached.MemcachedNode#removeCurrentWriteOp()
   */
  public final Operation removeCurrentWriteOp() {
    Operation rv=optimizedOp;
    if(rv == null) {
      rv=writeQ.remove();
    } else {
      optimizedOp=null;
    }
View Full Code Here

               int exp, T value, Transcoder<T> tc) {
    CachedData co=tc.encode(value);
    final CountDownLatch latch=new CountDownLatch(1);
    final OperationFuture<Boolean> rv=new OperationFuture<Boolean>(latch,
        operationTimeout);
    Operation op=opFact.store(storeType, key, co.getFlags(),
        exp, co.getData(), new OperationCallback() {
          public void receivedStatus(OperationStatus val) {
            rv.set(val.isSuccess());
          }
          public void complete() {
View Full Code Here

      T value, Transcoder<T> tc) {
    CachedData co=tc.encode(value);
    final CountDownLatch latch=new CountDownLatch(1);
    final OperationFuture<Boolean> rv=new OperationFuture<Boolean>(latch,
        operationTimeout);
    Operation op=opFact.cat(catType, cas, key, co.getData(),
        new OperationCallback() {
      public void receivedStatus(OperationStatus val) {
        rv.set(val.isSuccess());
      }
      public void complete() {
View Full Code Here

      Transcoder<T> tc) {
    CachedData co=tc.encode(value);
    final CountDownLatch latch=new CountDownLatch(1);
    final OperationFuture<CASResponse> rv=new OperationFuture<CASResponse>(
        latch, operationTimeout);
    Operation op=opFact.cas(StoreType.set, key, casId, co.getFlags(), exp,
        co.getData(), new OperationCallback() {
          public void receivedStatus(OperationStatus val) {
            if(val instanceof CASOperationStatus) {
              rv.set(((CASOperationStatus)val).getCASResponse());
            } else if(val instanceof CancelledOperationStatus) {
View Full Code Here

  public <T> Future<T> asyncGet(final String key, final Transcoder<T> tc) {

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

    Operation op=opFact.get(key,
        new GetOperation.Callback() {
      private Future<T> val=null;
      public void receivedStatus(OperationStatus status) {
        rv.set(val);
      }
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.