60 lines
925 B
Java
60 lines
925 B
Java
package network;
|
|
|
|
import java.io.IOException;
|
|
import java.util.logging.LogManager;
|
|
|
|
import peer.Node;
|
|
|
|
public class Network {
|
|
|
|
/**
|
|
* grow a network: Starting with one peer, repeatedly let peers spawn or
|
|
* leave at random
|
|
*/
|
|
public static void main(String[] args) {
|
|
|
|
System.setProperty("java.util.logging.config.file",
|
|
"logging.properties");
|
|
|
|
try {
|
|
LogManager.getLogManager().readConfiguration();
|
|
}
|
|
|
|
catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
int delay = 2000;
|
|
|
|
Node a = new Node();
|
|
|
|
try {
|
|
Node b = a.spawn();
|
|
Thread.sleep(delay);
|
|
|
|
Node c = a.spawn();
|
|
Thread.sleep(delay);
|
|
|
|
Node d = a.spawn();
|
|
Thread.sleep(delay);
|
|
|
|
a.leave();
|
|
Thread.sleep(delay);
|
|
|
|
b.leave();
|
|
Thread.sleep(delay);
|
|
|
|
c.leave();
|
|
Thread.sleep(delay);
|
|
|
|
d.leave();
|
|
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
}
|