summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-08-04 20:44:54 +0000
committerPaul Buetow <paul@buetow.org>2008-08-04 20:44:54 +0000
commit8ae434c63e6382a8cb850551d947285f5fcb3c25 (patch)
tree751b0b24cd86768d57e9338cf0718485f68a095e
parentbb4eb6634485d05e9e8cff6497c60ef696a28eeb (diff)
restructured stuff
-rwxr-xr-xscripts/printstatistics.sh2
-rw-r--r--sources/core/VSAbstractProcess.java (renamed from sources/core/VSProcess.java)505
-rw-r--r--sources/core/VSInternalProcess.java449
-rw-r--r--sources/core/VSMessage.java6
-rw-r--r--sources/core/VSMessageStub.java59
-rw-r--r--sources/core/VSTask.java20
-rw-r--r--sources/core/VSTaskManager.java32
-rw-r--r--sources/events/VSAbstractEvent.java10
-rw-r--r--sources/events/VSRegisteredEvents.java8
-rw-r--r--sources/prefs/VSDefaultPrefs.java2
-rw-r--r--sources/prefs/editors/VSProcessEditor.java6
-rw-r--r--sources/protocols/VSAbstractProtocol.java6
-rw-r--r--sources/protocols/implementations/VSBerkelyTimeProtocol.java4
-rw-r--r--sources/protocols/implementations/VSBroadcastProtocol.java129
-rw-r--r--sources/protocols/implementations/VSOnePhaseCommitProtocol.java2
-rw-r--r--sources/protocols/implementations/VSReliableMulticastProtocol.java20
-rw-r--r--sources/simulator/VSCreateTask.java2
-rw-r--r--sources/simulator/VSSimulator.java32
-rw-r--r--sources/simulator/VSSimulatorCanvas.java70
-rw-r--r--sources/simulator/VSSimulatorFrame.java4
20 files changed, 838 insertions, 530 deletions
diff --git a/scripts/printstatistics.sh b/scripts/printstatistics.sh
index ca356b5..614d36e 100755
--- a/scripts/printstatistics.sh
+++ b/scripts/printstatistics.sh
@@ -17,3 +17,5 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
find ./sources -name \*.java | xargs wc -l
+echo "Num .java files:"
+find ./sources -name \*.java | wc -l
diff --git a/sources/core/VSProcess.java b/sources/core/VSAbstractProcess.java
index ae08828..c526f3f 100644
--- a/sources/core/VSProcess.java
+++ b/sources/core/VSAbstractProcess.java
@@ -37,115 +37,116 @@ import simulator.*;
import utils.*;
/**
- * The class VSProcess, an object of this class represents a process of a
- * simulator.
+ * The class VSAbstractProcess, an object of this class represents a process
+ * of a simulator.
*
* @author Paul C. Buetow
*/
-public class VSProcess extends VSPrefs implements VSSerializable {
+public abstract class VSAbstractProcess extends VSPrefs
+ implements VSSerializable {
/** The data serialization id. */
- private static final long serialVersionUID = 1L;
+ protected static final long serialVersionUID = 1L;
/** The protocols to reset if the simulator is over or the reset
* button has been pressed.
*/
- private ArrayList<VSAbstractProtocol> protocolsToReset;
+ protected ArrayList<VSAbstractProtocol> protocolsToReset;
/** The crash history. represents all crashes of the process using the
* global simulator time.
*/
- private ArrayList<Long> crashHistory;
+ protected ArrayList<Long> crashHistory;
/** The lamport time history. */
- private ArrayList<VSLamportTime> lamportTimeHistory;
+ protected ArrayList<VSLamportTime> lamportTimeHistory;
/** The vector time history. */
- private ArrayList<VSVectorTime> vectorTimeHistory;
+ protected ArrayList<VSVectorTime> vectorTimeHistory;
/** The color used if the process has crashed. */
- private Color crashedColor;;
+ protected Color crashedColor;;
/** The process' current color. */
- private Color currentColor;
+ protected Color currentColor;
/** A temp. color. For internal usage. */
- private Color tmpColor;
+ protected Color tmpColor;
/** The logging object. */
- private VSLogging logging;
+ protected VSLogging logging;
/** The simulator's default prefs. */
- private VSPrefs prefs;
+ protected VSPrefs prefs;
/** The random generator of the process. */
- private VSRandom random;
+ protected VSRandom random;
/** The simulator canvas. */
- private VSSimulatorCanvas simulatorCanvas;
+ protected VSSimulatorCanvas simulatorCanvas;
/** The random crash task. May be null if there is no such random task. */
- private VSTask randomCrashTask;
+ protected VSTask randomCrashTask;
/** The vector time. */
- private VSVectorTime vectorTime;
+ protected VSVectorTime vectorTime;
/** The tasks of the process. DO ONLY MANIPULATE THIS OBJECT WITHIN THE
* VSTaskManager CLASS! OTHERWISE THE SYNCHRONIZATION IS WRONG! Use the
- * VSProcess.getTasks() method to get a reference to this object within the
+ * VSAbstractProcess.getTasks() method to get a reference to this object within the
* VSTaskManager! */
- private VSPriorityQueue<VSTask> tasks;
+ protected VSPriorityQueue<VSTask> tasks;
/** The process has crashed. But may be working again. */
- private boolean hasCrashed;
+ protected boolean hasCrashed;
/** The process has started. But may be paused or crashed.. */
- private boolean hasStarted;
+ protected boolean hasStarted;
/** The process is crashed. */
- private boolean isCrashed;
+ protected boolean isCrashed;
/** The process is highlighted. */
- private boolean isHighlighted;
+ protected boolean isHighlighted;
/** The process is paused. */
- private boolean isPaused;
+ protected boolean isPaused;
/** The time has been modified in a task. Needed by the task manager to
* calculate correct offsets.
*/
- private boolean timeModified;
+ protected boolean timeModified;
/** The clock offset. Used by the task manager and also by the process'
* clock variance.
*/
- private double clockOffset;
+ protected double clockOffset;
/** The clock variance. */
- private float clockVariance;
+ protected float clockVariance;
/** The process id. */
- private int processID;
+ protected int processID;
/** The process num. It is different to the process id. It represents the
* array index of there the process is stored at.
*/
- private int processNum;
+ protected int processNum;
/** The global time. */
- private long globalTime;
+ protected long globalTime;
/** The lamport time. */
- private long lamportTime;
+ protected long lamportTime;
/** The local time. */
- private long localTime;
+ protected long localTime;
/** The Constant DEFAULT_INTEGER_VALUE_KEYS.
* 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!
*/
- private static final String DEFAULT_INTEGER_VALUE_KEYS[] = {
+ protected static final String DEFAULT_INTEGER_VALUE_KEYS[] = {
"process.prob.crash",
"message.prob.outage",
};
@@ -155,7 +156,7 @@ public class VSProcess extends VSPrefs implements VSSerializable {
* 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_LONG_VALUE_KEYS[] = {
+ protected static final String DEFAULT_LONG_VALUE_KEYS[] = {
"message.sendingtime.min",
"message.sendingtime.max",
};
@@ -165,7 +166,7 @@ public class VSProcess extends VSPrefs implements VSSerializable {
* 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_FLOAT_VALUE_KEYS[] = {
+ protected static final String DEFAULT_FLOAT_VALUE_KEYS[] = {
"process.clock.variance",
};
@@ -174,7 +175,7 @@ public class VSProcess extends VSPrefs implements VSSerializable {
* 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_COLOR_VALUE_KEYS[] = {
+ protected static final String DEFAULT_COLOR_VALUE_KEYS[] = {
"col.process.default",
"col.process.running",
"col.process.stopped",
@@ -187,7 +188,7 @@ public class VSProcess extends VSPrefs implements VSSerializable {
* 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[] = {
+ protected static final String DEFAULT_STRING_VALUE_KEYS[] = {
};
/**
@@ -198,8 +199,8 @@ public class VSProcess extends VSPrefs implements VSSerializable {
* @param simulatorCanvas the simulator canvas
* @param logging the logging object
*/
- public VSProcess(VSPrefs prefs, int processNum,
- VSSimulatorCanvas simulatorCanvas, VSLogging logging) {
+ public VSAbstractProcess(VSPrefs prefs, int processNum,
+ VSSimulatorCanvas simulatorCanvas, VSLogging logging) {
init(prefs, processNum, simulatorCanvas, logging);
}
@@ -211,8 +212,8 @@ public class VSProcess extends VSPrefs implements VSSerializable {
* @param simulatorCanvas the simulator canvas
* @param logging the logging object
*/
- private void init(VSPrefs prefs, int processNum,
- VSSimulatorCanvas simulatorCanvas, VSLogging logging) {
+ protected void init(VSPrefs prefs, int processNum,
+ VSSimulatorCanvas simulatorCanvas, VSLogging logging) {
/* May be not null if called from deserialization */
if (this.protocolsToReset == null)
this.protocolsToReset = new ArrayList<VSAbstractProtocol>();
@@ -242,13 +243,13 @@ public class VSProcess extends VSPrefs implements VSSerializable {
initLong("process.localtime", localTime,
prefs.getString("lang.process.time.local"), "ms");
- createRandomCrashTask();
+ createRandomCrashTask_();
}
/**
* Inits the time formats. E.g. lamport and vector time stamps.
*/
- private void initTimeFormats() {
+ protected void initTimeFormats() {
lamportTime = 0;
lamportTimeHistory = new ArrayList<VSLamportTime>();
@@ -264,7 +265,7 @@ public class VSProcess extends VSPrefs implements VSSerializable {
/**
* Reset time formats. E.g. lamport and vector time stamps.
*/
- private void resetTimeFormats() {
+ protected void resetTimeFormats() {
lamportTime = 0;
lamportTimeHistory.clear();
@@ -278,132 +279,6 @@ public class VSProcess extends VSPrefs implements VSSerializable {
}
/**
- * Called from the VSProcessEditor, after finishing editing! This makes
- * sure that the VSProcess object is using the up to date prefs!
- */
- public synchronized void updateFromPrefs() {
- setClockVariance(getFloat("process.clock.variance"));
- setLocalTime(getLong("process.localtime"));
- crashedColor = getColor("col.process.crashed");
- createRandomCrashTask();
- }
-
- /**
- * Called from the VSProcessEditor, before starting editing! This makes
- * sure that the editor edits the up to date prefs of the process!
- */
- public synchronized void updatePrefs() {
- setFloat("process.clock.variance", getClockVariance());
- setLong("process.localtime", getTime());
- }
-
- /**
- * Syncs the process' time. This method is using the clockOffset and
- * clockVariance variables. This method is called repeatedly from the
- * VSSimulatorCanvas in order to update the process' local and global
- * time values.
- *
- * @param globalTime the global time.
- */
- public synchronized void syncTime(final long globalTime) {
- final long currentGlobalTimestep = globalTime - this.globalTime;
- this.globalTime = globalTime;
-
- localTime += currentGlobalTimestep;
- clockOffset += currentGlobalTimestep * (double) clockVariance;
-
- while (clockOffset >= 1) {
- clockOffset -= 1;
- ++localTime;
- }
-
- while (clockOffset <= -1) {
- clockOffset += 1;
- --localTime;
- }
-
- /* We do not want a negative time */
- if (localTime < 0)
- localTime = 0;
- }
-
- /**
- * Sets the current color.
- *
- * @param newColor the new current color
- */
- private void setCurrentColor(Color newColor) {
- if (isHighlighted)
- tmpColor = newColor;
- else
- 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;
- hasCrashed = false;
- localTime = 0;
- globalTime = 0;
- clockOffset = 0;
-
- for (VSAbstractProtocol protocol : protocolsToReset)
- protocol.reset();
-
- setCurrentColor(getColor("col.process.default"));
- resetTimeFormats();
- }
-
- /**
- * Creates the random crash task. The crash task will be created only if
- * the process is not crashed atm. and if VSProcess.getARandomCrashTime()
- * returns a non-negative value. The random crash task uses the simulaion's
- * global time for its scheduling.
- */
- public synchronized void createRandomCrashTask() {
- if (!isCrashed) {
- VSTaskManager taskManager = simulatorCanvas.getTaskManager();
- long crashTime = getARandomCrashTime();
-
- if (crashTime < 0)
- return;
-
- if (randomCrashTask != null)
- taskManager.removeTask(randomCrashTask);
-
- if (crashTime >= getGlobalTime()) {
- VSAbstractEvent event = new VSProcessCrashEvent();
- randomCrashTask = new VSTask(crashTime, this, event,
- VSTask.GLOBAL);
- taskManager.addTask(randomCrashTask);
-
- } else {
- randomCrashTask = null;
- }
- }
- }
-
- /**
* Creates a random percentage 0..100 using the process' own pseudo
* random number generator object of the VSRandom class.
*
@@ -420,35 +295,11 @@ public class VSProcess extends VSPrefs implements VSSerializable {
*
* @param add the clock offset to add.
*/
- public synchronized void addClockOffset(long add) {
+ protected synchronized void addClockOffset(long add) {
this.clockOffset += add;
}
/**
- * The process' state is 'play'. Called by the simulator canvas.
- */
- public synchronized void play() {
- isPaused = false;
- setCurrentColor(getColor("col.process.running"));
- }
-
- /**
- * The process' state is 'pause'. Called by the simulator canvas.
- */
- public synchronized void pause() {
- isPaused = true;
- setCurrentColor(getColor("col.process.stopped"));
- }
-
- /**
- * The process' state is 'Finish'. Called by the simulator canvas.
- */
- public synchronized void finish() {
- isPaused = true;
- setCurrentColor(getColor("col.process.default"));
- }
-
- /**
* Gets the process id.
*
* @return the process id
@@ -477,27 +328,6 @@ public class VSProcess extends VSPrefs implements VSSerializable {
}
/**
- * 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;
- else
- this.localTime = 0;
- }
-
- /**
* Gets the process' local time.
*
* @return the process' local time
@@ -554,35 +384,6 @@ public class VSProcess extends VSPrefs implements VSSerializable {
}
/**
- * Gets the color of this process if it's crashed.
- *
- * @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 in order to add a clock offset
- * to the process object.
- *
- * @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
@@ -592,15 +393,6 @@ public class VSProcess extends VSPrefs implements VSSerializable {
}
/**
- * 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
@@ -628,61 +420,12 @@ public class VSProcess extends VSPrefs implements VSSerializable {
}
/**
- * Gets the duration time of a message to send.
- *
- * @return the duration time
- */
- public synchronized long getDurationTime() {
- final long maxDurationTime = getLong("message.sendingtime.max");
- final long minDurationTime = getLong("message.sendingtime.min");
-
- if (maxDurationTime <= minDurationTime)
- return minDurationTime;
-
- final int diff = (int) (maxDurationTime - minDurationTime);
-
- /* Integer overflow */
- if (diff <= 0)
- return minDurationTime;
-
- 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. It will be -1 if the message
- * will not get lost at all.
- */
- public synchronized long getARandomMessageOutageTime(long durationTime,
- VSProcess receiverProcess) {
- int percentage = (int) ((getInteger("message.prob.outage") +
- receiverProcess.getInteger(
- "message.prob.outage")) / 2);
-
- /* Check if the message will have an outage or not */
- if (getRandomPercentage() < percentage) {
-
- /* Calculate the random outage time! */
- long outageTime = globalTime + random.nextLong(durationTime+1) %
- simulatorCanvas.getUntilTime();
-
- return outageTime;
- }
-
- /* No outage */
- return -1;
- }
-
- /**
* Gets the a random crash time.
*
* @return the a random crash time. It will be -1 if the process will not
* crash at all randomly!
*/
- private long getARandomCrashTime() {
+ protected long getARandomCrashTime() {
/* Check if the process will crash or not */
if (getRandomPercentage() < getInteger("process.prob.crash")) {
/* Calculate the random crash time! */
@@ -697,24 +440,6 @@ public class VSProcess extends VSPrefs implements VSSerializable {
}
/**
- * Gets the random crash task.
- *
- * @return the random crash task
- */
- public synchronized VSTask getCrashTask() {
- return randomCrashTask;
- }
-
- /**
- * Checks if the process is paused.
- *
- * @return true, if is paused
- */
- public synchronized boolean isPaused() {
- return isPaused;
- }
-
- /**
* Increases the process' lamport time.
*/
public synchronized void increaseLamportTime() {
@@ -770,7 +495,20 @@ public class VSProcess extends VSPrefs implements VSSerializable {
}
/**
- * Increases the vector time.
+ * Increases the vector and the lamport time by 1 each if
+ * sim.update.vectortime.all/sim.update.lamporttime.all are set
+ * to true.
+ */
+ public void increaseVectorAndLamportTimeIfAll() {
+ if (prefs.getBoolean("sim.update.lamporttime.all"))
+ increaseLamportTime();
+
+ if (prefs.getBoolean("sim.update.vectortime.all"))
+ increaseVectorTime();
+ }
+
+ /**
+ * Increases the vector time by 1.
*/
public synchronized void increaseVectorTime() {
vectorTime.set(processNum,
@@ -839,20 +577,6 @@ public class VSProcess extends VSPrefs implements VSSerializable {
}
/**
- * Called by a task if the process sends a message.
- *
- * @param message the message to send.
- */
- public synchronized void sendMessage(VSMessage message) {
- StringBuffer buffer = new StringBuffer();
- buffer.append(prefs.getString("lang.message.sent"));
- buffer.append("; ");
- buffer.append(message.toStringFull());
- logg(buffer.toString());
- simulatorCanvas.sendMessage(message);
- }
-
- /**
* Logg a message to the logging area.
*
* @param message the message to logg
@@ -919,20 +643,11 @@ public class VSProcess extends VSPrefs implements VSSerializable {
*
* @return true, if both processes are the same (same processNum).
*/
- public boolean equals(VSProcess process) {
+ public boolean equals(VSAbstractProcess process) {
return process.getProcessNum() == processNum;
}
/**
- * Gets the simulator canvas.
- *
- * @return the simulator canvas
- */
- public VSSimulatorCanvas getSimulatorCanvas() {
- return simulatorCanvas;
- }
-
- /**
* Gets the simulator's default prefs.
*
* @return the default prefs
@@ -941,77 +656,6 @@ public class VSProcess extends VSPrefs implements VSSerializable {
return prefs;
}
- /**
- * Removes the process at the specified index. Called by the simulator
- * canvas if a process has been removed from the simulator. Needed in
- * order to update the vector time and the local processNum.
- *
- * @param index the index the process has to get removed.
- */
- public synchronized void removedAProcessAtIndex(int index) {
- if (index < processNum)
- --processNum;
-
- vectorTime.remove(index);
- for (VSVectorTime vectorTime : vectorTimeHistory)
- vectorTime.remove(index);
- }
-
- /**
- * Added a process. Needed in order to update the vector time's size.
- * Called by the simulator canvas if a process has been added to the
- * simulator.
- */
- public synchronized void addedAProcess() {
- vectorTime.add(new Long(0));
- for (VSVectorTime vectorTime : vectorTimeHistory)
- vectorTime.add(new Long(0));
- }
-
- /**
- * Gets the tasks of the process.
- *
- * @return The tasks
- */
- public VSPriorityQueue<VSTask> getTasks() {
- return tasks;
- }
-
- /**
- * Sets the tasks of the process.
- *
- * @param tasks The tasks
- */
- public void setTasks(VSPriorityQueue<VSTask> tasks) {
- this.tasks = tasks;
- }
-
- /**
- * Gets the protocol object.
- *
- * @param protocolClassname the protocol classname
- *
- * @return the protocol object
- */
- public synchronized VSAbstractProtocol getProtocolObject(
- String protocolClassname) {
- VSAbstractProtocol protocol = null;
-
- if (!objectExists(protocolClassname)) {
- protocol = (VSAbstractProtocol)
- VSRegisteredEvents.createEventInstanceByClassname(
- protocolClassname, this);
-
- setObject(protocolClassname, protocol);
- protocolsToReset.add(protocol);
-
- } else {
- protocol = (VSAbstractProtocol) getObject(protocolClassname);
- }
-
- return protocol;
- }
-
/* (non-Javadoc)
* @see serialize.VSSerializable#serialize(serialize.VSSerialize,
* java.io.ObjectOutputStream)
@@ -1022,7 +666,7 @@ public class VSProcess extends VSPrefs implements VSSerializable {
super.serialize(serialize, objectOutputStream);
if (VSSerialize.DEBUG)
- System.out.println("Serializing: VSProcess (num: " + processNum
+ System.out.println("Serializing: VSAbstractProcess (num: " + processNum
+ "; id: " + processID + ")");
/** For later backwards compatibility, to add more stuff */
@@ -1048,10 +692,10 @@ public class VSProcess extends VSPrefs implements VSSerializable {
ObjectInputStream objectInputStream)
throws IOException, ClassNotFoundException {
super.deserialize(serialize, objectInputStream);
- updateFromPrefs();
+ updateFromPrefs_();
if (VSSerialize.DEBUG)
- System.out.println("Deserializing: VSProcess");
+ System.out.println("Deserializing: VSAbstractProcess");
/** For later backwards compatibility, to add more stuff */
objectInputStream.readObject();
@@ -1063,7 +707,7 @@ public class VSProcess extends VSPrefs implements VSSerializable {
for (int i = 0; i < numProtocols; ++i) {
String protocolClassname = (String) objectInputStream.readObject();
- VSAbstractProtocol protocol = getProtocolObject(protocolClassname);
+ VSAbstractProtocol protocol = getProtocolObject_(protocolClassname);
protocol.deserialize(serialize, objectInputStream);
}
@@ -1075,4 +719,21 @@ public class VSProcess extends VSPrefs implements VSSerializable {
serialize.setObject(processNum, "process", this);
}
+
+ /**
+ * Sets the current color.
+ *
+ * @param newColor the new current color
+ */
+ protected void setCurrentColor(Color newColor) {
+ if (isHighlighted)
+ tmpColor = newColor;
+ else
+ currentColor = newColor;
+ }
+
+ protected abstract void updateFromPrefs_();
+ protected abstract void createRandomCrashTask_();
+ protected abstract VSAbstractProtocol getProtocolObject_(
+ String protocolClassname);
}
diff --git a/sources/core/VSInternalProcess.java b/sources/core/VSInternalProcess.java
new file mode 100644
index 0000000..e88bb76
--- /dev/null
+++ b/sources/core/VSInternalProcess.java
@@ -0,0 +1,449 @@
+/*
+ * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * All icons of the icons/ folder are under a Creative Commons
+ * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa.
+ *
+ * The icon's homepage is http://code.google.com/p/ultimate-gnome/
+ */
+
+package core;
+
+import java.awt.*;
+import java.io.*;
+import java.util.*;
+
+import core.time.*;
+import events.*;
+import events.implementations.*;
+import prefs.*;
+import protocols.*;
+import serialize.*;
+import simulator.*;
+import utils.*;
+
+/**
+ * The class VSInternalProcess, an object of this class represents a process of a
+ * simulator.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSInternalProcess extends VSAbstractProcess {
+ /**
+ * Instantiates a new process.
+ *
+ * @param prefs the simulator's default prefs
+ * @param processNum the process num
+ * @param simulatorCanvas the simulator canvas
+ * @param logging the logging object
+ */
+ public VSInternalProcess(VSPrefs prefs, int processNum,
+ VSSimulatorCanvas simulatorCanvas, VSLogging logging) {
+ super(prefs, processNum, simulatorCanvas, logging);
+ }
+
+ /**
+ * Called from the VSProcessEditor, after finishing editing! This makes
+ * sure that the VSInternalProcess object is using the up to date prefs!
+ */
+ public synchronized void updateFromPrefs() {
+ setClockVariance(getFloat("process.clock.variance"));
+ setLocalTime(getLong("process.localtime"));
+ crashedColor = getColor("col.process.crashed");
+ createRandomCrashTask();
+ }
+
+ /**
+ * Called from the VSProcessEditor, before starting editing! This makes
+ * sure that the editor edits the up to date prefs of the process!
+ */
+ public synchronized void updatePrefs() {
+ setFloat("process.clock.variance", getClockVariance());
+ setLong("process.localtime", getTime());
+ }
+
+ /**
+ * Syncs the process' time. This method is using the clockOffset and
+ * clockVariance variables. This method is called repeatedly from the
+ * VSSimulatorCanvas in order to update the process' local and global
+ * time values.
+ *
+ * @param globalTime the global time.
+ */
+ public synchronized void syncTime(final long globalTime) {
+ final long currentGlobalTimestep = globalTime - this.globalTime;
+ this.globalTime = globalTime;
+
+ localTime += currentGlobalTimestep;
+ clockOffset += currentGlobalTimestep * (double) clockVariance;
+
+ while (clockOffset >= 1) {
+ clockOffset -= 1;
+ ++localTime;
+ }
+
+ while (clockOffset <= -1) {
+ clockOffset += 1;
+ --localTime;
+ }
+
+ /* We do not want a negative time */
+ if (localTime < 0)
+ localTime = 0;
+ }
+
+ /**
+ * 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;
+ hasCrashed = false;
+ localTime = 0;
+ globalTime = 0;
+ clockOffset = 0;
+
+ for (VSAbstractProtocol protocol : protocolsToReset)
+ protocol.reset();
+
+ setCurrentColor(getColor("col.process.default"));
+ resetTimeFormats();
+ }
+
+ /**
+ * Creates the random crash task. The crash task will be created only if
+ * the process is not crashed atm. and if VSInternalProcess.getARandomCrashTime()
+ * returns a non-negative value. The random crash task uses the simulaion's
+ * global time for its scheduling.
+ */
+ public synchronized void createRandomCrashTask() {
+ if (!isCrashed) {
+ VSTaskManager taskManager = simulatorCanvas.getTaskManager();
+ long crashTime = getARandomCrashTime();
+
+ if (crashTime < 0)
+ return;
+
+ if (randomCrashTask != null)
+ taskManager.removeTask(randomCrashTask);
+
+ if (crashTime >= getGlobalTime()) {
+ VSAbstractEvent event = new VSProcessCrashEvent();
+ randomCrashTask = new VSTask(crashTime, this, event,
+ VSTask.GLOBAL);
+ taskManager.addTask(randomCrashTask);
+
+ } else {
+ randomCrashTask = null;
+ }
+ }
+ }
+
+ /**
+ * Creates a random percentage 0..100 using the process' own pseudo
+ * random number generator object of the VSRandom class.
+ *
+ * @return A random percentage 0..100.
+ */
+ public synchronized int getRandomPercentage() {
+ return random.nextInt() % 101;
+ }
+
+ /**
+ * Adds the clock offset. This method is used by the task manager. The
+ * clock offset identifies if the local time of the process has changed and
+ * how much..
+ *
+ * @param add the clock offset to add.
+ */
+ public synchronized void addClockOffset(long add) {
+ this.clockOffset += add;
+ }
+
+ /**
+ * The process' state is 'play'. Called by the simulator canvas.
+ */
+ public synchronized void play() {
+ isPaused = false;
+ setCurrentColor(getColor("col.process.running"));
+ }
+
+ /**
+ * The process' state is 'pause'. Called by the simulator canvas.
+ */
+ public synchronized void pause() {
+ isPaused = true;
+ setCurrentColor(getColor("col.process.stopped"));
+ }
+
+ /**
+ * The process' state is 'Finish'. Called by the simulator canvas.
+ */
+ public synchronized void finish() {
+ isPaused = true;
+ setCurrentColor(getColor("col.process.default"));
+ }
+
+ /**
+ * Gets the current process' color.
+ *
+ * @return the current color of the process.
+ */
+ public synchronized Color getColor() {
+ return currentColor;
+ }
+
+ /**
+ * Gets the color of this process if it's crashed.
+ *
+ * @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 in order to add a clock offset
+ * to the process object.
+ *
+ * @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;
+ }
+
+ /**
+ * 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 duration time of a message to send.
+ *
+ * @return the duration time
+ */
+ public synchronized long getDurationTime() {
+ final long maxDurationTime = getLong("message.sendingtime.max");
+ final long minDurationTime = getLong("message.sendingtime.min");
+
+ if (maxDurationTime <= minDurationTime)
+ return minDurationTime;
+
+ final int diff = (int) (maxDurationTime - minDurationTime);
+
+ /* Integer overflow */
+ if (diff <= 0)
+ return minDurationTime;
+
+ 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. It will be -1 if the message
+ * will not get lost at all.
+ */
+ public synchronized long getARandomMessageOutageTime(long durationTime,
+ VSInternalProcess receiverProcess) {
+ int percentage = (int) ((getInteger("message.prob.outage") +
+ receiverProcess.getInteger(
+ "message.prob.outage")) / 2);
+
+ /* Check if the message will have an outage or not */
+ if (getRandomPercentage() < percentage) {
+
+ /* Calculate the random outage time! */
+ long outageTime = globalTime + random.nextLong(durationTime+1) %
+ simulatorCanvas.getUntilTime();
+
+ return outageTime;
+ }
+
+ /* No outage */
+ return -1;
+ }
+
+ /**
+ * Gets the random crash task.
+ *
+ * @return the random crash task
+ */
+ public synchronized VSTask getCrashTask() {
+ return randomCrashTask;
+ }
+
+ /**
+ * Checks if the process is paused.
+ *
+ * @return true, if is paused
+ */
+ public synchronized boolean isPaused() {
+ return isPaused;
+ }
+
+ /**
+ * Called by a task if the process sends a message.
+ *
+ * @param message the message to send.
+ */
+ public synchronized void sendMessage(VSMessage message) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(prefs.getString("lang.message.sent"));
+ buffer.append("; ");
+ buffer.append(message.toStringFull());
+ logg(buffer.toString());
+ simulatorCanvas.sendMessage(message);
+ }
+
+ /**
+ * Gets the simulator canvas.
+ *
+ * @return the simulator canvas
+ */
+ public VSSimulatorCanvas getSimulatorCanvas() {
+ return simulatorCanvas;
+ }
+
+ /**
+ * Removes the process at the specified index. Called by the simulator
+ * canvas if a process has been removed from the simulator. Needed in
+ * order to update the vector time and the local processNum.
+ *
+ * @param index the index the process has to get removed.
+ */
+ public synchronized void removedAProcessAtIndex(int index) {
+ if (index < processNum)
+ --processNum;
+
+ vectorTime.remove(index);
+ for (VSVectorTime vectorTime : vectorTimeHistory)
+ vectorTime.remove(index);
+ }
+
+ /**
+ * Added a process. Needed in order to update the vector time's size.
+ * Called by the simulator canvas if a process has been added to the
+ * simulator.
+ */
+ public synchronized void addedAProcess() {
+ vectorTime.add(new Long(0));
+ for (VSVectorTime vectorTime : vectorTimeHistory)
+ vectorTime.add(new Long(0));
+ }
+
+ /**
+ * Gets the tasks of the process.
+ *
+ * @return The tasks
+ */
+ public VSPriorityQueue<VSTask> getTasks() {
+ return tasks;
+ }
+
+ /**
+ * Sets the tasks of the process.
+ *
+ * @param tasks The tasks
+ */
+ public void setTasks(VSPriorityQueue<VSTask> tasks) {
+ this.tasks = tasks;
+ }
+
+ /**
+ * Gets the protocol object.
+ *
+ * @param protocolClassname the protocol classname
+ *
+ * @return the protocol object
+ */
+ public synchronized VSAbstractProtocol getProtocolObject(
+ String protocolClassname) {
+ VSAbstractProtocol protocol = null;
+
+ if (!objectExists(protocolClassname)) {
+ protocol = (VSAbstractProtocol)
+ VSRegisteredEvents.createEventInstanceByClassname(
+ protocolClassname, this);
+
+ setObject(protocolClassname, protocol);
+ protocolsToReset.add(protocol);
+
+ } else {
+ protocol = (VSAbstractProtocol) getObject(protocolClassname);
+ }
+
+ return protocol;
+ }
+
+ /**
+ * Sets the local time.
+ *
+ * @param localTime the new local time.
+ */
+ public synchronized void setLocalTime(final long localTime) {
+ if (localTime >= 0)
+ this.localTime = localTime;
+ else
+ this.localTime = 0;
+ }
+
+
+ protected void updateFromPrefs_() {
+ updateFromPrefs();
+ }
+
+ protected void createRandomCrashTask_() {
+ createRandomCrashTask();
+ }
+
+ protected VSAbstractProtocol getProtocolObject_(String protocolClassname) {
+ return getProtocolObject(protocolClassname);
+ }
+}
diff --git a/sources/core/VSMessage.java b/sources/core/VSMessage.java
index 1f1ad5b..388f3d0 100644
--- a/sources/core/VSMessage.java
+++ b/sources/core/VSMessage.java
@@ -57,7 +57,7 @@ public class VSMessage extends VSPrefs {
private VSPrefs prefs;
/** A reference to the process who sent this message. */
- private VSProcess sendingProcess;
+ private VSInternalProcess 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
@@ -93,7 +93,7 @@ public class VSMessage extends VSPrefs {
* @param protocolClassname The classname of the protocol this message.
* @param isServerMessage Sets if the message has been sent by a server.
*/
- public void init(VSProcess process, String protocolClassname,
+ void init(VSInternalProcess process, String protocolClassname,
boolean isServerMessage) {
this.sendingProcess = process;
this.protocolClassname = protocolClassname;
@@ -136,7 +136,7 @@ public class VSMessage extends VSPrefs {
*
* @return The process which sent this message.
*/
- public VSProcess getSendingProcess() {
+ public VSInternalProcess getSendingProcess() {
return sendingProcess;
}
diff --git a/sources/core/VSMessageStub.java b/sources/core/VSMessageStub.java
new file mode 100644
index 0000000..ac70e0b
--- /dev/null
+++ b/sources/core/VSMessageStub.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * All icons of the icons/ folder are under a Creative Commons
+ * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa.
+ *
+ * The icon's homepage is http://code.google.com/p/ultimate-gnome/
+ */
+
+package core;
+
+import core.time.*;
+import events.*;
+import prefs.VSPrefs;
+
+/**
+ * An object of this class represents a message stub. A message stub allows
+ * to run the init method on a VSMessage object. The init method should be
+ * hidden by the protocol programming API.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSMessageStub {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /** The message */
+ private VSMessage message;
+
+ /**
+ * The constructor of the message stub. Creates a new message stub object.
+ *
+ * @message the message
+ */
+ public VSMessageStub(VSMessage message) {
+ this.message = message;
+ }
+
+
+ public void init(VSInternalProcess process, String protocolClassname,
+ boolean isServerMessage) {
+ message.init(process, protocolClassname, isServerMessage);
+ }
+}
+
diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java
index 9167498..285e52c 100644
--- a/sources/core/VSTask.java
+++ b/sources/core/VSTask.java
@@ -64,7 +64,7 @@ public class VSTask implements Comparable, VSSerializable {
private VSAbstractEvent event;
/** The process to run the task at. */
- private VSProcess process;
+ private VSInternalProcess process;
/** The simulator's default prefs. */
private VSPrefs prefs;
@@ -91,7 +91,7 @@ public class VSTask implements Comparable, VSSerializable {
* @param event the event
* @param isLocal the taks is local timed
*/
- public VSTask(long taskTime, VSProcess process, VSAbstractEvent event,
+ public VSTask(long taskTime, VSInternalProcess process, VSAbstractEvent event,
boolean isLocal) {
init(taskTime, process, event, isLocal);
}
@@ -137,7 +137,7 @@ public class VSTask implements Comparable, VSSerializable {
* @param event the event
* @param isLocal the taks is local timed
*/
- private void init(long taskTime, VSProcess process, VSAbstractEvent event,
+ private void init(long taskTime, VSInternalProcess process, VSAbstractEvent event,
boolean isLocal) {
this.process = process;
this.taskTime = taskTime > 0 ? taskTime : 0;
@@ -256,7 +256,7 @@ public class VSTask implements Comparable, VSSerializable {
*
* @return true, if the task is using the process
*/
- public boolean isProcess(VSProcess process) {
+ public boolean isProcess(VSInternalProcess process) {
return this.process.equals(process);
}
@@ -274,7 +274,7 @@ public class VSTask implements Comparable, VSSerializable {
*
* @return the process of the event
*/
- public VSProcess getProcess() {
+ public VSInternalProcess getProcess() {
return process;
}
@@ -285,6 +285,10 @@ public class VSTask implements Comparable, VSSerializable {
if (event.getProcess() == null)
event.init(process);
+ if (!(event instanceof VSMessageReceiveEvent)
+ && !(event instanceof VSAbstractProtocol))
+ process.increaseVectorAndLamportTimeIfAll();
+
event.onStart();
}
@@ -311,7 +315,7 @@ public class VSTask implements Comparable, VSSerializable {
*
* @param process the process
*/
- public void setProcess(VSProcess process) {
+ public void setProcess(VSInternalProcess process) {
/* Only do it if the process differs */
if (!this.process.equals(process)) {
this.process = process;
@@ -484,8 +488,8 @@ public class VSTask implements Comparable, VSSerializable {
objectInputStream.readObject();
int processNum = ((Integer) objectInputStream.readObject()).intValue();
- VSProcess process = (VSProcess)
- serialize.getObject(processNum, "process");
+ VSInternalProcess process = (VSInternalProcess)
+ serialize.getObject(processNum, "process");
String eventClassname = (String) objectInputStream.readObject();
int eventID = ((Integer) objectInputStream.readObject()).intValue();
diff --git a/sources/core/VSTaskManager.java b/sources/core/VSTaskManager.java
index a435401..2161469 100644
--- a/sources/core/VSTaskManager.java
+++ b/sources/core/VSTaskManager.java
@@ -104,7 +104,7 @@ public class VSTaskManager implements VSSerializable {
long globalTime;
final long globalOffsetTime = lastGlobalTime + step;
boolean redo;
- ArrayList<VSProcess> processes = simulatorCanvas.getProcesses();
+ ArrayList<VSInternalProcess> processes = simulatorCanvas.getProcesses();
do {
redo = false;
@@ -112,7 +112,7 @@ public class VSTaskManager implements VSSerializable {
/* Run tasks which have for its schedule the global time */
while (globalTasks.size() != 0) {
task = globalTasks.peek();
- VSProcess process = task.getProcess();
+ VSInternalProcess process = task.getProcess();
localTime = process.getTime();
offsetTime = localTime + step;
taskTime = task.getTaskTime();
@@ -165,7 +165,7 @@ public class VSTaskManager implements VSSerializable {
}
synchronized (processes) {
- for (VSProcess process : processes) {
+ for (VSInternalProcess process : processes) {
PriorityQueue<VSTask> tasks = process.getTasks();
/* Run tasks which have for its schedule the local
@@ -232,11 +232,11 @@ public class VSTaskManager implements VSSerializable {
* Resets the task manager.
*/
public synchronized void reset() {
- ArrayList<VSProcess> processes = simulatorCanvas.getProcesses();
+ ArrayList<VSInternalProcess> processes = simulatorCanvas.getProcesses();
PriorityQueue<VSTask> tmp = null;
synchronized (processes) {
- for (VSProcess process : processes) {
+ for (VSInternalProcess process : processes) {
tmp = process.getTasks();
process.setTasks(new VSPriorityQueue<VSTask>());
@@ -337,7 +337,7 @@ public class VSTaskManager implements VSSerializable {
*
* @param process the process to remove the tasks of
*/
- public synchronized void removeTasksOf(VSProcess process) {
+ public synchronized void removeTasksOf(VSInternalProcess process) {
ArrayList<VSTask> removeThose = new ArrayList<VSTask>();
for (VSTask task : fullfilledProgrammedTasks)
@@ -366,14 +366,14 @@ public class VSTaskManager implements VSSerializable {
*/
public synchronized ArrayList<VSTask> getLocalTasks() {
ArrayList<VSTask> localTasks = new ArrayList<VSTask>();
- ArrayList<VSProcess> processes = simulatorCanvas.getProcesses();
+ ArrayList<VSInternalProcess> processes = simulatorCanvas.getProcesses();
for (VSTask task : fullfilledProgrammedTasks)
if (!task.isGlobalTimed())
localTasks.add(task);
synchronized (processes) {
- for (VSProcess process : processes) {
+ for (VSInternalProcess process : processes) {
VSPriorityQueue<VSTask> tasks = process.getTasks();
for (VSTask task : tasks)
localTasks.add(task);
@@ -410,7 +410,7 @@ public class VSTaskManager implements VSSerializable {
* @return the local tasks of the specified process
*/
public synchronized ArrayList<VSTask> getProcessLocalTasks(
- VSProcess process) {
+ VSInternalProcess process) {
ArrayList<VSTask> processTasks = new ArrayList<VSTask>();
VSPriorityQueue<VSTask> tasks = process.getTasks();
@@ -434,7 +434,7 @@ public class VSTaskManager implements VSSerializable {
* @return the global timed tasks of the specified process
*/
public synchronized ArrayList<VSTask> getProcessGlobalTasks(
- VSProcess process) {
+ VSInternalProcess process) {
ArrayList<VSTask> processTasks = new ArrayList<VSTask>();
for (VSTask task : fullfilledProgrammedTasks)
@@ -476,9 +476,9 @@ public class VSTaskManager implements VSSerializable {
buffer.append(prefs.getString("lang.tasks.local"));
buffer.append(": ");
- ArrayList<VSProcess> processes = simulatorCanvas.getProcesses();
+ ArrayList<VSInternalProcess> processes = simulatorCanvas.getProcesses();
synchronized (processes) {
- for (VSProcess process : processes) {
+ for (VSInternalProcess process : processes) {
VSPriorityQueue<VSTask> tasks = process.getTasks();
for (VSTask task : tasks) {
buffer.append(task);
@@ -517,10 +517,10 @@ public class VSTaskManager implements VSSerializable {
serializeThoseTasks.add(task);
}
- ArrayList<VSProcess> processes = simulatorCanvas.getProcesses();
+ ArrayList<VSInternalProcess> processes = simulatorCanvas.getProcesses();
synchronized (processes) {
- for (VSProcess process : processes) {
+ for (VSInternalProcess process : processes) {
VSPriorityQueue<VSTask> localTasks = process.getTasks();
for (VSTask task : localTasks) {
if (!task.hasNotSerializableEvent())
@@ -554,9 +554,9 @@ public class VSTaskManager implements VSSerializable {
globalTasks.clear();
- ArrayList<VSProcess> processes = simulatorCanvas.getProcesses();
+ ArrayList<VSInternalProcess> processes = simulatorCanvas.getProcesses();
synchronized (processes) {
- for (VSProcess process : processes)
+ for (VSInternalProcess process : processes)
process.getTasks().clear();
}
diff --git a/sources/events/VSAbstractEvent.java b/sources/events/VSAbstractEvent.java
index 510169b..d2c1352 100644
--- a/sources/events/VSAbstractEvent.java
+++ b/sources/events/VSAbstractEvent.java
@@ -25,7 +25,7 @@ package events;
import java.io.*;
-import core.VSProcess;
+import core.VSInternalProcess;
import exceptions.*;
import prefs.VSPrefs;
import serialize.*;
@@ -46,7 +46,7 @@ abstract public class VSAbstractEvent extends VSPrefs {
public VSPrefs prefs;
/** The process. */
- public VSProcess process;
+ public VSInternalProcess process;
/** The event shortname. */
private String eventShortname;
@@ -60,7 +60,7 @@ abstract public class VSAbstractEvent extends VSPrefs {
* @param theProcess The new process
* @return The copy
*/
- final public VSAbstractEvent getCopy(VSProcess theProcess)
+ final public VSAbstractEvent getCopy(VSInternalProcess theProcess)
throws VSEventNotCopyableException {
if (theProcess == null)
@@ -94,7 +94,7 @@ abstract public class VSAbstractEvent extends VSPrefs {
*
* @param process the process
*/
- public void init(VSProcess process) {
+ public void init(VSInternalProcess process) {
if (this.process == null) {
this.process = process;
this.prefs = process.getPrefs();
@@ -166,7 +166,7 @@ abstract public class VSAbstractEvent extends VSPrefs {
*
* @return the process
*/
- public VSProcess getProcess() {
+ public VSInternalProcess getProcess() {
return process;
}
diff --git a/sources/events/VSRegisteredEvents.java b/sources/events/VSRegisteredEvents.java
index 5f188d9..15c4023 100644
--- a/sources/events/VSRegisteredEvents.java
+++ b/sources/events/VSRegisteredEvents.java
@@ -89,8 +89,8 @@ public final class VSRegisteredEvents {
"Basic Multicast", "Basic Multicast");
registerEvent("protocols.implementations.VSBerkelyTimeProtocol",
"Berkeley Algorithmus zur internen Sync.", "Berkeley");
- registerEvent("protocols.implementations.VSBroadcastSturmProtocol",
- "Broadcaststurm", null);
+ registerEvent("protocols.implementations.VSBroadcastProtocol",
+ "Broadcast", null);
registerEvent("protocols.implementations.VSDummyProtocol",
"Beispiel/Dummy", null);
registerEvent("protocols.implementations.VSExternalTimeSyncProtocol",
@@ -322,7 +322,7 @@ public final class VSRegisteredEvents {
* @return An instance of the event classname, if exists. Else null.
*/
public static VSAbstractEvent createEventInstanceByClassname(
- String eventClassname, VSProcess process) {
+ String eventClassname, VSInternalProcess process) {
Object protocolObj = new VSClassLoader().newInstance(eventClassname);
if (protocolObj instanceof VSAbstractEvent) {
@@ -343,7 +343,7 @@ public final class VSRegisteredEvents {
* @return An instance of the event, if exists. Else null.
*/
public static VSAbstractEvent createEventInstanceByName(String eventName,
- VSProcess process) {
+ VSInternalProcess process) {
return createEventInstanceByClassname(
eventClassnamesByNames.get(eventName), process);
}
diff --git a/sources/prefs/VSDefaultPrefs.java b/sources/prefs/VSDefaultPrefs.java
index afd79de..3865947 100644
--- a/sources/prefs/VSDefaultPrefs.java
+++ b/sources/prefs/VSDefaultPrefs.java
@@ -274,5 +274,7 @@ public class VSDefaultPrefs extends VSPrefs {
initBoolean("sim.message.prob.mean", true, "Mittelwerte der Nachrichtverlustw'k. bilden");
initBoolean("sim.messages.relevant", true, "Nur relevante Nachrichten anzeigen");
initBoolean("sim.periodic", false, "Simulation periodisch wiederholen");
+ initBoolean("sim.update.lamporttime.all", false, "Lamportzeiten betreffen alle Ereignisse");
+ initBoolean("sim.update.vectortime.all", false, "Vektorzeiten betreffen alle Ereignisse");
}
}
diff --git a/sources/prefs/editors/VSProcessEditor.java b/sources/prefs/editors/VSProcessEditor.java
index 904bfff..ae2a61f 100644
--- a/sources/prefs/editors/VSProcessEditor.java
+++ b/sources/prefs/editors/VSProcessEditor.java
@@ -33,7 +33,7 @@ import events.*;
import prefs.VSPrefs;
/**
- * The class VSProcessEditor, is for editing a VSProcess object.
+ * The class VSProcessEditor, is for editing a VSInternalProcess object.
*
* @author Paul C. Buetow
*/
@@ -42,7 +42,7 @@ public class VSProcessEditor extends VSAbstractBetterEditor {
private static final long serialVersionUID = 1L;
/** The process. */
- private VSProcess process;
+ private VSInternalProcess process;
/** The TAKEOVE r_ button. */
public static boolean TAKEOVER_BUTTON;
@@ -53,7 +53,7 @@ public class VSProcessEditor extends VSAbstractBetterEditor {
* @param prefs the prefs
* @param process the process
*/
- public VSProcessEditor(VSPrefs prefs, VSProcess process) {
+ public VSProcessEditor(VSPrefs prefs, VSInternalProcess process) {
super(prefs, process, prefs.getString("lang.name") + " - " +
prefs.getString("lang.prefs.process"));;
this.process = process;
diff --git a/sources/protocols/VSAbstractProtocol.java b/sources/protocols/VSAbstractProtocol.java
index 7c3cd2e..dfa87a5 100644
--- a/sources/protocols/VSAbstractProtocol.java
+++ b/sources/protocols/VSAbstractProtocol.java
@@ -94,10 +94,12 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent {
process.increaseLamportTime();
process.increaseVectorTime();
+ VSMessageStub stub = new VSMessageStub(message);
+
if (currentContextIsServer)
- message.init(process, getClassname(), VSMessage.IS_SERVER_MESSAGE);
+ stub.init(process, getClassname(), VSMessage.IS_SERVER_MESSAGE);
else
- message.init(process, getClassname(), VSMessage.IS_CLIENT_MESSAGE);
+ stub.init(process, getClassname(), VSMessage.IS_CLIENT_MESSAGE);
process.sendMessage(message);
}
diff --git a/sources/protocols/implementations/VSBerkelyTimeProtocol.java b/sources/protocols/implementations/VSBerkelyTimeProtocol.java
index f432a1f..382a470 100644
--- a/sources/protocols/implementations/VSBerkelyTimeProtocol.java
+++ b/sources/protocols/implementations/VSBerkelyTimeProtocol.java
@@ -80,7 +80,7 @@ public class VSBerkelyTimeProtocol extends VSAbstractProtocol {
* @see protocols.VSAbstractProtocol#onServerReset()
*/
public void onServerReset() {
- //System.out.println("FOOBAR");
+ //System.out.println("FOOBAR");
processTimes.clear();
recvTimes.clear();
realTimesRTT.clear();
@@ -91,7 +91,7 @@ public class VSBerkelyTimeProtocol extends VSAbstractProtocol {
* @see protocols.VSAbstractProtocol#onServerStart()
*/
public void onServerStart() {
- //System.out.println("FOO");
+ //System.out.println("FOO");
peers.addAll(getVector("pids"));
requestTime = process.getTime();
VSMessage message = new VSMessage();
diff --git a/sources/protocols/implementations/VSBroadcastProtocol.java b/sources/protocols/implementations/VSBroadcastProtocol.java
new file mode 100644
index 0000000..0ae8fae
--- /dev/null
+++ b/sources/protocols/implementations/VSBroadcastProtocol.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * All icons of the icons/ folder are under a Creative Commons
+ * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa.
+ *
+ * The icon's homepage is http://code.google.com/p/ultimate-gnome/
+ */
+
+package protocols.implementations;
+
+import java.util.ArrayList;
+
+import core.VSMessage;
+import protocols.VSAbstractProtocol;
+
+/**
+ * The class VSBroadcastProtocol, an implementation of the broadcast
+ * sturm protocol.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSBroadcastProtocol extends VSAbstractProtocol {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /** The sent messages. */
+ private ArrayList<Integer> sentMessages;
+
+ /** The broadcast count. */
+ private static int broadcastCount;
+
+ /**
+ * Instantiates a new broadcast sturm protocol.
+ */
+ public VSBroadcastProtocol() {
+ super(VSAbstractProtocol.HAS_ON_CLIENT_START);
+ setClassname(getClass().toString());
+ sentMessages = new ArrayList<Integer>();
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractProtocol#onClientInit()
+ */
+ public void onClientInit() {
+ }
+
+ /* (non-Javadoc)
+ * @see protocols.VSAbstractProtocol#onClientReset()
+ */
+ public void onClientReset() {
+ }
+
+ /* (non-Javadoc)
+ * @see protocols.VSAbstractProtocol#onClientStart()
+ */
+ public void onClientStart() {
+ VSMessage message = new VSMessage();
+ message.setInteger("Broadcast", broadcastCount++);
+ sentMessages.add(message.getIntegerObj("Broadcast"));
+ sendMessage(message);
+ }
+
+ /* (non-Javadoc)
+ * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage)
+ */
+ public void onClientRecv(VSMessage recvMessage) {
+ onServerRecv(recvMessage);
+ }
+
+ /* (non-Javadoc)
+ * @see protocols.VSAbstractProtocol#onClientSchedule()
+ */
+ public void onClientSchedule() {
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractProtocol#onServerInit()
+ */
+ public void onServerInit() {
+ }
+
+ /* (non-Javadoc)
+ * @see protocols.VSAbstractProtocol#onServerReset()
+ */
+ public void onServerReset() {
+ sentMessages.clear();
+ }
+
+ /* (non-Javadoc)
+ * @see protocols.VSAbstractProtocol#onServerSchedule()
+ */
+ public void onServerSchedule() {
+ }
+
+ /* (non-Javadoc)
+ * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage)
+ */
+ public void onServerRecv(VSMessage recvMessage) {
+ if (!sentMessages.contains(recvMessage.getIntegerObj("Broadcast"))) {
+ VSMessage message = new VSMessage();
+ message.setInteger("Broadcast",
+ recvMessage.getInteger("Broadcast"));
+ sentMessages.add(message.getIntegerObj("Broadcast"));
+ sendMessage(message);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see protocols.VSAbstractProtocol#toString()
+ */
+ public String toString() {
+ return super.toString();
+ }
+}
diff --git a/sources/protocols/implementations/VSOnePhaseCommitProtocol.java b/sources/protocols/implementations/VSOnePhaseCommitProtocol.java
index 3c4e20e..0581b74 100644
--- a/sources/protocols/implementations/VSOnePhaseCommitProtocol.java
+++ b/sources/protocols/implementations/VSOnePhaseCommitProtocol.java
@@ -116,7 +116,7 @@ public class VSOnePhaseCommitProtocol extends VSAbstractProtocol {
/* Remove the active schedule which has been created in the
onServerStart method */
removeSchedules();
- }
+ }
}
}
diff --git a/sources/protocols/implementations/VSReliableMulticastProtocol.java b/sources/protocols/implementations/VSReliableMulticastProtocol.java
index 8a605fd..b876295 100644
--- a/sources/protocols/implementations/VSReliableMulticastProtocol.java
+++ b/sources/protocols/implementations/VSReliableMulticastProtocol.java
@@ -89,7 +89,7 @@ public class VSReliableMulticastProtocol extends VSAbstractProtocol {
VSMessage message = new VSMessage();
message.setBoolean("isMulticast", true);
sendMessage(message);
- }
+ }
}
/* (non-Javadoc)
@@ -124,8 +124,8 @@ public class VSReliableMulticastProtocol extends VSAbstractProtocol {
onClientStart();
}
- /** True if ACK has been sent already */
- private boolean ackSent;
+ /** True if ACK has been sent already */
+ private boolean ackSent;
/* (non-Javadoc)
* @see events.VSAbstractProtocol#onServerInit()
@@ -137,7 +137,7 @@ public class VSReliableMulticastProtocol extends VSAbstractProtocol {
* @see protocols.VSAbstractProtocol#onServerReset()
*/
public void onServerReset() {
- ackSent = false;
+ ackSent = false;
}
/* (non-Javadoc)
@@ -150,13 +150,13 @@ public class VSReliableMulticastProtocol extends VSAbstractProtocol {
message.setInteger("pid", process.getProcessID());
sendMessage(message);
- if (ackSent) {
- logg("ACK erneut versendet");
+ if (ackSent) {
+ logg("ACK erneut versendet");
- } else {
- logg("ACK versendet");
- ackSent = true;
- }
+ } else {
+ logg("ACK versendet");
+ ackSent = true;
+ }
}
}
diff --git a/sources/simulator/VSCreateTask.java b/sources/simulator/VSCreateTask.java
index 1363c6c..346263d 100644
--- a/sources/simulator/VSCreateTask.java
+++ b/sources/simulator/VSCreateTask.java
@@ -174,7 +174,7 @@ public class VSCreateTask {
*
* @return the new task
*/
- public VSTask createTask(VSProcess process, long time,
+ public VSTask createTask(VSInternalProcess process, long time,
boolean localTimedTask) {
VSAbstractEvent event = null;
diff --git a/sources/simulator/VSSimulator.java b/sources/simulator/VSSimulator.java
index ae3c2db..31b5631 100644
--- a/sources/simulator/VSSimulator.java
+++ b/sources/simulator/VSSimulator.java
@@ -212,7 +212,7 @@ public class VSSimulator extends JPanel implements VSSerializable {
* @param localTask true, if this table manages the local task. false,
* if this table manages the global tasks.
*/
- public VSTaskManagerTableModel(VSProcess process, boolean localTask) {
+ public VSTaskManagerTableModel(VSInternalProcess process, boolean localTask) {
tasks = new ArrayList<VSTask>();
set(process, localTask, ONE_PROCESS);
columnNames = new String[3];
@@ -249,7 +249,7 @@ public class VSSimulator extends JPanel implements VSSerializable {
* @param allProcesses true, if this table shows tasks of all processes.
* false, if this table only shows tasks of the specified process.
*/
- public void set(VSProcess process, boolean localTasks,
+ public void set(VSInternalProcess process, boolean localTasks,
boolean allProcesses) {
this.allProcesses = allProcesses;
@@ -516,8 +516,8 @@ public class VSSimulator extends JPanel implements VSSerializable {
public void actionPerformed(ActionEvent ae) {
try {
Long val = Long.valueOf(valField.getText());
- if (val.longValue() < 0)
- throw new VSNegativeNumberException();
+ if (val.longValue() < 0)
+ throw new VSNegativeNumberException();
VSTask task = model.removeTaskAtRow(row);
task.setTaskTime(val.longValue());
taskManager.addTask(task, VSTaskManager.PROGRAMMED);
@@ -539,7 +539,7 @@ public class VSSimulator extends JPanel implements VSSerializable {
} catch (VSNegativeNumberException exc) {
valField.setBackground(Color.RED);
isRed = true;
- }
+ }
}
});
return valField;
@@ -557,7 +557,7 @@ public class VSSimulator extends JPanel implements VSSerializable {
int index = comboBox.getSelectedIndex() - 1;
if (model.rowExists(row)) {
VSTask task = model.removeTaskAtRow(row);
- VSProcess process =
+ VSInternalProcess process =
simulatorCanvas.getProcess(index);
task.setProcess(process);
taskManager.addTask(task, VSTaskManager.PROGRAMMED);
@@ -892,7 +892,7 @@ public class VSSimulator extends JPanel implements VSSerializable {
}
if (processNum != simulatorCanvas.getNumProcesses()) {
- VSProcess process = getSelectedProcess();
+ VSInternalProcess process = getSelectedProcess();
VSProcessEditor processEditor =
new VSProcessEditor(prefs, process);
tabbedPane.setComponentAt(1,
@@ -961,7 +961,7 @@ public class VSSimulator extends JPanel implements VSSerializable {
* @return the table
*/
private JTable createTaskTable(boolean localTasks) {
- VSProcess process = getSelectedProcess();
+ VSInternalProcess process = getSelectedProcess();
VSTaskManagerTableModel model =
new VSTaskManagerTableModel(process, localTasks);
VSTaskManagerCellEditor cellEditor =
@@ -1076,17 +1076,17 @@ public class VSSimulator extends JPanel implements VSSerializable {
}
private boolean takeover(long time) {
- VSProcess selectedProcess = getSelectedProcess();
+ VSInternalProcess selectedProcess = getSelectedProcess();
int index = comboBox.getSelectedIndex();
VSCreateTask createTask = createTasks.get(index);
if (createTask.isDummy())
return false;
- ArrayList<VSProcess> processes =
+ ArrayList<VSInternalProcess> processes =
getConcernedProcesses(localTasks);
- for (VSProcess process : processes) {
+ for (VSInternalProcess process : processes) {
VSTask task = createTask.createTask(process, time,
localTasks);
taskManager.addTask(task, VSTaskManager.PROGRAMMED);
@@ -1266,7 +1266,7 @@ public class VSSimulator extends JPanel implements VSSerializable {
*
* @return the selected process
*/
- private VSProcess getSelectedProcess() {
+ private VSInternalProcess getSelectedProcess() {
int processNum = getSelectedProcessNum();
return simulatorCanvas.getProcess(processNum);
}
@@ -1279,7 +1279,7 @@ public class VSSimulator extends JPanel implements VSSerializable {
*
* @return the concerned processes
*/
- private ArrayList<VSProcess> getConcernedProcesses(boolean localTasks) {
+ private ArrayList<VSInternalProcess> getConcernedProcesses(boolean localTasks) {
int processNum = localTasks
? localPIDComboBox.getSelectedIndex()
: globalPIDComboBox.getSelectedIndex();
@@ -1287,7 +1287,7 @@ public class VSSimulator extends JPanel implements VSSerializable {
if (processNum == simulatorCanvas.getNumProcesses())
return simulatorCanvas.getProcessesArray();
- ArrayList<VSProcess> arr = new ArrayList<VSProcess>();
+ ArrayList<VSInternalProcess> arr = new ArrayList<VSInternalProcess>();
arr.add(simulatorCanvas.getProcess(processNum));
return arr;
@@ -1297,7 +1297,7 @@ public class VSSimulator extends JPanel implements VSSerializable {
* Update task manager table.
*/
public synchronized void updateTaskManagerTable() {
- VSProcess process = getSelectedProcess();
+ VSInternalProcess process = getSelectedProcess();
boolean allProcesses = process == null;
taskManagerLocalEditor.stopEditing();
@@ -1459,7 +1459,7 @@ public class VSSimulator extends JPanel implements VSSerializable {
/* Update the 'Variables tab' */
if (getSelectedProcessNum() != simulatorCanvas.getNumProcesses()) {
- VSProcess process = getSelectedProcess();
+ VSInternalProcess process = getSelectedProcess();
VSProcessEditor editor = new VSProcessEditor(prefs, process);
tabbedPane.setComponentAt(1, editor.getContentPane());
}
diff --git a/sources/simulator/VSSimulatorCanvas.java b/sources/simulator/VSSimulatorCanvas.java
index a00d3ad..baf4b3e 100644
--- a/sources/simulator/VSSimulatorCanvas.java
+++ b/sources/simulator/VSSimulatorCanvas.java
@@ -56,7 +56,7 @@ public class VSSimulatorCanvas extends Canvas
private static final long serialVersionUID = 1L;
/** The highlighted process. */
- private VSProcess highlightedProcess;
+ private VSInternalProcess highlightedProcess;
/** The simulator. */
private VSSimulator simulator;
@@ -125,7 +125,7 @@ public class VSSimulatorCanvas extends Canvas
private LinkedList<VSMessageLine> messageLinesToRemove;
/** The processes. */
- private ArrayList<VSProcess> processes;
+ private ArrayList<VSInternalProcess> processes;
/** The clock speed. */
private double clockSpeed;
@@ -242,7 +242,7 @@ public class VSSimulatorCanvas extends Canvas
private static final long serialVersionUID = 1L;
/** The receiver process. */
- private VSProcess receiverProcess;
+ private VSInternalProcess receiverProcess;
/** The color. */
private Color color;
@@ -312,7 +312,7 @@ public class VSSimulatorCanvas extends Canvas
* @param receiverNum the receiver num
* @param task the task
*/
- public VSMessageLine(VSProcess receiverProcess, long sendTime,
+ public VSMessageLine(VSInternalProcess receiverProcess, long sendTime,
long recvTime, long outageTime, int senderNum ,
int receiverNum, VSTask task) {
this.receiverProcess = receiverProcess;
@@ -500,7 +500,7 @@ public class VSSimulatorCanvas extends Canvas
/* May be not null if called from deserialization */
if (this.processes == null) {
- this.processes = new ArrayList<VSProcess>();
+ this.processes = new ArrayList<VSInternalProcess>();
numProcesses = prefs.getInteger("sim.process.num");
@@ -515,7 +515,7 @@ public class VSSimulatorCanvas extends Canvas
addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent me) {
- final VSProcess process = getProcessAtYPos(me.getY());
+ final VSInternalProcess process = getProcessAtYPos(me.getY());
if (SwingUtilities.isRightMouseButton(me)) {
ActionListener actionListener = new ActionListener() {
@@ -721,7 +721,7 @@ public class VSSimulatorCanvas extends Canvas
public void mouseDragged(MouseEvent e) { }
public void mouseMoved(MouseEvent e) {
- VSProcess p = getProcessAtYPos(e.getY());
+ VSInternalProcess p = getProcessAtYPos(e.getY());
if (p == null) {
if (highlightedProcess != null) {
@@ -864,7 +864,7 @@ public class VSSimulatorCanvas extends Canvas
taskManager.runTasks(l, offset, lastSimulatorTime);
synchronized (processes) {
- for (VSProcess process : processes)
+ for (VSInternalProcess process : processes)
process.syncTime(simulatorTime);
}
}
@@ -939,7 +939,7 @@ public class VSSimulatorCanvas extends Canvas
};
synchronized (processes) {
- for (VSProcess process : processes) {
+ for (VSInternalProcess process : processes) {
final long localTime = process.getTime();
g.setColor(process.getColor());
@@ -1006,7 +1006,7 @@ public class VSSimulatorCanvas extends Canvas
* @param distance the distance
*/
private void paintTime(final Graphics2D g, final VSTime times[],
- final VSProcess process, final int yStart,
+ final VSInternalProcess process, final int yStart,
final int distance) {
final int lastPos[] = { -1, -1, -1, -1 };
@@ -1106,7 +1106,7 @@ public class VSSimulatorCanvas extends Canvas
*
* @return the process at y pos
*/
- private VSProcess getProcessAtYPos(int yPos) {
+ private VSInternalProcess getProcessAtYPos(int yPos) {
final int reachDistance = (int) (yDistance/3);
int y = YOFFSET + YOUTER_SPACEING + YSEPLINE_SPACEING;
@@ -1120,7 +1120,7 @@ public class VSSimulatorCanvas extends Canvas
for (int i = 0; i < numProcesses; ++i) {
if (yPos < y + reachDistance && yPos > y - reachDistance -
LINE_WIDTH) {
- VSProcess process = null;
+ VSInternalProcess process = null;
synchronized (processes) {
process = processes.get(i);
}
@@ -1244,7 +1244,7 @@ public class VSSimulatorCanvas extends Canvas
*
* @return the process
*/
- public VSProcess getProcess(int processNum) {
+ public VSInternalProcess getProcess(int processNum) {
synchronized (processes) {
if (processNum >= processes.size())
return null;
@@ -1304,7 +1304,7 @@ public class VSSimulatorCanvas extends Canvas
final long currentTime = System.currentTimeMillis();
synchronized (processes) {
- for (VSProcess p : processes)
+ for (VSInternalProcess p : processes)
p.play();
}
@@ -1332,7 +1332,7 @@ public class VSSimulatorCanvas extends Canvas
*/
public void finish() {
synchronized (processes) {
- for (VSProcess p : processes)
+ for (VSInternalProcess p : processes)
p.finish();
}
@@ -1354,7 +1354,7 @@ public class VSSimulatorCanvas extends Canvas
public void pause() {
isPaused = true;
synchronized (processes) {
- for (VSProcess p : processes)
+ for (VSInternalProcess p : processes)
p.pause();
}
@@ -1380,7 +1380,7 @@ public class VSSimulatorCanvas extends Canvas
simulatorTime = 0;
synchronized (processes) {
- for (VSProcess process : processes)
+ for (VSInternalProcess process : processes)
process.reset();
}
@@ -1389,7 +1389,7 @@ public class VSSimulatorCanvas extends Canvas
taskManager.reset();
synchronized (processes) {
- for (VSProcess process : processes)
+ for (VSInternalProcess process : processes)
process.createRandomCrashTask();
}
@@ -1466,12 +1466,12 @@ public class VSSimulatorCanvas extends Canvas
public void sendMessage(VSMessage message) {
VSTask task = null;
VSAbstractEvent receiveEvent = null;
- VSProcess sendingProcess = message.getSendingProcess();
+ VSInternalProcess sendingProcess = message.getSendingProcess();
long deliverTime, outageTime, durationTime;
boolean recvOwn = prefs.getBoolean("sim.message.own.recv");
synchronized (processes) {
- for (VSProcess receiverProcess : processes) {
+ for (VSInternalProcess receiverProcess : processes) {
if (receiverProcess.equals(sendingProcess)) {
if (recvOwn) {
deliverTime = sendingProcess.getGlobalTime();
@@ -1523,7 +1523,7 @@ public class VSSimulatorCanvas extends Canvas
*/
public void editProcess(int processNum) {
synchronized (processes) {
- VSProcess process = processes.get(processNum);
+ VSInternalProcess process = processes.get(processNum);
/* May be null if another thread changed the processes arraylist
before this process actually called editProcess */
if (process != null)
@@ -1536,7 +1536,7 @@ public class VSSimulatorCanvas extends Canvas
*
* @param process the process
*/
- public void editProcess(VSProcess process) {
+ public void editProcess(VSInternalProcess process) {
if (process != null) {
process.updatePrefs();
new VSEditorFrame(prefs, simulator.getSimulatorFrame(),
@@ -1549,11 +1549,11 @@ public class VSSimulatorCanvas extends Canvas
*
* @return the processes array
*/
- public ArrayList<VSProcess> getProcessesArray() {
- ArrayList<VSProcess> arr = new ArrayList<VSProcess>();
+ public ArrayList<VSInternalProcess> getProcessesArray() {
+ ArrayList<VSInternalProcess> arr = new ArrayList<VSInternalProcess>();
synchronized (processes) {
- for (VSProcess process : processes)
+ for (VSInternalProcess process : processes)
arr.add(process);
}
@@ -1582,7 +1582,7 @@ public class VSSimulatorCanvas extends Canvas
*
* @return the processes
*/
- public ArrayList<VSProcess> getProcesses() {
+ public ArrayList<VSInternalProcess> getProcesses() {
return processes;
}
@@ -1621,7 +1621,7 @@ public class VSSimulatorCanvas extends Canvas
*
* @param process the process
*/
- private void removeProcess(VSProcess process) {
+ private void removeProcess(VSInternalProcess process) {
if (numProcesses == 1) {
simulator.getSimulatorFrame().removeSimulator(simulator);
@@ -1631,7 +1631,7 @@ public class VSSimulatorCanvas extends Canvas
index = processes.indexOf(process);
processes.remove(index);
- for (VSProcess p : processes)
+ for (VSInternalProcess p : processes)
p.removedAProcessAtIndex(index);
numProcesses = processes.size();
@@ -1668,8 +1668,8 @@ public class VSSimulatorCanvas extends Canvas
*
* @return the new process
*/
- private VSProcess createProcess(int processNum) {
- VSProcess process = new VSProcess(prefs, processNum, this, logging);
+ private VSInternalProcess createProcess(int processNum) {
+ VSInternalProcess process = new VSInternalProcess(prefs, processNum, this, logging);
logging.logg(prefs.getString("lang.process.new") + "; " + process);
return process;
}
@@ -1679,8 +1679,8 @@ public class VSSimulatorCanvas extends Canvas
*
* @return The process which has been added
*/
- private VSProcess addProcess() {
- VSProcess newProcess = null;
+ private VSInternalProcess addProcess() {
+ VSInternalProcess newProcess = null;
//int foo = -1;
//System.out.println("ADD " + ++foo);
synchronized (processes) {
@@ -1703,14 +1703,14 @@ public class VSSimulatorCanvas extends Canvas
*
* @newProcess The process to add
*/
- private void addProcess(VSProcess newProcess) {
+ private void addProcess(VSInternalProcess newProcess) {
//int foo = -1;
//System.out.println("ADD_ " + ++foo);
synchronized (processes) {
//System.out.println("ADD_ " + ++foo);
processes.add(newProcess);
- for (VSProcess process : processes)
+ for (VSInternalProcess process : processes)
if (!process.equals(newProcess))
process.addedAProcess();
//System.out.println("ADD_ " + ++foo);
@@ -1764,7 +1764,7 @@ public class VSSimulatorCanvas extends Canvas
synchronized (processes) {
objectOutputStream.writeObject(new Integer(numProcesses));
- for (VSProcess process : processes)
+ for (VSInternalProcess process : processes)
process.serialize(serialize, objectOutputStream);
}
diff --git a/sources/simulator/VSSimulatorFrame.java b/sources/simulator/VSSimulatorFrame.java
index b42f6f7..4d97b6e 100644
--- a/sources/simulator/VSSimulatorFrame.java
+++ b/sources/simulator/VSSimulatorFrame.java
@@ -440,13 +440,13 @@ public class VSSimulatorFrame extends VSFrame {
return;
String processString = prefs.getString("lang.process");
- ArrayList<VSProcess> arr =
+ ArrayList<VSInternalProcess> arr =
currentSimulator.getSimulatorCanvas().getProcessesArray();
int numProcesses = arr.size();
int processNum = 0;
- for (VSProcess process : arr) {
+ for (VSInternalProcess process : arr) {
int processID = process.getProcessID();
JMenuItem processItem = new JMenuItem(processString + " " +
processID);