Class HeadlessApplication<S extends org.eclipse.emf.ecore.EObject,M extends Model>

java.lang.Object
com.amalgamasimulation.studies.headlessapp.HeadlessApplication<S,M>
All Implemented Interfaces:
IHeadlessApplication

public class HeadlessApplication<S extends org.eclipse.emf.ecore.EObject,M extends Model> extends Object implements IHeadlessApplication
An application that accepts tasks (e.g. simulation tasks) via HTTP API and runs them in parallel.

Java API:
1. Submit a new task: submitTask(ShortId, String, int).
2. Gracefully stop a running task / prevent a submitted but not yet running task from running: stopTask(ShortId).
3. Get task progress and status: getProgressAndStatus(), hasTasksInProgress() .
4. Stop a single task or all tasks: stopTask(ShortId),stopAll().
5. Remove a task from the list of known tasks: deleteTask(ShortId).
For more details see IHeadlessApplication interface javadocs.

HTTP API is provided by an instance of the HeadlessHTTPServer class.

This class is designed to be agnostic of any concrete Model/Scenario implementations. Scenario file reading, model creation, and simulation result extraction logic are all passed as class constructor parameters.

A typical use case for this class is as follows:

 
 new HeadlessApplication<>(
                              OpenpitDataTransform.transform::createLoader,
                              (theScenario, theSeed, engine) -> new Model(theScenario, engine, new Mapping(), true, theSeed),
                              OpenpitResult::new,
                              httpPort());
 
 
Here, a HeadlessApplication instance receives an object to read a scenario file, a model creator, and a simulation result extractor. The last parameter denotes the HTTP port number the application will listen.
  • Constructor Details

    • HeadlessApplication

      public HeadlessApplication(Function<String,com.amalgamasimulation.emf.excel.EMFExcelLoader<S>> scenarioLoaderSupplier, ModelCreator<S,M> modelCreator, Function<M,SimulationRunResult> resultGenerator, int httpPort)
      Creates a new instance of HeadlessApplication. Use this constructor when creating a SimulationRunResult from the model object is expected to be fast (within seconds). Otherwise, consider using another constructor which allows reporting the progress of SimulationRunResult generation.
      Parameters:
      scenarioLoaderSupplier - function that accepts path to the scenario file (as String) and produces a EMFExcelLoader object to load the scenario
      modelCreator - function that accepts a Scenario object and creates a Model object
      resultGenerator - function that created SimulationRunResult from the Model object after the simulation has completed
      httpPort - HTTP port that this headless application will listen to
  • Method Details