Package net.spy.memcached.ops

Examples of net.spy.memcached.ops.Operation


   * @see net.spy.memcached.MemcachedNode#fillWriteBuffer(boolean)
   */
  public final void fillWriteBuffer(boolean optimizeGets) {
    if(toWrite == 0 && readQ.remainingCapacity() > 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 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

  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();
      o.initialize();
      node.addOp(o);
      addedQueue.offer(node);
    }
    Selector s=selector.wakeup();
    assert s == selector : "Wakeup returned the wrong selector.";
View Full Code Here

   * Broadcast an operation to all nodes.
   */
  public CountDownLatch broadcastOperation(final BroadcastOpFactory of) {
    final CountDownLatch latch=new CountDownLatch(locator.getAll().size());
    for(MemcachedNode node : locator.getAll()) {
      Operation op = of.newOp(node, latch);
      op.initialize();
      node.addOp(op);
      addedQueue.offer(node);
    }
    Selector s=selector.wakeup();
    assert s == selector : "Wakeup returned the wrong selector.";
View Full Code Here

      waitForAuth, dt);
  }

  @Override
  protected void optimize() {
    Operation firstOp = writeQ.peek();
    if(firstOp instanceof GetOperation) {
      optimizeGets();
    } else if(firstOp instanceof CASOperation) {
      optimizeSets();
    }
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

   * @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

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.