diff options
Diffstat (limited to 'extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka')
12 files changed, 0 insertions, 1467 deletions
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Activator.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Activator.java deleted file mode 100644 index 2efc2279232..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Activator.java +++ /dev/null @@ -1,72 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.async.fuml; - -import org.eclipse.papyrus.infra.core.log.LogHelper; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -// TODO: Auto-generated Javadoc -/** - * The activator class controls the plug-in life cycle. - */ -public class Activator extends AbstractUIPlugin { - - // The plug-in ID - /** The Constant PLUGIN_ID. */ - public static final String PLUGIN_ID = "org.eclipse.papyrus.moka.async.fuml"; //$NON-NLS-1$ - - // The shared instance - /** The plugin. */ - private static Activator plugin; - - public static LogHelper log; - - /** - * The constructor. - */ - public Activator() { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - log = new LogHelper(this); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ - @Override - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance. - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } - -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/FUMLAsyncExecutionEngine.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/FUMLAsyncExecutionEngine.java deleted file mode 100644 index 91e047243a9..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/FUMLAsyncExecutionEngine.java +++ /dev/null @@ -1,169 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.async.fuml; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.papyrus.infra.core.Activator; -import org.eclipse.papyrus.moka.MokaConstants; -import org.eclipse.papyrus.moka.async.fuml.Semantics.CommonBehaviors.Communications.AsyncFIFOGetNextEventStrategy; -import org.eclipse.papyrus.moka.async.fuml.Semantics.Loci.LociL1.AsyncLocus; -import org.eclipse.papyrus.moka.async.fuml.debug.AsyncControlDelegate; -import org.eclipse.papyrus.moka.communication.Marshaller; -import org.eclipse.papyrus.moka.communication.event.isuspendresume.Resume_Event; -import org.eclipse.papyrus.moka.communication.request.isuspendresume.Resume_Request; -import org.eclipse.papyrus.moka.composites.CompositeStructuresExecutionEngine; -import org.eclipse.papyrus.moka.composites.Semantics.CommonBehaviors.Communications.CS_DispatchOperationOfInterfaceStrategy; -import org.eclipse.papyrus.moka.composites.Semantics.CommonBehaviors.Communications.CS_NameBased_StructuralFeatureOfInterfaceAccessStrategy; -import org.eclipse.papyrus.moka.composites.Semantics.CompositeStructures.InvocationActions.CS_DefaultConstructStrategy; -import org.eclipse.papyrus.moka.composites.Semantics.CompositeStructures.InvocationActions.CS_DefaultRequestPropagationStrategy; -import org.eclipse.papyrus.moka.composites.Semantics.Loci.LociL3.CS_ExecutionFactory; -import org.eclipse.papyrus.moka.composites.Semantics.Loci.LociL3.CS_Executor; -import org.eclipse.papyrus.moka.fuml.FUMLExecutionEngine; -import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.Locus; -import org.eclipse.papyrus.moka.fuml.debug.ControlDelegate; -import org.eclipse.swt.widgets.Display; -import org.eclipse.uml2.uml.Behavior; - -/** - * Entry point of this plug-in. By extending the FUMLExecutionEngine it contributes - * to the extension point defined by Moka and is by the way registered as a new engine - * that can be used to execute a defined model - * - * @author CEA LIST (jt605650) - * - */ -public class FUMLAsyncExecutionEngine extends CompositeStructuresExecutionEngine { - - /* - * (non-Javadoc) - * - * @see org.eclipse.papyrus.moka.composites.CompositeStructuresExecutionEngine#start(org.eclipse.uml2.uml.Behavior) - */ - @Override - public void start(Behavior behavior) { - if (behavior != null) { - main = behavior; - // creates the locus, executor and execution factory - this.locus = new AsyncLocus(); - this.locus.setFactory(new CS_ExecutionFactory()); - this.locus.setExecutor(new CS_Executor()); - // initializes built-in primitive types - this.initializeBuiltInPrimitiveTypes(locus); - // Initializes opaque behavior executions - this.registerOpaqueBehaviorExecutions(locus); - // Initializes semantic strategies - this.registerSemanticStrategies(locus); - // Initializes system services - this.registerSystemServices(locus); - // Initializes arguments - this.initializeArguments(this.args); - // Finally launches the execution - this.started = true; - this.locus.executor.execute(main, null, this.arguments); - ((AsyncControlDelegate) eInstance.getControlDelegate()).notifyMainThreadLogicallyEnded(); - } - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.papyrus.moka.composites.CompositeStructuresExecutionEngine#registerSemanticStrategies(org.eclipse.papyrus.moka.fuml.Semantics.Loci - * .LociL1.Locus) - */ - @Override - protected void registerSemanticStrategies(Locus locus) { - super.registerSemanticStrategies(locus); - locus.factory.setStrategy(new AsyncFIFOGetNextEventStrategy()); - locus.factory.setStrategy(new CS_DispatchOperationOfInterfaceStrategy()); - locus.factory.setStrategy(new CS_NameBased_StructuralFeatureOfInterfaceAccessStrategy()); - locus.factory.setStrategy(new CS_DefaultRequestPropagationStrategy()); - locus.factory.setStrategy(new CS_DefaultConstructStrategy()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.papyrus.moka.fuml.FUMLExecutionEngineForMoka#getControlDelegate() - */ - @Override - public ControlDelegate getControlDelegate() { - if (this.controlDelegate == null) { - this.controlDelegate = new AsyncControlDelegate(this); - } - return this.controlDelegate; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.papyrus.moka.fuml.FUMLExecutionEngineForMoka#resume(org.eclipse.papyrus.moka.communication.request.isuspendresume.Resume_Request) - */ - @Override - public void resume(Resume_Request request) { - if (!this.started) { - Runnable execution = new Runnable() { - - public void run() { - if (main != null) { - try { - start(main); - } - catch (Exception e) { - Activator.log.error(e); - if (!MokaConstants.SILENT_MODE) { - Display.getDefault().syncExec(new Runnable() { - public void run() { - MessageDialog.openError(Display.getDefault().getActiveShell(), "Moka", "An unexpected error occurred during execution. See error log for details."); - } - }); - } - setIsTerminated(true); - } - // Waits for termination. i.e., the main thread is terminated, but object activations may still be running - FUMLExecutionEngine.eInstance.getControlDelegate().waitForTermination(); - try { - getDebugTarget().terminate(); - } catch (DebugException e) { - Activator.log.error(e); - } - } - } - }; - Thread mainThread = new Thread(execution); - ((AsyncControlDelegate) eInstance.getControlDelegate()).registerObjectActivation(null); - mainThread.start(); - } else { - this.getControlDelegate().resume(request); - } - } - - // ************************************** - // Management of a resume() request emitted from the debug target. - // @see ISuspendResume.resume() - // *************************************** - /** - * Manages reply to a resume() request emitted from the debug target. - * - * @param message - * the message - */ - @Override - protected void resume_reply(String message) { - Resume_Request request = Marshaller.getInstance().resume_request_unmarshal(message); - this.resume(request); - Resume_Event event = new Resume_Event(request.getDebugElement(), request.getResumeDetail(), this.getThreads()); - this.sendEvent(event); - } -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/Classes/Kernel/AsyncObject_.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/Classes/Kernel/AsyncObject_.java deleted file mode 100644 index 0a8e3608258..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/Classes/Kernel/AsyncObject_.java +++ /dev/null @@ -1,79 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2014 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:
- * CEA LIST - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.moka.async.fuml.Semantics.Classes.Kernel;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.papyrus.moka.async.fuml.Activator;
-import org.eclipse.papyrus.moka.async.fuml.Semantics.CommonBehaviors.Communications.AsyncObjectActivation;
-import org.eclipse.papyrus.moka.async.fuml.debug.AsyncControlDelegate;
-import org.eclipse.papyrus.moka.async.fuml.debug.AsyncDebug;
-import org.eclipse.papyrus.moka.composites.Semantics.CompositeStructures.StructuredClasses.CS_Object;
-import org.eclipse.papyrus.moka.fuml.FUMLExecutionEngine;
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.ParameterValue;
-import org.eclipse.uml2.uml.Class;
-
-/**
- * Object_ class is slightly modified in order to enable creation and starting of its
- * object activation on a new thread. This override the previous behavior that was limited
- * the call of the startBehavior(...) method
- *
- */
-public class AsyncObject_ extends CS_Object {
-
- /** The objectactivation thread. */
- protected Thread objectactivationThread;
-
- /**
- * Create and start the Java Thread required to execute its owning objectActivation.
- *
- * @param classifier
- * @param inputs
- */
- @Override
- public void startBehavior(Class classifier, List<ParameterValue> inputs) {
- if (this.objectActivation == null) {
- this.objectActivation = new AsyncObjectActivation(classifier, inputs);
- this.objectActivation.object = this;
- }
- /* 1. Create Thread Name */
- String threadName = "Thread_";
- Iterator<Class> classes = this.types.iterator();
- while (classes.hasNext()) {
- threadName += classes.next().getName();
- if (classes.hasNext()) {
- threadName += "|";
- }
- }
- /* 2. Pattern to start the Runnable corresponding to the AsyncObjectActivation */
- // Thread objectactivationThread = new Thread((AsyncObjectActivation)this.objectActivation, threadName);
- objectactivationThread = new Thread((AsyncObjectActivation) this.objectActivation, threadName);
-
- ((AsyncControlDelegate) FUMLExecutionEngine.eInstance.getControlDelegate()).registerObjectActivation(this.objectActivation, threadName); // Added for connection with debug api
-
- objectactivationThread.start();
-
- AsyncDebug.println("[NEW THREAD] Active object instance started on a new thread");
- }
-
- /**
- * TODO write Javadoc
- */
- public void join() {
- try {
- objectactivationThread.join();
- } catch (InterruptedException e) {
- Activator.log.error(e);
- }
- }
-}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncEventPool.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncEventPool.java deleted file mode 100644 index 40cbac0617d..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncEventPool.java +++ /dev/null @@ -1,92 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.async.fuml.Semantics.CommonBehaviors.Communications; - -import java.util.concurrent.LinkedBlockingQueue; - -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.SemanticStrategy; - -// TODO: Auto-generated Javadoc -/** - * The Class AsyncEventPool. - */ -@SuppressWarnings("serial") -/** - * The event pool provide a way for an object activation to communicate with others. - * An instance of such class is always owned by an object activation - * The only Java thread that can retrieve signal instances is the one linked to to the - * object activation. - * Every object activation that need to communicate with the one owning the event pool can - * use the send method to offer a new SignalInstance - * @author CEA LIST (jt605650) - */ -public class AsyncEventPool extends LinkedBlockingQueue<SignalInstance> implements IAsyncEventPool { - - /* Event pool owner */ - /** The object activation. */ - private ObjectActivation objectActivation; - - /** - * Constructor. - * - * @param activation - * that owns the event pool - */ - public AsyncEventPool(ObjectActivation activation) { - super(); - this.objectActivation = activation; - } - - /** - * Offers the given signal instance to the Queue. Since the eventPool is unbounded - * offer always deliver the SignalInstance to the event pool - * - * @param signalInstance - * that need to be added to the event pool - * @return true, if successful - */ - public boolean send(SignalInstance signalInstance) { - return this.offer(signalInstance); - } - - /** - * Call the getNextEvent strategy registered in the locus in order to take a signalInstance. - * - * @return the next event - */ - public SignalInstance getNextEvent() { - SemanticStrategy strategy = this.objectActivation.object.locus.factory.getStrategy("getNextEvent"); - return ((AsyncGetNextEventStrategy) strategy).getNextEvent(this); - } - - /** - * Get the object activation that owns the current event pool. - * - * @return objectActivation owning the event pool - */ - public synchronized ObjectActivation getObjectActivation() { - return objectActivation; - } - - /** - * Modify the owner of the current event pool. - * - * @param objectActivation - * new owner of the current event pool - */ - public synchronized void setObjectActivation(ObjectActivation objectActivation) { - this.objectActivation = objectActivation; - } - -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncFIFOGetNextEventStrategy.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncFIFOGetNextEventStrategy.java deleted file mode 100644 index e81d38d352b..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncFIFOGetNextEventStrategy.java +++ /dev/null @@ -1,45 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2014 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:
- * CEA LIST - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.moka.async.fuml.Semantics.CommonBehaviors.Communications;
-
-import org.eclipse.papyrus.moka.async.fuml.Activator;
-import org.eclipse.papyrus.moka.async.fuml.debug.AsyncDebug;
-import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.SignalInstance;
-
-/**
- * FIFO strategy that retrieve the oldest SignalInstance owned by the EventPool object.
- */
-public class AsyncFIFOGetNextEventStrategy extends AsyncGetNextEventStrategy {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.papyrus.moka.async.fuml.Semantics.CommonBehaviors.Communications.AsyncGetNextEventStrategy#getNextEvent(org.eclipse.papyrus.moka
- * .async.fuml.Semantics.CommonBehaviors.Communications.AsyncEventPool)
- */
- @Override
- /**
- * This method is always called by the object activation owning the event pool.
- * The call is blocking if no SignalInstance can be retrieved from the event pool.
- */
- public SignalInstance getNextEvent(AsyncEventPool eventPool) {
- SignalInstance nextEvent = null;
- try {
- nextEvent = eventPool.take();
- } catch (InterruptedException e) {
- AsyncDebug.println("getNextEvent interrupted while waiting");
- Activator.log.error(e);
- }
- return nextEvent;
- }
-}
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncGetNextEventStrategy.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncGetNextEventStrategy.java deleted file mode 100644 index 493f5410109..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncGetNextEventStrategy.java +++ /dev/null @@ -1,44 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.async.fuml.Semantics.CommonBehaviors.Communications; - -import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.SignalInstance; -import org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.SemanticStrategy; - - -// TODO: Auto-generated Javadoc -/** - * The Class AsyncGetNextEventStrategy. - * - * @author CEA LIST (jt605650) - */ -public abstract class AsyncGetNextEventStrategy extends SemanticStrategy { - - /* - * (non-Javadoc) - * - * @see org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.SemanticStrategy#getName() - */ - @Override - public String getName() { - return "getNextEvent"; - } - - /** - * Gets the next event. - * - * @param eventPool - * the event pool - * @return the next event - */ - public abstract SignalInstance getNextEvent(AsyncEventPool eventPool); -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncObjectActivation.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncObjectActivation.java deleted file mode 100644 index 221c671e025..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/AsyncObjectActivation.java +++ /dev/null @@ -1,325 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.async.fuml.Semantics.CommonBehaviors.Communications; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.papyrus.infra.core.Activator; -import org.eclipse.papyrus.moka.MokaConstants; -import org.eclipse.papyrus.moka.async.fuml.debug.AsyncControlDelegate; -import org.eclipse.papyrus.moka.async.fuml.debug.AsyncDebug; -import org.eclipse.papyrus.moka.fuml.FUMLExecutionEngine; -import org.eclipse.papyrus.moka.fuml.Semantics.Actions.CompleteActions.AcceptEventActionEventAccepter; -import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.ParameterValue; -import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.ClassifierBehaviorExecution; -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.standardlibrary.library.io.StandardOutputChannelImpl; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.console.IOConsoleOutputStream; -import org.eclipse.uml2.uml.AcceptEventAction; -import org.eclipse.uml2.uml.Behavior; -import org.eclipse.uml2.uml.Class; -import org.eclipse.uml2.uml.Signal; -import org.eclipse.uml2.uml.SignalEvent; -import org.eclipse.uml2.uml.Trigger; - -// TODO: Auto-generated Javadoc -/** - * Extend the original ObjectActivation class in order to support starting of execution - * of the different classifiers behaviors over a new Java Thread. - * - * @author CEA LIST (JT605650) - */ -public class AsyncObjectActivation extends ObjectActivation implements Runnable { - - /* Thread State */ - /** - * The Enum ObjectActivationState. - */ - public enum ObjectActivationState { - - /** The running. */ - RUNNING, - /** The stopped. */ - STOPPED, - /** The waiting. */ - WAITING - } // WAITING State added for connection with debug api - - /** The current state. */ - protected ObjectActivationState currentState = null; - - /* Arguments of the ObjectActivation */ - /** The classifier. */ - final protected Class classifier; - - /** The inputs. */ - final protected List<ParameterValue> inputs; - - /* The event pool handled by the ObjectActivation */ - /** The evt pool. */ - protected AsyncEventPool evtPool; - - /** - * Constructor of AsyncObjectActivation. - * - * @param classifier - * that need to be executed on the current object activation - * @param inputs - * parameters that are provided to the execution - */ - public AsyncObjectActivation(Class classifier, List<ParameterValue> inputs) { - super(); - this.classifier = classifier; - this.inputs = inputs; - this.evtPool = new AsyncEventPool(this); - } - - /** - * Implementation of the behavior of the current object activation. - */ - public void run() { - /* 1. The current object activation is in the running state */ - this.currentState = ObjectActivationState.RUNNING; - /* 2. Execute behavior(s) associated to the given classifier */ - try { - this.startBehavior(this.classifier, this.inputs); - } catch (Exception e) { - Activator.log.error(e); - if (!MokaConstants.SILENT_MODE) { - Display.getDefault().syncExec(new Runnable() { - public void run() { - MessageDialog.openError(Display.getDefault().getActiveShell(), "Moka", "An unexpected error occurred during execution. See error log for details."); - } - }); - } - ((AsyncControlDelegate) FUMLExecutionEngine.eInstance.getControlDelegate()).notifyThreadTermination(this); // Added for connection with debug api - } - /* 3. While current object activation is running then dispatch events */ - while (!FUMLExecutionEngine.eInstance.isTerminated() && this.currentState.equals(ObjectActivationState.RUNNING)) { - try { - this.dispatchNextEvent(); /* Dispatch is blocking if no SignalInstance available */ - } catch (Exception e) { - Activator.log.error(e); - if (!MokaConstants.SILENT_MODE) { - Display.getDefault().syncExec(new Runnable() { - public void run() { - MessageDialog.openError(Display.getDefault().getActiveShell(), "Moka", "An unexpected error occurred during execution. See error log for details."); - } - }); - } - ((AsyncControlDelegate) FUMLExecutionEngine.eInstance.getControlDelegate()).notifyThreadTermination(this); // Added for connection with debug api - } - if (this.waitingEventAccepters.isEmpty()) { - this.currentState = ObjectActivationState.STOPPED; - } - } - ((AsyncControlDelegate) FUMLExecutionEngine.eInstance.getControlDelegate()).notifyThreadTermination(this); // Added for connection with debug api - } - - // Added for connection with debug API - /** - * Gets the current state. - * - * @return the current state - */ - public ObjectActivationState getCurrentState() { - return this.currentState; - } - - /** - * Causality is broken here in order to let the thread that emitted - * the signal to continue its execution. - * - * @param signalInstance - * the signal instance - */ - @Override - public synchronized void send(SignalInstance signalInstance) { - SignalInstance copy = (SignalInstance) signalInstance.copy(); - this.evtPool.send(copy); - AsyncDebug.println("[SignalInstance sent] " + signalInstance.type.getName()); - } - - // Added for connection with debug API - /** The has been waiting. */ - protected boolean hasBeenWaiting = false; - - /** - * Retrieve a SignalInstance stored in the event pool. - * - * @return the next event - */ - @Override - public SignalInstance getNextEvent() { - // Added for connection with debug API - if (this.evtPool.isEmpty()) { - this.currentState = ObjectActivationState.WAITING; - this.hasBeenWaiting = true; - ((AsyncControlDelegate) FUMLExecutionEngine.eInstance.getControlDelegate()).notifyWaitingStateEntered(this); - } - SignalInstance signalInstance = this.evtPool.getNextEvent(); - this.currentState = ObjectActivationState.RUNNING; - // - - if (signalInstance != null) { - AsyncDebug.println("[consumed SignalInstance] " + signalInstance.type.getName()); - } - return signalInstance; - } - - /** - * Start the event dispatch loop for this object activation (if it has - * not already been started). - * If a classifier is given that is a type of the object of this object - * activation and there is not already a classifier behavior execution - * for it, then create a classifier behavior execution for it. - * Otherwise, create a classifier behavior execution for each of the - * types of the object of this object activation which has a classifier - * behavior or which is a behavior itself - * and for which there is not currently a classifier behavior execution. - * Start EventDispatchLoop - * - * @param classifier - * the classifier - * @param inputs - * the inputs - */ - @Override - public void startBehavior(Class classifier, List<ParameterValue> inputs) { - /* 1. Start behavior of the current classifier */ - if (classifier == null) { - AsyncDebug.println("Starting behavior for all classifiers..."); - // *** Start all classifier behaviors concurrently. *** - List<Class> types = this.object.types; - for (Iterator<Class> i = types.iterator(); i.hasNext();) { - Class type = i.next(); - if (type instanceof Behavior | type.getClassifierBehavior() != null) { - this.startBehavior(type, new ArrayList<ParameterValue>()); - } - } - } else { - AsyncDebug.println("Starting behavior for " + classifier.getName() + "..."); - boolean notYetStarted = true; - int i = 1; - while (notYetStarted & i <= this.classifierBehaviorExecutions.size()) { - notYetStarted = (this.classifierBehaviorExecutions.get(i - 1).classifier != classifier); - i = i + 1; - } - if (notYetStarted) { - ClassifierBehaviorExecution newExecution = new ClassifierBehaviorExecution(); - newExecution.objectActivation = this; - this.classifierBehaviorExecutions.add(newExecution); - newExecution.execute(classifier, inputs); - } - } - - } - - /** - * Stop all the classifier behaviors. The current object activation enters the STOPPED state - */ - @Override - public void stop() { - /* 1. Terminate all of my classifier behaviors */ - super.stop(); - /* 2. Terminate my execution thread */ - this.currentState = ObjectActivationState.STOPPED; - } - - /** The out. */ - protected IOConsoleOutputStream out; - - /** - * 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 - */ - @Override - public void dispatchNextEvent() { - /* 1. Get next event is blocking if used on a empty event pool */ - SignalInstance signalInstance = this.getNextEvent(); - AsyncDebug.println("[dispatchNextEvent] signalInstance = " + signalInstance); - /* 2. Look for EventAccepter that match the selected 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); - } - } - /* 3. Choose one matching event accepter non-deterministically */ - if (matchingEventAccepterIndexes.size() > 0) { - 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); - this.waitingEventAccepters.remove(selectedEventAccepter); - if (this.hasBeenWaiting) { - this.hasBeenWaiting = false; - if (selectedEventAccepter instanceof AcceptEventActionEventAccepter) { - ((AsyncControlDelegate) FUMLExecutionEngine.eInstance.getControlDelegate()).notifyWaitingStateExit(this, (AcceptEventActionEventAccepter) selectedEventAccepter); - } - } - selectedEventAccepter.accept(signalInstance); - } else { - if (this.out == null) { - this.out = StandardOutputChannelImpl.getConsole().newOutputStream(); - } - - String expectedSignals = ""; - for (EventAccepter eventAccepter : this.waitingEventAccepters) { - if (eventAccepter instanceof AcceptEventActionEventAccepter) { - AcceptEventActionEventAccepter acceptEventAccepter = (AcceptEventActionEventAccepter) eventAccepter; - AcceptEventAction acceptEventAction = (AcceptEventAction) acceptEventAccepter.actionActivation.node; - for (Trigger trigger : acceptEventAction.getTriggers()) { - if (trigger.getEvent() instanceof SignalEvent) { - SignalEvent signalEvent = (SignalEvent) trigger.getEvent(); - Signal signal = signalEvent.getSignal(); - if (!expectedSignals.isEmpty()) { - expectedSignals += ", "; - } - expectedSignals += signal.getName(); - } - } - } - } - - final SignalInstance finalSignalInstance = signalInstance; - final String finalExpectedSignals = expectedSignals; - Display.getDefault().syncExec(new Runnable() { - - public void run() { - try { - out.setColor(new Color(null, new RGB(200, 120, 10))); - out.write("[ WARNING : Lost signal " + finalSignalInstance.getTypes().get(0).getName() + " (classifier behavior of " + classifier.getName() + " was waiting for " + finalExpectedSignals + ") ]\n"); - out.flush(); - } catch (IOException e) { - Activator.log.error(e); - } - } - }); - } - - - } -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/IAsyncEventPool.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/IAsyncEventPool.java deleted file mode 100644 index 0f4a97a524e..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/CommonBehaviors/Communications/IAsyncEventPool.java +++ /dev/null @@ -1,39 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.async.fuml.Semantics.CommonBehaviors.Communications; - -import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.SignalInstance; - -// TODO: Auto-generated Javadoc -/** - * Interface that need to be implemented by the AsyncEventPool. - * - * @author CEA LIST (t605650) - */ -public interface IAsyncEventPool { - - /** - * Send. - * - * @param signalInstance - * the signal instance - * @return true, if successful - */ - public boolean send(SignalInstance signalInstance); - - /** - * Gets the next event. - * - * @return the next event - */ - public SignalInstance getNextEvent(); -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/Loci/LociL1/AsyncLocus.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/Loci/LociL1/AsyncLocus.java deleted file mode 100644 index b3113476d09..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/Semantics/Loci/LociL1/AsyncLocus.java +++ /dev/null @@ -1,63 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.async.fuml.Semantics.Loci.LociL1; - -import org.eclipse.papyrus.moka.async.fuml.Semantics.Classes.Kernel.AsyncObject_; -import org.eclipse.papyrus.moka.composites.Semantics.Loci.LociL3.CS_Locus; -import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.ExtensionalValue; -import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Object_; -import org.eclipse.uml2.uml.Behavior; -import org.eclipse.uml2.uml.Class; - -// TODO: Auto-generated Javadoc -/** - * Extends the original Locus class. - * - * @author CEA LIST (jt605650) - */ -public class AsyncLocus extends CS_Locus { - - /** - * Instantiate method now create AsyncObject_ instead of Object_. - * - * @param type - * the type - * @return the object_ - */ - @Override - public Object_ instantiate(Class type) { - // Instantiate the given class at this locus. - Object_ object = null; - if (type instanceof Behavior) { - object = this.factory.createExecution((Behavior) type, null); - } else { - object = new AsyncObject_(); - object.types.add(type); - object.createFeatureValues(); - this.add(object); - } - return object; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.papyrus.moka.fuml.Semantics.Loci.LociL1.Locus#remove(org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.ExtensionalValue) - */ - @Override - public void remove(ExtensionalValue value) { - synchronized (this) { - super.remove(value); - } - } - -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/debug/AsyncControlDelegate.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/debug/AsyncControlDelegate.java deleted file mode 100644 index 72374b88cb1..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/debug/AsyncControlDelegate.java +++ /dev/null @@ -1,459 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.async.fuml.debug; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.ILaunchManager; -import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.papyrus.infra.core.Activator; -import org.eclipse.papyrus.moka.MokaConstants; -import org.eclipse.papyrus.moka.async.fuml.Semantics.CommonBehaviors.Communications.AsyncObjectActivation; -import org.eclipse.papyrus.moka.communication.event.Start_Event; -import org.eclipse.papyrus.moka.communication.event.isuspendresume.Resume_Event; -import org.eclipse.papyrus.moka.communication.event.isuspendresume.Suspend_Event; -import org.eclipse.papyrus.moka.communication.event.iterminate.Terminate_Event; -import org.eclipse.papyrus.moka.communication.request.isuspendresume.Resume_Request; -import org.eclipse.papyrus.moka.communication.request.isuspendresume.Suspend_Request; -import org.eclipse.papyrus.moka.communication.request.iterminate.Terminate_Request; -import org.eclipse.papyrus.moka.debug.MokaStackFrame; -import org.eclipse.papyrus.moka.debug.MokaThread; -import org.eclipse.papyrus.moka.engine.AbstractExecutionEngine; -import org.eclipse.papyrus.moka.fuml.FUMLExecutionEngine; -import org.eclipse.papyrus.moka.fuml.Semantics.Actions.CompleteActions.AcceptEventActionEventAccepter; -import org.eclipse.papyrus.moka.fuml.Semantics.Activities.IntermediateActivities.ActivityEdgeInstance; -import org.eclipse.papyrus.moka.fuml.Semantics.Activities.IntermediateActivities.ActivityExecution; -import org.eclipse.papyrus.moka.fuml.Semantics.Activities.IntermediateActivities.ActivityNodeActivation; -import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.ExtensionalValue; -import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Object_; -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.debug.ControlDelegate; -import org.eclipse.papyrus.moka.fuml.debug.FUMLThread; -import org.eclipse.papyrus.moka.fuml.presentation.FUMLPresentationUtils; -import org.eclipse.papyrus.moka.ui.presentation.AnimationUtils; -import org.eclipse.uml2.uml.AcceptEventAction; - -// TODO: Auto-generated Javadoc -/** - * The Class AsyncControlDelegate. - */ -public class AsyncControlDelegate extends ControlDelegate { - - /** The main thread. */ - protected FUMLThread mainThread; - - /** The object activations. */ - protected List<ObjectActivation> objectActivations = new ArrayList<ObjectActivation>(); - - /** The object activations to fuml thread. */ - protected Map<ObjectActivation, FUMLThread> objectActivationsToFUMLThread = new HashMap<ObjectActivation, FUMLThread>(); - - /** The terminate request by client. */ - protected boolean terminateRequestByClient = false; - - /** The locks. */ - protected Map<FUMLThread, Object> locks = new HashMap<FUMLThread, Object>(); - - /** - * Instantiates a new async control delegate. - * - * @param engine - * the engine - */ - public AsyncControlDelegate(AbstractExecutionEngine engine) { - super(engine); - this.threads = new ArrayList<FUMLThread>(); - this.objectActivationToWaitingAcceptEventActions = new HashMap<AsyncObjectActivation, List<AcceptEventAction>>(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.papyrus.moka.fuml.debug.ControlDelegate#getThreads() - */ - @Override - public synchronized MokaThread[] getThreads() { - return threads.toArray(new MokaThread[threads.size()]); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.papyrus.moka.fuml.debug.ControlDelegate#waitForTermination() - */ - @Override - public void waitForTermination() { - while (!this.engine.isTerminated()) { - synchronized (this) { - try { - wait(); - } catch (InterruptedException e) { - Activator.log.error(e); - } - } - } - } - - /** - * Resume fuml thread. - * - * @param thread - * the thread - * @param reasonForResuming - * the reason for resuming - */ - protected void resumeFUMLThread(FUMLThread thread, int reasonForResuming) { - thread.setSuspended(false); - thread.stepEnded(); - thread.setReasonForResuming(reasonForResuming); - thread.setReasonForSuspending(-1); - if (reasonForResuming == DebugEvent.STEP_OVER) { - thread.setIsStepping(true); - } - thread.setStackFrames(new IStackFrame[] {}); - Object lock = this.locks.get(thread); - synchronized (lock) { - this.locks.remove(thread); - lock.notify(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.papyrus.moka.fuml.debug.ControlDelegate#resume(org.eclipse.papyrus.moka.communication.request.isuspendresume.Resume_Request) - */ - @Override - public synchronized void resume(Resume_Request request) { - this.reasonForResuming = request.getResumeDetail(); - if (reasonForResuming != DebugEvent.CLIENT_REQUEST) { - reasonForResuming = DebugEvent.STEP_OVER; - } - IDebugElement elementToResume = request.getDebugElement(); - if (elementToResume instanceof IDebugTarget) { - // resume all threads - for (FUMLThread thread : this.threads) { - if (thread.isSuspended() && !thread.isWaiting()) { - this.resumeFUMLThread(thread, reasonForResuming); - } - } - } else { - // This is a thread - FUMLThread thread = (FUMLThread) request.getDebugElement(); - this.resumeFUMLThread(thread, reasonForResuming); - } - } - - /** - * Register object activation. - * - * @param activation - * the activation - * @param activationName - * the activation name - */ - public synchronized void registerObjectActivation(ObjectActivation activation, String activationName) { - FUMLThread fUMLThread = new FUMLThread(FUMLExecutionEngine.eInstance.getDebugTarget()); - this.threads.add(0, fUMLThread); - if (activation == null) { // this is the main thread - fUMLThread.setName("Main Thread"); - fUMLThread.setStackFrames(new IStackFrame[] {}); - mainThread = fUMLThread; - return; - } - objectActivations.add(activation); - this.objectActivationsToFUMLThread.put(activation, fUMLThread); - // This is a thread for an object activation, created in the course of execution - Start_Event event = new Start_Event(fUMLThread, getThreads()); - fUMLThread.setName(activationName + " (" + fUMLThread.hashCode() + ")"); - fUMLThread.setStackFrames(new IStackFrame[] {}); - FUMLExecutionEngine.eInstance.sendEvent(event); - } - - /** - * Register object activation. - * - * @param activation - * the activation - */ - public void registerObjectActivation(ObjectActivation activation) { - this.registerObjectActivation(activation, "ObjectActivation"); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.papyrus.moka.fuml.debug.ControlDelegate#terminate(org.eclipse.papyrus.moka.communication.request.iterminate.Terminate_Request) - */ - @Override - public void terminate(Terminate_Request request) { - engine.setIsTerminated(true); - this.terminateRequestByClient = true; - for (List<AcceptEventAction> waitingOn : this.objectActivationToWaitingAcceptEventActions.values()) { - for (EObject o : waitingOn) { - AnimationUtils.getInstance().removeAnimationMarker(o); - } - } - /**********/ - // 439639: [Moka] oepm.async.fuml.debug.AsyncControlDelegate.terminate shall send a TerminateSignalInstance to all objects in the execution locus - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=439639 - for (ExtensionalValue v : FUMLExecutionEngine.eInstance.getLocus().extensionalValues) { - if (v instanceof Object_) { - ((Object_) v).send(new TerminateSignalInstance()); - } - } - // for(ObjectActivation activation : objectActivations) { - // if(activation != null /* && ((AsyncObjectActivation)activation).getCurrentState() == ObjectActivationState.WAITING */) { - // //activation.send(new TerminateSignalInstance()); - // activation.object.send(new TerminateSignalInstance()) ; - // } - // } - /***********/ - for (Object lock : this.locks.values()) { - synchronized (lock) { - lock.notify(); - } - } - synchronized (this) { - notifyAll(); - } - AnimationUtils.getInstance().removeAllAnimationMarker(); - } - - /** - * Notify thread termination. - * - * @param objectActivation - * the object activation - */ - public synchronized void notifyThreadTermination(ObjectActivation objectActivation) { - if (this.terminateRequestByClient) - { - return; // do nothing - } - if (!FUMLExecutionEngine.eInstance.isTerminated()) { - FUMLThread fUMLThread = this.objectActivationsToFUMLThread.get(objectActivation); - if (fUMLThread != null) { - fUMLThread.setIsTerminated(true); - this.threads.remove(fUMLThread); - } - Terminate_Event terminateEvent = null; - if (this.threads.isEmpty()) { - this.engine.setIsTerminated(true); - synchronized (this) { - notifyAll(); - } - terminateEvent = new Terminate_Event(this.engine.getDebugTarget(), this.getThreads()); - } else if (fUMLThread != null) { - terminateEvent = new Terminate_Event(fUMLThread, this.getThreads()); - } - // else { - // terminateEvent = new Terminate_Event(this.engine.getDebugTarget(), this.getThreads()) ; - // } - if (terminateEvent != null) { - FUMLExecutionEngine.eInstance.sendEvent(terminateEvent); - } - } - - } - - /** - * Notify main thread logically ended. - */ - public synchronized void notifyMainThreadLogicallyEnded() { - if (this.terminateRequestByClient) - { - return; // do nothing - } - this.mainThread.setIsTerminated(true); - Terminate_Event terminateEvent; - this.threads.remove(mainThread); - if (this.threads.isEmpty()) { - this.engine.setIsTerminated(true); - synchronized (this) { // FIXME - notifyAll(); - } - terminateEvent = new Terminate_Event(this.engine.getDebugTarget(), this.getThreads()); - } else { - terminateEvent = new Terminate_Event(mainThread, this.getThreads()); - } - FUMLExecutionEngine.eInstance.sendEvent(terminateEvent); - } - - - - /* - * (non-Javadoc) - * - * @see org.eclipse.papyrus.moka.fuml.debug.ControlDelegate#suspend(org.eclipse.papyrus.moka.communication.request.isuspendresume.Suspend_Request) - */ - @Override - public synchronized void suspend(Suspend_Request request) { - if (request.getDebugElement() instanceof IDebugTarget) { - for (FUMLThread thread : this.threads) { - thread.setReasonForSuspending(request.getSuspendDetail()); - thread.setIsStepping(false); - } - } else { // This is a thread - FUMLThread thread = (FUMLThread) request.getDebugElement(); - thread.setReasonForSuspending(request.getSuspendDetail()); - thread.setIsStepping(false); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.papyrus.moka.fuml.debug.ControlDelegate#control(java.lang.Object) - */ - @Override - public boolean control(Object object) { - if (this.engine.isTerminated()) { - return false; - } - - // Retrieves the semantic element - EObject semanticElement = null; - Object_ executionContext = null; - if (object instanceof ActivityNodeActivation) { - semanticElement = ((ActivityNodeActivation) object).node; - if (((ActivityNodeActivation) object).group != null) { - executionContext = ((ActivityNodeActivation) object).getExecutionContext(); - } - } else if (object instanceof ActivityEdgeInstance) { - semanticElement = ((ActivityEdgeInstance) object).edge; - if (((ActivityEdgeInstance) object).group != null) { - executionContext = ((ActivityEdgeInstance) object).group.getActivityExecution().context; - } - } else { - Activator.log.error(new Exception("Unexpected element in ControlDelegate::control")); - this.engine.setIsTerminated(true); - return false; - } - - if (executionContext != null) { - try { - FUMLThread thread = null; - if (executionContext instanceof ActivityExecution) { - // Execution takes place in the context of the Main thread - thread = this.mainThread; - } else { - ObjectActivation objectActivation = executionContext.objectActivation; - thread = this.objectActivationsToFUMLThread.get(objectActivation); - if (thread == null) { // This means that the context is a passive object executing in the context of the main thread ?? TODO check this... - thread = this.mainThread; - } - } - if (semanticElement != null && MokaConstants.MOKA_AUTOMATIC_ANIMATION && this.mode.equals(ILaunchManager.DEBUG_MODE) && !thread.isStepping()) { - this.animate(semanticElement); - } - int reasonForSuspending = -1; - if (thread.getReasonForSuspending() != -1) { - reasonForSuspending = thread.getReasonForSuspending(); - } else if (thread.getReasonForResuming() != DebugEvent.CLIENT_REQUEST) { - reasonForSuspending = DebugEvent.STEP_END; - } else if (this.elementsWithBreakpoints.contains(semanticElement)) { // Tries to check if a breakpoint applies - reasonForSuspending = DebugEvent.BREAKPOINT; - } - if (reasonForSuspending != -1) { - thread.setSuspended(true); - thread.setReasonForSuspending(reasonForSuspending); - MokaStackFrame stackFrame = FUMLPresentationUtils.getMokaStackFrame(object); - stackFrame.setThread(thread); - thread.setStackFrames(new IStackFrame[] { stackFrame }); - Suspend_Event suspendEvent = new Suspend_Event(thread, reasonForSuspending, this.getThreads()); - engine.sendEvent(suspendEvent); - String lock = new String(); - this.locks.put(thread, lock); - synchronized (lock) { - lock.wait(); - } - } - } catch (InterruptedException e) { - Activator.log.error(e); - } - } - - return !this.engine.isTerminated(); - } - - /** The object activation to waiting accept event actions. */ - protected Map<AsyncObjectActivation, List<AcceptEventAction>> objectActivationToWaitingAcceptEventActions; - - /** - * Notify waiting state entered. - * - * @param asyncObjectActivation - * the async object activation - */ - public void notifyWaitingStateEntered(AsyncObjectActivation asyncObjectActivation) { - FUMLThread thread = this.objectActivationsToFUMLThread.get(asyncObjectActivation); - if (thread != null) { - thread.setIsWaiting(true); - thread.setSuspended(true); - thread.setStackFrames(new IStackFrame[] {}); - if (MokaConstants.MOKA_AUTOMATIC_ANIMATION && this.mode.equals(ILaunchManager.DEBUG_MODE)) { - Suspend_Event suspendEvent = new Suspend_Event(thread, DebugEvent.CHANGE, this.getThreads()); - engine.sendEvent(suspendEvent); - List<AcceptEventAction> waitingAcceptEventActions = new ArrayList<AcceptEventAction>(); - for (EventAccepter eventAccepter : asyncObjectActivation.waitingEventAccepters) { - if (eventAccepter instanceof AcceptEventActionEventAccepter) { - AcceptEventAction action = (AcceptEventAction) ((AcceptEventActionEventAccepter) eventAccepter).actionActivation.node; - waitingAcceptEventActions.add(action); - AnimationUtils.getInstance().addAnimationMarker(action); - } - } - objectActivationToWaitingAcceptEventActions.put(asyncObjectActivation, waitingAcceptEventActions); - } - } - } - - /** - * Notify waiting state exit. - * - * @param asyncObjectActivation - * the async object activation - * @param accepter - * the accepter - */ - public void notifyWaitingStateExit(AsyncObjectActivation asyncObjectActivation, AcceptEventActionEventAccepter accepter) { - FUMLThread thread = this.objectActivationsToFUMLThread.get(asyncObjectActivation); - if (thread != null) { - thread.setIsWaiting(false); - thread.setSuspended(false); - thread.setStackFrames(new IStackFrame[] {}); - if (MokaConstants.MOKA_AUTOMATIC_ANIMATION && this.mode.equals(ILaunchManager.DEBUG_MODE)) { - Resume_Event resumeEvent = new Resume_Event(thread, DebugEvent.CHANGE, this.getThreads()); - engine.sendEvent(resumeEvent); - List<AcceptEventAction> waitingAcceptEventActions = objectActivationToWaitingAcceptEventActions.get(asyncObjectActivation); - AcceptEventAction action = (AcceptEventAction) accepter.actionActivation.node; - if (waitingAcceptEventActions != null) { - waitingAcceptEventActions.remove(action); - } else { - waitingAcceptEventActions = new ArrayList<AcceptEventAction>(); - } - objectActivationToWaitingAcceptEventActions.put(asyncObjectActivation, waitingAcceptEventActions); - if (action != null) { - AnimationUtils.getInstance().removeAnimationMarker(action); - } - } - } - } -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/debug/AsyncDebug.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/debug/AsyncDebug.java deleted file mode 100644 index b5165c63988..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/debug/AsyncDebug.java +++ /dev/null @@ -1,42 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.async.fuml.debug; - -import org.eclipse.papyrus.moka.fuml.debug.Debug; - -// TODO: Auto-generated Javadoc -/** - * The Class AsyncDebug. - */ -public class AsyncDebug extends Debug { - - /** - * Println. - * - * @param message - * the message - */ - public static void println(String message) { - // int remainingSpaces = 30-Thread.currentThread().getName().length(); - // if(remainingSpaces < 0){ - // System.out.println( - // String.format("%s", "["+Thread.currentThread().getName()+"]") - // +message); - // }else{ - // int sideSpaceCount = remainingSpaces/2; - // System.out.println( - // String.format("[%"+sideSpaceCount+"s%s%"+sideSpaceCount+"s]", " ", - // Thread.currentThread().getName() - // ," ")+message); - // } - } -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/debug/TerminateSignalInstance.java b/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/debug/TerminateSignalInstance.java deleted file mode 100644 index 094b9ce384e..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.async.fuml/src/org/eclipse/papyrus/moka/async/fuml/debug/TerminateSignalInstance.java +++ /dev/null @@ -1,38 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.async.fuml.debug; - -import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.Communications.SignalInstance; -import org.eclipse.uml2.uml.Signal; -import org.eclipse.uml2.uml.UMLFactory; - -// TODO: Auto-generated Javadoc -/** - * The Class TerminateSignalInstance. - */ -public class TerminateSignalInstance extends SignalInstance { - - /** The terminate signal. */ - protected static Signal terminateSignal; - - /** - * Instantiates a new terminate signal instance. - */ - public TerminateSignalInstance() { - if (terminateSignal == null) { - terminateSignal = UMLFactory.eINSTANCE.createSignal(); - terminateSignal.setName("TerminateSignal"); - } - this.type = terminateSignal; - } - -} |