public void addState(ControllerState state, ControllerState before) { lockWrite(); try { if (stateModel.addState(state, before)) { Set<ControllerContext> contexts = new CopyOnWriteArraySet<ControllerContext>(); contextsByState.put(state, contexts); } } finally { unlockWrite(); } }
/** * Handle uninstall lifecycle callbacks. * * @param context the context * @param state the state * @throws Throwable for any error */ protected void handleUninstallLifecycleCallbacks(ControllerContext context, ControllerState state) throws Throwable { ControllerState oldState = stateModel.getNextState(state); handleLifecycleCallbacks(context, oldState, false); }
public ControllerState indexState(ControllerState state) { return stateModel.indexState(state); }
if (!stateModel.isValidState(toState)) log.error("INTERNAL ERROR: unknown state " + toState + " states=" + stateModel, new Exception("STACKTRACE")); if (ControllerState.ERROR.equals(fromState)) return; if (!stateModel.isValidState(fromState)) log.error("INTERNAL ERROR: current state not found: " + context.toShortString(), new Exception("STACKTRACE")); if (stateModel.isAfterState(toState, fromState)) return; else
if (!stateModel.isValidState(context.getRequiredState())) throw new IllegalArgumentException("Unknown state: " + context.getRequiredState()); while(resolved && stateModel.isBeforeState(context.getState(), context.getRequiredState()) && !interrupted) ControllerState toState = stateModel.getNextState(context.getState()); if (advance(context)) uninstallContext(context, stateModel.getInitialState(), trace); errorContexts.put(context.getName(), context); context.setError(error);
if (!stateModel.isValidState(state)) throw new IllegalArgumentException("Unknown state: " + state); if (stateModel.isBeforeState(context.getState(), state)) resolveContexts(trace); else while (stateModel.isAfterState(context.getState(), state))
for (ControllerState fromState : stateModel) ControllerState toState = stateModel.getNextState(fromState); ControllerState nextState = stateModel.getNextState(state); if (stateModel.isValidState(nextState)) // only check states with valid next state
if (ControllerState.ERROR.equals(fromState)) ControllerState initialState = stateModel.getInitialState(); errorContexts.remove(context); Throwable error = null; if (fromContexts.contains(context) == false) throw new IllegalStateException("Context not found in previous state (" + fromState + "): " + context.toShortString()); toState = stateModel.getNextState(fromState); if (toState == null) throw new IllegalStateException("No state after " + fromState); uninstallContext(context, stateModel.getInitialState(), trace); errorContexts.put(context.getName(), context); context.setError(error);
whenRequired = stateModel.getInitialState(); if (stateModel.isBeforeState(dependent.getState(), whenRequired) == false)
/** * Whether we should advance the context<p> * <p/> * This method must be invoked with the write lock taken * * @param context the context * @return true when we should advance the context */ protected boolean advance(ControllerContext context) { ControllerMode mode = context.getMode(); // Never advance for disabled if (ControllerMode.DISABLED.equals(mode)) return false; return stateModel.isBeforeState(context.getState(), context.getRequiredState()); }
uninstallContext(ctx, stateModel.getInitialState(), trace); errorContexts.put(ctx.getName(), ctx); ctx.setError(error);
/** * Get all the contexts. * In state decending order. * * @return all contexts */ public Set<ControllerContext> getAllContexts() { lockRead(); try { LinkedHashSet<ControllerContext> result = new LinkedHashSet<ControllerContext>(); ListIterator<ControllerState> it = stateModel.listIteraror(); if (it.hasNext()) { result.addAll(getContextsByState(it.next())); while (it.hasPrevious()) { result.addAll(getContextsByState(it.previous())); } } result.addAll(errorContexts.values()); return result; } finally { unlockRead(); } }
if (state != null && stateModel.isBeforeState(result.getState(), state))
uninstallContext(context, stateModel.getInitialState(), trace);
ControllerState state = stateModel.getNextState(ControllerMode.ON_DEMAND.getRequiredState()); uninstallContext(other, state, trace);