Skip to content

Commit 03edf19

Browse files
committed
Restore KryoSeializer readObject(); Save before post working functionality slight refactor
1 parent cf5f4e2 commit 03edf19

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/main/java/org/numenta/nupic/network/CheckPointer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
*
5353
* @param <T> a {@link Network}
5454
*/
55+
@FunctionalInterface
5556
public interface CheckPointer<T> {
5657
/**
5758
* Registers the Observer for a single notification following the checkPoint

src/main/java/org/numenta/nupic/network/KryoSerializer.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package org.numenta.nupic.network;
22

3+
import java.io.IOException;
4+
import java.io.ObjectInputStream;
35
import java.io.Serializable;
46

57
import org.numenta.nupic.Persistable;
68
import org.nustaq.serialization.FSTConfiguration;
79
import org.nustaq.serialization.FSTObjectInput;
10+
import org.nustaq.serialization.FSTObjectOutput;
811

912
import com.esotericsoftware.kryo.Kryo;
1013
import com.esotericsoftware.kryo.KryoException;
@@ -35,6 +38,11 @@ public KryoSerializer(Class<?>... c) {
3538
initFST();
3639
}
3740

41+
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
42+
in.defaultReadObject();
43+
initFST();
44+
}
45+
3846
private void initFST() {
3947
fastSerialConfig = FSTConfiguration.createDefaultConfiguration();
4048
fastSerialConfig.registerClass(classes);
@@ -48,15 +56,16 @@ private void initFST() {
4856
*/
4957
@Override
5058
public void write(Kryo kryo, Output output, T t) {
59+
FSTObjectOutput writer = fastSerialConfig.getObjectOutput(output);
5160
try {
5261
if(t instanceof Persistable) {
5362
((Persistable) t).preSerialize();
5463
}
55-
56-
byte[] bytes = fastSerialConfig.asByteArray(t);
57-
output.write(bytes);
64+
65+
writer.writeObject(t, t.getClass());
66+
writer.flush();
5867
}
59-
catch(Exception e) {
68+
catch(IOException e) {
6069
throw new KryoException(e);
6170
}
6271
}

src/main/java/org/numenta/nupic/network/NetworkSerializerImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ class NetworkSerializerImpl<T extends Persistable> extends Serializer<T> impleme
9191
/** Stores the bytes of the last serialized object or null if there was a problem */
9292
private static AtomicReference<byte[]> lastBytes = new AtomicReference<byte[]>(null);
9393

94-
95-
9694
/**
9795
* All instances in this classloader will share the same atomic reference to the last checkpoint file name holder
9896
* which is perfectly fine.

0 commit comments

Comments
 (0)