use of edu.uah.rsesc.aadlsimulator.services.SimulationEngineChangeListener in project AGREE by loonwerks.
the class DefaultSimulationService method createEngine.
@Override
public SimulationEngine createEngine(final EngineType engineType, final SystemInstance systemInstance) {
Objects.requireNonNull(engineType, "engineType must not be null");
Objects.requireNonNull(engineType, "systemInstance must not be null");
if (!(engineType instanceof DefaultEngineType)) {
throw new IllegalArgumentException("engineType must be an engine type provided by this simulation service");
}
final DefaultEngineType defaultEngineType = (DefaultEngineType) engineType;
final SimulationEngine newSimulationEngine = defaultEngineType.factory.create(systemInstance, masterExceptionHandler);
// Notify listeners of the new simulation engine
for (final SimulationEngineChangeListener l : simulationEngineChangeListeners) {
l.onSimulationEngineCreated(newSimulationEngine);
}
return newSimulationEngine;
}
use of edu.uah.rsesc.aadlsimulator.services.SimulationEngineChangeListener in project AGREE by loonwerks.
the class SimulationLaunchConfigurationDelegate method launch.
@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
SimulationService simulationService = null;
try {
simulationService = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()).get(SimulationService.class);
Objects.requireNonNull(configuration, "configuration must not be null");
// Find the component implementation
final String componentImplementationName = configuration.getAttribute(SimulationLaunchConfigurationAttributes.COMPONENT_IMPLEMENTATION_NAME, (String) null);
final String projectName = configuration.getAttribute(SimulationLaunchConfigurationAttributes.PROJECT_NAME, (String) null);
final IProject project = projectName == null ? null : findProject(projectName);
final EObject obj = componentImplementationName == null ? null : findComponentImplementation(project, componentImplementationName);
if (obj instanceof ComponentImplementation) {
// Refresh the component implementation
final ComponentImplementation ci = refreshComponentImplementation((ComponentImplementation) obj);
// (Re)instantiate the model
final SystemInstance systemInstance = InstantiateModel.buildInstanceModelFile(ci);
// Get the selected simulation engine type.
final String selectedEngineTypeId = Objects.requireNonNull(configuration.getAttribute(SimulationLaunchConfigurationAttributes.ENGINE_TYPE_ID, (String) null), "Simulation Engine must be specified");
final EngineType engineType = Objects.requireNonNull(simulationService.getEngineTypeById(selectedEngineTypeId), "Unable to find specified simulation engine");
final SimulationEngine newEngine = simulationService.createEngine(engineType, systemInstance);
final SimulationService simService = simulationService;
simulationService.addSimulationEngineChangeListener(new SimulationEngineChangeListener() {
@Override
public void onSimulationEngineCreated(final SimulationEngine engine) {
}
@Override
public void onSimulationEngineDisposed(final SimulationEngine engine) {
if (engine == newEngine) {
DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
simService.removeSimulationEngineChangeListener(this);
}
}
});
if (launch instanceof SimulationLaunch) {
((SimulationLaunch) launch).setSimulationEngine(newEngine);
}
} else {
simulationService.getExceptionHandler().handleException(new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Unable to find Component Implementation.")));
}
} catch (final Exception e) {
DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
if (simulationService == null) {
throw new RuntimeException(e);
} else {
simulationService.getExceptionHandler().handleException(e);
}
}
}
Aggregations