1 | package de.uka.ipd.sdq.simucomframework.usage; |
2 | |
3 | import de.uka.ipd.sdq.probespec.framework.RequestContext; |
4 | import de.uka.ipd.sdq.probespec.framework.garbagecollection.IRegionBasedGarbageCollector; |
5 | import de.uka.ipd.sdq.reliability.core.FailureStatistics; |
6 | import de.uka.ipd.sdq.simucomframework.ReliabilitySensorHelper; |
7 | import de.uka.ipd.sdq.simucomframework.SimuComSimProcess; |
8 | import de.uka.ipd.sdq.simucomframework.exceptions.FailureException; |
9 | import de.uka.ipd.sdq.simucomframework.model.SimuComModel; |
10 | |
11 | /** |
12 | * Base class for open workload users. Open workload users begin their life, |
13 | * execute their behaviour once, and then they die |
14 | * |
15 | * @author Steffen Becker |
16 | * |
17 | */ |
18 | public class OpenWorkloadUser extends SimuComSimProcess implements IUser { |
19 | |
20 | private IScenarioRunner scenarioRunner; |
21 | private IRegionBasedGarbageCollector<RequestContext> blackboardGarbageCollector; |
22 | private String usageScenarioId; |
23 | |
24 | public OpenWorkloadUser(final SimuComModel owner, final String name, |
25 | final IScenarioRunner scenarioRunner, final String usageScenarioId) { |
26 | super(owner, name); |
27 | this.scenarioRunner = scenarioRunner; |
28 | blackboardGarbageCollector = owner.getProbeSpecContext().getBlackboardGarbageCollector(); |
29 | this.usageScenarioId = usageScenarioId; |
30 | } |
31 | |
32 | /* |
33 | * (non-Javadoc) |
34 | * |
35 | * @see desmoj.core.simulator.SimProcess#lifeCycle() |
36 | */ |
37 | @Override |
38 | protected void internalLifeCycle() { |
39 | logger.debug(getName() + " started! I'm alive!!!"); |
40 | // update session id |
41 | updateNewSessionID(); |
42 | try { |
43 | blackboardGarbageCollector.enterRegion(getRequestContext() |
44 | .rootContext()); |
45 | scenarioRunner(this); |
46 | if (getModel().getConfiguration().getSimulateFailures()) { |
47 | ReliabilitySensorHelper.recordScenarioRunResultSuccess( |
48 | getModel(), getRequestContext(), |
49 | usageScenarioId); |
50 | } |
51 | } catch (FailureException exception) { |
52 | if (getModel().getConfiguration().getSimulateFailures()) { |
53 | FailureStatistics.getInstance() |
54 | .increaseUnhandledFailureCounter( |
55 | exception.getFailureType(), currentSessionId); |
56 | ReliabilitySensorHelper.recordScenarioRunResultFailure( |
57 | getModel(), exception |
58 | .getFailureType(), getRequestContext(), |
59 | usageScenarioId); |
60 | } |
61 | } finally { |
62 | // Increase measurements counter manually as usage scenario run is |
63 | // not finished: |
64 | getModel().increaseMainMeasurementsCount(); |
65 | |
66 | blackboardGarbageCollector.leaveRegion(getRequestContext() |
67 | .rootContext()); |
68 | } |
69 | logger.debug(getName() + " done! I'm dying!!!"); |
70 | } |
71 | |
72 | /* |
73 | * (non-Javadoc) |
74 | * |
75 | * @see |
76 | * de.uka.ipd.sdq.simucomframework.usage.IScenarioRunner#scenarioRunner( |
77 | * desmoj.core.simulator.SimProcess) |
78 | */ |
79 | public void scenarioRunner(SimuComSimProcess thread) { |
80 | this.scenarioRunner.scenarioRunner(thread); |
81 | } |
82 | |
83 | /* |
84 | * (non-Javadoc) |
85 | * |
86 | * @see de.uka.ipd.sdq.simucomframework.usage.IUser#startUserLife() |
87 | */ |
88 | public void startUserLife() { |
89 | this.scheduleAt(0); |
90 | } |
91 | |
92 | } |