net.spy.memcached
Class MemcachedConnection

java.lang.Object
  extended by net.spy.memcached.compat.SpyObject
      extended by net.spy.memcached.MemcachedConnection
All Implemented Interfaces:
Reconfigurable

public final class MemcachedConnection
extends SpyObject
implements Reconfigurable

Connection to a cluster of memcached servers.


Constructor Summary
MemcachedConnection(int bufSize, ConnectionFactory f, List<InetSocketAddress> a, Collection<ConnectionObserver> obs, FailureMode fm, OperationFactory opfactory)
          Construct a memcached connection.
 
Method Summary
 boolean addObserver(ConnectionObserver obs)
          Add a connection observer.
 void addOperation(String key, Operation o)
          Add an operation to the given connection.
 void addOperations(Map<MemcachedNode,Operation> ops)
           
 CountDownLatch broadcastOperation(BroadcastOpFactory of)
          Broadcast an operation to all nodes.
 CountDownLatch broadcastOperation(BroadcastOpFactory of, Collection<MemcachedNode> nodes)
          Broadcast an operation to a specific collection of nodes.
 void handleIO()
          MemcachedClient calls this method to handle IO over the connections.
 void insertOperation(MemcachedNode node, Operation o)
           
static void opSucceeded(Operation op)
          helper method: reset timeout counter
static void opTimedOut(Operation op)
          helper method: increase timeout count on node attached to this op
 void reconfigure(Bucket bucket)
          Call on a configuration update
 boolean removeObserver(ConnectionObserver obs)
          Remove a connection observer.
 void shutdown()
          Shut down all of the connections.
 String toString()
           
 
Methods inherited from class net.spy.memcached.compat.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MemcachedConnection

public MemcachedConnection(int bufSize,
                           ConnectionFactory f,
                           List<InetSocketAddress> a,
                           Collection<ConnectionObserver> obs,
                           FailureMode fm,
                           OperationFactory opfactory)
                    throws IOException
Construct a memcached connection.

Parameters:
bufSize - the size of the buffer used for reading from the server
f - the factory that will provide an operation queue
a - the addresses of the servers to connect to
Throws:
IOException - if a connection attempt fails early
Method Detail

reconfigure

public void reconfigure(Bucket bucket)
Description copied from interface: Reconfigurable
Call on a configuration update

Specified by:
reconfigure in interface Reconfigurable
Parameters:
bucket - updated vbucket configuration

handleIO

public void handleIO()
              throws IOException
MemcachedClient calls this method to handle IO over the connections.

Throws:
IOException

addObserver

public boolean addObserver(ConnectionObserver obs)
Add a connection observer.

Returns:
whether the observer was successfully added

removeObserver

public boolean removeObserver(ConnectionObserver obs)
Remove a connection observer.

Returns:
true if the observer existed and now doesn't

addOperation

public void addOperation(String key,
                         Operation o)
Add an operation to the given connection.

Parameters:
key - the key the operation is operating upon
o - the operation

insertOperation

public void insertOperation(MemcachedNode node,
                            Operation o)

addOperations

public void addOperations(Map<MemcachedNode,Operation> ops)

broadcastOperation

public CountDownLatch broadcastOperation(BroadcastOpFactory of)
Broadcast an operation to all nodes.


broadcastOperation

public CountDownLatch broadcastOperation(BroadcastOpFactory of,
                                         Collection<MemcachedNode> nodes)
Broadcast an operation to a specific collection of nodes.


shutdown

public void shutdown()
              throws IOException
Shut down all of the connections.

Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

opTimedOut

public static void opTimedOut(Operation op)
helper method: increase timeout count on node attached to this op

Parameters:
op -

opSucceeded

public static void opSucceeded(Operation op)
helper method: reset timeout counter

Parameters:
op -