/// <summary> /// Dispatches the token to the processor. /// </summary> /// <param name="token"></param> public void Dispatch(Token token) { if (isStopping) { return; } lock (tokenDispatchingLock) { MessageFlowState messageflowState = token.GetMessageFlowState(); if (messageflowState.AssignedProcessor != null) { return; // Token is already dispatched } // NOTE: it compares to default GUID returned by the new Guid() if (messageflowState.MessageFlowGuid == new Guid()) { token = brokerService.UpdateTokenMessageFlow(token.Guid, messageFlowGuid); } try { TraceLog.Info(string.Format( "Dispatcher assigning token '{0}' to processor '{1}'", token.Guid, processor.ComponentName)); token = brokerService.UpdateTokenLastResponseFromProcessor(token.Guid, DateTime.Now); token = brokerService.UpdateTokenAssignedProcessor(token.Guid, processor.ComponentName); token.State = TokenState.InProcessor; processor.AddWork(token); } catch { // NOTE: token retains the Received state brokerService.UpdateTokenAssignedProcessor(token.Guid, null); } } }
public void FinishToken(string updatingProcessorName, Token targetToken, SerializableXDocument resultMessage) { lock (syncLock) { MessageFlowState messageflowState = targetToken.GetMessageFlowState(); if (messageflowState.AssignedProcessor == updatingProcessorName) { storage.UpdateToken(targetToken, delegate(Token token) { token.UpdateMessageFlowState(mfs => { mfs.LastResponseFromProcessor = DateTime.Now; }); }); XDocument sourceMetadata = targetToken.GetSourceMetadata(); var sourceAdress = targetToken.GetSourceAddress(); if (sourceAdress != null) { string sourceGatewayName = sourceAdress.GatewayName; GatewayAccessor sourceGateway = componentsAccessors.Values.OfType<GatewayAccessor>().SingleOrDefault(gwa => gwa.ComponentName == sourceGatewayName); sourceGateway.ReceiveReturn(targetToken.Guid, resultMessage, new SerializableXDocument(sourceMetadata)); } storage.UpdateToken(targetToken, delegate(Token token) { token.State = TokenState.Finished; }); } } }
/// <summary> /// Performs a single step in the message flow graph traversal. This /// corresponds to moving along an edge from one node to another. /// </summary> /// <remarks> /// After each step the message flow state is saved to the token. /// </remarks> /// <param name="token">token to be processed</param> /// <returns>true if the traversal should continue; false if it has /// finished</returns> public bool DoStep(Token token) { #region Determine currentNode Node currentNode; string currentNodeName = token.GetMessageFlowState().NextNodeName; if (currentNodeName != null) { currentNode = nodesByName[currentNodeName]; } else { currentNode = entryNode; } #endregion string nextNodeName = currentNode.Evaluate(token); MessageFlowState messageflowState = token.GetMessageFlowState(); messageflowState.NextNodeName = nextNodeName; token.SetMessageFlowState(messageflowState); if ((token.IsPersistent) && (!(currentNode is CbrNode))) { Processor.BrokerService.UpdateTokenMessageFlowState( Processor.Name, token, messageflowState); } bool shouldContinue = nextNodeName != null; return shouldContinue; }
/// <summary> /// Persistently updates the state of the message flow of a given /// token, ie. the state of its processing. /// </summary> /// <param name="token">token to be updated</param> /// <seealso cref="XRouter.Common.MessageFlowState"/> public void MakeMessageFlowStatePersistent(Token token) { BrokerService.UpdateTokenMessageFlowState(ProcessorName, token, token.GetMessageFlowState()); }