2019-02-04 08:59:39 +01:00
|
|
|
/**
|
|
|
|
*
|
2020-04-04 13:03:31 +02:00
|
|
|
* Copyright 2018-2020 Florian Schmaus
|
2019-02-04 08:59:39 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smack.fsm;
|
|
|
|
|
2020-04-04 13:03:31 +02:00
|
|
|
import org.jivesoftware.smack.fsm.StateDescriptorGraph.GraphVertex;
|
2019-02-04 08:59:39 +01:00
|
|
|
|
|
|
|
public class ConnectionStateEvent {
|
|
|
|
|
2020-04-04 13:03:31 +02:00
|
|
|
private final StateDescriptor currentStateDescriptor;
|
|
|
|
private final StateDescriptor successorStateDescriptor;
|
2019-02-04 08:59:39 +01:00
|
|
|
|
|
|
|
private final long timestamp;
|
|
|
|
|
2020-04-04 13:03:31 +02:00
|
|
|
public ConnectionStateEvent(StateDescriptor currentStateDescriptor) {
|
|
|
|
this(currentStateDescriptor, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConnectionStateEvent(StateDescriptor currentStateDescriptor, StateDescriptor successorStateDescriptor) {
|
|
|
|
this.currentStateDescriptor = currentStateDescriptor;
|
|
|
|
this.successorStateDescriptor = successorStateDescriptor;
|
2019-02-04 08:59:39 +01:00
|
|
|
this.timestamp = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
|
|
|
public StateDescriptor getStateDescriptor() {
|
2020-04-04 13:03:31 +02:00
|
|
|
return currentStateDescriptor;
|
2019-02-04 08:59:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2020-04-04 13:03:31 +02:00
|
|
|
if (successorStateDescriptor == null) {
|
|
|
|
return getClass().getSimpleName() + ": " + currentStateDescriptor.getStateName();
|
|
|
|
} else {
|
|
|
|
return currentStateDescriptor.getStateName() + ' ' + getClass().getSimpleName() + ' '
|
|
|
|
+ successorStateDescriptor.getStateName();
|
|
|
|
}
|
2019-02-04 08:59:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getTimestamp() {
|
|
|
|
return timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class StateRevertBackwardsWalk extends ConnectionStateEvent {
|
2020-04-04 13:03:31 +02:00
|
|
|
public StateRevertBackwardsWalk(State state) {
|
2019-02-04 08:59:39 +01:00
|
|
|
super(state.getStateDescriptor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class FinalStateReached extends ConnectionStateEvent {
|
2020-04-04 13:03:31 +02:00
|
|
|
public FinalStateReached(State state) {
|
2019-02-04 08:59:39 +01:00
|
|
|
super(state.getStateDescriptor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class TransitionNotPossible extends ConnectionStateEvent {
|
2020-04-04 13:03:31 +02:00
|
|
|
private final StateTransitionResult.TransitionImpossible transitionImpossibleReason;
|
2019-02-04 08:59:39 +01:00
|
|
|
|
2020-04-04 13:03:31 +02:00
|
|
|
public TransitionNotPossible(State currentState, State successorState, StateTransitionResult.TransitionImpossible reason) {
|
|
|
|
super(currentState.getStateDescriptor(), successorState.getStateDescriptor());
|
2019-02-04 08:59:39 +01:00
|
|
|
this.transitionImpossibleReason = reason;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return super.toString() + ": " + transitionImpossibleReason;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class AboutToTransitionInto extends ConnectionStateEvent {
|
2020-04-04 13:03:31 +02:00
|
|
|
public AboutToTransitionInto(State currentState, State successorState) {
|
|
|
|
super(currentState.getStateDescriptor(), successorState.getStateDescriptor());
|
2019-02-04 08:59:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class TransitionFailed extends ConnectionStateEvent {
|
2020-04-04 13:03:31 +02:00
|
|
|
private final StateTransitionResult.Failure transitionFailedReason;
|
2019-02-04 08:59:39 +01:00
|
|
|
|
2020-04-04 13:03:31 +02:00
|
|
|
public TransitionFailed(State currentState, State failedSuccessorState, StateTransitionResult.Failure transitionFailedReason) {
|
|
|
|
super(currentState.getStateDescriptor(), failedSuccessorState.getStateDescriptor());
|
2019-02-04 08:59:39 +01:00
|
|
|
this.transitionFailedReason = transitionFailedReason;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return super.toString() + ": " + transitionFailedReason;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-04 13:03:31 +02:00
|
|
|
public static class TransitionIgnoredDueCycle extends ConnectionStateEvent {
|
|
|
|
public TransitionIgnoredDueCycle(GraphVertex<State> currentStateVertex, GraphVertex<State> successorStateVertexCausingCycle) {
|
|
|
|
super(currentStateVertex.getElement().getStateDescriptor(), successorStateVertexCausingCycle.getElement().getStateDescriptor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 08:59:39 +01:00
|
|
|
public static class SuccessfullyTransitionedInto extends ConnectionStateEvent {
|
2020-04-04 13:03:31 +02:00
|
|
|
private final StateTransitionResult.Success transitionSuccessResult;
|
2019-02-04 08:59:39 +01:00
|
|
|
|
2020-04-04 13:03:31 +02:00
|
|
|
public SuccessfullyTransitionedInto(State state, StateTransitionResult.Success transitionSuccessResult) {
|
2019-02-04 08:59:39 +01:00
|
|
|
super(state.getStateDescriptor());
|
|
|
|
this.transitionSuccessResult = transitionSuccessResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return super.toString() + ": " + transitionSuccessResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract static class DetailedTransitionIntoInformation extends ConnectionStateEvent {
|
|
|
|
protected DetailedTransitionIntoInformation(State state) {
|
|
|
|
super(state.getStateDescriptor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|