public class MemcachedConnection extends SpyThread implements ClusterConfigurationObserver
| Constructor and Description |
|---|
MemcachedConnection(int bufSize,
ConnectionFactory f,
java.util.List<java.net.InetSocketAddress> socketAddressList,
java.util.Collection<ConnectionObserver> obs,
FailureMode fm,
OperationFactory opfactory)
Construct a
MemcachedConnection. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addObserver(ConnectionObserver obs)
Add a connection observer.
|
void |
addOperations(java.util.Map<MemcachedNode,Operation> ops)
Enqueue the given list of operations on each handling node.
|
java.util.concurrent.CountDownLatch |
broadcastOperation(BroadcastOpFactory of)
Broadcast an operation to all nodes.
|
java.util.concurrent.CountDownLatch |
broadcastOperation(BroadcastOpFactory of,
java.util.Collection<MemcachedNode> nodes)
Broadcast an operation to a collection of nodes.
|
java.lang.String |
connectionsStatus()
Construct a String containing information about all nodes and their state.
|
void |
enqueueOperation(java.net.InetSocketAddress addr,
Operation o) |
void |
enqueueOperation(java.lang.String key,
Operation o)
Enqueue the given
Operation with the used key. |
NodeLocator |
getLocator()
Returns the
NodeLocator in use for this connection. |
void |
handleIO()
Handle all IO that flows through the connection.
|
void |
insertOperation(MemcachedNode node,
Operation o)
Insert an operation on the given node to the beginning of the queue.
|
boolean |
isShutDown()
Returns whether the connection is shut down or not.
|
void |
notifyUpdate(ClusterConfiguration clusterConfiguration)
The publisher calls all the subscribers through this method.
|
static void |
opSucceeded(Operation op)
Reset the timeout counter for the given handling node.
|
static void |
opTimedOut(Operation op)
Increase the timeout counter for the given handling node.
|
void |
redistributeOperation(Operation op)
Redistribute the given operation to (potentially) other nodes.
|
void |
redistributeOperations(java.util.Collection<Operation> ops)
Redistribute the given list of operations to (potentially) other nodes.
|
boolean |
removeObserver(ConnectionObserver obs)
Remove a connection observer.
|
void |
retryOperation(Operation op)
Add a operation to the retry queue.
|
void |
run()
Handle IO as long as the application is running.
|
void |
shutdown()
Shut down all connections and do not accept further incoming ops.
|
java.lang.String |
toString() |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yieldpublic MemcachedConnection(int bufSize,
ConnectionFactory f,
java.util.List<java.net.InetSocketAddress> socketAddressList,
java.util.Collection<ConnectionObserver> obs,
FailureMode fm,
OperationFactory opfactory)
throws java.io.IOException
MemcachedConnection.bufSize - the size of the buffer used for reading from the serverf - the factory that will provide an operation queuesocketAddressList - the addresses of the servers to connect toobs - the initial observers to add.fm - the failure mode to use.opfactory - the operation factory.java.io.IOException - if a connection attempt fails earlypublic void notifyUpdate(ClusterConfiguration clusterConfiguration)
ClusterConfigurationObservernotifyUpdate in interface ClusterConfigurationObserverclusterConfiguration - - The parameter contains the latest information about the cluster.public void handleIO()
throws java.io.IOException
java.io.IOExceptionpublic boolean addObserver(ConnectionObserver obs)
public boolean removeObserver(ConnectionObserver obs)
public void redistributeOperations(java.util.Collection<Operation> ops)
ops - the operations to redistribute.public void redistributeOperation(Operation op)
op - the operation to redistribute.public NodeLocator getLocator()
NodeLocator in use for this connection.NodeLocator.public void enqueueOperation(java.lang.String key,
Operation o)
Operation with the used key.key - the key to use.o - the Operation to enqueue.public void enqueueOperation(java.net.InetSocketAddress addr,
Operation o)
public void insertOperation(MemcachedNode node, Operation o)
node - the node where to insert the Operation.o - the operation to insert.public void addOperations(java.util.Map<MemcachedNode,Operation> ops)
ops - the operations for each node.public java.util.concurrent.CountDownLatch broadcastOperation(BroadcastOpFactory of)
CountDownLatch that will be counted down when the
operations are complete.public java.util.concurrent.CountDownLatch broadcastOperation(BroadcastOpFactory of, java.util.Collection<MemcachedNode> nodes)
CountDownLatch that will be counted down when the
operations are complete.public void shutdown()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Threadpublic java.lang.String connectionsStatus()
public static void opTimedOut(Operation op)
op - the operation to grab the node from.public static void opSucceeded(Operation op)
op - the operation to grab the node from.public void run()
run in interface java.lang.Runnablerun in class java.lang.Threadpublic boolean isShutDown()
public void retryOperation(Operation op)
op - the operation to retry.