1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.tcfmoop.config; |
5 | |
6 | import de.uka.ipd.sdq.tcfmoop.config.exceptions.InvalidConfigException; |
7 | |
8 | /** |
9 | * Configuration class for ElapsedTime termination criterion. |
10 | * @author Atanas Dimitrov |
11 | */ |
12 | public class ElapsedTimeConfig extends AbstractConfiguration { |
13 | |
14 | public enum TimeType{USER_TIME, CPU_TIME}; |
15 | |
16 | //The minimum time the optimization is allowed to run |
17 | private Long executionInterval; |
18 | //The type of the time |
19 | private TimeType timeType; |
20 | |
21 | |
22 | public ElapsedTimeConfig(){ |
23 | super(TerminationCriteriaNames.ELAPSED_TIME); |
24 | } |
25 | |
26 | /** |
27 | * {@inheritDoc} |
28 | */ |
29 | @Override |
30 | public boolean validateConfiguration() { |
31 | if(this.getTerminationCriterionName() != TerminationCriteriaNames.ELAPSED_TIME || |
32 | this.executionInterval == null || |
33 | this.timeType != TimeType.CPU_TIME && |
34 | this.timeType != TimeType.USER_TIME){ |
35 | return false; |
36 | }else{ |
37 | return true; |
38 | } |
39 | } |
40 | |
41 | /** |
42 | * Sets the minimum time that the optimization is allowed to run. |
43 | * @param timeInMilis The minimum time in milliseconds that the optimization is allowed to run. Should be at least 1. |
44 | * @throws InvalidConfigException if the supplied parameter do not conform to the required conditions. |
45 | */ |
46 | public void setExecutionInterval(long timeInMilis) throws InvalidConfigException{ |
47 | if(timeInMilis < 1){ |
48 | throw new InvalidConfigException("ElapsedTimeConfig.setExecutionInterval: Negative Time is not allowed."); |
49 | } |
50 | this.executionInterval = timeInMilis; |
51 | } |
52 | |
53 | /** |
54 | * Returns the minimum time in milliseconds that the optimization is allowed to run. |
55 | * @return the minimum time in milliseconds that the optimization is allowed to run. |
56 | */ |
57 | public long getExecutionInterval(){ |
58 | return this.executionInterval; |
59 | } |
60 | |
61 | /** |
62 | * Sets the type of the time that is going to be measured: Pure-CPU time or Clock time. Please note that the |
63 | * measurement of the SPU-Time might not always be possible. If this is the case, then the criterion will |
64 | * automatically switch to Clock time. |
65 | * @param timeType the type of the time to be measured. |
66 | * @throws InvalidConfigException if the supplied parameter do not conform to the required conditions. |
67 | */ |
68 | public void setTimeType(TimeType timeType) throws InvalidConfigException{ |
69 | if(timeType == null){ |
70 | throw new InvalidConfigException("ElapsedTimeConfig.setTimeType(): The supplied parameter should be TimeType.CPU_TIME or TimeType.USER_TIME." + |
71 | "Currently the parameter is null."); |
72 | } |
73 | this.timeType = timeType; |
74 | } |
75 | |
76 | /** |
77 | * Returns the type of the time that is going to be measured. |
78 | * @return the type of the time that is going to be measured. |
79 | */ |
80 | public TimeType getTimeType(){ |
81 | return this.timeType; |
82 | } |
83 | |
84 | } |