Package net.spy.memcached.ops

Examples of net.spy.memcached.ops.Operation


  /* (non-Javadoc)
   * @see net.spy.memcached.MemcachedNode#setupResend()
   */
  public final void setupResend() {
    // First, reset the current write op.
    Operation op=getCurrentWriteOp();
    if(op != null) {
      op.getBuffer().reset();
    }
    // Now cancel all the pending read operations.  Might be better to
    // to requeue them.
    while(hasReadOp()) {
      op=removeCurrentReadOp();
      getLogger().warn("Discarding partially completed op: %s", op);
      op.cancel();
    }

    getWbuf().clear();
    getRbuf().clear();
    toWrite=0;
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 optimizeGets) {
    if(toWrite == 0) {
      getWbuf().clear();
      Operation o=getCurrentWriteOp();
      while(o != null && toWrite < getWbuf().capacity()) {
        assert o.getState() == OperationState.WRITING;
        ByteBuffer obuf=o.getBuffer();
        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(optimizeGets) {
            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("Transitioning %s to read", op);
    readQ.add(op);
  }
View Full Code Here

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

  private Future<Boolean> asyncStore(StoreType storeType,
      String key, int exp, Object value) {
    CachedData co=transcoder.encode(value);
    final CountDownLatch latch=new CountDownLatch(1);
    final OperationFuture<Boolean> rv=new OperationFuture<Boolean>(latch);
    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

  public Future<Object> asyncGet(final String key) {

    final CountDownLatch latch=new CountDownLatch(1);
    final OperationFuture<Object> rv=new OperationFuture<Object>(latch);

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

      try {
        MemcachedNode qa=null;
        while((qa=addedQueue.remove()) != null) {
          boolean readyForIO=false;
          if(qa.isActive()) {
            Operation op=qa.getCurrentWriteOp();
            if(op != null) {
              readyForIO=true;
              getLogger().debug("Handling queued write %s", qa);
            }
          } else {
View Full Code Here

    }
  }

  private void handleReads(SelectionKey sk, MemcachedNode qa)
    throws IOException {
    Operation currentOp = qa.getCurrentReadOp();
    ByteBuffer rbuf=qa.getRbuf();
    final SocketChannel channel = qa.getChannel();
    int read=channel.read(rbuf);
    while(read > 0) {
      getLogger().debug("Read %d bytes", read);
      rbuf.flip();
      while(rbuf.remaining() > 0) {
        assert currentOp != null : "No read operation";
        currentOp.readFromBuffer(rbuf);
        if(currentOp.getState() == OperationState.COMPLETE) {
          getLogger().debug(
              "Completed read op: %s and giving the next %d bytes",
              currentOp, rbuf.remaining());
          Operation op=qa.removeCurrentReadOp();
          assert op == currentOp
          : "Expected to pop " + currentOp + " got " + op;
          currentOp=qa.getCurrentReadOp();
        }
      }
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.