Skip to content

Commit d30e7e2

Browse files
author
Lukas Molzberger
committed
extended the suspension hook interface
1 parent 3c26438 commit d30e7e2

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/main/java/network/aika/Provider.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ public void save() {
118118
ByteArrayOutputStream baos = new ByteArrayOutputStream();
119119
try (
120120
GZIPOutputStream gzipos = new GZIPOutputStream(baos);
121-
DataOutputStream dos = new DataOutputStream(gzipos);) {
121+
DataOutputStream dos = new DataOutputStream(gzipos)) {
122122

123123
n.write(dos);
124124
} catch (IOException e) {
125125
throw new RuntimeException(e);
126126
}
127127

128-
model.suspensionHook.store(id, n.getLabel(), baos.toByteArray());
128+
model.suspensionHook.store(id, n.getLabel(), n.getModelLabels(), baos.toByteArray());
129129
}
130130
n.modified = false;
131131
}
@@ -138,7 +138,7 @@ private void reactivate() {
138138
ByteArrayInputStream bais = new ByteArrayInputStream(data);
139139
try (
140140
GZIPInputStream gzipis = new GZIPInputStream(bais);
141-
DataInputStream dis = new DataInputStream(gzipis);) {
141+
DataInputStream dis = new DataInputStream(gzipis)) {
142142
n = (T) AbstractNode.read(dis, this);
143143
} catch (IOException e) {
144144
throw new RuntimeException(e);
@@ -152,7 +152,12 @@ private void reactivate() {
152152

153153
@Override
154154
public boolean equals(Object o) {
155-
return id == ((Provider<?>) o).id;
155+
if(o == this) return true;
156+
157+
if(o instanceof Provider<?>) {
158+
return ((Provider<?>) o).id.equals(id);
159+
}
160+
return false;
156161
}
157162

158163

@@ -166,10 +171,7 @@ public String toString() {
166171
return "p(" + id + ":" + (n != null ? n.toString() : "SUSPENDED") + ")";
167172
}
168173

169-
170174
public int compareTo(Provider<?> n) {
171-
if (id < n.id) return -1;
172-
else if (id > n.id) return 1;
173-
else return 0;
175+
return id.compareTo(n.id);
174176
}
175177
}

src/main/java/network/aika/SuspensionHook.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package network.aika;
1818

1919

20+
import java.util.Set;
21+
2022
/**
2123
*
2224
* The suspension hook is used to suspend neurons and logic nodes to an external storage in order to reduce the memory footprint.
@@ -31,7 +33,7 @@ public interface SuspensionHook {
3133

3234
int getNewId();
3335

34-
void store(int id, String label, byte[] data);
36+
void store(int id, String label, Set<String> modelLabels, byte[] data);
3537

3638
byte[] retrieve(int id);
3739

src/test/java/network/aika/network/SuspensionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.junit.Test;
3030

3131
import java.util.Map;
32+
import java.util.Set;
3233
import java.util.TreeMap;
3334
import java.util.concurrent.atomic.AtomicInteger;
3435
import java.util.stream.Collectors;
@@ -149,7 +150,7 @@ public int getNewId() {
149150
}
150151

151152
@Override
152-
public void store(int id, String label, byte[] data) {
153+
public void store(int id, String label, Set<String> modelLabels, byte[] data) {
153154
storage.put(id, data);
154155
}
155156

0 commit comments

Comments
 (0)