Yuta HIGUCHI

Loosen Kryo config only for DistributedIntentStore

Change-Id: Ie3f05e2d894b0d44f7c0ad645b77c65d1f2ce02b
......@@ -30,6 +30,9 @@ import org.onlab.onos.net.intent.IntentStore;
import org.onlab.onos.net.intent.IntentStoreDelegate;
import org.onlab.onos.store.hz.AbstractHazelcastStore;
import org.onlab.onos.store.hz.SMap;
import org.onlab.onos.store.serializers.KryoNamespaces;
import org.onlab.onos.store.serializers.KryoSerializer;
import org.onlab.util.KryoNamespace;
import org.slf4j.Logger;
import java.util.List;
......@@ -61,9 +64,21 @@ public class DistributedIntentStore
@Activate
public void activate() {
// FIXME: We need a way to add serializer for intents which has been plugged-in.
// TODO: As a short term workaround, relax Kryo config to
// registrationRequired=false?
// As a short term workaround, relax Kryo config to
// registrationRequired=false
super.activate();
super.serializer = new KryoSerializer() {
@Override
protected void setupKryoPool() {
serializerPool = KryoNamespace.newBuilder()
.setRegistrationRequired(false)
.register(KryoNamespaces.API)
.build()
.populate(1);
}
};
// TODO: enable near cache, allow read from backup for this IMap
IMap<byte[], byte[]> rawIntents = super.theInstance.getMap("intents");
......
......@@ -56,6 +56,7 @@ public final class KryoNamespace implements KryoFactory {
public static final class Builder {
private final List<Pair<Class<?>, Serializer<?>>> types = new ArrayList<>();
private boolean registrationRequired = true;
/**
* Builds a {@link KryoNamespace} instance.
......@@ -63,7 +64,7 @@ public final class KryoNamespace implements KryoFactory {
* @return KryoNamespace
*/
public KryoNamespace build() {
return new KryoNamespace(types);
return new KryoNamespace(types, registrationRequired);
}
/**
......@@ -101,6 +102,11 @@ public final class KryoNamespace implements KryoFactory {
types.addAll(pool.registeredTypes);
return this;
}
public Builder setRegistrationRequired(boolean registrationRequired) {
this.registrationRequired = registrationRequired;
return this;
}
}
/**
......@@ -116,11 +122,11 @@ public final class KryoNamespace implements KryoFactory {
* Creates a Kryo instance pool.
*
* @param registeredTypes types to register
* @param registrationRequired
*/
private KryoNamespace(final List<Pair<Class<?>, Serializer<?>>> registeredTypes) {
private KryoNamespace(final List<Pair<Class<?>, Serializer<?>>> registeredTypes, boolean registrationRequired) {
this.registeredTypes = ImmutableList.copyOf(registeredTypes);
// always true for now
this.registrationRequired = true;
this.registrationRequired = registrationRequired;
}
/**
......