summaryrefslogtreecommitdiff
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
parentc46ed2242876bfb267ed0b6823c8a3e99ac62dd6 (diff)
The TaskManager works partly.
-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
-rw-r--r--sources/events/VSEvent.java47
-rw-r--r--sources/events/VSProcessEvent.java20
-rw-r--r--sources/events/VSRegisteredEvents.java110
-rw-r--r--sources/events/implementations/ProcessCrashEvent.java14
-rw-r--r--sources/events/implementations/ProcessRecoverEvent.java14
-rw-r--r--sources/events/implementations/ProtocolEvent.java23
-rw-r--r--sources/prefs/editors/VSProcessEditor.java17
-rw-r--r--sources/prefs/editors/VSProtocolEditor.java22
-rw-r--r--sources/protocols/VSProtocol.java46
-rw-r--r--sources/protocols/VSRegisteredProtocols.java86
-rw-r--r--sources/protocols/implementations/BerkelyTimeProtocol.java8
-rw-r--r--sources/protocols/implementations/BroadcastSturmProtocol.java6
-rw-r--r--sources/protocols/implementations/DummyProtocol.java4
-rw-r--r--sources/protocols/implementations/ExternalTimeSyncProtocol.java6
-rw-r--r--sources/protocols/implementations/InternalTimeSyncProtocol.java6
-rw-r--r--sources/protocols/implementations/PingPongProtocol.java8
-rw-r--r--sources/simulator/VSMain.java4
-rw-r--r--sources/simulator/VSSimulation.java362
-rw-r--r--sources/simulator/VSSimulationPanel.java12
-rw-r--r--sources/utils/VSClassLoader.java4
-rw-r--r--sources/utils/VSPriorityQueue.java15
25 files changed, 583 insertions, 410 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();
diff --git a/sources/events/VSEvent.java b/sources/events/VSEvent.java
index 2223d22..e84e3aa 100644
--- a/sources/events/VSEvent.java
+++ b/sources/events/VSEvent.java
@@ -1,8 +1,49 @@
package events;
import core.VSProcess;
+import prefs.VSPrefs;
-public interface VSEvent {
- public void init(VSProcess process);
- public void logg(String message);
+abstract public class VSEvent extends VSPrefs {
+ protected VSPrefs prefs;
+ protected VSProcess process;
+ private String eventClassname;
+
+ public void init(VSProcess process) {
+ this.process = process;
+ this.prefs = process.getPrefs();
+ }
+
+ protected final void setClassname(String eventClassname) {
+ if (eventClassname.startsWith("class "))
+ eventClassname = eventClassname.substring(6);
+
+ this.eventClassname = eventClassname;
+ }
+
+ public final String getClassname() {
+ return eventClassname;
+ }
+
+ public String getName() {
+ return VSRegisteredEvents.getName(eventClassname);
+ }
+
+ public final String getShortname() {
+ return VSRegisteredEvents.getShortname(eventClassname);
+ }
+
+ public final VSProcess getProcess() {
+ return process;
+ }
+
+ public void logg(String message) {
+ process.logg(toString() + "; " + message);
+ }
+
+ public boolean equals(VSEvent event) {
+ return super.getID() == event.getID();
+ }
+
+ abstract protected void onInit();
+ abstract public void onStart();
}
diff --git a/sources/events/VSProcessEvent.java b/sources/events/VSProcessEvent.java
deleted file mode 100644
index dcffa5e..0000000
--- a/sources/events/VSProcessEvent.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package events;
-
-import core.VSProcess;
-import prefs.VSPrefs;
-
-abstract public class VSProcessEvent implements VSEvent {
- protected VSProcess process;
- protected VSPrefs prefs;
-
- public void init(VSProcess process) {
- this.process = process;
- this.prefs = process.getPrefs();
- }
-
- public void logg(String message) {
- process.logg(message);
- }
-
- abstract public void onStart();
-}
diff --git a/sources/events/VSRegisteredEvents.java b/sources/events/VSRegisteredEvents.java
index 38676ca..5f73fea 100644
--- a/sources/events/VSRegisteredEvents.java
+++ b/sources/events/VSRegisteredEvents.java
@@ -7,4 +7,114 @@ import core.*;
import utils.*;
public final class VSRegisteredEvents {
+ private static HashMap<String,String> eventClassnames;
+ private static HashMap<String,String> eventShortnames;
+ private static HashMap<String,String> eventNames;
+ private static VSPrefs prefs;
+
+ public static void init(VSPrefs prefs_) {
+ prefs = prefs_;
+ eventNames = new HashMap<String, String>();
+ eventShortnames = new HashMap<String, String>();
+ eventClassnames = new HashMap<String, String>();
+
+ registerEvent("events.implementations.ProcessCrashEvent", "Prozessabsturz", null);
+ registerEvent("events.implementations.ProcessRecoverEvent", "Prozesswiederbelebung", null);
+ registerEvent("protocols.implementations.BerkelyTimeProtocol", "Berkeley Algorithmus zur internen Sync.", "Berkeley");
+ registerEvent("protocols.implementations.BroadcastSturmProtocol", "Broadcaststurm", null);
+ registerEvent("protocols.implementations.DummyProtocol", "Beispiel/Dummy", null);
+ registerEvent("protocols.implementations.ExternalTimeSyncProtocol", "Christians Methode zur externen Sync.", "Christians");
+ registerEvent("protocols.implementations.InternalTimeSyncProtocol", "Interne Synchronisation", "Interne Sync.");
+ registerEvent("protocols.implementations.PingPongProtocol", "Ping Pong", null);
+ }
+
+ public static Vector<String> getProtocolNames() {
+ Set<String> set = eventClassnames.keySet();
+ Vector<String> vector = new Vector<String>();
+
+ for (String eventName : set)
+ if (getClassname(eventName).startsWith("protocols"))
+ vector.add(eventName);
+
+ Collections.sort(vector);
+
+ return vector;
+ }
+
+ public static Vector<String> getProtocolClassnames() {
+ Set<String> set = eventNames.keySet();
+ Vector<String> vector = new Vector<String>();
+
+ for (String eventClassname : set)
+ if (eventClassname.startsWith("protocols"))
+ vector.add(eventClassname);
+
+ Collections.sort(vector);
+
+ return vector;
+ }
+
+ public static Vector<String> getNonProtocolNames() {
+ Set<String> set = eventClassnames.keySet();
+ Vector<String> vector = new Vector<String>();
+
+ for (String eventName : set)
+ if (!getClassname(eventName).startsWith("protocols"))
+ vector.add(eventName);
+
+ Collections.sort(vector);
+
+ return vector;
+ }
+
+ public static Vector<String> getNonProtocolClassnames() {
+ Set<String> set = eventNames.keySet();
+ Vector<String> vector = new Vector<String>();
+
+ for (String eventClassname : set)
+ if (!eventClassname.startsWith("protocols"))
+ vector.add(eventClassname);
+
+ Collections.sort(vector);
+
+ return vector;
+ }
+
+ public static String getClassname(String eventName) {
+ return eventClassnames.get(eventName);
+ }
+
+ public static String getName(String eventClassname) {
+ return eventNames.get(eventClassname);
+ }
+
+ public static String getShortname(String eventClassname) {
+ return eventShortnames.get(eventClassname);
+ }
+
+ public static VSEvent createEventInstanceByClassname(String eventClassname, VSProcess process) {
+ return createEventInstanceByName(getName(eventClassname), process);
+ }
+
+ public static VSEvent createEventInstanceByName(String eventName, VSProcess process) {
+ final String eventClassname = eventClassnames.get(eventName);
+ final Object protocolObj = new VSClassLoader().newInstance(eventClassname);
+
+ if (protocolObj instanceof VSEvent) {
+ VSEvent event = (VSEvent) protocolObj;
+ event.init(process);
+ return event;
+ }
+
+ return null;
+ }
+
+ private static void registerEvent(String eventClassname, String eventName, String eventShortname) {
+ if (eventShortname == null)
+ eventShortname = eventName;
+
+ eventNames.put(eventClassname, eventName);
+ eventShortnames.put(eventClassname, eventShortname);
+ eventClassnames.put(eventName, eventClassname);
+ }
}
diff --git a/sources/events/implementations/ProcessCrashEvent.java b/sources/events/implementations/ProcessCrashEvent.java
index c82fdb4..d675091 100644
--- a/sources/events/implementations/ProcessCrashEvent.java
+++ b/sources/events/implementations/ProcessCrashEvent.java
@@ -1,11 +1,17 @@
package events.implementations;
import core.VSProcess;
-import events.VSProcessEvent;
+import events.VSEvent;
+
+public class ProcessCrashEvent extends VSEvent {
+ protected void onInit() {
+ setClassname(getClass().toString());
+ }
-public class ProcessCrashEvent extends VSProcessEvent {
public void onStart() {
- process.isCrashed(true);
- logg(prefs.getString("lang.crashed"));
+ if (!process.isCrashed()) {
+ process.isCrashed(true);
+ logg(prefs.getString("lang.crashed"));
+ }
}
}
diff --git a/sources/events/implementations/ProcessRecoverEvent.java b/sources/events/implementations/ProcessRecoverEvent.java
index f0b54d4..231847c 100644
--- a/sources/events/implementations/ProcessRecoverEvent.java
+++ b/sources/events/implementations/ProcessRecoverEvent.java
@@ -1,11 +1,17 @@
package events.implementations;
import core.VSProcess;
-import events.VSProcessEvent;
+import events.VSEvent;
+
+public class ProcessRecoverEvent extends VSEvent {
+ protected void onInit() {
+ setClassname(getClass().toString());
+ }
-public class ProcessRecoverEvent extends VSProcessEvent {
public void onStart() {
- process.isCrashed(false);
- logg(prefs.getString("lang.recovered"));
+ if (process.isCrashed()) {
+ process.isCrashed(false);
+ logg(prefs.getString("lang.recovered"));
+ }
}
}
diff --git a/sources/events/implementations/ProtocolEvent.java b/sources/events/implementations/ProtocolEvent.java
index 442407d..096e9b6 100644
--- a/sources/events/implementations/ProtocolEvent.java
+++ b/sources/events/implementations/ProtocolEvent.java
@@ -1,20 +1,15 @@
package events.implementations;
import core.VSProcess;
-import events.VSProcessEvent;
-import protocols.VSRegisteredProtocols;
+import events.*;
-public class ProtocolEvent extends VSProcessEvent {
- private String protocolClassname;
+public class ProtocolEvent extends VSEvent {
+ private String eventClassname;
private boolean isClientProtocol; /* true = client, false = server */
private boolean isProtocolActivation; /* true = activate, false = deactivate */
- public void setProtocolClassname(String protocolClassname) {
- this.protocolClassname = protocolClassname;
- }
-
- public String getProtocolClassname() {
- return protocolClassname;
+ protected void onInit() {
+ setClassname(getClass().toString());
}
public void isClientProtocol(boolean isClientProtocol) {
@@ -33,13 +28,17 @@ public class ProtocolEvent extends VSProcessEvent {
return isProtocolActivation;
}
+ public void setEventClassname(String eventClassname) {
+ this.eventClassname = eventClassname;
+ }
+
public void onStart() {
String type = isClientProtocol ? "client" : "server";
- String name = VSRegisteredProtocols.getProtocolName(protocolClassname);
+ String name = VSRegisteredEvents.getName(eventClassname);
process.setBoolean("sim."+name.toLowerCase()+"."+type+".enabled!", isProtocolActivation);
StringBuffer buffer = new StringBuffer();
- buffer.append(VSRegisteredProtocols.getProtocolShortname(protocolClassname));
+ buffer.append(VSRegisteredEvents.getShortname(eventClassname));
buffer.append(" ");
buffer.append(isClientProtocol
? prefs.getString("lang.client") : prefs.getString("lang.server"));
diff --git a/sources/prefs/editors/VSProcessEditor.java b/sources/prefs/editors/VSProcessEditor.java
index 8392bdb..dcbe376 100644
--- a/sources/prefs/editors/VSProcessEditor.java
+++ b/sources/prefs/editors/VSProcessEditor.java
@@ -13,6 +13,7 @@ import simulator.*;
import utils.*;
import core.*;
import protocols.*;
+import events.*;
import prefs.VSPrefs;
public class VSProcessEditor extends VSEditorFrame {
@@ -65,7 +66,7 @@ public class VSProcessEditor extends VSEditorFrame {
private JPanel createProtocolSelector() {
JPanel panel = new JPanel(new GridBagLayout());
panel.setBorder(BorderFactory.createLineBorder(Color.black));
- Vector<String> registeredProtocols = VSRegisteredProtocols.getProtocolNames();
+ Vector<String> registeredProtocols = VSRegisteredEvents.getProtocolNames();
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
@@ -82,18 +83,18 @@ public class VSProcessEditor extends VSEditorFrame {
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals(prefs.getString("lang.edit"))) {
- String protocolName = (String) comboBox.getSelectedItem();
- String protocolClassname = VSRegisteredProtocols.getProtocolClassname(protocolName);
+ String eventName = (String) comboBox.getSelectedItem();
+ String eventClassname = VSRegisteredEvents.getClassname(eventName);
VSProtocol protocol = null;
- if (process.objectExists(protocolClassname)) {
- Object object = process.getObject(protocolClassname);
+ if (process.objectExists(eventClassname)) {
+ Object object = process.getObject(eventClassname);
if (object instanceof VSProtocol)
- protocol = (VSProtocol) process.getObject(protocolClassname);
+ protocol = (VSProtocol) process.getObject(eventClassname);
else
return;
} else {
- protocol = VSRegisteredProtocols.getProtocolInstanceByName(protocolName, process);
- process.setObject(protocolClassname, protocol);
+ protocol = (VSProtocol) VSRegisteredEvents.createEventInstanceByName(eventName, process);
+ process.setObject(eventClassname, protocol);
}
new VSProtocolEditor(prefs, frame, protocol);
}
diff --git a/sources/prefs/editors/VSProtocolEditor.java b/sources/prefs/editors/VSProtocolEditor.java
index 1cf5059..d0762a3 100644
--- a/sources/prefs/editors/VSProtocolEditor.java
+++ b/sources/prefs/editors/VSProtocolEditor.java
@@ -27,7 +27,7 @@ public class VSProtocolEditor extends VSEditorFrame {
public VSProtocolEditor(VSPrefs prefs, Component relativeTo, VSProtocol protocol) {
super(prefs, relativeTo, protocol, prefs.getString("name") + " - "
- + protocol.getProtocolName() + " " + prefs.getString("lang.editor"), ALL_PREFERENCES);
+ + protocol.getName() + " " + prefs.getString("lang.editor"), ALL_PREFERENCES);
this.protocol = protocol;
this.taskManager = protocol.getProcess().getSimulationPanel().getTaskManager();
@@ -130,12 +130,12 @@ public class VSProtocolEditor extends VSEditorFrame {
}
private void initClientServerCheckboxes() {
- final String protocolName = protocol.getProtocolName();
+ final String eventName = protocol.getName();
final VSProcess process = protocol.getProcess();
- String protocolKey = "sim."+protocolName.toLowerCase()+".client.enabled!";
+ String protocolKey = "sim."+eventName.toLowerCase()+".client.enabled!";
clientCheckBox.setSelected(process.getBoolean(protocolKey));
- protocolKey = "sim."+protocolName.toLowerCase()+".server.enabled!";
+ protocolKey = "sim."+eventName.toLowerCase()+".server.enabled!";
serverCheckBox.setSelected(process.getBoolean(protocolKey));
}
@@ -235,10 +235,10 @@ public class VSProtocolEditor extends VSEditorFrame {
resetTaskManager();
final VSProcess process = protocol.getProcess();
- final String protocolName = protocol.getProtocolName();
- String protocolKey = "sim."+protocolName.toLowerCase()+".client.enabled!";
+ final String eventName = protocol.getName();
+ String protocolKey = "sim."+eventName.toLowerCase()+".client.enabled!";
clientCheckBox.setSelected(process.getBoolean(protocolKey));
- protocolKey = "sim."+protocolName.toLowerCase()+".server.enabled!";
+ protocolKey = "sim."+eventName.toLowerCase()+".server.enabled!";
serverCheckBox.setSelected(process.getBoolean(protocolKey));
takeOverButton.setEnabled(clientCheckBox.isSelected());
@@ -269,7 +269,7 @@ public class VSProtocolEditor extends VSEditorFrame {
numItems = clientComboBox.getItemCount();
for (int i = 0; i < numItems; ++i) {
long taskTime = VSTools.getStringTime((String) clientComboBox.getItemAt(i));
- VSTask task = new VSTask(taskTime, protocol.getProcess(), protocol);
+ VSTask task = new VSTask(taskTime, protocol.getProcess(), protocol, VSTask.LOCAL);
task.isProgrammed(true);
tasks.addLast(task);
}
@@ -277,12 +277,12 @@ public class VSProtocolEditor extends VSEditorFrame {
taskManager.modifyProtocolTasks(protocol, tasks);
final VSProcess process = protocol.getProcess();
- final String protocolName = protocol.getProtocolName();
- String protocolKey = "sim."+protocolName.toLowerCase()+".client.enabled!";
+ final String eventName = protocol.getName();
+ String protocolKey = "sim."+eventName.toLowerCase()+".client.enabled!";
process.setBoolean(protocolKey, clientCheckBox.isSelected());
protocol.isClient(clientCheckBox.isSelected());
- protocolKey = "sim."+protocolName.toLowerCase()+".server.enabled!";
+ protocolKey = "sim."+eventName.toLowerCase()+".server.enabled!";
process.setBoolean(protocolKey, serverCheckBox.isSelected());
protocol.isServer(serverCheckBox.isSelected());
diff --git a/sources/protocols/VSProtocol.java b/sources/protocols/VSProtocol.java
index a7c5823..ceca348 100644
--- a/sources/protocols/VSProtocol.java
+++ b/sources/protocols/VSProtocol.java
@@ -1,47 +1,19 @@
package protocols;
import prefs.VSPrefs;
-import events.VSEvent;
+import events.*;
import core.*;
-abstract public class VSProtocol extends VSPrefs implements VSEvent {
- protected VSPrefs prefs;
- private String protocolClassname;
+abstract public class VSProtocol extends VSEvent {
private boolean isServer;
private boolean isClient;
- protected VSProcess process;
private boolean currentContextIsServer;
public void init(VSProcess process) {
- this.process = process;
- this.prefs = process.getPrefs();
-
+ super.init(process);
onInit();
}
- protected final void setProtocolClassname(String protocolClassname) {
- if (protocolClassname.startsWith("class "))
- protocolClassname = protocolClassname.substring(6);
-
- this.protocolClassname = protocolClassname;
- }
-
- public final String getProtocolClassname() {
- return protocolClassname;
- }
-
- public final String getProtocolName() {
- return VSRegisteredProtocols.getProtocolName(protocolClassname);
- }
-
- public final String getProtocolShortname() {
- return VSRegisteredProtocols.getProtocolShortname(protocolClassname);
- }
-
- public final VSProcess getProcess() {
- return process;
- }
-
protected void sendMessage(VSMessage message) {
process.increaseLamportTime();
process.increaseVectorTime();
@@ -50,7 +22,7 @@ abstract public class VSProtocol extends VSPrefs implements VSEvent {
}
private final boolean isIncorrectProtocol(VSMessage message) {
- return !message.getProtocolClassname().equals(getProtocolClassname());
+ return !message.getClassname().equals(getClassname());
}
public final void onStart() {
@@ -103,14 +75,6 @@ abstract public class VSProtocol extends VSPrefs implements VSEvent {
abstract protected void onServerReset();
abstract protected void onServerRecv(VSMessage message);
- public void logg(String message) {
- process.logg(toString() + "; " + message);
- }
-
- public boolean equals(VSProtocol protocol) {
- return protocol.getID() == getID();
- }
-
protected int getNumProcesses() {
return process.getSimulationPanel().getNumProcesses();
}
@@ -120,7 +84,7 @@ abstract public class VSProtocol extends VSPrefs implements VSEvent {
buffer.append(prefs.getString("lang.protocol"));
buffer.append(": ");
- buffer.append(getProtocolShortname());
+ buffer.append(getShortname());
buffer.append(" ");
if (currentContextIsServer)
diff --git a/sources/protocols/VSRegisteredProtocols.java b/sources/protocols/VSRegisteredProtocols.java
deleted file mode 100644
index d58385b..0000000
--- a/sources/protocols/VSRegisteredProtocols.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package protocols;
-
-import java.util.*;
-
-import prefs.*;
-import core.*;
-import utils.*;
-
-public final class VSRegisteredProtocols {
- private static HashMap<String,String> protocolClassnames;
- private static HashMap<String,String> protocolShortnames;
- private static HashMap<String,String> protocolNames;
- private static VSPrefs prefs;
-
- public static void init(VSPrefs prefs_) {
- prefs = prefs_;
- protocolNames = new HashMap<String, String>();
- protocolShortnames = new HashMap<String, String>();
- protocolClassnames = new HashMap<String, String>();
-
- registerProtocol("protocols.implementations.BerkelyTimeProtocol", "Berkeley Algorithmus zur internen Sync.", "Berkeley");
- registerProtocol("protocols.implementations.BroadcastSturmProtocol", "Broadcaststurm", null);
- registerProtocol("protocols.implementations.DummyProtocol", "Beispiel/Dummy", null);
- registerProtocol("protocols.implementations.ExternalTimeSyncProtocol", "Christians Methode zur externen Sync.", "Christians");
- registerProtocol("protocols.implementations.InternalTimeSyncProtocol", "Interne Synchronisation", "Interne Sync.");
- registerProtocol("protocols.implementations.PingPongProtocol", "Ping Pong", null);
- }
-
- public static Vector<String> getProtocolNames() {
- Set<String> set = protocolClassnames.keySet();
- Vector<String> vector = new Vector<String>();
-
- for (String protocolName : set)
- vector.add(protocolName);
-
- Collections.sort(vector);
-
- return vector;
- }
-
- public static Vector<String> getProtocolClassnames() {
- Set<String> set = protocolNames.keySet();
- Vector<String> vector = new Vector<String>();
-
- for (String protocolClassname : set)
- vector.add(protocolClassname);
-
- Collections.sort(vector);
-
- return vector;
- }
-
- public static String getProtocolClassname(String protocolName) {
- return protocolClassnames.get(protocolName);
- }
-
- public static String getProtocolName(String protocolClassname) {
- return protocolNames.get(protocolClassname);
- }
-
- public static String getProtocolShortname(String protocolClassname) {
- return protocolShortnames.get(protocolClassname);
- }
-
- public static VSProtocol getProtocolInstanceByName(String protocolName, VSProcess process) {
- final String protocolClassname = protocolClassnames.get(protocolName);
- final Object protocolObj = new VSClassLoader().newInstance(protocolClassname);
-
- if (protocolObj instanceof VSProtocol) {
- VSProtocol protocol = (VSProtocol) protocolObj;
- protocol.init(process);
- return protocol;
- }
-
- return null;
- }
-
- private static void registerProtocol(String protocolClassname, String protocolName, String protocolShortname) {
- if (protocolShortname == null)
- protocolShortname = protocolName;
-
- protocolNames.put(protocolClassname, protocolName);
- protocolShortnames.put(protocolClassname, protocolShortname);
- protocolClassnames.put(protocolName, protocolClassname);
- }
-}
diff --git a/sources/protocols/implementations/BerkelyTimeProtocol.java b/sources/protocols/implementations/BerkelyTimeProtocol.java
index 0063de1..c64e175 100644
--- a/sources/protocols/implementations/BerkelyTimeProtocol.java
+++ b/sources/protocols/implementations/BerkelyTimeProtocol.java
@@ -21,7 +21,7 @@ public class BerkelyTimeProtocol extends VSProtocol {
/* Berkely Client vairables */
protected void onInit() {
- setProtocolClassname(getClass().toString());
+ setClassname(getClass().toString());
/* Those prefs are editable through the VSProtocol VSEditor GUI. t_min and t_max in milliseconds */
setInteger("numProcesses", getNumProcesses()-1);
@@ -35,7 +35,7 @@ public class BerkelyTimeProtocol extends VSProtocol {
protected void onClientStart() {
requestTime = process.getTime();
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setBoolean("isRequest", true);
sendMessage(message);
}
@@ -88,7 +88,7 @@ public class BerkelyTimeProtocol extends VSProtocol {
for (Integer processID : processTimes.keySet()) {
long realProcessTime = realTimesRTT.get(processID).longValue();
long diff = avgTime - realProcessTime;
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setBoolean("isJustify", true);
message.setLong("timeDiff", diff);
message.setInteger("receiverProcessID", processID);
@@ -101,7 +101,7 @@ public class BerkelyTimeProtocol extends VSProtocol {
protected void onServerRecv(VSMessage recvMessage) {
if (recvMessage.getBoolean("isRequest")) {
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setInteger("processID", process.getProcessID());
message.setLong("time", process.getTime());
message.setBoolean("isResponse", true);
diff --git a/sources/protocols/implementations/BroadcastSturmProtocol.java b/sources/protocols/implementations/BroadcastSturmProtocol.java
index c68b548..7ef2c31 100644
--- a/sources/protocols/implementations/BroadcastSturmProtocol.java
+++ b/sources/protocols/implementations/BroadcastSturmProtocol.java
@@ -11,7 +11,7 @@ public class BroadcastSturmProtocol extends VSProtocol {
private static int broadcastCount;
protected void onInit() {
- setProtocolClassname(getClass().toString());
+ setClassname(getClass().toString());
sentMessages = new ArrayList<VSMessage>();
}
@@ -19,7 +19,7 @@ public class BroadcastSturmProtocol extends VSProtocol {
}
protected void onClientStart() {
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setInteger("Broadcast", broadcastCount++);
sentMessages.add(message);
sendMessage(message);
@@ -34,7 +34,7 @@ public class BroadcastSturmProtocol extends VSProtocol {
protected void onServerRecv(VSMessage recvMessage) {
if (!sentMessages.contains(recvMessage)) {
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setInteger("Broadcast", recvMessage.getInteger("Broadcast"));
sentMessages.add(message);
diff --git a/sources/protocols/implementations/DummyProtocol.java b/sources/protocols/implementations/DummyProtocol.java
index e79f62d..4e5d2cf 100644
--- a/sources/protocols/implementations/DummyProtocol.java
+++ b/sources/protocols/implementations/DummyProtocol.java
@@ -5,7 +5,7 @@ import core.VSMessage;
public class DummyProtocol extends VSProtocol {
protected void onInit() {
- setProtocolClassname(getClass().toString());
+ setClassname(getClass().toString());
}
protected void onClientReset() {
@@ -15,7 +15,7 @@ public class DummyProtocol extends VSProtocol {
protected void onClientStart() {
logg("onClientStart()");
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setString("Greeting", "Hello World!");
message.setInteger("A number", 1);
message.setBoolean("A boolean", true);
diff --git a/sources/protocols/implementations/ExternalTimeSyncProtocol.java b/sources/protocols/implementations/ExternalTimeSyncProtocol.java
index 3f40eca..49c4b51 100644
--- a/sources/protocols/implementations/ExternalTimeSyncProtocol.java
+++ b/sources/protocols/implementations/ExternalTimeSyncProtocol.java
@@ -9,7 +9,7 @@ public class ExternalTimeSyncProtocol extends VSProtocol {
private boolean waitingForResponse;
protected void onInit() {
- setProtocolClassname(getClass().toString());
+ setClassname(getClass().toString());
}
protected void onClientReset() {
@@ -20,7 +20,7 @@ public class ExternalTimeSyncProtocol extends VSProtocol {
waitingForResponse = true;
/* Multicast message to all processes */
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setBoolean("isClientRequest", true);
sendMessage(message);
}
@@ -51,7 +51,7 @@ public class ExternalTimeSyncProtocol extends VSProtocol {
return;
/* Multicast message to all processes */
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setLong("time", process.getTime());
message.setBoolean("isServerResponse", true);
sendMessage(message);
diff --git a/sources/protocols/implementations/InternalTimeSyncProtocol.java b/sources/protocols/implementations/InternalTimeSyncProtocol.java
index ccef2d3..cbe9fa8 100644
--- a/sources/protocols/implementations/InternalTimeSyncProtocol.java
+++ b/sources/protocols/implementations/InternalTimeSyncProtocol.java
@@ -8,7 +8,7 @@ public class InternalTimeSyncProtocol extends VSProtocol {
private boolean waitingForResponse;
protected void onInit() {
- setProtocolClassname(getClass().toString());
+ setClassname(getClass().toString());
/* Those prefs are editable through the VSProtocol VSEditor GUI. t_min and t_max in milliseconds */
setLong("t_min", 1000);
@@ -22,7 +22,7 @@ public class InternalTimeSyncProtocol extends VSProtocol {
waitingForResponse = true;
/* Multicast message to all processes */
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setBoolean("isClientRequest", true);
sendMessage(message);
}
@@ -58,7 +58,7 @@ public class InternalTimeSyncProtocol extends VSProtocol {
return;
/* Multicast message to all processes */
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setLong("time", process.getTime());
message.setBoolean("isServerResponse", true);
sendMessage(message);
diff --git a/sources/protocols/implementations/PingPongProtocol.java b/sources/protocols/implementations/PingPongProtocol.java
index aa2ce16..47a222d 100644
--- a/sources/protocols/implementations/PingPongProtocol.java
+++ b/sources/protocols/implementations/PingPongProtocol.java
@@ -9,7 +9,7 @@ public class PingPongProtocol extends VSProtocol {
private int serverCounter;
protected void onInit() {
- setProtocolClassname(getClass().toString());
+ setClassname(getClass().toString());
}
protected void onClientReset() {
@@ -17,7 +17,7 @@ public class PingPongProtocol extends VSProtocol {
}
protected void onClientStart() {
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setBoolean("fromClient", true);
message.setInteger("counter", ++clientCounter);
sendMessage(message);
@@ -29,7 +29,7 @@ public class PingPongProtocol extends VSProtocol {
logg("message: " + recvMessage.getInteger("counter"));
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setBoolean("fromClient", true);
message.setInteger("counter", ++clientCounter);
sendMessage(message);
@@ -45,7 +45,7 @@ public class PingPongProtocol extends VSProtocol {
logg("message: " + recvMessage.getInteger("counter"));
- VSMessage message = new VSMessage(getProtocolClassname());
+ VSMessage message = new VSMessage(getClassname());
message.setBoolean("fromServer", true);
message.setInteger("counter", ++serverCounter);
sendMessage(message);
diff --git a/sources/simulator/VSMain.java b/sources/simulator/VSMain.java
index 9646c64..58dfdb0 100644
--- a/sources/simulator/VSMain.java
+++ b/sources/simulator/VSMain.java
@@ -4,9 +4,9 @@ import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
+import events.*;
import prefs.*;
import prefs.editors.*;
-import protocols.*;
public class VSMain {
public VSMain(VSPrefs prefs) {
@@ -28,7 +28,7 @@ public class VSMain {
} catch (Exception e) { }
VSPrefs prefs = VSDefaultPrefs.init();
- VSRegisteredProtocols.init(prefs);
+ VSRegisteredEvents.init(prefs);
new VSMain(prefs);
}
}
diff --git a/sources/simulator/VSSimulation.java b/sources/simulator/VSSimulation.java
index d3547e3..7f10070 100644
--- a/sources/simulator/VSSimulation.java
+++ b/sources/simulator/VSSimulation.java
@@ -9,6 +9,8 @@ import javax.swing.event.*;
import javax.swing.table.*;
import core.*;
+import events.*;
+import events.implementations.*;
import prefs.*;
import protocols.*;
import utils.*;
@@ -18,7 +20,8 @@ public class VSSimulation extends VSFrame implements ActionListener {
private JCheckBox filterActiveCheckBox;
private JCheckBox lamportActiveCheckBox;
private JCheckBox vectorTimeActiveCheckBox;
- private JComboBox processesComboBox;
+ private JComboBox processesComboBox;
+ private ArrayList<VSCreateTask> createTasks;
private JMenuItem pauseItem;
private JMenuItem replayItem;
private JMenuItem resetItem;
@@ -30,8 +33,9 @@ public class VSSimulation extends VSFrame implements ActionListener {
private VSPrefs prefs;
private VSSimulationPanel simulationPanel;
private boolean hasStarted = false;
- private VSTaskManagerTableModel taskManagerLocalModel;
- private VSTaskManagerTableModel taskManagerGlobalModel;
+ private VSTaskManagerTableModel taskManagerLocalModel;
+ private VSTaskManagerTableModel taskManagerGlobalModel;
+ private VSTaskManager taskManager;
public VSSimulation (VSPrefs prefs, Component relativeTo) {
super(prefs.getString("name"), relativeTo);
@@ -168,8 +172,9 @@ public class VSSimulation extends VSFrame implements ActionListener {
- prefs.getInteger("window.loggsize"));
simulationPanel = new VSSimulationPanel(prefs, this, logging);
+ taskManager = simulationPanel.getTaskManager();
logging.setSimulationPanel(simulationPanel);
- simulationPanel.setBackground(prefs.getColor("paintarea.background"));//new Color(0xFD, 0xFC, 0xF7));
+ simulationPanel.setBackground(prefs.getColor("paintarea.background"));
JScrollPane paintScrollPane = new JScrollPane(simulationPanel);
JScrollPane textScrollPane = new JScrollPane(loggingArea);
@@ -309,11 +314,11 @@ public class VSSimulation extends VSFrame implements ActionListener {
splitPane2.setTopComponent(processesComboBox);
splitPane2.setBottomComponent(splitPane1);
- processesComboBox.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- updateTaskManagerTable();
- }
- });
+ processesComboBox.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ updateTaskManagerTable();
+ }
+ });
return splitPane2;
}
@@ -338,124 +343,277 @@ public class VSSimulation extends VSFrame implements ActionListener {
JScrollPane scrollPane = new JScrollPane(createTaskTable(localTasks));
panel.add(scrollPane);
- initAddPanel(panel);
+ initAddPanel(panel, localTasks);
return panel;
}
+ private class VSCreateTask {
+ private String eventClassname;
+
+ /* Those 3 values are for ProtocolEvent events */
+ private boolean isProtocolActivation;
+ private boolean isProtocolDeactivation;
+ private boolean isClientProtocol;
+
+ public VSCreateTask(String eventClassname) {
+ this.eventClassname = eventClassname;
+ }
+
+ public void isProtocolActivation(boolean isProtocolActivation) {
+ this.isProtocolActivation = isProtocolActivation;
+
+ if (isProtocolActivation)
+ isProtocolDeactivation(false);
+ }
+
+ public void isProtocolDeactivation(boolean isProtocolDeactivation) {
+ this.isProtocolDeactivation = isProtocolDeactivation;
+
+ if (isProtocolDeactivation)
+ isProtocolActivation(false);
+ }
+
+ public void isClientProtocol(boolean isClientProtocol) {
+ this.isClientProtocol = isClientProtocol;
+ }
+
+ public VSTask createTask(VSProcess process, long time, boolean localTimedTask) {
+ VSEvent event = VSRegisteredEvents.createEventInstanceByClassname(eventClassname, process);
+
+ if (isProtocolActivation || isProtocolDeactivation) {
+ ProtocolEvent protocolEvent = (ProtocolEvent) event;
+ protocolEvent.setEventClassname(eventClassname);
+ protocolEvent.isProtocolActivation(isProtocolActivation);
+ protocolEvent.isClientProtocol(isClientProtocol);
+ }
+
+ return new VSTask(time, process, event, localTimedTask);
+ }
+ }
+
private class VSTaskManagerTableModel extends AbstractTableModel {
- public static final boolean LOCAL = true;
- public static final boolean GLOBAL = false;
- private VSTaskManager taskManager;
- private ArrayList<VSTask> tasks;
+ public static final boolean LOCAL = true;
+ public static final boolean GLOBAL = false;
+ private VSPriorityQueue<VSTask> tasks;
private String columnNames[];
- private VSProcess process;
-
- public VSTaskManagerTableModel(VSProcess process, boolean localTask) {
- taskManager = simulationPanel.getTaskManager();
- set(process, localTask);
- columnNames = new String[2];
- columnNames[0]= prefs.getString("lang.time") + " (ms)";
- columnNames[1] = prefs.getString("lang.event");
- }
-
- public void set(VSProcess process, boolean localTasks) {
- this.process = process;
- this.tasks = localTasks
- ? taskManager.getProcessLocalTasks(process)
- : taskManager.getProcessGlobalTasks(process);
-
- fireTableDataChanged();
- }
-
- public String getColumnName(int col) {
- if (col == 0)
- return columnNames[0];
- return columnNames[1];
- }
-
- public int getRowCount() {
- return tasks.size();
- }
-
- public int getColumnCount() {
- return 2;
- }
-
- public Object getValueAt(int row, int col) {
- VSTask task = tasks.get(row);
-
- if (col == 0)
- return task.getTaskTime();
-
- return task.toStringBrief();
- }
-
- public boolean isCellEditable(int row, int col) {
- return false;
- }
-
- public void setValueAt(Object value, int row, int col) {
- }
- }
+ private VSProcess process;
+
+ public VSTaskManagerTableModel(VSProcess process, boolean localTask) {
+ set(process, localTask);
+ columnNames = new String[2];
+ columnNames[0]= prefs.getString("lang.time") + " (ms)";
+ columnNames[1] = prefs.getString("lang.event");
+ }
+
+ public void set(VSProcess process, boolean localTasks) {
+ this.process = process;
+ this.tasks = localTasks
+ ? taskManager.getProcessLocalTasks(process)
+ : taskManager.getProcessGlobalTasks(process);
+
+ fireTableDataChanged();
+ }
+
+ public String getColumnName(int col) {
+ if (col == 0)
+ return columnNames[0];
+ return columnNames[1];
+ }
+
+ public int getRowCount() {
+ return tasks.size();
+ }
+
+ public int getColumnCount() {
+ return 2;
+ }
+
+ public Object getValueAt(int row, int col) {
+ VSTask task = tasks.get(row);
+
+ if (col == 0)
+ return task.getTaskTime();
+
+ return task.getEvent().getShortname();
+ }
+
+ public boolean isCellEditable(int row, int col) {
+ return false;
+ }
+
+ public void setValueAt(Object value, int row, int col) {
+ fireTableDataChanged();
+ }
+
+ public void addTask(VSTask task) {
+ tasks.add(task);
+ fireTableDataChanged();
+ }
+ }
private JTable createTaskTable(boolean localTasks) {
- VSProcess process = getSelectedProcess();
- VSTaskManagerTableModel model = new VSTaskManagerTableModel(process, localTasks);
+ VSProcess process = getSelectedProcess();
+ VSTaskManagerTableModel model = new VSTaskManagerTableModel(process, localTasks);
- if (localTasks)
- taskManagerLocalModel = model;
- else
- taskManagerGlobalModel = model;
+ if (localTasks)
+ taskManagerLocalModel = model;
+ else
+ taskManagerGlobalModel = model;
JTable table = new JTable(model);
- TableColumn col = table.getColumnModel().getColumn(0);
- col.setMaxWidth(75);
- col.setResizable(false);
- col = table.getColumnModel().getColumn(1);
- col.sizeWidthToFit();
+ TableColumn col = table.getColumnModel().getColumn(0);
+ col.setMaxWidth(75);
+ col.setResizable(false);
+ col = table.getColumnModel().getColumn(1);
+ col.sizeWidthToFit();
table.setBackground(Color.WHITE);
return table;
}
- private void initAddPanel(JPanel panel) {
+ private void initAddPanel(JPanel panel, final boolean localTasks) {
JPanel panel1 = new JPanel();
panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
- panel1.add(new JTextField());
+ final JTextField textField = new JTextField();
+ textField.setText("0000");
+ textField.setBackground(Color.WHITE);
+ panel1.add(textField);
+
panel1.add(new JLabel(" ms "));
+ final JComboBox comboBox = new JComboBox();
+
JButton takeoverButton = new JButton(prefs.getString("lang.takeover"));
+ takeoverButton.addActionListener(new ActionListener() {
+ private boolean isRed;
+
+ public void actionPerformed(ActionEvent ae) {
+ String textValue = textField.getText();
+ Long longValue = null;
+
+ try {
+ longValue = Long.valueOf(textValue);
+
+ if (longValue.longValue() < 0) {
+ makeRed();
+ return;
+ }
+
+ if (isRed) {
+ makeWhite();
+ }
+
+ } catch (NumberFormatException e) {
+ makeRed();
+ }
+
+ if (longValue == null)
+ return;
+
+ if (takeover(longValue.longValue())) {
+ if (isRed)
+ makeWhite();
+
+ } else {
+ makeRed();
+ }
+ }
+
+ private void makeWhite() {
+ textField.setBackground(Color.WHITE);
+ isRed = false;
+ }
+
+ private void makeRed() {
+ textField.setBackground(Color.RED);
+ isRed = true;
+ }
+
+ private boolean takeover(long time) {
+ VSProcess process = getSelectedProcess();
+ int index = comboBox.getSelectedIndex();
+ VSCreateTask createTask = createTasks.get(index);
+
+ if (createTask == null)
+ return false;
+
+ VSTask task = createTask.createTask(process, time, localTasks);
+ taskManager.addTask(task, VSTaskManager.PROGRAMMED);
+
+ if (localTasks)
+ taskManagerLocalModel.addTask(task);
+ else
+ taskManagerGlobalModel.addTask(task);
+
+ return true;
+ }
+ });
+
panel1.add(takeoverButton);
- JComboBox comboBox = new JComboBox();
- comboBox.setMaximumRowCount(15);
+ boolean flag = createTasks == null;
+ if (flag) createTasks = new ArrayList<VSCreateTask>();
+
+ Vector<String> eventClassnames = VSRegisteredEvents.getNonProtocolClassnames();
+
+ comboBox.setMaximumRowCount(15);
comboBox.addItem("-- " + prefs.getString("lang.events.process") + " --");
- comboBox.addItem(prefs.getString("lang.crash"));
- comboBox.addItem(prefs.getString("lang.recover"));
+ if (flag) createTasks.add(null);
+
+ for (String eventClassname : eventClassnames) {
+ String eventShortname = VSRegisteredEvents.getShortname(eventClassname);
+ comboBox.addItem(eventShortname);
+ if (flag) createTasks.add(new VSCreateTask(eventClassname));
+ }
comboBox.addItem("-- " + prefs.getString("lang.events.protocol") + " --");
+ if (flag) createTasks.add(null);
- Vector<String> protocolClassnames = VSRegisteredProtocols.getProtocolClassnames();
+ eventClassnames = VSRegisteredEvents.getProtocolClassnames();
String activate = prefs.getString("lang.activate");
String deactivate = prefs.getString("lang.deactivate");
String client = prefs.getString("lang.client");
String server = prefs.getString("lang.server");
- for (String protocolClassname : protocolClassnames) {
- String protocolShortname = VSRegisteredProtocols.getProtocolShortname(protocolClassname);
- comboBox.addItem(protocolShortname + " " + client + " " + activate);
- comboBox.addItem(protocolShortname + " " + client + " " + deactivate);
- comboBox.addItem(protocolShortname + " " + server + " " + activate);
- comboBox.addItem(protocolShortname + " " + server + " " + deactivate);
+ for (String eventClassname : eventClassnames) {
+ String eventShortname = VSRegisteredEvents.getShortname(eventClassname);
+ comboBox.addItem(eventShortname + " " + client + " " + activate);
+ comboBox.addItem(eventShortname + " " + client + " " + deactivate);
+ comboBox.addItem(eventShortname + " " + server + " " + activate);
+ comboBox.addItem(eventShortname + " " + server + " " + deactivate);
+
+ if (flag) {
+ VSCreateTask createTask = new VSCreateTask(eventClassname);
+ createTask.isProtocolActivation(true);
+ createTask.isClientProtocol(true);
+ createTasks.add(createTask);
+
+ createTask = new VSCreateTask(eventClassname);
+ createTask.isProtocolDeactivation(true);
+ createTask.isClientProtocol(true);
+ createTasks.add(createTask);
+
+ createTask = new VSCreateTask(eventClassname);
+ createTask.isProtocolActivation(true);
+ createTask.isClientProtocol(false);
+ createTasks.add(createTask);
+
+ createTask = new VSCreateTask(eventClassname);
+ createTask.isProtocolDeactivation(true);
+ createTask.isClientProtocol(false);
+ createTasks.add(createTask);
+ }
}
comboBox.addItem("-- " + prefs.getString("lang.requests") + " --");
+ if (flag) createTasks.add(null);
String clientrequest = prefs.getString("lang.clientrequest.start");
- for (String protocolClassname : protocolClassnames) {
- String protocolShortname = VSRegisteredProtocols.getProtocolShortname(protocolClassname);
- comboBox.addItem(protocolShortname + " " + clientrequest);
+ for (String eventClassname : eventClassnames) {
+ String eventShortname = VSRegisteredEvents.getShortname(eventClassname);
+ comboBox.addItem(eventShortname + " " + clientrequest);
+ if (flag) createTasks.add(new VSCreateTask(eventClassname));
}
panel.add(comboBox);
@@ -532,20 +690,20 @@ public class VSSimulation extends VSFrame implements ActionListener {
}
}
- private VSProcess getSelectedProcess() {
- String string = (String) processesComboBox.getSelectedItem();
- int cutLen = prefs.getString("lang.process").length() + 1;
- string = string.substring(cutLen);
- int processNum = Integer.parseInt(string) - 1;
+ private VSProcess getSelectedProcess() {
+ String string = (String) processesComboBox.getSelectedItem();
+ int cutLen = prefs.getString("lang.process").length() + 1;
+ string = string.substring(cutLen);
+ int processNum = Integer.parseInt(string) - 1;
- return simulationPanel.getProcess(processNum);
- }
+ return simulationPanel.getProcess(processNum);
+ }
- public void updateTaskManagerTable() {
- VSProcess process = getSelectedProcess();
- taskManagerLocalModel.set(process, VSTaskManagerTableModel.LOCAL);
- taskManagerGlobalModel.set(process, VSTaskManagerTableModel.GLOBAL);
- }
+ public void updateTaskManagerTable() {
+ VSProcess process = getSelectedProcess();
+ taskManagerLocalModel.set(process, VSTaskManagerTableModel.LOCAL);
+ taskManagerGlobalModel.set(process, VSTaskManagerTableModel.GLOBAL);
+ }
public void finish() {
startItem.setEnabled(false);
diff --git a/sources/simulator/VSSimulationPanel.java b/sources/simulator/VSSimulationPanel.java
index 6514963..b1836c1 100644
--- a/sources/simulator/VSSimulationPanel.java
+++ b/sources/simulator/VSSimulationPanel.java
@@ -597,7 +597,7 @@ public class VSSimulationPanel extends JPanel implements Runnable, MouseMotionLi
if (receiverProcess.equals(sendingProcess)) {
if (recvOwn) {
deliverTime = sendingProcess.getGlobalTime();
- task = new VSTask(deliverTime, receiverProcess, message);
+ task = new VSTask(deliverTime, receiverProcess, message, VSTask.GLOBAL);
taskManager.addTask(task);
}
@@ -608,7 +608,7 @@ public class VSSimulationPanel extends JPanel implements Runnable, MouseMotionLi
/* Only add a 'receiving message' task if the message will not get lost! */
if (outageTime == -1) {
- task = new VSTask(deliverTime, receiverProcess, message);
+ task = new VSTask(deliverTime, receiverProcess, message, VSTask.GLOBAL);
taskManager.addTask(task);
}
@@ -636,14 +636,14 @@ public class VSSimulationPanel extends JPanel implements Runnable, MouseMotionLi
editProcess(process);
} else if (actionCommand.equals(prefs.getString("lang.crash"))) {
- VSProcessEvent event = new ProcessCrashEvent();
+ VSEvent event = new ProcessCrashEvent();
event.init(process);
- taskManager.addTask(new VSTask(process.getGlobalTime(), process, event));
+ taskManager.addTask(new VSTask(process.getGlobalTime(), process, event, VSTask.GLOBAL));
} else if (actionCommand.equals(prefs.getString("lang.recover"))) {
- VSProcessEvent event = new ProcessRecoverEvent();
+ VSEvent event = new ProcessRecoverEvent();
event.init(process);
- taskManager.addTask(new VSTask(process.getGlobalTime(), process, event));
+ taskManager.addTask(new VSTask(process.getGlobalTime(), process, event, VSTask.GLOBAL));
}
}
};
diff --git a/sources/utils/VSClassLoader.java b/sources/utils/VSClassLoader.java
index 8470f53..3e1611b 100644
--- a/sources/utils/VSClassLoader.java
+++ b/sources/utils/VSClassLoader.java
@@ -12,11 +12,9 @@ public class VSClassLoader extends ClassLoader {
try {
object = super.loadClass(classname, true).newInstance();
- //Constructor constructors[] = theClass.getConstructors();
- //object = constructors[0].newInstance(process);
} catch (Exception e) {
- System.out.println(e);
+ System.out.println(e + "; Classname " + classname);
}
return object;
diff --git a/sources/utils/VSPriorityQueue.java b/sources/utils/VSPriorityQueue.java
new file mode 100644
index 0000000..dd46a6e
--- /dev/null
+++ b/sources/utils/VSPriorityQueue.java
@@ -0,0 +1,15 @@
+package utils;
+
+import java.util.PriorityQueue;
+
+public final class VSPriorityQueue<T> extends PriorityQueue<T> {
+ public T get(int index) {
+ int i = 0;
+
+ for (T t : this)
+ if (i++ == index)
+ return t;
+
+ return null;
+ }
+}