Skip to content
This repository
Browse code

Make CachingStoreClientFactory JMX managed, add ability to rebootstra…

…p all clients.
  • Loading branch information...
commit 32d99bfe52bc55e71e7a5b3b6616e9e0685bca78 1 parent a444a67
Alex Feinberg afeinberg authored

Showing 1 changed file with 30 additions and 0 deletions. Show diff stats Hide diff stats

  1. +30 0 src/java/voldemort/client/CachingStoreClientFactory.java
30 src/java/voldemort/client/CachingStoreClientFactory.java
@@ -16,12 +16,17 @@
16 16
17 17 package voldemort.client;
18 18
  19 +import com.google.common.collect.ImmutableList;
  20 +import org.apache.log4j.Logger;
  21 +import voldemort.annotations.jmx.JmxManaged;
  22 +import voldemort.annotations.jmx.JmxOperation;
19 23 import voldemort.cluster.failuredetector.FailureDetector;
20 24 import voldemort.store.Store;
21 25 import voldemort.utils.Pair;
22 26 import voldemort.versioning.InconsistencyResolver;
23 27 import voldemort.versioning.Versioned;
24 28
  29 +import java.util.List;
25 30 import java.util.concurrent.ConcurrentHashMap;
26 31 import java.util.concurrent.ConcurrentMap;
27 32
@@ -30,8 +35,11 @@
30 35 * to <code>getStoreClient</code>
31 36 *
32 37 */
  38 +@JmxManaged(description = "A StoreClientFactory which caches clients")
33 39 public class CachingStoreClientFactory implements StoreClientFactory {
34 40
  41 + private final static Logger logger = Logger.getLogger(CachingStoreClientFactory.class);
  42 +
35 43 private final StoreClientFactory inner;
36 44 private final ConcurrentMap<Pair<String, Object>, StoreClient> cache;
37 45
@@ -80,4 +88,26 @@ public void close() {
80 88 public FailureDetector getFailureDetector() {
81 89 return inner.getFailureDetector();
82 90 }
  91 +
  92 + @JmxOperation(description = "Clear the cache")
  93 + public synchronized void clear() {
  94 + try {
  95 + cache.clear();
  96 + } catch(Exception e) {
  97 + logger.warn("Exception when clearing the cache", e);
  98 + }
  99 + }
  100 +
  101 + @JmxOperation(description = "Bootstrap all clients in the cache")
  102 + public void bootstrapAllClients() {
  103 + List<StoreClient> allClients = ImmutableList.copyOf(cache.values());
  104 + try {
  105 + for(StoreClient client: allClients) {
  106 + if(client instanceof DefaultStoreClient)
  107 + ((DefaultStoreClient) client).bootStrap();
  108 + }
  109 + } catch(Exception e) {
  110 + logger.warn("Exception during bootstrapAllClients", e);
  111 + }
  112 + }
83 113 }

0 comments on commit 32d99bf

Please sign in to comment.
Something went wrong with that request. Please try again.