diff options
| author | Paul Buetow <paul@buetow.org> | 2008-05-25 08:10:13 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-05-25 08:10:13 +0000 |
| commit | c015d586d22b69078b6da61858e5675793856b0b (patch) | |
| tree | efbc9881cf59363abef52a0beb5eedf9e81a224a /sources/core | |
| parent | 62fe28f0b0b0c9ebde18a6dc33907889ff3aa21b (diff) | |
JAutoDoc :)
Diffstat (limited to 'sources/core')
| -rw-r--r-- | sources/core/VSMessage.java | 76 | ||||
| -rw-r--r-- | sources/core/VSProcess.java | 343 | ||||
| -rw-r--r-- | sources/core/VSTask.java | 121 | ||||
| -rw-r--r-- | sources/core/VSTaskManager.java | 90 | ||||
| -rw-r--r-- | sources/core/time/VSLamportTime.java | 28 | ||||
| -rw-r--r-- | sources/core/time/VSTime.java | 16 | ||||
| -rw-r--r-- | sources/core/time/VSVectorTime.java | 39 |
7 files changed, 667 insertions, 46 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#fillWithDefaults() + */ public void fillWithDefaults() { prefs.copyIntegers(this, DEFAULT_INTEGER_VALUE_KEYS); prefs.copyLongs(this, DEFAULT_LONG_VALUE_KEYS); @@ -488,6 +777,9 @@ public class VSProcess extends VSPrefs { prefs.copyStrings(this, DEFAULT_STRING_VALUE_KEYS); } + /* (non-Javadoc) + * @see prefs.VSPrefs#toString() + */ public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(prefs.getString("lang.process.id")); @@ -508,6 +800,11 @@ public class VSProcess extends VSPrefs { return buffer.toString(); } + /** + * The extended string representation of the process object. + * + * @return the extended string representation + */ public String toStringFull() { StringBuffer buffer = new StringBuffer(); buffer.append(toString()); @@ -520,22 +817,48 @@ public class VSProcess extends VSPrefs { return buffer.toString(); } + /** + * Equals. Checks, if both processes have the same process id. + * + * @param process the process to compare to + * + * @return true, if both processes are the same. + */ public boolean equals(VSProcess process) { return process.getProcessID() == processID; } + /** + * Gets the simulation canvas. + * + * @return the simulation canvas + */ public VSSimulatorCanvas getSimulationCanvas() { return simulationCanvas; } + /** + * Gets the simulation's default prefs. + * + * @return the default prefs + */ public VSPrefs getPrefs() { return prefs; } + /** + * Resets the process counter. + */ public static void resetProcessCounter() { processCounter = 0; } + /** + * Removes the process at the specified index. + * Needed in order to update the vector time and the local processNum. + * + * @param index the index the process has to get removed. + */ public void removeProcessAtIndex(int index) { if (index < processNum) --processNum; @@ -545,12 +868,22 @@ public class VSProcess extends VSPrefs { vectorTime.remove(index); } + /** + * Added a process. Needed in order to update the vector time's size. + */ public void addedAProcess() { vectorTime.add(new Long(0)); for (VSVectorTime vectorTime : vectorTimeHistory) vectorTime.add(new Long(0)); } + /** + * Gets the protocol object. + * + * @param protocolClassname the protocol classname + * + * @return the protocol object + */ public VSProtocol getProtocolObject(String protocolClassname) { VSProtocol protocol = null; diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java index e38c1de..43d9cb5 100644 --- a/sources/core/VSTask.java +++ b/sources/core/VSTask.java @@ -1,3 +1,7 @@ +/* + * VS is (c) 2008 by Paul C. Buetow + * vs@dev.buetow.org + */ package core; import events.*; @@ -6,18 +10,50 @@ import events.internal.*; import prefs.VSPrefs; import protocols.VSProtocol; +// TODO: Auto-generated Javadoc +/** + * The Class VSTask. + */ public class VSTask implements Comparable { + + /** The Constant LOCAL. */ public final static boolean LOCAL = true; + + /** The Constant GLOBAL. */ public final static boolean GLOBAL = false; + + /** The task time. */ private long taskTime; + + /** The event. */ private VSEvent event; + + /** The process. */ private VSProcess process; + + /** The prefs. */ private VSPrefs prefs; + + /** The is programmed. */ private boolean isProgrammed; + + /** The is global timed. */ private boolean isGlobalTimed; + + /** The task counter. */ private static int taskCounter; + + /** The task num. */ private int taskNum; + /** + * Instantiates a new vS task. + * + * @param taskTime the task time + * @param process the process + * @param event the event + * @param isLocal the is local + */ public VSTask(long taskTime, VSProcess process, VSEvent event, boolean isLocal) { this.process = process; this.taskTime = taskTime > 0 ? taskTime : 0; @@ -27,26 +63,58 @@ public class VSTask implements Comparable { this.taskNum = ++taskCounter; } + /** + * Gets the task num. + * + * @return the task num + */ public int getTaskNum() { return taskNum; } + /** + * Checks if is programmed. + * + * @param isProgrammed the is programmed + */ public void isProgrammed(boolean isProgrammed) { this.isProgrammed = isProgrammed; } + /** + * Checks if is programmed. + * + * @return true, if is programmed + */ public boolean isProgrammed() { return isProgrammed; } + /** + * Checks if is message receive event. + * + * @return true, if is message receive event + */ public boolean isMessageReceiveEvent() { return event instanceof MessageReceiveEvent; } + /** + * Checks if is process recover event. + * + * @return true, if is process recover event + */ public boolean isProcessRecoverEvent() { return event instanceof ProcessRecoverEvent; } + /** + * Checks if is protocol. + * + * @param protocol the protocol + * + * @return true, if is protocol + */ public boolean isProtocol(VSProtocol protocol) { if (event instanceof VSProtocol) return ((VSProtocol) event).equals(protocol); @@ -54,6 +122,11 @@ public class VSTask implements Comparable { return false; } + /** + * Time over. + * + * @return true, if successful + */ public boolean timeOver() { if (isGlobalTimed) return taskTime < process.getGlobalTime(); @@ -61,6 +134,13 @@ public class VSTask implements Comparable { return taskTime < process.getTime(); } + /** + * Equals. + * + * @param task the task + * + * @return true, if successful + */ public boolean equals(VSTask task) { return taskNum == task.getTaskNum(); /* @@ -71,36 +151,74 @@ public class VSTask implements Comparable { */ } + /** + * Checks if is process. + * + * @param process the process + * + * @return true, if is process + */ public boolean isProcess(VSProcess process) { return this.process.equals(process); } + /** + * Checks if is global timed. + * + * @return true, if is global timed + */ public boolean isGlobalTimed() { return isGlobalTimed; } + /** + * Gets the process. + * + * @return the process + */ public VSProcess getProcess() { return process; } + /** + * Run. + */ public void run() { if (event.getProcess() == null) event.init(process); event.onStart(); } + /** + * Gets the task time. + * + * @return the task time + */ public long getTaskTime() { return taskTime; } + /** + * Gets the event. + * + * @return the event + */ public VSEvent getEvent() { return event; } + /** + * Logg. + * + * @param message the message + */ private void logg(String message) { process.logg(message); } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(prefs.getString("lang.task")); @@ -112,6 +230,9 @@ public class VSTask implements Comparable { return buffer.toString(); } + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ public int compareTo(Object object) { if (object instanceof VSTask) { final VSTask task = (VSTask) object; diff --git a/sources/core/VSTaskManager.java b/sources/core/VSTaskManager.java index cc2f262..272922f 100644 --- a/sources/core/VSTaskManager.java +++ b/sources/core/VSTaskManager.java @@ -1,3 +1,7 @@ +/* + * VS is (c) 2008 by Paul C. Buetow + * vs@dev.buetow.org + */ package core; import java.util.*; @@ -5,14 +9,35 @@ import java.util.*; import prefs.*; import utils.*; +// TODO: Auto-generated Javadoc +/** + * The Class VSTaskManager. + */ public class VSTaskManager { + + /** The tasks. */ private PriorityQueue<VSTask> tasks; + + /** The global tasks. */ private PriorityQueue<VSTask> globalTasks; + + /** The fullfilled programmed tasks. */ private LinkedList<VSTask> fullfilledProgrammedTasks; + + /** The Constant PROGRAMMED. */ public final static boolean PROGRAMMED = true; + + /** The Constant ONLY_ONCE. */ public final static boolean ONLY_ONCE = false; + + /** The prefs. */ private VSPrefs prefs; + /** + * Instantiates a new vS task manager. + * + * @param prefs the prefs + */ public VSTaskManager(VSPrefs prefs) { this.prefs = prefs; this.tasks = new PriorityQueue<VSTask>();//100, comparator); @@ -20,6 +45,13 @@ public class VSTaskManager { this.fullfilledProgrammedTasks = new LinkedList<VSTask>(); } + /** + * Run tasks. + * + * @param step the step + * @param offset the offset + * @param lastGlobalTime the last global time + */ public synchronized void runTasks(final long step, final long offset, final long lastGlobalTime) { VSTask task = null; VSProcess process = null; @@ -140,6 +172,9 @@ public class VSTaskManager { } while (redo); } + /** + * Reset. + */ public synchronized void reset() { PriorityQueue<VSTask> tmp = tasks; PriorityQueue<VSTask> tmp2 = globalTasks; @@ -165,6 +200,11 @@ public class VSTaskManager { } } + /** + * Insert. + * + * @param task the task + */ private void insert(VSTask task) { if (task.timeOver()) fullfilledProgrammedTasks.addLast(task); @@ -176,15 +216,33 @@ public class VSTaskManager { tasks.add(task); } + /** + * Adds the task. + * + * @param task the task + */ public void addTask(VSTask task) { addTask(task, VSTaskManager.ONLY_ONCE); } + /** + * Adds the task. + * + * @param task the task + * @param isProgrammed the is programmed + */ public synchronized void addTask(VSTask task, boolean isProgrammed) { task.isProgrammed(isProgrammed); insert(task); } + /** + * Removes the task. + * + * @param task the task + * + * @return true, if successful + */ public synchronized boolean removeTask(VSTask task) { if (fullfilledProgrammedTasks.remove(task)) return true; @@ -198,6 +256,11 @@ public class VSTaskManager { return false; } + /** + * Removes the tasks of. + * + * @param process the process + */ public synchronized void removeTasksOf(VSProcess process) { ArrayList<VSTask> removeThose = new ArrayList<VSTask>(); for (VSTask task : fullfilledProgrammedTasks) @@ -221,6 +284,11 @@ public class VSTaskManager { tasks.remove(task); } + /** + * Gets the local tasks. + * + * @return the local tasks + */ public synchronized VSPriorityQueue<VSTask> getLocalTasks() { VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>(); @@ -235,6 +303,11 @@ public class VSTaskManager { return processTasks; } + /** + * Gets the global tasks. + * + * @return the global tasks + */ public synchronized VSPriorityQueue<VSTask> getGlobalTasks() { VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>(); @@ -249,6 +322,13 @@ public class VSTaskManager { return processTasks; } + /** + * Gets the process local tasks. + * + * @param process the process + * + * @return the process local tasks + */ public synchronized VSPriorityQueue<VSTask> getProcessLocalTasks(VSProcess process) { VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>(); @@ -263,6 +343,13 @@ public class VSTaskManager { return processTasks; } + /** + * Gets the process global tasks. + * + * @param process the process + * + * @return the process global tasks + */ public synchronized VSPriorityQueue<VSTask> getProcessGlobalTasks(VSProcess process) { VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>(); @@ -277,6 +364,9 @@ public class VSTaskManager { return processTasks; } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ public String toString() { StringBuffer buffer = new StringBuffer(); diff --git a/sources/core/time/VSLamportTime.java b/sources/core/time/VSLamportTime.java index 592507a..4ee5ebd 100644 --- a/sources/core/time/VSLamportTime.java +++ b/sources/core/time/VSLamportTime.java @@ -1,16 +1,23 @@ +/* + * VS is (c) 2008 by Paul C. Buetow + * vs@dev.buetow.org + */ package core.time; -/** This class defined how the lamport timestamps are represented. +// TODO: Auto-generated Javadoc +/** + * This class defined how the lamport timestamps are represented. */ public class VSLamportTime implements VSTime { - /** Specified the global time of the lamport timestamp. It's used for correct painting in the simulator paint area. - */ + + /** Specified the global time of the lamport timestamp. It's used for correct painting in the simulator paint area. */ private long globalTime; - /** Specified the process' local lamport time. - */ + + /** Specified the process' local lamport time. */ private long lamportTime; - /** A simple constructor. + /** + * A simple constructor. * * @param globalTime The global time. * @param lamportTime The local lamport time. @@ -20,7 +27,8 @@ public class VSLamportTime implements VSTime { this.lamportTime = lamportTime; } - /** Getter method. + /** + * Getter method. * * @return The global time. */ @@ -28,7 +36,8 @@ public class VSLamportTime implements VSTime { return globalTime; } - /** Getter method. + /** + * Getter method. * * @return The process' local lamport time. */ @@ -36,7 +45,8 @@ public class VSLamportTime implements VSTime { return lamportTime; } - /** String representation. + /** + * String representation. * * @return The string representation of the lamport time. */ diff --git a/sources/core/time/VSTime.java b/sources/core/time/VSTime.java index ce20ecc..0aebf4a 100644 --- a/sources/core/time/VSTime.java +++ b/sources/core/time/VSTime.java @@ -1,14 +1,24 @@ +/* + * VS is (c) 2008 by Paul C. Buetow + * vs@dev.buetow.org + */ package core.time; -/** This interface is a guidline for general time format classes. +// TODO: Auto-generated Javadoc +/** + * This interface is a guidline for general time format classes. */ public interface VSTime { - /** Getter method. + + /** + * Getter method. * * @return The global time. */ public long getGlobalTime(); - /** String representation. + + /** + * String representation. * * @return The representation of the implementing object as a string. */ diff --git a/sources/core/time/VSVectorTime.java b/sources/core/time/VSVectorTime.java index eb6c0aa..647eb7a 100644 --- a/sources/core/time/VSVectorTime.java +++ b/sources/core/time/VSVectorTime.java @@ -1,14 +1,34 @@ +/* + * VS is (c) 2008 by Paul C. Buetow + * vs@dev.buetow.org + */ package core.time; import java.util.ArrayList; +// TODO: Auto-generated Javadoc +/** + * The Class VSVectorTime. + */ public class VSVectorTime extends ArrayList<Long> implements VSTime { + + /** The global time. */ private long globalTime; + /** + * Instantiates a new vS vector time. + * + * @param globalTime the global time + */ public VSVectorTime(long globalTime) { this.globalTime = globalTime; } + /** + * To long array. + * + * @return the long[] + */ public long[] toLongArray() { final int size = super.size(); final long[] arr = new long[size]; @@ -19,14 +39,27 @@ public class VSVectorTime extends ArrayList<Long> implements VSTime { return arr; } + /** + * Sets the global time. + * + * @param globalTime the new global time + */ public void setGlobalTime(long globalTime) { this.globalTime = globalTime; } + /* (non-Javadoc) + * @see core.time.VSTime#getGlobalTime() + */ public long getGlobalTime() { return globalTime; } + /** + * Gets the copy. + * + * @return the copy + */ public VSVectorTime getCopy() { final VSVectorTime vectorTime = new VSVectorTime(globalTime); final int size = super.size(); @@ -37,6 +70,9 @@ public class VSVectorTime extends ArrayList<Long> implements VSTime { return vectorTime; } + /* (non-Javadoc) + * @see java.util.AbstractCollection#toString() + */ public String toString() { final int size = super.size(); final StringBuffer buffer = new StringBuffer(); @@ -49,6 +85,9 @@ public class VSVectorTime extends ArrayList<Long> implements VSTime { return buffer.toString(); } + /* (non-Javadoc) + * @see java.util.ArrayList#get(int) + */ public Long get(int index) { if (index >= super.size()) return new Long(0); |
