Yuta HIGUCHI

DistributedIntentStore: remove transient state, after transition to parking state

Change-Id: Id0a5bf6a94c03c7eb15d399fd85bf00f4322f6d4
...@@ -168,9 +168,9 @@ public class DistributedIntentStore ...@@ -168,9 +168,9 @@ public class DistributedIntentStore
168 @Override 168 @Override
169 public IntentEvent setState(Intent intent, IntentState state) { 169 public IntentEvent setState(Intent intent, IntentState state) {
170 final IntentId id = intent.id(); 170 final IntentId id = intent.id();
171 - IntentEvent.Type type = null; 171 + IntentEvent.Type evtType = null;
172 final IntentState prevParking; 172 final IntentState prevParking;
173 - boolean transientStateChangeOnly = false; 173 + boolean transitionedToParking = true;
174 boolean updated; 174 boolean updated;
175 175
176 // parking state transition 176 // parking state transition
...@@ -187,7 +187,7 @@ public class DistributedIntentStore ...@@ -187,7 +187,7 @@ public class DistributedIntentStore
187 updated = states.replace(id, prevParking, SUBMITTED); 187 updated = states.replace(id, prevParking, SUBMITTED);
188 verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED); 188 verify(updated, "Conditional replace %s => %s failed", prevParking, SUBMITTED);
189 } 189 }
190 - type = IntentEvent.Type.SUBMITTED; 190 + evtType = IntentEvent.Type.SUBMITTED;
191 break; 191 break;
192 192
193 case INSTALLED: 193 case INSTALLED:
...@@ -197,14 +197,14 @@ public class DistributedIntentStore ...@@ -197,14 +197,14 @@ public class DistributedIntentStore
197 prevParking); 197 prevParking);
198 updated = states.replace(id, prevParking, INSTALLED); 198 updated = states.replace(id, prevParking, INSTALLED);
199 verify(updated, "Conditional replace %s => %s failed", prevParking, INSTALLED); 199 verify(updated, "Conditional replace %s => %s failed", prevParking, INSTALLED);
200 - type = IntentEvent.Type.INSTALLED; 200 + evtType = IntentEvent.Type.INSTALLED;
201 break; 201 break;
202 202
203 case FAILED: 203 case FAILED:
204 prevParking = states.get(id); 204 prevParking = states.get(id);
205 updated = states.replace(id, prevParking, FAILED); 205 updated = states.replace(id, prevParking, FAILED);
206 verify(updated, "Conditional replace %s => %s failed", prevParking, FAILED); 206 verify(updated, "Conditional replace %s => %s failed", prevParking, FAILED);
207 - type = IntentEvent.Type.FAILED; 207 + evtType = IntentEvent.Type.FAILED;
208 break; 208 break;
209 209
210 case WITHDRAWN: 210 case WITHDRAWN:
...@@ -214,25 +214,28 @@ public class DistributedIntentStore ...@@ -214,25 +214,28 @@ public class DistributedIntentStore
214 prevParking); 214 prevParking);
215 updated = states.replace(id, prevParking, WITHDRAWN); 215 updated = states.replace(id, prevParking, WITHDRAWN);
216 verify(updated, "Conditional replace %s => %s failed", prevParking, WITHDRAWN); 216 verify(updated, "Conditional replace %s => %s failed", prevParking, WITHDRAWN);
217 - type = IntentEvent.Type.WITHDRAWN; 217 + evtType = IntentEvent.Type.WITHDRAWN;
218 break; 218 break;
219 219
220 default: 220 default:
221 - transientStateChangeOnly = true; 221 + transitionedToParking = false;
222 prevParking = null; 222 prevParking = null;
223 break; 223 break;
224 } 224 }
225 - if (!transientStateChangeOnly) { 225 + if (transitionedToParking) {
226 log.debug("Parking State change: {} {}=>{}", id, prevParking, state); 226 log.debug("Parking State change: {} {}=>{}", id, prevParking, state);
227 + // remove instance local state
228 + transientStates.remove(id);
229 + } else {
230 + // Update instance local state, which includes non-parking state transition
231 + final IntentState prevTransient = transientStates.put(id, state);
232 + log.debug("Transient State change: {} {}=>{}", id, prevTransient, state);
227 } 233 }
228 - // Update instance local state, which includes non-parking state transition
229 - final IntentState prevTransient = transientStates.put(id, state);
230 - log.debug("Transient State change: {} {}=>{}", id, prevTransient, state);
231 234
232 - if (type == null) { 235 + if (evtType == null) {
233 return null; 236 return null;
234 } 237 }
235 - return new IntentEvent(type, intent); 238 + return new IntentEvent(evtType, intent);
236 } 239 }
237 240
238 @Override 241 @Override
......