summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-05-28 22:05:59 +0000
committerPaul Buetow <paul@buetow.org>2008-05-28 22:05:59 +0000
commit4d5a90f7191b6c175863d0375e9d1e17b2df39d4 (patch)
tree3d4ead53f3dc6e225688f18b554f767989cdd42b
parentcaa0c0443dc39003d79e0e50656e12c39799c48a (diff)
Style and javadoc.
-rw-r--r--sources/core/VSMessage.java63
-rw-r--r--sources/core/VSTask.java44
-rw-r--r--sources/core/VSTaskManager.java90
-rw-r--r--sources/core/time/VSLamportTime.java27
-rw-r--r--sources/core/time/VSTime.java11
-rw-r--r--sources/core/time/VSVectorTime.java7
6 files changed, 143 insertions, 99 deletions
diff --git a/sources/core/VSMessage.java b/sources/core/VSMessage.java
index 852e5f3..663abbc 100644
--- a/sources/core/VSMessage.java
+++ b/sources/core/VSMessage.java
@@ -9,12 +9,18 @@ import events.*;
import prefs.VSPrefs;
/**
- * This class represents a message which is send from one process to another process in the simulation.
+ * This class represents a message which is send from one process to another
+ * process in the simulation.
+ *
+ * @author Paul C. Buetow
*/
public class VSMessage extends VSPrefs {
+ /** The serial version uid */
private static final long serialVersionUID = 1L;
- /** 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. */
@@ -23,41 +29,50 @@ public class VSMessage extends VSPrefs {
/** 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
+ */
private long messageID;
/** 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. Creates a new message object.
*/
public VSMessage() {
this.messageID = ++messageCounter;
}
/**
- * Initialized the message.
+ * Initializes the message.
*
* @param process The sending process of this message.
- * @param protocolClassname The classname of the protocol this message
+ * @param protocolClassname The classname of the protocol this message.
*/
public void init(VSProcess process, String protocolClassname) {
this.sendingProcess = process;
this.protocolClassname = protocolClassname;
this.prefs = process.getPrefs();
+
lamportTime = sendingProcess.getLamportTime();
vectorTime = sendingProcess.getVectorTime().getCopy();
}
/**
- * Getter method.
+ * Gets the protocol name of the message.
*
* @return The protocol name of the message.
*/
@@ -66,7 +81,7 @@ public class VSMessage extends VSPrefs {
}
/**
- * Getter method.
+ * Gets the protocol classname.
*
* @return The protocol classname of the message.
*/
@@ -75,16 +90,16 @@ public class VSMessage extends VSPrefs {
}
/**
- * Getter method.
+ * Gets the message id.
*
- * @return The ID of the message.
+ * @return The id of the message.
*/
public long getMessageID() {
return messageID;
}
/**
- * Getter method.
+ * Gets a reference of the sending process.
*
* @return The process which sent this message.
*/
@@ -93,7 +108,7 @@ public class VSMessage extends VSPrefs {
}
/**
- * Getter method.
+ * Gets the lamport time.
*
* @return The lamport time of the sending process.
*/
@@ -102,7 +117,7 @@ public class VSMessage extends VSPrefs {
}
/**
- * Getter method.
+ * Gets the vector time.
*
* @return The vector time of the sending process.
*/
@@ -110,10 +125,8 @@ public class VSMessage extends VSPrefs {
return vectorTime;
}
- /**
- * String representation of the message object.
- *
- * @return String representation of the message object.
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#toString()
*/
public String toString() {
StringBuffer buffer = new StringBuffer();
@@ -123,7 +136,8 @@ public class VSMessage extends VSPrefs {
buffer.append("; ");
buffer.append(prefs.getString("lang.protocol"));
buffer.append(": ");
- buffer.append(VSRegisteredEvents.getShortnameByClassname(getProtocolClassname()));
+ buffer.append(VSRegisteredEvents.getShortnameByClassname(
+ getProtocolClassname()));
return buffer.toString();
}
@@ -142,17 +156,10 @@ public class VSMessage extends VSPrefs {
*
* @param message The message to compare with.
*
- * @return true, if the messages have the same ID. Otherwise false.
+ * @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!.
- *
- * @param message The message to logg.
- */
- public void logg(String message) { }
}
diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java
index dc55fcc..e281399 100644
--- a/sources/core/VSTask.java
+++ b/sources/core/VSTask.java
@@ -12,32 +12,42 @@ import protocols.VSAbstractProtocol;
/**
* The Class VSTask. An object of this class represents a task to do or done.
- * All tasks are managed by the task manager. There are local and global timed tasks.
- * Local timed tasks are being fullfilled if the process' local time is reached.
- * Global timed tasks are being fullfilled if the simulation's time is reached.
+ * All tasks are managed by the task manager. There are local and global timed
+ * tasks. Local timed tasks are being fullfilled if the process' local time is
+ * reached. Global timed tasks are being fullfilled if the simulation's time is
+ * reached.
+ *
+ * @author Paul C. Buetow
*/
public class VSTask implements Comparable {
+ /** The serial version uid */
private static final long serialVersionUID = 1L;
- /** The Constant LOCAL. Used for the constructor if it's a local timed task. */
+ /** The Constant LOCAL. Used for the constructor if it's a local timed
+ * task.
+ */
public final static boolean LOCAL = true;
- /** The Constant GLOBAL. Used for the constructor if it's a global timed task. */
+ /** The Constant GLOBAL. Used for the constructor if it's a global timed
+ * task.
+ */
public final static boolean GLOBAL = false;
/** The task time. */
private long taskTime;
- /** The event. */
+ /** The event which takes plase if the task time matches. */
private VSAbstractEvent event;
- /** The process. */
+ /** The process to run the task at. */
private VSProcess process;
- /** The prefs. */
+ /** The simulation's default prefs. */
private VSPrefs prefs;
- /** The task is programmed. The task will be still in the task manager after reset. */
+ /** The task is programmed. The task will be still in the task manager
+ * after reset.
+ */
private boolean isProgrammed;
/** The task is global timed. If set to true, its local timed. */
@@ -57,7 +67,8 @@ public class VSTask implements Comparable {
* @param event the event
* @param isLocal the taks is local timed
*/
- public VSTask(long taskTime, VSProcess process, VSAbstractEvent event, boolean isLocal) {
+ public VSTask(long taskTime, VSProcess process, VSAbstractEvent event,
+ boolean isLocal) {
this.process = process;
this.taskTime = taskTime > 0 ? taskTime : 0;
this.event = event;
@@ -76,9 +87,9 @@ public class VSTask implements Comparable {
}
/**
- * Checks if is programmed.
+ * Sets if the task is programmed.
*
- * @param isProgrammed the task is programmed
+ * @param isProgrammed true, if the task is programmed
*/
public void isProgrammed(boolean isProgrammed) {
this.isProgrammed = isProgrammed;
@@ -126,7 +137,7 @@ public class VSTask implements Comparable {
}
/**
- * Time over. The task's time is over.
+ * Checks if the task's time is over.
*
* @return true, if it's over
*/
@@ -142,18 +153,18 @@ public class VSTask implements Comparable {
*
* @param task the task to compare to
*
- * @return true, if equal
+ * @return true, if equal (the task nums equal)
*/
public boolean equals(VSTask task) {
return taskNum == task.getTaskNum();
}
/**
- * Checks if the event belongs to the specified process.
+ * Checks if the task belongs to the specified process.
*
* @param process the process to check against
*
- * @return true, if the event is using the process
+ * @return true, if the task is using the process
*/
public boolean isProcess(VSProcess process) {
return this.process.equals(process);
@@ -253,7 +264,6 @@ public class VSTask implements Comparable {
if (b)
return 1;
-
/* If it's a ProtocolEvent, it should get handled first */
a = event instanceof ProtocolEvent;
b = task.getEvent() instanceof ProtocolEvent;
diff --git a/sources/core/VSTaskManager.java b/sources/core/VSTaskManager.java
index ff5a39f..2dc64da 100644
--- a/sources/core/VSTaskManager.java
+++ b/sources/core/VSTaskManager.java
@@ -10,9 +10,15 @@ import prefs.*;
import utils.*;
/**
- * The Class VSTaskManager.
+ * The Class VSTaskManager. The task manager is responsible that all tasks
+ * will get fullfilled in the correct order. Please also read the javadoc
+ * of the VSTask class. It describes the difference between local and global
+ * timed tasks.
+ *
+ * @author Paul C. Buetow
*/
public class VSTaskManager {
+ /** The seriao version uid */
private static final long serialVersionUID = 1L;
/** The tasks. */
@@ -30,29 +36,31 @@ public class VSTaskManager {
/** The Constant ONLY_ONCE. */
public final static boolean ONLY_ONCE = false;
- /** The prefs. */
+ /** The simulator's default prefs. */
private VSPrefs prefs;
/**
* Instantiates a new lang.process.removetask manager.
*
- * @param prefs the prefs
+ * @param prefs the simulator's default prefs
*/
public VSTaskManager(VSPrefs prefs) {
this.prefs = prefs;
- this.tasks = new PriorityQueue<VSTask>();//100, comparator);
- this.globalTasks = new PriorityQueue<VSTask>();//(100, comparator);
+ this.tasks = new PriorityQueue<VSTask>();
+ this.globalTasks = new PriorityQueue<VSTask>();
this.fullfilledProgrammedTasks = new LinkedList<VSTask>();
}
/**
- * Run tasks.
+ * Run tasks. This method gets called by the simulation canvas repeatedly.
+ * Almost all simulation actions take place in this method.
*
* @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) {
+ public synchronized void runTasks(long step, long offset,
+ long lastGlobalTime) {
VSTask task = null;
VSProcess process = null;
long localTime;
@@ -111,7 +119,8 @@ public class VSTaskManager {
if (process.isCrashed())
process.addClockOffset(step);
if (process.timeModified())
- process.addClockOffset(process.getTime()-(offsetTime-diff));
+ process.addClockOffset(process.getTime()-
+ (offsetTime-diff));
process.setLocalTime(localTime);
}
@@ -161,7 +170,8 @@ public class VSTaskManager {
task.run();
process.setGlobalTime(globalTime);
if (process.timeModified())
- process.addClockOffset(process.getTime()-(offsetTime-diff));
+ process.addClockOffset(process.getTime()-
+ (offsetTime-diff));
process.setLocalTime(localTime);
}
@@ -202,6 +212,8 @@ public class VSTaskManager {
/**
* Inserts a task. Only for internal usage. Use the add methods instead.
+ * This method checks if the task to insert is a global or a local timed
+ * task. And it also checks if the task's time is over already.
*
* @param task the task to insert
*/
@@ -229,7 +241,7 @@ public class VSTaskManager {
* Adds a task.
*
* @param task the task to add
- * @param isProgrammed the task is programmed
+ * @param isProgrammed true, if the task is programmed
*/
public synchronized void addTask(VSTask task, boolean isProgrammed) {
task.isProgrammed(isProgrammed);
@@ -241,7 +253,7 @@ public class VSTaskManager {
*
* @param task the task to remove
*
- * @return true, if successful
+ * @return true, if the task has been removed with success
*/
public synchronized boolean removeTask(VSTask task) {
if (fullfilledProgrammedTasks.remove(task))
@@ -257,7 +269,7 @@ public class VSTaskManager {
}
/**
- * Removes several tasks
+ * Removes several tasks.
*
* @param tasks the tasks to remove
*/
@@ -273,77 +285,85 @@ public class VSTaskManager {
*/
public synchronized void removeTasksOf(VSProcess process) {
ArrayList<VSTask> removeThose = new ArrayList<VSTask>();
+
for (VSTask task : fullfilledProgrammedTasks)
if (task.isProcess(process))
removeThose.add(task);
+
for (VSTask task : removeThose)
fullfilledProgrammedTasks.remove(task);
removeThose.clear();
+
for (VSTask task : globalTasks)
if (task.isProcess(process))
removeThose.add(task);
+
for (VSTask task : removeThose)
globalTasks.remove(task);
removeThose.clear();
+
for (VSTask task : tasks)
if (task.isProcess(process))
removeThose.add(task);
+
for (VSTask task : removeThose)
tasks.remove(task);
}
/**
- * Gets the local tasks.
+ * Gets the local timed tasks.
*
- * @return the local tasks
+ * @return the local timed tasks
*/
public synchronized VSPriorityQueue<VSTask> getLocalTasks() {
- VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>();
+ VSPriorityQueue<VSTask> localTasks = new VSPriorityQueue<VSTask>();
for (VSTask task : fullfilledProgrammedTasks)
if (!task.isGlobalTimed() && task.isProgrammed())
- processTasks.add(task);
+ localTasks.add(task);
for (VSTask task : tasks)
if (task.isProgrammed())
- processTasks.add(task);
+ localTasks.add(task);
- return processTasks;
+ return localTasks;
}
/**
- * Gets the global tasks.
+ * Gets the global timed tasks.
*
- * @return the global tasks
+ * @return the global timed tasks
*/
public synchronized VSPriorityQueue<VSTask> getGlobalTasks() {
- VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>();
+ VSPriorityQueue<VSTask> globalTasks = new VSPriorityQueue<VSTask>();
for (VSTask task : fullfilledProgrammedTasks)
if (task.isGlobalTimed() && task.isProgrammed())
- processTasks.add(task);
+ globalTasks.add(task);
for (VSTask task : globalTasks)
if (task.isProgrammed())
- processTasks.add(task);
+ globalTasks.add(task);
- return processTasks;
+ return globalTasks;
}
/**
- * Gets the process local tasks.
+ * Gets the local timed tasks of a specific process.
*
- * @param process the process
+ * @param process the process to get the local timed tasks of
*
- * @return the process local tasks
+ * @return the local tasks of the specified process
*/
- public synchronized VSPriorityQueue<VSTask> getProcessLocalTasks(VSProcess process) {
+ public synchronized VSPriorityQueue<VSTask> getProcessLocalTasks(
+ VSProcess process) {
VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>();
for (VSTask task : fullfilledProgrammedTasks)
- if (!task.isGlobalTimed() && task.isProcess(process) && task.isProgrammed())
+ if (!task.isGlobalTimed() && task.isProcess(process) &&
+ task.isProgrammed())
processTasks.add(task);
for (VSTask task : tasks)
@@ -354,17 +374,19 @@ public class VSTaskManager {
}
/**
- * Gets the process global tasks.
+ * Gets the global timed tasks of a specific process.
*
- * @param process the process
+ * @param process the process to get the local timed tasks of
*
- * @return the process global tasks
+ * @return the global timed tasks of the specified process
*/
- public synchronized VSPriorityQueue<VSTask> getProcessGlobalTasks(VSProcess process) {
+ public synchronized VSPriorityQueue<VSTask> getProcessGlobalTasks(
+ VSProcess process) {
VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>();
for (VSTask task : fullfilledProgrammedTasks)
- if (task.isGlobalTimed() && task.isProcess(process) && task.isProgrammed())
+ if (task.isGlobalTimed() && task.isProcess(process) &&
+ task.isProgrammed())
processTasks.add(task);
for (VSTask task : globalTasks)
diff --git a/sources/core/time/VSLamportTime.java b/sources/core/time/VSLamportTime.java
index e78970f..25ad8af 100644
--- a/sources/core/time/VSLamportTime.java
+++ b/sources/core/time/VSLamportTime.java
@@ -4,14 +4,19 @@
*/
package core.time;
-// TODO: Auto-generated Javadoc
/**
- * This class defined how the lamport timestamps are represented.
+ * The Class VSLamportTime. This class defined how the lamport
+ * timestamps are represented.
+ *
+ * @author Paul C. Buetow
*/
public class VSLamportTime implements VSTime {
+ /** The serial version uid */
private static final long serialVersionUID = 1L;
- /** 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 position in the simulator canvas paint area.
+ */
private long globalTime;
/** Specified the process' local lamport time. */
@@ -28,28 +33,24 @@ public class VSLamportTime implements VSTime {
this.lamportTime = lamportTime;
}
- /**
- * Getter method.
- *
- * @return The global time.
+ /* (non-Javadoc)
+ * @see core.time.VSTime#getGlobalTime()
*/
public long getGlobalTime() {
return globalTime;
}
/**
- * Getter method.
+ * Gets the lamport time.
*
- * @return The process' local lamport time.
+ * @return The process' local lamport time
*/
public long getLamportTime() {
return lamportTime;
}
- /**
- * String representation.
- *
- * @return The string representation of the lamport time.
+ /* (non-Javadoc)
+ * @see core.time.VSTime#toString()
*/
public String toString() {
return "(" + lamportTime + ")";
diff --git a/sources/core/time/VSTime.java b/sources/core/time/VSTime.java
index c68882b..c5a2805 100644
--- a/sources/core/time/VSTime.java
+++ b/sources/core/time/VSTime.java
@@ -4,22 +4,23 @@
*/
package core.time;
-// TODO: Auto-generated Javadoc
/**
* This interface is a guidline for general time format classes.
+ *
+ * @author Paul C. Buetow
*/
public interface VSTime {
/**
- * Getter method.
+ * Gets the global time.
*
- * @return The global time.
+ * @return The global time
*/
public long getGlobalTime();
/**
- * String representation.
+ * Returns a string representation.
*
- * @return The representation of the implementing object as a string.
+ * @return The representation of the implementing object as a string
*/
public String toString();
}
diff --git a/sources/core/time/VSVectorTime.java b/sources/core/time/VSVectorTime.java
index 4b48477..5a52f96 100644
--- a/sources/core/time/VSVectorTime.java
+++ b/sources/core/time/VSVectorTime.java
@@ -6,11 +6,14 @@ package core.time;
import java.util.ArrayList;
-// TODO: Auto-generated Javadoc
/**
- * The Class VSVectorTime.
+ * The Class VSVectorTime. This class defined how the vector
+ * timestamps are represented.
+ *
+ * @author Paul C. Buetow
*/
public class VSVectorTime extends ArrayList<Long> implements VSTime {
+ /** The serial version uid */
private static final long serialVersionUID = 1L;
/** The global time. */