diff options
| author | Paul Buetow <paul@buetow.org> | 2008-05-27 17:23:45 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-05-27 17:23:45 +0000 |
| commit | 97a3a4f07cdc8437f73f4270b237e85c7739a6be (patch) | |
| tree | 32154e63775f1fa145d176301840e3150b8eb001 /sources/protocols/VSAbstractProtocol.java | |
| parent | 39e9eb74c011ee5351ac1796e5df529a70aa8945 (diff) | |
client and server variables are now separate in the editor.
Diffstat (limited to 'sources/protocols/VSAbstractProtocol.java')
| -rw-r--r-- | sources/protocols/VSAbstractProtocol.java | 74 |
1 files changed, 56 insertions, 18 deletions
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<VSTask> clientSchedules = new ArrayList<VSTask>(); + 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,17 +116,26 @@ 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. * * @param isServer the 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(); @@ -191,50 +219,60 @@ 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; |
