Support iterating through all elements of a DynamicMap

Expose the plugin name, export name and the Provider on each element
entry. This makes it easier for callers to filter members.

Change-Id: I47f65bf38b8395e776e7fb9283909dc5a5e5e224
This commit is contained in:
Shawn Pearce
2013-05-10 13:00:44 -07:00
parent 82e66ee4e5
commit 878b5a5544
4 changed files with 61 additions and 22 deletions

View File

@@ -28,10 +28,8 @@ abstract class CacheCommand extends SshCommand {
protected SortedSet<String> cacheNames() {
SortedSet<String> names = Sets.newTreeSet();
for (String plugin : cacheMap.plugins()) {
for (String name : cacheMap.byPlugin(plugin).keySet()) {
names.add(cacheNameOf(plugin, name));
}
for (DynamicMap.Entry<Cache<?, ?>> e : cacheMap) {
names.add(cacheNameOf(e.getPluginName(), e.getExportName()));
}
return names;
}

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.sshd.commands;
import com.google.common.cache.Cache;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.sshd.BaseCommand;
import com.google.gerrit.sshd.CommandMetaData;
@@ -98,16 +99,13 @@ final class FlushCaches extends CacheCommand {
private void doBulkFlush() {
try {
for (String plugin : cacheMap.plugins()) {
for (Map.Entry<String, Provider<Cache<?, ?>>> entry :
cacheMap.byPlugin(plugin).entrySet()) {
String n = cacheNameOf(plugin, entry.getKey());
if (flush(n)) {
try {
entry.getValue().get().invalidateAll();
} catch (Throwable err) {
stderr.println("error: cannot flush cache \"" + n + "\": " + err);
}
for (DynamicMap.Entry<Cache<?, ?>> e : cacheMap) {
String n = cacheNameOf(e.getPluginName(), e.getExportName());
if (flush(n)) {
try {
e.getProvider().get().invalidateAll();
} catch (Throwable err) {
stderr.println("error: cannot flush cache \"" + n + "\": " + err);
}
}
}

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.common.Version;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.events.LifecycleListener;
import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.server.cache.h2.H2CacheImpl;
import com.google.gerrit.server.config.SitePath;
import com.google.gerrit.server.git.WorkQueue;
@@ -208,13 +209,10 @@ final class ShowCaches extends CacheCommand {
private Map<String, Cache<?, ?>> sortedPluginCaches() {
SortedMap<String, Cache<?, ?>> m = Maps.newTreeMap();
for (String plugin : cacheMap.plugins()) {
if ("gerrit".equals(plugin)) {
continue;
}
for (Map.Entry<String, Provider<Cache<?, ?>>> entry :
cacheMap.byPlugin(plugin).entrySet()) {
m.put(cacheNameOf(plugin, entry.getKey()), entry.getValue().get());
for (DynamicMap.Entry<Cache<?, ?>> e : cacheMap) {
if (!"gerrit".equals(e.getPluginName())) {
m.put(cacheNameOf(e.getPluginName(), e.getExportName()),
e.getProvider().get());
}
}
return m;