1 | package de.uka.ipd.sdq.pcmsolver; |
2 | |
3 | import org.apache.log4j.BasicConfigurator; |
4 | import org.apache.log4j.Logger; |
5 | import org.apache.log4j.PatternLayout; |
6 | import org.apache.log4j.WriterAppender; |
7 | import org.eclipse.core.runtime.CoreException; |
8 | import org.eclipse.core.runtime.IProgressMonitor; |
9 | import org.eclipse.debug.core.ILaunchConfiguration; |
10 | import org.eclipse.ui.console.ConsolePlugin; |
11 | import org.eclipse.ui.console.IConsole; |
12 | import org.eclipse.ui.console.MessageConsole; |
13 | |
14 | import de.uka.ipd.sdq.pcmsolver.models.PCMInstance; |
15 | import de.uka.ipd.sdq.pcmsolver.runconfig.MessageStrings; |
16 | import de.uka.ipd.sdq.pcmsolver.transformations.SolverStrategy; |
17 | import de.uka.ipd.sdq.probfunction.math.IProbabilityFunctionFactory; |
18 | import de.uka.ipd.sdq.probfunction.math.PDFConfiguration; |
19 | |
20 | /** |
21 | * The central class that controls the PCM Solver process when launched from the |
22 | * eclipse UI. |
23 | * |
24 | * This class is deprecated by now (?). |
25 | * |
26 | * @see Heiko's dissertation, chapter 6 at |
27 | * http://docserver.bis.uni-oldenburg.de |
28 | * /_publikationen/dissertation/2008/kozpar08/pdf/kozpar08.pdf |
29 | * @author koziolek, brosch |
30 | * |
31 | */ |
32 | public class PCMSolver { |
33 | |
34 | /** |
35 | * A console for output of PCm Solver results. |
36 | */ |
37 | private static MessageConsole messageConsole; |
38 | |
39 | /** |
40 | * Retrieves the PCM Solver console. |
41 | * |
42 | * @return the PCM Solver console |
43 | */ |
44 | public static MessageConsole getConsole() { |
45 | return messageConsole; |
46 | } |
47 | |
48 | /** |
49 | * Enables log4j logging for this class. |
50 | */ |
51 | private static Logger logger = Logger.getLogger(PCMSolver.class.getName()); |
52 | |
53 | /** |
54 | * Configuration details constant. |
55 | */ |
56 | private static final int DOMAINSIZEDEFAULT = 32; |
57 | |
58 | /** |
59 | * Configuration details constant. |
60 | */ |
61 | private static final double DISTANCEDEFAULT = 1.0; |
62 | |
63 | /** |
64 | * Wrapper object for the model parts belonging to the PCM instance. |
65 | */ |
66 | private PCMInstance currentModel; |
67 | |
68 | /** |
69 | * References the progress monitor associated with the launch. |
70 | */ |
71 | private IProgressMonitor monitor; |
72 | |
73 | /** |
74 | * Indicates the actual type of the PCM solving process. The user can choose |
75 | * between different types through the launch configuration. |
76 | */ |
77 | private SolverStrategy strategy; |
78 | |
79 | /** |
80 | * The constructor. |
81 | * |
82 | * Configures the PCM Solver process according to the launch configuration |
83 | * defined by the user. |
84 | * |
85 | * @param configuration |
86 | * the launch configuration |
87 | * @param monitor |
88 | * the progress monitor |
89 | * @param reliability |
90 | * enables reliability analysis |
91 | */ |
92 | public PCMSolver(final ILaunchConfiguration configuration, |
93 | final IProgressMonitor monitor, final boolean reliability) { |
94 | |
95 | // Set the progress monitor: |
96 | this.monitor = monitor; |
97 | |
98 | // Configure log4j logging: |
99 | configureLogging(configuration); |
100 | |
101 | // Determine the PCM model parts from the launch configuration: |
102 | currentModel = new PCMInstance(configuration); |
103 | |
104 | // Determine configuration details: |
105 | int domainSize = DOMAINSIZEDEFAULT; |
106 | double distance = DISTANCEDEFAULT; |
107 | String solver = MessageStrings.SRE_SOLVER; |
108 | try { |
109 | domainSize = Integer.parseInt(configuration.getAttribute( |
110 | MessageStrings.MAX_DOMAIN, "" + DOMAINSIZEDEFAULT)); |
111 | distance = Double.parseDouble(configuration.getAttribute( |
112 | MessageStrings.SAMPLING_DIST, "" + DISTANCEDEFAULT)); |
113 | solver = configuration.getAttribute(MessageStrings.SOLVER, |
114 | MessageStrings.SRE_SOLVER); |
115 | } catch (CoreException e) { |
116 | e.printStackTrace(); |
117 | } |
118 | |
119 | // Configure the PCM Solver process: |
120 | PDFConfiguration.setCurrentConfiguration(domainSize, distance, |
121 | IProbabilityFunctionFactory.eINSTANCE.createDefaultUnit()); |
122 | if (reliability) { |
123 | // strategy = new Pcm2MarkovStrategy(configuration); |
124 | } else if (solver.equals(MessageStrings.SRE_SOLVER)) { |
125 | // strategy = new Pcm2RegExStrategy(); |
126 | } else if (solver.equals(MessageStrings.LQNS_SOLVER)) { |
127 | // strategy = new Pcm2LqnStrategy(configuration); |
128 | } else if (solver.equals(MessageStrings.LQSIM_SOLVER)) { |
129 | // strategy = new Pcm2LqnStrategy(configuration); |
130 | } |
131 | } |
132 | |
133 | /** |
134 | * The constructor with default value for reliability (FALSE). |
135 | * |
136 | * This constructor is maintained for being downwards compatible with the |
137 | * former PCM Solver version, which did not support reliability analysis. |
138 | * |
139 | * @param configuration |
140 | * the launch configuration |
141 | * @param monitor |
142 | * the progress monitor |
143 | */ |
144 | public PCMSolver(final ILaunchConfiguration configuration, |
145 | final IProgressMonitor monitor) { |
146 | this(configuration, monitor, false); |
147 | } |
148 | |
149 | /** |
150 | * Executes the PCM Solver process. |
151 | */ |
152 | public void execute() { |
153 | |
154 | // Check the model for being valid: |
155 | if (!currentModel.isValid()) { |
156 | logger.error("PCM Instance invalid! Check filenames."); |
157 | return; |
158 | } |
159 | |
160 | // Only a very coarse progress monitoring is supported, which assigns |
161 | // 50% progress to the execution of the involved transformation(s), and |
162 | // 50% to the final solving: |
163 | monitor.beginTask("Analysis", 100); |
164 | strategy.transform(currentModel); |
165 | monitor.worked(50); |
166 | strategy.solve(); |
167 | monitor.worked(50); |
168 | } |
169 | |
170 | /** |
171 | * Configures the log4j logging capability. |
172 | * |
173 | * @param configuration |
174 | * the launch configuration |
175 | */ |
176 | private void configureLogging(final ILaunchConfiguration configuration) { |
177 | |
178 | // Set the layout for logging messages: |
179 | PatternLayout myLayout = new PatternLayout( |
180 | "%d{HH:mm:ss,SSS} [%t] %-5p %c - %m%n"); |
181 | |
182 | // Define and configure a new message console: |
183 | if (messageConsole == null) { |
184 | messageConsole = new MessageConsole( |
185 | "PCM Solver Console: Analysis Tool Output", null); |
186 | ConsolePlugin.getDefault().getConsoleManager().addConsoles( |
187 | new IConsole[] { messageConsole }); |
188 | } |
189 | |
190 | // Switch to this console if any other console is active: |
191 | messageConsole.activate(); |
192 | |
193 | // Enable writing to the console: |
194 | BasicConfigurator.resetConfiguration(); |
195 | BasicConfigurator.configure(new WriterAppender(myLayout, messageConsole |
196 | .newMessageStream())); |
197 | |
198 | //Anne: Now superfluous, logging is handled by the ...ConfgurationDelegates |
199 | // Adapt the logging level to the choice of the user: |
200 | /* boolean verboseLogging = false; |
201 | try { |
202 | verboseLogging = configuration.getAttribute( |
203 | MessageStrings.VERBOSE_LOGGING, false); |
204 | } catch (CoreException e) { |
205 | e.printStackTrace(); |
206 | } |
207 | Logger.getRootLogger().setLevel( |
208 | (verboseLogging) ? Level.DEBUG : Level.INFO);*/ |
209 | } |
210 | |
211 | public SolverStrategy getStrategy() { |
212 | return strategy; |
213 | } |
214 | } |