Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-08-06 07:07:11 -0400
committerHenrik Rentz-Reichert2013-08-06 07:07:11 -0400
commit62034abcaee7d1a08be36484b3b76a756886fbd8 (patch)
tree211c1a77eb2c773a54ec2dd0b5462c251f72e30f /runtime/org.eclipse.etrice.runtime.java/src/org/eclipse
parentd899bf6f8a0471f575374fad678ebbefca5f0298 (diff)
downloadorg.eclipse.etrice-62034abcaee7d1a08be36484b3b76a756886fbd8.tar.gz
org.eclipse.etrice-62034abcaee7d1a08be36484b3b76a756886fbd8.tar.xz
org.eclipse.etrice-62034abcaee7d1a08be36484b3b76a756886fbd8.zip
[runtime.java, generator.java] bug 414477: [runtime.java][generator.java] add a possibility to let dynamic actors store and restore their data
https://bugs.eclipse.org/bugs/show_bug.cgi?id=414477
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.java/src/org/eclipse')
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IPersistable.java27
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/OptionalActorInterfaceBase.java65
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ScalarOptionalActorInterfaceBase.java3
3 files changed, 84 insertions, 11 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IPersistable.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IPersistable.java
new file mode 100644
index 000000000..c84e95c4d
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IPersistable.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.modelbase;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public interface IPersistable {
+
+ void saveObject(ObjectOutput output) throws IOException;
+ void loadObject(ObjectInput input) throws IOException, ClassNotFoundException;
+}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/OptionalActorInterfaceBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/OptionalActorInterfaceBase.java
index dfa9362a5..71de950b5 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/OptionalActorInterfaceBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/OptionalActorInterfaceBase.java
@@ -355,36 +355,83 @@ public abstract class OptionalActorInterfaceBase extends SystemPortOwner impleme
}
/**
- * TODO: persistence not implemented yet
+ * This method is called if an {@link ObjectInput} was passed to creation and after
+ * the actor instance sub tree is created and ports are bound.
*
- * @param actor
- * @param input
+ * <p>
+ * States, history and all attributes of the actor instances are restored.
+ * </p>
+ *
+ * @param actor an actor class
+ * @param input the input stream
*/
protected void loadActor(ActorClassBase actor, ObjectInput input) {
if (input==null || actor==null)
return;
try {
- input.close();
+ recursivelyLoad(actor, input);
}
- catch (IOException e) {
+ catch (Throwable e) {
}
}
/**
- * TODO: persistence not implemented yet
+ * The recursive loading of an instance sub tree.
*
- * @param actor
- * @param output
+ * @param actor an actor class
+ * @param input the input stream
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ private void recursivelyLoad(ActorClassBase actor, ObjectInput input) throws IOException, ClassNotFoundException {
+ if (actor instanceof IPersistable) {
+ ((IPersistable) actor).loadObject(input);
+
+ for (IRTObject child : actor.getChildren()) {
+ if (child instanceof ActorClassBase)
+ recursivelyLoad((ActorClassBase) child, input);
+ }
+ }
+ }
+
+ /**
+ * This method is called when an {@link ObjectOutput} was passed to destruction
+ * and before the instance sub tree is destroyed.
+ *
+ * <p>
+ * States, history and all attributes of the actor instances are stored.
+ * </p>
+ *
+ * @param actor an actor class
+ * @param output the output stream
*/
protected void saveActor(ActorClassBase actor, ObjectOutput output) {
if (output==null || actor==null)
return;
try {
- output.close();
+ recursivelySave(actor, output);
}
catch (IOException e) {
}
}
+
+ /**
+ * The recursive saving of an instance sub tree.
+ *
+ * @param actor an actor class
+ * @param output the output stream
+ * @throws IOException
+ */
+ private void recursivelySave(ActorClassBase actor, ObjectOutput output) throws IOException {
+ if (actor instanceof IPersistable) {
+ ((IPersistable) actor).saveObject(output);
+
+ for (IRTObject child : actor.getChildren()) {
+ if (child instanceof ActorClassBase)
+ recursivelySave((ActorClassBase) child, output);
+ }
+ }
+ }
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ScalarOptionalActorInterfaceBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ScalarOptionalActorInterfaceBase.java
index dfd6263be..2a01006c9 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ScalarOptionalActorInterfaceBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ScalarOptionalActorInterfaceBase.java
@@ -105,8 +105,7 @@ public class ScalarOptionalActorInterfaceBase extends OptionalActorInterfaceBase
logDeletion(getName());
- if (output!=null)
- saveActor(actor, output);
+ shutdownSubTree(actor, output);
actor.destroy();
actor = null;

Back to the top