|
Re: Web interface? [message #562706 is a reply to message #562680] |
Fri, 19 March 2010 16:17 |
Matthew Davis Messages: 269 Registered: July 2009 |
Senior Member |
|
|
Hi Doug,
We have some internal work on a Web-based STEM interface, but it's not really in a condition for public release at this time. It's really more of a proof-of-concept/what we can do. Right now, it's just a collection of JSON-generating servlets with a Dojo interface and visualizer built with Google Maps. Simulation controls are mainly related to state (start, stop, etc). The underlying container is running Jetty as an Eclipse plug-in. See: http://www.eclipse.org/equinox/server/
As for the hooks to control STEM through an API, my recommendation is that you start by looking at the SimulationManager and Simulation classes in in the org.eclipse.stem.jobs plug-in.
To initialize and run a headless simulation, pulling from our Web code, here's a very simple set of steps. Obviously any real system will be more advanced, but this is a basic startup. Note that the project name and scenario name correspond to projects and scenarios you created using the STEM UI.
import org.eclipse.emf.common.util.URI;
import org.eclipse.stem.core.Utility;
import org.eclipse.stem.core.scenario.Scenario;
import org.eclipse.stem.jobs.simulation.SimulationManager;
import org.eclipse.stem.jobs.simulation.ISimulation;
import org.eclipse.stem.jobs.simulation.Simulation;
...
String projectName = "somestemproject";
String scenarioName = "somescenarioname.scenario";
// Get the internal URI to the Scenario resource file in the workspace
URI scenarioUri = URI.createURI("platform:/resource/"+ projectName +"/scenarios/"+ scenarioName);
// Load the scenario from file
Scenario scenario = (Scenario)Utility.getIdentifiable(scenarioUri);
// Get the simulation manager
SimulationManager mgr = SimulationManager.getManager();
// Create a runnable simulation from the given scenario
ISimulation sim = mgr.createSimulation(scenario);
// Run the simulation
mgr.runSimulation(sim);
|
|
|
|
|
Re: Web interface? [message #563107 is a reply to message #562706] |
Tue, 06 April 2010 21:41 |
Doug Messages: 30 Registered: March 2010 |
Member |
|
|
I am still having trouble with this... I have what are probably lots of very basic questions. I have very limited time available to try to learn Eclipse and STEM, so perhaps this just isn't going to work out right now.
To simplify, I dropped the web app part for now and just want to create a standalone, command line version of STEM where parameters can be passed to specify the scenario, for example. I started with the code from Matt above, but swapped the last 4 lines for:
// Create a runnable simulation from the given scenario and run it
mgr.createAndRunSimulation(scenario);
(the version above was causing errors, but I don't recall what off the top of my head)
I assume I want to develop my command line driver as a plug-in, then set up a product configuration to export it as a standalone Eclipse application (I still can't seem to get that working for STEM itself, per http://www.eclipse.org/forums/index.php?t=msg&th=165083& amp;start=0&).
I have scenarios created from the version of STEM I downloaded, but can't seem to load them. Where would I need to copy/import/??? my "US-Flu" project in order to load its "test.scenario"?
If I run as a Java application, my working directory = C:\Documents and Settings\drafalsk\workspace\headlessSTEM, and
scenarioUri.toString() = platform:/resource/US-Flu/scenarios/test.scenario
scenarioUri.toFileString() = null
The code
Scenario scenario = (Scenario)Utility.getIdentifiable(scenarioUri);
Then fails withQuote:
> The serialized instance of an Identifiable at "platform:/resource/USFlu/scenarios/test.scenario" was not found or was of the wrong format
|
|
|
Powered by
FUDForum. Page generated in 0.02823 seconds