KryoNamespace as KryoFactory
Change-Id: I4b78433f08d01619b89f37a961213660a8e3c2db
diff --git a/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java b/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
index 9c5f790..42d801b 100644
--- a/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
+++ b/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
@@ -13,6 +13,7 @@
import com.esotericsoftware.kryo.io.ByteBufferOutput;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
+import com.esotericsoftware.kryo.pool.KryoFactory;
import com.google.common.collect.ImmutableList;
// TODO Add tests for this class.
@@ -20,7 +21,7 @@
* Pool of Kryo instances, with classes pre-registered.
*/
//@ThreadSafe
-public final class KryoNamespace {
+public final class KryoNamespace implements KryoFactory {
/**
* Default buffer size used for serialization.
@@ -116,7 +117,7 @@
public KryoNamespace populate(int instances) {
List<Kryo> kryos = new ArrayList<>(instances);
for (int i = 0; i < instances; ++i) {
- kryos.add(newKryoInstance());
+ kryos.add(create());
}
pool.addAll(kryos);
return this;
@@ -130,7 +131,7 @@
public Kryo getKryo() {
Kryo kryo = pool.poll();
if (kryo == null) {
- return newKryoInstance();
+ return create();
}
return kryo;
}
@@ -235,7 +236,8 @@
*
* @return Kryo instance
*/
- private Kryo newKryoInstance() {
+ @Override
+ public Kryo create() {
Kryo kryo = new Kryo();
kryo.setRegistrationRequired(registrationRequired);
for (Pair<Class<?>, Serializer<?>> registry : registeredTypes) {