Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeremie.tatibouet2015-09-02 09:58:15 +0000
committerjeremie.tatibouet2015-09-08 17:36:12 +0000
commit19323b5d09bf49b2ace0413d58a69eacdc578376 (patch)
tree1b70d5d9e29e9a3f084f515d5034e4d74eae9c79
parent35b23bb9d5fb8020380bd543d4a6c2d5d3f08999 (diff)
downloadorg.eclipse.papyrus-19323b5d09bf49b2ace0413d58a69eacdc578376.tar.gz
org.eclipse.papyrus-19323b5d09bf49b2ace0413d58a69eacdc578376.tar.xz
org.eclipse.papyrus-19323b5d09bf49b2ace0413d58a69eacdc578376.zip
Preserve common semantics for event dispatching as it is defined in
fUML. https://bugs.eclipse.org/bugs/show_bug.cgi?id=476408 Change-Id: I645e1f945270cd18717e7e23136ea0d873bff6a9 Signed-off-by: jeremie.tatibouet <jeremie.tatibouet@cea.fr>
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/SM_EventAccepter.java69
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Selection/DefaultTransitionSelectionStrategy.java5
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateMachineExecution.java33
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionActivation.java45
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionEventAccepter.java74
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/VertexActivation.java63
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/Activities/IntermediateActivities/ActivityExecution.java28
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/BasicBehaviors/Execution.java11
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/Communications/ClassifierBehaviorExecution.java10
-rw-r--r--extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/Communications/ObjectActivation.java29
10 files changed, 162 insertions, 205 deletions
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/SM_EventAccepter.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/SM_EventAccepter.java
new file mode 100644
index 00000000000..f3e5b0017a5
--- /dev/null
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/SM_EventAccepter.java
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ *
+ * 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:
+ * Jeremie Tatibouet (CEA LIST) - Based on Ed Seidewitz remarks
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.fuml.statemachines.Semantics;
+
+import java.util.List;
+
+import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.EventAccepter;
+import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.SignalInstance;
+import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.StateMachineExecution;
+import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.TransitionActivation;
+import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.Selection.TransitionChoiceStrategy;
+import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.Selection.TransitionSelectionStrategy;
+
+public class SM_EventAccepter extends EventAccepter{
+
+ protected StateMachineExecution execution;
+
+ public SM_EventAccepter(StateMachineExecution execution) {
+ this.execution = execution;
+ }
+
+ /**
+ * Among the set of ready to fire transitions select one and fire it.
+ * The execution continues while there are transition to fire (i.e. run
+ * to completion semantics)
+ *
+ * @param signalInstance - The signal consumed to trigger a transition
+ */
+ @Override
+ public void accept(SignalInstance signalInstance) {
+ /*1. Select the transition that will fire according to priority rules*/
+ TransitionSelectionStrategy selectionStrategy = (TransitionSelectionStrategy) this.execution.locus.factory.getStrategy(TransitionSelectionStrategy.NAME);
+ List<TransitionActivation> fireableTransition = selectionStrategy.selectTriggeredTransitions(this.execution.getConfiguration(), signalInstance);
+ TransitionChoiceStrategy choiceStrategy = (TransitionChoiceStrategy)this.execution.locus.factory.getStrategy(TransitionChoiceStrategy.NAME);
+ if(!fireableTransition.isEmpty()){
+ /*1.1. Fire the choosen transition */
+ TransitionActivation transitionActivation = choiceStrategy.choose(fireableTransition);
+ transitionActivation.fire();
+ /*1.2. Continue to fire transitions (not triggered) while it is possible*/
+ fireableTransition = selectionStrategy.selectTransitions(this.execution.getConfiguration());
+ while(!fireableTransition.isEmpty()){
+ choiceStrategy = (TransitionChoiceStrategy)this.execution.locus.factory.getStrategy(TransitionChoiceStrategy.NAME);
+ transitionActivation = choiceStrategy.choose(fireableTransition);
+ transitionActivation.fire();
+ fireableTransition = selectionStrategy.selectTransitions(this.execution.getConfiguration());
+ }
+ }
+ }
+
+ @Override
+ public Boolean match(SignalInstance signalInstance) {
+ // Return true if there is at least one transition that is
+ // ready to fire on this event. Return false otherwise
+ TransitionSelectionStrategy selectionStrategy = (TransitionSelectionStrategy) execution.locus.factory.getStrategy(TransitionSelectionStrategy.NAME);
+ return !selectionStrategy.selectTriggeredTransitions(execution.getConfiguration(), signalInstance).isEmpty();
+ }
+
+}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Selection/DefaultTransitionSelectionStrategy.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Selection/DefaultTransitionSelectionStrategy.java
index 9dbe3b2bb06..bc32eca2a81 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Selection/DefaultTransitionSelectionStrategy.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/Selection/DefaultTransitionSelectionStrategy.java
@@ -59,7 +59,8 @@ public class DefaultTransitionSelectionStrategy extends TransitionSelectionStrat
}
/**
- * TODO
+ * Find for the given configuration the set of triggered transitions that can fire regarding the signal instance
+ * provided in parameter.
*/
@Override
public List<TransitionActivation> selectTriggeredTransitions(StateMachineConfiguration configuration,
@@ -72,7 +73,7 @@ public class DefaultTransitionSelectionStrategy extends TransitionSelectionStrat
for(VertexActivation vertexActivation : cartography.get(i)){
for(TransitionActivation transitionActivation : vertexActivation.getOutgoingTransitions()){
if(transitionActivation.isTriggered() &&
- transitionActivation.hasTriggerEnabled(signal)){
+ transitionActivation.hasTrigger(signal)){
fireableTransition.add(transitionActivation);
}
}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateMachineExecution.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateMachineExecution.java
index 71015213593..9cc28798f5b 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateMachineExecution.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/StateMachineExecution.java
@@ -19,7 +19,6 @@ import java.util.List;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Object_;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Value;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.Execution;
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.SignalInstance;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.Configuration.StateMachineConfiguration;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.Selection.TransitionChoiceStrategy;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.Selection.TransitionSelectionStrategy;
@@ -115,38 +114,6 @@ public class StateMachineExecution extends Execution {
fireableTransition = selectionStrategy.selectTransitions(this.configuration);
}
}
-
- public boolean dispatchEvent(SignalInstance signal){
- boolean dispatched = false;
- TransitionSelectionStrategy selectionStrategy = (TransitionSelectionStrategy) this.locus.factory.getStrategy(TransitionSelectionStrategy.NAME);
- List<TransitionActivation> fireableTransition = selectionStrategy.selectTriggeredTransitions(this.configuration, signal);
- if(!fireableTransition.isEmpty()){
- TransitionChoiceStrategy choiceStrategy = (TransitionChoiceStrategy)this.locus.factory.getStrategy(TransitionChoiceStrategy.NAME);
- TransitionActivation transitionActivation = choiceStrategy.choose(fireableTransition);
- int i = 0;
- TransitionEventAccepter accepter = null;
- while(accepter==null && i < this.context.objectActivation.waitingEventAccepters.size()){
- accepter = (TransitionEventAccepter)this.context.objectActivation.waitingEventAccepters.get(i);
- if(accepter.registrationContext!=this || accepter.getTransition()!=transitionActivation || !accepter.match(signal)){
- i++;
- accepter = null;
- }
- }
- if(accepter!=null){
- accepter.accept(signal);
- this.context.objectActivation.unregister(accepter);
- dispatched = true;
- }
- fireableTransition = selectionStrategy.selectTransitions(this.configuration);
- while(!fireableTransition.isEmpty()){
- choiceStrategy = (TransitionChoiceStrategy)this.locus.factory.getStrategy(TransitionChoiceStrategy.NAME);
- transitionActivation = choiceStrategy.choose(fireableTransition);
- transitionActivation.fire();
- fireableTransition = selectionStrategy.selectTransitions(this.configuration);
- }
- }
- return dispatched;
- }
@Override
public Value new_() {
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionActivation.java
index 0c51d1c81dc..f2259b93d7f 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionActivation.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionActivation.java
@@ -16,19 +16,23 @@ package org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.Beha
import static org.eclipse.papyrus.moka.fuml.statemachines.Activator.logger;
+import java.util.List;
+
+import org.eclipse.papyrus.moka.composites.Semantics.CompositeStructures.InvocationActions.CS_SignalInstance;
import org.eclipse.papyrus.moka.fuml.FUMLExecutionEngine;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.BooleanValue;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Evaluation;
-import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Object_;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.Execution;
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.EventAccepter;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.SignalInstance;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.Classes.Kernel.SM_OpaqueExpressionEvaluation;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.Loci.LociL3.SM_SemanticVisitor;
import org.eclipse.papyrus.moka.fuml.statemachines.debug.SM_ControlDelegate;
import org.eclipse.uml2.uml.OpaqueExpression;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.SignalEvent;
import org.eclipse.uml2.uml.Transition;
import org.eclipse.uml2.uml.TransitionKind;
+import org.eclipse.uml2.uml.Trigger;
import org.eclipse.uml2.uml.ValueSpecification;
public class TransitionActivation extends SM_SemanticVisitor {
@@ -102,20 +106,39 @@ public class TransitionActivation extends SM_SemanticVisitor {
}
/**
- * @return true if a trigger of this transition is enabled by an event in the event pool false in the other case
+ * True if the transition has a trigger which matches the given signal type
*/
- public boolean hasTriggerEnabled(final SignalInstance signal){
- boolean result = false;
- Object_ context = this.getExecutionContext();
+ public boolean hasTrigger(final SignalInstance signal){
int i = 0;
- while(i < context.objectActivation.waitingEventAccepters.size() && !result){
- EventAccepter accepter = context.objectActivation.waitingEventAccepters.get(i);
- if(((TransitionEventAccepter)accepter).getTransition()==this){
- result = accepter.match(signal);
+ Transition transition = (Transition)this.node;
+ Trigger trigger = null;
+ while(i < transition.getTriggers().size() && trigger==null){
+ Trigger currentTrigger = transition.getTriggers().get(i);
+ /*1. Check that expected signal type and conforms to signal instance type*/
+ if(currentTrigger.getEvent()!=null &&
+ currentTrigger.getEvent() instanceof SignalEvent
+ && ((SignalEvent)currentTrigger.getEvent()).getSignal()==signal.type){
+ /*1.1. The port from which the signal was emitted must be one which is referenced
+ * in the trigger*/
+ if(currentTrigger.getPorts().size() > 0) {
+ List<Port> portsOfTrigger = currentTrigger.getPorts();
+ Port onPort = ((CS_SignalInstance)signal).interactionPoint.definingPort;
+ Boolean portMatches = false;
+ int j = 1;
+ while(!portMatches & j <= portsOfTrigger.size()) {
+ portMatches = onPort == portsOfTrigger.get(j - 1);
+ j = j + 1;
+ }
+ if(portMatches){
+ trigger = currentTrigger;
+ }
+ }else{
+ trigger = currentTrigger;
+ }
}
i++;
}
- return result;
+ return trigger != null;
}
/**
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionEventAccepter.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionEventAccepter.java
deleted file mode 100644
index 2c67a7e7f75..00000000000
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/TransitionEventAccepter.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2015 CEA LIST.
- *
- *
- * 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:
- * Jeremie Tatibouet (CEA LIST)
- *
- *****************************************************************************/
-package org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines;
-
-import java.util.List;
-
-import org.eclipse.papyrus.moka.composites.Semantics.CompositeStructures.InvocationActions.CS_SignalInstance;
-import org.eclipse.papyrus.moka.fuml.FUMLExecutionEngine;
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.EventAccepter;
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.SignalInstance;
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Signal;
-import org.eclipse.uml2.uml.SignalEvent;
-import org.eclipse.uml2.uml.Transition;
-import org.eclipse.uml2.uml.Trigger;
-
-public class TransitionEventAccepter extends EventAccepter {
-
- protected TransitionActivation transitionActivation;
-
- public TransitionEventAccepter(TransitionActivation activation){
- this.transitionActivation = activation;
- }
-
- public TransitionActivation getTransition(){
- return this.transitionActivation;
- }
-
- @Override
- public void accept(SignalInstance signalInstance) {
- this.transitionActivation.fire();
- }
-
- @Override
- public Boolean match(SignalInstance signalInstance) {
- if (FUMLExecutionEngine.eInstance.isTerminated())
- return false ;
- Transition transition = (Transition)(this.transitionActivation.getNode());
- List<Trigger> triggers = transition.getTriggers();
- Signal signal = signalInstance.type;
-
- Boolean matches = false;
- Integer i = 1;
- while(!matches & i <= triggers.size()) {
- Trigger t = triggers.get(i - 1);
- matches = ((SignalEvent)t.getEvent()).getSignal() == signal;
- if(matches && t.getPorts().size() > 0) {
- List<Port> portsOfTrigger = t.getPorts();
- Port onPort = ((CS_SignalInstance)signalInstance).interactionPoint.definingPort;
- Boolean portMatches = false;
- Integer j = 1;
- while(!portMatches & j <= portsOfTrigger.size()) {
- portMatches = onPort == portsOfTrigger.get(j - 1);
- j = j + 1;
- }
- matches = portMatches;
- }
- i = i + 1;
- }
- boolean guardEvaluation = this.transitionActivation.evaluateGuard() ;
- return matches && guardEvaluation ;
- }
-}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/VertexActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/VertexActivation.java
index 7f08f82e5dc..2c9a48d36ee 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/VertexActivation.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml.statemachines/src/org/eclipse/papyrus/moka/fuml/statemachines/Semantics/StateMachines/BehaviorStateMachines/VertexActivation.java
@@ -17,8 +17,10 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.papyrus.moka.fuml.FUMLExecutionEngine;
+import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.Execution;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.EventAccepter;
import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.SemanticVisitor;
+import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.SM_EventAccepter;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.Loci.LociL3.SM_SemanticVisitor;
import org.eclipse.papyrus.moka.fuml.statemachines.Semantics.StateMachines.BehaviorStateMachines.TransitionActivation.TransitionMetadata;
import org.eclipse.papyrus.moka.fuml.statemachines.debug.SM_ControlDelegate;
@@ -120,7 +122,7 @@ public abstract class VertexActivation extends SM_SemanticVisitor {
/*1. The vertex becomes active*/
this.setState(StateMetadata.ACTIVE);
/*2. Register event accepters for transitions having triggers*/
- this.registerEventAccepters();
+ this.tryToPlaceEventAccepter();
/*3. Vertex outgoing transitions are tag as REACHED*/
this.tagOutgoingTransitions(TransitionMetadata.REACHED);
/*4. The vertex starts to be highlighted*/
@@ -133,8 +135,8 @@ public abstract class VertexActivation extends SM_SemanticVisitor {
public void exit(TransitionActivation exitingTransition){
/*1. The representation of the vertex stops to be highlighted*/
((SM_ControlDelegate)FUMLExecutionEngine.eInstance.getControlDelegate()).inactive(this.getNode());
- /*2. If any, its registered accepters are removed from the event pool*/
- this.removeEventAccepters();
+ /*2. If there is a event accepter for the state-machine then remove it*/
+ this.removeEventAccepter();
/*3. The incoming transitions of this vertex get back to the NONE status*/
this.tagIncomingTransitions(TransitionMetadata.NONE);
/*4. The vertex becomes IDLE*/
@@ -154,40 +156,55 @@ public abstract class VertexActivation extends SM_SemanticVisitor {
}
/**
- * Register event accepters corresponding to the transition within the context object
- * executing the state-machine
+ * Determines if the registration of an event accepter is required
+ *
+ * @return
*/
- public void registerEventAccepters() {
+ protected boolean mustRegisterEventAccepter(){
List<SemanticVisitor> contextChain = this.getContextChain();
- StateMachineExecution execution = (StateMachineExecution) this.getStateMachineExecution();
int i = 0;
- while(contextChain.get(i) instanceof StateActivation){ //FIXME
+ boolean accepterRequired = false;
+ while(contextChain.get(i) instanceof StateActivation && !accepterRequired){
StateActivation stateActivation = (StateActivation)contextChain.get(i);
- for(TransitionActivation transitionActivation : stateActivation.getOutgoingTransitions()){
- if(transitionActivation.isTriggered()){
- EventAccepter accepter = new TransitionEventAccepter(transitionActivation);
- accepter.registrationContext = this.getStateMachineExecution();
- execution.context.register(accepter);
+ int t = 0;
+ while(!accepterRequired && t < stateActivation.getOutgoingTransitions().size()){
+ if(stateActivation.getOutgoingTransitions().get(i).isTriggered()){
+ accepterRequired = true;
}
+ t++;
}
i++;
}
+ return accepterRequired;
+ }
+
+ /**
+ * Register event accepters corresponding to the transition within the context object
+ * executing the state-machine
+ */
+ protected void tryToPlaceEventAccepter() {
+ if(this.mustRegisterEventAccepter()){
+ Execution execution = this.getStateMachineExecution();
+ execution.context.register(new SM_EventAccepter(((StateMachineExecution)execution)));
+ }
}
/**
* Remove all event accepters that are registered in the context of the given Vertex
*/
- public void removeEventAccepters(){
- List<EventAccepter> eventAcceptersToRemove = new ArrayList<>();
- List<EventAccepter> registerEventAccepters = this.getExecutionContext().objectActivation.waitingEventAccepters;
- for(TransitionActivation activation : this.getOutgoingTransitions()){
- for(EventAccepter accepter : registerEventAccepters){
- if(accepter instanceof TransitionEventAccepter &&
- ((TransitionEventAccepter)accepter).transitionActivation == activation){
- eventAcceptersToRemove.add(accepter);
- }
+ public void removeEventAccepter(){
+ int i = 0;
+ Execution execution = this.getStateMachineExecution();
+ EventAccepter accepter = null;
+ while(i < execution.context.objectActivation.waitingEventAccepters.size()
+ && accepter==null){
+ accepter = execution.context.objectActivation.waitingEventAccepters.get(i);
+ if(!(accepter instanceof SM_EventAccepter)){
+ accepter = null;
}
}
- this.getExecutionContext().objectActivation.waitingEventAccepters.removeAll(eventAcceptersToRemove) ;
+ if(accepter!=null){
+ execution.context.objectActivation.unregister(accepter);
+ }
}
}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/Activities/IntermediateActivities/ActivityExecution.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/Activities/IntermediateActivities/ActivityExecution.java
index 3757c8959a9..3d3ad5ce159 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/Activities/IntermediateActivities/ActivityExecution.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/Activities/IntermediateActivities/ActivityExecution.java
@@ -14,16 +14,11 @@
*****************************************************************************/
package org.eclipse.papyrus.moka.fuml.Semantics.Activities.IntermediateActivities;
-import java.util.ArrayList;
import java.util.List;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Value;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.Execution;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.ParameterValue;
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.EventAccepter;
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.ObjectActivation;
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.SignalInstance;
-import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ChoiceStrategy;
import org.eclipse.papyrus.moka.fuml.debug.Debug;
import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.ActivityParameterNode;
@@ -94,27 +89,4 @@ public class ActivityExecution extends Execution {
}
}
- @Override
- public boolean dispatchEvent(SignalInstance signal) {
- boolean dispatched = false;
- ObjectActivation objectActivation = this.context.objectActivation;
- List<Integer> matchingEventAccepterIndexes = new ArrayList<Integer>();
- List<EventAccepter> waitingEventAccepters = objectActivation.waitingEventAccepters;
- for (int i = 0; i < waitingEventAccepters.size(); i++) {
- EventAccepter eventAccepter = waitingEventAccepters.get(i);
- if (eventAccepter.registrationContext==this && eventAccepter.match(signal)) {
- matchingEventAccepterIndexes.add(i);
- }
- }
- if (matchingEventAccepterIndexes.size() > 0) {
- // *** Choose one matching event accepter non-deterministically.
- // ***
- int j = ((ChoiceStrategy) this.context.locus.factory.getStrategy("choice")).choose(matchingEventAccepterIndexes.size());
- EventAccepter selectedEventAccepter = objectActivation.waitingEventAccepters.get(matchingEventAccepterIndexes.get(j - 1));
- objectActivation.waitingEventAccepters.remove(j - 1);
- selectedEventAccepter.accept(signal);
- dispatched = true;
- }
- return dispatched;
- }
}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/BasicBehaviors/Execution.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/BasicBehaviors/Execution.java
index 7f67993881b..d56affb660c 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/BasicBehaviors/Execution.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/BasicBehaviors/Execution.java
@@ -19,7 +19,6 @@ import java.util.List;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Object_;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Value;
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.SignalInstance;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Parameter;
import org.eclipse.uml2.uml.ParameterDirectionKind;
@@ -43,16 +42,6 @@ public abstract class Execution extends Object_ {
public abstract void execute();
- /**
- * Called whenever a signal is dispatched through an object an need to be addressed to
- * an Execution representing the execution of a particular
- * @param signal
- * @return
- */
- public boolean dispatchEvent(SignalInstance signal){
- return false;
- }
-
public void terminate() {
// Terminate an ongoing execution. By default, do nothing.
return;
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/Communications/ClassifierBehaviorExecution.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/Communications/ClassifierBehaviorExecution.java
index 9639fb91a69..392066e37dd 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/Communications/ClassifierBehaviorExecution.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/Communications/ClassifierBehaviorExecution.java
@@ -39,16 +39,6 @@ public class ClassifierBehaviorExecution {
* The object activation that owns this classifier behavior execution.
*/
public ObjectActivation objectActivation;
-
- /**
- * Try to dispatch the selected signal onto the execution governed
- * by this classifier behavior execution
- * @param The signal being dispatched
- * @return A flag making sure the signal was dispatched
- */
- public boolean dispatchEvent(SignalInstance signal){
- return this.execution.dispatchEvent(signal);
- }
public void execute(Class classifier, List<ParameterValue> inputs) {
// Set the classifier for this classifier behavior execution to the
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/Communications/ObjectActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/Communications/ObjectActivation.java
index 985316696b3..2af46374889 100644
--- a/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/Communications/ObjectActivation.java
+++ b/extraplugins/moka/org.eclipse.papyrus.moka.fuml/generated/org/eclipse/papyrus/moka/fuml/Semantics/CommonBehaviors/Communications/ObjectActivation.java
@@ -20,12 +20,11 @@ import java.util.List;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Object_;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.ParameterValue;
+import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.ChoiceStrategy;
import org.eclipse.papyrus.moka.fuml.debug.Debug;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Class;
-import static org.eclipse.papyrus.moka.fuml.Activator.logger;
-
public class ObjectActivation {
/*
@@ -86,20 +85,24 @@ public class ObjectActivation {
}
public void dispatchNextEvent() {
- // Get the next signal instance out of the event pool.
- // If there is one or more waiting event accepters with triggers that
- // match the signal instance, then dispatch it to exactly one of those
- // waiting accepters.
if (this.eventPool.size() > 0) {
- int i = 0;
- boolean dispatched = false;
SignalInstance signalInstance = this.getNextEvent();
- while(!dispatched && i < this.classifierBehaviorExecutions.size()){
- dispatched = this.classifierBehaviorExecutions.get(i).dispatchEvent(signalInstance);
- i++;
+ Debug.println("[dispatchNextEvent] signalInstance = " + signalInstance);
+ List<Integer> matchingEventAccepterIndexes = new ArrayList<Integer>();
+ List<EventAccepter> waitingEventAccepters = this.waitingEventAccepters;
+ for (int i = 0; i < waitingEventAccepters.size(); i++) {
+ EventAccepter eventAccepter = waitingEventAccepters.get(i);
+ if (eventAccepter.match(signalInstance)) {
+ matchingEventAccepterIndexes.add(i);
+ }
}
- if(!dispatched){
- logger.debug("[Signal Lost] => "+signalInstance);
+ if (matchingEventAccepterIndexes.size() > 0) {
+ // *** Choose one matching event accepter non-deterministically.
+ // ***
+ int j = ((ChoiceStrategy) this.object.locus.factory.getStrategy("choice")).choose(matchingEventAccepterIndexes.size());
+ EventAccepter selectedEventAccepter = this.waitingEventAccepters.get(matchingEventAccepterIndexes.get(j - 1));
+ this.waitingEventAccepters.remove(j - 1);
+ selectedEventAccepter.accept(signalInstance);
}
}
}

Back to the top