summaryrefslogtreecommitdiff
path: root/sources/core/VSTaskManager.java
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-06-01 22:45:59 +0000
committerPaul Buetow <paul@buetow.org>2008-06-01 22:45:59 +0000
commit293c73f50f87b3d73d3947a9f79430b23ec4ddba (patch)
tree129ece28dcda9d17bb6e0fc417d8b25bb82dac4c /sources/core/VSTaskManager.java
parent8086082daaed71ee9105c156e3a1e8e63caf1990 (diff)
better serialization
Diffstat (limited to 'sources/core/VSTaskManager.java')
-rw-r--r--sources/core/VSTaskManager.java88
1 files changed, 34 insertions, 54 deletions
diff --git a/sources/core/VSTaskManager.java b/sources/core/VSTaskManager.java
index a63db51..cbbde56 100644
--- a/sources/core/VSTaskManager.java
+++ b/sources/core/VSTaskManager.java
@@ -27,6 +27,7 @@ import java.io.*;
import java.util.*;
import prefs.*;
+import serialize.*;
import simulator.*;
import utils.*;
@@ -38,7 +39,7 @@ import utils.*;
*
* @author Paul C. Buetow
*/
-public class VSTaskManager implements Serializable {
+public class VSTaskManager implements VSSerializable {
/** The seriao version uid */
private static final long serialVersionUID = 1L;
@@ -493,80 +494,59 @@ public class VSTaskManager implements Serializable {
return descr + ")";
}
- /**
- * Write object.
- *
- * @param objectOutputStream the object output stream
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ /* (non-Javadoc)
+ * @see serialize.VSSerializable#serialize(serialize.VSSerialize,
+ * java.io.ObjectOutputStream)
*/
- public synchronized void writeObject(ObjectOutputStream objectOutputStream)
+ public synchronized void serialize(VSSerialize serialize,
+ ObjectOutputStream objectOutputStream)
throws IOException {
- VSPriorityQueue<VSTask> temp = new VSPriorityQueue<VSTask>();
+
+ ArrayList<VSTask> tasks = new ArrayList<VSTask>();
for (VSTask task : fullfilledProgrammedTasks)
- if (task.isGlobalTimed())
- temp.add(task);
+ tasks.add(task);
- for (VSTask task : globalTasks)
- temp.add(task);
+ for (VSTask task : this.globalTasks)
+ tasks.add(task);
ArrayList<VSProcess> processes = simulatorCanvas.getProcesses();
- HashMap<Integer, ArrayList<VSTask>> map =
- new HashMap<Integer, ArrayList<VSTask>>();
synchronized (processes) {
for (VSProcess process : processes) {
- VSPriorityQueue<VSTask> tasks = process.getTasks();
- ArrayList<VSTask> tasks_ = new ArrayList<VSTask>();
- for (VSTask task : tasks)
- tasks_.add(task);
- map.put(new Integer(process.getProcessNum()), tasks_);
+ VSPriorityQueue<VSTask> localTasks = process.getTasks();
+ ArrayList<VSTask> tasks_ = new ArrayList<VSTask>();
+ for (VSTask task : localTasks)
+ tasks.add(task);
}
}
- objectOutputStream.writeObject(temp);
- objectOutputStream.writeObject(map);
+ objectOutputStream.writeObject(new Integer(tasks.size()));
+ for (VSTask task : tasks)
+ task.serialize(serialize, objectOutputStream);
}
- /**
- * Read object.
- *
- * @param objectInputStream the object input stream
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws ClassNotFoundException the class not found exception
+ /* (non-Javadoc)
+ * @see serialize.VSSerializable#deserialize(serialize.VSSerialize,
+ * java.io.ObjectInputStream)
*/
@SuppressWarnings("unchecked")
- public synchronized void readObject(ObjectInputStream objectInputStream)
+ public synchronized void deserialize(VSSerialize serialize,
+ ObjectInputStream objectInputStream)
throws IOException, ClassNotFoundException {
- if (VSDeserializationHelper.DEBUG)
+ if (VSSerialize.DEBUG)
System.out.println("Deserializing: VSTaskManager");
- VSPrefs prefs = (VSPrefs) VSDeserializationHelper.getObject("prefs");
- VSSimulatorCanvas simulatorCanvas = (VSSimulatorCanvas)
- VSDeserializationHelper.getObject(
- "prefs");
- this.globalTasks = (PriorityQueue<VSTask>)
- objectInputStream.readObject();
-
- HashMap<Integer, ArrayList<VSTask>> map =
- (HashMap<Integer, ArrayList<VSTask>>)
- objectInputStream.readObject();
-
- Set<Integer> set = map.keySet();
- for (Integer processNum : set) {
- VSProcess process = (VSProcess) VSDeserializationHelper.getObject(
- processNum.intValue(),
- "process");
+ int numTasks = ((Integer) objectInputStream.readObject()).intValue();
+ globalTasks.clear();
- ArrayList<VSTask> tasks = (ArrayList<VSTask>) map.get(processNum);
- VSPriorityQueue<VSTask> tasks_ = process.getTasks();
-
- for (VSTask task: tasks)
- tasks_.add(task);
- }
+ ArrayList<VSProcess> processes = simulatorCanvas.getProcesses();
+ synchronized (processes) {
+ for (VSProcess process : processes)
+ process.getTasks().clear();
+ }
- init(prefs, simulatorCanvas);
+ for (int i = 0; i < numTasks; ++i)
+ addTask(new VSTask(serialize, objectInputStream));
}
}