diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java index 5dd703e36d..03a5807c24 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java @@ -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()); diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/ExportReviewNotes.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/ExportReviewNotes.java index 7b8c286ae3..d453553bee 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/ExportReviewNotes.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/ExportReviewNotes.java @@ -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); } }); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/cache/CachePool.java b/gerrit-server/src/main/java/com/google/gerrit/server/cache/CachePool.java index ed596da649..3370b08b1a 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/cache/CachePool.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/cache/CachePool.java @@ -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> caches; - private CacheManager manager; - - @Inject - CachePool(@GerritServerConfig final Config cfg, final SitePaths site) { - this.config = cfg; - this.site = site; - this.caches = new HashMap>(); - } - - 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(); - } - } - } - - /** Discouraged Get the underlying cache descriptions, for statistics. */ - public CacheManager getCacheManager() { - synchronized (lock) { - return manager; - } - } - - ProxyEhcache register(final CacheProvider 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 ProxyCache register(CacheProvider provider); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/cache/CacheProvider.java b/gerrit-server/src/main/java/com/google/gerrit/server/cache/CacheProvider.java index 0ba424f2cd..1fa047bc35 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/cache/CacheProvider.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/cache/CacheProvider.java @@ -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 implements Provider>, +public final class CacheProvider implements Provider>, NamedCacheBinding, UnnamedCacheBinding { private final CacheModule module; private final boolean disk; @@ -35,7 +33,7 @@ final class CacheProvider implements Provider>, private long maxAge; private EvictionPolicy evictionPolicy; private String cacheName; - private ProxyEhcache cache; + private ProxyCache cache; private Provider> entryCreator; CacheProvider(final boolean disk, CacheModule module) { @@ -56,34 +54,41 @@ final class CacheProvider implements Provider>, this.cache = pool.register(this); } - void bind(final Ehcache ehcache) { - cache.bind(ehcache); + public void bind(Cache impl) { + if (cache == null) { + throw new ProvisionException("Cache was never registered"); + } + cache.bind(impl); } - String getName() { + public EntryCreator 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 implements Provider>, if (cache == null) { throw new ProvisionException("Cache \"" + cacheName + "\" not available"); } - if (entryCreator != null) { - return new PopulatingCache(cache, entryCreator.get()); - } - return new SimpleCache(cache); + return cache; } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/cache/EhcachePoolImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/cache/EhcachePoolImpl.java new file mode 100644 index 0000000000..c1749818b8 --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/cache/EhcachePoolImpl.java @@ -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> caches; + private CacheManager manager; + + @Inject + EhcachePoolImpl(@GerritServerConfig final Config cfg, final SitePaths site) { + this.config = cfg; + this.site = site; + this.caches = new HashMap>(); + } + + 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(); + } + } + } + + /** Discouraged Get the underlying cache descriptions, for statistics. */ + public CacheManager getCacheManager() { + synchronized (lock) { + return manager; + } + } + + public ProxyCache register(final CacheProvider 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(); + } + } + + 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; + } + } +} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/cache/ProxyCache.java b/gerrit-server/src/main/java/com/google/gerrit/server/cache/ProxyCache.java new file mode 100644 index 0000000000..1fbc819e0c --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/cache/ProxyCache.java @@ -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 implements Cache { + private volatile Cache self; + + public void bind(Cache 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(); + } +} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/cache/ProxyEhcache.java b/gerrit-server/src/main/java/com/google/gerrit/server/cache/ProxyEhcache.java deleted file mode 100644 index bcead637f8..0000000000 --- a/gerrit-server/src/main/java/com/google/gerrit/server/cache/ProxyEhcache.java +++ /dev/null @@ -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 getRegisteredCacheExtensions() { - return self().getRegisteredCacheExtensions(); - } - - public List 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); - } -} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritGlobalModule.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritGlobalModule.java index caadb0923c..171d71925f 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritGlobalModule.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritGlobalModule.java @@ -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); - } - }); } } diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CacheCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CacheCommand.java index 313b9dc3df..83cdc57b58 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CacheCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CacheCommand.java @@ -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 cacheNames() { final SortedSet names = new TreeSet(); diff --git a/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java b/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java index 8d633eba1e..04d11ca58d 100644 --- a/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java +++ b/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java @@ -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());