summaryrefslogtreecommitdiff
path: root/sources/protocols/VSAbstractProtocol.java
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-05-26 22:14:52 +0000
committerPaul Buetow <paul@buetow.org>2008-05-26 22:14:52 +0000
commit923b0503c91aa4a9c0bc94489caddf9ac94c5ad8 (patch)
tree74bf4a51494085c9ecb107d3facc31bb585669b4 /sources/protocols/VSAbstractProtocol.java
parentfaee8241ff7972ceeb622e0793c655f301ef0bd0 (diff)
Two phase commit protocol works.
Diffstat (limited to 'sources/protocols/VSAbstractProtocol.java')
-rw-r--r--sources/protocols/VSAbstractProtocol.java51
1 files changed, 39 insertions, 12 deletions
diff --git a/sources/protocols/VSAbstractProtocol.java b/sources/protocols/VSAbstractProtocol.java
index 05864fb..7f459c5 100644
--- a/sources/protocols/VSAbstractProtocol.java
+++ b/sources/protocols/VSAbstractProtocol.java
@@ -4,6 +4,8 @@
*/
package protocols;
+import java.util.ArrayList;
+
import events.internal.*;
import events.*;
import core.*;
@@ -23,6 +25,12 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent {
/** The current protocol object's context is a server. */
private boolean currentContextIsServer;
+ /** The protocol's server schedules */
+ private ArrayList<VSTask> serverSchedules = new ArrayList<VSTask>();
+
+ /** The protocol's client schedules */
+ private ArrayList<VSTask> clientSchedules = new ArrayList<VSTask>();
+
/**
* Send a message.
*
@@ -139,31 +147,50 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent {
* Reset.
*/
public void reset() {
- if (isServer) {
- currentContextIsServer = true;
- isServer = false;
- onServerReset();
- }
-
- if (isClient) {
- currentContextIsServer = false;
- isClient = false;
- onClientReset();
- }
+ //if (isServer) {
+ currentContextIsServer = true;
+ isServer = false;
+ onServerReset();
+ serverSchedules.clear();
+ //}
+
+ //if (isClient) {
+ currentContextIsServer = false;
+ isClient = false;
+ onClientReset();
+ clientSchedules.clear();
+ //}
}
/**
* Reschedules the protocol for a new time and runs onClientSchedule or onServerSchedule
*
- * @param isClient the is client
+ * @param time The process' local time to run the schedule at.
*/
protected final void scheduleAt(long time) {
VSAbstractEvent scheduleEvent = new ProtocolScheduleEvent(this, currentContextIsServer);
VSTask scheduleTask = new VSTask(time, process, scheduleEvent, VSTask.LOCAL);
+ if (currentContextIsServer)
+ serverSchedules.add(scheduleTask);
+ else
+ clientSchedules.add(scheduleTask);
process.getSimulationCanvas().getTaskManager().addTask(scheduleTask);
}
/**
+ * Removes all schedules of the protocol (server or client)
+ */
+ protected final void removeSchedules() {
+ if (currentContextIsServer) {
+ process.getSimulationCanvas().getTaskManager().removeAllTasks(serverSchedules);
+ serverSchedules.clear();
+ } else {
+ process.getSimulationCanvas().getTaskManager().removeAllTasks(clientSchedules);
+ clientSchedules.clear();
+ }
+ }
+
+ /**
* On client start.
*/
abstract protected void onClientStart();