From 97a3a4f07cdc8437f73f4270b237e85c7739a6be Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 27 May 2008 17:23:45 +0000 Subject: client and server variables are now separate in the editor. --- sources/core/VSProcess.java | 4 +- sources/events/VSAbstractEvent.java | 18 ++++-- sources/events/VSRegisteredEvents.java | 72 +++++++++++++++++---- .../events/implementations/ProcessCrashEvent.java | 2 +- .../implementations/ProcessRecoverEvent.java | 2 +- sources/events/internal/MessageReceiveEvent.java | 2 +- sources/events/internal/ProtocolEvent.java | 2 +- sources/events/internal/ProtocolScheduleEvent.java | 2 +- sources/prefs/VSPrefs.java | 40 +++++++++++- sources/prefs/editors/VSAbstractEditor.java | 44 ++++++++----- sources/prefs/editors/VSProcessEditor.java | 17 ++++- sources/protocols/VSAbstractProtocol.java | 74 ++++++++++++++++------ .../implementations/BerkelyTimeProtocol.java | 42 ++++++------ .../implementations/BroadcastSturmProtocol.java | 24 ++++--- .../protocols/implementations/DummyProtocol.java | 25 +++++--- .../implementations/ExternalTimeSyncProtocol.java | 24 ++++--- .../implementations/InternalTimeSyncProtocol.java | 30 +++++---- .../implementations/OnePhaseCommitProtocol.java | 31 +++++---- .../implementations/PingPongProtocol.java | 24 ++++--- .../implementations/TwoPhaseCommitProtocol.java | 37 +++++------ sources/simulator/VSSimulatorCanvas.java | 12 ++-- 21 files changed, 360 insertions(+), 168 deletions(-) (limited to 'sources') diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java index 1a7f319..e0dd770 100644 --- a/sources/core/VSProcess.java +++ b/sources/core/VSProcess.java @@ -585,8 +585,8 @@ public class VSProcess extends VSPrefs { * @return the a random message outage time */ public synchronized long getARandomMessageOutageTime(final long durationTime, VSProcess receiverProcess) { - int percentage = (int) ((getInteger("message.prob.outage") + - receiverProcess.getInteger("message.prob.outage")) / 2); + int percentage = (int) ((getInteger("message.prob.outage") + + receiverProcess.getInteger("message.prob.outage")) / 2); /* Check if the message will have an outage or not */ if (getRandomPercentage() <= percentage) { /* Calculate the random outage time! */ diff --git a/sources/events/VSAbstractEvent.java b/sources/events/VSAbstractEvent.java index 9562233..27be457 100644 --- a/sources/events/VSAbstractEvent.java +++ b/sources/events/VSAbstractEvent.java @@ -14,10 +14,10 @@ abstract public class VSAbstractEvent extends VSPrefs { private static final long serialVersionUID = 1L; /** The prefs. */ - protected VSPrefs prefs; + public VSPrefs prefs; /** The process. */ - protected VSProcess process; + public VSProcess process; /** The event shortname. */ private String eventShortname; @@ -26,7 +26,7 @@ abstract public class VSAbstractEvent extends VSPrefs { private String eventClassname; /** - * Inits the. + * Inits the event. * * @param process the process */ @@ -34,6 +34,14 @@ abstract public class VSAbstractEvent extends VSPrefs { this.process = process; this.prefs = process.getPrefs(); + init(); + } + + /** + * Inits the event. + * + */ + public void init() { onInit(); } @@ -42,7 +50,7 @@ abstract public class VSAbstractEvent extends VSPrefs { * * @param eventClassname the new classname */ - protected final void setClassname(String eventClassname) { + public final void setClassname(String eventClassname) { if (eventClassname.startsWith("class ")) eventClassname = eventClassname.substring(6); @@ -120,7 +128,7 @@ abstract public class VSAbstractEvent extends VSPrefs { /** * On init. */ - abstract protected void onInit(); + abstract public void onInit(); /** * On start. diff --git a/sources/events/VSRegisteredEvents.java b/sources/events/VSRegisteredEvents.java index 81b68dc..997cc19 100644 --- a/sources/events/VSRegisteredEvents.java +++ b/sources/events/VSRegisteredEvents.java @@ -17,16 +17,26 @@ public final class VSRegisteredEvents { private static final long serialVersionUID = 1L; /** The event classnames. */ - private static HashMap eventClassnames; + private static HashMap eventClassnames = + new HashMap(); /** The event shortnames. */ - private static HashMap eventShortnames; + private static HashMap eventShortnames = + new HashMap(); /** The event names. */ - private static HashMap eventNames; + private static HashMap eventNames = + new HashMap(); /** The editable protocols classnames. */ - private static ArrayList editableProtocolsClassnames; + private static ArrayList editableProtocolsClassnames = + new ArrayList(); + + private static HashMap> clientVariables = + new HashMap>(); + + private static HashMap> serverVariables = + new HashMap>(); /** The prefs. */ private static VSPrefs prefs; @@ -38,10 +48,6 @@ public final class VSRegisteredEvents { */ public static void init(VSPrefs prefs_) { prefs = prefs_; - eventNames = new HashMap(); - eventShortnames = new HashMap(); - eventClassnames = new HashMap(); - editableProtocolsClassnames = new ArrayList(); registerEvent("events.implementations.ProcessCrashEvent", "Prozessabsturz", null); registerEvent("events.implementations.ProcessRecoverEvent", "Prozesswiederbelebung", null); @@ -57,16 +63,36 @@ public final class VSRegisteredEvents { /* Make dummy objects of each protocol, to see if they contain VSPrefs values to edit */ Vector protocolClassnames = getProtocolClassnames(); VSClassLoader classLoader = new VSClassLoader(); + for (String protocolClassname : protocolClassnames) { - Object object = classLoader.newInstance(protocolClassname); - if (object instanceof protocols.VSAbstractProtocol) { - protocols.VSAbstractProtocol protocol = (protocols.VSAbstractProtocol) object; - if (!protocol.isEmpty()) + 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 variables = new ArrayList(); + variables.addAll(serverProtocol.getAllFullKeys()); + serverVariables.put(protocolClassname, variables); + } + + if (!clientProtocol.isEmpty()) { + ArrayList variables = new ArrayList(); + variables.addAll(clientProtocol.getAllFullKeys()); + clientVariables.put(protocolClassname, variables); + } } } - - //Collections.sort(editableProtocolsClassnames); } /** @@ -78,6 +104,24 @@ public final class VSRegisteredEvents { return editableProtocolsClassnames; } + /** + * Gets the protocols server variable names + * + * @return The variable names + */ + public static ArrayList getProtocolServerVariables(String protocolClassname) { + return serverVariables.get(protocolClassname); + } + + /** + * Gets the protocols server variable names + * + * @return The variable names + */ + public static ArrayList getProtocolClientVariables(String protocolClassname) { + return clientVariables.get(protocolClassname); + } + /** * Gets the protocol names. * diff --git a/sources/events/implementations/ProcessCrashEvent.java b/sources/events/implementations/ProcessCrashEvent.java index 873debc..d0db00e 100644 --- a/sources/events/implementations/ProcessCrashEvent.java +++ b/sources/events/implementations/ProcessCrashEvent.java @@ -14,7 +14,7 @@ public class ProcessCrashEvent extends VSAbstractEvent { /* (non-Javadoc) * @see events.VSAbstractEvent#onInit() */ - protected void onInit() { + public void onInit() { setClassname(getClass().toString()); } diff --git a/sources/events/implementations/ProcessRecoverEvent.java b/sources/events/implementations/ProcessRecoverEvent.java index 9d85f13..6ba4276 100644 --- a/sources/events/implementations/ProcessRecoverEvent.java +++ b/sources/events/implementations/ProcessRecoverEvent.java @@ -15,7 +15,7 @@ public class ProcessRecoverEvent extends VSAbstractEvent { /* (non-Javadoc) * @see events.VSAbstractEvent#onInit() */ - protected void onInit() { + public void onInit() { setClassname(getClass().toString()); } diff --git a/sources/events/internal/MessageReceiveEvent.java b/sources/events/internal/MessageReceiveEvent.java index f86b05f..60538df 100644 --- a/sources/events/internal/MessageReceiveEvent.java +++ b/sources/events/internal/MessageReceiveEvent.java @@ -29,7 +29,7 @@ public class MessageReceiveEvent extends VSAbstractEvent { /* (non-Javadoc) * @see events.VSAbstractEvent#onInit() */ - protected void onInit() { + public void onInit() { setClassname(getClass().toString()); } diff --git a/sources/events/internal/ProtocolEvent.java b/sources/events/internal/ProtocolEvent.java index 7001394..108bfb8 100644 --- a/sources/events/internal/ProtocolEvent.java +++ b/sources/events/internal/ProtocolEvent.java @@ -25,7 +25,7 @@ public class ProtocolEvent extends VSAbstractEvent { /* (non-Javadoc) * @see events.VSAbstractEvent#onInit() */ - protected void onInit() { + public void onInit() { setClassname(getClass().toString()); } diff --git a/sources/events/internal/ProtocolScheduleEvent.java b/sources/events/internal/ProtocolScheduleEvent.java index 12fbd7b..bbb776c 100644 --- a/sources/events/internal/ProtocolScheduleEvent.java +++ b/sources/events/internal/ProtocolScheduleEvent.java @@ -33,7 +33,7 @@ public class ProtocolScheduleEvent extends VSAbstractEvent { /* (non-Javadoc) * @see events.VSAbstractEvent#onInit() */ - protected void onInit() { + public void onInit() { setClassname(getClass().toString()); } diff --git a/sources/prefs/VSPrefs.java b/sources/prefs/VSPrefs.java index f8beb66..cac3b18 100644 --- a/sources/prefs/VSPrefs.java +++ b/sources/prefs/VSPrefs.java @@ -12,7 +12,6 @@ import java.util.*; * The Class VSPrefs. */ public class VSPrefs implements Serializable { - /** The Constant BOOLEAN_PREFIX. */ public static final String BOOLEAN_PREFIX = "Boolean: "; @@ -1235,4 +1234,43 @@ public class VSPrefs implements Serializable { return true; } + + /** + * Return all full keys + * + * @return Allf ull keys + */ + public ArrayList getAllFullKeys() { + ArrayList allKeys = new ArrayList(); + + Set set = null; + + set = getIntegerKeySet(); + for (String key : set) + allKeys.add(INTEGER_PREFIX + key); + + set = getVectorKeySet(); + for (String key : set) + allKeys.add(VECTOR_PREFIX + key); + + set = getLongKeySet(); + for (String key : set) + allKeys.add(LONG_PREFIX + key); + + set = getFloatKeySet(); + for (String key : set) + allKeys.add(FLOAT_PREFIX + key); + + set = getBooleanKeySet(); + for (String key : set) + allKeys.add(BOOLEAN_PREFIX + key); + + set = getStringKeySet(); + for (String key : set) + allKeys.add(STRING_PREFIX + key); + + Collections.sort(allKeys); + + return allKeys; + } } diff --git a/sources/prefs/editors/VSAbstractEditor.java b/sources/prefs/editors/VSAbstractEditor.java index 9ae98be..1b6351c 100644 --- a/sources/prefs/editors/VSAbstractEditor.java +++ b/sources/prefs/editors/VSAbstractEditor.java @@ -634,33 +634,47 @@ public abstract class VSAbstractEditor implements ActionListener { editTable.fireTableDataChanged(); } + private ArrayList filterOut(Set set, ArrayList filter, String prefix) { + ArrayList ret = new ArrayList(); + + for (String key : set) { + String fullKey = prefix + key; + if (filter.contains(fullKey)) + ret.add(fullKey); + } + + return ret; + } + /** * Adds the to editor. * * @param label the label * @param prefsKey the prefs key * @param prefsToAdd the prefs to add + * @param addOnlyThisVariables only add variables which are in this list */ - protected void addToEditor(String label, String prefsKey, VSPrefs prefsToAdd) { + protected void addToEditor(String label, String prefsKey, VSPrefs prefsToAdd, ArrayList addOnlyThisVariables) { addSeparator(label); prefsKey = "(" + prefsKey + ")"; ArrayList fullKeys = new ArrayList(); - Set integerKeys = prefsToAdd.getIntegerKeySet(); - Set vectorKeys = prefsToAdd.getVectorKeySet(); - Set floatKeys = prefsToAdd.getFloatKeySet(); - Set longKeys = prefsToAdd.getLongKeySet(); - Set booleanKeys = prefsToAdd.getBooleanKeySet(); - Set stringKeys = prefsToAdd.getStringKeySet(); - - for (String key : integerKeys) fullKeys.add(VSPrefs.INTEGER_PREFIX + key); - for (String key : vectorKeys) fullKeys.add(VSPrefs.VECTOR_PREFIX + key); - for (String key : floatKeys) fullKeys.add(VSPrefs.FLOAT_PREFIX + key); - for (String key : longKeys) fullKeys.add(VSPrefs.LONG_PREFIX + key); - for (String key : booleanKeys) fullKeys.add(VSPrefs.BOOLEAN_PREFIX + key); - for (String key : stringKeys) fullKeys.add(VSPrefs.STRING_PREFIX + key); - + fullKeys.addAll(filterOut(prefsToAdd.getIntegerKeySet(), addOnlyThisVariables, VSPrefs.INTEGER_PREFIX)); + fullKeys.addAll(filterOut(prefsToAdd.getVectorKeySet(), addOnlyThisVariables, VSPrefs.VECTOR_PREFIX)); + fullKeys.addAll(filterOut(prefsToAdd.getFloatKeySet(), addOnlyThisVariables, VSPrefs.FLOAT_PREFIX)); + fullKeys.addAll(filterOut(prefsToAdd.getLongKeySet(), addOnlyThisVariables, VSPrefs.LONG_PREFIX)); + fullKeys.addAll(filterOut(prefsToAdd.getBooleanKeySet(), addOnlyThisVariables, VSPrefs.BOOLEAN_PREFIX)); + fullKeys.addAll(filterOut(prefsToAdd.getStringKeySet(), addOnlyThisVariables, VSPrefs.STRING_PREFIX)); + + /* + for (String key : integerKeys) fullKeys.add(VSPrefs.INTEGER_PREFIX + key); + for (String key : vectorKeys) fullKeys.add(VSPrefs.VECTOR_PREFIX + key); + for (String key : floatKeys) fullKeys.add(VSPrefs.FLOAT_PREFIX + key); + for (String key : longKeys) fullKeys.add(VSPrefs.LONG_PREFIX + key); + for (String key : booleanKeys) fullKeys.add(VSPrefs.BOOLEAN_PREFIX + key); + for (String key : stringKeys) fullKeys.add(VSPrefs.STRING_PREFIX + key); + */ Collections.sort(fullKeys); for (String fullKey : fullKeys) { diff --git a/sources/prefs/editors/VSProcessEditor.java b/sources/prefs/editors/VSProcessEditor.java index 8666fbe..1992d6c 100644 --- a/sources/prefs/editors/VSProcessEditor.java +++ b/sources/prefs/editors/VSProcessEditor.java @@ -13,7 +13,6 @@ import protocols.*; import events.*; import prefs.VSPrefs; -// TODO: Auto-generated Javadoc /** * The Class VSProcessEditor. */ @@ -57,11 +56,23 @@ public class VSProcessEditor extends VSAbstractBetterEditor { ArrayList editableProtocolsClassnames = VSRegisteredEvents.getEditableProtocolsClassnames(); - String protocolString = " " + prefs.getString("lang.protocol"); + //String protocolString = " " + prefs.getString("lang.protocol"); + String clientString = " " + prefs.getString("lang.client"); + String serverString = " " + prefs.getString("lang.server"); + for (String protocolClassname : editableProtocolsClassnames) { String protocolShortname = VSRegisteredEvents.getShortname(protocolClassname); VSAbstractProtocol protocol = process.getProtocolObject(protocolClassname); - addToEditor(protocolShortname + protocolString, protocolShortname, protocol); + protocol.onClientInit(); + protocol.onServerInit(); + + ArrayList clientVariables = VSRegisteredEvents.getProtocolClientVariables(protocolClassname); + if (clientVariables != null) + addToEditor(protocolShortname + clientString, protocolShortname, protocol, clientVariables); + + ArrayList serverVariables = VSRegisteredEvents.getProtocolServerVariables(protocolClassname); + if (serverVariables != null) + addToEditor(protocolShortname + serverString, protocolShortname, protocol, serverVariables); } } diff --git a/sources/protocols/VSAbstractProtocol.java b/sources/protocols/VSAbstractProtocol.java index 7f459c5..299d23d 100644 --- a/sources/protocols/VSAbstractProtocol.java +++ b/sources/protocols/VSAbstractProtocol.java @@ -31,12 +31,15 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { /** The protocol's client schedules */ private ArrayList clientSchedules = new ArrayList(); + public VSAbstractProtocol() { + } + /** * Send a message. * * @param message the message to send */ - protected void sendMessage(VSMessage message) { + public void sendMessage(VSMessage message) { if (process == null) return; @@ -62,27 +65,43 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { */ public final void onStart() { if (isClient) { - currentContextIsServer = false; + currentContextIsServer(false); onClientStart(); } } + /* (non-Javadoc) + * @see events.VSAbstractEvent#onInit() + */ + public final void onInit() { + if (isClient) { + currentContextIsServer(false); + onClientInit(); + } + + if (isServer) { + currentContextIsServer(true); + onServerInit(); + } + } + /** * Runs a client schedule */ public final void onClientScheduleStart() { if (isClient) { - currentContextIsServer = false; + currentContextIsServer(false); onClientSchedule(); } } + /** * Runs a server schedule */ public final void onServerScheduleStart() { if (isServer) { - currentContextIsServer = true; + currentContextIsServer(true); onServerSchedule(); } } @@ -97,16 +116,25 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { return; if (isServer) { - currentContextIsServer = true; + currentContextIsServer(true); onServerRecv(message); } if (isClient) { - currentContextIsServer = false; + currentContextIsServer(false); onClientRecv(message); } } + /** + * Sets if the current context is server. + * + * @param currentContextIsServer the context. + */ + public final void currentContextIsServer(boolean currentContextIsServer) { + this.currentContextIsServer = currentContextIsServer; + } + /** * Sets if is server. * @@ -148,14 +176,14 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { */ public void reset() { //if (isServer) { - currentContextIsServer = true; + currentContextIsServer(true); isServer = false; onServerReset(); serverSchedules.clear(); //} //if (isClient) { - currentContextIsServer = false; + currentContextIsServer(false); isClient = false; onClientReset(); clientSchedules.clear(); @@ -167,7 +195,7 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { * * @param time The process' local time to run the schedule at. */ - protected final void scheduleAt(long time) { + public final void scheduleAt(long time) { VSAbstractEvent scheduleEvent = new ProtocolScheduleEvent(this, currentContextIsServer); VSTask scheduleTask = new VSTask(time, process, scheduleEvent, VSTask.LOCAL); if (currentContextIsServer) @@ -180,7 +208,7 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { /** * Removes all schedules of the protocol (server or client) */ - protected final void removeSchedules() { + public final void removeSchedules() { if (currentContextIsServer) { process.getSimulationCanvas().getTaskManager().removeAllTasks(serverSchedules); serverSchedules.clear(); @@ -190,51 +218,61 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { } } + /** + * On client init. + */ + abstract public void onClientInit(); + /** * On client start. */ - abstract protected void onClientStart(); + abstract public void onClientStart(); /** * On client reset. */ - abstract protected void onClientReset(); + abstract public void onClientReset(); /** * On client schedule. */ - abstract protected void onClientSchedule(); + abstract public void onClientSchedule(); /** * On client recv. * * @param message the message */ - abstract protected void onClientRecv(VSMessage message); + abstract public void onClientRecv(VSMessage message); + + /** + * On server init. + */ + abstract public void onServerInit(); /** * On server reset. */ - abstract protected void onServerReset(); + abstract public void onServerReset(); /** * On server recv. * * @param message the message */ - abstract protected void onServerRecv(VSMessage message); + abstract public void onServerRecv(VSMessage message); /** * On server schedule. */ - abstract protected void onServerSchedule(); + abstract public void onServerSchedule(); /** * Gets the num processes. * * @return the num processes */ - protected int getNumProcesses() { + public int getNumProcesses() { if (process == null) return 0; diff --git a/sources/protocols/implementations/BerkelyTimeProtocol.java b/sources/protocols/implementations/BerkelyTimeProtocol.java index 890221a..d680f41 100644 --- a/sources/protocols/implementations/BerkelyTimeProtocol.java +++ b/sources/protocols/implementations/BerkelyTimeProtocol.java @@ -17,7 +17,12 @@ import java.util.Vector; public class BerkelyTimeProtocol extends VSAbstractProtocol { private static final long serialVersionUID = 1L; - /* Berkely Server variables */ + /** + * Instantiates a new berkely time protocol. + */ + public BerkelyTimeProtocol() { + setClassname(getClass().toString()); + } /** Integer: Process ID, Long: Local time of the process */ private HashMap processTimes = new HashMap(); @@ -34,12 +39,11 @@ public class BerkelyTimeProtocol extends VSAbstractProtocol { /** Time the request/response has started */ private long requestTime; - /** - * Instantiates a new berkely time protocol. - */ - public BerkelyTimeProtocol() { - setClassname(getClass().toString()); + /* (non-Javadoc) + * @see events.VSAbstractProtocol#onClientInit() + */ + public void onClientInit() { /* Those prefs are editable through the VSAbstractProtocol VSAbstractEditor GUI. */ Vector vec = new Vector(); vec.add(2); @@ -47,16 +51,10 @@ public class BerkelyTimeProtocol extends VSAbstractProtocol { initVector("pids", vec, "PIDs beteiliger Prozesse"); } - /* (non-Javadoc) - * @see events.VSAbstractEvent#onInit() - */ - protected void onInit() { - } - /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientReset() */ - protected void onClientReset() { + public void onClientReset() { processTimes.clear(); recvTimes.clear(); realTimesRTT.clear(); @@ -67,7 +65,7 @@ public class BerkelyTimeProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientStart() */ - protected void onClientStart() { + public void onClientStart() { peers.addAll(getVector("pids")); requestTime = process.getTime(); VSMessage message = new VSMessage(); @@ -78,7 +76,7 @@ public class BerkelyTimeProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ - protected void onClientRecv(VSMessage recvMessage) { + public void onClientRecv(VSMessage recvMessage) { /* Ignore all protocol messages which are not a response message, e.g. itself */ if (!recvMessage.getBoolean("isResponse")) return; @@ -110,7 +108,7 @@ public class BerkelyTimeProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientSchedule() */ - protected void onClientSchedule() { + public void onClientSchedule() { } /** @@ -150,16 +148,22 @@ public class BerkelyTimeProtocol extends VSAbstractProtocol { } } + /* (non-Javadoc) + * @see events.VSAbstractProtocol#onServerInit() + */ + public void onServerInit() { + } + /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerReset() */ - protected void onServerReset() { + public void onServerReset() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ - protected void onServerRecv(VSMessage recvMessage) { + public void onServerRecv(VSMessage recvMessage) { if (recvMessage.getBoolean("isRequest")) { VSMessage message = new VSMessage(); message.setInteger("processID", process.getProcessID()); @@ -184,7 +188,7 @@ public class BerkelyTimeProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerSchedule() */ - protected void onServerSchedule() { + public void onServerSchedule() { } /* (non-Javadoc) diff --git a/sources/protocols/implementations/BroadcastSturmProtocol.java b/sources/protocols/implementations/BroadcastSturmProtocol.java index cfd258c..1121e98 100644 --- a/sources/protocols/implementations/BroadcastSturmProtocol.java +++ b/sources/protocols/implementations/BroadcastSturmProtocol.java @@ -31,21 +31,21 @@ public class BroadcastSturmProtocol extends VSAbstractProtocol { } /* (non-Javadoc) - * @see events.VSAbstractEvent#onInit() + * @see events.VSAbstractProtocol#onClientInit() */ - protected void onInit() { + public void onClientInit() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientReset() */ - protected void onClientReset() { + public void onClientReset() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientStart() */ - protected void onClientStart() { + public void onClientStart() { VSMessage message = new VSMessage(); message.setInteger("Broadcast", broadcastCount++); sentMessages.add(message); @@ -55,32 +55,38 @@ public class BroadcastSturmProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ - protected void onClientRecv(VSMessage recvMessage) { + public void onClientRecv(VSMessage recvMessage) { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientSchedule() */ - protected void onClientSchedule() { + public void onClientSchedule() { + } + + /* (non-Javadoc) + * @see events.VSAbstractProtocol#onServerInit() + */ + public void onServerInit() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerReset() */ - protected void onServerReset() { + public void onServerReset() { sentMessages.clear(); } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerSchedule() */ - protected void onServerSchedule() { + public void onServerSchedule() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ - protected void onServerRecv(VSMessage recvMessage) { + public void onServerRecv(VSMessage recvMessage) { if (!sentMessages.contains(recvMessage)) { VSMessage message = new VSMessage(); message.setInteger("Broadcast", recvMessage.getInteger("Broadcast")); diff --git a/sources/protocols/implementations/DummyProtocol.java b/sources/protocols/implementations/DummyProtocol.java index 684de87..91e46c8 100644 --- a/sources/protocols/implementations/DummyProtocol.java +++ b/sources/protocols/implementations/DummyProtocol.java @@ -7,7 +7,6 @@ package protocols.implementations; import protocols.VSAbstractProtocol; import core.VSMessage; -// TODO: Auto-generated Javadoc /** * The Class DummyProtocol. */ @@ -22,22 +21,22 @@ public class DummyProtocol extends VSAbstractProtocol { } /* (non-Javadoc) - * @see events.VSAbstractEvent#onInit() + * @see events.VSAbstractProtocol#onClientInit() */ - protected void onInit() { + public void onClientInit() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientReset() */ - protected void onClientReset() { + public void onClientReset() { logg("onClientReset()"); } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientStart() */ - protected void onClientStart() { + public void onClientStart() { logg("onClientStart()"); VSMessage message = new VSMessage(); @@ -51,7 +50,7 @@ public class DummyProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ - protected void onClientRecv(VSMessage recvMessage) { + public void onClientRecv(VSMessage recvMessage) { logg("onClientRecv("+recvMessage+")"); String s = recvMessage.getString("Greeting"); @@ -63,27 +62,33 @@ public class DummyProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientSchedule() */ - protected void onClientSchedule() { + public void onClientSchedule() { + } + + /* (non-Javadoc) + * @see events.VSAbstractProtocol#onServerInit() + */ + public void onServerInit() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerReset() */ - protected void onServerReset() { + public void onServerReset() { logg("onClientReset()"); } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ - protected void onServerRecv(VSMessage recvMessage) { + public void onServerRecv(VSMessage recvMessage) { logg("onServerRecv("+recvMessage+")"); } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerSchedule() */ - protected void onServerSchedule() { + public void onServerSchedule() { } /* (non-Javadoc) diff --git a/sources/protocols/implementations/ExternalTimeSyncProtocol.java b/sources/protocols/implementations/ExternalTimeSyncProtocol.java index 243418a..97a20ef 100644 --- a/sources/protocols/implementations/ExternalTimeSyncProtocol.java +++ b/sources/protocols/implementations/ExternalTimeSyncProtocol.java @@ -28,21 +28,21 @@ public class ExternalTimeSyncProtocol extends VSAbstractProtocol { } /* (non-Javadoc) - * @see events.VSAbstractEvent#onInit() + * @see events.VSAbstractProtocol#onClientInit() */ - protected void onInit() { + public void onClientInit() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientReset() */ - protected void onClientReset() { + public void onClientReset() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientStart() */ - protected void onClientStart() { + public void onClientStart() { requestTime = process.getTime(); waitingForResponse = true; @@ -55,7 +55,7 @@ public class ExternalTimeSyncProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ - protected void onClientRecv(VSMessage recvMessage) { + public void onClientRecv(VSMessage recvMessage) { if (!recvMessage.getBoolean("isServerResponse")) return; @@ -76,19 +76,25 @@ public class ExternalTimeSyncProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientSchedule() */ - protected void onClientSchedule() { + public void onClientSchedule() { + } + + /* (non-Javadoc) + * @see events.VSAbstractProtocol#onServerInit() + */ + public void onServerInit() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerReset() */ - protected void onServerReset() { + public void onServerReset() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ - protected void onServerRecv(VSMessage recvMessage) { + public void onServerRecv(VSMessage recvMessage) { if (!recvMessage.getBoolean("isClientRequest")) return; @@ -102,7 +108,7 @@ public class ExternalTimeSyncProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerSchedule() */ - protected void onServerSchedule() { + public void onServerSchedule() { } /* (non-Javadoc) diff --git a/sources/protocols/implementations/InternalTimeSyncProtocol.java b/sources/protocols/implementations/InternalTimeSyncProtocol.java index e196cfb..c35e201 100644 --- a/sources/protocols/implementations/InternalTimeSyncProtocol.java +++ b/sources/protocols/implementations/InternalTimeSyncProtocol.java @@ -23,27 +23,27 @@ public class InternalTimeSyncProtocol extends VSAbstractProtocol { public InternalTimeSyncProtocol() { setClassname(getClass().toString()); - /* Those prefs are editable through the VSAbstractProtocol VSAbstractEditor GUI. t_min and t_max in milliseconds */ - initLong("t_min", 2000, "Max. Übetragungszeit", "ms"); - initLong("t_max", 500, "Min. Übertragungszeit", "ms"); } /* (non-Javadoc) - * @see events.VSAbstractEvent#onInit() + * @see events.VSAbstractProtocol#onClientInit() */ - protected void onInit() { + public void onClientInit() { + /* Those prefs are editable through the VSAbstractProtocol VSAbstractEditor GUI. t_min and t_max in milliseconds */ + initLong("t_min", 2000, "Max. Übetragungszeit", "ms"); + initLong("t_max", 500, "Min. Übertragungszeit", "ms"); } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientReset() */ - protected void onClientReset() { + public void onClientReset() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientStart() */ - protected void onClientStart() { + public void onClientStart() { waitingForResponse = true; /* Multicast message to all processes */ @@ -55,7 +55,7 @@ public class InternalTimeSyncProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ - protected void onClientRecv(VSMessage recvMessage) { + public void onClientRecv(VSMessage recvMessage) { /* Ignore all protocol messages which are not a response message, e.g. itself */ if (!recvMessage.getBoolean("isServerResponse")) return; @@ -80,19 +80,25 @@ public class InternalTimeSyncProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientSchedule() */ - protected void onClientSchedule() { + public void onClientSchedule() { + } + + /* (non-Javadoc) + * @see events.VSAbstractProtocol#onServerInit() + */ + public void onServerInit() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerReset() */ - protected void onServerReset() { + public void onServerReset() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ - protected void onServerRecv(VSMessage recvMessage) { + public void onServerRecv(VSMessage recvMessage) { /* Ignore all protocol messages which are not a request message, e.g. itself */ if (!recvMessage.getBoolean("isClientRequest")) return; @@ -107,7 +113,7 @@ public class InternalTimeSyncProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerSchedule() */ - protected void onServerSchedule() { + public void onServerSchedule() { } /* (non-Javadoc) diff --git a/sources/protocols/implementations/OnePhaseCommitProtocol.java b/sources/protocols/implementations/OnePhaseCommitProtocol.java index c22c47d..53c8ce6 100644 --- a/sources/protocols/implementations/OnePhaseCommitProtocol.java +++ b/sources/protocols/implementations/OnePhaseCommitProtocol.java @@ -27,7 +27,12 @@ public class OnePhaseCommitProtocol extends VSAbstractProtocol { */ public OnePhaseCommitProtocol() { setClassname(getClass().toString()); + } + /* (non-Javadoc) + * @see events.VSAbstractProtocol#onClientInit() + */ + public void onClientInit() { /* Can be changed via GUI variables editor of each process */ Vector vec = new Vector(); vec.add(2); @@ -37,16 +42,10 @@ public class OnePhaseCommitProtocol extends VSAbstractProtocol { initLong("timeout", 2500, "Zeit bis erneuerter Anfrage", "ms"); } - /* (non-Javadoc) - * @see events.VSAbstractEvent#onInit() - */ - protected void onInit() { - } - /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientReset() */ - protected void onClientReset() { + public void onClientReset() { if (pids != null) { pids.clear(); pids.addAll(getVector("pids")); @@ -56,7 +55,7 @@ public class OnePhaseCommitProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientStart() */ - protected void onClientStart() { + public void onClientStart() { if (pids == null) { pids = new ArrayList(); pids.addAll(getVector("pids")); @@ -75,7 +74,7 @@ public class OnePhaseCommitProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ - protected void onClientRecv(VSMessage recvMessage) { + public void onClientRecv(VSMessage recvMessage) { if (pids.size() == 0) return; @@ -96,21 +95,27 @@ public class OnePhaseCommitProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientSchedule() */ - protected void onClientSchedule() { + public void onClientSchedule() { onClientStart(); } + /* (non-Javadoc) + * @see events.VSAbstractProtocol#onServerInit() + */ + public void onServerInit() { + } + /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerReset() */ - protected void onServerReset() { + public void onServerReset() { ackSent = false; } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ - protected void onServerRecv(VSMessage recvMessage) { + public void onServerRecv(VSMessage recvMessage) { if (ackSent) return; @@ -125,7 +130,7 @@ public class OnePhaseCommitProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerSchedule() */ - protected void onServerSchedule() { + public void onServerSchedule() { } /* (non-Javadoc) diff --git a/sources/protocols/implementations/PingPongProtocol.java b/sources/protocols/implementations/PingPongProtocol.java index 4082dd3..13a7b32 100644 --- a/sources/protocols/implementations/PingPongProtocol.java +++ b/sources/protocols/implementations/PingPongProtocol.java @@ -28,22 +28,22 @@ public class PingPongProtocol extends VSAbstractProtocol { } /* (non-Javadoc) - * @see events.VSAbstractEvent#onInit() + * @see events.VSAbstractProtocol#onClientInit() */ - protected void onInit() { + public void onClientInit() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientReset() */ - protected void onClientReset() { + public void onClientReset() { clientCounter = 0; } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientStart() */ - protected void onClientStart() { + public void onClientStart() { VSMessage message = new VSMessage(); message.setBoolean("fromClient", true); message.setInteger("counter", ++clientCounter); @@ -53,7 +53,7 @@ public class PingPongProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ - protected void onClientRecv(VSMessage recvMessage) { + public void onClientRecv(VSMessage recvMessage) { if (!recvMessage.getBoolean("fromServer")) return; @@ -68,20 +68,26 @@ public class PingPongProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientSchedule() */ - protected void onClientSchedule() { + public void onClientSchedule() { + } + + /* (non-Javadoc) + * @see events.VSAbstractProtocol#onServerInit() + */ + public void onServerInit() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerReset() */ - protected void onServerReset() { + public void onServerReset() { serverCounter = 0; } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ - protected void onServerRecv(VSMessage recvMessage) { + public void onServerRecv(VSMessage recvMessage) { if (!recvMessage.getBoolean("fromClient")) return; @@ -96,7 +102,7 @@ public class PingPongProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerSchedule() */ - protected void onServerSchedule() { + public void onServerSchedule() { } /* (non-Javadoc) diff --git a/sources/protocols/implementations/TwoPhaseCommitProtocol.java b/sources/protocols/implementations/TwoPhaseCommitProtocol.java index b7c38f8..cd1a5ce 100644 --- a/sources/protocols/implementations/TwoPhaseCommitProtocol.java +++ b/sources/protocols/implementations/TwoPhaseCommitProtocol.java @@ -30,30 +30,24 @@ public class TwoPhaseCommitProtocol extends VSAbstractProtocol { */ public TwoPhaseCommitProtocol() { setClassname(getClass().toString()); + } - /* Can be changed via GUI variables editor of each process */ + /* (non-Javadoc) + * @see events.VSAbstractProtocol#onClientInit() + */ + public void onClientInit() { Vector vec = new Vector(); vec.add(2); vec.add(3); - /* Server */ initVector("pids", vec, "PIDs beteilitger Prozesse"); initLong("timeout", 2500, "Zeit bis erneuerter Anfrage", "ms"); - - /* Client */ - initInteger("ackProb", 50, "Festschreibw'keit", 0, 100, "%"); - } - - /* (non-Javadoc) - * @see events.VSAbstractEvent#onInit() - */ - protected void onInit() { } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientReset() */ - protected void onClientReset() { + public void onClientReset() { if (votePids != null) { voteResult = true; votePids.clear(); @@ -66,7 +60,7 @@ public class TwoPhaseCommitProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientStart() */ - protected void onClientStart() { + public void onClientStart() { if (votePids == null) { voteResult = true; votePids = new ArrayList(); @@ -97,7 +91,7 @@ public class TwoPhaseCommitProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ - protected void onClientRecv(VSMessage recvMessage) { + public void onClientRecv(VSMessage recvMessage) { if (votePids.size() != 0 && recvMessage.getBoolean("isVote")) { Integer pid = recvMessage.getIntegerObj("pid"); if (votePids.contains(pid)) @@ -136,7 +130,7 @@ public class TwoPhaseCommitProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onClientSchedule() */ - protected void onClientSchedule() { + public void onClientSchedule() { onClientStart(); } @@ -144,17 +138,24 @@ public class TwoPhaseCommitProtocol extends VSAbstractProtocol { private boolean voteSent; private boolean myVote; + /* (non-Javadoc) + * @see events.VSAbstractProtocol#onServerInit() + */ + public void onServerInit() { + initInteger("ackProb", 50, "Festschreibw'keit", 0, 100, "%"); + } + /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerReset() */ - protected void onServerReset() { + public void onServerReset() { voteSent = false; } /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ - protected void onServerRecv(VSMessage recvMessage) { + public void onServerRecv(VSMessage recvMessage) { if (recvMessage.getBoolean("wantVote")) { if (!voteSent) { voteSent = true; @@ -183,6 +184,6 @@ public class TwoPhaseCommitProtocol extends VSAbstractProtocol { /* (non-Javadoc) * @see protocols.VSAbstractProtocol#onServerSchedule() */ - protected void onServerSchedule() { + public void onServerSchedule() { } } diff --git a/sources/simulator/VSSimulatorCanvas.java b/sources/simulator/VSSimulatorCanvas.java index 33a5f18..b5eaf00 100644 --- a/sources/simulator/VSSimulatorCanvas.java +++ b/sources/simulator/VSSimulatorCanvas.java @@ -1052,12 +1052,12 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi durationTime = sendingProcess.getDurationTime(); deliverTime = sendingProcess.getGlobalTime() + durationTime; - if (prefs.getBoolean("sim.message.prob.mean")) - outageTime = sendingProcess.getARandomMessageOutageTime( - durationTime, receiverProcess); - else - outageTime = sendingProcess.getARandomMessageOutageTime( - durationTime, null); + if (prefs.getBoolean("sim.message.prob.mean")) + outageTime = sendingProcess.getARandomMessageOutageTime( + durationTime, receiverProcess); + else + outageTime = sendingProcess.getARandomMessageOutageTime( + durationTime, null); /* Only add a 'receiving message' task if the message will not get lost! */ if (outageTime == -1) { -- cgit v1.2.3