Merge "Stop ProjectCacheClock thread on server shutdown"
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
import com.google.gerrit.server.config.ConfigUtil;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.inject.Inject;
|
||||
@@ -28,15 +29,22 @@ import org.eclipse.jgit.lib.Config;
|
||||
|
||||
/** Ticks periodically to force refresh events for {@link ProjectCacheImpl}. */
|
||||
@Singleton
|
||||
public class ProjectCacheClock {
|
||||
public class ProjectCacheClock implements LifecycleListener {
|
||||
private final Config serverConfig;
|
||||
|
||||
private final AtomicLong generation = new AtomicLong();
|
||||
|
||||
private ScheduledExecutorService executor;
|
||||
|
||||
@Inject
|
||||
public ProjectCacheClock(@GerritServerConfig Config serverConfig) {
|
||||
this(checkFrequency(serverConfig));
|
||||
this.serverConfig = serverConfig;
|
||||
}
|
||||
|
||||
public ProjectCacheClock(long checkFrequencyMillis) {
|
||||
@Override
|
||||
public void start() {
|
||||
long checkFrequencyMillis = checkFrequency(serverConfig);
|
||||
|
||||
if (checkFrequencyMillis == Long.MAX_VALUE) {
|
||||
// Start with generation 1 (to avoid magic 0 below).
|
||||
// Do not begin background thread, disabling the clock.
|
||||
@@ -44,7 +52,7 @@ public class ProjectCacheClock {
|
||||
} else if (10 < checkFrequencyMillis) {
|
||||
// Start with generation 1 (to avoid magic 0 below).
|
||||
generation.set(1);
|
||||
ScheduledExecutorService executor =
|
||||
executor =
|
||||
Executors.newScheduledThreadPool(
|
||||
1,
|
||||
new ThreadFactoryBuilder()
|
||||
@@ -68,6 +76,13 @@ public class ProjectCacheClock {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (executor != null) {
|
||||
executor.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
long read() {
|
||||
return generation.get();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.google.common.base.Throwables;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
import com.google.gerrit.lifecycle.LifecycleModule;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.cache.CacheModule;
|
||||
@@ -34,7 +34,6 @@ import com.google.inject.Module;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.internal.UniqueAnnotations;
|
||||
import com.google.inject.name.Named;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
@@ -71,9 +70,15 @@ public class ProjectCacheImpl implements ProjectCache {
|
||||
|
||||
bind(ProjectCacheImpl.class);
|
||||
bind(ProjectCache.class).to(ProjectCacheImpl.class);
|
||||
bind(LifecycleListener.class)
|
||||
.annotatedWith(UniqueAnnotations.create())
|
||||
.to(ProjectCacheWarmer.class);
|
||||
|
||||
install(
|
||||
new LifecycleModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
listener().to(ProjectCacheWarmer.class);
|
||||
listener().to(ProjectCacheClock.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user