Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-07-26 05:29:08 -0400
committerHenrik Rentz-Reichert2013-07-26 05:39:04 -0400
commit4f6f960093a1314b923d1132d15089d12a70a7d7 (patch)
treecfd99bc9789186c99297e0d1ced37d62851704ca /runtime/org.eclipse.etrice.runtime.java/src/org/eclipse
parent27dddfbd1b567c8fa5bc813d36bc4e957e377c50 (diff)
downloadorg.eclipse.etrice-4f6f960093a1314b923d1132d15089d12a70a7d7.tar.gz
org.eclipse.etrice-4f6f960093a1314b923d1132d15089d12a70a7d7.tar.xz
org.eclipse.etrice-4f6f960093a1314b923d1132d15089d12a70a7d7.zip
[*] manually merged DynamicActors, new ui.structure and physical model aware Java generator
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/debugging/DebuggingService.java33
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/debugging/MSCLogger.java16
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/Address.java2
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/IMessageService.java43
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/IRTObject.java3
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageDispatcher.java16
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java25
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java109
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTObject.java55
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java16
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/DataReceivePort.java3
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/DataSendPort.java3
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/EventReceiver.java21
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IEventReceiver.java16
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IInterfaceItemBroker.java24
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IInterfaceItemOwner.java37
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IOptionalActorFactory.java29
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IReplicatedInterfaceItem.java1
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBase.java102
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBroker.java90
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/OptionalActorInterfaceBase.java135
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PathToPeers.java53
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PathToThread.java24
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PortBase.java5
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/RTSystemProtocol.java19
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedInterfaceItemBase.java50
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedInterfaceItemBroker.java38
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedOptionalActorInterfaceBase.java118
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedPortBase.java3
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ScalarOptionalActorInterfaceBase.java74
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SubSystemClassBase.java108
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SystemPortOwner.java33
32 files changed, 1126 insertions, 178 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/debugging/DebuggingService.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/debugging/DebuggingService.java
index 5bd131ecf..4a9f52f8f 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/debugging/DebuggingService.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/debugging/DebuggingService.java
@@ -16,8 +16,11 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.IRTObject;
import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;
+import org.eclipse.etrice.runtime.java.modelbase.OptionalActorInterfaceBase;
import org.eclipse.etrice.runtime.java.modelbase.PortBase;
+import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase;
/**
@@ -79,10 +82,40 @@ public class DebuggingService {
asyncLogger.addActorState(actor.getInstancePath(), state);
}
+ public void addMessageActorCreate(SubSystemClassBase parent, String refName) {
+ asyncLogger.addMessageActorCreate(parent.getInstancePath(), parent.getInstancePath()+IRTObject.PATH_DELIM+refName);
+ }
+
+ public void addMessageActorCreate(ActorClassBase parent, String refName) {
+ asyncLogger.addMessageActorCreate(parent.getInstancePath(), parent.getInstancePath()+IRTObject.PATH_DELIM+refName);
+ }
+
+ public void addMessageActorDestroy(ActorClassBase inst) {
+ if (!(inst.getParent() instanceof OptionalActorInterfaceBase))
+ asyncLogger.addMessageActorDestroy(inst.getParent().getInstancePath(), inst.getInstancePath());
+ }
+
+ public void addMessageActorCreate(OptionalActorInterfaceBase oai, String actorClass) {
+ asyncLogger.addNote(oai.getParent().getInstancePath(), "dynamically creating actor class "+actorClass);
+ asyncLogger.addMessageActorCreate(oai.getParent().getInstancePath(), oai.getInstancePath()+IRTObject.PATH_DELIM+oai.getName());
+ }
+
+ public void addMessageActorDestroy(OptionalActorInterfaceBase oai) {
+ asyncLogger.addMessageActorDestroy(oai.getParent().getInstancePath(), oai.getInstancePath()+IRTObject.PATH_DELIM+oai.getName());
+ }
+
+ public void addVisibleComment(String comment) {
+ asyncLogger.addVisibleComment(comment);
+ }
+
public void addPortInstance(PortBase port){
portInstances.put(port.getAddress(), port);
}
+ public void removePortInstance(PortBase port){
+ portInstances.remove(port.getAddress());
+ }
+
public MSCLogger getSyncLogger() {
return syncLogger;
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/debugging/MSCLogger.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/debugging/MSCLogger.java
index 39820d6e4..b1274cebf 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/debugging/MSCLogger.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/debugging/MSCLogger.java
@@ -56,11 +56,27 @@ public class MSCLogger {
createLine(source, " <== ", target, message);
}
+ public synchronized void addMessageActorCreate(String source, String target){
+ createLine(source, " (!) ", target, "");
+ }
+
+ public synchronized void addMessageActorDestroy(String source, String target){
+ createLine(source, " (X) ", target, "");
+ }
+
+ public synchronized void addNote(String actor, String note){
+ if (filter.applyTo(actor))
+ getCommandList().add( new String ("\t"+filter.reduceString(actor)+" note: "+note) );
+ }
public synchronized void addActorState(String actor, String state){
if (filter.applyTo(actor))
getCommandList().add( new String ("\t"+filter.reduceString(actor)+" >>> "+state) );
}
+
+ public synchronized void addVisibleComment(String comment){
+ getCommandList().add("# "+comment);
+ }
private void createLine(String source, String mid, String target, String message) {
if (filter.applyTo(source) && filter.applyTo(target)) {
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/Address.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/Address.java
index 1943cbac9..1ad4904e9 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/Address.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/Address.java
@@ -33,7 +33,7 @@ public class Address {
public int objectID;
public String toString(){
- return "Address(nodeID="+nodeID+",threadID="+threadID+",objectID="+objectID+")";
+ return "Address(n="+nodeID+",t="+threadID+",o="+objectID+")";
}
public String toID(){
return nodeID+"_"+threadID+"_"+objectID;
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/IMessageService.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/IMessageService.java
new file mode 100644
index 000000000..836b73b5a
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/IMessageService.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.messaging;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public interface IMessageService extends IRTObject, IMessageReceiver, Runnable {
+
+ enum ExecMode {
+ POLLED, BLOCKED, MIXED
+ }
+
+ void terminate();
+
+ Address getFreeAddress();
+
+ void freeAddress(Address addr);
+
+ /**
+ * set the thread of this service
+ * (also sets the thread priority)
+ *
+ * @param thread
+ */
+ void setThread(Thread thread);
+
+ /**
+ * @return the thread of this service
+ */
+ Thread getThread();
+}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/IRTObject.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/IRTObject.java
index 4dc06e41d..42d95caba 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/IRTObject.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/IRTObject.java
@@ -36,4 +36,7 @@ public interface IRTObject {
String getInstancePath(char delim);
String getInstancePath();
String getInstancePathName();
+
+ int getThreadForPath(String path);
+ List<String> getPeersForPath(String path);
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageDispatcher.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageDispatcher.java
index 44e59efbf..b68583142 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageDispatcher.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageDispatcher.java
@@ -62,6 +62,22 @@ public class MessageDispatcher extends RTObject implements IMessageReceiver {
}
}
+ public void removeMessageReceiver(IMessageReceiver receiver){
+ if (receiver.getAddress()==null)
+ return;
+
+ // TODO: does only work same thread (else)
+ if (receiver.getAddress().nodeID != address.nodeID){
+ node_map.remove(receiver.getAddress().objectID);
+ }
+ else if(receiver.getAddress().threadID != address.threadID){
+ thread_map.remove(receiver.getAddress().threadID);
+ }
+ else {
+ local_map.remove(receiver.getAddress().objectID);
+ }
+ }
+
@Override
public void receive(Message msg) {
// TODO: does only work same thread (else)
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java
index e7aa4be0e..a5f1a76ae 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java
@@ -15,14 +15,14 @@ package org.eclipse.etrice.runtime.java.messaging;
/**
- * The MessageService the backbone of the asynchronous communication inside a SubSystem
+ * The MessageService is the backbone of the asynchronous communication inside a SubSystem
* It usually contains a thread a message queue and a dispatcher
*
* @author Thomas Schuetz (initial contribution)
* @author Henrik Rentz-Reichert (extending RTObject, implementing Runnable)
*
*/
-public class MessageService extends RTObject implements IMessageReceiver, Runnable {
+public class MessageService extends RTObject implements IMessageService {
private boolean running = false;
@@ -34,11 +34,15 @@ public class MessageService extends RTObject implements IMessageReceiver, Runnab
private Thread thread;
private int priority;
- public MessageService(IRTObject parent, int node, int thread, String name) {
- this(parent, node, thread, name, Thread.NORM_PRIORITY);
+ public MessageService(IRTObject parent, ExecMode mode, int node, int thread, String name) {
+ this(parent, mode, 0, node, thread, name, Thread.NORM_PRIORITY);
}
- public MessageService(IRTObject parent, int node, int thread, String name, int priority) {
+ public MessageService(IRTObject parent, ExecMode mode, int nsec, int node, int thread, String name) {
+ this(parent, mode, nsec, node, thread, name, Thread.NORM_PRIORITY);
+ }
+
+ public MessageService(IRTObject parent, ExecMode mode, int nsec, int node, int thread, String name, int priority) {
super(parent, "MessageService_"+name);
address = new Address(node, thread, 0);
@@ -117,11 +121,8 @@ public class MessageService extends RTObject implements IMessageReceiver, Runnab
}
}
- /**
- * set the thread of this service
- * (also sets the thread priority)
- *
- * @param thread
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.runtime.java.messaging.IMessageService#setThread(java.lang.Thread)
*/
public void setThread(Thread thread) {
this.thread = thread;
@@ -129,8 +130,8 @@ public class MessageService extends RTObject implements IMessageReceiver, Runnab
thread.setPriority(priority);
}
- /**
- * @return the thread of this service
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.runtime.java.messaging.IMessageService#getThread()
*/
public Thread getThread() {
return thread;
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java
index 35acd3f3f..8f8509e5f 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java
@@ -13,9 +13,6 @@
package org.eclipse.etrice.runtime.java.messaging;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -30,47 +27,16 @@ import java.util.Map;
public class MessageServiceController {
- @SuppressWarnings("serial")
- private static class PathToThread extends HashMap<String, Integer> {}
- @SuppressWarnings("serial")
- private static class PathToPeers extends HashMap<String, ArrayList<String>> {
- public void put(String key, String value) {
- ArrayList<String> list = get(key);
- if (list==null) {
- list = new ArrayList<String>();
- put(key, list);
- }
- list.add(value);
- }
-
- public void put(String key, Collection<String> values) {
- ArrayList<String> list = get(key);
- if (list==null) {
- list = new ArrayList<String>(values);
- put(key, list);
- }
- else
- list.addAll(values);
- }
-
- public void put(String key, String[] values) {
- List<String> list = Arrays.asList(values);
- put(key, list);
- }
- }
-
- private List<MessageService> messageServiceList = null;
- private PathToThread path2thread = new PathToThread();
- private PathToPeers path2peers = new PathToPeers();
+ private List<IMessageService> messageServiceList = null;
private boolean running = false;
public MessageServiceController(/*IRTObject parent*/){
// TODOTS: Who is parent of MessageServices and Controller?
// this.parent = parent;
- messageServiceList = new ArrayList<MessageService>();
+ messageServiceList = new ArrayList<IMessageService>();
}
- public void addMsgSvc(MessageService msgSvc){
+ public void addMsgSvc(IMessageService msgSvc){
// TODOTS: Who is parent of MessageServices ?
assert(msgSvc.getAddress().threadID == messageServiceList.size());
messageServiceList.add(msgSvc);
@@ -80,14 +46,14 @@ public class MessageServiceController {
return messageServiceList.size();
}
- public MessageService getMsgSvc(int threadID){
+ public IMessageService getMsgSvc(int threadID){
assert(threadID < messageServiceList.size());
return messageServiceList.get(threadID);
}
public void start() {
// start all message services
- for (MessageService msgSvc : messageServiceList){
+ for (IMessageService msgSvc : messageServiceList){
Thread thread = new Thread(msgSvc, msgSvc.getName());
msgSvc.setThread(thread);
thread.start();
@@ -130,7 +96,7 @@ public class MessageServiceController {
private void terminate() {
// terminate all message services
- for (MessageService msgSvc : messageServiceList){
+ for (IMessageService msgSvc : messageServiceList){
msgSvc.terminate();
// TODOTS: stop in order of priorities
}
@@ -141,7 +107,7 @@ public class MessageServiceController {
* ! not threadsafe !
*/
public void waitTerminate() {
- for (MessageService msgSvc : messageServiceList) {
+ for (IMessageService msgSvc : messageServiceList) {
try {
msgSvc.getThread().join(1000); // wait at most 1000ms
if (msgSvc.getThread().isAlive())
@@ -153,67 +119,8 @@ public class MessageServiceController {
}
}
- /**
- * map a path to a thread id
- * @param path
- * @param thread
- */
- public void addPathToThread(String path, int thread) {
- path2thread.put(path, thread);
- }
-
- /**
- * get thread for path
- * @param path
- * @return
- */
- public int getThreadForPath(String path) {
- Integer thread = path2thread.get(path);
- if (thread==null)
- return 0;
-
- return thread;
- }
-
- /**
- * add a peer for the given path
- * @param path
- * @param peer
- */
- public void addPathToPeer(String path, String peer) {
- path2peers.put(path, peer);
- }
-
- /**
- * add a collection of peers to the given path
- * @param path
- * @param peers
- */
- public void addPathToPeers(String path, Collection<String> peers) {
- path2peers.put(path, peers);
- }
-
- /**
- * add several peers to the given path
- * @param path
- * @param peers
- */
- public void addPathToPeers(String path, String... peers) {
- path2peers.put(path, peers);
- }
-
- /**
- * @param path
- * @return list of peer paths
- */
- public List<String> getPeersForPath(String path) {
- return path2peers.get(path);
- }
-
public void resetAll() {
stop();
messageServiceList.clear();
- path2peers.clear();
- path2thread.clear();
- }
+}
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTObject.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTObject.java
index d6ee1c3a6..0edd3400a 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTObject.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTObject.java
@@ -9,6 +9,7 @@
package org.eclipse.etrice.runtime.java.messaging;
import java.util.ArrayList;
+import java.util.List;
/**
* An implementation of the IRTObject interface using a hierarchical structure
@@ -44,14 +45,16 @@ public class RTObject implements IRTObject {
}
protected void destroy() {
- for (IRTObject child : children) {
+ while (!children.isEmpty()) {
+ IRTObject child = children.get(0);
if (child instanceof RTObject)
((RTObject) child).destroy();
}
-
- parent.getChildren().remove(this);
-
- parent = null;
+
+ if (parent!=null) {
+ parent.getChildren().remove(this);
+ parent = null;
+ }
}
public IRTObject getRoot() {
@@ -115,4 +118,46 @@ public class RTObject implements IRTObject {
public String getInstancePathName() {
return getInstancePath(PATHNAME_DELIM);
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.runtime.java.messaging.IRTObject#getThreadForPath(java.lang.String)
+ */
+ @Override
+ public int getThreadForPath(String path) {
+ if (parent!=null)
+ return parent.getThreadForPath(path);
+ return -1;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.runtime.java.messaging.IRTObject#getPeersForPath(java.lang.String)
+ */
+ @Override
+ public List<String> getPeersForPath(String path) {
+ if (parent!=null)
+ return parent.getPeersForPath(path);
+ return null;
+ }
+
+ private String toStringRecursive(String indent) {
+ StringBuilder result = new StringBuilder(indent+toString()+"\n");
+
+ indent = " "+indent;
+ for (IRTObject child : getChildren()) {
+ if (child instanceof RTObject)
+ result.append(((RTObject)child).toStringRecursive(indent));
+ else
+ result.append(child.toString()+"\n");
+ }
+ return result.toString();
+ }
+
+ public String toStringRecursive() {
+ return toStringRecursive("");
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java
index 3e5da5b32..9cd0075e4 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java
@@ -22,7 +22,7 @@ import org.eclipse.etrice.runtime.java.modelbase.RTSystemProtocol.RTSystemPort;
* @author Thomas Schuetz
*
*/
-public abstract class ActorClassBase extends EventReceiver implements IMessageReceiver {
+public abstract class ActorClassBase extends SystemPortOwner implements IMessageReceiver {
protected static final int EVT_SHIFT = 1000; // TODOHRR: use 256 or shift operation later
@@ -38,7 +38,7 @@ public abstract class ActorClassBase extends EventReceiver implements IMessageRe
/**
* the current state
*/
- protected int state;
+ protected int state = NO_STATE;
protected RTSystemPort rtSystemPort = null;
@@ -88,7 +88,7 @@ public abstract class ActorClassBase extends EventReceiver implements IMessageRe
return ssc.getVariableService();
}
- //--------------------- lifecycle functions
+ //--------------------- life cycle functions
public void init() {
for (IRTObject child : getChildren()) {
if (child instanceof ActorClassBase)
@@ -117,15 +117,12 @@ public abstract class ActorClassBase extends EventReceiver implements IMessageRe
}
public void destroy() {
- for (IRTObject child : getChildren()) {
- if (child instanceof ActorClassBase)
- ((ActorClassBase) child).destroy();
- }
+ super.destroy();
}
public abstract void executeInitTransition();
- // not automatically generated lifecycle functions
+ // not automatically generated life cycle functions
// are called, but with empty implementation -> can be overridden by user
public void initUser(){}
public void startUser(){}
@@ -146,7 +143,8 @@ public abstract class ActorClassBase extends EventReceiver implements IMessageRe
switch (evt){
case RTSystemServicesProtocol.IN_executeInitialTransition :
- executeInitTransition();
+ if (state==NO_STATE)
+ executeInitTransition();
break;
case RTSystemServicesProtocol.IN_startDebugging :
break;
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/DataReceivePort.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/DataReceivePort.java
index d4a3e11cb..f35b70c4a 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/DataReceivePort.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/DataReceivePort.java
@@ -15,7 +15,6 @@ package org.eclipse.etrice.runtime.java.modelbase;
import java.util.List;
import org.eclipse.etrice.runtime.java.messaging.IRTObject;
-import org.eclipse.etrice.runtime.java.messaging.RTServices;
/**
* @author Henrik Rentz-Reichert
@@ -30,7 +29,7 @@ public abstract class DataReceivePort extends DataPortBase {
protected DataReceivePort(IRTObject parent, String name, int localId) {
super(parent, name, localId);
- List<String> peerPaths = RTServices.getInstance().getMsgSvcCtrl().getPeersForPath(getInstancePath());
+ List<String> peerPaths = getParent().getPeersForPath(getInstancePath());
if (peerPaths!=null && !peerPaths.isEmpty()) {
IRTObject object = getObject(peerPaths.get(0));
connect((DataSendPort) object);
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/DataSendPort.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/DataSendPort.java
index 1b5e69aad..189a441cd 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/DataSendPort.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/DataSendPort.java
@@ -15,7 +15,6 @@ package org.eclipse.etrice.runtime.java.modelbase;
import java.util.List;
import org.eclipse.etrice.runtime.java.messaging.IRTObject;
-import org.eclipse.etrice.runtime.java.messaging.RTServices;
/**
* @author Henrik Rentz-Reichert
@@ -26,7 +25,7 @@ public class DataSendPort extends DataPortBase {
public DataSendPort(IRTObject parent, String name, int localId) {
super(parent, name, localId);
- List<String> peerPaths = RTServices.getInstance().getMsgSvcCtrl().getPeersForPath(getInstancePath());
+ List<String> peerPaths = getParent().getPeersForPath(getInstancePath());
if (peerPaths!=null) {
for (String peerPath : peerPaths) {
IRTObject object = getObject(peerPath);
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/EventReceiver.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/EventReceiver.java
index 2711bf4d0..1618c58db 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/EventReceiver.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/EventReceiver.java
@@ -19,8 +19,29 @@ import org.eclipse.etrice.runtime.java.messaging.RTObject;
*/
public abstract class EventReceiver extends RTObject implements IEventReceiver {
+ private int thread = -1;
+
+ /**
+ * The only constructor for {@link EventReceiver} objects.
+ *
+ * @param parent the parent object
+ * @param name the name of this object
+ */
public EventReceiver(IRTObject parent, String name) {
super(parent, name);
}
+
+ @Override
+ public int getThread() {
+ if (thread<0) {
+ thread = getThreadForPath(getInstancePath());
+ if (thread<0)
+ if (getParent() instanceof EventReceiver)
+ thread = ((EventReceiver)getParent()).getThread();
+ else
+ thread = 0;
+ }
+ return thread;
+ }
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IEventReceiver.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IEventReceiver.java
index 179cdcf60..cf26b5a75 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IEventReceiver.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IEventReceiver.java
@@ -11,12 +11,26 @@ package org.eclipse.etrice.runtime.java.modelbase;
import org.eclipse.etrice.runtime.java.messaging.IRTObject;
/**
- * The event reciver interface.
+ * The event receiver interface.
+ * An event receiver can {@link #receiveEvent(InterfaceItemBase, int, Object) receive events}
+ * an he knows the {@link #getThread()} on which it is running.
*
* @author Thomas Schuetz
*
*/
public interface IEventReceiver extends IRTObject {
+ /**
+ * This method is called by an {@link InterfaceItemBase}.
+ *
+ * @param ifitem the calling interface item
+ * @param evt the event ID
+ * @param data optional data (may be {@code null}
+ */
void receiveEvent(InterfaceItemBase ifitem, int evt, Object data);
+
+ /**
+ * @return the thread of this event receiver
+ */
+ int getThread();
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IInterfaceItemBroker.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IInterfaceItemBroker.java
new file mode 100644
index 000000000..d8b4dbb09
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IInterfaceItemBroker.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * This is just a marker interface.
+ *
+ * @see InterfaceItemBroker
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public interface IInterfaceItemBroker {
+
+}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IInterfaceItemOwner.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IInterfaceItemOwner.java
new file mode 100644
index 000000000..6268e5864
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IInterfaceItemOwner.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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 org.eclipse.etrice.runtime.java.messaging.IRTObject;
+
+/**
+ * {@link IRTObject runtime objects} that own interface items are derived
+ * from this interface. They have an {@link IEventReceiver} associated
+ * and they own the replicated system port responsible for their
+ * sub tree or delegate to their parent.
+ *
+ * @author Henrik Rentz-Reichert
+ */
+public interface IInterfaceItemOwner extends IRTObject {
+
+ /**
+ * @return the event receiver that receives messages of the owned interface items
+ */
+ IEventReceiver getEventReceiver();
+
+ /**
+ * @return the replicated system port which is responsible for this
+ * instance sub tree
+ */
+ IReplicatedInterfaceItem getSystemPort();
+}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IOptionalActorFactory.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IOptionalActorFactory.java
new file mode 100644
index 000000000..a05a1fad6
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IOptionalActorFactory.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public interface IOptionalActorFactory {
+
+ /**
+ * @param name
+ * @param replicatedOptionalActorInterfaceBase
+ * @param name
+ * @return
+ */
+ ActorClassBase create(OptionalActorInterfaceBase parent, String name);
+
+}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IReplicatedInterfaceItem.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IReplicatedInterfaceItem.java
index 9fcac1819..0899f67bc 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IReplicatedInterfaceItem.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/IReplicatedInterfaceItem.java
@@ -19,4 +19,5 @@ package org.eclipse.etrice.runtime.java.modelbase;
public interface IReplicatedInterfaceItem {
InterfaceItemBase createSubInterfaceItem();
+ void removeItem(InterfaceItemBase item);
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBase.java
index 6bfdec6aa..9b70125aa 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBase.java
@@ -13,33 +13,55 @@ import java.util.List;
import org.eclipse.etrice.runtime.java.messaging.AbstractMessageReceiver;
import org.eclipse.etrice.runtime.java.messaging.Address;
import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver;
+import org.eclipse.etrice.runtime.java.messaging.IMessageService;
import org.eclipse.etrice.runtime.java.messaging.IRTObject;
import org.eclipse.etrice.runtime.java.messaging.MessageService;
import org.eclipse.etrice.runtime.java.messaging.RTServices;
/**
- * The abstract base class for actor class interface items like ports and saps.
+ * The abstract base class for actor class interface items like {@link PortBase}
+ * and {@link InterfaceItemBroker}s.
*
* @author Henrik Rentz-Reichert
- *
*/
public abstract class InterfaceItemBase extends AbstractMessageReceiver {
- private IMessageReceiver ownMsgReceiver;
- private IMessageReceiver peerMsgReceiver;
+ /**
+ * If this is part of an {@link IReplicatedInterfaceItem} then the
+ * owner of this item is stored in this field.
+ * It is used for sub ports of a replicated ports. When of of this is
+ * disconnected then it is also removed from its parent and destroyed.
+ */
+ private IReplicatedInterfaceItem replicator = null;
+
+ protected IMessageReceiver ownMsgReceiver;
+ protected IMessageReceiver peerMsgReceiver;
private int localId;
private int idx;
- private Address peerAddress = null;
+ protected Address peerAddress = null;
+ private InterfaceItemBase peer;
+
- public InterfaceItemBase (IEventReceiver actor, String name, int localId, int idx) {
- super(actor, name);
+ /**
+ * The constructor determines the thread of its {@link IEventReceiver}
+ *
+ * @param owner
+ * @param name
+ * @param localId
+ * @param idx
+ */
+ public InterfaceItemBase (IInterfaceItemOwner owner, String name, int localId, int idx) {
+ super(owner.getEventReceiver(), name);
this.localId = localId;
this.idx = idx;
- int thread = RTServices.getInstance().getMsgSvcCtrl().getThreadForPath(getParent().getInstancePath());
+ if (owner instanceof IReplicatedInterfaceItem)
+ replicator = (IReplicatedInterfaceItem) owner;
+
+ int thread = owner.getEventReceiver().getThread();
if (thread>=0) {
- MessageService msgSvc = RTServices.getInstance().getMsgSvcCtrl().getMsgSvc(thread);
+ IMessageService msgSvc = RTServices.getInstance().getMsgSvcCtrl().getMsgSvc(thread);
Address addr = msgSvc.getFreeAddress();
setAddress(addr);
@@ -52,7 +74,7 @@ public abstract class InterfaceItemBase extends AbstractMessageReceiver {
}
}
- List<String> peerPaths = RTServices.getInstance().getMsgSvcCtrl().getPeersForPath(getInstancePath());
+ List<String> peerPaths = getParent().getPeersForPath(getInstancePath());
if (peerPaths!=null && !peerPaths.isEmpty()) {
IRTObject object = getObject(peerPaths.get(0));
InterfaceItemBase peer = null;
@@ -67,8 +89,15 @@ public abstract class InterfaceItemBase extends AbstractMessageReceiver {
}
- protected void connectWith(InterfaceItemBase peer) {
+ protected synchronized void connectWith(InterfaceItemBase peer) {
if (peer!=null) {
+ this.peer = peer;
+
+ if (peer instanceof IInterfaceItemBroker) {
+ peer.connectWith(this);
+ return;
+ }
+
// connect with each other
peerAddress = peer.getAddress();
peer.peerAddress = getAddress();
@@ -76,12 +105,32 @@ public abstract class InterfaceItemBase extends AbstractMessageReceiver {
peer.peerMsgReceiver = ownMsgReceiver;
}
}
+
+ protected synchronized void disconnect() {
+ disconnectInternal();
+ if (peer!=null) {
+ peer.disconnectInternal();
+ peer = null;
+ }
+ }
+ private void disconnectInternal() {
+ peerAddress = null;
+ peerMsgReceiver = null;
+
+ if (replicator!=null)
+ destroy();
+ }
+
protected IMessageReceiver getMsgReceiver() {
return ownMsgReceiver;
}
- protected IMessageReceiver getPeerMsgReceiver() {
+ protected synchronized Address getPeerAddress() {
+ return peerAddress;
+ }
+
+ protected synchronized IMessageReceiver getPeerMsgReceiver() {
return peerMsgReceiver;
}
@@ -100,8 +149,31 @@ public abstract class InterfaceItemBase extends AbstractMessageReceiver {
public int getIdx() {
return idx;
}
-
- protected Address getPeerAddress() {
- return peerAddress;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.runtime.java.messaging.RTObject#destroy()
+ */
+ @Override
+ protected void destroy() {
+ if (peerAddress!=null) {
+ disconnect();
+ }
+
+ if (replicator!=null) {
+ replicator.removeItem(this);
+ }
+
+ if (this.ownMsgReceiver instanceof MessageService) {
+ MessageService ms = (MessageService) this.ownMsgReceiver;
+ ms.getMessageDispatcher().removeMessageReceiver(this);
+ ms.freeAddress(getAddress());
+ }
+
+ super.destroy();
+ }
+
+ @Override
+ public String toString() {
+ return "port "+getName()+" "+getAddress()+" <-> "+getPeerAddress();
}
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBroker.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBroker.java
new file mode 100644
index 000000000..ae2771a14
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBroker.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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 org.eclipse.etrice.runtime.java.messaging.Message;
+
+/**
+ * The purpose of this class is to mediate the connection of two end ports which
+ * are separated by an {@link OptionalActorInterfaceBase}.
+ * The first peer that will connect is that one from the 'outside'.
+ * As soon as the second (somewhere in the dynamically created sub tree)
+ * will connect, the two peers will be connected with each other.
+ *
+ * <p>
+ * <b>Assumption</b>: The first (outside) peer will stay fixed.<br/>
+ *
+ * When the second (dynamic)
+ * peer will disconnect from its peer (the outside one) then nothing happens.
+ * When a new dynamic peer is instantiated then it again contacts this broker
+ * an it will be connected to the {@link #firstPeer} of this broker.
+ * </p>
+ *
+ * @author Henrik Rentz-Reichert
+ */
+public class InterfaceItemBroker extends InterfaceItemBase implements IInterfaceItemBroker {
+
+ private InterfaceItemBase firstPeer;
+
+ public InterfaceItemBroker(IInterfaceItemOwner parent, String name, int localId) {
+ this(parent, name, localId, 0);
+ }
+
+ /**
+ * @param actor
+ * @param name
+ * @param localId
+ * @param idx
+ */
+ public InterfaceItemBroker(IInterfaceItemOwner parent, String name, int localId, int idx) {
+ super(parent, name, localId, idx);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.runtime.java.messaging.IMessageReceiver#receive(org.eclipse.etrice.runtime.java.messaging.Message)
+ */
+ @Override
+ public void receive(Message msg) {
+ // ignore this, will never receive a message
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase#connectWith(org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase)
+ */
+ @Override
+ public void connectWith(InterfaceItemBase peer) {
+ if (firstPeer==null) {
+ firstPeer = peer;
+ super.connectWith(peer);
+ }
+ else {
+ // we are already connected, lets connect our new peer with the previous one
+
+ InterfaceItemBase peer1 = firstPeer;
+ InterfaceItemBase peer2 = peer;
+
+ // get a new replicated sub port if appropriate
+ if (peer1 instanceof IReplicatedInterfaceItem) {
+ peer1 = ((IReplicatedInterfaceItem) peer1).createSubInterfaceItem();
+ }
+ if (peer2 instanceof IReplicatedInterfaceItem) {
+ peer2 = ((IReplicatedInterfaceItem) peer2).createSubInterfaceItem();
+ }
+
+ peer2.peerAddress = peer1.getAddress();
+ peer2.peerMsgReceiver = peer1.ownMsgReceiver;
+ peer1.peerAddress = peer2.getAddress();
+ peer1.peerMsgReceiver = peer2.ownMsgReceiver;
+ }
+ }
+}
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
new file mode 100644
index 000000000..8072c0a1f
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/OptionalActorInterfaceBase.java
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * 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.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.etrice.runtime.java.messaging.IRTObject;
+import org.eclipse.etrice.runtime.java.modelbase.RTSystemProtocol.RTSystemConjPort;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public abstract class OptionalActorInterfaceBase extends SystemPortOwner implements IEventReceiver {
+
+ protected static final int IFITEM_RTSystemPort = 0;
+
+ private String className;
+ private PathToPeers path2peers = null;
+ private String ownPath;
+ private int subtreeThread;
+
+ private RTSystemConjPort RTSystemPort = null;
+
+ /**
+ * @param parent
+ * @param name
+ */
+ protected OptionalActorInterfaceBase(IEventReceiver parent, String name, String clsname) {
+ super(parent, name);
+ className = clsname;
+ subtreeThread = parent.getThread();
+ setOwnPath(getInstancePath()+IRTObject.PATH_DELIM+getName());
+
+ RTSystemPort = new RTSystemConjPort(this, IFITEM_RTSystemPort);
+ }
+
+ /**
+ * Get list of peer paths
+ *
+ * @param path
+ * @return list of peer paths or {@code null} if not mapped
+ */
+ public List<String> getPeersForPath(String path) {
+ if (getPath2peers()==null)
+ return getParent().getPeersForPath(path);
+
+ path = path.substring(getOwnPath().length()+getName().length()+1);
+// if (path.indexOf('/', 1)>=0)
+// path = path.substring(getName().length()+1);
+ ArrayList<String> paths = getPath2peers().get(path);
+ if (paths!=null) {
+ ArrayList<String> result = new ArrayList<String>();
+ for (String p : paths) {
+ if (p.indexOf('/', 1)>=0)
+ p = IRTObject.PATH_DELIM+getName()+IRTObject.PATH_DELIM+getName()+p;
+ p = getOwnPath()+p;
+ result.add(p);
+ }
+ return result;
+ }
+ return paths;
+ }
+
+ /**
+ * get thread for path
+ * @param path
+ * @return thread id or {@code -1} if not mapped
+ */
+ public int getThreadForPath(String path) {
+ return subtreeThread;
+ }
+
+ public void setPath2peers(PathToPeers path2peers) {
+ this.path2peers = path2peers;
+ }
+
+ /**
+ * @return the path2peers
+ */
+ protected PathToPeers getPath2peers() {
+ return path2peers;
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ @Override
+ public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data) {
+ // nothing to do, never called
+ }
+
+ /**
+ * @return the ownPath
+ */
+ public String getOwnPath() {
+ return ownPath;
+ }
+
+ /**
+ * @param ownPath the ownPath to set
+ */
+ public void setOwnPath(String ownPath) {
+ this.ownPath = ownPath;
+ }
+
+ protected int getSubtreeThread() {
+ return subtreeThread;
+ }
+
+ protected void setSubtreeThread(int subtreeThread) {
+ this.subtreeThread = subtreeThread;
+ }
+
+ protected void startSubTree() {
+ RTSystemPort.executeInitialTransition();
+ }
+
+ @Override
+ public IReplicatedInterfaceItem getSystemPort() {
+ return RTSystemPort;
+ }
+}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PathToPeers.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PathToPeers.java
new file mode 100644
index 000000000..0007b34ca
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PathToPeers.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class PathToPeers extends HashMap<String, ArrayList<String>> {
+
+ private static final long serialVersionUID = 1L;
+
+ public void put(String key, String value) {
+ ArrayList<String> list = get(key);
+ if (list==null) {
+ list = new ArrayList<String>();
+ put(key, list);
+ }
+ list.add(value);
+ }
+
+ public void put(String key, Collection<String> values) {
+ ArrayList<String> list = get(key);
+ if (list==null) {
+ list = new ArrayList<String>(values);
+ put(key, list);
+ }
+ else
+ list.addAll(values);
+ }
+
+ public void put(String key, String[] values) {
+ List<String> list = Arrays.asList(values);
+ put(key, list);
+ }
+
+} \ No newline at end of file
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PathToThread.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PathToThread.java
new file mode 100644
index 000000000..a71fadd40
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PathToThread.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.util.HashMap;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class PathToThread extends HashMap<String, Integer> {
+
+ private static final long serialVersionUID = 1L;
+} \ No newline at end of file
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PortBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PortBase.java
index 2c0997034..90e13b9a9 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PortBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PortBase.java
@@ -9,6 +9,7 @@
package org.eclipse.etrice.runtime.java.modelbase;
+
/**
* An abstract base class for port instances.
*
@@ -17,11 +18,11 @@ package org.eclipse.etrice.runtime.java.modelbase;
*/
public abstract class PortBase extends InterfaceItemBase {
- public PortBase (IEventReceiver actor, String name, int localId){
+ public PortBase (IInterfaceItemOwner actor, String name, int localId){
super(actor, name, localId, 0);
}
- public PortBase (IEventReceiver actor, String name, int localId, int idx){
+ public PortBase (IInterfaceItemOwner actor, String name, int localId, int idx){
super(actor, name, localId, idx);
}
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/RTSystemProtocol.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/RTSystemProtocol.java
index e54ef6e27..d26b402c2 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/RTSystemProtocol.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/RTSystemProtocol.java
@@ -12,7 +12,6 @@
package org.eclipse.etrice.runtime.java.modelbase;
-import org.eclipse.etrice.runtime.java.messaging.IRTObject;
import org.eclipse.etrice.runtime.java.modelbase.RTSystemServicesProtocol.RTSystemServicesProtocolConjReplPort;
import org.eclipse.etrice.runtime.java.modelbase.RTSystemServicesProtocol.RTSystemServicesProtocolPort;
@@ -26,25 +25,27 @@ public class RTSystemProtocol {
public static class RTSystemPort extends RTSystemServicesProtocolPort {
- public RTSystemPort(IEventReceiver actor, int localId) {
+ public RTSystemPort(IInterfaceItemOwner actor, int localId) {
super(actor, RT_SYSTEM_PORT_NAME, localId);
// since we have no mapping for the system ports we connect them directly here
- IRTObject root = getRoot();
- if (root instanceof RTSystem)
- root = root.getChildren().get(0);
- IRTObject sysport = root.getChild(RT_SYSTEM_PORT_NAME);
- if (sysport!=null) {
- InterfaceItemBase peer = ((IReplicatedInterfaceItem) sysport).createSubInterfaceItem();
+ IReplicatedInterfaceItem systemPort = actor.getSystemPort();
+ if (systemPort!=null) {
+ InterfaceItemBase peer = systemPort.createSubInterfaceItem();
connectWith(peer);
}
}
+
+ @Override
+ protected void destroy() {
+ super.destroy();
+ }
}
public static class RTSystemConjPort extends RTSystemServicesProtocolConjReplPort {
- public RTSystemConjPort(IEventReceiver actor, int localId) {
+ public RTSystemConjPort(IInterfaceItemOwner actor, int localId) {
super(actor, RT_SYSTEM_PORT_NAME, localId);
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedInterfaceItemBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedInterfaceItemBase.java
index 9732d7a6c..0e631647d 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedInterfaceItemBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedInterfaceItemBase.java
@@ -13,32 +13,33 @@
package org.eclipse.etrice.runtime.java.modelbase;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import org.eclipse.etrice.runtime.java.messaging.IRTObject;
import org.eclipse.etrice.runtime.java.messaging.RTObject;
-import org.eclipse.etrice.runtime.java.messaging.RTServices;
/**
* @author Henrik Rentz-Reichert
*
*/
-public abstract class ReplicatedInterfaceItemBase extends RTObject implements IReplicatedInterfaceItem {
+public abstract class ReplicatedInterfaceItemBase extends RTObject implements IReplicatedInterfaceItem, IInterfaceItemOwner {
private int localId;
private ArrayList<InterfaceItemBase> items = new ArrayList<InterfaceItemBase>();
+ private LinkedList<Integer> releasedIndices = new LinkedList<Integer>();
/**
- * @param parent
+ * @param owner
* @param name
* @param localId
*/
- protected ReplicatedInterfaceItemBase(IEventReceiver parent, String name, int localId) {
- super(parent, name);
+ protected ReplicatedInterfaceItemBase(IInterfaceItemOwner owner, String name, int localId) {
+ super(owner, name);
this.localId = localId;
- List<String> peerPaths = RTServices.getInstance().getMsgSvcCtrl().getPeersForPath(getInstancePath());
+ List<String> peerPaths = getParent().getPeersForPath(getInstancePath());
if (peerPaths!=null) {
for (String path : peerPaths) {
IRTObject object = getObject(path);
@@ -62,14 +63,29 @@ public abstract class ReplicatedInterfaceItemBase extends RTObject implements IR
*/
@Override
public InterfaceItemBase createSubInterfaceItem() {
- InterfaceItemBase item = createInterfaceItem((IEventReceiver)getParent(), getName()+items.size(), localId, items.size());
+ InterfaceItemBase item = createInterfaceItem(this, getName()+items.size(), localId, getFreeIndex());
items.add(item);
return item;
}
+ public void removeItem(InterfaceItemBase item) {
+ assert(item.getParent()==this): "is own child";
+ releasedIndices.push(item.getIdx());
+ items.remove(item);
+ }
+
+ private int getFreeIndex() {
+ if (releasedIndices.isEmpty())
+ return items.size();
+ else
+ return releasedIndices.pop();
+ }
+
public InterfaceItemBase getInterfaceItem(int idx) {
- if (0<=idx && idx<items.size())
- return items.get(idx);
+ for (InterfaceItemBase item : items) {
+ if (item.getIdx()==idx)
+ return item;
+ }
return null;
}
@@ -82,5 +98,19 @@ public abstract class ReplicatedInterfaceItemBase extends RTObject implements IR
return localId;
}
- protected abstract InterfaceItemBase createInterfaceItem(IEventReceiver rcv, String name, int lid, int idx);
+ @Override
+ public IEventReceiver getEventReceiver() {
+ return (IEventReceiver) getParent();
+ }
+
+ @Override
+ public IReplicatedInterfaceItem getSystemPort() {
+ return ((IInterfaceItemOwner)getParent()).getSystemPort();
+ }
+
+ protected ArrayList<InterfaceItemBase> getItems() {
+ return items;
+ }
+
+ protected abstract InterfaceItemBase createInterfaceItem(IInterfaceItemOwner rcv, String name, int lid, int idx);
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedInterfaceItemBroker.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedInterfaceItemBroker.java
new file mode 100644
index 000000000..15a7e4591
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedInterfaceItemBroker.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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;
+
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class ReplicatedInterfaceItemBroker extends ReplicatedInterfaceItemBase {
+
+ /**
+ * @param parent
+ * @param name
+ * @param localId
+ */
+ public ReplicatedInterfaceItemBroker(IInterfaceItemOwner parent, String name, int localId) {
+ super(parent, name, localId);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.runtime.java.modelbase.ReplicatedInterfaceItemBase#createInterfaceItem(org.eclipse.etrice.runtime.java.messaging.IRTObject, java.lang.String, int, int)
+ */
+ @Override
+ protected InterfaceItemBase createInterfaceItem(IInterfaceItemOwner rcv, String name, int lid, int idx) {
+ return new InterfaceItemBroker(this, name, lid, idx);
+ }
+}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedOptionalActorInterfaceBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedOptionalActorInterfaceBase.java
new file mode 100644
index 000000000..828a336c8
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedOptionalActorInterfaceBase.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * 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.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.etrice.runtime.java.messaging.IRTObject;
+import org.eclipse.etrice.runtime.java.messaging.RTServices;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class ReplicatedOptionalActorInterfaceBase extends OptionalActorInterfaceBase {
+
+ private static final char INDEX_SEP = ':';
+ private LinkedList<Integer> releasedIndices = new LinkedList<Integer>();
+ private ArrayList<ActorClassBase> actors = new ArrayList<ActorClassBase>();
+
+ /**
+ * @param parent
+ * @param name
+ * @param clsname
+ */
+ public ReplicatedOptionalActorInterfaceBase(IEventReceiver parent, String name, String clsname) {
+ super(parent, name, clsname);
+ }
+
+ public int createOptionalActor(String actorClass, int thread) {
+ setSubtreeThread(thread);
+
+ // make sure the path is up to date
+ setOwnPath(getInstancePath());
+
+ IOptionalActorFactory factory = RTServices.getInstance().getSubSystem().getFactory(getClassName(), actorClass);
+ if (factory==null)
+ return -1;
+
+ // the factory will set our path2peers map
+ int index = getFreeIndex();
+ String name = getChildName(index);
+ ActorClassBase actor = factory.create(this, name);
+ if (actor==null)
+ return -1;
+
+ actors.add(actor);
+
+ startSubTree();
+
+ return index;
+ }
+
+ /**
+ * @param idx
+ * @return
+ */
+ public boolean destroyOptionalActor(int idx) {
+ IRTObject child = getChild(getChildName(idx));
+ if (!(child instanceof ActorClassBase))
+ return false;
+
+ ((ActorClassBase)child).destroy();
+ releasedIndices.push(idx);
+ actors.remove(child);
+
+ return true;
+ }
+
+ public void destroyAllOptionalActors() {
+ for (ActorClassBase actor : actors) {
+ actor.destroy();
+ int idx = Integer.parseInt(actor.getName().substring(getName().length()));
+ releasedIndices.push(idx);
+ }
+ actors.clear();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.runtime.java.modelbase.OptionalActorInterfaceBase#getPeersForPath(java.lang.String)
+ */
+ @Override
+ public List<String> getPeersForPath(String path) {
+// if (getPath2peers()==null)
+// return null;
+//
+// path = path.substring(getOwnPath().length(), path.lastIndexOf(INDEX_SEP));
+// return getPath2peers().get(path);
+ return super.getPeersForPath(path);
+ }
+
+ public String getChildName(int idx) {
+ return getName()+INDEX_SEP+idx;
+ }
+
+ private int getFreeIndex() {
+ if (releasedIndices.isEmpty())
+ return actors.size();
+ else
+ return releasedIndices.pop();
+ }
+
+ public String toString(){
+ return "ReplicatedOptionalActorInterface(className="+getClassName()+", instancePath="+getInstancePath()+")";
+ }
+
+}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedPortBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedPortBase.java
index e511717ff..deb7d4f5d 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedPortBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ReplicatedPortBase.java
@@ -12,6 +12,7 @@
package org.eclipse.etrice.runtime.java.modelbase;
+
/**
* An abstract base class for instances of replicated ports.
*
@@ -25,7 +26,7 @@ public abstract class ReplicatedPortBase extends ReplicatedInterfaceItemBase {
* @param name
* @param localId
*/
- public ReplicatedPortBase(IEventReceiver parent, String name, int localId) {
+ public ReplicatedPortBase(IInterfaceItemOwner parent, String name, int localId) {
super(parent, name, localId);
}
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
new file mode 100644
index 000000000..325780159
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ScalarOptionalActorInterfaceBase.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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 org.eclipse.etrice.runtime.java.messaging.RTServices;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class ScalarOptionalActorInterfaceBase extends OptionalActorInterfaceBase {
+
+ private ActorClassBase actor = null;
+
+ /**
+ * @param parent
+ * @param name
+ * @param clsname
+ */
+ public ScalarOptionalActorInterfaceBase(IEventReceiver parent, String name, String clsname) {
+ super(parent, name, clsname);
+ }
+
+ public boolean createOptionalActor(String actorClass, int thread) {
+ if (actor!=null)
+ return false;
+
+ setSubtreeThread(thread);
+
+ // make sure the path is up to date
+ setOwnPath(getInstancePath());
+
+ // SubSystemClass.createOptionalActor() will set our PathTo* maps
+ IOptionalActorFactory factory = RTServices.getInstance().getSubSystem().getFactory(getClassName(), actorClass);
+ if (factory==null)
+ return false;
+
+ // the factory will set our path2peers map
+ actor = factory.create(this, getName());
+
+ startSubTree();
+
+ return actor!=null;
+ }
+
+ /**
+ * @param idx
+ * @return
+ */
+ public boolean destroyOptionalActor() {
+ if (actor==null)
+ return false;
+
+ actor.destroy();
+ actor = null;
+
+ return true;
+ }
+
+ public String toString(){
+ return "ScalarOptionalActorInterface(className="+getClassName()+", instancePath="+getInstancePath()+")";
+ }
+
+}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SubSystemClassBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SubSystemClassBase.java
index 3219c7fda..498f6732e 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SubSystemClassBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SubSystemClassBase.java
@@ -8,11 +8,14 @@
package org.eclipse.etrice.runtime.java.modelbase;
+import java.util.Collection;
+import java.util.List;
+
import org.eclipse.etrice.runtime.java.config.IVariableService;
import org.eclipse.etrice.runtime.java.debugging.DebuggingService;
import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.IMessageService;
import org.eclipse.etrice.runtime.java.messaging.IRTObject;
-import org.eclipse.etrice.runtime.java.messaging.MessageService;
import org.eclipse.etrice.runtime.java.messaging.RTObject;
import org.eclipse.etrice.runtime.java.messaging.RTServices;
import org.eclipse.etrice.runtime.java.modelbase.RTSystemProtocol.RTSystemConjPort;
@@ -24,7 +27,7 @@ import org.eclipse.etrice.runtime.java.modelbase.RTSystemProtocol.RTSystemConjPo
* @author Henrik Rentz-Reichert
*
*/
-public abstract class SubSystemClassBase extends RTObject implements IEventReceiver{
+public abstract class SubSystemClassBase extends RTObject implements IEventReceiver, IInterfaceItemOwner {
// variable service (is only instantiated if needed)
protected IVariableService variableService = null;
@@ -35,6 +38,9 @@ public abstract class SubSystemClassBase extends RTObject implements IEventRecei
//--------------------- interface item IDs
protected static final int IFITEM_RTSystemPort = 0;
+ private PathToThread path2thread = new PathToThread();
+ private PathToPeers path2peers = new PathToPeers();
+
// for tests only
private TestSemaphore terminateSem=null;
private int terminateCode;
@@ -105,10 +111,7 @@ public abstract class SubSystemClassBase extends RTObject implements IEventRecei
public void destroy() {
System.out.println("*** MainComponent "+getInstancePath()+"::destroy ***");
- for (IRTObject child : getChildren()) {
- if (child instanceof ActorClassBase)
- ((ActorClassBase) child).destroy();
- }
+ super.destroy();
System.out.println("=== done destroy actor instances");
DebuggingService.getInstance().getAsyncLogger().close();
@@ -116,10 +119,10 @@ public abstract class SubSystemClassBase extends RTObject implements IEventRecei
System.out.println("=== done close loggers");
RTServices.getInstance().destroy();
- System.out.println("=== done destroy RTServices");
+ System.out.println("=== done destroy RTServices\n\n\n");
}
- public MessageService getMsgService(int idx) {
+ public IMessageService getMsgService(int idx) {
return RTServices.getInstance().getMsgSvcCtrl().getMsgSvc(idx);
}
@@ -163,4 +166,93 @@ public abstract class SubSystemClassBase extends RTObject implements IEventRecei
public IVariableService getVariableService() {
return variableService;
}
+
+ /**
+ * map a path to a thread id
+ * @param path
+ * @param thread
+ */
+ public void addPathToThread(String path, int thread) {
+ path2thread.put(path, thread);
+ }
+
+ /**
+ * get thread for path
+ * @param path
+ * @return
+ */
+ public int getThreadForPath(String path) {
+ Integer thread = path2thread.get(path);
+ if (thread==null)
+ return -1;
+
+ return thread;
+ }
+
+ /**
+ * add a peer for the given path
+ * @param path
+ * @param peer
+ */
+ public void addPathToPeer(String path, String peer) {
+ path2peers.put(path, peer);
+ }
+
+ /**
+ * add a collection of peers to the given path
+ * @param path
+ * @param peers
+ */
+ public void addPathToPeers(String path, Collection<String> peers) {
+ path2peers.put(path, peers);
+ }
+
+ /**
+ * add several peers to the given path
+ * @param path
+ * @param peers
+ */
+ public void addPathToPeers(String path, String... peers) {
+ path2peers.put(path, peers);
+ }
+
+ /**
+ * @param path
+ * @return list of peer paths
+ */
+ public List<String> getPeersForPath(String path) {
+ return path2peers.get(path);
+ }
+
+ /**
+ * Clears thread and peer mappings.
+ */
+ public void resetAll() {
+ path2peers.clear();
+ path2thread.clear();
+ }
+ /**
+ * @param optionalActorClass
+ * @param instanceActorClass
+ * @return
+ */
+ abstract public IOptionalActorFactory getFactory(String optionalActorClass, String instanceActorClass);
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.runtime.java.modelbase.IInterfaceItemOwner#getEventReceiver()
+ */
+ @Override
+ public IEventReceiver getEventReceiver() {
+ return this;
+ }
+
+ @Override
+ public int getThread() {
+ return 0;
+ }
+
+ @Override
+ public IReplicatedInterfaceItem getSystemPort() {
+ return RTSystemPort;
+ }
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SystemPortOwner.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SystemPortOwner.java
new file mode 100644
index 000000000..6c9a0e1c1
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SystemPortOwner.java
@@ -0,0 +1,33 @@
+/**
+ *
+ */
+package org.eclipse.etrice.runtime.java.modelbase;
+
+import org.eclipse.etrice.runtime.java.messaging.IRTObject;
+
+/**
+ * @author hrentz
+ *
+ */
+public abstract class SystemPortOwner extends EventReceiver implements IInterfaceItemOwner {
+
+ /**
+ * @param parent
+ * @param name
+ */
+ public SystemPortOwner(IRTObject parent, String name) {
+ super(parent, name);
+ }
+
+ public IEventReceiver getEventReceiver() {
+ return this;
+ }
+
+ @Override
+ public IReplicatedInterfaceItem getSystemPort() {
+ if (getParent() instanceof IInterfaceItemOwner)
+ return ((IInterfaceItemOwner)getParent()).getSystemPort();
+
+ return null;
+ }
+}

Back to the top