Skip to content

Commit

Permalink
add: doc
Browse files Browse the repository at this point in the history
  • Loading branch information
elblasco committed Jul 30, 2024
1 parent 211c28a commit e58903f
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/it/unitn/disi/ds1/qtop/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

import static it.unitn.disi.ds1.qtop.Utils.*;

/**
* The Client actor is responsible for sending requests to the Nodes in the network. The requests are randomised
* between read and write operations. The Client actor also has the ability to make crash a random Node in the network.
*/
public class Client extends AbstractActor{
private static final Random RAND = new Random();
private static final Logger LOGGER = Logger.getInstance();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/it/unitn/disi/ds1/qtop/Controller.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package it.unitn.disi.ds1.qtop;

/**
* Controller for the simulation.
*/
public class Controller {
private static final Logger LOGGER = Logger.getInstance();
private final Simulation simulation;
Expand All @@ -10,6 +13,14 @@ public Controller(Simulation simulation, UserInterface ui) {
this.ui = ui;
}

/**
* Start the simulation (network), with the given parameters.
* @param numberOfNodes number of nodes
* @param numberOfClients number of clients
* @param decisionTimeout decision timeout
* @param voteTimeout vote timeout
* @param writeTimeout write timeout
*/
public void startSimulation(int numberOfNodes, int numberOfClients, int decisionTimeout, int voteTimeout,
int writeTimeout) {
simulation.start(
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/it/unitn/disi/ds1/qtop/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Logger class to log messages to the console and to files.
*/
public class Logger {

private static Logger instance = null;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/it/unitn/disi/ds1/qtop/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

import static it.unitn.disi.ds1.qtop.Utils.*;

/**
* Node class, it represents a single node in the network. It can be either receiver or coordinator.
* During the election all the nodes become voters.
*/
public class Node extends AbstractActor {
private static final int COUNTDOWN_REFRESH = 10;
private static final Random rand = new Random();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/it/unitn/disi/ds1/qtop/PairsHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import java.util.ArrayList;

/**
* PairsHistory class to store the history of the pairs and the final decision associated to it
*/
public class PairsHistory extends ArrayList<ArrayList<Pair<Integer, Utils.Decision>>> {
public PairsHistory() {
super();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/it/unitn/disi/ds1/qtop/QTop.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package it.unitn.disi.ds1.qtop;

/**
* Main class to start the simulation.
*/
public class QTop{

public static void main(String[] args) {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/it/unitn/disi/ds1/qtop/Simulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import java.util.List;
import java.util.Random;

/**
* Simulation class layer between the UserInterface and the network.
*/
public class Simulation {
private final ActorSystem system;
private final List<ActorRef> group;
Expand All @@ -19,6 +22,15 @@ public Simulation() {
system = ActorSystem.create("qtop");
}

/**
* Start the network with the given parameters.
*
* @param numberOfNodes number of nodes
* @param numberOfClients number of clients
* @param decisionTimeout decision timeout
* @param voteTimeout vote timeout
* @param writeTimeout write timeout
*/
public void start(int numberOfNodes, int numberOfClients, int decisionTimeout, int voteTimeout, int writeTimeout) {
// Set initial number of nodes
this.numberOfNodes = numberOfNodes;
Expand Down Expand Up @@ -71,6 +83,11 @@ public void start(int numberOfNodes, int numberOfClients, int decisionTimeout, i

}

/**
* Add a crash to the network.
*
* @param crashType the type of crash
*/
public void addCrashNode(int crashType) {
int clientId = new Random().nextInt(this.group.size() - this.numberOfNodes) + this.numberOfNodes;
Utils.CrashType crashReason = switch (crashType)
Expand All @@ -93,6 +110,9 @@ public void addCrashNode(int crashType) {
);
}

/**
* Shut down the network.
*/
public void exit() {
logger.log(Utils.LogLevel.INFO, "Simulation terminated");
system.terminate();
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/it/unitn/disi/ds1/qtop/SimulationCallback.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package it.unitn.disi.ds1.qtop;

/**
* SimulationCallback interface to handle the simulation callbacks
*/
public interface SimulationCallback {

/**
* Start the simulation.
*/
void start();

/**
* Display to the user the textual menu.
*/
void clientMenu();

}
3 changes: 3 additions & 0 deletions src/main/java/it/unitn/disi/ds1/qtop/TimeOutManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import java.util.EnumMap;
import java.util.Map;

/**
* TimeOutManager class to manage the timeouts of a Node
*/
public class TimeOutManager extends EnumMap<Utils.TimeOutReason, ArrayList<Pair<Cancellable, Integer>>> {
// Phony map to associate a reason with its specific refresh ratio
private final EnumMap<Utils.TimeOutReason, Integer> customTimeouts;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/it/unitn/disi/ds1/qtop/UserInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.Scanner;

/**
* UserInterface class to manage/generate the user interface.
*/
public class UserInterface implements SimulationCallback {
private Controller controller;

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/it/unitn/disi/ds1/qtop/VotersMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.ArrayList;
import java.util.HashMap;

/**
* Class that represents/handle the voters map.
*/
public class VotersMap extends ArrayList<ArrayList<Utils.VotePair>> {

public VotersMap() {
Expand Down

0 comments on commit e58903f

Please sign in to comment.