Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
protected ConcurrentLinkedQueue<MemcachedNode> |
addedQueue
AddedQueue is used to track the QueueAttachments for which operations
have recently been queued.
|
protected FailureMode |
failureMode
The configured
FailureMode . |
protected NodeLocator |
locator
The
NodeLocator to use for this connection. |
protected MetricCollector |
metrics
The
MetricCollector to accumulate metrics (or dummy). |
protected MetricType |
metricType
The current type of metrics to collect.
|
protected ConcurrentLinkedQueue<MemcachedNode> |
nodesToShutdown
Holds all nodes that are scheduled for shutdown.
|
protected boolean |
running
True if not shutting down or shut down.
|
protected Selector |
selector
Holds the current
Selector to use. |
protected boolean |
shutDown
If the connection is alread shut down or shutting down.
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
MemcachedConnection(int bufSize,
ConnectionFactory f,
List<InetSocketAddress> a,
Collection<ConnectionObserver> obs,
FailureMode fm,
OperationFactory opfactory)
Construct a
MemcachedConnection . |
Modifier and Type | Method and Description |
---|---|
boolean |
addObserver(ConnectionObserver obs)
Add a connection observer.
|
protected void |
addOperation(MemcachedNode node,
Operation o)
Enqueue an operation on the given node.
|
protected void |
addOperation(String key,
Operation o)
Add an operation to a connection identified by the given key.
|
void |
addOperations(Map<MemcachedNode,Operation> ops)
Enqueue the given list of operations on each handling node.
|
CountDownLatch |
broadcastOperation(BroadcastOpFactory of)
Broadcast an operation to all nodes.
|
CountDownLatch |
broadcastOperation(BroadcastOpFactory of,
Collection<MemcachedNode> nodes)
Broadcast an operation to a collection of nodes.
|
protected void |
checkState()
Check to see if this connection is shutting down.
|
String |
connectionsStatus()
Construct a String containing information about all nodes and their state.
|
protected List<MemcachedNode> |
createConnections(Collection<InetSocketAddress> addrs)
Create connections for the given list of addresses.
|
void |
enqueueOperation(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.
|
protected void |
handleRetryInformation(byte[] retryMessage)
Optionally handle retry (NOT_MY_VBUKET) responses.
|
protected void |
handleWokenUpSelector()
Helper method which gets called if the selector is woken up because of the
timeout setting, if has been interrupted or if happens during regular
write operation phases.
|
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.
|
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.
|
protected void |
queueReconnect(MemcachedNode node)
Enqueue the given
MemcachedNode for reconnect. |
void |
redistributeOperation(Operation op)
Redistribute the given operation to (potentially) other nodes.
|
void |
redistributeOperations(Collection<Operation> ops)
Redistribute the given list of operations to (potentially) other nodes.
|
protected void |
registerMetrics()
Register Metrics for collection.
|
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.
|
String |
toString() |
activeCount, checkAccess, clone, 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, yield
protected volatile boolean shutDown
protected final NodeLocator locator
NodeLocator
to use for this connection.protected final FailureMode failureMode
FailureMode
.protected final ConcurrentLinkedQueue<MemcachedNode> addedQueue
protected volatile boolean running
protected final ConcurrentLinkedQueue<MemcachedNode> nodesToShutdown
protected final MetricCollector metrics
MetricCollector
to accumulate metrics (or dummy).protected final MetricType metricType
public MemcachedConnection(int bufSize, ConnectionFactory f, List<InetSocketAddress> a, Collection<ConnectionObserver> obs, FailureMode fm, OperationFactory opfactory) throws IOException
MemcachedConnection
.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.obs
- the initial observers to add.fm
- the failure mode to use.opfactory
- the operation factory.IOException
- if a connection attempt fails earlyprotected void registerMetrics()
MetricCollector
implementation. This can be controlled from
the DefaultConnectionFactory
.protected List<MemcachedNode> createConnections(Collection<InetSocketAddress> addrs) throws IOException
addrs
- the list of addresses to connect to.MemcachedNode
s.IOException
- if connecting was not successful.public void handleIO() throws IOException
IOException
protected void handleWokenUpSelector()
This method can be overriden by child implementations to handle custom behavior on a manually woken selector, like sending pings through the channels to make sure they are alive.
Note that there is no guarantee that this method is at all or in the regular interval called, so all overriding implementations need to take that into account. Also, it needs to take into account that it may be called very often under heavy workloads, so it should not perform extensive tasks in the same thread.
public boolean addObserver(ConnectionObserver obs)
public boolean removeObserver(ConnectionObserver obs)
protected void handleRetryInformation(byte[] retryMessage)
retryMessage
- the body of the retry message.protected void queueReconnect(MemcachedNode node)
MemcachedNode
for reconnect.node
- the node to reconnect.public void redistributeOperations(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(String key, Operation o)
Operation
with the used key.key
- the key to use.o
- the Operation
to enqueue.protected void addOperation(String key, Operation o)
MemcachedNode
is active or the FailureMode
is set
to retry, the primary node will be used for that key. If the primary
node is not available and the FailureMode
cancel is used, the
operation will be cancelled without further retry.
For any other FailureMode
mechanisms (Redistribute), another
possible node is used (only if its active as well). If no other active
node could be identified, the original primary node is used and retried.key
- the key the operation is operating upon.o
- the operation to add.public void insertOperation(MemcachedNode node, Operation o)
node
- the node where to insert the Operation
.o
- the operation to insert.protected void addOperation(MemcachedNode node, Operation o)
node
- the node where to enqueue the Operation
.o
- the operation to add.public void addOperations(Map<MemcachedNode,Operation> ops)
ops
- the operations for each node.public CountDownLatch broadcastOperation(BroadcastOpFactory of)
CountDownLatch
that will be counted down when the
operations are complete.public CountDownLatch broadcastOperation(BroadcastOpFactory of, Collection<MemcachedNode> nodes)
CountDownLatch
that will be counted down when the
operations are complete.public void shutdown() throws IOException
IOException
public 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.protected void checkState()
IllegalStateException
- when shutting down.public void run()
public boolean isShutDown()
public void retryOperation(Operation op)
op
- the operation to retry.Copyright © 2023. All rights reserved.