/// <summary>
 /// This method handles ACK/Reject messages from remote application for a data transfer message.
 /// </summary>
 /// <param name="communicator">Communicator that sent message</param>
 /// <param name="operationResultMessage">Response message</param>
 protected override void OnResponseReceived(ICommunicator communicator, NGRIDOperationResultMessage operationResultMessage)
 {
     base.OnResponseReceived(communicator, operationResultMessage);
     EvaluateResponse(communicator, operationResultMessage, null);
 }
        /// <summary>
        /// This method evaluates ACK/Reject messages from remote application for a data transfer message.
        /// </summary>
        /// <param name="communicator">Communicator that sent message</param>
        /// <param name="operationResultMessage">Response message</param>
        /// <param name="waitingMessage">Waiting message for this response (may be null, if it is null, it is searched in _waitingMessages list)</param>
        private void EvaluateResponse(ICommunicator communicator, NGRIDOperationResultMessage operationResultMessage, WaitingMessage waitingMessage)
        {
            lock (_waitingMessages)
            {
                //If waitingMessage argument is not supplied, find waiting message from _waitingMessages list
                if (waitingMessage == null)
                {
                    foreach (var wMessage in _waitingMessages)
                    {
                        if (wMessage.State == WaitingMessage.WaitingMessageStates.WaitingForAcknowledgment &&
                            wMessage.MessageRecord.MessageId == operationResultMessage.RepliedMessageId)
                        {
                            waitingMessage = wMessage;
                            break;
                        }
                    }

                    //If there is not message that waits for this response, just exit from method..
                    if (waitingMessage == null)
                    {
                        return;
                    }
                }

                //If message is stored to database in this server
                if (waitingMessage.MessageRecord.Id >= 0)
                {
                    if (operationResultMessage.Success)
                    {
                        //If message is persistent (Stored on database), remove from database.
                        if (waitingMessage.MessageRecord.Id > 0)
                        {
                            StorageManager.RemoveMessage(waitingMessage.MessageRecord.Id);
                        }

                        //Remove from list
                        _waitingMessages.Remove(waitingMessage);
                        //Reset _waitingTimeOnError (because this is a success situation)
                        _waitingTimeOnError = FirstWaitingTimeOnError;
                    }
                    else
                    {
                        //Set message state as 'ready to send' again. Thus, message is added to send queue again.
                        waitingMessage.State = WaitingMessage.WaitingMessageStates.ReadyToSend;
                        //Pulse if a thread waiting in ProcessWaitingMessageRecords method
                        Monitor.PulseAll(_waitingMessages);
                    }
                }
                //If message is not stored to database in this server
                else
                {
                    //Remove from list
                    _waitingMessages.Remove(waitingMessage);
                }

                Logger.Debug("EvaluateResponse - WaitingMessages.Count = " + _waitingMessages.Count + ", Application = " + Name);
            }

            //If it is not stored message..
            if (waitingMessage.MessageRecord.Id < 0)
            {
                //Create event to send response message to upper layers
                OnMessageReceived(this, new MessageReceivedFromCommunicatorEventArgs
                                        {
                                            Communicator = communicator,
                                            Message = operationResultMessage
                                        });
            }
        }
Esempio n. 3
0
 protected virtual void OnResponseReceived(ICommunicator communicator, NGRIDOperationResultMessage operationResultMessage)
 {
     //No action
 }