in omega/omega-transaction/src/main/java/org/apache/servicecomb/pack/omega/transaction/wrapper/SagaStartAnnotationProcessorTimeoutWrapper.java [43:99]
public Object apply(ProceedingJoinPoint joinPoint, SagaStart sagaStart, OmegaContext context)
throws Throwable {
final TimeoutProb timeoutProb = TimeoutProbManager.getInstance()
.addTimeoutProb(sagaStart.timeout());
Object output;
try {
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
sagaStartAnnotationProcessor.preIntercept(sagaStart.timeout());
if (LOG.isDebugEnabled()) {
LOG.debug("Initialized context {} before execution of method {}", context,
method.toString());
}
try {
output = joinPoint.proceed();
if (timeoutProb.getInterruptFailureException() != null) {
throw new OmegaException(timeoutProb.getInterruptFailureException());
}
if (sagaStart.autoClose()) {
sagaStartAnnotationProcessor.postIntercept(context.globalTxId());
if (LOG.isDebugEnabled()) {
LOG.debug("Transaction with context {} has finished.", context);
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Transaction with context {} is not finished in the SagaStarted annotated method.", context);
}
}
return output;
} catch (Throwable throwable) {
// TODO We still need to intercept some exceptions that we can't judge the state of the child transaction.
// At this point, we don't need to send SagaAbortEvent, just need to throw a TransactionTimeoutException
// For example, java.net.SocketTimeoutException, etc.
if (LOG.isDebugEnabled()) {
LOG.debug("TimeoutWrapper exception {}", throwable.getClass().getName());
}
if (timeoutProb.getInterruptFailureException() != null) {
LOG.info("TimeoutProb interrupt fail");
throw timeoutProb.getInterruptFailureException();
} else if (isThreadInterruptException(throwable)) {
// We don't have to send an SagaAbortEvent
// Because the SagaActor state automatically change to suspended when timeout.
throw new TransactionTimeoutException("Timeout interrupt", throwable);
} else {
// We don't need to handle the OmegaException here
if (!(throwable instanceof OmegaException)) {
LOG.info("TimeoutWrapper Exception {}", throwable.getClass().getName());
sagaStartAnnotationProcessor.onError(method.toString(), throwable);
LOG.error("Transaction {} failed.", context.globalTxId());
}
}
throw throwable;
}
} finally {
context.clear();
TimeoutProbManager.getInstance().removeTimeoutProb(timeoutProb);
}
}