Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java')
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java109
1 files changed, 101 insertions, 8 deletions
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 8f8509e5f..35acd3f3f 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,6 +13,9 @@
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;
@@ -27,16 +30,47 @@ import java.util.Map;
public class MessageServiceController {
- private List<IMessageService> messageServiceList = null;
+ @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 boolean running = false;
public MessageServiceController(/*IRTObject parent*/){
// TODOTS: Who is parent of MessageServices and Controller?
// this.parent = parent;
- messageServiceList = new ArrayList<IMessageService>();
+ messageServiceList = new ArrayList<MessageService>();
}
- public void addMsgSvc(IMessageService msgSvc){
+ public void addMsgSvc(MessageService msgSvc){
// TODOTS: Who is parent of MessageServices ?
assert(msgSvc.getAddress().threadID == messageServiceList.size());
messageServiceList.add(msgSvc);
@@ -46,14 +80,14 @@ public class MessageServiceController {
return messageServiceList.size();
}
- public IMessageService getMsgSvc(int threadID){
+ public MessageService getMsgSvc(int threadID){
assert(threadID < messageServiceList.size());
return messageServiceList.get(threadID);
}
public void start() {
// start all message services
- for (IMessageService msgSvc : messageServiceList){
+ for (MessageService msgSvc : messageServiceList){
Thread thread = new Thread(msgSvc, msgSvc.getName());
msgSvc.setThread(thread);
thread.start();
@@ -96,7 +130,7 @@ public class MessageServiceController {
private void terminate() {
// terminate all message services
- for (IMessageService msgSvc : messageServiceList){
+ for (MessageService msgSvc : messageServiceList){
msgSvc.terminate();
// TODOTS: stop in order of priorities
}
@@ -107,7 +141,7 @@ public class MessageServiceController {
* ! not threadsafe !
*/
public void waitTerminate() {
- for (IMessageService msgSvc : messageServiceList) {
+ for (MessageService msgSvc : messageServiceList) {
try {
msgSvc.getThread().join(1000); // wait at most 1000ms
if (msgSvc.getThread().isAlive())
@@ -119,8 +153,67 @@ 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();
+ }
}

Back to the top