Class TCPMemcachedNodeImpl

java.lang.Object
net.spy.memcached.compat.SpyObject
net.spy.memcached.protocol.TCPMemcachedNodeImpl
All Implemented Interfaces:
MemcachedNode
Direct Known Subclasses:
AsciiMemcachedNodeImpl, BinaryMemcachedNodeImpl

public abstract class TCPMemcachedNodeImpl extends SpyObject implements MemcachedNode
Represents a node with the memcached cluster, along with buffering and operation queues.
  • Field Details

  • Constructor Details

  • Method Details

    • copyInputQueue

      public final void copyInputQueue()
      Description copied from interface: MemcachedNode
      Move all of the operations delivered via addOperation into the internal write queue.
      Specified by:
      copyInputQueue in interface MemcachedNode
    • destroyInputQueue

      public Collection<Operation> destroyInputQueue()
      Description copied from interface: MemcachedNode
      Extract all queued items for this node destructively. This is useful for redistributing items.
      Specified by:
      destroyInputQueue in interface MemcachedNode
    • setupResend

      public final void setupResend()
      Description copied from interface: MemcachedNode
      Clear the queue of currently processing operations by either cancelling them or setting them up to be reapplied after a reconnect.
      Specified by:
      setupResend in interface MemcachedNode
    • preparePending

      private boolean preparePending()
    • fillWriteBuffer

      public final void fillWriteBuffer(boolean shouldOptimize)
      Description copied from interface: MemcachedNode
      Fill the write buffer with data from the next operations in the queue.
      Specified by:
      fillWriteBuffer in interface MemcachedNode
      Parameters:
      shouldOptimize - if true, combine sequential gets into a single multi-key get
    • getNextWritableOp

      private Operation getNextWritableOp()
    • transitionWriteItem

      public final void transitionWriteItem()
      Description copied from interface: MemcachedNode
      Transition the current write item into a read state.
      Specified by:
      transitionWriteItem in interface MemcachedNode
    • optimize

      protected abstract void optimize()
    • getCurrentReadOp

      public final Operation getCurrentReadOp()
      Description copied from interface: MemcachedNode
      Get the operation at the top of the queue that is requiring input.
      Specified by:
      getCurrentReadOp in interface MemcachedNode
    • removeCurrentReadOp

      public final Operation removeCurrentReadOp()
      Description copied from interface: MemcachedNode
      Remove the operation at the top of the queue that is requiring input.
      Specified by:
      removeCurrentReadOp in interface MemcachedNode
    • getCurrentWriteOp

      public final Operation getCurrentWriteOp()
      Description copied from interface: MemcachedNode
      Get the operation at the top of the queue that has information available to write.
      Specified by:
      getCurrentWriteOp in interface MemcachedNode
    • removeCurrentWriteOp

      public final Operation removeCurrentWriteOp()
      Description copied from interface: MemcachedNode
      Remove the operation at the top of the queue that has information available to write.
      Specified by:
      removeCurrentWriteOp in interface MemcachedNode
    • hasReadOp

      public final boolean hasReadOp()
      Description copied from interface: MemcachedNode
      True if an operation is available to read.
      Specified by:
      hasReadOp in interface MemcachedNode
    • hasWriteOp

      public final boolean hasWriteOp()
      Description copied from interface: MemcachedNode
      True if an operation is available to write.
      Specified by:
      hasWriteOp in interface MemcachedNode
    • addOp

      public final void addOp(Operation op)
      Description copied from interface: MemcachedNode
      Add an operation to the queue. Authentication operations should never be added to the queue, but this is not checked.
      Specified by:
      addOp in interface MemcachedNode
    • insertOp

      public final void insertOp(Operation op)
      Description copied from interface: MemcachedNode
      Insert an operation to the beginning of the queue. This method is meant to be invoked rarely.
      Specified by:
      insertOp in interface MemcachedNode
    • getSelectionOps

      public final int getSelectionOps()
      Description copied from interface: MemcachedNode
      Compute the appropriate selection operations for the channel this MemcachedNode holds to the server.
      Specified by:
      getSelectionOps in interface MemcachedNode
    • getRbuf

      public final ByteBuffer getRbuf()
      Description copied from interface: MemcachedNode
      Get the buffer used for reading data from this node.
      Specified by:
      getRbuf in interface MemcachedNode
    • getWbuf

      public final ByteBuffer getWbuf()
      Description copied from interface: MemcachedNode
      Get the buffer used for writing data to this node.
      Specified by:
      getWbuf in interface MemcachedNode
    • getSocketAddress

      public final SocketAddress getSocketAddress()
      Description copied from interface: MemcachedNode
      Get the SocketAddress of the server to which this node is connected.
      Specified by:
      getSocketAddress in interface MemcachedNode
    • isActive

      public final boolean isActive()
      Description copied from interface: MemcachedNode
      True if this node is active. i.e. is is currently connected and expected to be able to process requests
      Specified by:
      isActive in interface MemcachedNode
    • isAuthenticated

      public boolean isAuthenticated()
      Description copied from interface: MemcachedNode
      True if this node is authenticated.
      Specified by:
      isAuthenticated in interface MemcachedNode
    • reconnecting

      public final void reconnecting()
      Description copied from interface: MemcachedNode
      Notify this node that it will be reconnecting.
      Specified by:
      reconnecting in interface MemcachedNode
    • connected

      public final void connected()
      Description copied from interface: MemcachedNode
      Notify this node that it has reconnected.
      Specified by:
      connected in interface MemcachedNode
    • getReconnectCount

      public final int getReconnectCount()
      Description copied from interface: MemcachedNode
      Get the current reconnect count.
      Specified by:
      getReconnectCount in interface MemcachedNode
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • registerChannel

      public final void registerChannel(SocketChannel ch, SelectionKey skey)
      Description copied from interface: MemcachedNode
      Register a channel with this node.
      Specified by:
      registerChannel in interface MemcachedNode
    • setChannel

      public final void setChannel(SocketChannel to)
      Description copied from interface: MemcachedNode
      Set the SocketChannel this node uses.
      Specified by:
      setChannel in interface MemcachedNode
    • getChannel

      public final SocketChannel getChannel()
      Description copied from interface: MemcachedNode
      Get the SocketChannel for this connection.
      Specified by:
      getChannel in interface MemcachedNode
    • setSk

      public final void setSk(SelectionKey to)
      Description copied from interface: MemcachedNode
      Set the selection key for this node.
      Specified by:
      setSk in interface MemcachedNode
    • getSk

      public final SelectionKey getSk()
      Description copied from interface: MemcachedNode
      Get the selection key from this node.
      Specified by:
      getSk in interface MemcachedNode
    • getBytesRemainingToWrite

      public final int getBytesRemainingToWrite()
      Description copied from interface: MemcachedNode
      Get the number of bytes remaining to write.
      Specified by:
      getBytesRemainingToWrite in interface MemcachedNode
    • writeSome

      public final int writeSome() throws IOException
      Description copied from interface: MemcachedNode
      Write some bytes and return the number of bytes written.
      Specified by:
      writeSome in interface MemcachedNode
      Returns:
      the number of bytes written
      Throws:
      IOException - if there's a problem writing
    • setContinuousTimeout

      public void setContinuousTimeout(boolean timedOut)
      Description copied from interface: MemcachedNode
      Count 'time out' exceptions to drop connections that fail perpetually.
      Specified by:
      setContinuousTimeout in interface MemcachedNode
      Parameters:
      timedOut -
    • getContinuousTimeout

      public int getContinuousTimeout()
      Specified by:
      getContinuousTimeout in interface MemcachedNode
    • fixupOps

      public final void fixupOps()
      Description copied from interface: MemcachedNode
      Fix up the selection ops on the selection key.
      Specified by:
      fixupOps in interface MemcachedNode
    • authComplete

      public final void authComplete()
      Description copied from interface: MemcachedNode
      Let the node know that auth is complete. Typically this would mean the node can start processing and accept new operations to its input queue.
      Specified by:
      authComplete in interface MemcachedNode
    • setupForAuth

      public final void setupForAuth()
      Description copied from interface: MemcachedNode
      Tell a node to set up for authentication. Typically this would mean blocking additions to the queue. In a reconnect situation this may mean putting any queued operations on hold to get to an auth complete state.
      Specified by:
      setupForAuth in interface MemcachedNode
    • lastReadDelta

      public long lastReadDelta()
      Number of milliseconds since the last read of this node completed.
      Specified by:
      lastReadDelta in interface MemcachedNode
      Returns:
      milliseconds since last read.
    • completedRead

      public void completedRead()
      Mark this node as having just completed a read.
      Specified by:
      completedRead in interface MemcachedNode
    • getConnection

      public MemcachedConnection getConnection()
      Specified by:
      getConnection in interface MemcachedNode
    • setConnection

      public void setConnection(MemcachedConnection connection)
      Specified by:
      setConnection in interface MemcachedNode