KryoNamespace as KryoFactory
Change-Id: I4b78433f08d01619b89f37a961213660a8e3c2db
Showing
1 changed file
with
6 additions
and
4 deletions
| ... | @@ -13,6 +13,7 @@ import com.esotericsoftware.kryo.io.ByteBufferInput; | ... | @@ -13,6 +13,7 @@ import com.esotericsoftware.kryo.io.ByteBufferInput; |
| 13 | import com.esotericsoftware.kryo.io.ByteBufferOutput; | 13 | import com.esotericsoftware.kryo.io.ByteBufferOutput; |
| 14 | import com.esotericsoftware.kryo.io.Input; | 14 | import com.esotericsoftware.kryo.io.Input; |
| 15 | import com.esotericsoftware.kryo.io.Output; | 15 | import com.esotericsoftware.kryo.io.Output; |
| 16 | +import com.esotericsoftware.kryo.pool.KryoFactory; | ||
| 16 | import com.google.common.collect.ImmutableList; | 17 | import com.google.common.collect.ImmutableList; |
| 17 | 18 | ||
| 18 | // TODO Add tests for this class. | 19 | // TODO Add tests for this class. |
| ... | @@ -20,7 +21,7 @@ import com.google.common.collect.ImmutableList; | ... | @@ -20,7 +21,7 @@ import com.google.common.collect.ImmutableList; |
| 20 | * Pool of Kryo instances, with classes pre-registered. | 21 | * Pool of Kryo instances, with classes pre-registered. |
| 21 | */ | 22 | */ |
| 22 | //@ThreadSafe | 23 | //@ThreadSafe |
| 23 | -public final class KryoNamespace { | 24 | +public final class KryoNamespace implements KryoFactory { |
| 24 | 25 | ||
| 25 | /** | 26 | /** |
| 26 | * Default buffer size used for serialization. | 27 | * Default buffer size used for serialization. |
| ... | @@ -116,7 +117,7 @@ public final class KryoNamespace { | ... | @@ -116,7 +117,7 @@ public final class KryoNamespace { |
| 116 | public KryoNamespace populate(int instances) { | 117 | public KryoNamespace populate(int instances) { |
| 117 | List<Kryo> kryos = new ArrayList<>(instances); | 118 | List<Kryo> kryos = new ArrayList<>(instances); |
| 118 | for (int i = 0; i < instances; ++i) { | 119 | for (int i = 0; i < instances; ++i) { |
| 119 | - kryos.add(newKryoInstance()); | 120 | + kryos.add(create()); |
| 120 | } | 121 | } |
| 121 | pool.addAll(kryos); | 122 | pool.addAll(kryos); |
| 122 | return this; | 123 | return this; |
| ... | @@ -130,7 +131,7 @@ public final class KryoNamespace { | ... | @@ -130,7 +131,7 @@ public final class KryoNamespace { |
| 130 | public Kryo getKryo() { | 131 | public Kryo getKryo() { |
| 131 | Kryo kryo = pool.poll(); | 132 | Kryo kryo = pool.poll(); |
| 132 | if (kryo == null) { | 133 | if (kryo == null) { |
| 133 | - return newKryoInstance(); | 134 | + return create(); |
| 134 | } | 135 | } |
| 135 | return kryo; | 136 | return kryo; |
| 136 | } | 137 | } |
| ... | @@ -235,7 +236,8 @@ public final class KryoNamespace { | ... | @@ -235,7 +236,8 @@ public final class KryoNamespace { |
| 235 | * | 236 | * |
| 236 | * @return Kryo instance | 237 | * @return Kryo instance |
| 237 | */ | 238 | */ |
| 238 | - private Kryo newKryoInstance() { | 239 | + @Override |
| 240 | + public Kryo create() { | ||
| 239 | Kryo kryo = new Kryo(); | 241 | Kryo kryo = new Kryo(); |
| 240 | kryo.setRegistrationRequired(registrationRequired); | 242 | kryo.setRegistrationRequired(registrationRequired); |
| 241 | for (Pair<Class<?>, Serializer<?>> registry : registeredTypes) { | 243 | for (Pair<Class<?>, Serializer<?>> registry : registeredTypes) { | ... | ... |
-
Please register or login to post a comment