summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-05-20 16:36:49 +0000
committerPaul Buetow <paul@buetow.org>2008-05-20 16:36:49 +0000
commit8131638fc01dbde84864656e197b14772ff53346 (patch)
tree04a79601a8aa3d48a6c6c674f6baeafe61170374
parentda095a0767dfaabe363f2b7ed7d95fb35e066e14 (diff)
A VSMessage is not a VSEvent any more. Instead a MessageReceiveEvent has been introduced.
-rw-r--r--sources/core/VSMessage.java2
-rw-r--r--sources/core/VSTask.java83
-rw-r--r--sources/events/implementations/MessageReceiveEvent.java52
-rw-r--r--sources/prefs/VSDefaultPrefs.java1
-rw-r--r--sources/simulator/VSMain.java2
-rw-r--r--sources/simulator/VSSimulation.java2
-rw-r--r--sources/simulator/VSSimulationPanel.java9
7 files changed, 67 insertions, 84 deletions
diff --git a/sources/core/VSMessage.java b/sources/core/VSMessage.java
index 7e822b3..ab6bca8 100644
--- a/sources/core/VSMessage.java
+++ b/sources/core/VSMessage.java
@@ -5,7 +5,7 @@ import events.*;
import prefs.VSPrefs;
import protocols.*;
-public class VSMessage extends VSEvent {
+public class VSMessage extends VSPrefs {
private String protocolClassname;
private VSProcess sendingProcess;
private long messageID;
diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java
index 89c61fb..ada581b 100644
--- a/sources/core/VSTask.java
+++ b/sources/core/VSTask.java
@@ -32,8 +32,8 @@ public class VSTask implements Comparable {
return isProgrammed;
}
- public boolean isMessage() {
- return event instanceof VSMessage;
+ public boolean isMessageReceiveEvent() {
+ return event instanceof events.implementations.MessageReceiveEvent;
}
public boolean isProcessRecoverEvent() {
@@ -74,72 +74,8 @@ public class VSTask implements Comparable {
}
public void run() {
- if (event instanceof VSMessage) {
- onMessageRecv();
-
- } else if (event instanceof VSProtocol) {
- /* Lamport time will get incremented by the VSProtocol class */
- onProtocolStart();
-
- } else if (event instanceof VSEvent) {
- onEventStart();
-
- } else {
- onDummy();
- }
- }
-
- private void onDummy() {
- logg(prefs.getString("lang.process.task"));
- }
-
- /**
- * If the process recv a message, check if the message's protocol is activated
- * by the process. If yes, run the protocol on the message! If not, just logg
- * that the process does not support this protocol! The process will ignore the
- * message!
- */
- private void onMessageRecv() {
- final VSMessage message = (VSMessage) event;
- final String eventName = message.getName();
- final String protocolClassname = message.getProtocolClassname();
-
- process.updateLamportTime(message.getLamportTime()+1);
- process.updateVectorTime(message.getVectorTime());
-
- Object protocolObj;
-
- if (process.objectExists(protocolClassname))
- protocolObj = process.getObject(protocolClassname);
- else
- protocolObj = null;
-
- StringBuffer buffer = new StringBuffer();
- buffer.append(prefs.getString("lang.message.recv"));
- 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());
-
- } else {
- final VSProtocol protocol = (VSProtocol) protocolObj;
- logg(buffer.toString());
- protocol.onMessageRecv(message);
- }
- }
-
- private void onProtocolStart() {
- ((VSProtocol) event).onStart();
- }
-
- private void onEventStart() {
+ if (event.getProcess() == null)
+ event.init(process);
event.onStart();
}
@@ -160,16 +96,7 @@ public class VSTask implements Comparable {
buffer.append(prefs.getString("lang.task"));
buffer.append(" ");
buffer.append(getTaskTime());
-
- if (event instanceof VSMessage) {
- buffer.append("; ");
- buffer.append(((VSMessage)event).toString());
-
- } else if (event instanceof VSProtocol) {
- buffer.append("; ");
- buffer.append(((VSProtocol)event).toString());
- }
-
+ buffer.append(event.toString());
return buffer.toString();
}
diff --git a/sources/events/implementations/MessageReceiveEvent.java b/sources/events/implementations/MessageReceiveEvent.java
new file mode 100644
index 0000000..0a99b5f
--- /dev/null
+++ b/sources/events/implementations/MessageReceiveEvent.java
@@ -0,0 +1,52 @@
+package events.implementations;
+
+import core.VSMessage;
+import core.VSProcess;
+import events.VSEvent;
+import protocols.VSProtocol;
+
+public class MessageReceiveEvent extends VSEvent {
+ private VSMessage message;
+
+ public MessageReceiveEvent(VSMessage message) {
+ this.message = message;
+ }
+
+ protected void onInit() {
+ setClassname(getClass().toString());
+ }
+
+ public void onStart() {
+ String eventName = message.getName();
+ String protocolClassname = message.getProtocolClassname();
+
+ process.updateLamportTime(message.getLamportTime()+1);
+ process.updateVectorTime(message.getVectorTime());
+
+ Object protocolObj = null;
+
+ if (process.objectExists(protocolClassname))
+ protocolObj = process.getObject(protocolClassname);
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(prefs.getString("lang.message.recv"));
+ 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());
+
+ } else {
+ final VSProtocol protocol = (VSProtocol) protocolObj;
+ logg(buffer.toString());
+ protocol.onMessageRecv(message);
+ }
+
+ }
+}
diff --git a/sources/prefs/VSDefaultPrefs.java b/sources/prefs/VSDefaultPrefs.java
index 60fe1c8..5332988 100644
--- a/sources/prefs/VSDefaultPrefs.java
+++ b/sources/prefs/VSDefaultPrefs.java
@@ -193,6 +193,7 @@ public class VSDefaultPrefs extends VSPrefs {
}
public void fillDefaultBooleans() {
+ //initBoolean("sim.message.broadcast", false, "Nachrichten sind immer Broadcasts");
initBoolean("sim.message.own.recv", false, "Prozesse empfangen ihre eigenen Nachrichten");
}
}
diff --git a/sources/simulator/VSMain.java b/sources/simulator/VSMain.java
index 2f4c188..4398226 100644
--- a/sources/simulator/VSMain.java
+++ b/sources/simulator/VSMain.java
@@ -27,7 +27,7 @@ public class VSMain {
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) { }
- javax.swing.JPopupMenu.setDefaultLightWeightPopupEnabled(false);
+ javax.swing.JPopupMenu.setDefaultLightWeightPopupEnabled(false);
VSPrefs prefs = VSDefaultPrefs.init();
VSRegisteredEvents.init(prefs);
new VSMain(prefs);
diff --git a/sources/simulator/VSSimulation.java b/sources/simulator/VSSimulation.java
index 3252e58..8b4515b 100644
--- a/sources/simulator/VSSimulation.java
+++ b/sources/simulator/VSSimulation.java
@@ -70,7 +70,7 @@ public class VSSimulation extends VSFrame implements ActionListener {
globalTextFields.add("0000");
}
- processesComboBox.setSelectedIndex(numProcesses);
+ processesComboBox.setSelectedIndex(numProcesses);
}
private JMenuBar createJMenuBar() {
diff --git a/sources/simulator/VSSimulationPanel.java b/sources/simulator/VSSimulationPanel.java
index 9599ea2..fb7d6a1 100644
--- a/sources/simulator/VSSimulationPanel.java
+++ b/sources/simulator/VSSimulationPanel.java
@@ -665,6 +665,7 @@ public class VSSimulationPanel extends Canvas implements Runnable, MouseMotionLi
public void sendMessage(VSMessage message) {
VSTask task = null;
+ VSEvent messageReceiveEvent = null;
VSProcess sendingProcess = message.getSendingProcess();
long deliverTime, outageTime, durationTime;
boolean recvOwn = prefs.getBoolean("sim.message.own.recv");
@@ -673,7 +674,8 @@ public class VSSimulationPanel extends Canvas implements Runnable, MouseMotionLi
if (receiverProcess.equals(sendingProcess)) {
if (recvOwn) {
deliverTime = sendingProcess.getGlobalTime();
- task = new VSTask(deliverTime, receiverProcess, message, VSTask.GLOBAL);
+ messageReceiveEvent = new MessageReceiveEvent(message);
+ task = new VSTask(deliverTime, receiverProcess, messageReceiveEvent, VSTask.GLOBAL);
taskManager.addTask(task);
}
@@ -684,7 +686,8 @@ public class VSSimulationPanel extends Canvas 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, VSTask.GLOBAL);
+ messageReceiveEvent = new MessageReceiveEvent(message);
+ task = new VSTask(deliverTime, receiverProcess, messageReceiveEvent, VSTask.GLOBAL);
taskManager.addTask(task);
}
@@ -724,7 +727,7 @@ public class VSSimulationPanel extends Canvas implements Runnable, MouseMotionLi
}
};
-
+
JPopupMenu popup = new JPopupMenu();
JMenuItem item = new JMenuItem(prefs.getString("lang.edit"));
item.addActionListener(actionListener);