diff options
| -rw-r--r-- | docs/SERIALIZATION_NOTES.txt | 7 | ||||
| -rw-r--r-- | sources/core/VSProcess.java | 2 | ||||
| -rw-r--r-- | sources/core/VSTask.java | 19 | ||||
| -rw-r--r-- | sources/core/VSTaskManager.java | 8 | ||||
| -rw-r--r-- | sources/events/VSAbstractEvent.java | 11 | ||||
| -rw-r--r-- | sources/events/internal/VSProtocolEvent.java | 36 | ||||
| -rw-r--r-- | sources/serialize/VSSerialize.java | 25 | ||||
| -rw-r--r-- | sources/simulator/VSSimulator.java | 5 | ||||
| -rw-r--r-- | sources/simulator/VSSimulatorCanvas.java | 4 | ||||
| -rw-r--r-- | sources/simulator/VSSimulatorFrame.java | 51 |
10 files changed, 133 insertions, 35 deletions
diff --git a/docs/SERIALIZATION_NOTES.txt b/docs/SERIALIZATION_NOTES.txt index 7130d36..55e13af 100644 --- a/docs/SERIALIZATION_NOTES.txt +++ b/docs/SERIALIZATION_NOTES.txt @@ -33,4 +33,9 @@ VSSerialize writeObject(taskTime) writeObject(isGlobalTimed) writeObject(isProgrammed) - + +VSProtocolEvent.serialize + super(=VSAbstractEvent).serialize + writeObject(protocolClassname) + writeObject(isClientProtocol) + writeObject(isProtocolActivation) diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java index bf4fa98..1b88fc0 100644 --- a/sources/core/VSProcess.java +++ b/sources/core/VSProcess.java @@ -214,7 +214,7 @@ public class VSProcess extends VSPrefs implements VSSerializable { private void init(VSPrefs prefs, int processNum, VSSimulatorCanvas simulatorCanvas, VSLogging logging) { /* May be not null if called from deserialization */ - if (protocolsToReset == null) + if (this.protocolsToReset == null) this.protocolsToReset = new ArrayList<VSAbstractProtocol>(); this.processNum = processNum; this.prefs = prefs; diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java index a903868..1b8f744 100644 --- a/sources/core/VSTask.java +++ b/sources/core/VSTask.java @@ -119,7 +119,7 @@ public class VSTask implements Comparable, VSSerializable { this.process = process; this.taskTime = taskTime > 0 ? taskTime : 0; /* May be not null if called from deserialization */ - if (event == null) + if (this.event == null) this.event = event; this.prefs = process.getPrefs(); this.isGlobalTimed = !isLocal; @@ -286,6 +286,11 @@ public class VSTask implements Comparable, VSSerializable { buffer.append(event.toString()); buffer.append("; PID: "); buffer.append(process.getProcessID()); + /* + if (isProgrammed()) { + buffer.append("; Programmed"); + } + */ return buffer.toString(); } @@ -385,25 +390,27 @@ public class VSTask implements Comparable, VSSerializable { String eventClassname = (String) objectInputStream.readObject(); int eventID = ((Integer) objectInputStream.readObject()).intValue(); - VSAbstractEvent event = (VSAbstractEvent) - serialize.getObject(eventID, "event"); + VSAbstractEvent event = null; + + if (serialize.objectExists(eventID, "event")) { + event = (VSAbstractEvent) serialize.getObject(eventID, "event"); - if (event == null) { + } else { event = VSRegisteredEvents. createEventInstanceByClassname(eventClassname, process); serialize.setObject(eventID, "event", event); } + event.deserialize(serialize, objectInputStream); + int taskNum = ((Integer) objectInputStream.readObject()).intValue(); long taskTime = ((Long) objectInputStream.readObject()).longValue(); Boolean isGlobalTimed = (Boolean) objectInputStream.readObject(); Boolean isProgrammed = (Boolean) objectInputStream.readObject(); serialize.setObject(taskNum, "task", this); - init(taskTime, process, event, !isGlobalTimed.booleanValue()); - this.isProgrammed = isProgrammed.booleanValue(); } } diff --git a/sources/core/VSTaskManager.java b/sources/core/VSTaskManager.java index cbbde56..5e32183 100644 --- a/sources/core/VSTaskManager.java +++ b/sources/core/VSTaskManager.java @@ -537,7 +537,6 @@ public class VSTaskManager implements VSSerializable { if (VSSerialize.DEBUG) System.out.println("Deserializing: VSTaskManager"); - int numTasks = ((Integer) objectInputStream.readObject()).intValue(); globalTasks.clear(); ArrayList<VSProcess> processes = simulatorCanvas.getProcesses(); @@ -546,7 +545,10 @@ public class VSTaskManager implements VSSerializable { process.getTasks().clear(); } - for (int i = 0; i < numTasks; ++i) - addTask(new VSTask(serialize, objectInputStream)); + int numTasks = ((Integer) objectInputStream.readObject()).intValue(); + for (int i = 0; i < numTasks; ++i) { + VSTask task = new VSTask(serialize, objectInputStream); + addTask(task, task.isProgrammed()); + } } } diff --git a/sources/events/VSAbstractEvent.java b/sources/events/VSAbstractEvent.java index 34e2b87..0dd814c 100644 --- a/sources/events/VSAbstractEvent.java +++ b/sources/events/VSAbstractEvent.java @@ -173,8 +173,11 @@ abstract public class VSAbstractEvent extends VSPrefs { ObjectOutputStream objectOutputStream) throws IOException { super.serialize(serialize, objectOutputStream); + + if (VSSerialize.DEBUG) + System.out.println("Serializing: VSAbstractEvent; id="+getID()); + objectOutputStream.writeObject(new Integer(super.getID())); - //objectOutputStream.writeObject(new Integer(process.getProcessNum())); objectOutputStream.writeObject(eventShortname); objectOutputStream.writeObject(eventClassname); } @@ -190,13 +193,15 @@ abstract public class VSAbstractEvent extends VSPrefs { super.deserialize(serialize, objectInputStream); if (VSSerialize.DEBUG) - System.out.println("Deserializing: VSAbstractEvent"); + System.out.print("Deserializing: VSAbstractEvent "); int id = ((Integer) objectInputStream.readObject()).intValue(); - //Integer processNum = (Integer) objectInputStream.readObject(); this.eventShortname = (String) objectInputStream.readObject(); this.eventClassname = (String) objectInputStream.readObject(); + if (VSSerialize.DEBUG) + System.out.println(eventClassname); + serialize.setObject(id, "event", this); } } diff --git a/sources/events/internal/VSProtocolEvent.java b/sources/events/internal/VSProtocolEvent.java index cfb1e35..5f5ceb4 100644 --- a/sources/events/internal/VSProtocolEvent.java +++ b/sources/events/internal/VSProtocolEvent.java @@ -23,8 +23,11 @@ package events.internal; +import java.io.*; + import events.*; import protocols.VSAbstractProtocol; +import serialize.*; /** * The class VSProtocolEvent. This event is used if a protocol (server or @@ -132,4 +135,37 @@ public class VSProtocolEvent extends VSAbstractEvent { logg(buffer.toString()); } + + /* (non-Javadoc) + * @see serialize.VSSerializable#serialize(serialize.VSSerialize, + * java.io.ObjectOutputStream) + */ + public synchronized void serialize(VSSerialize serialize, + ObjectOutputStream objectOutputStream) + throws IOException { + super.serialize(serialize, objectOutputStream); + objectOutputStream.writeObject(protocolClassname); + objectOutputStream.writeObject(new Boolean(isClientProtocol)); + objectOutputStream.writeObject(new Boolean(isProtocolActivation)); + } + + /* (non-Javadoc) + * @see serialize.VSSerializable#deserialize(serialize.VSSerialize, + * java.io.ObjectInputStream) + */ + @SuppressWarnings("unchecked") + public synchronized void deserialize(VSSerialize serialize, + ObjectInputStream objectInputStream) + throws IOException, ClassNotFoundException { + super.deserialize(serialize, objectInputStream); + + if (VSSerialize.DEBUG) + System.out.println("Deserializing: VSProtocolEvent"); + + protocolClassname = (String) objectInputStream.readObject(); + isClientProtocol = ((Boolean) + objectInputStream.readObject()).booleanValue();; + isProtocolActivation = ((Boolean) + objectInputStream.readObject()).booleanValue();; + } } diff --git a/sources/serialize/VSSerialize.java b/sources/serialize/VSSerialize.java index b659879..20023c9 100644 --- a/sources/serialize/VSSerialize.java +++ b/sources/serialize/VSSerialize.java @@ -82,6 +82,9 @@ public final class VSSerialize { * @param object The object itself */ public void setObject(String key, Object object) { + if (DEBUG) + System.out.println("setObject("+key+")"); + objects.put(key, object); } @@ -93,10 +96,25 @@ public final class VSSerialize { * @param object The object itself */ public void setObject(int num, String key, Object object) { + if (DEBUG) + System.out.println("setObject("+key+":"+num+")"); + objects.put(key + ":" + num, object); } /** + * Checks if an object exists. + * + * @param num The object number + * @param key The object key + * + * @return true, if the object exists. false, if the object does not exist + */ + public boolean objectExists(int num, String key) { + return null != objects.get(key + ":" + num); + } + + /** * Gets an object. * * @param num The object number @@ -153,6 +171,9 @@ public final class VSSerialize { } catch (IOException e) { e.printStackTrace(); + + } finally { + //objectOutputStream.close(); } } @@ -167,6 +188,7 @@ public final class VSSerialize { public VSSimulator openSimulator(String filename, VSSimulatorFrame simulatorFrame) { VSSimulator simulator = null; + simulatorFrame.resetCurrentSimulator(); try { FileInputStream fileInputStream = @@ -183,6 +205,9 @@ public final class VSSerialize { } catch (Exception e) { e.printStackTrace(); + + } finally { + //objectInputStream.close(); } return simulator; diff --git a/sources/simulator/VSSimulator.java b/sources/simulator/VSSimulator.java index f376719..4323190 100644 --- a/sources/simulator/VSSimulator.java +++ b/sources/simulator/VSSimulator.java @@ -402,7 +402,7 @@ public class VSSimulator extends JPanel implements VSSerializable { this.globalTextFields = new ArrayList<String>(); /* Not null if init has been called from the deserialization */ - if (logging == null) + if (this.logging == null) this.logging = new VSLogging(); logging.logg(prefs.getString("lang.simulator.new")); @@ -443,7 +443,7 @@ public class VSSimulator extends JPanel implements VSSerializable { splitPaneV = new JSplitPane(); /* Not null if init has been called from the deserialization */ - if (simulatorCanvas == null) + if (this.simulatorCanvas == null) simulatorCanvas = new VSSimulatorCanvas(prefs, this, logging); taskManager = simulatorCanvas.getTaskManager(); @@ -873,6 +873,7 @@ public class VSSimulator extends JPanel implements VSSerializable { for (VSProcess process : processes) { VSTask task = createTask.createTask(process, time, localTasks); + System.out.println(task); taskManager.addTask(task, VSTaskManager.PROGRAMMED); if (selectedProcess == null || diff --git a/sources/simulator/VSSimulatorCanvas.java b/sources/simulator/VSSimulatorCanvas.java index cfc6549..1d12a06 100644 --- a/sources/simulator/VSSimulatorCanvas.java +++ b/sources/simulator/VSSimulatorCanvas.java @@ -495,11 +495,11 @@ public class VSSimulatorCanvas extends Canvas this.messageLinesToRemove = new LinkedList<VSMessageLine>(); /* May be not null if called from deserialization */ - if (taskManager == null) + if (this.taskManager == null) this.taskManager = new VSTaskManager(prefs, this); /* May be not null if called from deserialization */ - if (processes == null) { + if (this.processes == null) { this.processes = new ArrayList<VSProcess>(); numProcesses = prefs.getInteger("sim.process.num"); diff --git a/sources/simulator/VSSimulatorFrame.java b/sources/simulator/VSSimulatorFrame.java index aff8787..c538284 100644 --- a/sources/simulator/VSSimulatorFrame.java +++ b/sources/simulator/VSSimulatorFrame.java @@ -145,7 +145,8 @@ public class VSSimulatorFrame extends VSFrame { } else if (sourceText.equals( finalPrefs.getString("lang.open"))) { - + pauseCurrentSimulator(); + resetCurrentSimulator(); VSSerialize serialize = new VSSerialize(); VSSimulator simulator = serialize.openSimulator( VSSerialize.STANDARD_FILENAME, @@ -155,6 +156,8 @@ public class VSSimulatorFrame extends VSFrame { } else if (sourceText.equals( finalPrefs.getString("lang.save"))) { + pauseCurrentSimulator(); + resetCurrentSimulator(); VSSerialize serialize = new VSSerialize(); serialize.saveSimulator(VSSerialize.STANDARD_FILENAME, currentSimulator); @@ -180,25 +183,11 @@ public class VSSimulatorFrame extends VSFrame { } else if (sourceText.equals( finalPrefs.getString("lang.pause"))) { - VSMenuItemStates menuItemState = - currentSimulator.getMenuItemStates(); - menuItemState.setStart(true); - menuItemState.setPause(false); - menuItemState.setReset(true); - menuItemState.setReplay(true); - currentSimulator.getSimulatorCanvas().pause(); - updateSimulatorMenu(); + pauseCurrentSimulator(); } else if (sourceText.equals( finalPrefs.getString("lang.reset"))) { - VSMenuItemStates menuItemState = - currentSimulator.getMenuItemStates(); - menuItemState.setStart(true); - menuItemState.setPause(false); - menuItemState.setReset(false); - menuItemState.setReplay(false); - currentSimulator.getSimulatorCanvas().reset(); - updateSimulatorMenu(); + resetCurrentSimulator(); } else if (sourceText.equals( finalPrefs.getString("lang.replay"))) { @@ -532,6 +521,34 @@ public class VSSimulatorFrame extends VSFrame { } /** + * Resets the current simulator + */ + public void resetCurrentSimulator() { + VSMenuItemStates menuItemState = + currentSimulator.getMenuItemStates(); + menuItemState.setStart(true); + menuItemState.setPause(false); + menuItemState.setReset(false); + menuItemState.setReplay(false); + currentSimulator.getSimulatorCanvas().reset(); + updateSimulatorMenu(); + } + + /** + * Pauses the current simulator + */ + public void pauseCurrentSimulator() { + VSMenuItemStates menuItemState = + currentSimulator.getMenuItemStates(); + menuItemState.setStart(true); + menuItemState.setPause(false); + menuItemState.setReset(true); + menuItemState.setReplay(true); + currentSimulator.getSimulatorCanvas().pause(); + updateSimulatorMenu(); + } + + /** * Gets the image icon. * * @param name the name |
