Yuta HIGUCHI
Committed by Yuta Higuchi

Add probes to DistributedIntentStore

Change-Id: I23a5823d3924392dc17166404a17fc1918c01453
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onlab.onos.store.intent.impl; 16 package org.onlab.onos.store.intent.impl;
17 17
18 +import com.codahale.metrics.Timer;
19 +import com.codahale.metrics.Timer.Context;
18 import com.google.common.base.Verify; 20 import com.google.common.base.Verify;
19 import com.google.common.collect.ImmutableSet; 21 import com.google.common.collect.ImmutableSet;
20 22
...@@ -24,6 +26,8 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -24,6 +26,8 @@ import org.apache.felix.scr.annotations.Deactivate;
24 import org.apache.felix.scr.annotations.Reference; 26 import org.apache.felix.scr.annotations.Reference;
25 import org.apache.felix.scr.annotations.ReferenceCardinality; 27 import org.apache.felix.scr.annotations.ReferenceCardinality;
26 import org.apache.felix.scr.annotations.Service; 28 import org.apache.felix.scr.annotations.Service;
29 +import org.onlab.metrics.MetricsService;
30 +import org.onlab.onos.core.MetricsHelper;
27 import org.onlab.onos.net.intent.Intent; 31 import org.onlab.onos.net.intent.Intent;
28 import org.onlab.onos.net.intent.IntentEvent; 32 import org.onlab.onos.net.intent.IntentEvent;
29 import org.onlab.onos.net.intent.IntentId; 33 import org.onlab.onos.net.intent.IntentId;
...@@ -48,12 +52,13 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -48,12 +52,13 @@ import java.util.concurrent.ConcurrentHashMap;
48 52
49 import static org.onlab.onos.net.intent.IntentState.*; 53 import static org.onlab.onos.net.intent.IntentState.*;
50 import static org.slf4j.LoggerFactory.getLogger; 54 import static org.slf4j.LoggerFactory.getLogger;
55 +import static org.onlab.metrics.MetricsUtil.*;
51 56
52 @Component(immediate = true, enabled = true) 57 @Component(immediate = true, enabled = true)
53 @Service 58 @Service
54 public class DistributedIntentStore 59 public class DistributedIntentStore
55 extends AbstractStore<IntentEvent, IntentStoreDelegate> 60 extends AbstractStore<IntentEvent, IntentStoreDelegate>
56 - implements IntentStore { 61 + implements IntentStore, MetricsHelper {
57 62
58 /** Valid parking state, which can transition to INSTALLED. */ 63 /** Valid parking state, which can transition to INSTALLED. */
59 private static final Set<IntentState> PRE_INSTALLED = EnumSet.of(SUBMITTED, INSTALLED, FAILED); 64 private static final Set<IntentState> PRE_INSTALLED = EnumSet.of(SUBMITTED, INSTALLED, FAILED);
...@@ -81,11 +86,41 @@ public class DistributedIntentStore ...@@ -81,11 +86,41 @@ public class DistributedIntentStore
81 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 86 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
82 protected DatabaseService dbService; 87 protected DatabaseService dbService;
83 88
89 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
90 + protected MetricsService metricsService;
91 +
84 // TODO make this configurable 92 // TODO make this configurable
85 private boolean onlyLogTransitionError = true; 93 private boolean onlyLogTransitionError = true;
86 94
95 + private Timer createIntentTimer;
96 + private Timer removeIntentTimer;
97 + private Timer setInstallableIntentsTimer;
98 + private Timer getInstallableIntentsTimer;
99 + private Timer removeInstalledIntentsTimer;
100 + private Timer setStateTimer;
101 + private Timer getIntentCountTimer;
102 + private Timer getIntentsTimer;
103 + private Timer getIntentTimer;
104 + private Timer getIntentStateTimer;
105 +
106 +
107 + private Timer createResponseTimer(String methodName) {
108 + return createTimer("IntentStore", methodName, "responseTime");
109 + }
110 +
87 @Activate 111 @Activate
88 public void activate() { 112 public void activate() {
113 + createIntentTimer = createResponseTimer("createIntent");
114 + removeIntentTimer = createResponseTimer("removeIntent");
115 + setInstallableIntentsTimer = createResponseTimer("setInstallableIntents");
116 + getInstallableIntentsTimer = createResponseTimer("getInstallableIntents");
117 + removeInstalledIntentsTimer = createResponseTimer("removeInstalledIntents");
118 + setStateTimer = createResponseTimer("setState");
119 + getIntentCountTimer = createResponseTimer("getIntentCount");
120 + getIntentsTimer = createResponseTimer("getIntents");
121 + getIntentTimer = createResponseTimer("getIntent");
122 + getIntentStateTimer = createResponseTimer("getIntentState");
123 +
89 // FIXME: We need a way to add serializer for intents which has been plugged-in. 124 // FIXME: We need a way to add serializer for intents which has been plugged-in.
90 // As a short term workaround, relax Kryo config to 125 // As a short term workaround, relax Kryo config to
91 // registrationRequired=false 126 // registrationRequired=false
...@@ -118,55 +153,91 @@ public class DistributedIntentStore ...@@ -118,55 +153,91 @@ public class DistributedIntentStore
118 } 153 }
119 154
120 @Override 155 @Override
156 + public MetricsService metricsService() {
157 + return metricsService;
158 + }
159 +
160 + @Override
121 public IntentEvent createIntent(Intent intent) { 161 public IntentEvent createIntent(Intent intent) {
122 - boolean absent = intents.putIfAbsent(intent.id(), intent); 162 + Context timer = startTimer(createIntentTimer);
123 - if (!absent) { 163 + try {
124 - // duplicate, ignore 164 + boolean absent = intents.putIfAbsent(intent.id(), intent);
125 - return null; 165 + if (!absent) {
126 - } else { 166 + // duplicate, ignore
127 - return this.setState(intent, IntentState.SUBMITTED); 167 + return null;
168 + } else {
169 + return this.setState(intent, IntentState.SUBMITTED);
170 + }
171 + } finally {
172 + stopTimer(timer);
128 } 173 }
129 } 174 }
130 175
131 @Override 176 @Override
132 public IntentEvent removeIntent(IntentId intentId) { 177 public IntentEvent removeIntent(IntentId intentId) {
133 - Intent intent = intents.remove(intentId); 178 + Context timer = startTimer(removeIntentTimer);
134 - installable.remove(intentId); 179 + try {
135 - if (intent == null) { 180 + Intent intent = intents.remove(intentId);
136 - // was already removed 181 + installable.remove(intentId);
137 - return null; 182 + if (intent == null) {
183 + // was already removed
184 + return null;
185 + }
186 + IntentEvent event = this.setState(intent, WITHDRAWN);
187 + states.remove(intentId);
188 + transientStates.remove(intentId);
189 + // TODO: Should we callremoveInstalledIntents if this Intent was
190 + return event;
191 + } finally {
192 + stopTimer(timer);
138 } 193 }
139 - IntentEvent event = this.setState(intent, WITHDRAWN);
140 - states.remove(intentId);
141 - transientStates.remove(intentId);
142 - // TODO: Should we callremoveInstalledIntents if this Intent was
143 - return event;
144 } 194 }
145 195
146 @Override 196 @Override
147 public long getIntentCount() { 197 public long getIntentCount() {
148 - return intents.size(); 198 + Context timer = startTimer(getIntentCountTimer);
199 + try {
200 + return intents.size();
201 + } finally {
202 + stopTimer(timer);
203 + }
149 } 204 }
150 205
151 @Override 206 @Override
152 public Iterable<Intent> getIntents() { 207 public Iterable<Intent> getIntents() {
153 - return ImmutableSet.copyOf(intents.values()); 208 + Context timer = startTimer(getIntentsTimer);
209 + try {
210 + return ImmutableSet.copyOf(intents.values());
211 + } finally {
212 + stopTimer(timer);
213 + }
154 } 214 }
155 215
156 @Override 216 @Override
157 public Intent getIntent(IntentId intentId) { 217 public Intent getIntent(IntentId intentId) {
158 - return intents.get(intentId); 218 + Context timer = startTimer(getIntentTimer);
219 + try {
220 + return intents.get(intentId);
221 + } finally {
222 + stopTimer(timer);
223 + }
159 } 224 }
160 225
161 @Override 226 @Override
162 public IntentState getIntentState(IntentId id) { 227 public IntentState getIntentState(IntentId id) {
163 - final IntentState localState = transientStates.get(id); 228 + Context timer = startTimer(getIntentStateTimer);
164 - if (localState != null) { 229 + try {
165 - return localState; 230 + final IntentState localState = transientStates.get(id);
231 + if (localState != null) {
232 + return localState;
233 + }
234 + return states.get(id);
235 + } finally {
236 + stopTimer(timer);
166 } 237 }
167 - return states.get(id);
168 } 238 }
169 239
240 + // FIXME temporary workaround until we fix our state machine
170 private void verify(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) { 241 private void verify(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) {
171 if (onlyLogTransitionError) { 242 if (onlyLogTransitionError) {
172 if (!expression) { 243 if (!expression) {
...@@ -179,89 +250,109 @@ public class DistributedIntentStore ...@@ -179,89 +250,109 @@ public class DistributedIntentStore
179 250
180 @Override 251 @Override
181 public IntentEvent setState(Intent intent, IntentState state) { 252 public IntentEvent setState(Intent intent, IntentState state) {
182 - final IntentId id = intent.id(); 253 + Context timer = startTimer(setStateTimer);
183 - IntentEvent.Type evtType = null; 254 + try {
184 - final IntentState prevParking; 255 + final IntentId id = intent.id();
185 - boolean transitionedToParking = true; 256 + IntentEvent.Type evtType = null;
186 - boolean updated; 257 + final IntentState prevParking;
187 - 258 + boolean transitionedToParking = true;
188 - // parking state transition 259 + boolean updated;
189 - switch (state) { 260 +
190 - case SUBMITTED: 261 + // parking state transition
191 - prevParking = states.get(id); 262 + switch (state) {
192 - if (prevParking == null) { 263 + case SUBMITTED:
193 - updated = states.putIfAbsent(id, SUBMITTED); 264 + prevParking = states.get(id);
194 - verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED); 265 + if (prevParking == null) {
266 + updated = states.putIfAbsent(id, SUBMITTED);
267 + verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED);
268 + } else {
269 + verify(prevParking == WITHDRAWN,
270 + "Illegal state transition attempted from %s to SUBMITTED",
271 + prevParking);
272 + updated = states.replace(id, prevParking, SUBMITTED);
273 + verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED);
274 + }
275 + evtType = IntentEvent.Type.SUBMITTED;
276 + break;
277 +
278 + case INSTALLED:
279 + prevParking = states.get(id);
280 + verify(PRE_INSTALLED.contains(prevParking),
281 + "Illegal state transition attempted from %s to INSTALLED",
282 + prevParking);
283 + updated = states.replace(id, prevParking, INSTALLED);
284 + verify(updated, "Conditional replace %s => %s failed", prevParking, INSTALLED);
285 + evtType = IntentEvent.Type.INSTALLED;
286 + break;
287 +
288 + case FAILED:
289 + prevParking = states.get(id);
290 + updated = states.replace(id, prevParking, FAILED);
291 + verify(updated, "Conditional replace %s => %s failed", prevParking, FAILED);
292 + evtType = IntentEvent.Type.FAILED;
293 + break;
294 +
295 + case WITHDRAWN:
296 + prevParking = states.get(id);
297 + verify(PRE_WITHDRAWN.contains(prevParking),
298 + "Illegal state transition attempted from %s to WITHDRAWN",
299 + prevParking);
300 + updated = states.replace(id, prevParking, WITHDRAWN);
301 + verify(updated, "Conditional replace %s => %s failed", prevParking, WITHDRAWN);
302 + evtType = IntentEvent.Type.WITHDRAWN;
303 + break;
304 +
305 + default:
306 + transitionedToParking = false;
307 + prevParking = null;
308 + break;
309 + }
310 + if (transitionedToParking) {
311 + log.debug("Parking State change: {} {}=>{}", id, prevParking, state);
312 + // remove instance local state
313 + transientStates.remove(id);
195 } else { 314 } else {
196 - verify(prevParking == WITHDRAWN, 315 + // Update instance local state, which includes non-parking state transition
197 - "Illegal state transition attempted from %s to SUBMITTED", 316 + final IntentState prevTransient = transientStates.put(id, state);
198 - prevParking); 317 + log.debug("Transient State change: {} {}=>{}", id, prevTransient, state);
199 - updated = states.replace(id, prevParking, SUBMITTED);
200 - verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED);
201 } 318 }
202 - evtType = IntentEvent.Type.SUBMITTED;
203 - break;
204 -
205 - case INSTALLED:
206 - prevParking = states.get(id);
207 - verify(PRE_INSTALLED.contains(prevParking),
208 - "Illegal state transition attempted from %s to INSTALLED",
209 - prevParking);
210 - updated = states.replace(id, prevParking, INSTALLED);
211 - verify(updated, "Conditional replace %s => %s failed", prevParking, INSTALLED);
212 - evtType = IntentEvent.Type.INSTALLED;
213 - break;
214 -
215 - case FAILED:
216 - prevParking = states.get(id);
217 - updated = states.replace(id, prevParking, FAILED);
218 - verify(updated, "Conditional replace %s => %s failed", prevParking, FAILED);
219 - evtType = IntentEvent.Type.FAILED;
220 - break;
221 -
222 - case WITHDRAWN:
223 - prevParking = states.get(id);
224 - verify(PRE_WITHDRAWN.contains(prevParking),
225 - "Illegal state transition attempted from %s to WITHDRAWN",
226 - prevParking);
227 - updated = states.replace(id, prevParking, WITHDRAWN);
228 - verify(updated, "Conditional replace %s => %s failed", prevParking, WITHDRAWN);
229 - evtType = IntentEvent.Type.WITHDRAWN;
230 - break;
231 -
232 - default:
233 - transitionedToParking = false;
234 - prevParking = null;
235 - break;
236 - }
237 - if (transitionedToParking) {
238 - log.debug("Parking State change: {} {}=>{}", id, prevParking, state);
239 - // remove instance local state
240 - transientStates.remove(id);
241 - } else {
242 - // Update instance local state, which includes non-parking state transition
243 - final IntentState prevTransient = transientStates.put(id, state);
244 - log.debug("Transient State change: {} {}=>{}", id, prevTransient, state);
245 - }
246 319
247 - if (evtType == null) { 320 + if (evtType == null) {
248 - return null; 321 + return null;
322 + }
323 + return new IntentEvent(evtType, intent);
324 + } finally {
325 + stopTimer(timer);
249 } 326 }
250 - return new IntentEvent(evtType, intent);
251 } 327 }
252 328
253 @Override 329 @Override
254 public void setInstallableIntents(IntentId intentId, List<Intent> result) { 330 public void setInstallableIntents(IntentId intentId, List<Intent> result) {
255 - installable.put(intentId, result); 331 + Context timer = startTimer(setInstallableIntentsTimer);
332 + try {
333 + installable.put(intentId, result);
334 + } finally {
335 + stopTimer(timer);
336 + }
256 } 337 }
257 338
258 @Override 339 @Override
259 public List<Intent> getInstallableIntents(IntentId intentId) { 340 public List<Intent> getInstallableIntents(IntentId intentId) {
260 - return installable.get(intentId); 341 + Context timer = startTimer(getInstallableIntentsTimer);
342 + try {
343 + return installable.get(intentId);
344 + } finally {
345 + stopTimer(timer);
346 + }
261 } 347 }
262 348
263 @Override 349 @Override
264 public void removeInstalledIntents(IntentId intentId) { 350 public void removeInstalledIntents(IntentId intentId) {
265 - installable.remove(intentId); 351 + Context timer = startTimer(removeInstalledIntentsTimer);
352 + try {
353 + installable.remove(intentId);
354 + } finally {
355 + stopTimer(timer);
356 + }
266 } 357 }
267 } 358 }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onlab.onos.store.intent.impl; 16 package org.onlab.onos.store.intent.impl;
17 17
18 +import com.codahale.metrics.Timer;
19 +import com.codahale.metrics.Timer.Context;
18 import com.google.common.base.Verify; 20 import com.google.common.base.Verify;
19 import com.google.common.collect.ImmutableSet; 21 import com.google.common.collect.ImmutableSet;
20 import com.hazelcast.core.EntryAdapter; 22 import com.hazelcast.core.EntryAdapter;
...@@ -26,7 +28,11 @@ import com.hazelcast.core.Member; ...@@ -26,7 +28,11 @@ import com.hazelcast.core.Member;
26 import org.apache.felix.scr.annotations.Activate; 28 import org.apache.felix.scr.annotations.Activate;
27 import org.apache.felix.scr.annotations.Component; 29 import org.apache.felix.scr.annotations.Component;
28 import org.apache.felix.scr.annotations.Deactivate; 30 import org.apache.felix.scr.annotations.Deactivate;
31 +import org.apache.felix.scr.annotations.Reference;
32 +import org.apache.felix.scr.annotations.ReferenceCardinality;
29 import org.apache.felix.scr.annotations.Service; 33 import org.apache.felix.scr.annotations.Service;
34 +import org.onlab.metrics.MetricsService;
35 +import org.onlab.onos.core.MetricsHelper;
30 import org.onlab.onos.net.intent.Intent; 36 import org.onlab.onos.net.intent.Intent;
31 import org.onlab.onos.net.intent.IntentEvent; 37 import org.onlab.onos.net.intent.IntentEvent;
32 import org.onlab.onos.net.intent.IntentId; 38 import org.onlab.onos.net.intent.IntentId;
...@@ -48,12 +54,13 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -48,12 +54,13 @@ import java.util.concurrent.ConcurrentHashMap;
48 54
49 import static org.onlab.onos.net.intent.IntentState.*; 55 import static org.onlab.onos.net.intent.IntentState.*;
50 import static org.slf4j.LoggerFactory.getLogger; 56 import static org.slf4j.LoggerFactory.getLogger;
57 +import static org.onlab.metrics.MetricsUtil.*;
51 58
52 @Component(immediate = true, enabled = false) 59 @Component(immediate = true, enabled = false)
53 @Service 60 @Service
54 public class HazelcastIntentStore 61 public class HazelcastIntentStore
55 extends AbstractHazelcastStore<IntentEvent, IntentStoreDelegate> 62 extends AbstractHazelcastStore<IntentEvent, IntentStoreDelegate>
56 - implements IntentStore { 63 + implements IntentStore, MetricsHelper {
57 64
58 /** Valid parking state, which can transition to INSTALLED. */ 65 /** Valid parking state, which can transition to INSTALLED. */
59 private static final Set<IntentState> PRE_INSTALLED = EnumSet.of(SUBMITTED, INSTALLED, FAILED); 66 private static final Set<IntentState> PRE_INSTALLED = EnumSet.of(SUBMITTED, INSTALLED, FAILED);
...@@ -72,12 +79,41 @@ public class HazelcastIntentStore ...@@ -72,12 +79,41 @@ public class HazelcastIntentStore
72 79
73 private SMap<IntentId, List<Intent>> installable; 80 private SMap<IntentId, List<Intent>> installable;
74 81
82 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
83 + protected MetricsService metricsService;
84 +
75 // TODO make this configurable 85 // TODO make this configurable
76 private boolean onlyLogTransitionError = true; 86 private boolean onlyLogTransitionError = true;
77 87
88 + private Timer createIntentTimer;
89 + private Timer removeIntentTimer;
90 + private Timer setInstallableIntentsTimer;
91 + private Timer getInstallableIntentsTimer;
92 + private Timer removeInstalledIntentsTimer;
93 + private Timer setStateTimer;
94 + private Timer getIntentCountTimer;
95 + private Timer getIntentsTimer;
96 + private Timer getIntentTimer;
97 + private Timer getIntentStateTimer;
98 +
99 + private Timer createResponseTimer(String methodName) {
100 + return createTimer("IntentStore", methodName, "responseTime");
101 + }
102 +
78 @Override 103 @Override
79 @Activate 104 @Activate
80 public void activate() { 105 public void activate() {
106 + createIntentTimer = createResponseTimer("createIntent");
107 + removeIntentTimer = createResponseTimer("removeIntent");
108 + setInstallableIntentsTimer = createResponseTimer("setInstallableIntents");
109 + getInstallableIntentsTimer = createResponseTimer("getInstallableIntents");
110 + removeInstalledIntentsTimer = createResponseTimer("removeInstalledIntents");
111 + setStateTimer = createResponseTimer("setState");
112 + getIntentCountTimer = createResponseTimer("getIntentCount");
113 + getIntentsTimer = createResponseTimer("getIntents");
114 + getIntentTimer = createResponseTimer("getIntent");
115 + getIntentStateTimer = createResponseTimer("getIntentState");
116 +
81 // FIXME: We need a way to add serializer for intents which has been plugged-in. 117 // FIXME: We need a way to add serializer for intents which has been plugged-in.
82 // As a short term workaround, relax Kryo config to 118 // As a short term workaround, relax Kryo config to
83 // registrationRequired=false 119 // registrationRequired=false
...@@ -120,53 +156,88 @@ public class HazelcastIntentStore ...@@ -120,53 +156,88 @@ public class HazelcastIntentStore
120 } 156 }
121 157
122 @Override 158 @Override
159 + public MetricsService metricsService() {
160 + return metricsService;
161 + }
162 +
163 + @Override
123 public IntentEvent createIntent(Intent intent) { 164 public IntentEvent createIntent(Intent intent) {
124 - Intent existing = intents.putIfAbsent(intent.id(), intent); 165 + Context timer = startTimer(createIntentTimer);
125 - if (existing != null) { 166 + try {
126 - // duplicate, ignore 167 + Intent existing = intents.putIfAbsent(intent.id(), intent);
127 - return null; 168 + if (existing != null) {
128 - } else { 169 + // duplicate, ignore
129 - return this.setState(intent, IntentState.SUBMITTED); 170 + return null;
171 + } else {
172 + return this.setState(intent, IntentState.SUBMITTED);
173 + }
174 + } finally {
175 + stopTimer(timer);
130 } 176 }
131 } 177 }
132 178
133 @Override 179 @Override
134 public IntentEvent removeIntent(IntentId intentId) { 180 public IntentEvent removeIntent(IntentId intentId) {
135 - Intent intent = intents.remove(intentId); 181 + Context timer = startTimer(removeIntentTimer);
136 - installable.remove(intentId); 182 + try {
137 - if (intent == null) { 183 + Intent intent = intents.remove(intentId);
138 - // was already removed 184 + installable.remove(intentId);
139 - return null; 185 + if (intent == null) {
186 + // was already removed
187 + return null;
188 + }
189 + IntentEvent event = this.setState(intent, WITHDRAWN);
190 + states.remove(intentId);
191 + transientStates.remove(intentId);
192 + // TODO: Should we callremoveInstalledIntents if this Intent was
193 + return event;
194 + } finally {
195 + stopTimer(timer);
140 } 196 }
141 - IntentEvent event = this.setState(intent, WITHDRAWN);
142 - states.remove(intentId);
143 - transientStates.remove(intentId);
144 - // TODO: Should we callremoveInstalledIntents if this Intent was
145 - return event;
146 } 197 }
147 198
148 @Override 199 @Override
149 public long getIntentCount() { 200 public long getIntentCount() {
150 - return intents.size(); 201 + Context timer = startTimer(getIntentCountTimer);
202 + try {
203 + return intents.size();
204 + } finally {
205 + stopTimer(timer);
206 + }
151 } 207 }
152 208
153 @Override 209 @Override
154 public Iterable<Intent> getIntents() { 210 public Iterable<Intent> getIntents() {
155 - return ImmutableSet.copyOf(intents.values()); 211 + Context timer = startTimer(getIntentsTimer);
212 + try {
213 + return ImmutableSet.copyOf(intents.values());
214 + } finally {
215 + stopTimer(timer);
216 + }
156 } 217 }
157 218
158 @Override 219 @Override
159 public Intent getIntent(IntentId intentId) { 220 public Intent getIntent(IntentId intentId) {
160 - return intents.get(intentId); 221 + Context timer = startTimer(getIntentTimer);
222 + try {
223 + return intents.get(intentId);
224 + } finally {
225 + stopTimer(timer);
226 + }
161 } 227 }
162 228
163 @Override 229 @Override
164 public IntentState getIntentState(IntentId id) { 230 public IntentState getIntentState(IntentId id) {
165 - final IntentState localState = transientStates.get(id); 231 + Context timer = startTimer(getIntentStateTimer);
166 - if (localState != null) { 232 + try {
167 - return localState; 233 + final IntentState localState = transientStates.get(id);
234 + if (localState != null) {
235 + return localState;
236 + }
237 + return states.get(id);
238 + } finally {
239 + stopTimer(timer);
168 } 240 }
169 - return states.get(id);
170 } 241 }
171 242
172 private void verify(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) { 243 private void verify(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) {
...@@ -181,76 +252,97 @@ public class HazelcastIntentStore ...@@ -181,76 +252,97 @@ public class HazelcastIntentStore
181 252
182 @Override 253 @Override
183 public IntentEvent setState(Intent intent, IntentState state) { 254 public IntentEvent setState(Intent intent, IntentState state) {
184 - final IntentId id = intent.id(); 255 + Context timer = startTimer(setStateTimer);
185 - IntentEvent.Type type = null; 256 + try {
186 - final IntentState prevParking; 257 +
187 - boolean transientStateChangeOnly = false; 258 + final IntentId id = intent.id();
188 - 259 + IntentEvent.Type type = null;
189 - // parking state transition 260 + final IntentState prevParking;
190 - switch (state) { 261 + boolean transientStateChangeOnly = false;
191 - case SUBMITTED: 262 +
192 - prevParking = states.get(id); 263 + // parking state transition
193 - if (prevParking == null) { 264 + switch (state) {
194 - IntentState existing = states.putIfAbsent(id, SUBMITTED); 265 + case SUBMITTED:
195 - verify(existing == null, "Conditional replace %s => %s failed", prevParking, SUBMITTED); 266 + prevParking = states.get(id);
196 - } else { 267 + if (prevParking == null) {
197 - verify(prevParking == WITHDRAWN, 268 + IntentState existing = states.putIfAbsent(id, SUBMITTED);
198 - "Illegal state transition attempted from %s to SUBMITTED", 269 + verify(existing == null, "Conditional replace %s => %s failed", prevParking, SUBMITTED);
199 - prevParking); 270 + } else {
200 - boolean updated = states.replace(id, prevParking, SUBMITTED); 271 + verify(prevParking == WITHDRAWN,
201 - verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED); 272 + "Illegal state transition attempted from %s to SUBMITTED",
273 + prevParking);
274 + boolean updated = states.replace(id, prevParking, SUBMITTED);
275 + verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED);
276 + }
277 + type = IntentEvent.Type.SUBMITTED;
278 + break;
279 + case INSTALLED:
280 + prevParking = states.replace(id, INSTALLED);
281 + verify(PRE_INSTALLED.contains(prevParking),
282 + "Illegal state transition attempted from %s to INSTALLED",
283 + prevParking);
284 + type = IntentEvent.Type.INSTALLED;
285 + break;
286 + case FAILED:
287 + prevParking = states.replace(id, FAILED);
288 + type = IntentEvent.Type.FAILED;
289 + break;
290 + case WITHDRAWN:
291 + prevParking = states.replace(id, WITHDRAWN);
292 + verify(PRE_WITHDRAWN.contains(prevParking),
293 + "Illegal state transition attempted from %s to WITHDRAWN",
294 + prevParking);
295 + type = IntentEvent.Type.WITHDRAWN;
296 + break;
297 + default:
298 + transientStateChangeOnly = true;
299 + prevParking = null;
300 + break;
202 } 301 }
203 - type = IntentEvent.Type.SUBMITTED; 302 + if (!transientStateChangeOnly) {
204 - break; 303 + log.debug("Parking State change: {} {}=>{}", id, prevParking, state);
205 - case INSTALLED: 304 + }
206 - prevParking = states.replace(id, INSTALLED); 305 + // Update instance local state, which includes non-parking state transition
207 - verify(PRE_INSTALLED.contains(prevParking), 306 + final IntentState prevTransient = transientStates.put(id, state);
208 - "Illegal state transition attempted from %s to INSTALLED", 307 + log.debug("Transient State change: {} {}=>{}", id, prevTransient, state);
209 - prevParking);
210 - type = IntentEvent.Type.INSTALLED;
211 - break;
212 - case FAILED:
213 - prevParking = states.replace(id, FAILED);
214 - type = IntentEvent.Type.FAILED;
215 - break;
216 - case WITHDRAWN:
217 - prevParking = states.replace(id, WITHDRAWN);
218 - verify(PRE_WITHDRAWN.contains(prevParking),
219 - "Illegal state transition attempted from %s to WITHDRAWN",
220 - prevParking);
221 - type = IntentEvent.Type.WITHDRAWN;
222 - break;
223 - default:
224 - transientStateChangeOnly = true;
225 - prevParking = null;
226 - break;
227 - }
228 - if (!transientStateChangeOnly) {
229 - log.debug("Parking State change: {} {}=>{}", id, prevParking, state);
230 - }
231 - // Update instance local state, which includes non-parking state transition
232 - final IntentState prevTransient = transientStates.put(id, state);
233 - log.debug("Transient State change: {} {}=>{}", id, prevTransient, state);
234 308
235 - if (type == null) { 309 + if (type == null) {
236 - return null; 310 + return null;
311 + }
312 + return new IntentEvent(type, intent);
313 + } finally {
314 + stopTimer(timer);
237 } 315 }
238 - return new IntentEvent(type, intent);
239 } 316 }
240 317
241 @Override 318 @Override
242 public void setInstallableIntents(IntentId intentId, List<Intent> result) { 319 public void setInstallableIntents(IntentId intentId, List<Intent> result) {
243 - installable.put(intentId, result); 320 + Context timer = startTimer(setInstallableIntentsTimer);
321 + try {
322 + installable.put(intentId, result);
323 + } finally {
324 + stopTimer(timer);
325 + }
244 } 326 }
245 327
246 @Override 328 @Override
247 public List<Intent> getInstallableIntents(IntentId intentId) { 329 public List<Intent> getInstallableIntents(IntentId intentId) {
248 - return installable.get(intentId); 330 + Context timer = startTimer(getInstallableIntentsTimer);
331 + try {
332 + return installable.get(intentId);
333 + } finally {
334 + stopTimer(timer);
335 + }
249 } 336 }
250 337
251 @Override 338 @Override
252 public void removeInstalledIntents(IntentId intentId) { 339 public void removeInstalledIntents(IntentId intentId) {
253 - installable.remove(intentId); 340 + Context timer = startTimer(removeInstalledIntentsTimer);
341 + try {
342 + installable.remove(intentId);
343 + } finally {
344 + stopTimer(timer);
345 + }
254 } 346 }
255 347
256 public final class RemoteIntentStateListener extends EntryAdapter<IntentId, IntentState> { 348 public final class RemoteIntentStateListener extends EntryAdapter<IntentId, IntentState> {
......