lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [lucene-solr] 19/36: Renaming and refactoring.
Date Wed, 18 Dec 2019 16:38:57 GMT
This is an automated email from the ASF dual-hosted git repository.

ab pushed a commit to branch jira/solr-13579
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 55c0060eaed0db72247a93a11d0bca6eaf6bda81
Author: Andrzej Bialecki <ab@apache.org>
AuthorDate: Thu Jul 25 17:12:13 2019 +0200

    Renaming and refactoring.
---
 .../solr/handler/admin/ResourceManagerHandler.java | 40 +++++++++++-----------
 .../solr/managed/DefaultResourceManager.java       | 10 +++---
 .../solr/managed/DefaultResourceManagerPool.java   | 35 +++++++------------
 ...{ManagedResource.java => ManagedComponent.java} | 18 ++++++----
 .../{ResourceId.java => ManagedComponentId.java}   | 12 +++----
 .../apache/solr/managed/ManagedMetricProducer.java |  2 +-
 .../apache/solr/managed/NoOpResourceManager.java   | 17 ++++-----
 ...gedMetricProducer.java => ResourceContext.java} | 27 ++-------------
 .../org/apache/solr/managed/ResourceManager.java   | 28 +++++++--------
 .../apache/solr/managed/ResourceManagerPlugin.java |  4 +--
 .../apache/solr/managed/ResourceManagerPool.java   | 30 +++++-----------
 .../solr/managed/plugins/CacheManagerPlugin.java   | 20 +++++++++--
 .../java/org/apache/solr/search/FastLRUCache.java  | 10 +++---
 .../src/java/org/apache/solr/search/LFUCache.java  | 10 +++---
 .../src/java/org/apache/solr/search/LRUCache.java  | 10 +++---
 .../src/java/org/apache/solr/search/SolrCache.java |  4 +--
 .../org/apache/solr/search/SolrIndexSearcher.java  |  6 ++--
 17 files changed, 129 insertions(+), 154 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ResourceManagerHandler.java
b/solr/core/src/java/org/apache/solr/handler/admin/ResourceManagerHandler.java
index e76dbc7..76b3aa7 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/ResourceManagerHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/ResourceManagerHandler.java
@@ -28,7 +28,7 @@ import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.handler.RequestHandlerBase;
-import org.apache.solr.managed.ManagedResource;
+import org.apache.solr.managed.ManagedComponent;
 import org.apache.solr.managed.ResourceManager;
 import org.apache.solr.managed.ResourceManagerPool;
 import org.apache.solr.request.SolrQueryRequest;
@@ -134,10 +134,10 @@ public class ResourceManagerHandler extends RequestHandlerBase implements
Permis
           NamedList<Object> perPool = new SimpleOrderedMap<>();
           result.add(p, perPool);
           perPool.add("type", pool.getType());
-          perPool.add("size", pool.getResources().size());
+          perPool.add("size", pool.getComponents().size());
           perPool.add("poolLimits", pool.getPoolLimits());
           perPool.add("poolParams", pool.getParams());
-          perPool.add("resources", pool.getResources().keySet());
+          perPool.add("resources", pool.getComponents().keySet());
         });
         break;
       case STATUS:
@@ -146,10 +146,10 @@ public class ResourceManagerHandler extends RequestHandlerBase implements
Permis
           throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "Pool '" + name + "'
not found.");
         }
         result.add("type", pool.getType());
-        result.add("size", pool.getResources().size());
+        result.add("size", pool.getComponents().size());
         result.add("poolLimits", pool.getPoolLimits());
         result.add("poolParams", pool.getParams());
-        result.add("resources", pool.getResources().keySet());
+        result.add("resources", pool.getComponents().keySet());
         try {
           pool.getCurrentValues();
           result.add("totalValues", pool.getTotalValues());
@@ -237,7 +237,7 @@ public class ResourceManagerHandler extends RequestHandlerBase implements
Permis
     NamedList<Object> result = new SimpleOrderedMap<>();
     switch (op) {
       case LIST:
-        pool.getResources().forEach((n, resource) -> {
+        pool.getComponents().forEach((n, resource) -> {
           NamedList<Object> perRes = new SimpleOrderedMap<>();
           result.add(n, perRes);
           perRes.add("class", resource.getClass().getName());
@@ -246,33 +246,33 @@ public class ResourceManagerHandler extends RequestHandlerBase implements
Permis
         });
         break;
       case STATUS:
-        ManagedResource resource = pool.getResources().get(resName);
-        if (resource == null) {
+        ManagedComponent managedComponent = pool.getComponents().get(resName);
+        if (managedComponent == null) {
           throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "Resource '" + resName
+ " not found in pool '" + poolName + "'.");
         }
-        result.add("class", resource.getClass().getName());
-        result.add("types", resource.getManagedResourceTypes());
-        result.add("resourceLimits", resource.getResourceLimits());
+        result.add("class", managedComponent.getClass().getName());
+        result.add("types", managedComponent.getManagedResourceTypes());
+        result.add("resourceLimits", managedComponent.getResourceLimits());
         try {
-          result.add("monitoredValues", resource.getMonitoredValues(Collections.emptySet()));
+          result.add("monitoredValues", managedComponent.getMonitoredValues(Collections.emptySet()));
         } catch (Exception e) {
           log.warn("Error getting monitored values of " + resName + "/" + poolName + " :
" + e.toString(), e);
           result.add("error", "Error getting monitored values of " + resName + ": " + e.toString());
         }
         break;
       case GETLIMITS:
-        ManagedResource resource1 = pool.getResources().get(resName);
-        if (resource1 == null) {
+        ManagedComponent managedComponent1 = pool.getComponents().get(resName);
+        if (managedComponent1 == null) {
           throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "Resource '" + resName
+ " not found in pool '" + poolName + "'.");
         }
-        result.add("resourceLimits", resource1.getResourceLimits());
+        result.add("resourceLimits", managedComponent1.getResourceLimits());
         break;
       case SETLIMITS:
-        ManagedResource resource2 = pool.getResources().get(resName);
-        if (resource2 == null) {
+        ManagedComponent managedComponent2 = pool.getComponents().get(resName);
+        if (managedComponent2 == null) {
           throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "Resource '" + resName
+ " not found in pool '" + poolName + "'.");
         }
-        Map<String, Object> currentLimits = new HashMap<>(resource2.getResourceLimits());
+        Map<String, Object> currentLimits = new HashMap<>(managedComponent2.getResourceLimits());
         Map<String, Object> newLimits = getMap(params, LIMIT_PREFIX_PARAM);
         newLimits.forEach((k, v) -> {
           if (v == null) {
@@ -281,11 +281,11 @@ public class ResourceManagerHandler extends RequestHandlerBase implements
Permis
             currentLimits.put(k, v);
           }
         });
-        resource2.setResourceLimits(newLimits);
+        managedComponent2.setResourceLimits(newLimits);
         result.add("success", newLimits);
         break;
       case DELETE:
-        result.add("success", pool.removeResource(resName) ? "removed" : "not found");
+        result.add("success", pool.unregisterComponent(resName) ? "removed" : "not found");
     }
     rsp.getValues().add("result", result);
   }
diff --git a/solr/core/src/java/org/apache/solr/managed/DefaultResourceManager.java b/solr/core/src/java/org/apache/solr/managed/DefaultResourceManager.java
index d0d8233..93dfb2d2 100644
--- a/solr/core/src/java/org/apache/solr/managed/DefaultResourceManager.java
+++ b/solr/core/src/java/org/apache/solr/managed/DefaultResourceManager.java
@@ -169,7 +169,7 @@ public class DefaultResourceManager extends ResourceManager {
   }
 
   @Override
-  public void addResource(String name, ManagedResource managedResource) {
+  public void registerComponent(String name, ManagedComponent managedComponent) {
     ensureActive();
     ResourceManagerPool pool = resourcePools.get(name);
     if (pool == null) {
@@ -181,22 +181,22 @@ public class DefaultResourceManager extends ResourceManager {
         return;
       }
       if (otherPool.getType().equals(type)) {
-        throw new IllegalArgumentException("Resource " + managedResource.getResourceId()
+
+        throw new IllegalArgumentException("Resource " + managedComponent.getManagedComponentId()
+
             " is already managed in another pool (" +
             otherPool.getName() + ") of the same type " + type);
       }
     });
-    pool.addResource(managedResource);
+    pool.registerComponent(managedComponent);
   }
 
   @Override
-  public boolean removeResource(String poolName, String resourceId) {
+  public boolean unregisterComponent(String poolName, String resourceId) {
     ensureActive();
     ResourceManagerPool pool = resourcePools.get(poolName);
     if (pool == null) {
       throw new IllegalArgumentException("Pool '" + poolName + "' doesn't exist.");
     }
-    return pool.removeResource(resourceId);
+    return pool.unregisterComponent(resourceId);
   }
 
   @Override
diff --git a/solr/core/src/java/org/apache/solr/managed/DefaultResourceManagerPool.java b/solr/core/src/java/org/apache/solr/managed/DefaultResourceManagerPool.java
index d46666f..b966336 100644
--- a/solr/core/src/java/org/apache/solr/managed/DefaultResourceManagerPool.java
+++ b/solr/core/src/java/org/apache/solr/managed/DefaultResourceManagerPool.java
@@ -37,14 +37,13 @@ import org.slf4j.LoggerFactory;
 public class DefaultResourceManagerPool implements ResourceManagerPool {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-  private final Map<String, ManagedResource> resources = new ConcurrentHashMap<>();
-  private final Map<String, Context> resourceContexts = new ConcurrentHashMap<>();
+  private final Map<String, ManagedComponent> resources = new ConcurrentHashMap<>();
   private Map<String, Object> poolLimits;
   private final String type;
   private final String name;
   private final ResourceManagerPlugin resourceManagerPlugin;
   private final Map<String, Object> args;
-  private final Context poolContext = new Context();
+  private final ResourceContext poolContext = new ResourceContext();
   private Map<String, Float> totalValues = null;
   private final ReentrantLock updateLock = new ReentrantLock();
   int scheduleDelaySeconds;
@@ -83,27 +82,25 @@ public class DefaultResourceManagerPool implements ResourceManagerPool
{
   }
 
   @Override
-  public void addResource(ManagedResource managedResource) {
-    Collection<String> types = managedResource.getManagedResourceTypes();
+  public void registerComponent(ManagedComponent managedComponent) {
+    Collection<String> types = managedComponent.getManagedResourceTypes();
     if (!types.contains(type)) {
-      log.debug("Pool type '" + type + "' is not supported by the resource " + managedResource.getResourceId());
+      log.debug("Pool type '" + type + "' is not supported by the resource " + managedComponent.getManagedComponentId());
       return;
     }
-    ManagedResource existing = resources.putIfAbsent(managedResource.getResourceId().toString(),
managedResource);
+    ManagedComponent existing = resources.putIfAbsent(managedComponent.getManagedComponentId().toString(),
managedComponent);
     if (existing != null) {
-      throw new IllegalArgumentException("Resource '" + managedResource.getResourceId() +
"' already exists in pool '" + name + "' !");
+      throw new IllegalArgumentException("Resource '" + managedComponent.getManagedComponentId()
+ "' already exists in pool '" + name + "' !");
     }
-    resourceContexts.putIfAbsent(managedResource.getResourceId().toString(), new Context());
   }
 
   @Override
-  public boolean removeResource(String name) {
-    resourceContexts.remove(name);
+  public boolean unregisterComponent(String name) {
     return resources.remove(name) != null;
   }
 
   @Override
-  public Map<String, ManagedResource> getResources() {
+  public Map<String, ManagedComponent> getComponents() {
     return Collections.unmodifiableMap(resources);
   }
 
@@ -113,11 +110,11 @@ public class DefaultResourceManagerPool implements ResourceManagerPool
{
     try {
       // collect current values
       Map<String, Map<String, Object>> currentValues = new HashMap<>();
-      for (ManagedResource resource : resources.values()) {
+      for (ManagedComponent managedComponent : resources.values()) {
         try {
-          currentValues.put(resource.getResourceId().toString(), resource.getMonitoredValues(resourceManagerPlugin.getMonitoredParams()));
+          currentValues.put(managedComponent.getManagedComponentId().toString(), managedComponent.getMonitoredValues(resourceManagerPlugin.getMonitoredParams()));
         } catch (Exception e) {
-          log.warn("Error getting managed values from " + resource.getResourceId(), e);
+          log.warn("Error getting managed values from " + managedComponent.getManagedComponentId(),
e);
         }
       }
       // calculate totals
@@ -167,16 +164,11 @@ public class DefaultResourceManagerPool implements ResourceManagerPool
{
   }
 
   @Override
-  public Context getPoolContext() {
+  public ResourceContext getPoolContext() {
     return poolContext;
   }
 
   @Override
-  public Context getResourceContext(String name) {
-    return resourceContexts.get(name);
-  }
-
-  @Override
   public void run() {
     try {
       resourceManagerPlugin.manage(this);
@@ -192,7 +184,6 @@ public class DefaultResourceManagerPool implements ResourceManagerPool
{
       scheduledFuture = null;
     }
     resources.clear();
-    resourceContexts.clear();
     poolContext.clear();
   }
 }
diff --git a/solr/core/src/java/org/apache/solr/managed/ManagedResource.java b/solr/core/src/java/org/apache/solr/managed/ManagedComponent.java
similarity index 83%
rename from solr/core/src/java/org/apache/solr/managed/ManagedResource.java
rename to solr/core/src/java/org/apache/solr/managed/ManagedComponent.java
index d058c97..c8d3dba 100644
--- a/solr/core/src/java/org/apache/solr/managed/ManagedResource.java
+++ b/solr/core/src/java/org/apache/solr/managed/ManagedComponent.java
@@ -24,19 +24,19 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A managed resource.
+ * A managed component.
  */
-public interface ManagedResource {
+public interface ManagedComponent {
   Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   /**
-   * Unique name of this resource. By convention id-s form a dot-separated hierarchy that
+   * Unique name of this component. By convention id-s form a dot-separated hierarchy that
    * follows the naming of metric registries and metric names.
    */
-  ResourceId getResourceId();
+  ManagedComponentId getManagedComponentId();
 
   /**
-   * Returns types of management plugins supported by this resource. This must always
+   * Returns types of management plugins supported by this component. This must always
    * return a non-null collection with at least one entry.
    */
   Collection<String> getManagedResourceTypes();
@@ -54,7 +54,7 @@ public interface ManagedResource {
         setResourceLimit(key, value);
       } catch (Exception e) {
         log.warn("Exception setting resource limit on {}: key={}, value={}, exception={}",
-            getResourceId(), key, value, e);
+            getManagedComponentId(), key, value, e);
       }
     });
   }
@@ -78,4 +78,10 @@ public interface ManagedResource {
    * @return map of parameter names to current values.
    */
   Map<String, Object> getMonitoredValues(Collection<String> params) throws Exception;
+
+  /**
+   * Component context used for managing additional component state.
+   * @return component's context
+   */
+  ResourceContext getManagedContext();
 }
diff --git a/solr/core/src/java/org/apache/solr/managed/ResourceId.java b/solr/core/src/java/org/apache/solr/managed/ManagedComponentId.java
similarity index 85%
rename from solr/core/src/java/org/apache/solr/managed/ResourceId.java
rename to solr/core/src/java/org/apache/solr/managed/ManagedComponentId.java
index 81b7a80..064cbe5 100644
--- a/solr/core/src/java/org/apache/solr/managed/ResourceId.java
+++ b/solr/core/src/java/org/apache/solr/managed/ManagedComponentId.java
@@ -22,14 +22,14 @@ import java.util.Arrays;
 import org.apache.solr.metrics.SolrMetricManager;
 
 /**
- * Hierarchical resource id.
+ * Hierarchical component id.
  */
-public class ResourceId {
+public class ManagedComponentId {
   private final String name;
   private final String[] path;
   private final String id;
 
-  public ResourceId(String name, String... path) {
+  public ManagedComponentId(String name, String... path) {
     this.name = name;
     this.path = path;
     this.id = SolrMetricManager.mkName(name, path);
@@ -47,7 +47,7 @@ public class ResourceId {
     return id;
   }
 
-  public ResourceId of(String fullName) {
+  public ManagedComponentId of(String fullName) {
     if (fullName == null || fullName.isEmpty()) {
       return null;
     }
@@ -55,9 +55,9 @@ public class ResourceId {
     if (parts.length > 1) {
       String name = parts[parts.length - 1];
       String[] path = Arrays.copyOfRange(parts, 0, parts.length - 1);
-      return new ResourceId(name, path);
+      return new ManagedComponentId(name, path);
     } else {
-      return new ResourceId(parts[0]);
+      return new ManagedComponentId(parts[0]);
     }
   }
 }
diff --git a/solr/core/src/java/org/apache/solr/managed/ManagedMetricProducer.java b/solr/core/src/java/org/apache/solr/managed/ManagedMetricProducer.java
index 82d431e..1cb9a04 100644
--- a/solr/core/src/java/org/apache/solr/managed/ManagedMetricProducer.java
+++ b/solr/core/src/java/org/apache/solr/managed/ManagedMetricProducer.java
@@ -26,7 +26,7 @@ import org.apache.solr.core.SolrInfoBean;
 /**
  * Convenience interface for {@link SolrInfoBean}-s that need to be managed.
  */
-public interface ManagedMetricProducer extends SolrInfoBean, ManagedResource {
+public interface ManagedMetricProducer extends SolrInfoBean, ManagedComponent {
 
   @Override
   default Map<String, Object> getMonitoredValues(Collection<String> params) {
diff --git a/solr/core/src/java/org/apache/solr/managed/NoOpResourceManager.java b/solr/core/src/java/org/apache/solr/managed/NoOpResourceManager.java
index 1eccff2..cd94afe 100644
--- a/solr/core/src/java/org/apache/solr/managed/NoOpResourceManager.java
+++ b/solr/core/src/java/org/apache/solr/managed/NoOpResourceManager.java
@@ -44,17 +44,17 @@ public class NoOpResourceManager extends ResourceManager {
     }
 
     @Override
-    public void addResource(ManagedResource managedResource) {
+    public void registerComponent(ManagedComponent managedComponent) {
 
     }
 
     @Override
-    public boolean removeResource(String name) {
+    public boolean unregisterComponent(String name) {
       return false;
     }
 
     @Override
-    public Map<String, ManagedResource> getResources() {
+    public Map<String, ManagedComponent> getComponents() {
       return Collections.emptyMap();
     }
 
@@ -84,12 +84,7 @@ public class NoOpResourceManager extends ResourceManager {
     }
 
     @Override
-    public Context getPoolContext() {
-      return null;
-    }
-
-    @Override
-    public Context getResourceContext(String name) {
+    public ResourceContext getPoolContext() {
       return null;
     }
 
@@ -135,12 +130,12 @@ public class NoOpResourceManager extends ResourceManager {
   }
 
   @Override
-  public void addResource(String pool, ManagedResource managedResource) throws Exception
{
+  public void registerComponent(String pool, ManagedComponent managedComponent) throws Exception
{
 
   }
 
   @Override
-  public boolean removeResource(String pool, String resourceId) {
+  public boolean unregisterComponent(String pool, String componentId) {
     return false;
   }
 
diff --git a/solr/core/src/java/org/apache/solr/managed/ManagedMetricProducer.java b/solr/core/src/java/org/apache/solr/managed/ResourceContext.java
similarity index 53%
copy from solr/core/src/java/org/apache/solr/managed/ManagedMetricProducer.java
copy to solr/core/src/java/org/apache/solr/managed/ResourceContext.java
index 82d431e..0c8e5a3 100644
--- a/solr/core/src/java/org/apache/solr/managed/ManagedMetricProducer.java
+++ b/solr/core/src/java/org/apache/solr/managed/ResourceContext.java
@@ -16,32 +16,11 @@
  */
 package org.apache.solr.managed;
 
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.solr.core.SolrInfoBean;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
- * Convenience interface for {@link SolrInfoBean}-s that need to be managed.
+ *
  */
-public interface ManagedMetricProducer extends SolrInfoBean, ManagedResource {
+public class ResourceContext extends ConcurrentHashMap<String, Object> {
 
-  @Override
-  default Map<String, Object> getMonitoredValues(Collection<String> params) {
-    Map<String, Object> metrics = getMetricsSnapshot();
-    if (metrics == null) {
-      return Collections.emptyMap();
-    }
-    Map<String, Object> result = new HashMap<>();
-    params.forEach(tag -> {
-      Object value = metrics.get(tag);
-      if (value == null) {
-        return;
-      }
-      result.put(tag, value);
-    });
-    return result;
-  }
 }
diff --git a/solr/core/src/java/org/apache/solr/managed/ResourceManager.java b/solr/core/src/java/org/apache/solr/managed/ResourceManager.java
index 43054fe..48c2273 100644
--- a/solr/core/src/java/org/apache/solr/managed/ResourceManager.java
+++ b/solr/core/src/java/org/apache/solr/managed/ResourceManager.java
@@ -197,34 +197,34 @@ public abstract class ResourceManager implements SolrCloseable, PluginInfoInitia
   public abstract void removePool(String name) throws Exception;
 
   /**
-   * Add managed resources to a pool.
+   * Add managed components to a pool.
    * @param pool existing pool name.
-   * @param managedResources resources to add
+   * @param managedComponents components to add
    */
-  public void addResources(String pool, Collection<ManagedResource> managedResources)
throws Exception {
+  public void registerComponents(String pool, Collection<ManagedComponent> managedComponents)
throws Exception {
     ensureActive();
-    for (ManagedResource resource : managedResources) {
-      addResource(pool, resource);
+    for (ManagedComponent managedComponent : managedComponents) {
+      registerComponent(pool, managedComponent);
     }
   }
 
   /**
-   * Add a managed resource to a pool.
+   * Add a managed component to a pool.
    * @param pool existing pool name.
-   * @param managedResource managed resource. The resource must support the management type
-   *                        (in its {@link ManagedResource#getManagedResourceTypes()}) used
-   *                        in the selected pool. The resource must not be already managed
by
+   * @param managedComponent managed component. The component must support the management
type
+   *                        (in its {@link ManagedComponent#getManagedResourceTypes()}) used
+   *                        in the selected pool. The component must not be already managed
by
    *                        another pool of the same type.
    */
-  public abstract void addResource(String pool, ManagedResource managedResource) throws Exception;
+  public abstract void registerComponent(String pool, ManagedComponent managedComponent)
throws Exception;
 
   /**
-   * Remove a managed resource from a pool.
+   * Remove a managed component from a pool.
    * @param pool existing pool name.
-   * @param resourceId resource id to remove
-   * @return true if a resource was actually registered and has been removed
+   * @param componentId component id to remove
+   * @return true if a component was actually registered and has been removed
    */
-  public abstract boolean removeResource(String pool, String resourceId);
+  public abstract boolean unregisterComponent(String pool, String componentId);
 
   protected void ensureActive() {
     if (isClosed()) {
diff --git a/solr/core/src/java/org/apache/solr/managed/ResourceManagerPlugin.java b/solr/core/src/java/org/apache/solr/managed/ResourceManagerPlugin.java
index f531c46..01f8363 100644
--- a/solr/core/src/java/org/apache/solr/managed/ResourceManagerPlugin.java
+++ b/solr/core/src/java/org/apache/solr/managed/ResourceManagerPlugin.java
@@ -30,12 +30,12 @@ public interface ResourceManagerPlugin {
   void init(Map<String, Object> params);
 
   /**
-   * Name of monitored parameters that {@link ManagedResource}-s managed by this plugin
+   * Name of monitored parameters that {@link ManagedComponent}-s managed by this plugin
    * are expected to support.
    */
   Collection<String> getMonitoredParams();
   /**
-   * Name of controlled parameters that {@link ManagedResource}-s managed by this plugin
+   * Name of controlled parameters that {@link ManagedComponent}-s managed by this plugin
    * are expected to support.
    */
   Collection<String> getControlledParams();
diff --git a/solr/core/src/java/org/apache/solr/managed/ResourceManagerPool.java b/solr/core/src/java/org/apache/solr/managed/ResourceManagerPool.java
index a8a7666..3a3bd78 100644
--- a/solr/core/src/java/org/apache/solr/managed/ResourceManagerPool.java
+++ b/solr/core/src/java/org/apache/solr/managed/ResourceManagerPool.java
@@ -2,31 +2,26 @@ package org.apache.solr.managed;
 
 import java.io.Closeable;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 /**
  *
  */
 public interface ResourceManagerPool extends Runnable, Closeable {
 
-  public class Context extends ConcurrentHashMap<String, Object> {
-
-  }
-
   /** Unique pool name. */
   String getName();
 
   /** Pool type. */
   String getType();
 
-  /** Add resource to this pool. */
-  void addResource(ManagedResource managedResource);
+  /** Add component to this pool. */
+  void registerComponent(ManagedComponent managedComponent);
 
-  /** Remove named resource from this pool. */
-  boolean removeResource(String name);
+  /** Remove named component from this pool. */
+  boolean unregisterComponent(String componentId);
 
-  /** Get resources managed by this pool. */
-  Map<String, ManagedResource> getResources();
+  /** Get components managed by this pool. */
+  Map<String, ManagedComponent> getComponents();
 
   /**
    * Get the current monitored values from all resources. Result is a map with resource names
as keys,
@@ -35,7 +30,7 @@ public interface ResourceManagerPool extends Runnable, Closeable {
   Map<String, Map<String, Object>> getCurrentValues() throws InterruptedException;
 
   /**
-   * This returns cumulative monitored values of all resources.
+   * This returns cumulative monitored values of all components.
    * <p>NOTE: you must call {@link #getCurrentValues()} first!</p>
    */
   Map<String, Number> getTotalValues() throws InterruptedException;
@@ -52,14 +47,7 @@ public interface ResourceManagerPool extends Runnable, Closeable {
   void setPoolLimits(Map<String, Object> poolLimits);
 
   /**
-   * Pool context used for managing pool state.
-   */
-  Context getPoolContext();
-
-  /**
-   * Resource context used for managing resource state. This context is always present for
-   * a resource registered in this pool, and it is unique to this pool.
-   * @param name resource name
+   * Pool context used for managing additional pool state.
    */
-  Context getResourceContext(String name);
+  ResourceContext getPoolContext();
 }
diff --git a/solr/core/src/java/org/apache/solr/managed/plugins/CacheManagerPlugin.java b/solr/core/src/java/org/apache/solr/managed/plugins/CacheManagerPlugin.java
index f522ad3..67a5bf3 100644
--- a/solr/core/src/java/org/apache/solr/managed/plugins/CacheManagerPlugin.java
+++ b/solr/core/src/java/org/apache/solr/managed/plugins/CacheManagerPlugin.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.solr.managed.plugins;
 
 import java.lang.invoke.MethodHandles;
@@ -105,7 +121,7 @@ public class CacheManagerPlugin extends AbstractResourceManagerPlugin
{
 
       float changeRatio = poolLimitValue / totalValue.floatValue();
       // modify current limits by the changeRatio
-      pool.getResources().forEach((name, resource) -> {
+      pool.getComponents().forEach((name, resource) -> {
         Map<String, Object> resourceLimits = resource.getResourceLimits();
         Object limit = resourceLimits.get(poolLimitName);
         // XXX we could attempt here to control eg. ramBytesUsed by adjusting maxSize limit
@@ -122,7 +138,7 @@ public class CacheManagerPlugin extends AbstractResourceManagerPlugin
{
           resource.setResourceLimit(poolLimitName, newLimit);
         } catch (Exception e) {
           log.warn("Failed to set managed limit " + poolLimitName +
-              " from " + currentResourceLimit + " to " + newLimit + " on " + resource.getResourceId(),
e);
+              " from " + currentResourceLimit + " to " + newLimit + " on " + resource.getManagedComponentId(),
e);
         }
       });
     });
diff --git a/solr/core/src/java/org/apache/solr/search/FastLRUCache.java b/solr/core/src/java/org/apache/solr/search/FastLRUCache.java
index 0ad4a9b..3f40135 100644
--- a/solr/core/src/java/org/apache/solr/search/FastLRUCache.java
+++ b/solr/core/src/java/org/apache/solr/search/FastLRUCache.java
@@ -20,7 +20,7 @@ import com.codahale.metrics.MetricRegistry;
 import org.apache.lucene.util.Accountable;
 import org.apache.lucene.util.RamUsageEstimator;
 import org.apache.solr.common.SolrException;
-import org.apache.solr.managed.ResourceId;
+import org.apache.solr.managed.ManagedComponentId;
 import org.apache.solr.managed.plugins.CacheManagerPlugin;
 import org.apache.solr.metrics.MetricsMap;
 import org.apache.solr.metrics.SolrMetricManager;
@@ -82,7 +82,7 @@ public class FastLRUCache<K, V> extends SolrCacheBase implements SolrCache<K,V>,
   private MetricsMap cacheMap;
   private Set<String> metricNames = ConcurrentHashMap.newKeySet();
   private MetricRegistry registry;
-  private ResourceId resourceId;
+  private ManagedComponentId managedComponentId;
 
   @Override
   public Object init(Map args, Object persistence, CacheRegenerator regenerator) {
@@ -310,7 +310,7 @@ public class FastLRUCache<K, V> extends SolrCacheBase implements
SolrCache<K,V>,
       }
     });
     manager.registerGauge(this, registryName, cacheMap, tag, true, scope, getCategory().toString());
-    resourceId = new ResourceId(tag, registryName, getCategory().toString(), scope);
+    managedComponentId = new ManagedComponentId(tag, registryName, getCategory().toString(),
scope);
   }
 
 
@@ -354,8 +354,8 @@ public class FastLRUCache<K, V> extends SolrCacheBase implements
SolrCache<K,V>,
   }
 
   @Override
-  public ResourceId getResourceId() {
-    return resourceId;
+  public ManagedComponentId getManagedComponentId() {
+    return managedComponentId;
   }
 
   @Override
diff --git a/solr/core/src/java/org/apache/solr/search/LFUCache.java b/solr/core/src/java/org/apache/solr/search/LFUCache.java
index 5d82a2d..a4dd8ff 100644
--- a/solr/core/src/java/org/apache/solr/search/LFUCache.java
+++ b/solr/core/src/java/org/apache/solr/search/LFUCache.java
@@ -31,7 +31,7 @@ import com.codahale.metrics.MetricRegistry;
 import org.apache.lucene.util.Accountable;
 import org.apache.lucene.util.RamUsageEstimator;
 import org.apache.solr.common.SolrException;
-import org.apache.solr.managed.ResourceId;
+import org.apache.solr.managed.ManagedComponentId;
 import org.apache.solr.managed.plugins.CacheManagerPlugin;
 import org.apache.solr.metrics.MetricsMap;
 import org.apache.solr.metrics.SolrMetricManager;
@@ -83,7 +83,7 @@ public class LFUCache<K, V> implements SolrCache<K, V>, Accountable
{
   private MetricsMap cacheMap;
   private Set<String> metricNames = ConcurrentHashMap.newKeySet();
   private MetricRegistry registry;
-  private ResourceId resourceId;
+  private ManagedComponentId managedComponentId;
 
   private int maxSize;
   private int minSize;
@@ -318,7 +318,7 @@ public class LFUCache<K, V> implements SolrCache<K, V>, Accountable
{
       }
     });
     manager.registerGauge(this, registryName, cacheMap, tag, true, scope, getCategory().toString());
-    resourceId = new ResourceId(tag, registryName, getCategory().toString(), scope);
+    managedComponentId = new ManagedComponentId(tag, registryName, getCategory().toString(),
scope);
   }
 
   // for unit tests only
@@ -353,8 +353,8 @@ public class LFUCache<K, V> implements SolrCache<K, V>, Accountable
{
   }
 
   @Override
-  public ResourceId getResourceId() {
-    return resourceId;
+  public ManagedComponentId getManagedComponentId() {
+    return managedComponentId;
   }
 
   @Override
diff --git a/solr/core/src/java/org/apache/solr/search/LRUCache.java b/solr/core/src/java/org/apache/solr/search/LRUCache.java
index 3ab0d60..c62d4fd 100644
--- a/solr/core/src/java/org/apache/solr/search/LRUCache.java
+++ b/solr/core/src/java/org/apache/solr/search/LRUCache.java
@@ -33,7 +33,7 @@ import org.apache.lucene.util.Accountable;
 import org.apache.lucene.util.Accountables;
 import org.apache.lucene.util.RamUsageEstimator;
 import org.apache.solr.common.SolrException;
-import org.apache.solr.managed.ResourceId;
+import org.apache.solr.managed.ManagedComponentId;
 import org.apache.solr.managed.plugins.CacheManagerPlugin;
 import org.apache.solr.metrics.MetricsMap;
 import org.apache.solr.metrics.SolrMetricManager;
@@ -81,7 +81,7 @@ public class LRUCache<K,V> extends SolrCacheBase implements SolrCache<K,V>,
Acco
   private MetricRegistry registry;
   private int maxSize;
   private int initialSize;
-  private ResourceId resourceId;
+  private ManagedComponentId managedComponentId;
 
   private long maxRamBytes = Long.MAX_VALUE;
   // The synchronization used for the map will be used to update this,
@@ -340,7 +340,7 @@ public class LRUCache<K,V> extends SolrCacheBase implements SolrCache<K,V>,
Acco
       res.put("cumulative_evictionsRamUsage", stats.evictionsRamUsage.longValue());
     });
     manager.registerGauge(this, registryName, cacheMap, tag, true, scope, getCategory().toString());
-    resourceId = new ResourceId(tag, registryName, getCategory().toString(), scope);
+    managedComponentId = new ManagedComponentId(tag, registryName, getCategory().toString(),
scope);
   }
 
   // for unit tests only
@@ -386,8 +386,8 @@ public class LRUCache<K,V> extends SolrCacheBase implements SolrCache<K,V>,
Acco
   }
 
   @Override
-  public ResourceId getResourceId() {
-    return resourceId;
+  public ManagedComponentId getManagedComponentId() {
+    return managedComponentId;
   }
 
   @Override
diff --git a/solr/core/src/java/org/apache/solr/search/SolrCache.java b/solr/core/src/java/org/apache/solr/search/SolrCache.java
index e2c6440..7814384 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrCache.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrCache.java
@@ -17,7 +17,7 @@
 package org.apache.solr.search;
 
 import org.apache.solr.core.SolrInfoBean;
-import org.apache.solr.managed.ManagedResource;
+import org.apache.solr.managed.ManagedComponent;
 import org.apache.solr.metrics.SolrMetricProducer;
 
 import java.util.Map;
@@ -26,7 +26,7 @@ import java.util.Map;
 /**
  * Primary API for dealing with Solr's internal caches.
  */
-public interface SolrCache<K,V> extends SolrInfoBean, SolrMetricProducer, ManagedResource
{
+public interface SolrCache<K,V> extends SolrInfoBean, SolrMetricProducer, ManagedComponent
{
 
   /** Current size of the cache. */
   String SIZE_PARAM = "size";
diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
index 561136e..b1c4b12 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -431,9 +431,9 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,
SolrI
     for (SolrCache cache : cacheList) {
       cache.initializeMetrics(metricManager, registryName, core.getMetricTag(), SolrMetricManager.mkName(cache.name(),
STATISTICS_KEY));
       try {
-        resourceManager.addResource(DefaultResourceManager.NODE_SEARCHER_CACHE_POOL, cache);
+        resourceManager.registerComponent(DefaultResourceManager.NODE_SEARCHER_CACHE_POOL,
cache);
       } catch (Exception e) {
-        log.warn("Exception adding cache '" + cache.getResourceId() + "' to the resource
manager pool", e);
+        log.warn("Exception adding cache '" + cache.getManagedComponentId() + "' to the resource
manager pool", e);
       }
     }
     initializeMetrics(metricManager, registryName, core.getMetricTag(), STATISTICS_KEY);
@@ -479,7 +479,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,
SolrI
     }
 
     for (SolrCache cache : cacheList) {
-      core.getCoreContainer().getResourceManager().removeResource(DefaultResourceManager.NODE_SEARCHER_CACHE_POOL,
cache.getResourceId().toString());
+      core.getCoreContainer().getResourceManager().unregisterComponent(DefaultResourceManager.NODE_SEARCHER_CACHE_POOL,
cache.getManagedComponentId().toString());
       cache.close();
     }
 


Mime
View raw message