| 1 | package de.uka.ipd.sdq.probespec.framework; |
| 2 | |
| 3 | import de.uka.ipd.sdq.pipesandfilters.framework.PipesAndFiltersManager; |
| 4 | import de.uka.ipd.sdq.probespec.framework.calculator.CalculatorRegistry; |
| 5 | import de.uka.ipd.sdq.probespec.framework.calculator.ICalculatorFactory; |
| 6 | import de.uka.ipd.sdq.probespec.framework.concurrency.ThreadManager; |
| 7 | import de.uka.ipd.sdq.probespec.framework.garbagecollection.IRegionBasedGarbageCollector; |
| 8 | import de.uka.ipd.sdq.probespec.framework.probes.IProbeStrategyRegistry; |
| 9 | import de.uka.ipd.sdq.probespec.framework.utils.ProbeSetIDGenerator; |
| 10 | |
| 11 | public class ProbeSpecContext { |
| 12 | |
| 13 | private IProbeStrategyRegistry probeStrategyRegistry; |
| 14 | |
| 15 | private ICalculatorFactory calculatorFactory; |
| 16 | |
| 17 | private ISampleBlackboard sampleBlackboard; |
| 18 | |
| 19 | private ThreadManager threadManager; |
| 20 | |
| 21 | private ProbeSetIDGenerator probeSetIdGenerator; |
| 22 | |
| 23 | private IRegionBasedGarbageCollector<RequestContext> blackboardGarbageCollector; |
| 24 | |
| 25 | private CalculatorRegistry calculatorRegistry; |
| 26 | |
| 27 | private Registry<PipesAndFiltersManager> pipeManagerRegisty; |
| 28 | |
| 29 | private boolean initialised; |
| 30 | |
| 31 | public ProbeSpecContext() { |
| 32 | threadManager = new ThreadManager(); |
| 33 | probeSetIdGenerator = new ProbeSetIDGenerator(); |
| 34 | calculatorRegistry = new CalculatorRegistry(); |
| 35 | pipeManagerRegisty = new Registry<PipesAndFiltersManager>(); |
| 36 | } |
| 37 | |
| 38 | public void initialise(ISampleBlackboard blackboard, |
| 39 | IProbeStrategyRegistry probeStrategyRegistry, |
| 40 | ICalculatorFactory calculatorFactory) { |
| 41 | this.sampleBlackboard = blackboard; |
| 42 | this.probeStrategyRegistry = probeStrategyRegistry; |
| 43 | this.calculatorFactory = calculatorFactory; |
| 44 | this.initialised = true; |
| 45 | } |
| 46 | |
| 47 | public Integer obtainProbeSetId(String probeSetId) { |
| 48 | return probeSetIdGenerator.obtainId(probeSetId); |
| 49 | } |
| 50 | |
| 51 | public String obtainOriginalProbeSetId(Integer probeSetId) { |
| 52 | return probeSetIdGenerator.obtainOriginalId(probeSetId); |
| 53 | } |
| 54 | |
| 55 | public IProbeStrategyRegistry getProbeStrategyRegistry() { |
| 56 | throwExceptionIfNotInitialised(); |
| 57 | return probeStrategyRegistry; |
| 58 | } |
| 59 | |
| 60 | public void setProbeStrategyRegistry( |
| 61 | IProbeStrategyRegistry probeStrategyRegistry) { |
| 62 | this.probeStrategyRegistry = probeStrategyRegistry; |
| 63 | } |
| 64 | |
| 65 | public ICalculatorFactory getCalculatorFactory() { |
| 66 | throwExceptionIfNotInitialised(); |
| 67 | return calculatorFactory; |
| 68 | } |
| 69 | |
| 70 | public void setCalculatorFactory(ICalculatorFactory calculatorFactory) { |
| 71 | this.calculatorFactory = calculatorFactory; |
| 72 | } |
| 73 | |
| 74 | public ISampleBlackboard getSampleBlackboard() { |
| 75 | throwExceptionIfNotInitialised(); |
| 76 | return sampleBlackboard; |
| 77 | } |
| 78 | |
| 79 | public void setSampleBlackboard(ISampleBlackboard sampleBlackboard) { |
| 80 | this.sampleBlackboard = sampleBlackboard; |
| 81 | } |
| 82 | |
| 83 | public IRegionBasedGarbageCollector<RequestContext> getBlackboardGarbageCollector() { |
| 84 | return blackboardGarbageCollector; |
| 85 | } |
| 86 | |
| 87 | public void setBlackboardGarbageCollector( |
| 88 | IRegionBasedGarbageCollector<RequestContext> blackboardGarbageCollector) { |
| 89 | this.blackboardGarbageCollector = blackboardGarbageCollector; |
| 90 | } |
| 91 | |
| 92 | public ThreadManager getThreadManager() { |
| 93 | return threadManager; |
| 94 | } |
| 95 | |
| 96 | public CalculatorRegistry getCalculatorRegistry() { |
| 97 | return calculatorRegistry; |
| 98 | } |
| 99 | |
| 100 | public Registry<PipesAndFiltersManager> getPipeManagerRegisty() { |
| 101 | throwExceptionIfNotInitialised(); |
| 102 | return pipeManagerRegisty; |
| 103 | } |
| 104 | |
| 105 | public void finish() { |
| 106 | throwExceptionIfNotInitialised(); |
| 107 | |
| 108 | // stop registered threads |
| 109 | getThreadManager().stopThreads(); |
| 110 | |
| 111 | // flush pipes |
| 112 | for(PipesAndFiltersManager p : pipeManagerRegisty) { |
| 113 | p.flush(); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | private void throwExceptionIfNotInitialised() { |
| 118 | if (!initialised) { |
| 119 | throw new RuntimeException("Initialise the ProbeSpecification context before using it."); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | } |