/// <summary>
 /// Handler for the MessageProcessor MessageArrived event
 /// </summary>
 /// <param name="msgId">The new message identifier</param>
 /// <param name="outcome">The outcome of the message (not used)</param>
 /// <param name="msg">The message received</param>
 /// <param name="sender">The message processor that received the message</param>
 /// <param name="srcId">The source unit id</param>
 public void NewMessage(decimal msgId, RequestOutcome outcome,
                        string msg, MessageProcessor sender, string srcId)
 {
     lock (_msgQueue)
     {
         _msgQueue.Enqueue(new ReceivedMessage(msg, sender.Id, srcId));
     }
     if (MessagesAvailable != null)
     {
         ThreadPool.QueueUserWorkItem(
             new WaitCallback(FireMessagesAvailableEventThreadProc));
     }
     else
     {
         CommMain.Logger.AddLog("WARNING: SocketChannel.NewMessage: MessagesAvailable is null.", LoggerSeverities.Error);
     }
 }
Пример #2
0
        /*
         *              public delegate void MessageArrivedHandler(decimal msgId,
         *                      RequestOutcome outcome, OPSTelegrama response,
         *                      MessageProcessor sender);
         *              /// <summary>
         *              /// The signature for handlers of the Done event
         *              /// </summary>
         *              public delegate void DoneHandler(MessageProcessor sender);
         *              /// <summary>
         *              /// The signature for handlers of the MessageRetried event
         *              /// </summary>
         *              public delegate void MessageRetriedHandler(decimal msgId,
         *                      decimal retriesLeft, MessageProcessor sender);
         *
         */
        /// <summary>
        /// Handler for the MessageProcessor.MessageArrived event
        /// </summary>
        /// <param name="msgId">The identifier of the message arrived</param>
        /// <param name="outcome">The outcome of the sending process</param>
        /// <param name="response">The contents of the response when the outcome
        /// indicates success, null otherwise</param>
        /// <param name="sender">The processor that received the message</param>
        protected void OnRequestResponse(decimal msgId,
                                         RequestOutcome outcome, string response,
                                         MessageProcessor sender, string srcId)
        {
            string text = string.Format("Sender - Updating row({0}): {1}, {2}",
                                        msgId, outcome, (response != null)? response : String.Empty);

            Debug.WriteLine(text);
            if (response != null)
            {
                if (_messages.UpdateMessageStatus(
                        msgId, (decimal)(int)GetMessageStatus(outcome)))
                {
                    if (_responseRouter != null)
                    {
                        _responseRouter.RouteAck(msgId, response);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Sends the contents of the dataset as one or more messages
        /// </summary>
        /// <param name="msgDataSet">It has the structure of the MSGS table; that is:
        ///
        ///	MSG_ID               NUMBER  NOT NULL,
        ///	MSG_DMSG_ID          NUMBER  NOT NULL,
        ///	MSG_MMSG_ID          NUMBER  NOT NULL,
        ///	MSG_DATE             DATE    NOT NULL,
        ///	MSG_PRIORITY         NUMBER  NOT NULL,
        ///	MSG_MANDATORY        NUMBER  NOT NULL,
        ///	MSG_MSG_ID           NUMBER,
        ///	MSG_MSG_ORDER        NUMBER,
        ///	MSG_XML              VARCHAR2(255 BYTE),
        ///	MSG_UNI_ID           NUMBER,
        ///	MSG_IPADAPTER        VARCHAR2(20 BYTE),
        ///	MSG_PORTADAPTER      NUMBER,
        ///	MSG_STATUS           NUMBER  NOT NULL,
        ///	MSG_NUMRETRIES       NUMBER,
        ///	MSG_LASTRETRY        DATE,
        ///	MSG_TOTALRETRIES     NUMBER  NOT NULL,
        ///	MSG_PARCIALRETRIES   NUMBER  NOT NULL,
        ///	MSG_TOTALINTERVAL    NUMBER  NOT NULL,
        ///	MSG_PARCIALINTERVAL  NUMBER  NOT NULL,
        ///	MSG_TOTALTIME        NUMBER  NOT NULL,
        ///	MSG_HISMANDATORY     NUMBER  DEFAULT 1 NOT NULL,
        ///	MSG_FID              NUMBER,
        ///	MSG_VERSION          NUMBER,
        ///	MSG_VALID            NUMBER DEFAULT 1 NOT NULL,
        ///	MSG_DELETED          NUMBER DEFAULT 0  NOT NULL,
        ///	CONSTRAINT PK_MSGS PRIMARY KEY (MSG_ID)
        ///
        /// </param>
        /// <remarks>All messages have the same destination and
        /// priority</remarks>
        public void Send(DataSet msgDataSet)
        {
            _msgDataSet        = msgDataSet;
            _messages          = new MessagesObject(_msgDataSet);
            _requestsInProcess = 0;
            ArrayList msgGroups = _messages.GetRetryGroups();

            if (msgGroups != null && msgGroups.Count > 0)
            {
                _processorsInUse = new MessageProcessor[msgGroups.Count];
                foreach (RetryGroup g in msgGroups)
                {
                    MessageProcessor proc =
                        MessageProcessorManager.GetProcessor(g.Policy);
                    if (null == proc)
                    {
                        IChannel ch = _channelMgr.OpenChannel(g.Policy.URI);
                        if (ch != null)
                        {
                            proc        = new MessageProcessor(ch);
                            proc.Policy = g.Policy;
                            MessageProcessorManager.AddProcessor(proc);
                        }
                    }
                    if (proc != null)
                    {
                        RegisterProcessor(proc);
                        proc.Send(g.Messages);
                        _requestsInProcess++;
                    }
                }
            }
            else
            {
                //TODO: Done!
            }
        }
Пример #4
0
 /// <summary>
 /// Stops listening for a MessageProcessor events
 /// </summary>
 /// <param name="proc"></param>
 protected void UnregisterProcessor(MessageProcessor proc)
 {
     proc.Done           -= new MessageProcessor.DoneHandler(OnRequestDone);
     proc.MessageRetried -= new MessageProcessor.MessageRetriedHandler(OnMessageRetried);
     proc.MessageArrived -= new MessageProcessor.MessageArrivedHandler(OnRequestResponse);
 }
Пример #5
0
 /// <summary>
 /// Handler for the MessageProcessor.MessageRetried event
 /// </summary>
 /// <param name="msgId">The message retried</param>
 /// <param name="retriesLeft">The number of retries left for
 /// the message</param>
 /// <param name="sender">The sender of the event</param>
 protected void OnMessageRetried(decimal msgId, decimal retriesLeft,
                                 MessageProcessor sender)
 {
     _messages.UpdateMessageRetries(msgId, retriesLeft, DateTime.Now);
 }