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