List of usage examples for org.springframework.statemachine.support StateMachineUtils containsAtleastOne
public static <S> boolean containsAtleastOne(Collection<S> left, Collection<S> right)
From source file:org.springframework.statemachine.processor.StateMachineHandlerCallHelper.java
private boolean annotationHandlerVariableMatch(Annotation annotation, Object key) { boolean handle = false; Map<String, Object> annotationAttributes = AnnotationUtils.getAnnotationAttributes(annotation); Object object = annotationAttributes.get("key"); Collection<String> scoll = StateMachineUtils.toStringCollection(object); if (!scoll.isEmpty()) { if (StateMachineUtils.containsAtleastOne(scoll, StateMachineUtils.toStringCollection(key))) { handle = true;/*from ww w . j a va 2 s. com*/ } } else { handle = true; } return handle; }
From source file:org.springframework.statemachine.processor.StateMachineHandlerCallHelper.java
private boolean annotationHandlerEventVariableMatch(Annotation annotation, Object key) { boolean handle = false; Map<String, Object> annotationAttributes = AnnotationUtils.getAnnotationAttributes(annotation); Object object = annotationAttributes.get("event"); Collection<String> scoll = StateMachineUtils.toStringCollection(object); if (!scoll.isEmpty()) { if (StateMachineUtils.containsAtleastOne(scoll, StateMachineUtils.toStringCollection(key))) { handle = true;/* w w w . ja v a 2 s . co m*/ } } else { handle = true; } return handle; }
From source file:org.springframework.statemachine.processor.StateMachineHandlerCallHelper.java
private boolean annotationHandlerSourceTargetMatch(String[] msources, String[] mtargets, Annotation methodAnnotation, State<S, E> sourceState, State<S, E> targetState) { Map<String, Object> annotationAttributes = AnnotationUtils.getAnnotationAttributes(methodAnnotation); Object source = annotationAttributes.get("source"); Object target = annotationAttributes.get("target"); Collection<String> scoll = StateMachineUtils.toStringCollection(source); if (scoll.isEmpty() && msources != null) { scoll = Arrays.asList(msources); }/*w w w. j av a 2 s .c o m*/ Collection<String> tcoll = StateMachineUtils.toStringCollection(target); if (tcoll.isEmpty() && mtargets != null) { tcoll = Arrays.asList(mtargets); } boolean handle = false; if (!scoll.isEmpty() && !tcoll.isEmpty()) { if (sourceState != null && targetState != null && StateMachineUtils.containsAtleastOne(scoll, StateMachineUtils.toStringCollection(sourceState.getIds())) && StateMachineUtils.containsAtleastOne(tcoll, StateMachineUtils.toStringCollection(targetState.getIds()))) { handle = true; } } else if (!scoll.isEmpty()) { if (sourceState != null && StateMachineUtils.containsAtleastOne(scoll, StateMachineUtils.toStringCollection(sourceState.getIds()))) { handle = true; } } else if (!tcoll.isEmpty()) { if (targetState != null && StateMachineUtils.containsAtleastOne(tcoll, StateMachineUtils.toStringCollection(targetState.getIds()))) { handle = true; } } else if (scoll.isEmpty() && tcoll.isEmpty()) { handle = true; } return handle; }
From source file:org.springframework.statemachine.support.AbstractStateMachine.java
protected synchronized boolean acceptEvent(Message<E> message) { if ((currentState != null && currentState.shouldDefer(message))) { log.info("Current state " + currentState + " deferred event " + message); stateMachineExecutor.queueDeferredEvent(message); return true; }//from ww w. ja v a 2 s. com if ((currentState != null && currentState.sendEvent(message))) { return true; } if (log.isDebugEnabled()) { log.debug("Queue event " + message + " " + this); } for (Transition<S, E> transition : transitions) { State<S, E> source = transition.getSource(); Trigger<S, E> trigger = transition.getTrigger(); if (StateMachineUtils.containsAtleastOne(source.getIds(), currentState.getIds())) { if (trigger != null && trigger.evaluate(new DefaultTriggerContext<S, E>(message.getPayload()))) { stateMachineExecutor.queueEvent(message); return true; } } } // if we're about to not accept event, check defer again in case // state was changed between original check and now if ((currentState != null && currentState.shouldDefer(message))) { log.info("Current state " + currentState + " deferred event " + message); stateMachineExecutor.queueDeferredEvent(message); return true; } return false; }
From source file:org.springframework.statemachine.support.DefaultStateMachineExecutor.java
private boolean handleTriggerTrans(List<Transition<S, E>> trans, Message<E> queuedMessage) { boolean transit = false; for (Transition<S, E> t : trans) { if (t == null) { continue; }/*from w ww .j a v a 2 s . co m*/ State<S, E> source = t.getSource(); if (source == null) { continue; } State<S, E> currentState = stateMachine.getState(); if (currentState == null) { continue; } if (!StateMachineUtils.containsAtleastOne(source.getIds(), currentState.getIds())) { continue; } // special handling of join if (StateMachineUtils.isPseudoState(t.getTarget(), PseudoStateKind.JOIN)) { if (joinSyncStates.isEmpty()) { List<State<S, E>> joins = ((JoinPseudoState<S, E>) t.getTarget().getPseudoState()).getJoins(); joinSyncStates.addAll(joins); } joinSyncTransitions.add(t); boolean removed = joinSyncStates.remove(t.getSource()); boolean joincomplete = removed & joinSyncStates.isEmpty(); if (joincomplete) { for (Transition<S, E> tt : joinSyncTransitions) { StateContext<S, E> stateContext = buildStateContext(queuedMessage, tt, relayStateMachine); tt.transit(stateContext); stateMachineExecutorTransit.transit(tt, stateContext, queuedMessage); } joinSyncTransitions.clear(); break; } else { continue; } } StateContext<S, E> stateContext = buildStateContext(queuedMessage, t, relayStateMachine); try { stateContext = interceptors.preTransition(stateContext); } catch (Exception e) { // currently expect that if exception is // thrown, this transition will not match. // i.e. security may throw AccessDeniedException log.info("Interceptors threw exception", e); stateContext = null; } if (stateContext == null) { break; } try { transit = t.transit(stateContext); } catch (Exception e) { log.warn("Transition " + t + " caused error " + e); } if (transit) { stateMachineExecutorTransit.transit(t, stateContext, queuedMessage); interceptors.postTransition(stateContext); break; } } return transit; }
From source file:org.springframework.statemachine.support.DefaultStateMachineExecutor.java
private boolean processEventQueue() { if (log.isDebugEnabled()) { log.debug("Process event queue, size=" + eventQueue.size()); }/*from w w w .j a va 2s. co m*/ Message<E> queuedEvent = eventQueue.poll(); State<S, E> currentState = stateMachine.getState(); if (queuedEvent != null) { if ((currentState != null && currentState.shouldDefer(queuedEvent))) { log.info("Current state " + currentState + " deferred event " + queuedEvent); queueDeferredEvent(queuedEvent); return true; } for (Transition<S, E> transition : transitions) { State<S, E> source = transition.getSource(); Trigger<S, E> trigger = transition.getTrigger(); if (StateMachineUtils.containsAtleastOne(source.getIds(), currentState.getIds())) { if (trigger != null && trigger.evaluate(new DefaultTriggerContext<S, E>(queuedEvent.getPayload()))) { queueTrigger(trigger, queuedEvent); return true; } } } } return false; }