summaryrefslogtreecommitdiff
path: root/sources/protocols/VSProtocol.java
diff options
context:
space:
mode:
Diffstat (limited to 'sources/protocols/VSProtocol.java')
-rw-r--r--sources/protocols/VSProtocol.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/sources/protocols/VSProtocol.java b/sources/protocols/VSProtocol.java
index 3b25d04..b3ebfe6 100644
--- a/sources/protocols/VSProtocol.java
+++ b/sources/protocols/VSProtocol.java
@@ -1,13 +1,32 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package protocols;
import events.*;
import core.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSProtocol.
+ */
abstract public class VSProtocol extends VSEvent {
+
+ /** The is server. */
private boolean isServer;
+
+ /** The is client. */
private boolean isClient;
+
+ /** The current context is server. */
private boolean currentContextIsServer;
+ /**
+ * Send message.
+ *
+ * @param message the message
+ */
protected void sendMessage(VSMessage message) {
if (process == null)
return;
@@ -18,10 +37,20 @@ abstract public class VSProtocol extends VSEvent {
process.sendMessage(message);
}
+ /**
+ * Checks if is incorrect protocol.
+ *
+ * @param message the message
+ *
+ * @return true, if is incorrect protocol
+ */
private final boolean isIncorrectProtocol(VSMessage message) {
return !message.getProtocolClassname().equals(getClassname());
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onStart()
+ */
public final void onStart() {
if (isClient) {
onClientStart();
@@ -29,6 +58,11 @@ abstract public class VSProtocol extends VSEvent {
}
}
+ /**
+ * On message recv.
+ *
+ * @param message the message
+ */
public final void onMessageRecv(VSMessage message) {
if (isIncorrectProtocol(message))
return;
@@ -44,14 +78,27 @@ abstract public class VSProtocol extends VSEvent {
}
}
+ /**
+ * Checks if is server.
+ *
+ * @param isServer the is server
+ */
public final void isServer(boolean isServer) {
this.isServer = isServer;
}
+ /**
+ * Checks if is client.
+ *
+ * @param isClient the is client
+ */
public final void isClient(boolean isClient) {
this.isClient = isClient;
}
+ /**
+ * Reset.
+ */
public void reset() {
if (isServer) {
currentContextIsServer = true;
@@ -66,12 +113,40 @@ abstract public class VSProtocol extends VSEvent {
}
}
+ /**
+ * On client start.
+ */
abstract protected void onClientStart();
+
+ /**
+ * On client reset.
+ */
abstract protected void onClientReset();
+
+ /**
+ * On client recv.
+ *
+ * @param message the message
+ */
abstract protected void onClientRecv(VSMessage message);
+
+ /**
+ * On server reset.
+ */
abstract protected void onServerReset();
+
+ /**
+ * On server recv.
+ *
+ * @param message the message
+ */
abstract protected void onServerRecv(VSMessage message);
+ /**
+ * Gets the num processes.
+ *
+ * @return the num processes
+ */
protected int getNumProcesses() {
if (process == null)
return 0;
@@ -79,6 +154,9 @@ abstract public class VSProtocol extends VSEvent {
return process.getSimulationCanvas().getNumProcesses();
}
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#toString()
+ */
public String toString() {
if (process == null)
return "";