summaryrefslogtreecommitdiff
path: root/sources
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
parentc46ed2242876bfb267ed0b6823c8a3e99ac62dd6 (diff)
The TaskManager works partly.
Diffstat (limited to 'sources')
-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;
- }
-