Skip to content

Commit 4ea5935

Browse files
committed
fix conflicts
2 parents 8a65e1f + cc0d1dc commit 4ea5935

File tree

75 files changed

+843
-541
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+843
-541
lines changed

simulator/src/main/java/byzzbench/simulator/Client.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
/**
1313
* Represents a client in the system. Each client has a unique identifier.
1414
* The client is responsible for sending requests to the replicas in the system.
15-
*
16-
* @param <T> The type of the entries in the commit log of each {@link Replica}.
1715
*/
1816
@Getter
1917
@RequiredArgsConstructor
20-
public class Client<T extends Serializable> implements Serializable {
18+
public class Client implements Serializable {
2119
/**
2220
* The unique ID of the client.
2321
*/
@@ -27,7 +25,7 @@ public class Client<T extends Serializable> implements Serializable {
2725
* The transport layer for the client.
2826
*/
2927
@JsonIgnore
30-
private final transient Transport<T> transport;
28+
private final transient Transport transport;
3129

3230
private final long maxRequests = 1;
3331

simulator/src/main/java/byzzbench/simulator/LeaderBasedProtocolReplica.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44
import byzzbench.simulator.transport.Transport;
55
import lombok.Getter;
66

7-
import java.io.Serializable;
8-
import java.util.Set;
7+
import java.util.SortedSet;
98

109
/**
1110
* Abstract class for a replica that is part of a leader-based protocol.
12-
*
13-
* @param <T> The type of the entries in the commit log.
1411
*/
1512
@Getter
16-
public abstract class LeaderBasedProtocolReplica<T extends Serializable> extends Replica<T> {
13+
public abstract class LeaderBasedProtocolReplica extends Replica {
1714
private long viewNumber = -1;
1815
private String leaderId;
1916

20-
protected LeaderBasedProtocolReplica(String nodeId, Set<String> nodeIds, Transport<T> transport, CommitLog<T> commitLog) {
17+
protected LeaderBasedProtocolReplica(String nodeId, SortedSet<String> nodeIds, Transport transport, CommitLog commitLog) {
2118
super(nodeId, nodeIds, transport, commitLog);
2219
}
2320

simulator/src/main/java/byzzbench/simulator/Replica.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package byzzbench.simulator;
22

33
import byzzbench.simulator.state.CommitLog;
4+
import byzzbench.simulator.state.LogEntry;
45
import byzzbench.simulator.transport.MessagePayload;
56
import byzzbench.simulator.transport.Transport;
67
import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -12,20 +13,18 @@
1213
import java.security.MessageDigest;
1314
import java.security.NoSuchAlgorithmException;
1415
import java.util.List;
15-
import java.util.Set;
16+
import java.util.SortedSet;
1617

1718
/**
1819
* Superclass for all replicas in the system.
1920
* <p>
2021
* Each replica has a unique node ID, a set of known node IDs in the system, a
2122
* reference to the {@link Transport} layer, and a {@link CommitLog}.
22-
*
23-
* @param <T> The type of the entries in the commit log of each {@link Replica}.
2423
*/
2524
@Log
2625
@Getter
2726
@ToString
28-
public abstract class Replica<T extends Serializable> implements Serializable {
27+
public abstract class Replica implements Serializable {
2928
/**
3029
* The message digest algorithm to use for hashing messages.
3130
*/
@@ -44,7 +43,7 @@ public abstract class Replica<T extends Serializable> implements Serializable {
4443
* The commit log for this replica.
4544
*/
4645
@Getter
47-
private final transient CommitLog<T> commitLog;
46+
private final transient CommitLog commitLog;
4847

4948
/**
5049
* The unique ID of the replica.
@@ -55,13 +54,13 @@ public abstract class Replica<T extends Serializable> implements Serializable {
5554
* The set of known node IDs in the system (excludes client IDs).
5655
*/
5756
@JsonIgnore
58-
private final transient Set<String> nodeIds;
57+
private final transient SortedSet<String> nodeIds;
5958

6059
/**
6160
* The transport layer for this replica.
6261
*/
6362
@JsonIgnore
64-
private final transient Transport<T> transport;
63+
private final transient Transport transport;
6564

6665
/**
6766
* The observers of this replica.
@@ -77,8 +76,8 @@ public abstract class Replica<T extends Serializable> implements Serializable {
7776
* @param transport the transport layer
7877
* @param commitLog the commit log
7978
*/
80-
protected Replica(String nodeId, Set<String> nodeIds, Transport<T> transport,
81-
CommitLog<T> commitLog) {
79+
protected Replica(String nodeId, SortedSet<String> nodeIds, Transport transport,
80+
CommitLog commitLog) {
8281
this.nodeId = nodeId;
8382
this.nodeIds = nodeIds;
8483
this.transport = transport;
@@ -104,7 +103,7 @@ protected void sendMessage(MessagePayload message, String recipient) {
104103
* @param recipients the recipients of the message
105104
*/
106105
protected void multicastMessage(MessagePayload message,
107-
Set<String> recipients) {
106+
SortedSet<String> recipients) {
108107
message.sign(this.nodeId);
109108
this.transport.multicast(this.nodeId, recipients, message);
110109

@@ -116,9 +115,9 @@ protected void multicastMessage(MessagePayload message,
116115
* @param message the message to broadcast
117116
*/
118117
protected void broadcastMessage(MessagePayload message) {
119-
Set<String> otherNodes = this.nodeIds.stream()
118+
SortedSet<String> otherNodes = this.nodeIds.stream()
120119
.filter(otherNodeId -> !otherNodeId.equals(this.nodeId))
121-
.collect(java.util.stream.Collectors.toSet());
120+
.collect(java.util.stream.Collectors.toCollection(java.util.TreeSet::new));
122121

123122
message.sign(this.nodeId);
124123
this.transport.multicast(this.nodeId, otherNodes, message);
@@ -184,7 +183,7 @@ public abstract void handleMessage(String sender, MessagePayload message)
184183
*
185184
* @param operation the operation to commit
186185
*/
187-
public void commitOperation(T operation) {
186+
public void commitOperation(LogEntry operation) {
188187
this.commitLog.add(operation);
189188
this.notifyObserversLocalCommit(operation);
190189
}

simulator/src/main/java/byzzbench/simulator/ScenarioExecutor.java

+26-11
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,35 @@
88
import byzzbench.simulator.state.LivenessPredicate;
99
import byzzbench.simulator.state.adob.AdobDistributedState;
1010
import byzzbench.simulator.transport.Transport;
11+
import com.fasterxml.jackson.databind.JsonNode;
1112
import lombok.Getter;
1213
import lombok.Setter;
1314
import lombok.ToString;
15+
import lombok.extern.java.Log;
1416

15-
import java.io.Serializable;
1617
import java.util.List;
1718
import java.util.Set;
1819
import java.util.function.Predicate;
20+
import java.util.logging.Level;
1921
import java.util.stream.Collectors;
2022

2123
/**
2224
* Abstract class for running a scenario, which consists of a set of {@link
2325
* Replica} and a {@link Transport} layer.
24-
*
25-
* @param <T> The type of the entries in the commit log of each {@link Replica}.
2626
*/
2727
@Getter
2828
@ToString
29-
public abstract class ScenarioExecutor<T extends Serializable> {
29+
@Log
30+
public abstract class ScenarioExecutor {
3031
/**
3132
* The transport layer for the scenario.
3233
*/
3334
@ToString.Exclude
34-
protected final Transport<T> transport;
35+
protected final Transport transport;
3536
/**
3637
* The scheduler for the scenario.
3738
*/
38-
protected final BaseScheduler<T> scheduler;
39+
protected final BaseScheduler scheduler;
3940
/**
4041
* The AdoB oracle for the scenario, which keeps track of the distributed state.
4142
*/
@@ -63,8 +64,8 @@ public abstract class ScenarioExecutor<T extends Serializable> {
6364
*/
6465
protected ScenarioExecutor(String id, MessageMutatorService messageMutatorService, SchedulesService schedulesService) {
6566
this.id = id;
66-
this.transport = new Transport<>(this, messageMutatorService, schedulesService);
67-
this.scheduler = new RandomScheduler<>(messageMutatorService, transport);
67+
this.transport = new Transport(this, schedulesService);
68+
this.scheduler = new RandomScheduler(messageMutatorService, transport);
6869
this.setup();
6970

7071
// AdoB must be initialized after the setup method is called
@@ -79,16 +80,15 @@ public void reset() {
7980
this.setupScenario();
8081
this.adobOracle.reset();
8182
this.runScenario();
82-
System.out.println("Scenario reset");
83-
System.out.println(this);
83+
log.log(Level.INFO,"Scenario reset: %s", this.toString());
8484
}
8585

8686
/**
8787
* Adds a node to the scenario.
8888
*
8989
* @param replica The node to add.
9090
*/
91-
public void addNode(Replica<T> replica) {
91+
public void addNode(Replica replica) {
9292
this.transport.addNode(replica);
9393
replica.addObserver(this.adobOracle);
9494
}
@@ -102,6 +102,21 @@ public final void setupScenario() {
102102
this.setup();
103103
}
104104

105+
public final void loadParameters(JsonNode parameters) {
106+
// get num clients
107+
if (parameters.has("numClients")) {
108+
this.numClients = parameters.get("numClients").asInt();
109+
}
110+
111+
this.loadParameters(parameters);
112+
}
113+
114+
/**
115+
* Loads the parameters for the scenario from a JSON object.
116+
* @param parameters The JSON object containing the parameters for the scenario.
117+
*/
118+
public abstract void loadScenarioParameters(JsonNode parameters);
119+
105120
/**
106121
* Logic to set up the scenario - must be implemented by subclasses.
107122
*/
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package byzzbench.simulator;
22

33

4-
public abstract class TerminationCondition {
4+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
5+
6+
import java.io.Serializable;
7+
8+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
9+
public abstract class TerminationCondition implements Serializable {
510
public abstract boolean shouldTerminate();
611
}

0 commit comments

Comments
 (0)