summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-05-17 14:55:16 +0000
committerPaul Buetow <paul@buetow.org>2008-05-17 14:55:16 +0000
commit271949bf140359dd97cbee9ef927ee9280c9f31f (patch)
tree31cd0e175401d2041e23128402c235eb6d2e3117 /sources
parent5a0924146201bc577ca170952a21a42464ac7c71 (diff)
Vectortimestamps work
Better representation of Lamporttimestamps BerkelyTimeProtocol M trunk/ROADMAP M trunk/sources/prefs/VSPrefs.java M trunk/sources/prefs/VSDefaultPrefs.java M trunk/sources/simulator/VSMain.java M trunk/sources/simulator/VSSimulation.java M trunk/sources/simulator/VSSimulationPanel.java M trunk/sources/utils/VSFrame.java M trunk/sources/utils/VSClassLoader.java M trunk/sources/utils/VSInfoArea.java M trunk/sources/protocols/BroadcastSturmProtocol.java M trunk/sources/protocols/ExternalTimeSyncProtocol.java M trunk/sources/protocols/RegisteredProtocols.java M trunk/sources/protocols/PingPongProtocol.java M trunk/sources/protocols/InternalTimeSyncProtocol.java M trunk/sources/protocols/VSProtocol.java M trunk/sources/protocols/DummyProtocol.java A trunk/sources/protocols/BerkelyTimeProtocol.java M trunk/sources/core/VSLamport.java M trunk/sources/core/VSProcess.java A trunk/sources/core/VSTime.java A trunk/sources/core/VSVectorTime.java M trunk/sources/core/VSTask.java M trunk/sources/core/VSMessage.java M trunk/sources/editors/VSEditor.java M trunk/sources/editors/VSProtocolEditor.java M trunk/sources/editors/VSSimulationEditor.java M trunk/sources/editors/VSEditorFrame.java M trunk/sources/editors/VSProcessEditor.java
Diffstat (limited to 'sources')
-rw-r--r--sources/core/VSLamport.java16
-rw-r--r--sources/core/VSMessage.java6
-rw-r--r--sources/core/VSProcess.java152
-rw-r--r--sources/core/VSTask.java13
-rw-r--r--sources/core/VSTime.java6
-rw-r--r--sources/core/VSVectorTime.java52
-rw-r--r--sources/editors/VSEditor.java6
-rw-r--r--sources/editors/VSEditorFrame.java8
-rw-r--r--sources/editors/VSProcessEditor.java10
-rw-r--r--sources/editors/VSProtocolEditor.java12
-rw-r--r--sources/editors/VSSimulationEditor.java6
-rw-r--r--sources/prefs/VSDefaultPrefs.java11
-rw-r--r--sources/prefs/VSPrefs.java7
-rw-r--r--sources/protocols/BerkelyTimeProtocol.java126
-rw-r--r--sources/protocols/BroadcastSturmProtocol.java2
-rw-r--r--sources/protocols/DummyProtocol.java2
-rw-r--r--sources/protocols/ExternalTimeSyncProtocol.java2
-rw-r--r--sources/protocols/InternalTimeSyncProtocol.java2
-rw-r--r--sources/protocols/PingPongProtocol.java3
-rw-r--r--sources/protocols/RegisteredProtocols.java12
-rw-r--r--sources/protocols/VSProtocol.java23
-rw-r--r--sources/simulator/VSMain.java10
-rw-r--r--sources/simulator/VSSimulation.java21
-rw-r--r--sources/simulator/VSSimulationPanel.java72
-rw-r--r--sources/utils/VSClassLoader.java6
-rw-r--r--sources/utils/VSFrame.java6
-rw-r--r--sources/utils/VSInfoArea.java6
27 files changed, 464 insertions, 134 deletions
diff --git a/sources/core/VSLamport.java b/sources/core/VSLamport.java
index 157aaae..4c4707f 100644
--- a/sources/core/VSLamport.java
+++ b/sources/core/VSLamport.java
@@ -1,19 +1,23 @@
package core;
-public class VSLamport {
- private long time;
+public class VSLamport implements VSTime {
+ private long globalTime;
private long lamportTime;
- public VSLamport(long time, long lamportTime) {
- this.time = time;
+ public VSLamport(long globalTime, long lamportTime) {
+ this.globalTime = globalTime;
this.lamportTime = lamportTime;
}
- public long getTime() {
- return time;
+ public long getGlobalTime() {
+ return globalTime;
}
public long getLamportTime() {
return lamportTime;
}
+
+ public String toString() {
+ return "(" + lamportTime + ")";
+ }
}
diff --git a/sources/core/VSMessage.java b/sources/core/VSMessage.java
index b3c1d31..466fc4d 100644
--- a/sources/core/VSMessage.java
+++ b/sources/core/VSMessage.java
@@ -10,6 +10,7 @@ public class VSMessage extends VSPrefs implements VSEvent {
private long messageID;
private static long messageCounter;
private long lamportTime;
+ private VSVectorTime vectorTime;
public VSMessage(String protocolClassname) {
this.protocolClassname = protocolClassname;
@@ -31,6 +32,7 @@ public class VSMessage extends VSPrefs implements VSEvent {
public void setSendingProcess(VSProcess sendingProcess) {
this.sendingProcess = sendingProcess;
lamportTime = sendingProcess.getLamportTime();
+ vectorTime = sendingProcess.getVectorTime().getCopy();
}
public VSProcess getSendingProcess() {
@@ -41,6 +43,10 @@ public class VSMessage extends VSPrefs implements VSEvent {
return lamportTime;
}
+ public VSVectorTime getVectorTime() {
+ return vectorTime;
+ }
+
public String toString() {
return "ID: " + messageID;
}
diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java
index bb65959..c9002ca 100644
--- a/sources/core/VSProcess.java
+++ b/sources/core/VSProcess.java
@@ -24,15 +24,15 @@ public final class VSProcess extends VSPrefs {
private boolean timeModified;
private double clockOffset;
private float clockVariance;
- private int num;
private int processID;
private long globalTime;
private long localTime;
private static int processCounter;
private boolean isCrashed;
private long lamportTime;
- private ArrayList<VSLamport> lamportTimestamps;
- private ArrayList<Integer> vectorTimestamps;
+ private ArrayList<VSLamport> lamportTimeHistory;
+ private VSVectorTime vectorTime;
+ private ArrayList<VSVectorTime> vectorTimeHistory;
/* This array contains all Integer prefs of the process which should show
* up in the prefs menu! All keys which dont start with "sim." only show
@@ -79,16 +79,13 @@ public final class VSProcess extends VSPrefs {
private static final String DEFAULT_STRING_VALUE_KEYS[] = {
};
- public VSProcess(VSPrefs prefs, VSSimulationPanel simulationPanel, VSLogging logging, int num) {
+ public VSProcess(VSPrefs prefs, VSSimulationPanel simulationPanel, VSLogging logging) {
this.prefs = prefs;
this.simulationPanel = simulationPanel;
this.logging = logging;
- this.num = num;
- this.random = new VSRandom(processID+processCounter);
- this.lamportTimestamps = new ArrayList<VSLamport>();
- this.vectorTimestamps = new ArrayList<Integer>();
- setLamportTime(0);
+ random = new VSRandom(processID+processCounter);
+ initTimeFormats();
setObject("protocols", new ArrayList<VSProtocol>());
isPaused = true;
@@ -110,6 +107,31 @@ public final class VSProcess extends VSPrefs {
createRandomCrashTask();
}
+ private void initTimeFormats() {
+ lamportTime = 0;
+ lamportTimeHistory = new ArrayList<VSLamport>();
+
+ vectorTime = new VSVectorTime(0);
+ vectorTimeHistory = new ArrayList<VSVectorTime>();
+
+ final int numProcesses = simulationPanel.getNumProcesses();
+ for (int i = 0; i < numProcesses; ++i)
+ vectorTime.add(new Long(0));
+ }
+
+ private void resetTimeFormats() {
+ lamportTime = 0;
+ lamportTimeHistory.clear();
+
+ vectorTime = new VSVectorTime(0);
+ vectorTimeHistory.clear();
+
+ final int numProcesses = simulationPanel.getNumProcesses();
+ for (int i = numProcesses; i > 0; --i)
+ vectorTime.add(new Long(0));
+ }
+
+
/**
* Called from the VSProcessEditor, after finishing editing!
*/
@@ -178,9 +200,6 @@ public final class VSProcess extends VSPrefs {
localTime = 0;
globalTime = 0;
clockOffset = 0;
- lamportTime = 0;
- lamportTimestamps.clear();
- vectorTimestamps.clear();
if (objectExists("protocols.registered")) {
Object protocolsObj = getObject("protocols.registered");
@@ -193,6 +212,7 @@ public final class VSProcess extends VSPrefs {
setCurrentColor(getColor("process.default"));
createRandomCrashTask();
+ resetTimeFormats();
}
private void createRandomCrashTask() {
@@ -277,10 +297,6 @@ public final class VSProcess extends VSPrefs {
return crashedColor;
}
- public int getNum() {
- return num;
- }
-
public synchronized boolean timeModified() {
return timeModified;
}
@@ -362,40 +378,83 @@ public final class VSProcess extends VSPrefs {
return isPaused;
}
+ public void increaseLamportTime() {
+ setLamportTime(getLamportTime()+1);
+ }
+
+ public void updateLamportTime(long time) {
+ final long lamportTime = getLamportTime() + 1;
+
+ if (time > lamportTime)
+ setLamportTime(time);
+ else
+ setLamportTime(lamportTime);
+ }
+
public synchronized long getLamportTime() {
return lamportTime;
}
public synchronized void setLamportTime(long lamportTime) {
this.lamportTime = lamportTime;
- lamportTimestamps.add(new VSLamport(globalTime, lamportTime));
+ lamportTimeHistory.add(new VSLamport(globalTime, lamportTime));
}
- public synchronized VSLamport[] getLamportArray() {
- final int size = lamportTimestamps.size();
- final VSLamport[] arr = new VSLamport[size];
+ public synchronized VSTime[] getLamportTimeArray() {
+ final int size = lamportTimeHistory.size();
+ final VSTime[] arr = new VSLamport[size];
for (int i = 0; i < size; ++i)
- arr[i] = lamportTimestamps.get(i);
+ arr[i] = (VSTime) lamportTimeHistory.get(i);
return arr;
}
- public synchronized int[] getVectorTime() {
- final int size = vectorTimestamps.size();
- final int[] arr = new int[size];
+ public synchronized void increaseVectorTime() {
+ vectorTime.set(processID-1, new Long(vectorTime.get(processID-1).longValue()+1));
+ vectorTime.setGlobalTime(globalTime);
+ vectorTimeHistory.add(vectorTime.getCopy());
+ }
+
+ public synchronized void updateVectorTime(VSVectorTime vectorTimeUpdate) {
+ final int size = vectorTime.size();
+
+ for (int i = 0; i < size; ++i) {
+ if (i == processID-1)
+ vectorTime.set(i, new Long(vectorTime.get(i).longValue()+1));
+ else if (vectorTimeUpdate.get(i) > vectorTime.get(i))
+ vectorTime.set(i, vectorTimeUpdate.get(i));
+ }
+
+ vectorTime.setGlobalTime(globalTime);
+ vectorTimeHistory.add(vectorTime.getCopy());
+ }
+
+ public synchronized VSVectorTime getVectorTime() {
+ return vectorTime;
+ }
+
+ public synchronized VSTime[] getVectorTimeArray() {
+ final int size = vectorTimeHistory.size();
+ final VSTime[] arr = new VSTime[size];
for (int i = 0; i < size; ++i)
- arr[i] = vectorTimestamps.get(i);
+ arr[i] = (VSTime) vectorTimeHistory.get(i);
return arr;
}
-
public void sendMessage(VSMessage message) {
- logg(prefs.getString("lang.message.sent") + "; "
- + prefs.getString("lang.protocol") + ": " + message.getProtocolName() + "; "
- + prefs.getString("lang.message") + " " + message.toStringFull());
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(prefs.getString("lang.message.sent"));
+ buffer.append("; ");
+ buffer.append(prefs.getString("lang.protocol"));
+ buffer.append(": " + message.getProtocolName());
+ buffer.append("; ");
+ buffer.append(prefs.getString("lang.message"));
+ buffer.append(" ");
+ buffer.append(message.toStringFull());
+ logg(buffer.toString());
simulationPanel.sendMessage(message);
}
@@ -412,20 +471,39 @@ public final class VSProcess extends VSPrefs {
}
public String toString() {
- return
- prefs.getString("lang.process.id") + ": "
- + getProcessID() + "; "
- + prefs.getString("lang.process.time.local") + ": "
- + VSTools.getTimeString(getTime())
- + "; Lamport: " + lamportTime;
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(prefs.getString("lang.process.id"));
+ buffer.append(": ");
+ buffer.append(getProcessID());
+ buffer.append("; ");
+ buffer.append(prefs.getString("lang.process.time.local"));
+ buffer.append(": ");
+ buffer.append(VSTools.getTimeString(getTime()));
+ buffer.append("; ");
+ buffer.append(prefs.getString("lang.time.lamport"));
+ buffer.append(": ");
+ buffer.append(lamportTime);
+ buffer.append("; ");
+ buffer.append(prefs.getString("lang.time.vector"));
+ buffer.append(": ");
+ buffer.append(vectorTime);
+ return buffer.toString();
}
public String toStringFull() {
- return toString() + "; paused: " + isPaused + "; crashed: " + isCrashed + "; crashTask: " + randomCrashTask;
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(toString());
+ buffer.append("; paused: ");
+ buffer.append(isPaused);
+ buffer.append("; crashed: ");
+ buffer.append(isCrashed);
+ buffer.append("; crashTask: ");
+ buffer.append(randomCrashTask);
+ return buffer.toString();
}
public boolean equals(VSProcess process) {
- return process.getNum() == getNum();
+ return process.getProcessID() == processID;
}
public VSSimulationPanel getSimulationPanel() {
diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java
index 43b0265..26b2485 100644
--- a/sources/core/VSTask.java
+++ b/sources/core/VSTask.java
@@ -84,13 +84,8 @@ public class VSTask implements Comparable {
final String protocolName = message.getProtocolName();
final String protocolClassname = message.getProtocolClassname();
- final long recvLamportTime = message.getLamportTime() + 1;
- final long lamportTime = process.getLamportTime() + 1;
-
- if (recvLamportTime > lamportTime)
- process.setLamportTime(recvLamportTime);
- else
- process.setLamportTime(lamportTime);
+ process.updateLamportTime(message.getLamportTime()+1);
+ process.updateVectorTime(message.getVectorTime());
Object protocolObj;
@@ -120,10 +115,6 @@ public class VSTask implements Comparable {
private void onProcessEventStart() {
final VSProcessEvent processEvent = (VSProcessEvent) event;
processEvent.onStart(process);
- /*
- if (process.isCrashed())
- process.setLamportTime(process.getLamportTime()-1);
- */
}
public long getTaskTime() {
diff --git a/sources/core/VSTime.java b/sources/core/VSTime.java
new file mode 100644
index 0000000..f35c0dd
--- /dev/null
+++ b/sources/core/VSTime.java
@@ -0,0 +1,6 @@
+package core;
+
+public interface VSTime {
+ public long getGlobalTime();
+ public String toString();
+}
diff --git a/sources/core/VSVectorTime.java b/sources/core/VSVectorTime.java
new file mode 100644
index 0000000..70a62a2
--- /dev/null
+++ b/sources/core/VSVectorTime.java
@@ -0,0 +1,52 @@
+package core;
+
+import java.util.ArrayList;
+
+public class VSVectorTime extends ArrayList<Long> implements VSTime {
+ /* Only needed for painting in the painting panel */
+ private long globalTime;
+
+ public VSVectorTime(long globalTime) {
+ this.globalTime = globalTime;
+ }
+
+ public long[] toLongArray() {
+ final int size = super.size();
+ final long[] arr = new long[size];
+
+ for (int i = 0; i < size; ++i)
+ arr[i] = super.get(i).longValue();
+
+ return arr;
+ }
+
+ public void setGlobalTime(long globalTime) {
+ this.globalTime = globalTime;
+ }
+
+ public long getGlobalTime() {
+ return globalTime;
+ }
+
+ public VSVectorTime getCopy() {
+ final VSVectorTime vectorTime = new VSVectorTime(globalTime);
+ final int size = super.size();
+
+ for (int i = 0; i < size; ++i)
+ vectorTime.add(super.get(i));
+
+ return vectorTime;
+ }
+
+ public String toString() {
+ final int size = super.size();
+ final StringBuffer buffer = new StringBuffer();
+ buffer.append("(");
+
+ for (int i = 0; i < size-1; ++i)
+ buffer.append(super.get(i)+",");
+ buffer.append(super.get(size-1)+")");
+
+ return buffer.toString();
+ }
+}
diff --git a/sources/editors/VSEditor.java b/sources/editors/VSEditor.java
index 074bfd4..a81300d 100644
--- a/sources/editors/VSEditor.java
+++ b/sources/editors/VSEditor.java
@@ -38,14 +38,14 @@ abstract class VSEditor implements ActionListener {
protected Insets insets = new Insets(0, 0, 0, 0);
public VSEditor(VSPrefs prefs, VSPrefs prefsToEdit) {
- initialize(prefs, prefsToEdit, SIMULATION_PREFERENCES);
+ init(prefs, prefsToEdit, SIMULATION_PREFERENCES);
}
public VSEditor(VSPrefs prefs, VSPrefs prefsToEdit, int prefsCategory) {
- initialize(prefs, prefsToEdit, prefsCategory);
+ init(prefs, prefsToEdit, prefsCategory);
}
- private void initialize(VSPrefs prefs, VSPrefs prefsToEdit, int prefsCategory) {
+ private void init(VSPrefs prefs, VSPrefs prefsToEdit, int prefsCategory) {
this.prefs = prefs;
this.prefsToEdit = prefsToEdit;
this.prefsCategory = prefsCategory;
diff --git a/sources/editors/VSEditorFrame.java b/sources/editors/VSEditorFrame.java
index b9c14c6..1276e5b 100644
--- a/sources/editors/VSEditorFrame.java
+++ b/sources/editors/VSEditorFrame.java
@@ -19,16 +19,16 @@ public abstract class VSEditorFrame extends VSEditor {
public VSEditorFrame(VSPrefs prefs, Component relativeTo, VSPrefs prefsToEdit, String title) {
super(prefs, prefsToEdit);
frame = new VSFrame(title, relativeTo);
- initialize();
+ init();
}
public VSEditorFrame(VSPrefs prefs, Component relativeTo, VSPrefs prefsToEdit, String title, int prefsCategory) {
super(prefs, prefsToEdit, prefsCategory);
frame = new VSFrame(title, relativeTo);
- initialize();
+ init();
}
- private void initialize() {
+ private void init() {
frame.setJMenuBar(createJMenuBar());
frame.setContentPane(createContentPane());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
@@ -198,7 +198,7 @@ public abstract class VSEditorFrame extends VSEditor {
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
- prefsToEdit = prefs = VSDefaultPrefs.initialize(file.getName());
+ prefsToEdit = prefs = VSDefaultPrefs.init(file.getName());
resetEditPanel();
}
diff --git a/sources/editors/VSProcessEditor.java b/sources/editors/VSProcessEditor.java
index ecd495d..158295a 100644
--- a/sources/editors/VSProcessEditor.java
+++ b/sources/editors/VSProcessEditor.java
@@ -24,7 +24,7 @@ public class VSProcessEditor extends VSEditorFrame {
this.process = process;
- initialize();
+ init();
}
public VSProcessEditor(VSPrefs prefs, Component relativeTo, VSProcess process, int prefsCategory) {
@@ -35,10 +35,10 @@ public class VSProcessEditor extends VSEditorFrame {
this.process = process;
- initialize();
+ init();
}
- private void initialize() {
+ private void init() {
super.infoArea.setText(prefs.getString("lang.prefs.process.info!"));
getFrame().disposeWithParent();
createButtonPanel();
@@ -92,10 +92,8 @@ public class VSProcessEditor extends VSEditorFrame {
else
return;
} else {
- protocol = RegisteredProtocols.getProtocolInstanceByName(protocolName);
+ protocol = RegisteredProtocols.getProtocolInstanceByName(protocolName, process);
process.setObject(protocolClassname, protocol);
- protocol.setProcess(process);
- protocol.setVSPrefs(prefs);
}
new VSProtocolEditor(prefs, frame, protocol);
}
diff --git a/sources/editors/VSProtocolEditor.java b/sources/editors/VSProtocolEditor.java
index b347498..7a0961c 100644
--- a/sources/editors/VSProtocolEditor.java
+++ b/sources/editors/VSProtocolEditor.java
@@ -32,14 +32,14 @@ public class VSProtocolEditor extends VSEditorFrame {
this.protocol = protocol;
this.taskManager = protocol.getProcess().getSimulationPanel().getTaskManager();
- initialize();
+ init();
}
- private void initialize() {
+ private void init() {
super.getFrame().disposeWithParent();
super.infoArea.setText(prefs.getString("lang.prefs.protocol.info!"));
- initializeTaskManagerEditor(clientTaskManagerEditorPanel);
- initlializeClientServerCheckboxes();
+ initTaskManagerEditor(clientTaskManagerEditorPanel);
+ initClientServerCheckboxes();
createButtonPanel();
}
@@ -129,7 +129,7 @@ public class VSProtocolEditor extends VSEditorFrame {
return panel;
}
- private void initlializeClientServerCheckboxes() {
+ private void initClientServerCheckboxes() {
final String protocolName = protocol.getProtocolName();
final VSProcess process = protocol.getProcess();
@@ -140,7 +140,7 @@ public class VSProtocolEditor extends VSEditorFrame {
}
- private void initializeTaskManagerEditor(JPanel panel) {
+ private void initTaskManagerEditor(JPanel panel) {
clientComboBox = new JComboBox();
deleteButton = new JButton(prefs.getString("lang.remove"));
takeOverButton = new JButton(prefs.getString("lang.takeover"));
diff --git a/sources/editors/VSSimulationEditor.java b/sources/editors/VSSimulationEditor.java
index c455d64..31d40d8 100644
--- a/sources/editors/VSSimulationEditor.java
+++ b/sources/editors/VSSimulationEditor.java
@@ -20,7 +20,7 @@ public class VSSimulationEditor extends VSEditorFrame {
+ " - " + prefs.getString("lang.prefs"));
startNewVSSimulation = true;
- initialize();
+ init();
}
public VSSimulationEditor(VSPrefs prefs, Component relativeTo, int prefsCategory) {
@@ -30,10 +30,10 @@ public class VSSimulationEditor extends VSEditorFrame {
prefsCategory);
startNewVSSimulation = false;
- initialize();
+ init();
}
- private void initialize() {
+ private void init() {
super.infoArea.setText(prefs.getString("lang.prefs.info!"));
}
diff --git a/sources/prefs/VSDefaultPrefs.java b/sources/prefs/VSDefaultPrefs.java
index b985e8c..dac1b5c 100644
--- a/sources/prefs/VSDefaultPrefs.java
+++ b/sources/prefs/VSDefaultPrefs.java
@@ -5,11 +5,11 @@ import java.awt.event.KeyEvent;
import java.io.*;
public class VSDefaultPrefs extends VSPrefs {
- public static VSPrefs initialize() {
- return initialize(VSPrefs.PREFERENCES_FILENAME);
+ public static VSPrefs init() {
+ return init(VSPrefs.PREFERENCES_FILENAME);
}
- public static VSPrefs initialize(String fileName) {
+ public static VSPrefs init(String fileName) {
File file = new File(fileName);
VSPrefs prefs = null;
@@ -40,7 +40,8 @@ public class VSDefaultPrefs extends VSPrefs {
public void fillDefaultStrings() {
/* Internal prefs */
- initString("lang.time.lamport", "Lamport");
+ initString("lang.time.vector", "Vektorzeit");
+ initString("lang.time.lamport", "Lamportzeit");
initString("lang.message.sent", "Nachricht versendet");
initString("lang.logging.active", "Logging");
initString("lang.message", "Nachricht");
@@ -141,7 +142,7 @@ public class VSDefaultPrefs extends VSPrefs {
initIntegerUnit("window.prefs.xsize", 400, "X-Grösse des Einstellungsfensters", 550, 3200, "px");
initIntegerUnit("window.prefs.ysize", 650, "Y-Grösse des Einstellungsfensters", 640, 2400, "px");
- initIntegerUnit("window.loggsize", 350, "Y-Grösse des Loggingfensters", 100, 1000, "px");
+ initIntegerUnit("window.loggsize", 300, "Y-Grösse des Loggingfensters", 100, 1000, "px");
initIntegerUnit("window.splitsize", 180, null, 100, 1000, "px");
initIntegerUnit("window.xsize", 1024, "X-Grösse des Hauptfensters", 800, 3200, "px");
initIntegerUnit("window.ysize", 768, "Y-Grösse des Hauptfensters", 600, 2400, "px");
diff --git a/sources/prefs/VSPrefs.java b/sources/prefs/VSPrefs.java
index 9da4808..be9aea6 100644
--- a/sources/prefs/VSPrefs.java
+++ b/sources/prefs/VSPrefs.java
@@ -520,6 +520,13 @@ public abstract class VSPrefs implements Serializable {
descr += key + "=" + getInteger(key) + "; ";
}
+ set = getLongKeySet();
+ if (set.size() > 0) {
+ descr += LONG_PREFIX;
+ for (String key : set)
+ descr += key + "=" + getLong(key) + "; ";
+ }
+
set = getFloatKeySet();
if (set.size() > 0) {
descr += FLOAT_PREFIX;
diff --git a/sources/protocols/BerkelyTimeProtocol.java b/sources/protocols/BerkelyTimeProtocol.java
new file mode 100644
index 0000000..ea81cba
--- /dev/null
+++ b/sources/protocols/BerkelyTimeProtocol.java
@@ -0,0 +1,126 @@
+package protocols;
+
+import prefs.VSPrefs;
+import core.VSMessage;
+
+import java.util.HashMap;
+
+public class BerkelyTimeProtocol extends VSProtocol {
+ /* Berkely Server variables */
+
+ /* Integer: Process ID, Long: Local time of the process */
+ private HashMap<Integer,Long> processTimes = new HashMap<Integer,Long>();
+ /* Integer: Process ID, Long: Time of receiving the response from the process */
+ private HashMap<Integer,Long> recvTimes = new HashMap<Integer,Long>();
+ /* Integer: Process ID, Long: Calculated process times (using the RTT) */
+ private HashMap<Integer,Long> realTimesRTT = new HashMap<Integer,Long>();
+ /* Time the request/response has started */
+ private long requestTime;
+
+ /* Berkely Client vairables */
+
+ protected void onInit() {
+ setProtocolClassname(getClass().toString());
+
+ /* Those prefs are editable through the VSProtocol VSEditor GUI. t_min and t_max in milliseconds */
+ setInteger("numProcesses", getNumProcesses()-1);
+ }
+
+ protected void onClientReset() {
+ processTimes.clear();
+ recvTimes.clear();
+ realTimesRTT.clear();
+ }
+
+ protected void onClientStart() {
+ requestTime = process.getTime();
+ VSMessage message = new VSMessage(getProtocolClassname());
+ message.setBoolean("isRequest", true);
+ sendMessage(message);
+ }
+
+ protected void onClientRecv(VSMessage recvMessage) {
+ /* Ignore all protocol messages which are not a response message, e.g. itself */
+ if (!recvMessage.getBoolean("isResponse"))
+ return;
+
+ Integer processID = new Integer(recvMessage.getInteger("processID"));
+ Long time = new Long(recvMessage.getLong("time"));
+
+ processTimes.put(processID, time);
+ recvTimes.put(processID, new Long(process.getTime()));
+
+ /* All processes have comitted the response */
+ if (processTimes.size() == getInteger("numProcesses")) {
+ long avgTime = calculateAverageTime();
+ /* Set the local's process time to the new avg reference time */
+ process.setTime(avgTime);
+ /* Tell all other processes what to do in order to justify their times */
+ sendJustifyRequests(avgTime);
+ /* Start "clean" next time */
+ onClientReset();
+ }
+ }
+
+ /**
+ * Calculate the new average time
+ */
+ private long calculateAverageTime() {
+ long sum = 0;
+ for (Integer processID : processTimes.keySet()) {
+ Long localTime = processTimes.get(processID);
+ Long recvTime = recvTimes.get(processID);
+ long rtt = recvTime.longValue() - requestTime;
+ long realProcessTime = localTime + (long) (rtt / 2);
+ realTimesRTT.put(processID, new Long(realProcessTime));
+ sum += realProcessTime;
+ }
+ /* Include the time of the local process */
+ sum += process.getTime();
+ return (long) sum / (1 + getInteger("numProcesses"));
+ }
+
+ /**
+ * Sends to all clients a value to justify their local clocks
+ */
+ private void sendJustifyRequests(long avgTime) {
+ for (Integer processID : processTimes.keySet()) {
+ long realProcessTime = realTimesRTT.get(processID).longValue();
+ long diff = avgTime - realProcessTime;
+ VSMessage message = new VSMessage(getProtocolClassname());
+ message.setBoolean("isJustify", true);
+ message.setLong("timeDiff", diff);
+ message.setInteger("receiverProcessID", processID);
+ sendMessage(message);
+ }
+ }
+
+ protected void onServerReset() {
+ }
+
+ protected void onServerRecv(VSMessage recvMessage) {
+ if (recvMessage.getBoolean("isRequest")) {
+ VSMessage message = new VSMessage(getProtocolClassname());
+ message.setInteger("processID", process.getProcessID());
+ message.setLong("time", process.getTime());
+ message.setBoolean("isResponse", true);
+ sendMessage(message);
+
+ } else if (recvMessage.getBoolean("isJustify")) {
+ /* Check if it's "my" justify message */
+ if (recvMessage.getInteger("receiverProcessID") != process.getProcessID())
+ return;
+
+ long timeDiff = recvMessage.getLong("timeDiff");
+ long recvTime = process.getTime();
+ long newTime = process.getTime() + timeDiff;
+ logg("Neue Zeit: " + newTime);
+
+ process.setTime(newTime);
+ }
+ }
+
+ public String toString() {
+ return super.toString();
+ }
+}
diff --git a/sources/protocols/BroadcastSturmProtocol.java b/sources/protocols/BroadcastSturmProtocol.java
index 3940e5f..6ce95e8 100644
--- a/sources/protocols/BroadcastSturmProtocol.java
+++ b/sources/protocols/BroadcastSturmProtocol.java
@@ -9,7 +9,7 @@ public class BroadcastSturmProtocol extends VSPro