summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-02-23 17:10:45 (EST)
committer Henrik Rentz-Reichert2011-02-23 17:10:45 (EST)
commitc5e939ebca6576a089a4d3c8101f61fd7553371c (patch)
tree0eb9c803244e79b691eb351ad4d828bab6e0e34f
parentf2c3d8e1319515d3ab14323a15cb75df7af28c16 (diff)
downloadorg.eclipse.etrice-c5e939ebca6576a089a4d3c8101f61fd7553371c.zip
org.eclipse.etrice-c5e939ebca6576a089a4d3c8101f61fd7553371c.tar.gz
org.eclipse.etrice-c5e939ebca6576a089a4d3c8101f61fd7553371c.tar.bz2
applied patch 2 of
https://bugs.eclipse.org/bugs/show_bug.cgi?id=337075 Thanks for the contribution!
-rw-r--r--modellib/org.eclipse.etrice.modellib/models/TimingService.room158
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt12
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt16
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt19
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageDispatcher.java4
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java4
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java192
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTServices.java84
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java12
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBase.java24
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/PortBase.java4
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SubSystemClassBase.java18
-rw-r--r--tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestFSMGenerator.java2
-rw-r--r--tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/PortBaseTest.java2
14 files changed, 292 insertions, 259 deletions
diff --git a/modellib/org.eclipse.etrice.modellib/models/TimingService.room b/modellib/org.eclipse.etrice.modellib/models/TimingService.room
index 2de1bf0..a7f4d5b 100644
--- a/modellib/org.eclipse.etrice.modellib/models/TimingService.room
+++ b/modellib/org.eclipse.etrice.modellib/models/TimingService.room
@@ -1,6 +1,71 @@
-RoomModel room.basic.service.timing {
-
- ProtocolClass PTimer {
+RoomModel room.basic.service.timing { ActorClass ATimingService {
+ Interface {
+ SPP timer: PTimer
+ SPP timeout: PTimeout
+ }
+ Structure {
+ usercode1 {
+ "import java.util.Timer;"
+ }
+ usercode2 {
+ "private Timer timerService = null;"
+ "private int taskCount = 0;"
+ "private static final int PURGE_LIMIT = 1000;"
+ }
+ ServiceImplementation of timer
+ ServiceImplementation of timeout
+ }
+ Behavior {
+ Operation stop() {
+ "System.out.println(toString() + \"::stop()\");"
+ "timerService.cancel();"
+ "timerService = null;"
+ }
+ StateMachine { Transition tr0: initial -> Operational {
+ action {
+ "timerService = new Timer();"
+ }
+ }
+ Transition tr1: Operational -> Operational {
+ triggers {
+ <Start:timeout>
+ }
+ action {
+ "// start timeout"
+ "taskCount++;"
+ "if (taskCount>PURGE_LIMIT) timerService.purge();"
+ "timerService.schedule(((PTimeoutPort)ifitem).getTask(), time_ms);"
+ }
+ }
+ Transition tr2: Operational -> Operational {
+ triggers {
+ <Kill:timeout>
+ }
+ // nothing to do to kill timeout (handled by timerService)
+ }
+ Transition tr3: Operational -> Operational {
+ triggers {
+ <Start:timer>
+ }
+ action {
+ "// start timer"
+ "taskCount++;"
+ "if (taskCount>PURGE_LIMIT) timerService.purge();"
+ "timerService.scheduleAtFixedRate(((PTimerPort)ifitem).getTask(), time_ms, time_ms);"
+ }
+ }
+ Transition tr4: Operational -> Operational {
+ triggers {
+ <Kill:timer>
+ }
+ // nothing to do to kill timer (handled by timer)
+ } State Operational {
+ entry {
+ "// prepare"
+ }
+ }}
+ }
+ }ProtocolClass PTimer {
usercode1 {
"import java.util.TimerTask;"
}
@@ -73,7 +138,7 @@ RoomModel room.basic.service.timing {
DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
getPeerAddress(), messageStrings[OUT_timerTick]);
- getMsgReceiver().receive(
+ getPeerMsgReceiver().receive(
new EventWithDataMessage(getPeerAddress(), OUT_timerTick, id));"
}
}
@@ -100,7 +165,7 @@ RoomModel room.basic.service.timing {
DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
getPeerAddress(), messageStrings[IN_Start]);
- getMsgReceiver()
+ getPeerMsgReceiver()
.receive(
new EventWithDataMessage(getPeerAddress(),
IN_Start, new TimerData(time_ms, ++currentId)));"
@@ -112,7 +177,7 @@ RoomModel room.basic.service.timing {
if (active) {
active = false;
- getMsgReceiver().receive(
+ getPeerMsgReceiver().receive(
new EventWithDataMessage(getPeerAddress(), IN_Kill, currentId));
}"
}
@@ -192,7 +257,7 @@ RoomModel room.basic.service.timing {
DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
getPeerAddress(), messageStrings[OUT_timeoutTick]);
- getMsgReceiver().receive(
+ getPeerMsgReceiver().receive(
new EventWithDataMessage(getPeerAddress(), OUT_timeoutTick, id));"
}
}
@@ -220,7 +285,7 @@ RoomModel room.basic.service.timing {
DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
getPeerAddress(), messageStrings[IN_Start]);
- getMsgReceiver()
+ getPeerMsgReceiver()
.receive(
new EventWithDataMessage(getPeerAddress(),
IN_Start, new TimeoutData(time_ms, ++currentId)));"
@@ -232,82 +297,9 @@ RoomModel room.basic.service.timing {
if (active) {
active = false;
- getMsgReceiver().receive(
+ getPeerMsgReceiver().receive(
new EventWithDataMessage(getPeerAddress(), IN_Kill, new Integer(currentId)));
}"
}
}
- }
-
- ActorClass ATimingService {
- Interface {
- SPP timer: PTimer
- SPP timeout: PTimeout
- }
- Structure {
- usercode1 {
- "import java.util.Timer;"
- }
- usercode2 {
- "private Timer timerService = null;"
- "private int taskCount = 0;"
- "private static final int PURGE_LIMIT = 1000;"
- }
- ServiceImplementation of timer
- ServiceImplementation of timeout
- }
- Behavior {
- Operation stop() {
- "System.out.println(toString() + \"::stop()\");"
- "timerService.cancel();"
- "timerService = null;"
- }
- StateMachine {
- State Operational {
- entry {
- "// prepare"
- }
- }
- Transition tr0: initial -> Operational {
- action {
- "timerService = new Timer();"
- }
- }
- Transition tr1: Operational -> Operational {
- triggers {
- <Start:timeout>
- }
- action {
- "// start timeout"
- "taskCount++;"
- "if (taskCount>PURGE_LIMIT) timerService.purge();"
- "timerService.schedule(((PTimeoutPort)ifitem).getTask(), time_ms);"
- }
- }
- Transition tr2: Operational -> Operational {
- triggers {
- <Kill:timeout>
- }
- // nothing to do to kill timeout (handled by timerService)
- }
- Transition tr3: Operational -> Operational {
- triggers {
- <Start:timer>
- }
- action {
- "// start timer"
- "taskCount++;"
- "if (taskCount>PURGE_LIMIT) timerService.purge();"
- "timerService.scheduleAtFixedRate(((PTimerPort)ifitem).getTask(), time_ms, time_ms);"
- }
- }
- Transition tr4: Operational -> Operational {
- triggers {
- <Kill:timer>
- }
- // nothing to do to kill timer (handled by timer)
- }
- }
- }
- }
-}
+ }} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt
index 5a5248c..9086006 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt
@@ -76,22 +76,22 @@ public «IF ac.abstract»abstract «ENDIF»class «ac.name» extends «IF ac.base!=null
«EXPAND ProcedureHelpers::Operations FOR ac.operations»
//--------------------- construction
- public «ac.name»(IRTObject parent, String name, IMessageReceiver msgsvc, Address[][] port_addr, Address[][] peer_addr){
+ public «ac.name»(IRTObject parent, String name, Address ownAddr, Address[][] port_addr, Address[][] peer_addr){
«IF ac.base==null»
- super(parent, name, msgsvc);
+ super(parent, name, ownAddr);
«ELSE»
- super(parent, name, msgsvc, port_addr, peer_addr);
+ super(parent, name, ownAddr, port_addr, peer_addr);
«ENDIF»
setClassName("«ac.name»");
// own ports«FOREACH ac.getEndPorts() AS ep»
- «ep.name» = new «ep.getPortClassName()»(this, "«ep.name»", IFITEM_«ep.name», «IF ep.multiplicity==1»0, «ENDIF»port_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF», peer_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF», msgsvc);
+ «ep.name» = new «ep.getPortClassName()»(this, "«ep.name»", IFITEM_«ep.name», «IF ep.multiplicity==1»0, «ENDIF»port_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF», peer_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF»);
«ENDFOREACH»
// own saps«FOREACH ac.strSAPs AS sap»
- «sap.name» = new «sap.getPortClassName()»(this, "«sap.name»", IFITEM_«sap.name», 0, port_addr[IFITEM_«sap.name»][0], peer_addr[IFITEM_«sap.name»][0], msgsvc);
+ «sap.name» = new «sap.getPortClassName()»(this, "«sap.name»", IFITEM_«sap.name», 0, port_addr[IFITEM_«sap.name»][0], peer_addr[IFITEM_«sap.name»][0]);
«ENDFOREACH»
// own service implementations«FOREACH ac.serviceImplementations AS svc»
- «svc.spp.name» = new «svc.getPortClassName()»(this, "«svc.spp.name»", IFITEM_«svc.spp.name», port_addr[IFITEM_«svc.spp.name»], peer_addr[IFITEM_«svc.spp.name»], msgsvc);
+ «svc.spp.name» = new «svc.getPortClassName()»(this, "«svc.spp.name»", IFITEM_«svc.spp.name», port_addr[IFITEM_«svc.spp.name»], peer_addr[IFITEM_«svc.spp.name»]);
«ENDFOREACH»
}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt
index 610573a..e29cc35 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt
@@ -87,12 +87,12 @@ static public class «name» extends PortBase {
«ENDIF»
// constructors
- public «name»(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress, IMessageReceiver msgService) {
- super(actor, name, localId, 0, addr, peerAddress, msgService);
+ public «name»(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) {
+ super(actor, name, localId, 0, addr, peerAddress);
DebuggingService.getInstance().addPortInstance(this);
}
- public «name»(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress, IMessageReceiver msgService) {
- super(actor, name, localId, idx, addr, peerAddress, msgService);
+ public «name»(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress) {
+ super(actor, name, localId, idx, addr, peerAddress);
DebuggingService.getInstance().addPortInstance(this);
}
@@ -142,12 +142,12 @@ static public class «name»Repl {
private int replication;
public «name»Repl(IEventReceiver actor, String name, int localId, Address[] addr,
- Address[] peerAddress, IMessageReceiver msgService) {
+ Address[] peerAddress) {
replication = addr.length;
ports = new ArrayList<«this.name».«name»>(replication);
for (int i=0; i<replication; ++i) {
ports.add(new «name»(
- actor, name+i, localId, i, addr[i], peerAddress[i], msgService));
+ actor, name+i, localId, i, addr[i], peerAddress[i]));
}
}
@@ -212,8 +212,8 @@ public interface I«name»{
DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[«dir»_«this.name»]);
}
if (getPeerAddress()!=null)
- «IF this.arguments.isEmpty»getMsgReceiver().receive(new EventMessage(getPeerAddress(), «dir»_«this.name»));
- «ELSE» getMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), «dir»_«this.name», new Object[]{«FOREACH this.arguments AS a SEPARATOR ","» «a.name»«ENDFOREACH»}));
+ «IF this.arguments.isEmpty»getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), «dir»_«this.name»));
+ «ELSE» getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), «dir»_«this.name», new Object[]{«FOREACH this.arguments AS a SEPARATOR ","» «a.name»«ENDFOREACH»}));
«ENDIF»
«ENDIF»
}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt
index 2e8153f..3eb03a2 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt
@@ -27,6 +27,8 @@
«FILE getPath(cc)+cc.name+".java"»
package «getPackage(cc)»;
+import org.eclipse.etrice.runtime.java.messaging.MessageService;
+import org.eclipse.etrice.runtime.java.messaging.RTServices;
import org.eclipse.etrice.runtime.java.messaging.Address;
import org.eclipse.etrice.runtime.java.messaging.IRTObject;
import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;
@@ -44,13 +46,24 @@ public class «comp.name» extends SubSystemClassBase {
}
@Override
+ public void instantiateMessageServices(){
+
+ RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, new Address(0, 0, 0),"MessageService_Main"));
+ «FOREACH comp.subSystemClass.threads AS thread ITERATOR tid»
+ RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, new Address(0, «tid.counter0»+1, 0),"MessageService_«thread.name»"));
+ «ENDFOREACH»
+ }
+
+ @Override
public void instantiateActors(){
// all addresses
«FOREACH comp.allContainedInstances AS ai»
+ // actor instance «ai.path» itself
+ Address addr«ai.path.getPathName()»= new Address(0,«ai.threadId»,«ai.objId»);
// interface items of «ai.path»«FOREACH ai.orderedIfItemInstances AS pi»
- «IF ServiceImplInstance.isInstance(pi) || pi.peers.size>1»«FOREACH pi.peers AS peer ITERATOR i»Address addr«pi.path.getPathName()»_«i.counter0» = new Address(0,0,«pi.objId»+«i.counter0»);
+ «IF ServiceImplInstance.isInstance(pi) || pi.peers.size>1»«FOREACH pi.peers AS peer ITERATOR i»Address addr«pi.path.getPathName()»_«i.counter0» = new Address(0,«pi.threadId»,«pi.objId»+«i.counter0»);
«ENDFOREACH»
- «ELSE»Address addr«pi.path.getPathName()» = new Address(0,0,«pi.objId»);
+ «ELSE»Address addr«pi.path.getPathName()» = new Address(0,«ai.threadId»,«pi.objId»);
«ENDIF»
«ENDFOREACH»
«ENDFOREACH»
@@ -60,7 +73,7 @@ public class «comp.name» extends SubSystemClassBase {
«FOREACH comp.allContainedInstances AS ai»instances[«comp.allContainedInstances.indexOf(ai)»] = new «ai.actorClass.name»(
«IF SubSystemInstance.isInstance(ai.eContainer)»this«ELSE»instances[«comp.allContainedInstances.indexOf(ai.eContainer)»]«ENDIF»,
"«ai.name»",
- getMsgService(),
+ addr«ai.path.getPathName()»,
// own interface item addresses
new Address[][] {«FOREACH ai.orderedIfItemInstances AS pi SEPARATOR ","»{«IF ServiceImplInstance.isInstance(pi) || pi.peers.size>1»«FOREACH pi.peers AS peer ITERATOR i SEPARATOR ","»addr«pi.path.getPathName()»_«i.counter0»«ENDFOREACH»
«ELSE»addr«pi.path.getPathName()»
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 ab3ec7c..5ba4115 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
@@ -38,7 +38,7 @@ public class MessageDispatcher extends RTObject implements IMessageReceiver {
node_map.put(receiver.getAddress().objectID, receiver);
}
else if(receiver.getAddress().threadID != address.threadID){
- thread_map.put(receiver.getAddress().objectID, receiver);
+ thread_map.put(receiver.getAddress().threadID, receiver);
}
else {
local_map.put(receiver.getAddress().objectID, receiver);
@@ -53,7 +53,7 @@ public class MessageDispatcher extends RTObject implements IMessageReceiver {
receiver = node_map.get(msg.getAddress().objectID);
}
else if(msg.getAddress().threadID != address.threadID){
- receiver = thread_map.get(msg.getAddress().objectID);
+ receiver = thread_map.get(msg.getAddress().threadID);
}
else {
// Same node, same thread -> local call Dispatch Map
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 f709f3d..a12463a 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
@@ -38,8 +38,7 @@ public class MessageService extends Thread implements IMessageReceiver,
this.parent = parent;
address = addr;
this.name = name;
- messageDispatcher = new MessageDispatcher(this, new Address(addr.nodeID,
- addr.threadID, addr.objectID + 1), "Dispatcher");
+ messageDispatcher = new MessageDispatcher(this, new Address(addr.nodeID,addr.threadID, addr.objectID + 1), "Dispatcher");
messageQueue = new MessageSeQueue(this, "Queue");
}
@@ -75,6 +74,7 @@ public class MessageService extends Thread implements IMessageReceiver,
}
else {
lastMessageTimestamp = System.currentTimeMillis();
+ //System.out.printf("%i. msgServ %i addr.Thread \n",address.threadID,msg.getAddress().threadID);
messageDispatcher.receive(msg);
}
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 f941cad..20986d0 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
@@ -1,90 +1,102 @@
-/*******************************************************************************
- * Copyright (c) 2011 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:
- * Thomas Schuetz
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.runtime.java.messaging;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * The MessageServiceController controls lifecycle of and access to all MessageServices in one SubSystem
- *
- * @author Thomas Schuetz
- *
- */
-
-public class MessageServiceController {
-
- public MessageServiceController(/*IRTObject parent*/){
- // TODOTS: Who is parent of MessageServices and Controller?
- // this.parent = parent;
- messageServiceList = new ArrayList<MessageService>();
- }
-
- public void addMsgSrv(MessageService msgSrv){
- // TODOTS: Who is parent of MessageServices ?
- assert(msgSrv.getAddress().threadID == messageServiceList.size());
- messageServiceList.add(msgSrv);
- }
-
- public MessageService getMessageService(int threadID){
- assert(threadID < messageServiceList.size());
- return messageServiceList.get(threadID);
- }
-
-
-
- public void start() {
- // start all message services
- for (MessageService msgSrv : messageServiceList){
- msgSrv.start();
- // TODOTS: start in order of priorities
- }
- running = true;
- }
-
- public void stop() {
- terminate();
- waitTerminate();
- }
-
- private void terminate() {
- if (!running){
- return;
- }
- running = false;
-
- // terminate all message services
- for (MessageService msgSrv : messageServiceList){
- msgSrv.terminate();
- // TODOTS: stop in order of priorities
- }
- }
-
- /**
- * waitTerminate waits blocking for all MessageServices to terminate
- * ! not threadsafe !
- */
- public void waitTerminate() {
- for (MessageService msgSrv : messageServiceList){
- try {
- msgSrv.join();
- }
- catch (InterruptedException e1) {
- }
- }
- }
-
- private List<MessageService> messageServiceList = null;
-// private IRTObject parent = null;
- private boolean running = false;
-}
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.messaging;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The MessageServiceController controls lifecycle of and access to all MessageServices in one SubSystem
+ *
+ * @author Thomas Schuetz
+ *
+ */
+
+public class MessageServiceController {
+
+ public MessageServiceController(/*IRTObject parent*/){
+ // TODOTS: Who is parent of MessageServices and Controller?
+ // this.parent = parent;
+ messageServiceList = new ArrayList<MessageService>();
+ }
+
+ public void addMsgSvc(MessageService msgSvc){
+ // TODOTS: Who is parent of MessageServices ?
+ assert(msgSvc.getAddress().threadID == messageServiceList.size());
+ messageServiceList.add(msgSvc);
+ }
+
+ public MessageService getMsgSvc(int threadID){
+ assert(threadID < messageServiceList.size());
+ return messageServiceList.get(threadID);
+ }
+
+ //the connectAll method connects all messageServices
+ //it is included for test purposes
+ //currently it is not called
+ public void connectAll(){
+ for (int i=0; i < messageServiceList.size(); i++){
+ MessageDispatcher dispatcher = getMsgSvc(i).getMessageDispatcher();
+ for (int j=0;j < messageServiceList.size();j++){
+ if(i!=j){
+ dispatcher.addMessageReceiver(RTServices.getInstance().getMsgSvcCtrl().getMsgSvc(j));
+ }
+ }
+ }
+ }
+
+ public void start() {
+ // start all message services
+ for (MessageService msgSvc : messageServiceList){
+ msgSvc.start();
+ // TODOTS: start in order of priorities
+ }
+ running = true;
+ }
+
+ public void stop() {
+ terminate();
+ waitTerminate();
+ }
+
+ private void terminate() {
+ if (!running){
+ return;
+ }
+ running = false;
+
+ // terminate all message services
+ for (MessageService msgSvc : messageServiceList){
+ msgSvc.terminate();
+ // TODOTS: stop in order of priorities
+ }
+ }
+
+ /**
+ * waitTerminate waits blocking for all MessageServices to terminate
+ * ! not threadsafe !
+ */
+ public void waitTerminate() {
+ for (MessageService msgSvc : messageServiceList){
+ try {
+ msgSvc.join();
+ }
+ catch (InterruptedException e1) {
+ }
+ }
+ }
+
+ private List<MessageService> messageServiceList = null;
+// private IRTObject parent = null;
+ private boolean running = false;
+}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTServices.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTServices.java
index b029c72..910aaf1 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTServices.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTServices.java
@@ -1,42 +1,42 @@
-/*******************************************************************************
- * Copyright (c) 2011 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:
- * Thomas Schuetz
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.runtime.java.messaging;
-
-/**
- * RTServices is the single point of access to all runtime services in one SubSystem
- * e.g. MessageServices, DebuggingService, ...
- *
- * @author Thomas Schuetz
- *
- */
-public class RTServices {
-
- private RTServices(){
- messageServiceController = new MessageServiceController();
- }
-
- public static RTServices getInstance(){
- if (instance == null){
- instance = new RTServices();
- }
- return instance;
- }
-
- public MessageServiceController getMsgSrvCtrl(){
- assert(messageServiceController != null);
- return messageServiceController;
- }
-
- private static RTServices instance = null;
- private MessageServiceController messageServiceController = null;
-}
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.runtime.java.messaging;
+
+/**
+ * RTServices is the single point of access to all runtime services in one SubSystem
+ * e.g. MessageServices, DebuggingService, ...
+ *
+ * @author Thomas Schuetz
+ *
+ */
+public class RTServices {
+
+ private RTServices(){
+ messageServiceController = new MessageServiceController();
+ }
+
+ public static RTServices getInstance(){
+ if (instance == null){
+ instance = new RTServices();
+ }
+ return instance;
+ }
+
+ public MessageServiceController getMsgSvcCtrl(){
+ assert(messageServiceController != null);
+ return messageServiceController;
+ }
+
+ private static RTServices instance = null;
+ private MessageServiceController messageServiceController = null;
+}
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 de874bd..57a8eb8 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
@@ -13,6 +13,7 @@ import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver;
import org.eclipse.etrice.runtime.java.messaging.IRTObject;
import org.eclipse.etrice.runtime.java.messaging.Message;
import org.eclipse.etrice.runtime.java.messaging.MessageService;
+import org.eclipse.etrice.runtime.java.messaging.RTServices;
/**
* The base class for model actor classes.
@@ -36,13 +37,14 @@ public abstract class ActorClassBase extends EventReceiver implements IMessageRe
*/
protected int state;
- private MessageService msgsvc = null;
+ private MessageService ownMsgsvc = null;
+ private Address ownAddr = null;
- public ActorClassBase(IRTObject parent, String name, IMessageReceiver msgsvc) {
+ public ActorClassBase(IRTObject parent, String name, Address ownAddr) {
super(parent, name);
- if (msgsvc instanceof MessageService)
- this.msgsvc = (MessageService) msgsvc;
+ this.ownAddr = ownAddr;
+ ownMsgsvc = RTServices.getInstance().getMsgSvcCtrl().getMsgSvc(this.ownAddr.threadID);
}
public String toString(){
@@ -77,6 +79,6 @@ public abstract class ActorClassBase extends EventReceiver implements IMessageRe
}
public MessageService getMsgsvc() {
- return msgsvc;
+ return ownMsgsvc;
}
}
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 5ffe6ae..5492c96 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
@@ -12,6 +12,7 @@ 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.MessageService;
+import org.eclipse.etrice.runtime.java.messaging.RTServices;
/**
* The abstract base class for actor class interface items like ports and saps.
@@ -21,30 +22,37 @@ import org.eclipse.etrice.runtime.java.messaging.MessageService;
*/
public abstract class InterfaceItemBase extends AbstractMessageReceiver {
- private IMessageReceiver msgReceiver;
+ private IMessageReceiver ownMsgReceiver;
+ private IMessageReceiver peerMsgReceiver;
private int localId;
private int idx;
private Address peerAddress;
- public InterfaceItemBase (IEventReceiver actor, String name, int localId, int idx, Address address, Address peerAddress, IMessageReceiver msgReceiver){
- super(actor, address, name);
- this.msgReceiver = msgReceiver;
+ public InterfaceItemBase (IEventReceiver actor, String name, int localId, int idx, Address ownAddress, Address peerAddress){
+ super(actor, ownAddress, name);
+ this.ownMsgReceiver = RTServices.getInstance().getMsgSvcCtrl().getMsgSvc(ownAddress.threadID);
+ this.peerMsgReceiver = RTServices.getInstance().getMsgSvcCtrl().getMsgSvc(peerAddress.threadID);
this.localId = localId;
this.idx = idx;
this.peerAddress = peerAddress;
- if (getAddress()!=null && msgReceiver instanceof MessageService) {
- MessageService ms = (MessageService) msgReceiver;
+ if (getAddress()!=null && this.ownMsgReceiver instanceof MessageService) {
+ MessageService ms = (MessageService) this.ownMsgReceiver;
+ // register at the own dispatcher to receive messages
ms.getMessageDispatcher().addMessageReceiver(this);
}
}
protected IMessageReceiver getMsgReceiver() {
- return msgReceiver;
+ return ownMsgReceiver;
+ }
+
+ protected IMessageReceiver getPeerMsgReceiver() {
+ return peerMsgReceiver;
}
public void setMsgReceiver(IMessageReceiver msgReceiver) {
- this.msgReceiver = msgReceiver;
+ this.ownMsgReceiver = msgReceiver;
}
public IEventReceiver getActor() {
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 67f346f..9a4989b 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
@@ -19,7 +19,7 @@ import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver;
*/
public abstract class PortBase extends InterfaceItemBase {
- public PortBase (IEventReceiver actor, String name, int localId, int idx, Address address, Address peerAddress, IMessageReceiver msgReceiver){
- super(actor, name, localId, idx, address, peerAddress, msgReceiver);
+ public PortBase (IEventReceiver actor, String name, int localId, int idx, Address address, Address peerAddress){
+ super(actor, name, localId, idx, address, peerAddress);
}
}
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 3980691..6da6db7 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
@@ -54,8 +54,12 @@ public abstract class SubSystemClassBase extends RTObject {
System.out.println("*** MainComponent "+getInstancePath()+"::init ***");
// MessageService
- RTServices.getInstance().getMsgSrvCtrl().addMsgSrv(new MessageService(this, new Address(0, 0, 0), "MessageService0"));
- //instantiateMessageServices();
+ instantiateMessageServices();
+
+ // this is the place to connect the message services if necessary
+ // normaly the ports will address the correct target message service directly
+ // it is just for test purposes
+ // RTServices.getInstance().getMsgSvcCtrl().connectAll();
instantiateActors();
@@ -66,7 +70,7 @@ public abstract class SubSystemClassBase extends RTObject {
}
}
- //public abstract void instantiateMessageServices();
+ public abstract void instantiateMessageServices();
public abstract void instantiateActors();
@@ -78,13 +82,13 @@ public abstract class SubSystemClassBase extends RTObject {
}
// start all message services
- RTServices.getInstance().getMsgSrvCtrl().start();
+ RTServices.getInstance().getMsgSvcCtrl().start();
running = true;
}
public void stop() {
- RTServices.getInstance().getMsgSrvCtrl().stop();
+ RTServices.getInstance().getMsgSvcCtrl().stop();
// stop all actor instances
if (instances!=null)
@@ -105,8 +109,8 @@ public abstract class SubSystemClassBase extends RTObject {
System.out.println("*** MainComponent "+getInstancePath()+"::destroy ***");
}
- public MessageService getMsgService() {
- return RTServices.getInstance().getMsgSrvCtrl().getMessageService(0);
+ public MessageService getMsgService(int idx) {
+ return RTServices.getInstance().getMsgSvcCtrl().getMsgSvc(idx);
}
public ActorClassBase getInstance(int i) {
diff --git a/tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestFSMGenerator.java b/tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestFSMGenerator.java
index 69b32e6..ff7d5f9 100644
--- a/tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestFSMGenerator.java
+++ b/tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestFSMGenerator.java
@@ -48,6 +48,8 @@ public class IntegrationTestFSMGenerator {
main_component.init(); // lifecycle init
main_component.start(); // lifecycle start
+ RTServices.getInstance().getMsgSvcCtrl().waitTerminate();
+
// TODOTS: Test broken -> repair after changes for multi threading
// main_component.waitTerminate();
diff --git a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/PortBaseTest.java b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/PortBaseTest.java
index 7b91b93..1be4960 100644
--- a/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/PortBaseTest.java
+++ b/tests/org.eclipse.etrice.runtime.java.tests/src/org/eclipse/etrice/runtime/java/modelbase/PortBaseTest.java
@@ -47,7 +47,7 @@ public class PortBaseTest extends TestCase {
class MyPortBase extends PortBase {
public MyPortBase(IEventReceiver parent, String name, int localId, int idx, Address address,
Address peerAddress, IMessageReceiver msgReceiver) {
- super(parent, name, localId, idx, address, peerAddress, msgReceiver);
+ super(parent, name, localId, idx, address, peerAddress/*, msgReceiver*/);
}
public void receive(Message msg) {