1 | package de.uka.ipd.sdq.codegen.simucontroller.workflow.jobs; |
2 | |
3 | import org.eclipse.core.runtime.IProgressMonitor; |
4 | |
5 | import de.uka.ipd.sdq.codegen.simucontroller.SimuControllerPlugin; |
6 | import de.uka.ipd.sdq.codegen.simucontroller.debug.IDebugListener; |
7 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.DockModel; |
8 | import de.uka.ipd.sdq.codegen.simucontroller.runconfig.AbstractSimulationWorkflowConfiguration; |
9 | import de.uka.ipd.sdq.simucomframework.simulationdock.SimulationDockService; |
10 | import de.uka.ipd.sdq.simucomframework.simulationdock.SimulationDockServiceImpl; |
11 | import de.uka.ipd.sdq.workflow.IJob; |
12 | import de.uka.ipd.sdq.workflow.IJobWithResult; |
13 | import de.uka.ipd.sdq.workflow.exceptions.JobFailedException; |
14 | import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException; |
15 | import de.uka.ipd.sdq.workflow.launchconfig.extension.AbstractExtendableJob; |
16 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard; |
17 | |
18 | /** |
19 | * Installs a Plug-In from the specified location string with use a bundles |
20 | * context.The context is used to grant access to other methods so that this |
21 | * bundle can interact with the Framework. |
22 | */ |
23 | public class TransferSimulationBundleToDock extends AbstractExtendableJob<MDSDBlackboard> { |
24 | |
25 | /** |
26 | * This job's parent job which creates a JAR archive of the simulation bundle |
27 | */ |
28 | private IJobWithResult<byte[]> myCreatePluginProjectJob; |
29 | |
30 | /** |
31 | * Configuration object for the simulation |
32 | */ |
33 | private AbstractSimulationWorkflowConfiguration myConfig; |
34 | |
35 | private boolean isDebug; |
36 | |
37 | private IDebugListener debugListener; |
38 | |
39 | public TransferSimulationBundleToDock( |
40 | AbstractSimulationWorkflowConfiguration configuration, |
41 | IDebugListener debugListener, |
42 | IJobWithResult<byte[]> createPluginJarJob) { |
43 | super(); |
44 | |
45 | this.myCreatePluginProjectJob = createPluginJarJob; |
46 | this.myConfig = configuration; |
47 | this.debugListener = debugListener; |
48 | this.isDebug = configuration.isDebug(); |
49 | handleJobExtensions(WorkflowHooks.WORKFLOW_ID_AFTER_DOCK,configuration); |
50 | } |
51 | |
52 | public void execute(IProgressMonitor monitor) throws JobFailedException, UserCanceledException { |
53 | |
54 | |
55 | assert (myCreatePluginProjectJob != null); |
56 | |
57 | try { |
58 | DockModel dock = SimuControllerPlugin.getDockModel().getBestFreeDock(); |
59 | SimulationDockService simService = dock.getService(); |
60 | if (isDebug) { |
61 | debugListener.simulationStartsInDock(dock); |
62 | } |
63 | simService.load( |
64 | myConfig.getSimulationConfiguration(), |
65 | myCreatePluginProjectJob.getResult(), |
66 | dock.isRemote()); |
67 | |
68 | // Execute extension jobs first |
69 | // TODO: don't call this here. Put TransferSimulationBundleToDock job logic into a separate job that is nested in a OrderPreservingCompositeJob |
70 | // together with the extension jobs |
71 | for (IJob extensionJob : myJobs) { |
72 | if (extensionJob instanceof AbstractSimuComExtensionJob) { |
73 | ((AbstractSimuComExtensionJob)extensionJob).setSimuComModel(((SimulationDockServiceImpl)simService).getSimuComModel()); |
74 | } |
75 | } |
76 | super.execute(monitor); |
77 | |
78 | |
79 | simService.simulate( |
80 | myConfig.getSimulationConfiguration(), |
81 | myCreatePluginProjectJob.getResult(), |
82 | dock.isRemote()); |
83 | } catch (InterruptedException e) { |
84 | throw new JobFailedException("Job failed while waiting for a dock to become available",e); |
85 | } |
86 | catch (Exception e) { |
87 | throw new JobFailedException("Simulation run failed.",e); |
88 | } |
89 | finally { |
90 | if (isDebug) { |
91 | this.debugListener.simulationStoppedInDock(); |
92 | } |
93 | } |
94 | } |
95 | |
96 | public String getName() { |
97 | return "Transfer Plugin to Dock and Simulate"; |
98 | } |
99 | |
100 | } |