blob: ca19b58216bf6bb5181735ee1e755d05c388c82d [file] [log] [blame]
Sangsik Yoonb1b823f2016-05-16 18:55:39 +09001/*
2 * Copyright 2014-2016 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.net.statistic;
17
18import static com.google.common.base.Preconditions.checkArgument;
19
20/**
21 * Default polling interval values.
22 */
23public final class PollInterval {
24 private static final long DEFAULT_POLL_INTERVAL = 10;
25 private static final long DEFAULT_MID_POLL_INTERVAL = 20;
26 private static final long DEFAULT_LONG_POLL_INTERVAL = 30;
27 private static final long DEFAULT_ENTIRE_POLL_INTERVAL = 60;
28
29 private static PollInterval pollIntervalInstance =
30 new PollInterval(DEFAULT_POLL_INTERVAL,
31 DEFAULT_MID_POLL_INTERVAL,
32 DEFAULT_LONG_POLL_INTERVAL,
33 DEFAULT_ENTIRE_POLL_INTERVAL);
34
35 /**
36 * Indicates the flow statistics poll interval in seconds.
37 */
38 private long pollInterval = DEFAULT_POLL_INTERVAL;
39 // same as IMMEDIATE and SHORT flow live type
40
41 // These may be used in NewFlowStatsCollector
42 private long midPollInterval = DEFAULT_MID_POLL_INTERVAL; // default is 2*pollInterval
43 private long longPollInterval = DEFAULT_LONG_POLL_INTERVAL; // default is 3*pollInterval
44 private long entirePollInterval = DEFAULT_ENTIRE_POLL_INTERVAL; // default is 6*pollInterval
45
46 /**
47 * Returns the singleton PollInterval instance class for FlowStatisticService and other statistic services.
48 * This instance is only used Adaptive Flow Sampling(adaptiveFlowSampling) mode is enabled(true).
49 *
50 * @return the singleton PollInterval instance class
51 */
52 public static PollInterval getInstance() {
53 return pollIntervalInstance;
54 }
55
56 /**
57 * Creates an default poll interval.
58 */
59 protected PollInterval() {
60 this.pollInterval = DEFAULT_POLL_INTERVAL;
61 this.midPollInterval = DEFAULT_MID_POLL_INTERVAL;
62 this.longPollInterval = DEFAULT_LONG_POLL_INTERVAL;
63 this.entirePollInterval = DEFAULT_ENTIRE_POLL_INTERVAL;
64 }
65
66 // Public construction is prohibited
67 /**
68 * Creates a poll interval from the parameters.
69 *
70 * @param pollInterval the poll interval value
71 * @param midPollInterval the mid poll interval value
72 * @param longPollInterval the long poll interval value
73 * @param entirePollInterval the entire poll interval value
74 */
75 private PollInterval(long pollInterval, long midPollInterval,
76 long longPollInterval, long entirePollInterval) {
77 checkArgument(pollInterval > 0, "Poll interval must be greater than 0");
78 checkArgument(midPollInterval > 0 && midPollInterval > pollInterval,
79 "Mid poll interval must be greater than 0 and pollInterval");
80 checkArgument(longPollInterval > 0 && longPollInterval > midPollInterval,
81 "Long poll interval must be greater than 0 and midPollInterval");
82 checkArgument(entirePollInterval > 0 && entirePollInterval > longPollInterval,
83 "Entire poll interval must be greater than 0 and longPollInterval");
84
85 this.pollInterval = pollInterval;
86 this.midPollInterval = midPollInterval;
87 this.longPollInterval = longPollInterval;
88 this.entirePollInterval = entirePollInterval;
89 }
90
91 /**
92 * Sets the poll interval in seconds. Used solely for the purpose of
93 * computing the load.
94 *
95 * @param newPollInterval poll interval duration in seconds
96 */
97 public void setPollInterval(long newPollInterval) {
98 checkArgument(newPollInterval > 0, "Poll interval must be greater than 0");
99
100 pollInterval = newPollInterval;
101 }
102
103 /**
104 * Sets the mid poll interval in seconds. Used solely for the purpose of
105 * computing the load.
106 *
107 * @param newPollInterval poll interval duration in seconds
108 */
109 public void setMidPollInterval(long newPollInterval) {
110 checkArgument(newPollInterval > 0 && newPollInterval > pollInterval,
111 "Mid poll interval must be greater than 0 and pollInterval");
112
113 midPollInterval = newPollInterval;
114 }
115
116 /**
117 * Sets the long poll interval in seconds. Used solely for the purpose of
118 * computing the load.
119 *
120 * @param newPollInterval poll interval duration in seconds
121 */
122 public void setLongPollInterval(long newPollInterval) {
123 checkArgument(newPollInterval > 0 && newPollInterval > midPollInterval,
124 "Long poll interval must be greater than 0 and midPollInterval");
125
126 longPollInterval = newPollInterval;
127 }
128
129 /**
130 * Sets the entire poll interval in seconds. Used solely for the purpose of
131 * computing the load.
132 *
133 * @param newPollInterval poll interval duration in seconds
134 */
135 public void setEntirePollInterval(long newPollInterval) {
136 checkArgument(newPollInterval > 0 && newPollInterval > longPollInterval,
137 "Entire poll interval must be greater than 0 and longPollInterval");
138
139 entirePollInterval = newPollInterval;
140 }
141
142 /**
143 * Returns default poll interval value in seconds.
144 *
145 * @return default poll interval
146 */
147 public long getPollInterval() {
148 return pollInterval;
149 }
150
151 /**
152 * Returns mid poll interval value in seconds.
153 *
154 * @return mid poll interval
155 */
156 public long getMidPollInterval() {
157 return midPollInterval;
158 }
159
160 /**
161 * Returns long poll interval value in seconds.
162 *
163 * @return long poll interval
164 */
165 public long getLongPollInterval() {
166 return longPollInterval;
167 }
168
169 /**
170 * Returns entire poll interval value in seconds.
171 *
172 * @return entire poll interval
173 */
174 public long getEntirePollInterval() {
175 return entirePollInterval;
176 }
177
178 /**
179 * Returns average poll interval value in seconds.
180 *
181 * @return average poll interval
182 */
183 public long getAvgPollInterval() {
184 return (pollInterval + midPollInterval + longPollInterval) / 3;
185 }
186}