Refactor CachePool to permit other types of caching

In a cluster configuration we might choose to avoid using Ehcache
altogether, and instead use no caching, or use some other type of
cluster based cache such as memcache.

Although Ehcache has pluggable providers underneath of it that may
permit use in a cluster environment, we might not always be able to
use that provider.  Abstract it away as a Guice injection so that we
can replace Ehcache entirely if we need to.

Change-Id: Ia3f918606968148b4ab1450011c1a077234d3cbd
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2010-06-09 10:31:25 -07:00
parent d0dc9f5c4f
commit edcc56aad4
10 changed files with 341 additions and 654 deletions

View File

@@ -32,6 +32,7 @@ import com.google.gerrit.pgm.util.LogFileCompressor;
import com.google.gerrit.pgm.util.RuntimeShutdown;
import com.google.gerrit.pgm.util.SiteProgram;
import com.google.gerrit.reviewdb.AuthType;
import com.google.gerrit.server.cache.EhcachePoolImpl;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.AuthConfigModule;
import com.google.gerrit.server.config.CanonicalWebUrlModule;
@@ -200,6 +201,7 @@ public class Daemon extends SiteProgram {
modules.add(new WorkQueue.Module());
modules.add(new ChangeHookRunner.Module());
modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
modules.add(new EhcachePoolImpl.Module());
modules.add(new SmtpEmailSender.Module());
modules.add(new SignedTokenEmailTokenVerifier.Module());
modules.add(new PushReplication.Module());

View File

@@ -27,6 +27,7 @@ import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gerrit.server.account.AccountCacheImpl;
import com.google.gerrit.server.account.GroupCacheImpl;
import com.google.gerrit.server.cache.CachePool;
import com.google.gerrit.server.cache.EhcachePoolImpl;
import com.google.gerrit.server.config.ApprovalTypesProvider;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.CanonicalWebUrlProvider;
@@ -100,6 +101,7 @@ public class ExportReviewNotes extends SiteProgram {
install(AccountCacheImpl.module());
install(GroupCacheImpl.module());
install(new EhcachePoolImpl.Module());
install(new FactoryModule() {
@Override
protected void configure() {
@@ -109,7 +111,6 @@ public class ExportReviewNotes extends SiteProgram {
install(new LifecycleModule() {
@Override
protected void configure() {
listener().to(CachePool.Lifecycle.class);
listener().to(LocalDiskRepositoryManager.Lifecycle.class);
}
});

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2009 The Android Open Source Project
// Copyright (C) 2010 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,234 +14,6 @@
package com.google.gerrit.server.cache;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.gerrit.lifecycle.LifecycleListener;
import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.Configuration;
import net.sf.ehcache.config.DiskStoreConfiguration;
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
import org.eclipse.jgit.lib.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/** Pool of all declared caches created by {@link CacheModule}s. */
@Singleton
public class CachePool {
private static final Logger log = LoggerFactory.getLogger(CachePool.class);
public static class Lifecycle implements LifecycleListener {
private final CachePool cachePool;
@Inject
Lifecycle(final CachePool cachePool) {
this.cachePool = cachePool;
}
@Override
public void start() {
cachePool.start();
}
@Override
public void stop() {
cachePool.stop();
}
}
private final Config config;
private final SitePaths site;
private final Object lock = new Object();
private final Map<String, CacheProvider<?, ?>> caches;
private CacheManager manager;
@Inject
CachePool(@GerritServerConfig final Config cfg, final SitePaths site) {
this.config = cfg;
this.site = site;
this.caches = new HashMap<String, CacheProvider<?, ?>>();
}
private void start() {
synchronized (lock) {
if (manager != null) {
throw new IllegalStateException("Cache pool has already been started");
}
try {
System.setProperty("net.sf.ehcache.skipUpdateCheck", "" + true);
} catch (SecurityException e) {
// Ignore it, the system is just going to ping some external page
// using a background thread and there's not much we can do about
// it now.
}
manager = new CacheManager(new Factory().toConfiguration());
for (CacheProvider<?, ?> p : caches.values()) {
p.bind(manager.getEhcache(p.getName()));
}
}
}
private void stop() {
synchronized (lock) {
if (manager != null) {
manager.shutdown();
}
}
}
/** <i>Discouraged</i> Get the underlying cache descriptions, for statistics. */
public CacheManager getCacheManager() {
synchronized (lock) {
return manager;
}
}
<K, V> ProxyEhcache register(final CacheProvider<K, V> provider) {
synchronized (lock) {
if (manager != null) {
throw new IllegalStateException("Cache pool has already been started");
}
final String n = provider.getName();
if (caches.containsKey(n) && caches.get(n) != provider) {
throw new IllegalStateException("Cache \"" + n + "\" already defined");
}
caches.put(n, provider);
return new ProxyEhcache(n);
}
}
private class Factory {
private static final int MB = 1024 * 1024;
private final Configuration mgr = new Configuration();
Configuration toConfiguration() {
configureDiskStore();
configureDefaultCache();
for (CacheProvider<?, ?> p : caches.values()) {
final String name = p.getName();
final CacheConfiguration c = newCache(name);
c.setMemoryStoreEvictionPolicyFromObject(toPolicy(p.evictionPolicy()));
c.setMaxElementsInMemory(getInt(name, "memorylimit", p.memoryLimit()));
c.setTimeToIdleSeconds(0);
c.setTimeToLiveSeconds(getSeconds(name, "maxage", p.maxAge()));
c.setEternal(c.getTimeToLiveSeconds() == 0);
if (p.disk() && mgr.getDiskStoreConfiguration() != null) {
c.setMaxElementsOnDisk(getInt(name, "disklimit", p.diskLimit()));
int v = c.getDiskSpoolBufferSizeMB() * MB;
v = getInt(name, "diskbuffer", v) / MB;
c.setDiskSpoolBufferSizeMB(Math.max(1, v));
c.setOverflowToDisk(c.getMaxElementsOnDisk() > 0);
c.setDiskPersistent(c.getMaxElementsOnDisk() > 0);
}
mgr.addCache(c);
}
return mgr;
}
private MemoryStoreEvictionPolicy toPolicy(final EvictionPolicy policy) {
switch (policy) {
case LFU:
return MemoryStoreEvictionPolicy.LFU;
case LRU:
return MemoryStoreEvictionPolicy.LRU;
default:
throw new IllegalArgumentException("Unsupported " + policy);
}
}
private int getInt(String n, String s, int d) {
return config.getInt("cache", n, s, d);
}
private long getSeconds(String n, String s, long d) {
d = MINUTES.convert(d, SECONDS);
long m = ConfigUtil.getTimeUnit(config, "cache", n, s, d, MINUTES);
return SECONDS.convert(m, MINUTES);
}
private void configureDiskStore() {
boolean needDisk = false;
for (CacheProvider<?, ?> p : caches.values()) {
if (p.disk()) {
needDisk = true;
break;
}
}
if (!needDisk) {
return;
}
File loc = site.resolve(config.getString("cache", null, "directory"));
if (loc == null) {
} else if (loc.exists() || loc.mkdirs()) {
if (loc.canWrite()) {
final DiskStoreConfiguration c = new DiskStoreConfiguration();
c.setPath(loc.getAbsolutePath());
mgr.addDiskStore(c);
log.info("Enabling disk cache " + loc.getAbsolutePath());
} else {
log.warn("Can't write to disk cache: " + loc.getAbsolutePath());
}
} else {
log.warn("Can't create disk cache: " + loc.getAbsolutePath());
}
}
private CacheConfiguration newConfiguration() {
CacheConfiguration c = new CacheConfiguration();
c.setMaxElementsInMemory(1024);
c.setMemoryStoreEvictionPolicyFromObject(MemoryStoreEvictionPolicy.LFU);
c.setTimeToIdleSeconds(0);
c.setTimeToLiveSeconds(0 /* infinite */);
c.setEternal(true);
if (mgr.getDiskStoreConfiguration() != null) {
c.setMaxElementsOnDisk(16384);
c.setOverflowToDisk(false);
c.setDiskPersistent(false);
c.setDiskSpoolBufferSizeMB(5);
c.setDiskExpiryThreadIntervalSeconds(60 * 60);
}
return c;
}
private void configureDefaultCache() {
mgr.setDefaultCacheConfiguration(newConfiguration());
}
private CacheConfiguration newCache(final String name) {
CacheConfiguration c = newConfiguration();
c.setName(name);
return c;
}
}
public interface CachePool {
public <K, V> ProxyCache<K, V> register(CacheProvider<K, V> provider);
}

View File

@@ -22,11 +22,9 @@ import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.ProvisionException;
import net.sf.ehcache.Ehcache;
import java.util.concurrent.TimeUnit;
final class CacheProvider<K, V> implements Provider<Cache<K, V>>,
public final class CacheProvider<K, V> implements Provider<Cache<K, V>>,
NamedCacheBinding<K, V>, UnnamedCacheBinding<K, V> {
private final CacheModule module;
private final boolean disk;
@@ -35,7 +33,7 @@ final class CacheProvider<K, V> implements Provider<Cache<K, V>>,
private long maxAge;
private EvictionPolicy evictionPolicy;
private String cacheName;
private ProxyEhcache cache;
private ProxyCache<K, V> cache;
private Provider<EntryCreator<K, V>> entryCreator;
CacheProvider(final boolean disk, CacheModule module) {
@@ -56,34 +54,41 @@ final class CacheProvider<K, V> implements Provider<Cache<K, V>>,
this.cache = pool.register(this);
}
void bind(final Ehcache ehcache) {
cache.bind(ehcache);
public void bind(Cache<K, V> impl) {
if (cache == null) {
throw new ProvisionException("Cache was never registered");
}
cache.bind(impl);
}
String getName() {
public EntryCreator<K, V> getEntryCreator() {
return entryCreator != null ? entryCreator.get() : null;
}
public String getName() {
if (cacheName == null) {
throw new ProvisionException("Cache has no name");
}
return cacheName;
}
boolean disk() {
public boolean disk() {
return disk;
}
int memoryLimit() {
public int memoryLimit() {
return memoryLimit;
}
int diskLimit() {
public int diskLimit() {
return diskLimit;
}
long maxAge() {
public long maxAge() {
return maxAge;
}
EvictionPolicy evictionPolicy() {
public EvictionPolicy evictionPolicy() {
return evictionPolicy;
}
@@ -133,9 +138,6 @@ final class CacheProvider<K, V> implements Provider<Cache<K, V>>,
if (cache == null) {
throw new ProvisionException("Cache \"" + cacheName + "\" not available");
}
if (entryCreator != null) {
return new PopulatingCache<K, V>(cache, entryCreator.get());
}
return new SimpleCache<K, V>(cache);
return cache;
}
}

View File

@@ -0,0 +1,265 @@
// Copyright (C) 2009 The Android Open Source Project
//
// Licensed 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 com.google.gerrit.server.cache;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.gerrit.lifecycle.LifecycleListener;
import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.Configuration;
import net.sf.ehcache.config.DiskStoreConfiguration;
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
import org.eclipse.jgit.lib.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/** Pool of all declared caches created by {@link CacheModule}s. */
@Singleton
public class EhcachePoolImpl implements CachePool {
private static final Logger log =
LoggerFactory.getLogger(EhcachePoolImpl.class);
public static class Module extends LifecycleModule {
@Override
protected void configure() {
bind(CachePool.class).to(EhcachePoolImpl.class);
bind(EhcachePoolImpl.class);
listener().to(EhcachePoolImpl.Lifecycle.class);
}
}
public static class Lifecycle implements LifecycleListener {
private final EhcachePoolImpl cachePool;
@Inject
Lifecycle(final EhcachePoolImpl cachePool) {
this.cachePool = cachePool;
}
@Override
public void start() {
cachePool.start();
}
@Override
public void stop() {
cachePool.stop();
}
}
private final Config config;
private final SitePaths site;
private final Object lock = new Object();
private final Map<String, CacheProvider<?, ?>> caches;
private CacheManager manager;
@Inject
EhcachePoolImpl(@GerritServerConfig final Config cfg, final SitePaths site) {
this.config = cfg;
this.site = site;
this.caches = new HashMap<String, CacheProvider<?, ?>>();
}
private void start() {
synchronized (lock) {
if (manager != null) {
throw new IllegalStateException("Cache pool has already been started");
}
try {
System.setProperty("net.sf.ehcache.skipUpdateCheck", "" + true);
} catch (SecurityException e) {
// Ignore it, the system is just going to ping some external page
// using a background thread and there's not much we can do about
// it now.
}
manager = new CacheManager(new Factory().toConfiguration());
for (CacheProvider<?, ?> p : caches.values()) {
Ehcache eh = manager.getEhcache(p.getName());
EntryCreator<?, ?> c = p.getEntryCreator();
if (c != null) {
p.bind(new PopulatingCache(eh, c));
} else {
p.bind(new SimpleCache(eh));
}
}
}
}
private void stop() {
synchronized (lock) {
if (manager != null) {
manager.shutdown();
}
}
}
/** <i>Discouraged</i> Get the underlying cache descriptions, for statistics. */
public CacheManager getCacheManager() {
synchronized (lock) {
return manager;
}
}
public <K, V> ProxyCache<K, V> register(final CacheProvider<K, V> provider) {
synchronized (lock) {
if (manager != null) {
throw new IllegalStateException("Cache pool has already been started");
}
final String n = provider.getName();
if (caches.containsKey(n) && caches.get(n) != provider) {
throw new IllegalStateException("Cache \"" + n + "\" already defined");
}
caches.put(n, provider);
return new ProxyCache<K, V>();
}
}
private class Factory {
private static final int MB = 1024 * 1024;
private final Configuration mgr = new Configuration();
Configuration toConfiguration() {
configureDiskStore();
configureDefaultCache();
for (CacheProvider<?, ?> p : caches.values()) {
final String name = p.getName();
final CacheConfiguration c = newCache(name);
c.setMemoryStoreEvictionPolicyFromObject(toPolicy(p.evictionPolicy()));
c.setMaxElementsInMemory(getInt(name, "memorylimit", p.memoryLimit()));
c.setTimeToIdleSeconds(0);
c.setTimeToLiveSeconds(getSeconds(name, "maxage", p.maxAge()));
c.setEternal(c.getTimeToLiveSeconds() == 0);
if (p.disk() && mgr.getDiskStoreConfiguration() != null) {
c.setMaxElementsOnDisk(getInt(name, "disklimit", p.diskLimit()));
int v = c.getDiskSpoolBufferSizeMB() * MB;
v = getInt(name, "diskbuffer", v) / MB;
c.setDiskSpoolBufferSizeMB(Math.max(1, v));
c.setOverflowToDisk(c.getMaxElementsOnDisk() > 0);
c.setDiskPersistent(c.getMaxElementsOnDisk() > 0);
}
mgr.addCache(c);
}
return mgr;
}
private MemoryStoreEvictionPolicy toPolicy(final EvictionPolicy policy) {
switch (policy) {
case LFU:
return MemoryStoreEvictionPolicy.LFU;
case LRU:
return MemoryStoreEvictionPolicy.LRU;
default:
throw new IllegalArgumentException("Unsupported " + policy);
}
}
private int getInt(String n, String s, int d) {
return config.getInt("cache", n, s, d);
}
private long getSeconds(String n, String s, long d) {
d = MINUTES.convert(d, SECONDS);
long m = ConfigUtil.getTimeUnit(config, "cache", n, s, d, MINUTES);
return SECONDS.convert(m, MINUTES);
}
private void configureDiskStore() {
boolean needDisk = false;
for (CacheProvider<?, ?> p : caches.values()) {
if (p.disk()) {
needDisk = true;
break;
}
}
if (!needDisk) {
return;
}
File loc = site.resolve(config.getString("cache", null, "directory"));
if (loc == null) {
} else if (loc.exists() || loc.mkdirs()) {
if (loc.canWrite()) {
final DiskStoreConfiguration c = new DiskStoreConfiguration();
c.setPath(loc.getAbsolutePath());
mgr.addDiskStore(c);
log.info("Enabling disk cache " + loc.getAbsolutePath());
} else {
log.warn("Can't write to disk cache: " + loc.getAbsolutePath());
}
} else {
log.warn("Can't create disk cache: " + loc.getAbsolutePath());
}
}
private CacheConfiguration newConfiguration() {
CacheConfiguration c = new CacheConfiguration();
c.setMaxElementsInMemory(1024);
c.setMemoryStoreEvictionPolicyFromObject(MemoryStoreEvictionPolicy.LFU);
c.setTimeToIdleSeconds(0);
c.setTimeToLiveSeconds(0 /* infinite */);
c.setEternal(true);
if (mgr.getDiskStoreConfiguration() != null) {
c.setMaxElementsOnDisk(16384);
c.setOverflowToDisk(false);
c.setDiskPersistent(false);
c.setDiskSpoolBufferSizeMB(5);
c.setDiskExpiryThreadIntervalSeconds(60 * 60);
}
return c;
}
private void configureDefaultCache() {
mgr.setDefaultCacheConfiguration(newConfiguration());
}
private CacheConfiguration newCache(final String name) {
CacheConfiguration c = newConfiguration();
c.setName(name);
return c;
}
}
}

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2010 The Android Open Source Project
//
// Licensed 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 com.google.gerrit.server.cache;
import java.util.concurrent.TimeUnit;
/** Proxy around a cache which has not yet been created. */
public final class ProxyCache<K, V> implements Cache<K, V> {
private volatile Cache<K, V> self;
public void bind(Cache<K, V> self) {
this.self = self;
}
public V get(K key) {
return self.get(key);
}
public long getTimeToLive(TimeUnit unit) {
return self.getTimeToLive(unit);
}
public void put(K key, V value) {
self.put(key, value);
}
public void remove(K key) {
self.remove(key);
}
public void removeAll() {
self.removeAll();
}
}

View File

@@ -1,393 +0,0 @@
// Copyright (C) 2008 The Android Open Source Project
//
// Licensed 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 com.google.gerrit.server.cache;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import net.sf.ehcache.Statistics;
import net.sf.ehcache.Status;
import net.sf.ehcache.bootstrap.BootstrapCacheLoader;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.event.RegisteredEventListeners;
import net.sf.ehcache.exceptionhandler.CacheExceptionHandler;
import net.sf.ehcache.extension.CacheExtension;
import net.sf.ehcache.loader.CacheLoader;
import net.sf.ehcache.statistics.CacheUsageListener;
import net.sf.ehcache.statistics.LiveCacheStatistics;
import net.sf.ehcache.statistics.sampled.SampledCacheStatistics;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/** Proxy around a cache which has not yet been created. */
final class ProxyEhcache implements Ehcache {
private final String cacheName;
private volatile Ehcache self;
ProxyEhcache(final String cacheName) {
this.cacheName = cacheName;
}
void bind(final Ehcache self) {
this.self = self;
}
private Ehcache self() {
return self;
}
@Override
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
@Override
public String getName() {
return cacheName;
}
@Override
public void setName(String name) {
throw new UnsupportedOperationException();
}
//
// Everything else delegates through self.
//
public void bootstrap() {
self().bootstrap();
}
public long calculateInMemorySize() throws IllegalStateException,
CacheException {
return self().calculateInMemorySize();
}
public void clearStatistics() {
self().clearStatistics();
}
public void dispose() throws IllegalStateException {
self().dispose();
}
public void evictExpiredElements() {
self().evictExpiredElements();
}
public void flush() throws IllegalStateException, CacheException {
self().flush();
}
public Element get(Object key) throws IllegalStateException, CacheException {
return self().get(key);
}
public Element get(Serializable key) throws IllegalStateException,
CacheException {
return self().get(key);
}
@SuppressWarnings("rawtypes")
public Map getAllWithLoader(Collection keys, Object loaderArgument)
throws CacheException {
return self().getAllWithLoader(keys, loaderArgument);
}
public float getAverageGetTime() {
return self().getAverageGetTime();
}
public BootstrapCacheLoader getBootstrapCacheLoader() {
return self().getBootstrapCacheLoader();
}
public CacheConfiguration getCacheConfiguration() {
if (self == null) {
// In Ehcache 1.7, BlockingCache wants to ask us if we are
// clustered using Terracotta. Unfortunately it is too early
// to know for certain as the caches have not actually been
// created or configured.
//
return new CacheConfiguration();
}
return self().getCacheConfiguration();
}
public RegisteredEventListeners getCacheEventNotificationService() {
return self().getCacheEventNotificationService();
}
public CacheExceptionHandler getCacheExceptionHandler() {
return self().getCacheExceptionHandler();
}
public CacheManager getCacheManager() {
return self().getCacheManager();
}
public int getDiskStoreSize() throws IllegalStateException {
return self().getDiskStoreSize();
}
public String getGuid() {
return self().getGuid();
}
@SuppressWarnings("rawtypes")
public List getKeys() throws IllegalStateException, CacheException {
return self().getKeys();
}
@SuppressWarnings("rawtypes")
public List getKeysNoDuplicateCheck() throws IllegalStateException {
return self().getKeysNoDuplicateCheck();
}
@SuppressWarnings("rawtypes")
public List getKeysWithExpiryCheck() throws IllegalStateException,
CacheException {
return self().getKeysWithExpiryCheck();
}
public long getMemoryStoreSize() throws IllegalStateException {
return self().getMemoryStoreSize();
}
public Element getQuiet(Object key) throws IllegalStateException,
CacheException {
return self().getQuiet(key);
}
public Element getQuiet(Serializable key) throws IllegalStateException,
CacheException {
return self().getQuiet(key);
}
public List<CacheExtension> getRegisteredCacheExtensions() {
return self().getRegisteredCacheExtensions();
}
public List<CacheLoader> getRegisteredCacheLoaders() {
return self().getRegisteredCacheLoaders();
}
public int getSize() throws IllegalStateException, CacheException {
return self().getSize();
}
public Statistics getStatistics() throws IllegalStateException {
return self().getStatistics();
}
public int getStatisticsAccuracy() {
return self().getStatisticsAccuracy();
}
public Status getStatus() {
return self().getStatus();
}
public Element getWithLoader(Object key, CacheLoader loader,
Object loaderArgument) throws CacheException {
return self().getWithLoader(key, loader, loaderArgument);
}
public void initialise() {
self().initialise();
}
public boolean isDisabled() {
return self().isDisabled();
}
public boolean isElementInMemory(Object key) {
return self().isElementInMemory(key);
}
public boolean isElementInMemory(Serializable key) {
return self().isElementInMemory(key);
}
public boolean isElementOnDisk(Object key) {
return self().isElementOnDisk(key);
}
public boolean isElementOnDisk(Serializable key) {
return self().isElementOnDisk(key);
}
public boolean isExpired(Element element) throws IllegalStateException,
NullPointerException {
return self().isExpired(element);
}
public boolean isKeyInCache(Object key) {
return self().isKeyInCache(key);
}
public boolean isValueInCache(Object value) {
return self().isValueInCache(value);
}
public void load(Object key) throws CacheException {
self().load(key);
}
@SuppressWarnings("rawtypes")
public void loadAll(Collection keys, Object argument) throws CacheException {
self().loadAll(keys, argument);
}
public void put(Element element, boolean doNotNotifyCacheReplicators)
throws IllegalArgumentException, IllegalStateException, CacheException {
self().put(element, doNotNotifyCacheReplicators);
}
public void put(Element element) throws IllegalArgumentException,
IllegalStateException, CacheException {
self().put(element);
}
public void putQuiet(Element element) throws IllegalArgumentException,
IllegalStateException, CacheException {
self().putQuiet(element);
}
public void registerCacheExtension(CacheExtension cacheExtension) {
self().registerCacheExtension(cacheExtension);
}
public void registerCacheLoader(CacheLoader cacheLoader) {
self().registerCacheLoader(cacheLoader);
}
public boolean remove(Object key, boolean doNotNotifyCacheReplicators)
throws IllegalStateException {
return self().remove(key, doNotNotifyCacheReplicators);
}
public boolean remove(Object key) throws IllegalStateException {
return self().remove(key);
}
public boolean remove(Serializable key, boolean doNotNotifyCacheReplicators)
throws IllegalStateException {
return self().remove(key, doNotNotifyCacheReplicators);
}
public boolean remove(Serializable key) throws IllegalStateException {
return self().remove(key);
}
public void removeAll() throws IllegalStateException, CacheException {
self().removeAll();
}
public void removeAll(boolean doNotNotifyCacheReplicators)
throws IllegalStateException, CacheException {
self().removeAll(doNotNotifyCacheReplicators);
}
public boolean removeQuiet(Object key) throws IllegalStateException {
return self().removeQuiet(key);
}
public boolean removeQuiet(Serializable key) throws IllegalStateException {
return self().removeQuiet(key);
}
public void setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader)
throws CacheException {
self().setBootstrapCacheLoader(bootstrapCacheLoader);
}
public void setCacheExceptionHandler(
CacheExceptionHandler cacheExceptionHandler) {
self().setCacheExceptionHandler(cacheExceptionHandler);
}
public void setCacheManager(CacheManager cacheManager) {
self().setCacheManager(cacheManager);
}
public void setDisabled(boolean disabled) {
self().setDisabled(disabled);
}
public void setDiskStorePath(String diskStorePath) throws CacheException {
self().setDiskStorePath(diskStorePath);
}
public void setStatisticsAccuracy(int statisticsAccuracy) {
self().setStatisticsAccuracy(statisticsAccuracy);
}
public void unregisterCacheExtension(CacheExtension cacheExtension) {
self().unregisterCacheExtension(cacheExtension);
}
public void unregisterCacheLoader(CacheLoader cacheLoader) {
self().unregisterCacheLoader(cacheLoader);
}
public Object getInternalContext() {
return self.getInternalContext();
}
public LiveCacheStatistics getLiveCacheStatistics() throws IllegalStateException {
return self.getLiveCacheStatistics();
}
public SampledCacheStatistics getSampledCacheStatistics() {
return self.getSampledCacheStatistics();
}
public int getSizeBasedOnAccuracy(int statisticsAccuracy) throws IllegalArgumentException,
IllegalStateException, CacheException {
return self.getSizeBasedOnAccuracy(statisticsAccuracy);
}
public boolean isSampledStatisticsEnabled() {
return self.isSampledStatisticsEnabled();
}
public boolean isStatisticsEnabled() {
return self.isStatisticsEnabled();
}
public void registerCacheUsageListener(CacheUsageListener cacheUsageListener)
throws IllegalStateException {
self.registerCacheUsageListener(cacheUsageListener);
}
public void removeCacheUsageListener(CacheUsageListener cacheUsageListener)
throws IllegalStateException {
self.removeCacheUsageListener(cacheUsageListener);
}
public void setSampledStatisticsEnabled(boolean enableStatistics) {
self.setSampledStatisticsEnabled(enableStatistics);
}
public void setStatisticsEnabled(boolean enableStatistics) {
self.setStatisticsEnabled(enableStatistics);
}
}

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.config;
import static com.google.inject.Scopes.SINGLETON;
import com.google.gerrit.common.data.ApprovalTypes;
import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.reviewdb.AuthType;
import com.google.gerrit.rules.PrologModule;
import com.google.gerrit.rules.RulesCache;
@@ -36,7 +35,6 @@ import com.google.gerrit.server.account.GroupIncludeCacheImpl;
import com.google.gerrit.server.account.GroupInfoCacheFactory;
import com.google.gerrit.server.account.Realm;
import com.google.gerrit.server.auth.ldap.LdapModule;
import com.google.gerrit.server.cache.CachePool;
import com.google.gerrit.server.events.EventFactory;
import com.google.gerrit.server.git.ChangeMergeQueue;
import com.google.gerrit.server.git.GitModule;
@@ -101,7 +99,6 @@ public class GerritGlobalModule extends FactoryModule {
SINGLETON);
bind(IdGenerator.class);
bind(CachePool.class);
bind(RulesCache.class);
install(AccountByEmailCacheImpl.module());
install(AccountCacheImpl.module());
@@ -145,12 +142,5 @@ public class GerritGlobalModule extends FactoryModule {
bind(ProjectControl.GenericFactory.class);
factory(FunctionState.Factory.class);
factory(ReplicationUser.Factory.class);
install(new LifecycleModule() {
@Override
protected void configure() {
listener().to(CachePool.Lifecycle.class);
}
});
}
}

View File

@@ -14,7 +14,7 @@
package com.google.gerrit.sshd.commands;
import com.google.gerrit.server.cache.CachePool;
import com.google.gerrit.server.cache.EhcachePoolImpl;
import com.google.gerrit.sshd.BaseCommand;
import com.google.inject.Inject;
@@ -27,7 +27,7 @@ import java.util.TreeSet;
abstract class CacheCommand extends BaseCommand {
@Inject
protected CachePool cachePool;
protected EhcachePoolImpl cachePool;
protected SortedSet<String> cacheNames() {
final SortedSet<String> names = new TreeSet<String>();

View File

@@ -18,10 +18,11 @@ import static com.google.inject.Scopes.SINGLETON;
import static com.google.inject.Stage.PRODUCTION;
import com.google.gerrit.common.ChangeHookRunner;
import com.google.gerrit.httpd.auth.openid.OpenIdModule;
import com.google.gerrit.lifecycle.LifecycleManager;
import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.httpd.auth.openid.OpenIdModule;
import com.google.gerrit.reviewdb.AuthType;
import com.google.gerrit.server.cache.EhcachePoolImpl;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.AuthConfigModule;
import com.google.gerrit.server.config.CanonicalWebUrlModule;
@@ -190,6 +191,7 @@ public class WebAppInitializer extends GuiceServletContextListener {
modules.add(new WorkQueue.Module());
modules.add(new ChangeHookRunner.Module());
modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
modules.add(new EhcachePoolImpl.Module());
modules.add(new SmtpEmailSender.Module());
modules.add(new SignedTokenEmailTokenVerifier.Module());
modules.add(new PushReplication.Module());