summaryrefslogtreecommitdiff
path: root/sources/core
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-05-18 19:29:30 +0000
committerPaul Buetow <paul@buetow.org>2008-05-18 19:29:30 +0000
commit2d45de18df35f6d3ba4ca0b86ec1188e49637413 (patch)
tree6c84c8cd14a89a6dabeada811c6477d1e5459767 /sources/core
parentc46ed2242876bfb267ed0b6823c8a3e99ac62dd6 (diff)
The TaskManager works partly.
Diffstat (limited to 'sources/core')
-rw-r--r--sources/core/VSMessage.java20
-rw-r--r--sources/core/VSProcess.java6
-rw-r--r--sources/core/VSTask.java86
-rw-r--r--sources/core/VSTaskManager.java47
4 files changed, 70 insertions, 89 deletions
diff --git a/sources/core/VSMessage.java b/sources/core/VSMessage.java
index 3989539..7362284 100644
--- a/sources/core/VSMessage.java
+++ b/sources/core/VSMessage.java
@@ -5,16 +5,16 @@ import events.*;
import prefs.VSPrefs;
import protocols.*;
-public class VSMessage extends VSPrefs implements VSEvent {
- private String protocolClassname;
+public class VSMessage extends VSEvent {
+ private String eventClassname;
private VSProcess sendingProcess;
private long messageID;
private static long messageCounter;
private long lamportTime;
private VSVectorTime vectorTime;
- public VSMessage(String protocolClassname) {
- this.protocolClassname = protocolClassname;
+ public VSMessage(String eventClassname) {
+ this.eventClassname = eventClassname;
this.messageID = ++messageCounter;
}
@@ -24,12 +24,12 @@ public class VSMessage extends VSPrefs implements VSEvent {
vectorTime = sendingProcess.getVectorTime().getCopy();
}
- public String getProtocolName() {
- return VSRegisteredProtocols.getProtocolName(getProtocolClassname());
+ public String getName() {
+ return VSRegisteredEvents.getName(getProtocolClassname());
}
public String getProtocolClassname() {
- return protocolClassname;
+ return eventClassname;
}
public long getMessageID() {
@@ -60,8 +60,8 @@ public class VSMessage extends VSPrefs implements VSEvent {
return messageID == message.getMessageID();
}
- public void logg(String message) {
- //System.out.println(message);
- }
+ public void logg(String message) { }
+ public void onInit() { }
+ public void onStart() { }
}
diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java
index bef1f58..467ee46 100644
--- a/sources/core/VSProcess.java
+++ b/sources/core/VSProcess.java
@@ -231,9 +231,9 @@ public final class VSProcess extends VSPrefs {
taskManager.removeTask(randomCrashTask);
if (crashTime >= 0 && crashTime >= getGlobalTime()) {
- VSProcessEvent event = new ProcessCrashEvent();
+ VSEvent event = new ProcessCrashEvent();
event.init(this);
- randomCrashTask = new VSTask(crashTime, this, event);
+ randomCrashTask = new VSTask(crashTime, this, event, VSTask.GLOBAL);
taskManager.addTask(randomCrashTask);
} else {
@@ -474,7 +474,7 @@ public final class VSProcess extends VSPrefs {
buffer.append(prefs.getString("lang.message.sent"));
buffer.append("; ");
buffer.append(prefs.getString("lang.protocol"));
- buffer.append(": " + message.getProtocolName());
+ buffer.append(": " + message.getName());
buffer.append("; ");
buffer.append(prefs.getString("lang.message"));
buffer.append(" ");
diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java
index 7787373..eef2642 100644
--- a/sources/core/VSTask.java
+++ b/sources/core/VSTask.java
@@ -7,17 +7,21 @@ import protocols.VSProtocol;
import simulator.*;
public class VSTask implements Comparable {
+ public final static boolean LOCAL = true;
+ public final static boolean GLOBAL = false;
private long taskTime;
private VSEvent event;
private VSProcess process;
private VSPrefs prefs;
private boolean isProgrammed;
+ private boolean isGlobalTimed;
- public VSTask(long taskTime, VSProcess process, VSEvent event) {
+ public VSTask(long taskTime, VSProcess process, VSEvent event, boolean isLocal) {
this.process = process;
this.taskTime = taskTime > 0 ? taskTime : 0;
this.event = event;
this.prefs = process.getPrefs();
+ this.isGlobalTimed = !isLocal;
}
public void isProgrammed(boolean isProgrammed) {
@@ -48,10 +52,7 @@ public class VSTask implements Comparable {
}
public boolean isGlobalTimed() {
- if (event instanceof VSProtocol)
- return false;
-
- return true;
+ return isGlobalTimed;
}
public VSProcess getProcess() {
@@ -66,8 +67,8 @@ public class VSTask implements Comparable {
/* Lamport time will get incremented by the VSProtocol class */
onProtocolStart();
- } else if (event instanceof VSProcessEvent) {
- onProcessEventStart();
+ } else if (event instanceof VSEvent) {
+ onEventStart();
} else {
onDummy();
@@ -86,29 +87,29 @@ public class VSTask implements Comparable {
*/
private void onMessageRecv() {
final VSMessage message = (VSMessage) event;
- final String protocolName = message.getProtocolName();
- final String protocolClassname = message.getProtocolClassname();
+ final String eventName = message.getName();
+ final String eventClassname = message.getProtocolClassname();
process.updateLamportTime(message.getLamportTime()+1);
process.updateVectorTime(message.getVectorTime());
Object protocolObj;
- if (process.objectExists(protocolClassname))
- protocolObj = process.getObject(protocolClassname);
+ if (process.objectExists(eventClassname))
+ protocolObj = process.getObject(eventClassname);
else
protocolObj = null;
- StringBuffer buffer = new StringBuffer();
+ StringBuffer buffer = new StringBuffer();
buffer.append(prefs.getString("lang.message.recv"));
- buffer.append("; ");
- buffer.append(prefs.getString("lang.protocol"));
- buffer.append(": " );
- buffer.append(protocolName);
- buffer.append("; ");
- buffer.append(prefs.getString("lang.message"));
- buffer.append(" ");
- buffer.append(message);;
+ buffer.append("; ");
+ buffer.append(prefs.getString("lang.protocol"));
+ buffer.append(": " );
+ buffer.append(eventName);
+ buffer.append("; ");
+ buffer.append(prefs.getString("lang.message"));
+ buffer.append(" ");
+ buffer.append(message);;
if (protocolObj == null) {
logg(buffer.toString());
@@ -124,9 +125,8 @@ public class VSTask implements Comparable {
((VSProtocol) event).onStart();
}
- private void onProcessEventStart() {
- final VSProcessEvent processEvent = (VSProcessEvent) event;
- processEvent.onStart();
+ private void onEventStart() {
+ event.onStart();
}
public long getTaskTime() {
@@ -141,40 +141,20 @@ public class VSTask implements Comparable {
process.logg(message);
}
- public String toStringBrief() {
- StringBuffer buffer = new StringBuffer();
- if (event instanceof ProcessCrashEvent) {
- buffer.append(prefs.getString("process.crash"));
-
- } else if (event instanceof ProcessRecoverEvent) {
- buffer.append(prefs.getString("process.recover"));
-
- } else if (event instanceof VSProtocol) {
- buffer.append(((VSProtocol) event).getProtocolShortname());
- buffer.append(" ");
- buffer.append(prefs.getString("lang.clientrequest.start"));
-
- } else {
- buffer.append("null");
- }
-
- return buffer.toString();
- }
-
public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append(prefs.getString("lang.task"));
- buffer.append(" ");
- buffer.append(getTaskTime());
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(prefs.getString("lang.task"));
+ buffer.append(" ");
+ buffer.append(getTaskTime());
if (event instanceof VSMessage) {
- buffer.append("; ");
- buffer.append(((VSMessage)event).toString());
+ buffer.append("; ");
+ buffer.append(((VSMessage)event).toString());
- } else if (event instanceof VSProtocol) {
- buffer.append("; ");
- buffer.append(((VSProtocol)event).toString());
- }
+ } else if (event instanceof VSProtocol) {
+ buffer.append("; ");
+ buffer.append(((VSProtocol)event).toString());
+ }
return buffer.toString();
}
diff --git a/sources/core/VSTaskManager.java b/sources/core/VSTaskManager.java
index 19935df..04cff9d 100644
--- a/sources/core/VSTaskManager.java
+++ b/sources/core/VSTaskManager.java
@@ -4,13 +4,14 @@ import java.util.*;
import protocols.*;
import prefs.*;
+import utils.*;
public class VSTaskManager {
private PriorityQueue<VSTask> tasks;
private PriorityQueue<VSTask> globalTasks;
private LinkedList<VSTask> fullfilledProgrammedTasks;
- public final static boolean PROGRAMMED_TASK = true;
- public final static boolean NOT_PROGRAMMED_TASK = false;
+ public final static boolean PROGRAMMED = true;
+ public final static boolean ONLY_ONCE = false;
private VSPrefs prefs;
public VSTaskManager(VSPrefs prefs) {
@@ -188,7 +189,7 @@ public class VSTaskManager {
}
public void addTask(VSTask task) {
- addTask(task, VSTaskManager.NOT_PROGRAMMED_TASK);
+ addTask(task, VSTaskManager.ONLY_ONCE);
}
public synchronized void addTask(VSTask task, boolean isProgrammed) {
@@ -265,33 +266,33 @@ public class VSTaskManager {
}
}
- public synchronized ArrayList<VSTask> getProcessLocalTasks(VSProcess process) {
- ArrayList<VSTask> processTasks = new ArrayList<VSTask>();
+ public synchronized VSPriorityQueue<VSTask> getProcessLocalTasks(VSProcess process) {
+ VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>();
- for (VSTask task : fullfilledProgrammedTasks)
- if (!task.isGlobalTimed() && task.isProcess(process))
- processTasks.add(task);
+ for (VSTask task : fullfilledProgrammedTasks)
+ if (!task.isGlobalTimed() && task.isProcess(process) && task.isProgrammed())
+ processTasks.add(task);
- for (VSTask task : tasks)
- if (task.isProcess(process))
- processTasks.add(task);
+ for (VSTask task : tasks)
+ if (task.isProcess(process) && task.isProgrammed())
+ processTasks.add(task);
- return processTasks;
- }
+ return processTasks;
+ }
- public synchronized ArrayList<VSTask> getProcessGlobalTasks(VSProcess process) {
- ArrayList<VSTask> processTasks = new ArrayList<VSTask>();
+ public synchronized VSPriorityQueue<VSTask> getProcessGlobalTasks(VSProcess process) {
+ VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>();
- for (VSTask task : fullfilledProgrammedTasks)
- if (task.isGlobalTimed() && task.isProcess(process))
- processTasks.add(task);
+ for (VSTask task : fullfilledProgrammedTasks)
+ if (task.isGlobalTimed() && task.isProcess(process) && task.isProgrammed())
+ processTasks.add(task);
- for (VSTask task : globalTasks)
- if (task.isProcess(process))
- processTasks.add(task);
+ for (VSTask task : globalTasks)
+ if (task.isProcess(process) && task.isProgrammed())
+ processTasks.add(task);
- return processTasks;
- }
+ return processTasks;
+ }
public String toString() {
StringBuffer buffer = new StringBuffer();