All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fUML.Semantics.CommonBehaviors.Communications.ExecutionQueue Maven / Gradle / Ivy

Go to download

This open source software is a reference implementation, consisting of software and related files, for the OMG specification called the Semantics of a Foundational Subset for Executable UML Models (fUML). The reference implementation is intended to implement the execution semantics of UML activity models, accepting an XMI file from a conformant UML model as its input and providing an execution trace of the selected activity model(s) as its output. The core execution engine, which is directly generated from the normative syntactic and semantic models for fUML, may also be used as a library implementation of fUML in other software.

There is a newer version: 1.5.0a
Show newest version
/*
 * Initial version copyright 2008 Lockheed Martin Corporation, except  
 * as stated in the file entitled Licensing-Information. 
 * 
 * Modifications copyright 2009-2017 Data Access Technologies, Inc.
 *
 * Licensed under the Academic Free License version 3.0 
 * (http://www.opensource.org/licenses/afl-3.0.php), except as stated 
 * in the file entitled Licensing-Information. 
 */

package fUML.Semantics.CommonBehaviors.Communications;

import java.util.ArrayList;

import fUML.Debug;
import fUML.Semantics.CommonBehaviors.BasicBehaviors.Execution;

public class ExecutionQueue {
	
	private ArrayList queue = new ArrayList();

	private void run() {
		while (this.runNext());
	}
	
    private boolean runNext() {
		if (this.queue.size() == 0) {
			return false;
		} else {
			Execution execution = this.queue.get(0);
			this.queue.remove(0);
			if (execution.context.getTypes().size() > 0) {
				Debug.println("[runNext] execution = " + execution);
				execution.execute();
			}
			return true;
		}
    }
	
	private void add(Execution execution) {
		queue.add(execution);
	}
	
	private static ExecutionQueue executionQueue;
	
	public static boolean notStarted() {
		return executionQueue == null;
	}
	
	public static void start(Execution execution) {
		// Debug.println("[start] execution = " + execution);
		executionQueue = new ExecutionQueue();
		executionQueue.add(execution);
		executionQueue.run();
		executionQueue = null;
	}
	
	public static boolean step() {
		return executionQueue.runNext();
	}
	
	public static void enqueue(Execution execution) {
		if (notStarted()) {
			start(execution);
		} else {
			Debug.println("[enqueue] execution = " + execution);
			executionQueue.add(execution);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy