Loosen Kryo config only for DistributedIntentStore
Change-Id: Ie3f05e2d894b0d44f7c0ad645b77c65d1f2ce02b
Showing
2 changed files
with
27 additions
and
6 deletions
| ... | @@ -30,6 +30,9 @@ import org.onlab.onos.net.intent.IntentStore; | ... | @@ -30,6 +30,9 @@ import org.onlab.onos.net.intent.IntentStore; |
| 30 | import org.onlab.onos.net.intent.IntentStoreDelegate; | 30 | import org.onlab.onos.net.intent.IntentStoreDelegate; |
| 31 | import org.onlab.onos.store.hz.AbstractHazelcastStore; | 31 | import org.onlab.onos.store.hz.AbstractHazelcastStore; |
| 32 | import org.onlab.onos.store.hz.SMap; | 32 | import org.onlab.onos.store.hz.SMap; |
| 33 | +import org.onlab.onos.store.serializers.KryoNamespaces; | ||
| 34 | +import org.onlab.onos.store.serializers.KryoSerializer; | ||
| 35 | +import org.onlab.util.KryoNamespace; | ||
| 33 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
| 34 | 37 | ||
| 35 | import java.util.List; | 38 | import java.util.List; |
| ... | @@ -61,9 +64,21 @@ public class DistributedIntentStore | ... | @@ -61,9 +64,21 @@ public class DistributedIntentStore |
| 61 | @Activate | 64 | @Activate |
| 62 | public void activate() { | 65 | public void activate() { |
| 63 | // FIXME: We need a way to add serializer for intents which has been plugged-in. | 66 | // FIXME: We need a way to add serializer for intents which has been plugged-in. |
| 64 | - // TODO: As a short term workaround, relax Kryo config to | 67 | + // As a short term workaround, relax Kryo config to |
| 65 | - // registrationRequired=false? | 68 | + // registrationRequired=false |
| 66 | super.activate(); | 69 | super.activate(); |
| 70 | + super.serializer = new KryoSerializer() { | ||
| 71 | + | ||
| 72 | + @Override | ||
| 73 | + protected void setupKryoPool() { | ||
| 74 | + serializerPool = KryoNamespace.newBuilder() | ||
| 75 | + .setRegistrationRequired(false) | ||
| 76 | + .register(KryoNamespaces.API) | ||
| 77 | + .build() | ||
| 78 | + .populate(1); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + }; | ||
| 67 | 82 | ||
| 68 | // TODO: enable near cache, allow read from backup for this IMap | 83 | // TODO: enable near cache, allow read from backup for this IMap |
| 69 | IMap<byte[], byte[]> rawIntents = super.theInstance.getMap("intents"); | 84 | IMap<byte[], byte[]> rawIntents = super.theInstance.getMap("intents"); | ... | ... |
| ... | @@ -56,6 +56,7 @@ public final class KryoNamespace implements KryoFactory { | ... | @@ -56,6 +56,7 @@ public final class KryoNamespace implements KryoFactory { |
| 56 | public static final class Builder { | 56 | public static final class Builder { |
| 57 | 57 | ||
| 58 | private final List<Pair<Class<?>, Serializer<?>>> types = new ArrayList<>(); | 58 | private final List<Pair<Class<?>, Serializer<?>>> types = new ArrayList<>(); |
| 59 | + private boolean registrationRequired = true; | ||
| 59 | 60 | ||
| 60 | /** | 61 | /** |
| 61 | * Builds a {@link KryoNamespace} instance. | 62 | * Builds a {@link KryoNamespace} instance. |
| ... | @@ -63,7 +64,7 @@ public final class KryoNamespace implements KryoFactory { | ... | @@ -63,7 +64,7 @@ public final class KryoNamespace implements KryoFactory { |
| 63 | * @return KryoNamespace | 64 | * @return KryoNamespace |
| 64 | */ | 65 | */ |
| 65 | public KryoNamespace build() { | 66 | public KryoNamespace build() { |
| 66 | - return new KryoNamespace(types); | 67 | + return new KryoNamespace(types, registrationRequired); |
| 67 | } | 68 | } |
| 68 | 69 | ||
| 69 | /** | 70 | /** |
| ... | @@ -101,6 +102,11 @@ public final class KryoNamespace implements KryoFactory { | ... | @@ -101,6 +102,11 @@ public final class KryoNamespace implements KryoFactory { |
| 101 | types.addAll(pool.registeredTypes); | 102 | types.addAll(pool.registeredTypes); |
| 102 | return this; | 103 | return this; |
| 103 | } | 104 | } |
| 105 | + | ||
| 106 | + public Builder setRegistrationRequired(boolean registrationRequired) { | ||
| 107 | + this.registrationRequired = registrationRequired; | ||
| 108 | + return this; | ||
| 109 | + } | ||
| 104 | } | 110 | } |
| 105 | 111 | ||
| 106 | /** | 112 | /** |
| ... | @@ -116,11 +122,11 @@ public final class KryoNamespace implements KryoFactory { | ... | @@ -116,11 +122,11 @@ public final class KryoNamespace implements KryoFactory { |
| 116 | * Creates a Kryo instance pool. | 122 | * Creates a Kryo instance pool. |
| 117 | * | 123 | * |
| 118 | * @param registeredTypes types to register | 124 | * @param registeredTypes types to register |
| 125 | + * @param registrationRequired | ||
| 119 | */ | 126 | */ |
| 120 | - private KryoNamespace(final List<Pair<Class<?>, Serializer<?>>> registeredTypes) { | 127 | + private KryoNamespace(final List<Pair<Class<?>, Serializer<?>>> registeredTypes, boolean registrationRequired) { |
| 121 | this.registeredTypes = ImmutableList.copyOf(registeredTypes); | 128 | this.registeredTypes = ImmutableList.copyOf(registeredTypes); |
| 122 | - // always true for now | 129 | + this.registrationRequired = registrationRequired; |
| 123 | - this.registrationRequired = true; | ||
| 124 | } | 130 | } |
| 125 | 131 | ||
| 126 | /** | 132 | /** | ... | ... |
-
Please register or login to post a comment