Remove hand serialization of cache data
We now encode them using protobuf.
Change-Id: I88e3efcfd85d60d516921cbb487fc3e8e197fce3
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/gerrit-ehcache/src/main/java/com/google/gerrit/ehcache/SerializableProtobuf.java b/gerrit-ehcache/src/main/java/com/google/gerrit/ehcache/SerializableProtobuf.java
index 41ac1de..31a3b5e 100644
--- a/gerrit-ehcache/src/main/java/com/google/gerrit/ehcache/SerializableProtobuf.java
+++ b/gerrit-ehcache/src/main/java/com/google/gerrit/ehcache/SerializableProtobuf.java
@@ -27,7 +27,7 @@
import java.util.Arrays;
class SerializableProtobuf<T> implements Serializable {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 100L;
private transient volatile Object data;
private transient ProtobufCodec<T> codec;
@@ -113,8 +113,7 @@
}
}
- private void readObject(ObjectInputStream in) throws IOException,
- ClassNotFoundException {
+ private void readObject(ObjectInputStream in) throws IOException {
hash = in.readInt();
int len = in.readInt();
byte[] d = new byte[len];
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebSession.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebSession.java
index 4fb2743..151d7aa 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebSession.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebSession.java
@@ -70,7 +70,7 @@
protected void configure() {
final TypeLiteral<Cache<ActiveSession.Key, ActiveSession>> type =
new TypeLiteral<Cache<ActiveSession.Key, ActiveSession>>() {};
- core(type, CACHE_NAME) //
+ cache(type, CACHE_NAME) //
.memoryLimit(1024) // reasonable default for many sites
.maxAge(12, HOURS) // expire sessions if they are inactive
.evictionPolicy(EvictionPolicy.LRU) // keep most recently used
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/StarredChangesCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/StarredChangesCacheImpl.java
index 2aa8db0..bfc8e64 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/StarredChangesCacheImpl.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/StarredChangesCacheImpl.java
@@ -58,12 +58,12 @@
protected void configure() {
final TypeLiteral<Cache<Account.Id, StarredChangeList>> byAccountIdType =
new TypeLiteral<Cache<Account.Id, StarredChangeList>>() {};
- core(byAccountIdType, BY_ACCOUNT_ID).populateWith(
+ cache(byAccountIdType, BY_ACCOUNT_ID).populateWith(
ByAccountIdLoader.class);
final TypeLiteral<Cache<Change.Id, StarredChangeList>> byChangeIdType =
new TypeLiteral<Cache<Change.Id, StarredChangeList>>() {};
- core(byChangeIdType, BY_CHANGE_ID).populateWith(ByChangeIdLoader.class);
+ cache(byChangeIdType, BY_CHANGE_ID).populateWith(ByChangeIdLoader.class);
bind(StarredChangesCacheImpl.class);
bind(StarredChangesCache.class).to(StarredChangesCacheImpl.class);
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountAgreementsCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountAgreementsCacheImpl.java
index 1918ee5..3463ed6 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountAgreementsCacheImpl.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountAgreementsCacheImpl.java
@@ -55,7 +55,7 @@
protected void configure() {
final TypeLiteral<Cache<Account.Id, AccountAgreementsList>> byAccountIdType =
new TypeLiteral<Cache<Account.Id, AccountAgreementsList>>() {};
- core(byAccountIdType, BY_ACCOUNT_ID).populateWith(
+ cache(byAccountIdType, BY_ACCOUNT_ID).populateWith(
ByAccountIdLoader.class);
bind(AccountAgreementsCacheImpl.class);
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountCacheImpl.java
index 216ec22..5bd7886 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountCacheImpl.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountCacheImpl.java
@@ -57,15 +57,15 @@
protected void configure() {
final TypeLiteral<Cache<Account.Id, AccountState>> byIdType =
new TypeLiteral<Cache<Account.Id, AccountState>>() {};
- core(byIdType, BYID_NAME).populateWith(StateLoader.class);
+ cache(byIdType, BYID_NAME).populateWith(StateLoader.class);
final TypeLiteral<Cache<AccountExternalId.Key, AccountExternalId>> byKeyType =
new TypeLiteral<Cache<AccountExternalId.Key, AccountExternalId>>() {};
- core(byKeyType, BYEXT_NAME).populateWith(ExtLoader.class);
+ cache(byKeyType, BYEXT_NAME).populateWith(ExtLoader.class);
final TypeLiteral<Cache<Email, AccountIdSet>> type =
new TypeLiteral<Cache<Email, AccountIdSet>>() {};
- core(type, BYEMAIL_NAME).populateWith(EmailLoader.class);
+ cache(type, BYEMAIL_NAME).populateWith(EmailLoader.class);
bind(AccountCacheImpl.class);
bind(AccountCache.class).to(AccountCacheImpl.class);
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountDiffPreferencesCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountDiffPreferencesCacheImpl.java
index 713ef6b..b54f50c 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountDiffPreferencesCacheImpl.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountDiffPreferencesCacheImpl.java
@@ -18,7 +18,6 @@
import com.google.gerrit.reviewdb.Account;
import com.google.gerrit.reviewdb.AccountDiffPreference;
import com.google.gerrit.reviewdb.ReviewDb;
-import com.google.gerrit.reviewdb.Account.Id;
import com.google.gerrit.server.cache.Cache;
import com.google.gerrit.server.cache.CacheModule;
import com.google.gerrit.server.cache.EntryCreator;
@@ -40,7 +39,7 @@
protected void configure() {
final TypeLiteral<Cache<Account.Id, AccountDiffPreference>> byAccountIdType =
new TypeLiteral<Cache<Account.Id, AccountDiffPreference>>() {};
- core(byAccountIdType, BY_ACCOUNT_ID).populateWith(
+ cache(byAccountIdType, BY_ACCOUNT_ID).populateWith(
ByAccountIdLoader.class);
bind(AccountDiffPreferencesCacheImpl.class);
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountGroupAgreementsCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountGroupAgreementsCacheImpl.java
index bfa7cc1..9f5ce62 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountGroupAgreementsCacheImpl.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountGroupAgreementsCacheImpl.java
@@ -57,7 +57,7 @@
protected void configure() {
final TypeLiteral<Cache<AccountGroup.Id, AccountGroupAgreementList>> byGroupIdType =
new TypeLiteral<Cache<AccountGroup.Id, AccountGroupAgreementList>>() {};
- core(byGroupIdType, BY_GROUP_ID).populateWith(ByGroupIdLoader.class);
+ cache(byGroupIdType, BY_GROUP_ID).populateWith(ByGroupIdLoader.class);
bind(AccountGroupAgreementsCacheImpl.class);
bind(AccountGroupAgreementsCache.class).to(
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountProjectWatchCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountProjectWatchCacheImpl.java
index 04d3cc4..c683031 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountProjectWatchCacheImpl.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountProjectWatchCacheImpl.java
@@ -58,12 +58,12 @@
protected void configure() {
final TypeLiteral<Cache<Account.Id, AccountProjectWatchList>> byAccountIdType =
new TypeLiteral<Cache<Account.Id, AccountProjectWatchList>>() {};
- core(byAccountIdType, BY_ACCOUNT_ID).populateWith(
+ cache(byAccountIdType, BY_ACCOUNT_ID).populateWith(
ByAccountIdLoader.class);
final TypeLiteral<Cache<Project.NameKey, AccountProjectWatchList>> byProjectNameType =
new TypeLiteral<Cache<Project.NameKey, AccountProjectWatchList>>() {};
- core(byProjectNameType, BY_PROJECT_NAME).populateWith(
+ cache(byProjectNameType, BY_PROJECT_NAME).populateWith(
ByProjectNameLoader.class);
bind(AccountProjectWatchCacheImpl.class);
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/GroupCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/GroupCacheImpl.java
index f4db830..b3a858a 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/GroupCacheImpl.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/GroupCacheImpl.java
@@ -46,15 +46,15 @@
protected void configure() {
final TypeLiteral<Cache<AccountGroup.Id, AccountGroup>> byId =
new TypeLiteral<Cache<AccountGroup.Id, AccountGroup>>() {};
- core(byId, BYID_NAME).populateWith(ByIdLoader.class);
+ cache(byId, BYID_NAME).populateWith(ByIdLoader.class);
final TypeLiteral<Cache<AccountGroup.NameKey, AccountGroup>> byName =
new TypeLiteral<Cache<AccountGroup.NameKey, AccountGroup>>() {};
- core(byName, BYNAME_NAME).populateWith(ByNameLoader.class);
+ cache(byName, BYNAME_NAME).populateWith(ByNameLoader.class);
final TypeLiteral<Cache<AccountGroup.ExternalNameKey, AccountGroupCollection>> byExternalName =
new TypeLiteral<Cache<AccountGroup.ExternalNameKey, AccountGroupCollection>>() {};
- core(byExternalName, BYEXT_NAME) //
+ cache(byExternalName, BYEXT_NAME) //
.populateWith(ByExternalNameLoader.class);
bind(GroupCacheImpl.class);
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/LdapModule.java b/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/LdapModule.java
index 810df28..d16b635 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/LdapModule.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/LdapModule.java
@@ -34,12 +34,12 @@
protected void configure() {
final TypeLiteral<Cache<String, Set<AccountGroup.Id>>> groups =
new TypeLiteral<Cache<String, Set<AccountGroup.Id>>>() {};
- core(groups, GROUP_CACHE).maxAge(1, HOURS) //
+ cache(groups, GROUP_CACHE).maxAge(1, HOURS) //
.populateWith(LdapRealm.MemberLoader.class);
final TypeLiteral<Cache<String, Account.Id>> usernames =
new TypeLiteral<Cache<String, Account.Id>>() {};
- core(usernames, USERNAME_CACHE) //
+ cache(usernames, USERNAME_CACHE) //
.populateWith(LdapRealm.UserLoader.class);
bind(Realm.class).to(LdapRealm.class).in(Scopes.SINGLETON);
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/cache/CacheModule.java b/gerrit-server/src/main/java/com/google/gerrit/server/cache/CacheModule.java
index 0c520c7..c185f7c 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/cache/CacheModule.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/cache/CacheModule.java
@@ -22,8 +22,6 @@
import com.google.inject.internal.UniqueAnnotations;
import com.google.inject.name.Names;
-import java.io.Serializable;
-
/**
* Miniature DSL to support binding {@link Cache} instances in Guice.
*/
@@ -38,9 +36,9 @@
* @return binding to describe the cache. Caller must set at least the name on
* the returned binding.
*/
- protected <K, V> UnnamedCacheBinding<K, V> core(
+ protected <K, V> UnnamedCacheBinding<K, V> cache(
final TypeLiteral<Cache<K, V>> type) {
- return core(Key.get(type), type);
+ return cache(Key.get(type), type);
}
/**
@@ -53,54 +51,15 @@
* and with {@code @Named} annotations.
* @return binding to describe the cache.
*/
- protected <K, V> NamedCacheBinding<K, V> core(
+ protected <K, V> NamedCacheBinding<K, V> cache(
final TypeLiteral<Cache<K, V>> type, final String name) {
- return core(Key.get(type, Names.named(name)), type).name(name);
+ return cache(Key.get(type, Names.named(name)), type).name(name);
}
- private <K, V> UnnamedCacheBinding<K, V> core(final Key<Cache<K, V>> key,
+ private <K, V> UnnamedCacheBinding<K, V> cache(final Key<Cache<K, V>> key,
final TypeLiteral<Cache<K, V>> type) {
final boolean disk = false;
- final CacheProvider<K, V> b = new CacheProvider<K, V>(disk, this, type);
- bind(key).toProvider(b).in(Scopes.SINGLETON);
- return b;
- }
-
- /**
- * Declare an unnamed in-memory/on-disk cache.
- *
- * @param <K> type of key used to find entries, must be {@link Serializable}.
- * @param <V> type of value stored by the cache, must be {@link Serializable}.
- * @param type type literal for the cache, this literal will be used to match
- * injection sites. Injection sites are matched by this type literal
- * and with {@code @Named} annotations.
- * @return binding to describe the cache. Caller must set at least the name on
- * the returned binding.
- */
- protected <K extends Serializable, V extends Serializable> UnnamedCacheBinding<K, V> disk(
- final TypeLiteral<Cache<K, V>> type) {
- return disk(Key.get(type), type);
- }
-
- /**
- * Declare a named in-memory/on-disk cache.
- *
- * @param <K> type of key used to find entries, must be {@link Serializable}.
- * @param <V> type of value stored by the cache, must be {@link Serializable}.
- * @param type type literal for the cache, this literal will be used to match
- * injection sites. Injection sites are matched by this type literal
- * and with {@code @Named} annotations.
- * @return binding to describe the cache.
- */
- protected <K extends Serializable, V extends Serializable> NamedCacheBinding<K, V> disk(
- final TypeLiteral<Cache<K, V>> type, final String name) {
- return disk(Key.get(type, Names.named(name)), type).name(name);
- }
-
- private <K, V> UnnamedCacheBinding<K, V> disk(final Key<Cache<K, V>> key,
- final TypeLiteral<Cache<K, V>> type) {
- final boolean disk = true;
- final CacheProvider<K, V> b = new CacheProvider<K, V>(disk, this, type);
+ final CacheProvider<K, V> b = new CacheProvider<K, V>(this, type);
bind(key).toProvider(b).in(Scopes.SINGLETON);
return b;
}
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 b4d8d78..72973e1 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
@@ -33,7 +33,6 @@
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;
private int memoryLimit;
private int diskLimit;
private long maxAge;
@@ -46,9 +45,7 @@
private Provider<V> valueProvider;
@SuppressWarnings("unchecked")
- CacheProvider(final boolean disk, CacheModule module,
- TypeLiteral<Cache<K, V>> typeLiteral) {
- this.disk = disk;
+ CacheProvider(CacheModule module, TypeLiteral<Cache<K, V>> typeLiteral) {
this.module = module;
memoryLimit(1024);
@@ -83,10 +80,6 @@
+ " in protobuf format", err);
}
}
-
- if (disk) {
- diskLimit(16384);
- }
}
@Inject
@@ -117,7 +110,7 @@
}
public boolean disk() {
- return disk;
+ return diskLimit() > 0;
}
public int memoryLimit() {
@@ -158,13 +151,6 @@
}
public NamedCacheBinding<K, V> diskLimit(final int objects) {
- if (!disk) {
- // TODO This should really be a compile time type error, but I'm
- // too lazy to create the mess of permutations required to setup
- // type safe returns for bindings in our little DSL.
- //
- throw new IllegalStateException("Cache is not disk based");
- }
diskLimit = objects;
return this;
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchList.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchList.java
index 67a041b..cd39e1f 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchList.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchList.java
@@ -15,15 +15,6 @@
package com.google.gerrit.server.patch;
-import static com.google.gerrit.server.ioutil.BasicSerialization.readBytes;
-import static com.google.gerrit.server.ioutil.BasicSerialization.readVarInt32;
-import static com.google.gerrit.server.ioutil.BasicSerialization.writeBytes;
-import static com.google.gerrit.server.ioutil.BasicSerialization.writeVarInt32;
-import static org.eclipse.jgit.lib.ObjectIdSerialization.readCanBeNull;
-import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull;
-import static org.eclipse.jgit.lib.ObjectIdSerialization.writeCanBeNull;
-import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull;
-
import com.google.gerrit.reviewdb.Patch;
import com.google.gerrit.reviewdb.PatchSet;
import com.google.gwtorm.client.Column;
@@ -31,24 +22,15 @@
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.InflaterInputStream;
import javax.annotation.Nullable;
-public class PatchList implements Serializable {
- private static final long serialVersionUID = PatchListKey.serialVersionUID;
+public class PatchList {
private static final Comparator<PatchListEntry> PATCH_CMP =
new Comparator<PatchListEntry>() {
@Override
@@ -70,10 +52,10 @@
@Column(id = 4)
protected List<PatchListEntry> patches;
- private transient ObjectId oldId;
- private transient ObjectId newId;
+ private volatile ObjectId oldId;
+ private volatile ObjectId newId;
- protected PatchList(){
+ protected PatchList() {
}
PatchList(@Nullable final AnyObjectId oldId, final AnyObjectId newId,
@@ -91,13 +73,17 @@
/** Old side tree or commit; null only if this is a combined diff. */
@Nullable
public ObjectId getOldId() {
- refreshObjectIds();
+ if (oldId == null && oldIdName != null) {
+ oldId = ObjectId.fromString(oldIdName);
+ }
return oldId;
}
/** New side commit. */
public ObjectId getNewId() {
- refreshObjectIds();
+ if (newId == null) {
+ newId = ObjectId.fromString(newIdName);
+ }
return newId;
}
@@ -154,51 +140,4 @@
}
return -(low + 1);
}
-
- private void writeObject(final ObjectOutputStream output) throws IOException {
- final ByteArrayOutputStream buf = new ByteArrayOutputStream();
- final DeflaterOutputStream out = new DeflaterOutputStream(buf);
- refreshObjectIds();
- try {
- writeCanBeNull(out, oldId);
- writeNotNull(out, newId);
- writeVarInt32(out, intralineDifference ? 1 : 0);
- writeVarInt32(out, patches.size());
- for (PatchListEntry p : patches) {
- p.writeTo(out);
- }
- } finally {
- out.close();
- }
- writeBytes(output, buf.toByteArray());
- }
-
- private void readObject(final ObjectInputStream input) throws IOException {
- final ByteArrayInputStream buf = new ByteArrayInputStream(readBytes(input));
- final InflaterInputStream in = new InflaterInputStream(buf);
- try {
- oldId = readCanBeNull(in);
- newId = readNotNull(in);
- oldIdName = oldId != null ? oldId.name() : null;
- newIdName = newId.name();
- intralineDifference = readVarInt32(in) != 0;
- final int cnt = readVarInt32(in);
- final PatchListEntry[] all = new PatchListEntry[cnt];
- for (int i = 0; i < all.length; i++) {
- all[i] = PatchListEntry.readFrom(in);
- }
- patches = Arrays.asList(all);
- } finally {
- in.close();
- }
- }
-
- private void refreshObjectIds() {
- if (oldId == null && oldIdName != null) {
- oldId = ObjectId.fromString(oldIdName);
- }
- if (newId == null) {
- newId = ObjectId.fromString(newIdName);
- }
- }
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java
index 8a5256d..4f52e2a 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java
@@ -127,8 +127,9 @@
protected void configure() {
final TypeLiteral<Cache<PatchListKey, PatchList>> type =
new TypeLiteral<Cache<PatchListKey, PatchList>>() {};
- disk(type, CACHE_NAME) //
+ cache(type, CACHE_NAME) //
.memoryLimit(128) // very large items, cache only a few
+ .diskLimit(16384) // cache a lot on disk, they are hard to make
.evictionPolicy(EvictionPolicy.LRU) // prefer most recent
.populateWith(Loader.class) //
;
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java
index 893567e..e9d35bb 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java
@@ -14,13 +14,6 @@
package com.google.gerrit.server.patch;
-import static com.google.gerrit.server.ioutil.BasicSerialization.readEnum;
-import static com.google.gerrit.server.ioutil.BasicSerialization.writeEnum;
-import static org.eclipse.jgit.lib.ObjectIdSerialization.readCanBeNull;
-import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull;
-import static org.eclipse.jgit.lib.ObjectIdSerialization.writeCanBeNull;
-import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull;
-
import com.google.gerrit.reviewdb.Project;
import com.google.gerrit.reviewdb.AccountDiffPreference.Whitespace;
import com.google.gwtorm.client.Column;
@@ -28,32 +21,25 @@
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-
import javax.annotation.Nullable;
-public class PatchListKey implements Serializable {
- static final long serialVersionUID = 13L;
-
+public class PatchListKey {
@Column(id = 1)
- protected transient String oldIdName;
+ protected String oldIdName;
@Column(id = 2)
- protected transient String newIdName;
+ protected String newIdName;
@Column(id = 3)
- protected transient char whitespaceCode;
+ protected char whitespaceCode;
- private transient ObjectId oldId;
- private transient ObjectId newId;
- private transient Whitespace whitespace;
+ private volatile ObjectId oldId;
+ private volatile ObjectId newId;
+ private volatile Whitespace whitespace;
transient Project.NameKey projectKey; // not required to form the key
- protected PatchListKey(){
+ protected PatchListKey() {
}
public PatchListKey(final Project.NameKey pk, final AnyObjectId a,
@@ -93,16 +79,14 @@
@Override
public int hashCode() {
- refreshObjectIds();
-
int h = 0;
- if (oldId != null) {
- h = h * 31 + oldId.hashCode();
+ if (oldIdName != null) {
+ h = h * 31 + getOldId().hashCode();
}
- h = h * 31 + newId.hashCode();
- h = h * 31 + getWhitespace().name().hashCode();
+ h = h * 31 + getNewId().hashCode();
+ h = h * 31 + whitespaceCode;
return h;
}
@@ -111,9 +95,10 @@
public boolean equals(final Object o) {
if (o instanceof PatchListKey) {
final PatchListKey k = (PatchListKey) o;
- return oldIdName != null ? oldIdName.equals(k.oldIdName) : k.oldIdName == null //
- && newIdName.equals(k.newIdName) //
- && getWhitespace() == k.getWhitespace();
+ return oldIdName != null ? oldIdName.equals(k.oldIdName)
+ : k.oldIdName == null //
+ && newIdName.equals(k.newIdName) //
+ && getWhitespace() == k.getWhitespace();
}
return false;
}
@@ -134,29 +119,4 @@
n.append("]");
return n.toString();
}
-
- private void writeObject(final ObjectOutputStream out) throws IOException {
- refreshObjectIds();
- writeCanBeNull(out, oldId);
- writeNotNull(out, newId);
- writeEnum(out, getWhitespace());
- }
-
- private void readObject(final ObjectInputStream in) throws IOException {
- oldId = readCanBeNull(in);
- newId = readNotNull(in);
- oldIdName = (oldId != null ? oldId.name() : null);
- newIdName = newId.name();
- whitespace = readEnum(in, Whitespace.values());
- whitespaceCode = whitespace.getCode();
- }
-
- private void refreshObjectIds(){
- if (oldId == null && oldIdName != null) {
- oldId = ObjectId.fromString(oldIdName);
- }
- if (newId == null) {
- newId = ObjectId.fromString(newIdName);
- }
- }
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectCacheImpl.java
index a721090..2099432 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectCacheImpl.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectCacheImpl.java
@@ -44,7 +44,7 @@
protected void configure() {
final TypeLiteral<Cache<Project.NameKey, ProjectState>> type =
new TypeLiteral<Cache<Project.NameKey, ProjectState>>() {};
- core(type, CACHE_NAME).populateWith(Loader.class);
+ cache(type, CACHE_NAME).populateWith(Loader.class);
bind(ProjectCacheImpl.class);
bind(ProjectCache.class).to(ProjectCacheImpl.class);
}
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshKeyCacheImpl.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshKeyCacheImpl.java
index e7d301c..fb4bcef 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshKeyCacheImpl.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshKeyCacheImpl.java
@@ -60,7 +60,7 @@
protected void configure() {
final TypeLiteral<Cache<Username, EntryList>> type =
new TypeLiteral<Cache<Username, EntryList>>() {};
- core(type, CACHE_NAME).populateWith(Loader.class);
+ cache(type, CACHE_NAME).populateWith(Loader.class);
bind(SshKeyCacheImpl.class);
bind(SshKeyCache.class).to(SshKeyCacheImpl.class);
}