private void OnReceiveTransfer(Transfer transfer, Frame rawFrame) { Delivery value = null; bool flag = this.CreateDelivery(out value); if (flag) { value.Link = this; value.DeliveryId = transfer.DeliveryId.Value; value.DeliveryTag = transfer.DeliveryTag; value.Settled = transfer.Settled(); value.Batchable = transfer.Batchable(); value.MessageFormat = transfer.MessageFormat; TransactionalState state = transfer.State as TransactionalState; if (state != null) { value.TxnId = state.TxnId; } } if (!this.Session.OnAcceptTransfer(value, transfer, flag)) { return; } this.ProcessTransfer(transfer, rawFrame, value, flag); }
void OnReceiveTransfer(Transfer transfer, Frame rawFrame) { Delivery delivery = null; bool newDelivery = this.CreateDelivery(transfer, out delivery); // Initialize new delivery if (newDelivery) { delivery.Link = this; delivery.DeliveryId = transfer.DeliveryId.Value; delivery.DeliveryTag = transfer.DeliveryTag; delivery.Settled = transfer.Settled(); delivery.Batchable = transfer.Batchable(); delivery.MessageFormat = transfer.MessageFormat; TransactionalState txnState = transfer.State as TransactionalState; if (txnState != null) { delivery.TxnId = txnState.TxnId; } } else if (delivery == null) { // if the upper layer wants to ignore this transfer, it must // return newDelivery=false and delivery=null return; } // let session process the transfer first if (!this.Session.OnAcceptTransfer(delivery, transfer, newDelivery)) { return; } this.ProcessTransfer(transfer, rawFrame, delivery, newDelivery); }
public async Task Begin(NmsTransactionInfo transactionInfo) { if (this.current != null) { throw new NMSException("Begin called while a TX is still Active."); } if (this.coordinator == null || this.coordinator.IsDetaching()) { this.coordinator = new AmqpTransactionCoordinator(this.session); } this.txnId = await this.coordinator.DeclareAsync().Await(); this.current = transactionInfo.Id; transactionInfo.ProviderTxId = this.txnId; this.cachedTransactedState = new TransactionalState { TxnId = this.txnId }; this.cachedAcceptedState = new TransactionalState { Outcome = new Accepted(), TxnId = this.txnId }; }
public IFaultInjectionTransactionalState <TState> Create <TState>(IFaultInjectionTransactionalStateConfiguration config) where TState : class, new() { TransactionalState <TState> transactionalState = ActivatorUtilities.CreateInstance <TransactionalState <TState> >(this.context.ActivationServices, config as ITransactionalStateConfiguration, this.serializerSettings, this.context); FaultInjectionTransactionalState <TState> deactivationTransactionalState = ActivatorUtilities.CreateInstance <FaultInjectionTransactionalState <TState> >(this.context.ActivationServices, transactionalState, this.context); deactivationTransactionalState.Participate(context.ObservableLifecycle); return(deactivationTransactionalState); }
public FaultInjectionTransactionalState(TransactionalState <TState> txState, IControlledTransactionFaultInjector faultInjector, IGrainRuntime grainRuntime, ILogger <FaultInjectionTransactionalState <TState> > logger) { this.grainRuntime = grainRuntime; this.txState = txState; this.logger = logger; this.FaultInjectionControl = new FaultInjectionControl(); this.faultInjector = faultInjector; }
public IFaultInjectionTransactionalState <TState> Create <TState>(IFaultInjectionTransactionalStateConfiguration config) where TState : class, new() { var currentContext = this.contextAccessor.GrainContext; TransactionalState <TState> transactionalState = ActivatorUtilities.CreateInstance <TransactionalState <TState> >(currentContext.ActivationServices, new TransactionalStateConfiguration(config), this.contextAccessor); FaultInjectionTransactionalState <TState> deactivationTransactionalState = ActivatorUtilities.CreateInstance <FaultInjectionTransactionalState <TState> >(currentContext.ActivationServices, transactionalState, this.contextAccessor); deactivationTransactionalState.Participate(currentContext.ObservableLifecycle); return(deactivationTransactionalState); }
public FaultInjectionTransactionalState(TransactionalState <TState> txState, IGrainActivationContext activationContext, IGrainRuntime grainRuntime, ILogger <FaultInjectionTransactionalState <TState> > logger) { this.grainRuntime = grainRuntime; this.txState = txState; this.logger = logger; this.FaultInjectionControl = new FaultInjectionControl(); //fault injector has to be injected to DI as a scoped service, so each grain activation share one injector. but different grain activation use different ones. this.faultInjector = activationContext.ActivationServices.GetService <IControlledTransactionFaultInjector>(); if (this.faultInjector == null) { throw new ArgumentOutOfRangeException($"Incorrect {nameof(faultInjector)} type configured. Only {nameof(IControlledTransactionFaultInjector)} is allowed."); } }
static void OnSendComplete(object state) { SendAsyncResult thisPtr = (SendAsyncResult)state; thisPtr.message.CompleteCallback = null; thisPtr.message.UserToken = null; DeliveryState deliveryState = thisPtr.message.State; TransactionalState txnState = deliveryState as TransactionalState; if (txnState != null) { deliveryState = txnState.Outcome; } thisPtr.outcome = (Outcome)deliveryState; thisPtr.Complete(false); }
public void ProcessTransfer(Delivery delivery, Transfer transfer) { Utils.Trace(TraceLevel.Verbose, "{0}: Receive a transfer(id:{1}, settled:{2}).", this, transfer.DeliveryId, transfer.Settled()); if (delivery != null) { // handle new delivery bool creditAvailable = true; lock (this.syncRoot) { creditAvailable = this.TryChargeCredit(); } if (!creditAvailable) { Utils.Trace(TraceLevel.Verbose, "{0}: The transfer {1} was rejected due to insufficient link credit.", this, transfer.DeliveryId.Value); this.TryClose(new AmqpException(AmqpError.TransferLimitExceeded)); } else { delivery.Link = this; delivery.DeliveryId = transfer.DeliveryId.Value; delivery.DeliveryTag = transfer.DeliveryTag; delivery.Settled = transfer.Settled(); delivery.Batchable = transfer.Batchable(); TransactionalState txnState = transfer.State as TransactionalState; if (txnState != null) { delivery.TxnId = txnState.TxnId; } if (!delivery.Settled) { lock (this.syncRoot) { this.unsettledMap.Add(delivery.DeliveryTag, delivery); } } } } else { this.Session.OnAcceptIncomingTransfer(); } this.OnProcessTransfer(delivery, transfer); }
protected override void OnDisposeDeliveryInternal(Delivery delivery) { if (this.dispositionListener != null) { this.dispositionListener(delivery); return; } DeliveryState state = delivery.State; if (state.DescriptorCode == Received.Code) { return; } TransactionalState transactionalState = state as TransactionalState; if (transactionalState != null) { state = transactionalState.Outcome; } this.inflightSends.CompleteWork(delivery.DeliveryTag, false, (Outcome)state); }
public void Start() { DeliveryState deliveryState; if (txnId.Array != null) { deliveryState = new TransactionalState() { Outcome = this.outcome, TxnId = this.txnId }; } else { deliveryState = this.outcome; } if (!link.DisposeDelivery(deliveryTag, false, deliveryState, batchable)) { // Delivery tag not found link.pendingDispositions.CompleteWork(deliveryTag, true, AmqpConstants.RejectedNotFoundOutcome); } }