Fix event overflow

- Fixes #89
- Added new method into EnsembleListeger which can
  be used to listen ensemble errors.
This commit is contained in:
Janne Valkealahti
2015-07-25 08:31:03 +01:00
parent 74f2f72ed6
commit 0fba91cbf2
8 changed files with 269 additions and 3 deletions

View File

@@ -56,4 +56,12 @@ public class CompositeEnsembleListener<S, E> extends AbstractCompositeListener<E
}
}
@Override
public void ensembleError(StateMachineEnsembleException exception) {
for (Iterator<EnsembleListeger<S, E>> iterator = getListeners().reverse(); iterator.hasNext();) {
EnsembleListeger<S, E> listener = iterator.next();
listener.ensembleError(exception);
}
}
}

View File

@@ -202,9 +202,9 @@ public class DistributedStateMachine<S, E> extends LifecycleObjectSupport implem
&& stateContext.getTransition().getKind() == TransitionKind.INTERNAL
&& ObjectUtils.nullSafeEquals(delegate.getId(),
stateContext.getMessageHeader(StateMachineSystemConstants.STATEMACHINE_IDENTIFIER))) {
StateMachineContext<S, E> xxx = ensemble.getState();
StateMachineContext<S, E> current = ensemble.getState();
ensemble.setState(new DefaultStateMachineContext<S, E>(
xxx.getState(), stateContext.getEvent(), stateContext
current.getState(), stateContext.getEvent(), stateContext
.getMessageHeaders(), stateContext.getStateMachine().getExtendedState()));
}
return stateContext;
@@ -262,6 +262,14 @@ public class DistributedStateMachine<S, E> extends LifecycleObjectSupport implem
}
}
@Override
public void ensembleError(StateMachineEnsembleException exception) {
// TODO: when we get support for sm error handling,
// propagate this exception there
log.error("Ensemble error", exception);
throw exception;
}
}
}

View File

@@ -51,4 +51,11 @@ public interface EnsembleListeger<S, E> {
*/
void stateChanged(StateMachineContext<S, E> context);
/**
* Called when {@link StateMachineEnsemble} resulted an error.
*
* @param exception the exception
*/
void ensembleError(StateMachineEnsembleException exception);
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright 2015 the original author or authors.
*
* 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.springframework.statemachine.ensemble;
import java.io.IOException;
import org.springframework.statemachine.StateMachineException;
/**
* General exception indicating a problem in ensemble.
*
* @author Janne Valkealahti
*
*/
public class StateMachineEnsembleException extends StateMachineException {
private static final long serialVersionUID = 960498044587123343L;
/**
* Instantiates a new state machine ensemble exception.
*
* @param e the e
*/
public StateMachineEnsembleException(IOException e) {
super(e);
}
/**
* Instantiates a new state machine ensemble exception.
*
* @param message the message
* @param e the e
*/
public StateMachineEnsembleException(String message, Exception e) {
super(message, e);
}
/**
* Instantiates a new state machine ensemble exception.
*
* @param message the message
* @param cause the cause
*/
public StateMachineEnsembleException(String message, Throwable cause) {
super(message, cause);
}
/**
* Instantiates a new state machine ensemble exception.
*
* @param message the message
*/
public StateMachineEnsembleException(String message) {
super(message);
}
}

View File

@@ -59,6 +59,10 @@ public abstract class StateMachineEnsembleObjectSupport<S, E> extends LifecycleO
ensembleListener.stateMachineLeft(stateMachine, context);
}
protected void notifyError(StateMachineEnsembleException exception) {
ensembleListener.ensembleError(exception);
}
protected void notifyStateChanged(StateMachineContext<S, E> context) {
if (log.isTraceEnabled()) {
log.trace("Notify notifyStateChanged " + context);