use of org.jivesoftware.smack.fsm.StateDescriptorGraph.GraphVertex in project Smack by igniterealtime.
the class ModularXmppClientToServerConnection method walkStateGraphInternal.
private void walkStateGraphInternal(WalkStateGraphContext walkStateGraphContext) throws IOException, SmackException, InterruptedException, XMPPException {
// Save a copy of the current state
final GraphVertex<State> initialStateVertex = currentStateVertex;
final State initialState = initialStateVertex.getElement();
final StateDescriptor initialStateDescriptor = initialState.getStateDescriptor();
walkStateGraphContext.recordWalkTo(initialState);
// Check if this is the walk's final state.
if (walkStateGraphContext.isWalksFinalState(initialStateDescriptor)) {
// If this is used as final state, then it should be marked as such.
assert initialStateDescriptor.isFinalState();
// We reached the final state.
invokeConnectionStateMachineListener(new ConnectionStateEvent.FinalStateReached(initialState));
return;
}
List<GraphVertex<State>> outgoingStateEdges = initialStateVertex.getOutgoingEdges();
// See if we need to handle mandatory intermediate states.
GraphVertex<State> mandatoryIntermediateStateVertex = walkStateGraphContext.maybeReturnMandatoryImmediateState(outgoingStateEdges);
if (mandatoryIntermediateStateVertex != null) {
StateTransitionResult reason = attemptEnterState(mandatoryIntermediateStateVertex, walkStateGraphContext);
if (reason instanceof StateTransitionResult.Success) {
walkStateGraph(walkStateGraphContext);
return;
}
// We could not enter a mandatory intermediate state. Throw here.
throw new StateMachineException.SmackMandatoryStateFailedException(mandatoryIntermediateStateVertex.getElement(), reason);
}
for (Iterator<GraphVertex<State>> it = outgoingStateEdges.iterator(); it.hasNext(); ) {
GraphVertex<State> successorStateVertex = it.next();
State successorState = successorStateVertex.getElement();
// state.
if (walkStateGraphContext.wouldCauseCycle(successorStateVertex)) {
// Ignore this successor.
invokeConnectionStateMachineListener(new ConnectionStateEvent.TransitionIgnoredDueCycle(initialStateVertex, successorStateVertex));
} else {
StateTransitionResult result = attemptEnterState(successorStateVertex, walkStateGraphContext);
if (result instanceof StateTransitionResult.Success) {
break;
}
// record it.
if (result != null) {
walkStateGraphContext.recordFailedState(successorState, result);
}
}
if (!it.hasNext()) {
throw StateMachineException.SmackStateGraphDeadEndException.from(walkStateGraphContext, initialStateVertex);
}
}
// Walk the state graph by recursion.
walkStateGraph(walkStateGraphContext);
}
Aggregations