Skip to content

Moving Modelclass method to suspensionCallback #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions core/src/main/java/network/aika/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Model implements Writable {

private long N = 0;

private SuspensionCallback suspensionCallback;
public SuspensionCallback suspensionCallback;
private final AtomicLong retrievalCounter = new AtomicLong(0);
private final AtomicLong thoughtIdCounter = new AtomicLong(0);

Expand Down Expand Up @@ -214,15 +214,6 @@ public void close() throws IOException {
suspensionCallback.close();
}

public Object modelClass(String clazzName) {
try {
Class clazz = getClass().getClassLoader().loadClass(clazzName);
return clazz.getConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public void write(DataOutput out) throws IOException {
out.writeLong(N);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,13 @@ public interface SuspensionCallback {
void loadIndex(Model m);

void saveIndex(Model m) throws IOException;

default Object modelClass(String clazzName, Model model) {
try {
Class clazz = model.getClass().getClassLoader().loadClass(clazzName);
return clazz.getConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public void write(DataOutput out) throws IOException {

public static Neuron read(DataInput in, Model m) throws Exception {
String neuronClazz = in.readUTF();
Neuron n = (Neuron) m.modelClass(neuronClazz);
Neuron n = (Neuron) m.suspensionCallback.modelClass(neuronClazz, m);

n.readFields(in, m);
return n;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public void write(DataOutput out) throws IOException {
public static Synapse read(DataInput in, Model m) throws IOException {
String synClazz = in.readUTF();

Synapse s = (Synapse) m.modelClass(synClazz);
Synapse s = (Synapse) m.suspensionCallback.modelClass(synClazz, m);
s.readFields(in, m);
return s;
}
Expand Down