A Java-based framework for simulating distributed algorithms.
Distributed algorithms are notoriously difficult to prototype and test due to the complexity of networking, threading, and message handling. sim4da abstracts away these concerns, letting you concentrate on your algorithm’s logic. With minimal boilerplate, you can quickly spin up nodes, pass messages, and visualize behavior in a controlled simulation.
-
IS-A Node
Extend theorg.oxoo2a.sim4da.Nodebase class. The framework handles thread creation, message routing, and logging. Override theengage()method to implement your node’s algorithmic steps, using helper methods likesend(),broadcast(), andreceive(). -
HAS-A NetworkConnection
For scenarios where inheritance isn’t ideal, instantiate and manage aNetworkConnectiondirectly:public class CustomAgent { private final NetworkConnection nc = new NetworkConnection("Agent1"); public CustomAgent() { nc.engage(this::runLogic); } private void runLogic() { // send, receive, process messages } }
public class RingNode extends Node {
public RingNode(String name) {
super(name);
}
@Override
protected void engage() {
// send, receive, process token passing
}
}public class Agent {
private final NetworkConnection nc = new NetworkConnection("AgentX");
public Agent() {
nc.engage(this::main);
}
private void main() {
Message msg = nc.receive();
// algorithm logic
}
}By default, a “hidden” logback.xml on the classpath configures DEBUG-level logging for all network activity and node operations. To customize:
- Create your own
logback.xmlinsrc/main/resources/. - Define desired log levels, appenders, and formats.
- The simulator will automatically pick up your configuration instead of the default.
- See
OneRingToRuleThemAllTest.javafor a complete token-passing simulation example. - Review Javadoc comments in
Node.javaandNetworkConnection.javafor detailed API guidance.