/** Make a copy of the StateMachine maintaining the current state. * * @return a copy of the StateMachine. */ public Object clone() { StateMachine clone = new StateMachine(states, startState, description); clone.currentState = currentState; return clone; }
/** Transition to the next state given the name of a valid transition. * @param actionName - the name of transition that is valid for the * current state. * @return the next state * @throws IllegalTransitionException */ public State nextState(String actionName) throws IllegalTransitionException { Transition t = currentState.getTransition(actionName); if( t == null ) { String msg = "No transition for action: '" + actionName + "' from state: '" + currentState.getName() + "'"; throw new IllegalTransitionException(msg); } State nextState = t.getTarget(); log.trace("nextState("+actionName+") = "+nextState); currentState = nextState; return currentState; }
/** Add a transition to the allowed transition map. * * @param transition * @return this to allow chained addTransition calls */ public State addTransition(Transition transition) { allowedTransitions.put(transition.getName(), transition); return this; }
State s = new State(stateName); states.add(s); nameToStateMap.put(stateName, s); log.debug(msg); Transition t = new Transition(name, target); s.addTransition(t); throw new Exception("Failed to resolve transition targets: " + resolveFailed); StateMachine sm = new StateMachine(states, startState, description); return sm;
public boolean inService() throws PolicyContextException { validateState("inService"); State state = configStateMachine.getCurrentState(); boolean inService = state.getName().equals("inService"); return inService; }
public String toString() { StringBuffer tmp = new StringBuffer("State(name="); tmp.append(name); Iterator i = allowedTransitions.entrySet().iterator(); while( i.hasNext() ) { Map.Entry e = (Map.Entry) i.next(); tmp.append("\n\t on: "); tmp.append(e.getKey()); Transition t = (Transition) e.getValue(); tmp.append(" go to: "); tmp.append(t.getTarget().getName()); } tmp.append(')'); return tmp.toString(); } }
public String toString() { StringBuffer tmp = new StringBuffer("StateMachine[:\n"); tmp.append("\tCurrentState: "+currentState.getName()); Iterator i = states.iterator(); while( i.hasNext() ) { tmp.append('\n').append(i.next()); } tmp.append(']'); return tmp.toString(); } }
protected void validateState(String action) throws PolicyContextException { try { configStateMachine.nextState(action); } catch(IllegalTransitionException e) { log.debug("validateState failure", e); throw new PolicyContextException("Operation not allowed", e); } } }
public PolicyConfiguration getPolicyConfiguration(String contextID, boolean remove) throws PolicyContextException { JBossPolicyConfiguration pc = (JBossPolicyConfiguration) policyConfigMap.get(contextID); if( pc == null ) { StateMachine sm = (StateMachine) configStateMachine.clone(); pc = new JBossPolicyConfiguration(contextID, policy, sm); policyConfigMap.put(contextID, pc); } pc.initPolicyConfiguration(remove); return pc; }
/** * Create a new StateMachine that follows the ServiceMBean * lifecycle, initialized to the STATE_UNREGISTERED state. * * @param description A string description for this state machine, or null * @return the StateMachine */ public static StateMachine createStateMachine(String description) { return new StateMachine(STATES, STATE_UNREGISTERED, description); }
/** * Create a new StateMachine that follows the ServiceMBean * lifecycle, initialized to the STATE_UNREGISTERED state. * * @param description A string description for this state machine, or null * @return the StateMachine */ public static StateMachine createStateMachine(String description) { return new StateMachine(STATES, STATE_UNREGISTERED, description); }