summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sources/core/VSMessage.java76
-rw-r--r--sources/core/VSProcess.java343
-rw-r--r--sources/core/VSTask.java121
-rw-r--r--sources/core/VSTaskManager.java90
-rw-r--r--sources/core/time/VSLamportTime.java28
-rw-r--r--sources/core/time/VSTime.java16
-rw-r--r--sources/core/time/VSVectorTime.java39
-rw-r--r--sources/events/VSEvent.java70
-rw-r--r--sources/events/VSRegisteredEvents.java92
-rw-r--r--sources/events/implementations/ProcessCrashEvent.java15
-rw-r--r--sources/events/implementations/ProcessRecoverEvent.java15
-rw-r--r--sources/events/internal/MessageReceiveEvent.java21
-rw-r--r--sources/events/internal/ProtocolEvent.java45
-rw-r--r--sources/prefs/VSDefaultPrefs.java42
-rw-r--r--sources/prefs/VSPrefs.java596
-rw-r--r--sources/prefs/editors/VSBetterEditor.java55
-rw-r--r--sources/prefs/editors/VSColorChooser.java25
-rw-r--r--sources/prefs/editors/VSEditor.java253
-rw-r--r--sources/prefs/editors/VSEditorFrame.java30
-rw-r--r--sources/prefs/editors/VSEditorTable.java110
-rw-r--r--sources/prefs/editors/VSProcessEditor.java28
-rw-r--r--sources/prefs/editors/VSSimulatorEditor.java35
-rw-r--r--sources/protocols/VSProtocol.java78
-rw-r--r--sources/protocols/implementations/BerkelyTimeProtocol.java44
-rw-r--r--sources/protocols/implementations/BroadcastSturmProtocol.java36
-rw-r--r--sources/protocols/implementations/DummyProtocol.java33
-rw-r--r--sources/protocols/implementations/ExternalTimeSyncProtocol.java36
-rw-r--r--sources/protocols/implementations/InternalTimeSyncProtocol.java34
-rw-r--r--sources/protocols/implementations/PingPongProtocol.java36
-rw-r--r--sources/simulator/VSAbout.java29
-rw-r--r--sources/simulator/VSLogging.java74
-rw-r--r--sources/simulator/VSMain.java31
-rw-r--r--sources/simulator/VSSimulator.java405
-rw-r--r--sources/simulator/VSSimulatorCanvas.java402
-rw-r--r--sources/simulator/VSSimulatorFrame.java94
-rw-r--r--sources/utils/VSClassLoader.java16
-rw-r--r--sources/utils/VSFrame.java41
-rw-r--r--sources/utils/VSInfoArea.java20
-rw-r--r--sources/utils/VSPriorityQueue.java16
-rw-r--r--sources/utils/VSRandom.java24
-rw-r--r--sources/utils/VSTools.java24
-rw-r--r--sources/utils/VSTupel.java36
42 files changed, 3606 insertions, 48 deletions
diff --git a/sources/core/VSMessage.java b/sources/core/VSMessage.java
index 05c9e6a..a16d35b 100644
--- a/sources/core/VSMessage.java
+++ b/sources/core/VSMessage.java
@@ -1,45 +1,53 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package core;
import core.time.*;
import events.*;
import prefs.VSPrefs;
-/** This class represents a message which is send from one process to another process in the simulation.
+// TODO: Auto-generated Javadoc
+/**
+ * This class represents a message which is send from one process to another process in the simulation.
*/
public class VSMessage extends VSPrefs {
- /** Each message belongs to a specific protocol. This variable defined the class name of the protocol being used.
- */
+
+ /** Each message belongs to a specific protocol. This variable defined the class name of the protocol being used. */
private String protocolClassname;
- /** The default application preferences.
- */
+
+ /** The default application preferences. */
private VSPrefs prefs;
- /** A reference to the process who sent this message.
- */
+
+ /** A reference to the process who sent this message. */
private VSProcess sendingProcess;
- /** The vector time of the sending process after sending. The receiver process will use this vector time in order to update the local vector time.
- */
+
+ /** The vector time of the sending process after sending. The receiver process will use this vector time in order to update the local vector time. */
private VSVectorTime vectorTime;
- /** The lamport time of the sending process after sending. The receiver process will use this lamport time in order to update the local vector time.
- */
+
+ /** The lamport time of the sending process after sending. The receiver process will use this lamport time in order to update the local vector time. */
private long lamportTime;
- /** Each message has its own unique ID. The ID will show up in the logging window of the simulator as well.
- */
+
+ /** Each message has its own unique ID. The ID will show up in the logging window of the simulator as well. */
private long messageID;
- /** This counter is used in order to generate unique message ID's.
- */
+
+ /** This counter is used in order to generate unique message ID's. */
private static long messageCounter;
- /** The constructor of the message.
+ /**
+ * The constructor of the message.
*
- * @param protocolClassname The classname of the protocol this message
- * belongs to.
+ * @param protocolClassname The classname of the protocol this message
+ * belongs to.
*/
public VSMessage(String protocolClassname) {
this.protocolClassname = protocolClassname;
this.messageID = ++messageCounter;
}
- /** Initialized the message.
+ /**
+ * Initialized the message.
*
* @param process The sending process of this message.
*/
@@ -50,7 +58,7 @@ public class VSMessage extends VSPrefs {
vectorTime = sendingProcess.getVectorTime().getCopy();
}
- /**
+ /**
* Getter method.
*
* @return The protocol name of the message.
@@ -59,7 +67,8 @@ public class VSMessage extends VSPrefs {
return VSRegisteredEvents.getName(getProtocolClassname());
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The protocol classname of the message.
*/
@@ -67,7 +76,8 @@ public class VSMessage extends VSPrefs {
return protocolClassname;
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The ID of the message.
*/
@@ -75,7 +85,8 @@ public class VSMessage extends VSPrefs {
return messageID;
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The process which sent this message.
*/
@@ -83,7 +94,8 @@ public class VSMessage extends VSPrefs {
return sendingProcess;
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The lamport time of the sending process.
*/
@@ -91,7 +103,8 @@ public class VSMessage extends VSPrefs {
return lamportTime;
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The vector time of the sending process.
*/
@@ -99,7 +112,8 @@ public class VSMessage extends VSPrefs {
return vectorTime;
}
- /** String representation of the message object.
+ /**
+ * String representation of the message object.
*
* @return String representation of the message object.
*/
@@ -116,7 +130,8 @@ public class VSMessage extends VSPrefs {
return buffer.toString();
}
- /** Extended string representation of the message object.
+ /**
+ * Extended string representation of the message object.
*
* @return Extended string representation of the message object.
*/
@@ -124,16 +139,19 @@ public class VSMessage extends VSPrefs {
return toString() + "; " + super.toString();
}
- /** Compares two messages.
+ /**
+ * Compares two messages.
*
* @param message The message to compare with.
+ *
* @return true, if the messages have the same ID. Otherwise false.
*/
public boolean equals(VSMessage message) {
return messageID == message.getMessageID();
}
- /** For logging in the simulator's logging window!
+ /**
+ * For logging in the simulator's logging window!.
*
* @param message The message to logg.
*/
diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java
index 3773bd6..e4c7561 100644
--- a/sources/core/VSProcess.java
+++ b/sources/core/VSProcess.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package core;
import java.awt.*;
@@ -11,39 +15,97 @@ import protocols.*;
import simulator.*;
import utils.*;
+/**
+ * The Class VSProcess. A object of this class represents a process of a simulation.
+ */
public class VSProcess extends VSPrefs {
+
+ /** The protocols to reset if the simulation is over or the reset button has been pressed. */
private ArrayList<VSProtocol> protocolsToReset;
+
+ /** The crash history. represents all crashes of the process using the global simulation time. */
private ArrayList<Long> crashHistory;
+
+ /** The lamport time history. */
private ArrayList<VSLamportTime> lamportTimeHistory;
+
+ /** The vector time history. */
private ArrayList<VSVectorTime> vectorTimeHistory;
+
+ /** The crashed color. */
private Color crashedColor;;
+
+ /** The current color. */
private Color currentColor;
+
+ /** The tmp color. For internal usage. */
private Color tmpColor;
+
+ /** The logging object. */
private VSLogging logging;
+
+ /** The simulation's default prefs. */
private VSPrefs prefs;
+
+ /** The random generator of the process. */
private VSRandom random;
+
+ /** The simulation canvas. */
private VSSimulatorCanvas simulationCanvas;
+
+ /** The random crash task. May be null if there is no such random task. */
private VSTask randomCrashTask;
+
+ /** The vector time. */
private VSVectorTime vectorTime;
+
+ /** The process has crashed. But may be working again. */
private boolean hasCrashed;
+
+ /** The process has started. But may be paused or crashed.. */
private boolean hasStarted;
+
+ /** The process is crashed. */
private boolean isCrashed;
+
+ /** The process is highlighted. */
private boolean isHighlighted;
+
+ /** The process is paused. */
private boolean isPaused;
+
+ /** The time has been modified in a task. Needed by the task manager to calculate correct offsets. */
private boolean timeModified;
+
+ /** The clock offset. Used by the task manager and also by the process' clock variance. */
private double clockOffset;
+
+ /** The clock variance. */
private float clockVariance;
+
+ /** The process id. */
private int processID; // Represents the PID of a process
+
+ /** The process num. It is different to the process id. It represents the array index of the process. */
private int processNum; // Represents the array index of the process, for internal usage
+
+ /** The global time. */
private long globalTime;
+
+ /** The lamport time. */
private long lamportTime;
+
+ /** The local time. */
private long localTime;
+
+ /** The process counter. Needed for the unique process id's. */
private static int processCounter;
/* 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
* up in the extended prefs menu!
*/
+ /** The Constant DEFAULT_INTEGER_VALUE_KEYS. */
private static final String DEFAULT_INTEGER_VALUE_KEYS[] = {
"process.prob.crash",
"message.prob.outage",
@@ -53,12 +115,14 @@ public class VSProcess extends VSPrefs {
* up in the prefs menu! All keys which dont start with "sim." only show
* up in the extended prefs menu!
*/
+ /** The Constant DEFAULT_LONG_VALUE_KEYS. */
private static final String DEFAULT_LONG_VALUE_KEYS[] = {
"message.sendingtime.min",
"message.sendingtime.max",
};
- /* This array contains all Float prefs of the process which should show
+ /** The Constant DEFAULT_FLOAT_VALUE_KEYS. */
+ /** This array contains all Float prefs of the process which should show
* up in the prefs menu! All keys which dont start with "sim." only show
* up in the extended prefs menu!
*/
@@ -66,7 +130,8 @@ public class VSProcess extends VSPrefs {
"process.clock.variance",
};
- /* This array contains all Color prefs of the process which should show
+ /** The Constant DEFAULT_COLOR_VALUE_KEYS. */
+ /** This array contains all Color prefs of the process which should show
* up in the prefs menu! All keys which dont start with "sim." only show
* up in the extended prefs menu!
*/
@@ -78,13 +143,22 @@ public class VSProcess extends VSPrefs {
"col.process.crashed",
};
- /* This array contains all String prefs of the process which should show
+ /** The Constant DEFAULT_STRING_VALUE_KEYS. */
+ /** This array contains all String prefs of the process which should show
* up in the prefs menu! All keys which dont start with "sim." only show
* up in the extended prefs menu!
*/
private static final String DEFAULT_STRING_VALUE_KEYS[] = {
};
+ /**
+ * Instantiates a new process.
+ *
+ * @param prefs the simulation's default prefs
+ * @param processNum the process num
+ * @param simulationCanvas the simulation canvas
+ * @param logging the logging object
+ */
public VSProcess(VSPrefs prefs, int processNum, VSSimulatorCanvas simulationCanvas, VSLogging logging) {
this.protocolsToReset = new ArrayList<VSProtocol>();
this.processNum = processNum;
@@ -112,6 +186,9 @@ public class VSProcess extends VSPrefs {
createRandomCrashTask();
}
+ /**
+ * Inits the time formats.
+ */
private void initTimeFormats() {
lamportTime = 0;
lamportTimeHistory = new ArrayList<VSLamportTime>();
@@ -125,6 +202,9 @@ public class VSProcess extends VSPrefs {
vectorTime.add(new Long(0));
}
+ /**
+ * Reset time formats.
+ */
private void resetTimeFormats() {
lamportTime = 0;
lamportTimeHistory.clear();
@@ -140,7 +220,7 @@ public class VSProcess extends VSPrefs {
/**
- * Called from the VSProcessEditor, after finishing editing!
+ * Called from the VSProcessEditor, after finishing editing!.
*/
public synchronized void updateFromVSPrefs() {
setClockVariance(getFloat("process.clock.variance"));
@@ -151,13 +231,18 @@ public class VSProcess extends VSPrefs {
}
/**
- * Called from the VSProcessEditor, before starting editing!
+ * Called from the VSProcessEditor, before starting editing!.
*/
public synchronized void updatePrefs() {
setFloat("process.clock.variance", getClockVariance());
setLong("process.localtime", getTime());
}
+ /**
+ * Sync time. Using the clockOffset and clockVariance.
+ *
+ * @param globalTime the global time
+ */
public synchronized void syncTime(final long globalTime) {
final long currentGlobalTimestep = globalTime - this.globalTime;
this.globalTime = globalTime;
@@ -179,6 +264,11 @@ public class VSProcess extends VSPrefs {
localTime = 0;
}
+ /**
+ * Sets the current color.
+ *
+ * @param newColor the new current color
+ */
private void setCurrentColor(Color newColor) {
if (isHighlighted)
tmpColor = newColor;
@@ -186,17 +276,26 @@ public class VSProcess extends VSPrefs {
currentColor = newColor;
}
+ /**
+ * Highlights the process.
+ */
public synchronized void highlightOn() {
tmpColor = currentColor;
currentColor = getColor("col.process.highlight");
isHighlighted = true;
}
+ /**
+ * Unhighlights the process.
+ */
public synchronized void highlightOff() {
currentColor = tmpColor;
isHighlighted = false;
}
+ /**
+ * Resets the process.
+ */
public synchronized void reset() {
isPaused = true;
isCrashed = false;
@@ -212,6 +311,9 @@ public class VSProcess extends VSPrefs {
resetTimeFormats();
}
+ /**
+ * Creates the random crash task.
+ */
public void createRandomCrashTask() {
if (!isCrashed) {
VSTaskManager taskManager = simulationCanvas.getTaskManager();
@@ -236,41 +338,80 @@ public class VSProcess extends VSPrefs {
}
}
+ /**
+ * Adds the clock offset. This method is used by the task manager.
+ *
+ * @param add the clock offset to add.
+ */
public synchronized void addClockOffset(long add) {
this.clockOffset += add;
}
+ /**
+ * Play. Called by the simulation canvas.
+ */
public synchronized void play() {
isPaused = false;
setCurrentColor(getColor("col.process.running"));
}
+ /**
+ * Pause. Called by the simulation canvas.
+ */
public synchronized void pause() {
isPaused = true;
setCurrentColor(getColor("col.process.stopped"));
}
+ /**
+ * Finish. Called by the simulation canvas.
+ */
public synchronized void finish() {
isPaused = true;
setCurrentColor(getColor("col.process.default"));
}
+ /**
+ * Gets the process id.
+ *
+ * @return the process id
+ */
public synchronized int getProcessID() {
return processID;
}
+ /**
+ * Gets the process num.
+ *
+ * @return the process num
+ */
public synchronized int getProcessNum() {
return processNum;
}
+ /**
+ * Sets the process id.
+ *
+ * @param processID the new process id
+ */
public synchronized void setProcessID(int processID) {
this.processID = processID;
}
+ /**
+ * Gets the current process' color.
+ *
+ * @return the current color of the process.
+ */
public synchronized Color getColor() {
return currentColor;
}
+ /**
+ * Sets the local time.
+ *
+ * @param localTime the new local time.
+ */
public synchronized void setLocalTime(final long localTime) {
if (localTime >= 0)
this.localTime = localTime;
@@ -278,10 +419,20 @@ public class VSProcess extends VSPrefs {
this.localTime = 0;
}
+ /**
+ * Gets the process' local time.
+ *
+ * @return the process' local time
+ */
public synchronized long getTime() {
return localTime;
}
+ /**
+ * Sets the process' local time.
+ *
+ * @param time the new local time of the process.
+ */
public synchronized void setTime(final long time) {
if (time >= 0)
this.localTime = time;
@@ -291,10 +442,20 @@ public class VSProcess extends VSPrefs {
this.timeModified = true;
}
+ /**
+ * Checks if the process is crashed.
+ *
+ * @return true, if is crashed
+ */
public synchronized boolean isCrashed() {
return isCrashed;
}
+ /**
+ * Sets if the process is crashed.
+ *
+ * @param isCrashed true if the process is crashed.
+ */
public synchronized void isCrashed(boolean isCrashed) {
this.isCrashed = isCrashed;
crashHistory.add(new Long(globalTime));
@@ -302,34 +463,76 @@ public class VSProcess extends VSPrefs {
hasCrashed = true;
}
+ /**
+ * Checks if the process has crashed at least once during the current
+ * simulation.
+ *
+ * @return true, if yes
+ */
public synchronized boolean hasCrashed() {
return hasCrashed;
}
+ /**
+ * Gets the crashed color.
+ *
+ * @return the crashed color
+ */
public synchronized Color getCrashedColor() {
return crashedColor;
}
+ /**
+ * Checks if the time has been modified. by a task.
+ * This mehod is needed by the task manager.
+ *
+ * @return true, if yes
+ */
public synchronized boolean timeModified() {
return timeModified;
}
+ /**
+ * Sets if the time has been modified by a task.
+ *
+ * @param timeModified true, if it has been modified.
+ */
public synchronized void timeModified(boolean timeModified) {
this.timeModified = timeModified;
}
+ /**
+ * Gets the global time.
+ *
+ * @return the global time
+ */
public synchronized long getGlobalTime() {
return globalTime;
}
+ /**
+ * Sets the global time.
+ *
+ * @param globalTime the new global time
+ */
public synchronized void setGlobalTime(final long globalTime) {
this.globalTime = globalTime >= 0 ? globalTime : 0;
}
+ /**
+ * Gets the clock variance.
+ *
+ * @return the clock variance
+ */
public synchronized float getClockVariance() {
return clockVariance;
}
+ /**
+ * Sets the clock variance.
+ *
+ * @param clockVariance the new clock variance
+ */
public synchronized void setClockVariance(float clockVariance) {
/* If negative, only allow < 1 prefs */
if (clockVariance < 0) {
@@ -343,6 +546,11 @@ public class VSProcess extends VSPrefs {
this.clockVariance = clockVariance;
}
+ /**
+ * Gets the duration time.
+ *
+ * @return the duration time
+ */
public synchronized long getDurationTime() {
final long maxDurationTime = getLong("message.sendingtime.max");
final long minDurationTime = getLong("message.sendingtime.min");
@@ -359,6 +567,13 @@ public class VSProcess extends VSPrefs {
return minDurationTime + random.nextInt(diff+1);
}
+ /**
+ * Gets the a random message outage time.
+ *
+ * @param durationTime the duration time
+ *
+ * @return the a random message outage time
+ */
public synchronized long getARandomMessageOutageTime(final long durationTime) {
/* Check if the message will have an outage or not */
if (random.nextInt(100) < getInteger("message.prob.outage")) {
@@ -371,6 +586,11 @@ public class VSProcess extends VSPrefs {
return -1;
}
+ /**
+ * Gets the a random crash time.
+ *
+ * @return the a random crash time
+ */
private long getARandomCrashTime() {
/* Check if the process will crash or not */
if (random.nextInt(100) <= getInteger("process.prob.crash")) {
@@ -383,18 +603,36 @@ public class VSProcess extends VSPrefs {
return -1;
}
+ /**
+ * Gets the random crash task.
+ *
+ * @return the random crash task
+ */
public synchronized VSTask getCrashTask() {
return randomCrashTask;
}
+ /**
+ * Checks if is paused.
+ *
+ * @return true, if is paused
+ */
public synchronized boolean isPaused() {
return isPaused;
}
+ /**
+ * Increases the lamport time.
+ */
public void increaseLamportTime() {
setLamportTime(getLamportTime()+1);
}
+ /**
+ * Updates the lamport time.
+ *
+ * @param time the lamport time
+ */
public void updateLamportTime(long time) {
final long lamportTime = getLamportTime() + 1;
@@ -404,15 +642,30 @@ public class VSProcess extends VSPrefs {
setLamportTime(lamportTime);
}
+ /**
+ * Gets the lamport time.
+ *
+ * @return the lamport time.
+ */
public synchronized long getLamportTime() {
return lamportTime;
}
+ /**
+ * Sets the lamport time.
+ *
+ * @param lamportTime the new lamport time
+ */
public synchronized void setLamportTime(long lamportTime) {
this.lamportTime = lamportTime;
lamportTimeHistory.add(new VSLamportTime(globalTime, lamportTime));
}
+ /**
+ * Gets the lamport time history as an array.
+ *
+ * @return the lamport time history array
+ */
public synchronized VSTime[] getLamportTimeArray() {
final int size = lamportTimeHistory.size();
final VSTime[] arr = new VSLamportTime[size];
@@ -423,12 +676,20 @@ public class VSProcess extends VSPrefs {
return arr;
}
+ /**
+ * Increases the vector time.
+ */
public synchronized void increaseVectorTime() {
vectorTime.set(processNum, new Long(vectorTime.get(processNum).longValue()+1));
vectorTime.setGlobalTime(globalTime);
vectorTimeHistory.add(vectorTime.getCopy());
}
+ /**
+ * Updates the vector time.
+ *
+ * @param vectorTimeUpdate the vector time of the other process to use for the update
+ */
public synchronized void updateVectorTime(VSVectorTime vectorTimeUpdate) {
final int size = vectorTime.size();
@@ -443,10 +704,20 @@ public class VSProcess extends VSPrefs {
vectorTimeHistory.add(vectorTime.getCopy());
}
+ /**
+ * Gets the vector time.
+ *
+ * @return the vector time
+ */
public synchronized VSVectorTime getVectorTime() {
return vectorTime;
}
+ /**
+ * Gets the vector time history as an array.
+ *
+ * @return the vector time history array
+ */
public synchronized VSTime[] getVectorTimeArray() {
final int size = vectorTimeHistory.size();
final VSTime[] arr = new VSTime[size];
@@ -457,6 +728,11 @@ public class VSProcess extends VSPrefs {
return arr;
}
+ /**
+ * Gets the crash history array.
+ *
+ * @return the crash history array
+ */
public synchronized Long[] getCrashHistoryArray() {
final int size = crashHistory.size();
final Long[] arr = new Long[size];
@@ -467,6 +743,11 @@ public class VSProcess extends VSPrefs {
return arr;
}
+ /**
+ * Called by a task if the process sends a message.
+ *
+ * @param message the message to send.
+ */
public void sendMessage(VSMessage message) {
StringBuffer buffer = new StringBuffer();
buffer.append(prefs.getString("lang.message.sent"));
@@ -476,10 +757,18 @@ public class VSProcess extends VSPrefs {
simulationCanvas.sendMessage(message);
}
+ /**
+ * Logg a message to the logging area.
+ *
+ * @param message the message to logg
+ */
public void logg(String message) {
logging.logg(toString() + "; " + message, globalTime);
}
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#fill