Move default memory cache implementation out of H2 package
The memory cache doesn't depend on H2 at all, and this separation of packages makes it harder to reintroduce the kind of source-level dependency that was removed in I570fd54adf. Change-Id: Ie23e39cd7ea9a0813a914e65614b889c248342ae
This commit is contained in:
parent
5517ec316f
commit
a3cc510fc1
28
gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheModule.java
vendored
Normal file
28
gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheModule.java
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2018 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.h2;
|
||||||
|
|
||||||
|
import com.google.gerrit.lifecycle.LifecycleModule;
|
||||||
|
import com.google.gerrit.server.cache.CacheImpl;
|
||||||
|
import com.google.gerrit.server.cache.PersistentCacheFactory;
|
||||||
|
|
||||||
|
@CacheImpl(type = CacheImpl.Type.PERSISTENT)
|
||||||
|
public class H2CacheModule extends LifecycleModule {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(PersistentCacheFactory.class).to(H2CacheFactory.class);
|
||||||
|
listener().to(H2CacheFactory.class);
|
||||||
|
}
|
||||||
|
}
|
12
gerrit-cache-mem/BUILD
Normal file
12
gerrit-cache-mem/BUILD
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
java_library(
|
||||||
|
name = "mem",
|
||||||
|
srcs = glob(["src/main/java/**/*.java"]),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
"//gerrit-extension-api:api",
|
||||||
|
"//gerrit-server:server",
|
||||||
|
"//lib:guava",
|
||||||
|
"//lib/guice",
|
||||||
|
"//lib/jgit/org.eclipse.jgit:jgit",
|
||||||
|
],
|
||||||
|
)
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package com.google.gerrit.server.cache.h2;
|
package com.google.gerrit.server.cache.mem;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
@ -20,43 +20,21 @@ import com.google.common.cache.CacheBuilder;
|
|||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.cache.Weigher;
|
import com.google.common.cache.Weigher;
|
||||||
import com.google.gerrit.extensions.config.FactoryModule;
|
|
||||||
import com.google.gerrit.lifecycle.LifecycleModule;
|
|
||||||
import com.google.gerrit.server.cache.CacheBinding;
|
import com.google.gerrit.server.cache.CacheBinding;
|
||||||
import com.google.gerrit.server.cache.CacheImpl;
|
|
||||||
import com.google.gerrit.server.cache.ForwardingRemovalListener;
|
import com.google.gerrit.server.cache.ForwardingRemovalListener;
|
||||||
import com.google.gerrit.server.cache.MemoryCacheFactory;
|
import com.google.gerrit.server.cache.MemoryCacheFactory;
|
||||||
import com.google.gerrit.server.cache.PersistentCacheFactory;
|
|
||||||
import com.google.gerrit.server.config.ConfigUtil;
|
import com.google.gerrit.server.config.ConfigUtil;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
|
|
||||||
public class DefaultCacheFactory implements MemoryCacheFactory {
|
public class DefaultMemoryCacheFactory implements MemoryCacheFactory {
|
||||||
@CacheImpl(type = CacheImpl.Type.MEMORY)
|
|
||||||
public static class MemoryCacheModule extends FactoryModule {
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
factory(ForwardingRemovalListener.Factory.class);
|
|
||||||
bind(MemoryCacheFactory.class).to(DefaultCacheFactory.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@CacheImpl(type = CacheImpl.Type.PERSISTENT)
|
|
||||||
public static class PersistentCacheModule extends LifecycleModule {
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
bind(PersistentCacheFactory.class).to(H2CacheFactory.class);
|
|
||||||
listener().to(H2CacheFactory.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Config cfg;
|
private final Config cfg;
|
||||||
private final ForwardingRemovalListener.Factory forwardingRemovalListenerFactory;
|
private final ForwardingRemovalListener.Factory forwardingRemovalListenerFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public DefaultCacheFactory(
|
DefaultMemoryCacheFactory(
|
||||||
@GerritServerConfig Config config,
|
@GerritServerConfig Config config,
|
||||||
ForwardingRemovalListener.Factory forwardingRemovalListenerFactory) {
|
ForwardingRemovalListener.Factory forwardingRemovalListenerFactory) {
|
||||||
this.cfg = config;
|
this.cfg = config;
|
29
gerrit-cache-mem/src/main/java/com/google/gerrit/server/cache/mem/DefaultMemoryCacheModule.java
vendored
Normal file
29
gerrit-cache-mem/src/main/java/com/google/gerrit/server/cache/mem/DefaultMemoryCacheModule.java
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright (C) 2018 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.mem;
|
||||||
|
|
||||||
|
import com.google.gerrit.extensions.config.FactoryModule;
|
||||||
|
import com.google.gerrit.server.cache.CacheImpl;
|
||||||
|
import com.google.gerrit.server.cache.ForwardingRemovalListener;
|
||||||
|
import com.google.gerrit.server.cache.MemoryCacheFactory;
|
||||||
|
|
||||||
|
@CacheImpl(type = CacheImpl.Type.MEMORY)
|
||||||
|
public class DefaultMemoryCacheModule extends FactoryModule {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
factory(ForwardingRemovalListener.Factory.class);
|
||||||
|
bind(MemoryCacheFactory.class).to(DefaultMemoryCacheFactory.class);
|
||||||
|
}
|
||||||
|
}
|
@ -49,6 +49,7 @@ junit_tests(
|
|||||||
":gpg",
|
":gpg",
|
||||||
":testutil",
|
":testutil",
|
||||||
"//gerrit-cache-h2:cache-h2",
|
"//gerrit-cache-h2:cache-h2",
|
||||||
|
"//gerrit-cache-mem:mem",
|
||||||
"//gerrit-lucene:lucene",
|
"//gerrit-lucene:lucene",
|
||||||
"//gerrit-server:testutil",
|
"//gerrit-server:testutil",
|
||||||
"//lib:truth",
|
"//lib:truth",
|
||||||
|
@ -62,6 +62,7 @@ java_library(
|
|||||||
|
|
||||||
REST_UTIL_DEPS = [
|
REST_UTIL_DEPS = [
|
||||||
"//gerrit-cache-h2:cache-h2",
|
"//gerrit-cache-h2:cache-h2",
|
||||||
|
"//gerrit-cache-mem:mem",
|
||||||
"//gerrit-util-cli:cli",
|
"//gerrit-util-cli:cli",
|
||||||
"//lib:args4j",
|
"//lib:args4j",
|
||||||
"//lib:gwtorm",
|
"//lib:gwtorm",
|
||||||
@ -113,6 +114,7 @@ REST_PGM_DEPS = [
|
|||||||
":init-api",
|
":init-api",
|
||||||
":util",
|
":util",
|
||||||
"//gerrit-cache-h2:cache-h2",
|
"//gerrit-cache-h2:cache-h2",
|
||||||
|
"//gerrit-cache-mem:mem",
|
||||||
"//gerrit-elasticsearch:elasticsearch",
|
"//gerrit-elasticsearch:elasticsearch",
|
||||||
"//gerrit-gpg:gpg",
|
"//gerrit-gpg:gpg",
|
||||||
"//gerrit-lucene:lucene",
|
"//gerrit-lucene:lucene",
|
||||||
|
@ -51,7 +51,8 @@ import com.google.gerrit.server.LibModuleLoader;
|
|||||||
import com.google.gerrit.server.StartupChecks;
|
import com.google.gerrit.server.StartupChecks;
|
||||||
import com.google.gerrit.server.account.InternalAccountDirectory;
|
import com.google.gerrit.server.account.InternalAccountDirectory;
|
||||||
import com.google.gerrit.server.cache.CacheOverrides;
|
import com.google.gerrit.server.cache.CacheOverrides;
|
||||||
import com.google.gerrit.server.cache.h2.DefaultCacheFactory;
|
import com.google.gerrit.server.cache.h2.H2CacheModule;
|
||||||
|
import com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule;
|
||||||
import com.google.gerrit.server.change.ChangeCleanupRunner;
|
import com.google.gerrit.server.change.ChangeCleanupRunner;
|
||||||
import com.google.gerrit.server.config.AuthConfig;
|
import com.google.gerrit.server.config.AuthConfig;
|
||||||
import com.google.gerrit.server.config.AuthConfigModule;
|
import com.google.gerrit.server.config.AuthConfigModule;
|
||||||
@ -386,8 +387,8 @@ public class Daemon extends SiteProgram {
|
|||||||
modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
|
modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
|
||||||
modules.add(new SearchingChangeCacheImpl.Module(slave));
|
modules.add(new SearchingChangeCacheImpl.Module(slave));
|
||||||
modules.add(new InternalAccountDirectory.Module());
|
modules.add(new InternalAccountDirectory.Module());
|
||||||
modules.add(new DefaultCacheFactory.MemoryCacheModule());
|
modules.add(new DefaultMemoryCacheModule());
|
||||||
modules.add(new DefaultCacheFactory.PersistentCacheModule());
|
modules.add(new H2CacheModule());
|
||||||
modules.add(cfgInjector.getInstance(MailReceiver.Module.class));
|
modules.add(cfgInjector.getInstance(MailReceiver.Module.class));
|
||||||
if (emailModule != null) {
|
if (emailModule != null) {
|
||||||
modules.add(emailModule);
|
modules.add(emailModule);
|
||||||
|
@ -38,7 +38,8 @@ import com.google.gerrit.server.account.GroupCacheImpl;
|
|||||||
import com.google.gerrit.server.account.GroupIncludeCacheImpl;
|
import com.google.gerrit.server.account.GroupIncludeCacheImpl;
|
||||||
import com.google.gerrit.server.account.Realm;
|
import com.google.gerrit.server.account.Realm;
|
||||||
import com.google.gerrit.server.cache.CacheRemovalListener;
|
import com.google.gerrit.server.cache.CacheRemovalListener;
|
||||||
import com.google.gerrit.server.cache.h2.DefaultCacheFactory;
|
import com.google.gerrit.server.cache.h2.H2CacheModule;
|
||||||
|
import com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule;
|
||||||
import com.google.gerrit.server.change.ChangeJson;
|
import com.google.gerrit.server.change.ChangeJson;
|
||||||
import com.google.gerrit.server.change.ChangeKindCacheImpl;
|
import com.google.gerrit.server.change.ChangeKindCacheImpl;
|
||||||
import com.google.gerrit.server.change.MergeabilityCacheImpl;
|
import com.google.gerrit.server.change.MergeabilityCacheImpl;
|
||||||
@ -148,8 +149,8 @@ public class BatchProgramModule extends FactoryModule {
|
|||||||
factory(ProjectControl.AssistedFactory.class);
|
factory(ProjectControl.AssistedFactory.class);
|
||||||
|
|
||||||
install(new BatchGitModule());
|
install(new BatchGitModule());
|
||||||
install(new DefaultCacheFactory.MemoryCacheModule());
|
install(new DefaultMemoryCacheModule());
|
||||||
install(new DefaultCacheFactory.PersistentCacheModule());
|
install(new H2CacheModule());
|
||||||
install(new GroupModule());
|
install(new GroupModule());
|
||||||
install(new NoteDbModule(cfg));
|
install(new NoteDbModule(cfg));
|
||||||
install(new PrologModule());
|
install(new PrologModule());
|
||||||
|
@ -91,6 +91,7 @@ TESTUTIL_DEPS = [
|
|||||||
"//gerrit-common:annotations",
|
"//gerrit-common:annotations",
|
||||||
"//gerrit-common:server",
|
"//gerrit-common:server",
|
||||||
"//gerrit-cache-h2:cache-h2",
|
"//gerrit-cache-h2:cache-h2",
|
||||||
|
"//gerrit-cache-mem:mem",
|
||||||
"//gerrit-extension-api:api",
|
"//gerrit-extension-api:api",
|
||||||
"//gerrit-gpg:gpg",
|
"//gerrit-gpg:gpg",
|
||||||
"//gerrit-lucene:lucene",
|
"//gerrit-lucene:lucene",
|
||||||
|
@ -26,7 +26,8 @@ import com.google.gerrit.metrics.MetricMaker;
|
|||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.GerritPersonIdent;
|
import com.google.gerrit.server.GerritPersonIdent;
|
||||||
import com.google.gerrit.server.GerritPersonIdentProvider;
|
import com.google.gerrit.server.GerritPersonIdentProvider;
|
||||||
import com.google.gerrit.server.cache.h2.DefaultCacheFactory;
|
import com.google.gerrit.server.cache.h2.H2CacheModule;
|
||||||
|
import com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule;
|
||||||
import com.google.gerrit.server.config.AllProjectsName;
|
import com.google.gerrit.server.config.AllProjectsName;
|
||||||
import com.google.gerrit.server.config.AllProjectsNameProvider;
|
import com.google.gerrit.server.config.AllProjectsNameProvider;
|
||||||
import com.google.gerrit.server.config.AllUsersName;
|
import com.google.gerrit.server.config.AllUsersName;
|
||||||
@ -199,8 +200,8 @@ public class InMemoryModule extends FactoryModule {
|
|||||||
return MoreExecutors.newDirectExecutorService();
|
return MoreExecutors.newDirectExecutorService();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
install(new DefaultCacheFactory.MemoryCacheModule());
|
install(new DefaultMemoryCacheModule());
|
||||||
install(new DefaultCacheFactory.PersistentCacheModule());
|
install(new H2CacheModule());
|
||||||
install(new FakeEmailSender.Module());
|
install(new FakeEmailSender.Module());
|
||||||
install(new SignedTokenEmailTokenVerifier.Module());
|
install(new SignedTokenEmailTokenVerifier.Module());
|
||||||
install(new GpgModule(cfg));
|
install(new GpgModule(cfg));
|
||||||
|
@ -8,6 +8,7 @@ java_library(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
"//gerrit-cache-h2:cache-h2",
|
"//gerrit-cache-h2:cache-h2",
|
||||||
|
"//gerrit-cache-mem:mem",
|
||||||
"//gerrit-common:annotations",
|
"//gerrit-common:annotations",
|
||||||
"//gerrit-common:server",
|
"//gerrit-common:server",
|
||||||
"//gerrit-extension-api:api",
|
"//gerrit-extension-api:api",
|
||||||
|
@ -6,6 +6,7 @@ java_library(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
"//gerrit-cache-h2:cache-h2",
|
"//gerrit-cache-h2:cache-h2",
|
||||||
|
"//gerrit-cache-mem:mem",
|
||||||
"//gerrit-elasticsearch:elasticsearch",
|
"//gerrit-elasticsearch:elasticsearch",
|
||||||
"//gerrit-extension-api:api",
|
"//gerrit-extension-api:api",
|
||||||
"//gerrit-gpg:gpg",
|
"//gerrit-gpg:gpg",
|
||||||
|
@ -35,7 +35,8 @@ import com.google.gerrit.server.LibModuleLoader;
|
|||||||
import com.google.gerrit.server.StartupChecks;
|
import com.google.gerrit.server.StartupChecks;
|
||||||
import com.google.gerrit.server.account.InternalAccountDirectory;
|
import com.google.gerrit.server.account.InternalAccountDirectory;
|
||||||
import com.google.gerrit.server.cache.CacheOverrides;
|
import com.google.gerrit.server.cache.CacheOverrides;
|
||||||
import com.google.gerrit.server.cache.h2.DefaultCacheFactory;
|
import com.google.gerrit.server.cache.h2.H2CacheModule;
|
||||||
|
import com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule;
|
||||||
import com.google.gerrit.server.change.ChangeCleanupRunner;
|
import com.google.gerrit.server.change.ChangeCleanupRunner;
|
||||||
import com.google.gerrit.server.config.AuthConfig;
|
import com.google.gerrit.server.config.AuthConfig;
|
||||||
import com.google.gerrit.server.config.AuthConfigModule;
|
import com.google.gerrit.server.config.AuthConfigModule;
|
||||||
@ -319,8 +320,8 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi
|
|||||||
modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
|
modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
|
||||||
modules.add(new SearchingChangeCacheImpl.Module());
|
modules.add(new SearchingChangeCacheImpl.Module());
|
||||||
modules.add(new InternalAccountDirectory.Module());
|
modules.add(new InternalAccountDirectory.Module());
|
||||||
modules.add(new DefaultCacheFactory.MemoryCacheModule());
|
modules.add(new DefaultMemoryCacheModule());
|
||||||
modules.add(new DefaultCacheFactory.PersistentCacheModule());
|
modules.add(new H2CacheModule());
|
||||||
modules.add(cfgInjector.getInstance(MailReceiver.Module.class));
|
modules.add(cfgInjector.getInstance(MailReceiver.Module.class));
|
||||||
modules.add(new SmtpEmailSender.Module());
|
modules.add(new SmtpEmailSender.Module());
|
||||||
modules.add(new SignedTokenEmailTokenVerifier.Module());
|
modules.add(new SignedTokenEmailTokenVerifier.Module());
|
||||||
|
Loading…
Reference in New Issue
Block a user