neilconway / overlog-paxos

A clean implementation of the Paxos consensus protocol in Overlog, a language for distributed computing.

Changed (Δ1.6 KB):

raw changeset »

src/Main.java (2 lines added, 0 lines removed)

src/PaxosClient.java (28 lines added, 0 lines removed)

src/PerfRunner.java (5 lines added, 22 lines removed)

Up to file-list src/Main.java:

1
1
public class Main {
2
	static final int BASE_PORT = 7000;
3
2
4
    public static void main(String[] args) {
3
5
    	if (args.length != 1)
4
6
    		usage();

Up to file-list src/PaxosClient.java:

1
import jol.core.JolSystem;
2
import jol.types.exception.JolRuntimeException;
3
4
public class PaxosClient extends Thread {
5
	private final int id;
6
	private JolSystem sys;
7
8
	PaxosClient(int id) {
9
		this.id = id;
10
	}
11
12
	public void run() {
13
		try {
14
			this.sys = jol.core.Runtime.create(jol.core.Runtime.DEBUG_ALL,
15
					   System.err, Main.BASE_PORT + this.id);
16
			this.sys.install("paxos", ClassLoader.getSystemResource("olg/ident.olg"));
17
			this.sys.install("paxos", ClassLoader.getSystemResource("olg/election.olg"));
18
			this.sys.install("paxos", ClassLoader.getSystemResource("olg/prepare.olg"));
19
			this.sys.install("paxos", ClassLoader.getSystemResource("olg/propose.olg"));
20
			this.sys.install("paxos", ClassLoader.getSystemResource("olg/insertions.olg"));
21
			this.sys.evaluate();
22
		} catch (JolRuntimeException e) {
23
			throw new RuntimeException(e);
24
		}
25
26
		this.sys.start();
27
	}
28
}

Up to file-list src/PerfRunner.java:

1
1
import java.util.LinkedList;
2
2
import java.util.List;
3
3
4
import jol.core.JolSystem;
5
import jol.types.exception.JolRuntimeException;
6
7
4
public class PerfRunner {
8
	private final static int BASE_PORT = 7000;
9
10
5
	private final int nClients;
11
	private final List<JolSystem> workers;
6
	private final List<PaxosClient> clients;
12
7
13
8
	public PerfRunner(int nClients) {
14
9
		this.nClients = nClients;
15
		this.workers = new LinkedList<JolSystem>();
10
		this.clients = new LinkedList<PaxosClient>();
16
11
17
12
		for (int i = 0; i < this.nClients; i++) {
18
			try {
19
				JolSystem j = jol.core.Runtime.create(jol.core.Runtime.DEBUG_ALL,
20
													  System.err, BASE_PORT + i);
21
				j.install("paxos", ClassLoader.getSystemResource("olg/ident.olg"));
22
				j.install("paxos", ClassLoader.getSystemResource("olg/election.olg"));
23
				j.install("paxos", ClassLoader.getSystemResource("olg/prepare.olg"));
24
				j.install("paxos", ClassLoader.getSystemResource("olg/propose.olg"));
25
				j.install("paxos", ClassLoader.getSystemResource("olg/insertions.olg"));
26
				j.evaluate();
27
				this.workers.add(j);
28
			} catch (JolRuntimeException e) {
29
				throw new RuntimeException(e);
30
			}
13
			this.clients.add(new PaxosClient(i));
31
14
		}
32
15
	}
33
16
34
17
	public void run() {
35
		for (JolSystem sys : this.workers) {
36
			sys.start();
18
		for (PaxosClient c : this.clients) {
19
			c.start();
37
20
		}
38
21
	}
39
22
}