Object advise()

in omega/omega-transaction/src/main/java/org/apache/servicecomb/pack/omega/transaction/tcc/TccParticipatorAspect.java [60:99]


  Object advise(ProceedingJoinPoint joinPoint, Participate participate) throws Throwable {
    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    TransactionContext transactionContext = extractTransactionContext(joinPoint.getArgs());
    if (transactionContext != null) {
      populateOmegaContext(context, transactionContext);
    }

    String localTxId = context.localTxId();
    String cancelMethod = callbackMethodSignature(joinPoint, participate.cancelMethod(), method);
    String confirmMethod = callbackMethodSignature(joinPoint, participate.confirmMethod(), method);

    context.newLocalTxId();
    LOG.debug("Updated context {} for participate method {} ", context, method.toString());

    try {
      AlphaResponse response = tccMessageSender.participationStart(new ParticipationStartedEvent(context.globalTxId(), context.localTxId(), localTxId,
                                   confirmMethod, cancelMethod));
      if(response.aborted()){
        throw new OmegaException("transcation has aborted: " + context.globalTxId());
      }
      Object result = joinPoint.proceed();
      // Send the participate message back
      tccMessageSender.participationEnd(new ParticipationEndedEvent(context.globalTxId(), context.localTxId(), localTxId,
          confirmMethod, cancelMethod, TransactionStatus.Succeed));
      // Just store the parameters into the context
      parametersContext.putParameters(context.localTxId(), joinPoint.getArgs());
      LOG.debug("Participate Transaction with context {} has finished.", context);
      return result;
    } catch (Throwable throwable) {
      // Now we don't handle the error message
      if(!(throwable instanceof OmegaException)){
        tccMessageSender.participationEnd(new ParticipationEndedEvent(context.globalTxId(), context.localTxId(), localTxId,
                confirmMethod, cancelMethod, TransactionStatus.Failed));
      }
      LOG.error("Participate Transaction with context {} failed.", context, throwable);
      throw throwable;
    } finally {
      context.setLocalTxId(localTxId);
    }
  }