use of org.broadleafcommerce.core.workflow.state.RollbackStateLocal in project BroadleafCommerce by BroadleafCommerce.
the class TestRollbackHandler method rollbackState.
@Override
@Transactional("blTransactionManager")
public void rollbackState(Activity<ProcessContext<CheckoutSeed>> activity, ProcessContext<CheckoutSeed> processContext, Map<String, Object> stateConfiguration) throws RollbackFailureException {
LOG.warn("******************* TestRollbackHandler Engaged *********************");
LOG.warn("******************* Activity: " + activity.getBeanName() + " *********************");
RollbackStateLocal rollbackStateLocal = RollbackStateLocal.getRollbackStateLocal();
LOG.warn("******************* Workflow: " + rollbackStateLocal.getWorkflowId() + " *********************");
LOG.warn("******************* Thread: " + rollbackStateLocal.getThreadId() + " *********************");
}
use of org.broadleafcommerce.core.workflow.state.RollbackStateLocal in project BroadleafCommerce by BroadleafCommerce.
the class SequenceProcessor method doActivities.
@Override
public <P extends ProcessContext<U>> P doActivities(T seedData) throws WorkflowException {
if (LOG.isDebugEnabled()) {
LOG.debug(getBeanName() + " processor is running..");
}
ActivityStateManager activityStateManager = getBeanFactory().getBean(ActivityStateManager.class, "blActivityStateManager");
if (activityStateManager == null) {
throw new IllegalStateException("Unable to find an instance of ActivityStateManager registered under bean id blActivityStateManager");
}
ProcessContext<U> context = null;
RollbackStateLocal rollbackStateLocal = new RollbackStateLocal();
rollbackStateLocal.setThreadId(String.valueOf(Thread.currentThread().getId()));
rollbackStateLocal.setWorkflowId(getBeanName());
RollbackStateLocal.setRollbackStateLocal(rollbackStateLocal);
try {
// retrieve injected by Spring
List<Activity<ProcessContext<U>>> activities = getActivities();
// retrieve a new instance of the Workflow ProcessContext
context = createContext(seedData);
for (Activity<ProcessContext<U>> activity : activities) {
if (activity.shouldExecute(context)) {
if (LOG.isDebugEnabled()) {
LOG.debug("running activity:" + activity.getBeanName() + " using arguments:" + context);
}
try {
context = activity.execute(context);
} catch (Throwable activityException) {
RollbackFailureException rollbackFailure = null;
if (getAutoRollbackOnError()) {
LOG.info(String.format("Exception ocurred in %s, executing rollback handlers", rollbackStateLocal.getWorkflowId()));
try {
ActivityStateManagerImpl.getStateManager().rollbackAllState();
} catch (Throwable rollbackException) {
LOG.fatal(String.format("There was an exception rolling back %s", rollbackStateLocal.getWorkflowId()), rollbackException);
if (rollbackException instanceof RollbackFailureException) {
rollbackFailure = (RollbackFailureException) rollbackException;
} else {
rollbackFailure = new RollbackFailureException(rollbackException);
}
LOG.error(String.format("The original cause of the rollback for %s was", rollbackStateLocal.getWorkflowId()), activityException);
rollbackFailure.setOriginalWorkflowException(activityException);
throw rollbackFailure;
}
}
ErrorHandler errorHandler = activity.getErrorHandler();
if (errorHandler == null) {
getDefaultErrorHandler().handleError(context, activityException);
break;
} else {
errorHandler.handleError(context, activityException);
}
}
// ensure its ok to continue the process
if (processShouldStop(context, activity)) {
break;
}
// register the RollbackHandler
if (activity.getRollbackHandler() != null && activity.getAutomaticallyRegisterRollbackHandler()) {
ActivityStateManagerImpl.getStateManager().registerState(activity, context, activity.getRollbackRegion(), activity.getRollbackHandler(), activity.getStateConfiguration());
}
} else {
LOG.debug("Not executing activity: " + activity.getBeanName() + " based on the context: " + context);
}
}
} finally {
rollbackStateLocal = RollbackStateLocal.getRollbackStateLocal();
if (rollbackStateLocal != null && rollbackStateLocal.getWorkflowId().equals(getBeanName())) {
activityStateManager.clearAllState();
}
}
LOG.debug(getBeanName() + " processor is done.");
return (P) context;
}
Aggregations