1 | package de.uka.ipd.sdq.simucomframework.calculator; |
2 | |
3 | import java.util.Vector; |
4 | |
5 | import javax.measure.Measure; |
6 | import javax.measure.quantity.Quantity; |
7 | |
8 | import org.apache.log4j.Logger; |
9 | import org.eclipse.core.runtime.CoreException; |
10 | |
11 | import de.uka.ipd.sdq.pipesandfilters.framework.MetaDataInit; |
12 | import de.uka.ipd.sdq.pipesandfilters.framework.PipeData; |
13 | import de.uka.ipd.sdq.pipesandfilters.framework.PipesAndFiltersManager; |
14 | import de.uka.ipd.sdq.pipesandfilters.framework.recorder.IRawWriteStrategy; |
15 | import de.uka.ipd.sdq.pipesandfilters.framework.recorder.RawRecorder; |
16 | import de.uka.ipd.sdq.pipesandfilters.framework.recorder.Recorder; |
17 | import de.uka.ipd.sdq.pipesandfilters.framework.recorder.launch.RecorderExtensionHelper; |
18 | import de.uka.ipd.sdq.probespec.framework.calculator.Calculator; |
19 | import de.uka.ipd.sdq.probespec.framework.calculator.ICalculatorListener; |
20 | import de.uka.ipd.sdq.simucomframework.model.SimuComModel; |
21 | |
22 | public class SetupPipesAndFiltersStrategy implements ISetupDataSinkStrategy { |
23 | /** Logger for this class. */ |
24 | private static final Logger logger = Logger.getLogger(SetupPipesAndFiltersStrategy.class); |
25 | |
26 | private SimuComModel model; |
27 | |
28 | public SetupPipesAndFiltersStrategy(SimuComModel model) { |
29 | this.model = model; |
30 | } |
31 | |
32 | public PipesAndFiltersManager setupDataSink(Calculator calculator, MetaDataInit metaData) { |
33 | // Initialize recorder and Pipes-and-Filters-Manger |
34 | Recorder recorder = new RawRecorder(createWriteStrategy()); |
35 | final PipesAndFiltersManager pipeManager = new PipesAndFiltersManager( |
36 | recorder); |
37 | pipeManager.initialize(metaData); |
38 | |
39 | calculator.addCalculatorListener(new ICalculatorListener() { |
40 | |
41 | public void calculated(Vector<Measure<?, ? extends Quantity>> resultTuple) { |
42 | pipeManager.processData(new PipeData(resultTuple)); |
43 | } |
44 | }); |
45 | |
46 | return pipeManager; |
47 | } |
48 | |
49 | private IRawWriteStrategy createWriteStrategy() { |
50 | try { |
51 | String writeStrategyClass = RecorderExtensionHelper |
52 | .getWriteStrategyClassNameForName(model.getConfiguration() |
53 | .getRecorderName()); |
54 | return (IRawWriteStrategy) Class.forName(writeStrategyClass).newInstance(); |
55 | } catch (CoreException e) { |
56 | logger.error("Could not create write strategy.", e); |
57 | } catch (InstantiationException e) { |
58 | logger.error("Could not create write strategy.", e); |
59 | } catch (IllegalAccessException e) { |
60 | logger.error("Could not create write strategy.", e); |
61 | } catch (ClassNotFoundException e) { |
62 | logger.error("Could not create write strategy.", e); |
63 | } |
64 | return null; |
65 | } |
66 | |
67 | } |