Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions chill-java/src/main/java/com/twitter/chill/ClassRegistrar.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ public ClassRegistrar(Class<T> cls) {

@Override
public boolean equals(Object that) {
if(null == that) {
return false;
}
else if(that instanceof ClassRegistrar) {
return klass.equals(((ClassRegistrar)that).klass);
}
else {
return false;
if (that instanceof ClassRegistrar<?> other) {
return klass.equals(other.klass);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,9 @@ public ReflectingDefaultRegistrar(Class<T> cls, Class<? extends Serializer<?>> s

@Override
public boolean equals(Object that) {
if(null == that) {
return false;
}
else if(that instanceof ReflectingDefaultRegistrar) {
return klass.equals(((ReflectingDefaultRegistrar)that).klass) &&
serializerKlass.equals(((ReflectingDefaultRegistrar)that).serializerKlass);
}
else {
return false;
if (that instanceof ReflectingDefaultRegistrar<?> other) {
return klass.equals(other.klass) && serializerKlass.equals(other.serializerKlass);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,9 @@ public void apply(Kryo k) {

@Override
public boolean equals(Object that) {
if(null == that) {
return false;
}
else if(that instanceof ReflectingRegistrar) {
return klass.equals(((ReflectingRegistrar)that).klass) &&
serializerKlass.equals(((ReflectingRegistrar)that).serializerKlass);
}
else {
return false;
if (that instanceof ReflectingRegistrar<?> other) {
return klass.equals(other.klass) && serializerKlass.equals(other.serializerKlass);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,8 @@ static KryoInstantiator reflect(Class<? extends KryoInstantiator> instClass, Con
return instClass.getDeclaredConstructor().newInstance();
}
}
catch(NoSuchMethodException x) {
throw new ConfigurationException(x);
}
catch(InstantiationException x) {
throw new ConfigurationException(x);
}
catch(IllegalAccessException x) {
throw new ConfigurationException(x);
}
catch(InvocationTargetException x) {
catch (NoSuchMethodException | InstantiationException |
IllegalAccessException | InvocationTargetException x) {
throw new ConfigurationException(x);
}
}
Expand Down Expand Up @@ -153,17 +145,10 @@ protected static String serialize(Kryo k, KryoInstantiator ki) {
return Base64.encodeBytes(out.toBytes());
}

/** Simple class to hold the cached copy of the latest kryo instantiator.
* As well as its corresponding base64 encoded data.
/** Simple record to hold the cached copy of the latest kryo instantiator
* along with its corresponding base64 encoded data.
*/
private static class CachedKryoInstantiator {
public final KryoInstantiator kryoInstantiator;
public final String base64Value;
public CachedKryoInstantiator(KryoInstantiator ki, String bv) {
kryoInstantiator = ki;
base64Value = bv;
}
}
private record CachedKryoInstantiator(KryoInstantiator kryoInstantiator, String base64Value) {}

private static CachedKryoInstantiator cachedKryoInstantiator = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,28 @@
import java.util.Map;

/**
* This takes a raw Map and calls toString on the objects before returning them as values
* This takes a Map and calls toString on the objects before returning them as values
*/
public class JavaMapConfig extends Config {

final Map conf;
public JavaMapConfig(Map conf) {
this.conf = conf;
final Map<String, Object> conf;

public JavaMapConfig(Map<String, ?> conf) {
// We need to store as Map<String, Object> to allow put() with String values
this.conf = new java.util.HashMap<>(conf);
}

public JavaMapConfig() {
this(new java.util.HashMap<String, String>());
this.conf = new java.util.HashMap<>();
}
/** Return null if this key is undefined */

/** Return null if this key is undefined */
@Override
public String get(String key) {
Object value = conf.get(key);
if(null != value) {
return value.toString();
}
else {
return null;
}
return value != null ? value.toString() : null;
}

@Override
public void set(String key, String value) {
conf.put(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ public ReflectingInstantiator(Config conf) throws ConfigurationException {
// Make sure we can make a newKryo, this throws a runtime exception if not.
newKryoWithEx();
}
catch(ClassNotFoundException x) { throw new ConfigurationException(x); }
catch(InstantiationException x) { throw new ConfigurationException(x); }
catch(IllegalAccessException x) { throw new ConfigurationException(x); }
catch(NoSuchMethodException x) { throw new ConfigurationException(x); }
catch(java.lang.reflect.InvocationTargetException x) { throw new ConfigurationException(x); }
catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
NoSuchMethodException | InvocationTargetException x) {
throw new ConfigurationException(x);
}
}

/** Create an instance using the defaults for non-listed params */
Expand Down Expand Up @@ -92,12 +91,12 @@ public ReflectingInstantiator(Class<? extends Kryo> kryoClass,
this.regRequired = regRequired;
this.skipMissing = skipMissing;

this.registrations = new ArrayList<IKryoRegistrar>();
for(IKryoRegistrar cr: classRegistrations) { this.registrations.add(cr); }
for(IKryoRegistrar rr: registrations) { this.registrations.add(rr); }
this.registrations = new ArrayList<>();
for (IKryoRegistrar cr : classRegistrations) { this.registrations.add(cr); }
for (IKryoRegistrar rr : registrations) { this.registrations.add(rr); }

defaultRegistrations = new ArrayList<ReflectingDefaultRegistrar>();
for(ReflectingDefaultRegistrar rdr: defaults) { defaultRegistrations.add(rdr); }
defaultRegistrations = new ArrayList<>();
for (ReflectingDefaultRegistrar rdr : defaults) { defaultRegistrations.add(rdr); }
}

public void set(Config conf) throws ConfigurationException {
Expand Down Expand Up @@ -131,10 +130,10 @@ public Kryo newKryo() {
try {
return newKryoWithEx();
}
catch(InstantiationException x) { throw new RuntimeException(x); }
catch(IllegalAccessException x) { throw new RuntimeException(x); }
catch(NoSuchMethodException x) { throw new RuntimeException(x); }
catch(java.lang.reflect.InvocationTargetException x) { throw new RuntimeException(x); }
catch (InstantiationException | IllegalAccessException |
NoSuchMethodException | InvocationTargetException x) {
throw new RuntimeException(x);
}
}

/** All keys are prefixed with this string */
Expand Down Expand Up @@ -192,7 +191,7 @@ public Kryo newKryo() {

protected List<? extends IKryoRegistrar> buildRegistrars(String base, boolean isAddDefault)
throws ConfigurationException {
List<IKryoRegistrar> builder = new ArrayList<IKryoRegistrar>();
List<IKryoRegistrar> builder = new ArrayList<>();

if (base == null)
return builder;
Expand Down Expand Up @@ -240,19 +239,13 @@ protected String registrarsToString(Iterable<? extends IKryoRegistrar> registrar
builder.append(":");
isFirst = false;
String part = null;
if(reg instanceof ClassRegistrar) {
ClassRegistrar r = (ClassRegistrar)reg;
if (reg instanceof ClassRegistrar<?> r) {
part = r.getRegisteredClass().getName();
}
else if(reg instanceof ReflectingRegistrar) {
ReflectingRegistrar r = (ReflectingRegistrar)reg;
} else if (reg instanceof ReflectingRegistrar<?> r) {
part = r.getRegisteredClass().getName() + "," + r.getSerializerClass().getName();
}
else if(reg instanceof ReflectingDefaultRegistrar) {
ReflectingDefaultRegistrar r = (ReflectingDefaultRegistrar)reg;
} else if (reg instanceof ReflectingDefaultRegistrar<?> r) {
part = r.getRegisteredClass().getName() + "," + r.getSerializerClass().getName();
}
else {
} else {
throw new ConfigurationException("Unknown type of reflecting registrar: " + reg.getClass().getName());
}
builder.append(part);
Expand All @@ -269,21 +262,15 @@ public int hashCode() {

@Override
public boolean equals(Object that) {
if(null == that) {
return false;
}
else if(that instanceof ReflectingInstantiator) {
ReflectingInstantiator thatri = (ReflectingInstantiator)that;
return (regRequired == thatri.regRequired) &&
(skipMissing == thatri.skipMissing) &&
kryoClass.equals(thatri.kryoClass) &&
instStratClass.equals(thatri.instStratClass) &&
registrations.equals(thatri.registrations) &&
defaultRegistrations.equals(thatri.defaultRegistrations);
}
else {
return false;
if (that instanceof ReflectingInstantiator other) {
return regRequired == other.regRequired &&
skipMissing == other.skipMissing &&
kryoClass.equals(other.kryoClass) &&
instStratClass.equals(other.instStratClass) &&
registrations.equals(other.registrations) &&
defaultRegistrations.equals(other.defaultRegistrations);
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void write(Kryo kryo, Output output, IterableRegistrar obj) {
kryo.writeClassAndObject(output, null);
}
public IterableRegistrar read(Kryo kryo, Input input, Class<IterableRegistrar> type) {
ArrayList<IKryoRegistrar> krs = new ArrayList<IKryoRegistrar>();
var krs = new ArrayList<IKryoRegistrar>();
IKryoRegistrar thisKr = (IKryoRegistrar)kryo.readClassAndObject(input);
while(thisKr != null) {
krs.add(thisKr);
Expand Down