summaryrefslogtreecommitdiff
path: root/src/main/java/events
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-06 08:02:52 +0300
committerPaul Buetow <paul@buetow.org>2025-06-06 08:02:52 +0300
commit1d99762c7965d351510cfb5e08eac25e48d96038 (patch)
treef469493e911878ab9055ccf0494211bf9015922d /src/main/java/events
parent4d35597bd92607c4d194686e20b125044506c79a (diff)
Modernize project structure, update Maven config, move sources, add logging config, update README and .gitignore
Diffstat (limited to 'src/main/java/events')
-rw-r--r--src/main/java/events/VSAbstractEvent.java243
-rw-r--r--src/main/java/events/VSCopyableEvent.java16
-rw-r--r--src/main/java/events/VSRegisteredEvents.java346
-rw-r--r--src/main/java/events/implementations/VSProcessCrashEvent.java43
-rw-r--r--src/main/java/events/implementations/VSProcessRecoverEvent.java44
-rw-r--r--src/main/java/events/internal/VSAbstractInternalEvent.java58
-rw-r--r--src/main/java/events/internal/VSMessageReceiveEvent.java84
-rw-r--r--src/main/java/events/internal/VSProtocolEvent.java175
-rw-r--r--src/main/java/events/internal/VSProtocolScheduleEvent.java126
9 files changed, 1135 insertions, 0 deletions
diff --git a/src/main/java/events/VSAbstractEvent.java b/src/main/java/events/VSAbstractEvent.java
new file mode 100644
index 0000000..52c2423
--- /dev/null
+++ b/src/main/java/events/VSAbstractEvent.java
@@ -0,0 +1,243 @@
+package events;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import core.VSAbstractProcess;
+import core.VSInternalProcess;
+import exceptions.VSEventNotCopyableException;
+import prefs.VSPrefs;
+import prefs.VSSerializablePrefs;
+import serialize.VSSerialize;
+
+/**
+ * The class VSAbstractEvent. This abstract class defines the basic framework
+ * of each event. an event is used to fullfill a specific task. An event object
+ * will get stored in a VSTask object.
+ *
+ * @author Paul C. Buetow
+ */
+abstract public class VSAbstractEvent extends VSSerializablePrefs {
+ /** The prefs. */
+ public VSPrefs prefs;
+
+ /** The process. */
+ public VSAbstractProcess process;
+
+ /** The event shortname. */
+ private String eventShortname;
+
+ /** The event classname. */
+ private String eventClassname;
+
+ /**
+ * Creates a copy of the event and using a new process.
+ *
+ * @param theProcess The new process
+ * @return The copy
+ */
+ final public VSAbstractEvent getCopy(VSInternalProcess theProcess)
+ throws VSEventNotCopyableException {
+
+ if (theProcess == null)
+ theProcess = (VSInternalProcess) process;
+
+ if (!(this instanceof VSCopyableEvent))
+ throw new VSEventNotCopyableException(
+ eventShortname + " (" + eventClassname + ")");
+
+ VSAbstractEvent copy =
+ VSRegisteredEvents.createEventInstanceByClassname(
+ eventClassname, theProcess);
+
+ ((VSCopyableEvent) this).initCopy(copy);
+ copy.setShortname(eventShortname);
+
+ return copy;
+ }
+
+ /**
+ * Creates a copy of the event.
+ *
+ * @return The copy
+ */
+ final public VSAbstractEvent getCopy() throws VSEventNotCopyableException {
+ return getCopy(null);
+ }
+
+ /**
+ * Inits the event.
+ *
+ * @param process the process
+ */
+ public void init(VSInternalProcess process) {
+ if (this.process == null) {
+ this.process = process;
+ this.prefs = process.getPrefs();
+ init();
+ }
+ }
+
+ /**
+ * Inits the event without setting the processes and prefs variables
+ * of the object.
+ */
+ public void init() {
+ onInit();
+ }
+
+ /**
+ * Sets the classname.
+ *
+ * @param eventClassname the new classname
+ */
+ public final void setClassname(String eventClassname) {
+ if (eventClassname.startsWith("class "))
+ eventClassname = eventClassname.substring(6);
+
+ this.eventClassname = eventClassname;
+ }
+
+ /**
+ * Gets the classname.
+ *
+ * @return the classname
+ */
+ public String getClassname() {
+ return eventClassname;
+ }
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return VSRegisteredEvents.getNameByClassname(eventClassname);
+ }
+
+ /**
+ * Sets the shortname.
+ *
+ * @param eventShortname the new shortname
+ */
+ public void setShortname(String eventShortname) {
+ this.eventShortname = eventShortname;
+ }
+
+ /**
+ * Gets the shortname.
+ *
+ * @return the shortname
+ */
+ public String getShortname() {
+ if (eventShortname == null)
+ return VSRegisteredEvents.getShortnameByClassname(eventClassname);
+
+ return eventShortname;
+ }
+
+ /**
+ * Gets the process.
+ *
+ * @return the process
+ */
+ public VSAbstractProcess getProcess() {
+ return process;
+ }
+
+ /**
+ * Logg a specific message.
+ *
+ * @param message the loging message
+ */
+ public void log(String message) {
+ process.log(/*toString() + "; " + */message);
+ }
+
+ /**
+ * Checks if the event equals to another event..
+ *
+ * @param event the event to compare against.
+ *
+ * @return true, if the events are the same (have the same event id)
+ */
+ public boolean equals(VSAbstractEvent event) {
+ return super.getID() == event.getID();
+ }
+
+ /**
+ * Every event has its own initialize method.
+ */
+ abstract public void onInit();
+
+ /**
+ * Every event can get started. This method get's executed if the event
+ * takes place.
+ */
+ abstract public void onStart();
+
+ /**
+ * Every event has to be able to set its own shortname
+ *
+ * @param shortName The saved short name. May be overwritten due wrong lang
+ *
+ * @return The event's shortname
+ */
+ abstract protected String createShortname(String savedShortname);
+
+ /* (non-Javadoc)
+ * @see serialize.VSSerializable#serialize(serialize.VSSerialize,
+ * java.io.ObjectOutputStream)
+ */
+ public synchronized void serialize(VSSerialize serialize,
+ ObjectOutputStream objectOutputStream)
+ throws IOException {
+ super.serialize(serialize, objectOutputStream);
+
+ if (VSSerialize.DEBUG)
+ System.out.println("Serializing: VSAbstractEvent; id="+getID());
+
+ /** For later backwards compatibility, to add more stuff */
+ objectOutputStream.writeObject(Boolean.valueOf(false));
+
+ objectOutputStream.writeObject(Integer.valueOf(super.getID()));
+ objectOutputStream.writeObject(eventShortname);
+ objectOutputStream.writeObject(eventClassname);
+
+ /** For later backwards compatibility, to add more stuff */
+ objectOutputStream.writeObject(Boolean.valueOf(false));
+ }
+
+ /* (non-Javadoc)
+ * @see serialize.VSSerializable#deserialize(serialize.VSSerialize,
+ * java.io.ObjectInputStream)
+ */
+ public synchronized void deserialize(VSSerialize serialize,
+ ObjectInputStream objectInputStream)
+ throws IOException, ClassNotFoundException {
+ super.deserialize(serialize, objectInputStream);
+
+ if (VSSerialize.DEBUG)
+ System.out.print("Deserializing: VSAbstractEvent ");
+
+ /** For later backwards compatibility, to add more stuff */
+ objectInputStream.readObject();
+
+ int id = ((Integer) objectInputStream.readObject()).intValue();
+ String savedEventShortname = (String) objectInputStream.readObject();
+ this.eventClassname = (String) objectInputStream.readObject();
+ this.eventShortname = createShortname(savedEventShortname);
+
+ if (VSSerialize.DEBUG) {
+ System.out.println("eventClassname: " + eventClassname);
+ System.out.println("eventShortname: " + eventShortname);
+ }
+
+ serialize.setObject(id, "event", this);
+
+ /** For later backwards compatibility, to add more stuff */
+ objectInputStream.readObject();
+ }
+}
diff --git a/src/main/java/events/VSCopyableEvent.java b/src/main/java/events/VSCopyableEvent.java
new file mode 100644
index 0000000..23125ce
--- /dev/null
+++ b/src/main/java/events/VSCopyableEvent.java
@@ -0,0 +1,16 @@
+package events;
+
+/**
+ * The interface VSCopyableEvent, all events which implement this class
+ * are copyable.
+ *
+ * @author Paul C. Buetow
+ */
+public interface VSCopyableEvent {
+ /**
+ * Fills a copy of this event with its values
+ *
+ * @param copy The copy
+ */
+ public void initCopy(VSAbstractEvent copy);
+}
diff --git a/src/main/java/events/VSRegisteredEvents.java b/src/main/java/events/VSRegisteredEvents.java
new file mode 100644
index 0000000..6d50ae5
--- /dev/null
+++ b/src/main/java/events/VSRegisteredEvents.java
@@ -0,0 +1,346 @@
+package events;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.Vector;
+
+import core.VSInternalProcess;
+import prefs.VSPrefs;
+import utils.VSClassLoader;
+
+/**
+ * The class VSRegisteredEvents. This class is responsible to manage all
+ * events. It manages the event classnames, the event shortnames and the event
+ * names. It also checks if a protocol (which is an event as well) has
+ * variables which are editable through the GUI of the simulator.
+ *
+ * @author Paul C. Buetow
+ */
+public final class VSRegisteredEvents {
+ /** The event classnames by eventnames. */
+ private static HashMap<String,String> eventClassnamesByNames =
+ new HashMap<String,String>();
+
+ /** The event shortnames by classnames. */
+ private static HashMap<String,String> eventShortnamesByClassnames =
+ new HashMap<String,String>();
+
+ /** The event names by classnames. */
+ private static HashMap<String,String> eventNamesByClassnames =
+ new HashMap<String,String>();
+
+ /** The event classnames by shortnames. */
+ private static HashMap<String,String> eventClassnamesByShortnames =
+ new HashMap<String,String>();
+
+ /** The editable protocols classnames. */
+ private static ArrayList<String> editableProtocolsClassnames =
+ new ArrayList<String>();
+
+ private static HashMap<String,ArrayList<String>> clientVariables =
+ new HashMap<String,ArrayList<String>>();
+
+ private static HashMap<String,ArrayList<String>> serverVariables =
+ new HashMap<String,ArrayList<String>>();
+
+ private static HashMap<String,Boolean> isOnServerStartProtocol =
+ new HashMap<String,Boolean>();
+
+ /** The prefs. */
+ private static VSPrefs prefs;
+
+ /**
+ * Registers available events.
+ *
+ * @param prefs_ the prefs_
+ */
+ public static void init(VSPrefs prefs_) {
+ prefs = prefs_;
+ registerEvent("events.implementations.VSProcessCrashEvent");
+ registerEvent("events.implementations.VSProcessRecoverEvent");
+ registerEvent("protocols.implementations.VSBasicMulticastProtocol");
+ registerEvent("protocols.implementations.VSBerkelyTimeProtocol");
+ registerEvent("protocols.implementations.VSBroadcastProtocol");
+ registerEvent("protocols.implementations.VSDummyProtocol");
+ registerEvent("protocols.implementations.VSExternalTimeSyncProtocol");
+ registerEvent("protocols.implementations.VSInternalTimeSyncProtocol");
+ registerEvent("protocols.implementations.VSOnePhaseCommitProtocol");
+ registerEvent("protocols.implementations.VSPingPongProtocol");
+ registerEvent("protocols.implementations.VSReliableMulticastProtocol");
+ registerEvent("protocols.implementations.VSTwoPhaseCommitProtocol");
+
+ /* Make dummy objects of each protocol, to see if they contain VSPrefs
+ values to edit */
+ Vector<String> protocolClassnames = getProtocolClassnames();
+ VSClassLoader classLoader = new VSClassLoader();
+
+ for (String protocolClassname : protocolClassnames) {
+ Object serverObject = classLoader.newInstance(protocolClassname);
+ Object clientObject = classLoader.newInstance(protocolClassname);
+
+ if (clientObject instanceof protocols.VSAbstractProtocol &&
+ serverObject instanceof protocols.VSAbstractProtocol) {
+
+ protocols.VSAbstractProtocol serverProtocol =
+ (protocols.VSAbstractProtocol) serverObject;
+ protocols.VSAbstractProtocol clientProtocol =
+ (protocols.VSAbstractProtocol) clientObject;
+
+ serverProtocol.onServerInit();
+ clientProtocol.onClientInit();
+
+ if (!serverProtocol.isEmpty() || !clientProtocol.isEmpty())
+ editableProtocolsClassnames.add(protocolClassname);
+
+ if (!serverProtocol.isEmpty()) {
+ ArrayList<String> variables = new ArrayList<String>();
+ variables.addAll(serverProtocol.getAllFullKeys());
+ serverVariables.put(protocolClassname, variables);
+ }
+
+ if (!clientProtocol.isEmpty()) {
+ ArrayList<String> variables = new ArrayList<String>();
+ variables.addAll(clientProtocol.getAllFullKeys());
+ clientVariables.put(protocolClassname, variables);
+ }
+
+ if (serverProtocol.hasOnServerStart())
+ isOnServerStartProtocol.put(protocolClassname,
+ Boolean.valueOf(true));
+ }
+ }
+ }
+
+ /**
+ * Gets the editable protocols classnames.
+ *
+ * @return the editable protocols classnames
+ */
+ public static ArrayList<String> getEditableProtocolsClassnames() {
+ return editableProtocolsClassnames;
+ }
+
+ /**
+ * Gets the protocols server variable names.
+ *
+ * @return The variable names
+ */
+ public static ArrayList<String> getProtocolServerVariables(
+ String protocolClassname) {
+ return serverVariables.get(protocolClassname);
+ }
+
+ /**
+ * Gets the protocols server variable names.
+ *
+ * @return The variable names
+ */
+ public static ArrayList<String> getProtocolClientVariables(
+ String protocolClassname) {
+ return clientVariables.get(protocolClassname);
+ }
+
+ /**
+ * Gets the protocol names.
+ *
+ * @return the protocol names
+ */
+ public static Vector<String> getProtocolNames() {
+ Set<String> set = eventClassnamesByNames.keySet();
+ Vector<String> vector = new Vector<String>();
+
+ for (String eventName : set)
+ if (getClassnameByEventname(eventName).startsWith(
+ "protocols.implementations"))
+ vector.add(eventName);
+
+ Collections.sort(vector);
+
+ return vector;
+ }
+
+ /**
+ * Gets the protocol classnames.
+ *
+ * @return the protocol classnames
+ */
+ public static Vector<String> getProtocolClassnames() {
+ ArrayList<String> shortnames = new ArrayList<String>();
+ shortnames.addAll(eventClassnamesByShortnames.keySet());
+ Collections.sort(shortnames);
+ Vector<String> vector = new Vector<String>();
+
+ for (String eventShortname : shortnames) {
+ String eventClassname = getClassnameByShortname(eventShortname);
+ if (eventClassname.startsWith("protocols.implementations"))
+ vector.add(eventClassname);
+ }
+
+ return vector;
+ }
+
+ /**
+ * Gets the non protocol names.
+ *
+ * @return the non protocol names
+ */
+ public static Vector<String> getNonProtocolNames() {
+ Set<String> set = eventClassnamesByNames.keySet();
+ Vector<String> vector = new Vector<String>();
+
+ for (String eventName : set)
+ if (getClassnameByEventname(eventName).startsWith(
+ "events.implementations"))
+ vector.add(eventName);
+
+ Collections.sort(vector);
+
+ return vector;
+ }
+
+ /**
+ * Gets the non protocol classnames.
+ *
+ * @return the non protocol classnames
+ */
+ public static Vector<String> getNonProtocolClassnames() {
+ Set<String> set = eventNamesByClassnames.keySet();
+ Vector<String> vector = new Vector<String>();
+
+ for (String eventClassname : set)
+ if (eventClassname.startsWith("events.implementations"))
+ vector.add(eventClassname);
+
+ Collections.sort(vector);
+
+ return vector;
+ }
+
+ /**
+ * Gets the classname.
+ *
+ * @param eventName the event name
+ *
+ * @return the classname
+ */
+ public static String getClassnameByEventname(String eventName) {
+ return eventClassnamesByNames.get(eventName);
+ }
+
+ /**
+ * Gets the name.
+ *
+ * @param eventClassname the event classname
+ *
+ * @return the name
+ */
+ public static String getNameByClassname(String eventClassname) {
+ return eventNamesByClassnames.get(eventClassname);
+ }
+
+ /**
+ * Gets the shortname.
+ *
+ * @param eventClassname the event classname
+ *
+ * @return the shortname
+ */
+ public static String getShortnameByClassname(String eventClassname) {
+ return eventShortnamesByClassnames.get(eventClassname);
+ }
+
+ /**
+ * Gets the classname.
+ *
+ * @param eventShortname the event shortname
+ *
+ * @return the shortname
+ */
+ public static String getClassnameByShortname(String eventShortname) {
+ return eventClassnamesByShortnames.get(eventShortname);
+ }
+
+ /**
+ * Checks if the protocol uses onServerStart or onClientStart
+ *
+ * @param protocolClassname the protocol's classname
+ *
+ * @return true if onServerStart, false if onClientStart
+ */
+ public static boolean isOnServerStartProtocol(String protocolClassname) {
+ if (isOnServerStartProtocol.containsKey(protocolClassname)) {
+ Boolean bool = isOnServerStartProtocol.get(protocolClassname);
+ return bool.booleanValue();
+ }
+
+ return false;
+ }
+
+ /**
+ * Creates the event instance by classname.
+ *
+ * @param eventClassname the event classname
+ * @param process the process
+ *
+ * @return An instance of the event classname, if exists. Else null.
+ */
+ public static VSAbstractEvent createEventInstanceByClassname(
+ String eventClassname, VSInternalProcess process) {
+ Object protocolObj = new VSClassLoader().newInstance(eventClassname);
+
+ if (protocolObj instanceof VSAbstractEvent) {
+ VSAbstractEvent event = (VSAbstractEvent) protocolObj;
+ event.init(process);
+ return event;
+ }
+
+ return null;
+ }
+
+ /**
+ * Creates the event instance by name.
+ *
+ * @param eventName the event name
+ * @param process the process
+ *
+ * @return An instance of the event, if exists. Else null.
+ */
+ public static VSAbstractEvent createEventInstanceByName(String eventName,
+ VSInternalProcess process) {
+ return createEventInstanceByClassname(
+ eventClassnamesByNames.get(eventName), process);
+ }
+
+ /**
+ * Registers an event. Use the language settings of VSPrefs.
+ *
+ * @param eventClassname the event classname
+ */
+ private static void registerEvent(String eventClassname) {
+ String eventName =
+ prefs.getString("lang." + eventClassname);
+ String eventShortname =
+ prefs.getString("lang." + eventClassname + ".short");
+ registerEvent(eventClassname, eventName, eventShortname);
+ }
+
+ /**
+ * Registers an event.
+ *
+ * @param eventClassname the event classname
+ * @param eventName the event name
+ * @param eventShortname the event shortname
+ */
+ private static void registerEvent(String eventClassname, String eventName,
+ String eventShortname) {
+ if (eventShortname == null)
+ eventShortname = eventName;
+
+ eventNamesByClassnames.put(eventClassname, eventName);
+ eventShortnamesByClassnames.put(eventClassname, eventShortname);
+ eventClassnamesByNames.put(eventName, eventClassname);
+ eventClassnamesByShortnames.put(eventShortname, eventClassname);
+ }
+}
diff --git a/src/main/java/events/implementations/VSProcessCrashEvent.java b/src/main/java/events/implementations/VSProcessCrashEvent.java
new file mode 100644
index 0000000..a68e8a1
--- /dev/null
+++ b/src/main/java/events/implementations/VSProcessCrashEvent.java
@@ -0,0 +1,43 @@
+package events.implementations;
+
+import events.VSAbstractEvent;
+import events.VSCopyableEvent;
+import simulator.VSMain;
+
+/**
+ * The class VSProcessCrashEvent. This event makes a process to crash.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSProcessCrashEvent extends VSAbstractEvent
+ implements VSCopyableEvent {
+ /* (non-Javadoc)
+ * @see events.VSCopyableEvent#initCopy(events.VSAbstractEvent)
+ */
+ public void initCopy(VSAbstractEvent copy) {
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#onInit()
+ */
+ public void onInit() {
+ setClassname(getClass().toString());
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#createShortname()()
+ */
+ protected String createShortname(String savedShortname) {
+ return VSMain.prefs.getString("lang.process.crash");
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#onStart()
+ */
+ public void onStart() {
+ if (!process.isCrashed()) {
+ process.isCrashed(true);
+ log(prefs.getString("lang.crashed"));
+ }
+ }
+}
diff --git a/src/main/java/events/implementations/VSProcessRecoverEvent.java b/src/main/java/events/implementations/VSProcessRecoverEvent.java
new file mode 100644
index 0000000..2aa5758
--- /dev/null
+++ b/src/main/java/events/implementations/VSProcessRecoverEvent.java
@@ -0,0 +1,44 @@
+package events.implementations;
+
+import events.VSAbstractEvent;
+import events.VSCopyableEvent;
+import simulator.VSMain;
+
+/**
+ * The class VSProcessRecoverEvent. This event makes a process to recover if
+ * it is crashed.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSProcessRecoverEvent extends VSAbstractEvent
+ implements VSCopyableEvent {
+ /* (non-Javadoc)
+ * @see events.VSCopyableEvent#initCopy(events.VSAbstractEvent)
+ */
+ public void initCopy(VSAbstractEvent copy) {
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#onInit()
+ */
+ public void onInit() {
+ setClassname(getClass().toString());
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#createShortname()()
+ */
+ protected String createShortname(String savedShortname) {
+ return VSMain.prefs.getString("lang.process.recover");
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#onStart()
+ */
+ public void onStart() {
+ if (process.isCrashed()) {
+ process.isCrashed(false);
+ log(prefs.getString("lang.recovered"));
+ }
+ }
+}
diff --git a/src/main/java/events/internal/VSAbstractInternalEvent.java b/src/main/java/events/internal/VSAbstractInternalEvent.java
new file mode 100644
index 0000000..33e3763
--- /dev/null
+++ b/src/main/java/events/internal/VSAbstractInternalEvent.java
@@ -0,0 +1,58 @@
+package events.internal;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import events.VSAbstractEvent;
+import serialize.VSSerialize;
+
+/**
+ * The class VSAbstractInternalEvent, this class if for destinguishing between
+ * internal and non-internal events. Internal usage only.
+ *
+ * @author Paul C. Buetow
+ */
+abstract public class VSAbstractInternalEvent extends VSAbstractEvent {
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#createShortname()()
+ */
+ protected String createShortname(String savedShortname) {
+ return savedShortname;
+ }
+
+ /* (non-Javadoc)
+ * @see serialize.VSSerializable#serialize(serialize.VSSerialize,
+ * java.io.ObjectOutputStream)
+ */
+ public synchronized void serialize(VSSerialize serialize,
+ ObjectOutputStream objectOutputStream)
+ throws IOException {
+ super.serialize(serialize, objectOutputStream);
+
+ /** For later backwards compatibility, to add more stuff */
+ objectOutputStream.writeObject(Boolean.valueOf(false));
+
+ /** For later backwards compatibility, to add more stuff */
+ objectOutputStream.writeObject(Boolean.valueOf(false));
+ }
+
+ /* (non-Javadoc)
+ * @see serialize.VSSerializable#deserialize(serialize.VSSerialize,
+ * java.io.ObjectInputStream)
+ */
+ public synchronized void deserialize(VSSerialize serialize,
+ ObjectInputStream objectInputStream)
+ throws IOException, ClassNotFoundException {
+ super.deserialize(serialize, objectInputStream);
+
+ if (VSSerialize.DEBUG)
+ System.out.println("Deserializing: VSAbstractInternalEvent");
+
+ /** For later backwards compatibility, to add more stuff */
+ objectInputStream.readObject();
+
+ /** For later backwards compatibility, to add more stuff */
+ objectInputStream.readObject();
+ }
+}
diff --git a/src/main/java/events/internal/VSMessageReceiveEvent.java b/src/main/java/events/internal/VSMessageReceiveEvent.java
new file mode 100644
index 0000000..51ae926
--- /dev/null
+++ b/src/main/java/events/internal/VSMessageReceiveEvent.java
@@ -0,0 +1,84 @@
+package events.internal;
+
+import core.VSMessage;
+import protocols.VSAbstractProtocol;
+import serialize.VSNotSerializable;
+
+/**
+ * The class VSMessageReceiveEvent, this event is used if a process receives
+ * a message.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSMessageReceiveEvent extends VSAbstractInternalEvent
+ implements VSNotSerializable {
+
+ /** The message. */
+ private VSMessage message;
+
+ /**
+ * Instantiates a new message receive event.
+ *
+ * @param message the message
+ */
+ public VSMessageReceiveEvent(VSMessage message) {
+ this.message = message;
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#onInit()
+ */
+ public void onInit() {
+ setClassname(getClass().toString());
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#onStart()
+ */
+ public void onStart() {
+ boolean onlyRelevantMessages = process.getPrefs().getBoolean("sim.messages.relevant");
+
+ //String eventName = message.getName();
+ String protocolClassname = message.getProtocolClassname();
+
+ if (onlyRelevantMessages && !isRelevantMessage())
+ return;
+
+ Object protocolObj = null;
+
+ if (process.objectExists(protocolClassname))
+ protocolObj = process.getObject(protocolClassname);
+
+ process.updateLamportTime(message.getLamportTime()+1);
+ process.updateVectorTime(message.getVectorTime());
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(prefs.getString("lang.message.recv"));
+ buffer.append("; ");
+ buffer.append(message);;
+ log(buffer.toString());
+
+ if (protocolObj != null)
+ ((VSAbstractProtocol) protocolObj).onMessageRecvStart(message);
+ }
+
+ /**
+ * Checks if the message delivering is relevant.
+ *
+ * @return true, if relevant
+ */
+ public boolean isRelevantMessage() {
+ String protocolClassname = message.getProtocolClassname();
+ Object protocolObj = null;
+
+ if (process.objectExists(protocolClassname))
+ protocolObj = process.getObject(protocolClassname);
+ else
+ return false;
+
+ if (!((VSAbstractProtocol) protocolObj).isRelevantMessage(message))
+ return false;
+
+ return true;
+ }
+}
diff --git a/src/main/java/events/internal/VSProtocolEvent.java b/src/main/java/events/internal/VSProtocolEvent.java
new file mode 100644
index 0000000..de630e3
--- /dev/null
+++ b/src/main/java/events/internal/VSProtocolEvent.java
@@ -0,0 +1,175 @@
+package events.internal;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import core.VSInternalProcess;
+import events.VSAbstractEvent;
+import events.VSCopyableEvent;
+import events.VSRegisteredEvents;
+import protocols.VSAbstractProtocol;
+import serialize.VSSerialize;
+
+/**
+ * The class VSProtocolEvent, this event is used if a protocol (server or
+ * client part) of a process gets enabled or disabled, an object of this class
+ * can be for 4 different purporses! Activation of the client protocol,
+ * deactivation of the client protocol, activation of the server protocol,
+ * deactivation of the server protocol.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSProtocolEvent extends VSAbstractInternalEvent
+ implements VSCopyableEvent {
+ /** The protocol classname. */
+ private String protocolClassname;
+
+ /** The event is a client protocol if true. Else it is a server protocol */
+ private boolean isClientProtocol;
+
+ /** The event is a protocol activation if true. Else it is a deactivation */
+ private boolean isProtocolActivation;
+
+ /* (non-Javadoc)
+ * @see events.VSCopyableEvent#initCopy(events.VSAbstractEvent)
+ */
+ public void initCopy(VSAbstractEvent copy) {
+ VSProtocolEvent protocolEventCopy = (VSProtocolEvent) copy;
+ protocolEventCopy.isClientProtocol(isClientProtocol);
+ protocolEventCopy.isProtocolActivation(isProtocolActivation);
+ protocolEventCopy.setProtocolClassname(protocolClassname);
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#onInit()
+ */
+ public void onInit() {
+ setClassname(getClass().toString());
+ }
+
+ /**
+ * Sets if it is a client protocol activation/deactivation.
+ *
+ * @param isClientProtocol the event is client protocol if true. the event
+ * is a server protocol if false.
+ */
+ public void isClientProtocol(boolean isClientProtocol) {
+ this.isClientProtocol = isClientProtocol;
+ }
+
+ /**
+ * Checks if it is a client protocol activation/deactivation.
+ *
+ * @return the event is client protocol if true. the event
+ * is a server protocol if false.
+ */
+ public boolean isClientProtocol() {
+ return isClientProtocol;
+ }
+
+ /**
+ * Sets if it is protocol activation.
+ *
+ * @param isProtocolActivation true, if it is a protocol activation. false,
+ * if it is a protocol deactivation.
+ */
+ public void isProtocolActivation(boolean isProtocolActivation) {
+ this.isProtocolActivation = isProtocolActivation;
+ }
+
+ /**
+ * Checks if it is protocol activation.
+ *
+ * @return true, if it is a protocol activation. false, if it is a protocol
+ * deactivation.
+ */
+ public boolean isProtocolActivation() {
+ return isProtocolActivation;
+ }
+
+ /**
+ * Sets the protocol classname.
+ *
+ * @param protocolClassname the new protocol classname
+ */
+ public void setProtocolClassname(String protocolClassname) {
+ this.protocolClassname = protocolClassname;
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#onStart()
+ */
+ public void onStart() {
+ VSInternalProcess internalProcess = (VSInternalProcess) process;
+ VSAbstractProtocol protocol =
+ internalProcess.getProtocolObject(protocolClassname);
+
+ if (isClientProtocol)
+ protocol.isClient(isProtocolActivation);
+ else
+ protocol.isServer(isProtocolActivation);
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(VSRegisteredEvents.getShortnameByClassname(
+ protocolClassname));
+
+ buffer.append(" ");
+ buffer.append(isClientProtocol
+ ? prefs.getString("lang.client")
+ : prefs.getString("lang.server"));
+
+ buffer.append(" ");
+ buffer.append(isProtocolActivation
+ ? prefs.getString("lang.activated")
+ : prefs.getString("langactivated"));
+
+ log(buffer.toString());
+ }
+
+ /* (non-Javadoc)
+ * @see serialize.VSSerializable#serialize(serialize.VSSerialize,
+ * java.io.ObjectOutputStream)
+ */
+ public synchronized void serialize(VSSerialize serialize,
+ ObjectOutputStream objectOutputStream)
+ throws IOException {
+ super.serialize(serialize, objectOutputStream);
+
+ /** For later backwards compatibility, to add more stuff */
+ objectOutputStream.writeObject(Boolean.valueOf(false));
+
+ objectOutputStream.writeObject(protocolClassname);
+ objectOutputStream.writeObject(Boolean.valueOf(isClientProtocol));
+ objectOutputStream.writeObject(Boolean.valueOf(isProtocolActivation));
+
+ /** For later backwards compatibility, to add more stuff */
+ objectOutputStream.writeObject(Boolean.valueOf(false));
+ }
+
+ /* (non-Javadoc)
+ * @see serialize.VSSerializable#deserialize(serialize.VSSerialize,
+ * java.io.ObjectInputStream)
+ */
+ public synchronized void deserialize(VSSerialize serialize,
+ ObjectInputStream objectInputStream)
+ throws IOException, ClassNotFoundException {
+ super.deserialize(serialize, objectInputStream);
+
+ if (VSSerialize.DEBUG)
+ System.out.println("Deserializing: VSProtocolEvent");
+
+ /** For later backwards compatibility, to add more stuff */
+ objectInputStream.readObject();
+
+ protocolClassname = (String) objectInputStream.readObject();
+
+ isClientProtocol = ((Boolean)
+ objectInputStream.readObject()).booleanValue();;
+ isProtocolActivation = ((Boolean)
+ objectInputStream.readObject()).booleanValue();;
+
+ /** For later backwards compatibility, to add more stuff */
+ objectInputStream.readObject();
+ }
+}
diff --git a/src/main/java/events/internal/VSProtocolScheduleEvent.java b/src/main/java/events/internal/VSProtocolScheduleEvent.java
new file mode 100644
index 0000000..c940212
--- /dev/null
+++ b/src/main/java/events/internal/VSProtocolScheduleEvent.java
@@ -0,0 +1,126 @@
+package events.internal;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import protocols.VSAbstractProtocol;
+import serialize.VSNotSerializable;
+import serialize.VSSerialize;
+
+/**
+ * The class VSProtocolScheduleEvent, this event is used if a protocol (which
+ * is a subclass of VSAbstractProtocol) reschedules itself to run again on a
+ * specific time.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSProtocolScheduleEvent extends VSAbstractInternalEvent
+ implements VSNotSerializable {
+ /** The event is a server protocol schedule. */
+ private boolean isServerSchedule; /* true = server, false = client */
+
+ /** The reference to the protocol object to schedule. */
+ private VSAbstractProtocol protocol;
+
+ /**
+ * Create a VSProtocolScheduleEvent object
+ *
+ * @param protocol the protocol
+ * @param isServerSchedule the event is a client protocol schedule if
+ * false, else server schedule
+ */
+ public VSProtocolScheduleEvent(VSAbstractProtocol protocol,
+ boolean isServerSchedule) {
+ this.protocol = protocol;
+ this.isServerSchedule = isServerSchedule;
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#onInit()
+ */
+ public void onInit() {
+ setClassname(getClass().toString());
+ }
+
+ /**
+ * Sets if it is client protocol schedule.
+ *
+ * @param isServerSchedule false, if the event is a client protocol
+ * schedule. true, if server.
+ */
+ public void isServerSchedule(boolean isServerSchedule) {
+ this.isServerSchedule = isServerSchedule;
+ }
+
+ /**
+ * Sets if it is client protocol schedule.
+ *
+ * @return false, if the event is a client protocol schedule. true, if
+ * server.
+ */
+ public boolean isServerSchedule() {
+ return isServerSchedule;
+ }
+
+ /**
+ * Sets the protocol.
+ *
+ * @param protocol the protocol
+ */
+ public void setProtocol(VSAbstractProtocol protocol) {
+ this.protocol = protocol;
+ }
+
+ /**
+ * Gets the protocol.
+ *
+ * @return the protocol
+ */
+ public VSAbstractProtocol getProtocol() {
+ return protocol;
+ }
+
+ /* (non-Javadoc)
+ * @see events.VSAbstractEvent#onStart()
+ */
+ public void onStart() {
+ if (isServerSchedule)
+ protocol.onServerScheduleStart();
+ else
+ protocol.onClientScheduleStart();
+ }
+
+ /* (non-Javadoc)
+ * @see serialize.VSSerializable#serialize(serialize.VSSerialize,
+ * java.io.ObjectOutputStream)
+ */
+ public synchronized void serialize(VSSerialize serialize,
+ ObjectOutputStream objectOutputStream)
+ throws IOException {
+ super.serialize(serialize, objectOutputStream);
+
+ /** For later backwards compatibility, to add more stuff */
+ objectOutputStream.writeObject(Boolean.valueOf(false));
+
+ /** For later backwards compatibility, to add more stuff */
+ objectOutputStream.writeObject(Boolean.valueOf(false));
+ }
+
+ /* (non-Javadoc)
+ * @see serialize.VSSerializable#deserialize(serialize.VSSerialize,
+ * java.io.ObjectInputStream)
+ */
+ public synchronized void deserialize(VSSerialize serialize,
+ ObjectInputStream objectInputStream)
+ throws IOException, ClassNotFoundException {
+ super.deserialize(serialize, objectInputStream);
+
+ if (VSSerialize.DEBUG)
+ System.out.println("Deserializing: VSProtocolEvent");
+
+ /** For later backwards compatibility, to add more stuff */
+ objectInputStream.readObject();
+
+ }
+}