public TccTransaction(TccTransactionData data, TccCoordinator <TContext> coordinator, TContext ctx) { // TODO: 从TransactionData中恢复数据 _context = ctx.Deserialize <TContext>(data.ContextData); _txId = data.TxId; _txState = data.TxState; _lock = null; _works = new List <TccWorkUnit <TContext> >(); _txCtx = null; _coordinator = coordinator; if (_coordinator != null) { _coordinator.NewTransaction(this); _tracing = _coordinator.Tracing; } else { _tracing = _defaultTracing; } Prepare(); foreach (var a in _works) { a.Tracing = _tracing; } }
public TccTransaction(TContext ctx, TccCoordinator <TContext> coordinator) { _context = ctx; _txId = Guid.NewGuid().ToString(); _txState = TccTransactionState.New; _lock = null; _works = new List <TccWorkUnit <TContext> >(); _txCtx = null; Prepare(); _coordinator = coordinator; if (_coordinator != null) { _coordinator.NewTransaction(this); _tracing = _coordinator.Tracing; } else { _tracing = _defaultTracing; } foreach (var a in _works) { a.Tracing = _tracing; } }
public void BeginExecute(Action <TccTransactionContext <TContext> > callback) { lock (_syncRoot) { if (_txCtx != null) { throw new NotSupportedException("[BUG] BeginInvoke for every TccTransaction can only run once"); } _txCtx = new TccTransactionContext <TContext>(this, callback); _txState = _lock != null ? TccTransactionState.LockTrying : TccTransactionState.Trying; _beginTime = DateTime.Now; } try { CheckAndRunNext(null); } catch (Exception ex) { _txCtx.ThrowException("[BUG] BeginExecute CheckAndRunNext Failed", ex); } }
public void BeginReclose(Action <TccTransactionContext <TContext> > callback) { // // TODO:尝试重新关闭Transaction,当Confirm或者Cancel Failed // // ?: 当从Persister当中序列化出来的时候,应当怎样去操作 // // Confirming & ConfirmFailed : 继续confirm // Cancelling & cancelFailed : 继续cancel // Trying : cancel // if (_txCtx != null) { throw new NotSupportedException("TccTransactionContext is not Null"); } _txCtx = new TccTransactionContext <TContext>(this, callback); lock (_syncRoot) { if (_txState == TccTransactionState.CancelFailed || _txState == TccTransactionState.Cancelling || _txState == TccTransactionState.Trying) { _txState = TccTransactionState.Cancelling; } else if (_txState == TccTransactionState.ConfirmFailed || _txState == TccTransactionState.Confirming) { _txState = TccTransactionState.Confirming; } else { throw new NotSupportedException("TccTransactionState can not Reclose:" + _txState.ToString()); } } try { CheckAndRunNext(null); } catch (Exception ex) { _txCtx.ThrowException("[BUG] BeginClose CheckAndRunNext Failed", ex); } }