Example #1
0
        public void EndHandleMessage(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            RelayMessageAsyncResult resultMessage = (RelayMessageAsyncResult)asyncResult;

            if (resultMessage.Exception != null)
            {
                throw resultMessage.Exception;
            }
        }
Example #2
0
        public IAsyncResult BeginHandleMessage(RelayMessage message, object state, AsyncCallback callback)
        {
            RelayMessageAsyncResult resultMessage = new RelayMessageAsyncResult(message, state, callback);

            try
            {
                if (message != null)
                {
                    messageTracer.WriteMessageInfo(message);

                    if (components.DoHandleMessagesOfType(message.MessageType))
                    {
                        #region Assign SourceZone
                        if (message.SourceZone == 0)
                        {
                            message.SourceZone = MyZone;
                        }
                        #endregion

                        if (message.IsTwoWayMessage)
                        {
                            if (outMessagesPort == null)
                            {
                                throw new InvalidOperationException("DataRelay is misconfigured.  BeginHandleMessages was called without OutMessagesOnRelayThreads enabled.");
                            }
                            outMessagePort.Post(resultMessage);
                        }
                        else
                        {
                            //post message to async queue
                            inMessagePort.Post(message);
                            //by wasSync being false we're letting the caller know
                            //that complete is being called on the same thread
                            const bool wasSynchronous = true;
                            resultMessage.CompleteOperation(wasSynchronous);
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat("Exception doing BeginHandleMessage: {0}", exc);
                }
                resultMessage.Exception = exc;
                const bool wasSynchronous = true;
                resultMessage.CompleteOperation(wasSynchronous);
            }
            return(resultMessage);
        }
Example #3
0
 private IEnumerator <ITask> HandleOutMessage(RelayMessageAsyncResult asyncMessage)
 {
     try
     {
         counters.CountInputBytes(asyncMessage.Message);
         foreach (var task in components.HandleOutMessage(asyncMessage))
         {
             yield return(task);
         }
     }
     finally
     {
         counters.CountOutMessage(asyncMessage.Message);
         const bool wasSynchronous = false;
         asyncMessage.CompleteOperation(wasSynchronous);
     }
 }
Example #4
0
		private IEnumerator<ITask> HandleOutMessage(RelayMessageAsyncResult asyncMessage)
		{
			try
			{
				counters.CountInputBytes(asyncMessage.Message);
				foreach (var task in components.HandleOutMessage(asyncMessage))
				{
					yield return task;
				}
			}
			finally
			{
				counters.CountOutMessage(asyncMessage.Message);
				const bool wasSynchronous = false;
				asyncMessage.CompleteOperation(wasSynchronous);
			}
		}
Example #5
0
		public IAsyncResult BeginHandleMessage(RelayMessage message, object state, AsyncCallback callback)
		{
			RelayMessageAsyncResult resultMessage = new RelayMessageAsyncResult(message, state, callback);
			try
			{
				if (message != null)
				{
					messageTracer.WriteMessageInfo(message);

					if (components.DoHandleMessagesOfType(message.MessageType))
					{
						#region Assign SourceZone
						if (message.SourceZone == 0)
						{
							message.SourceZone = MyZone;
						}
						#endregion

						if (message.IsTwoWayMessage)
						{
							if (outMessagesPort == null)
							{
								throw new InvalidOperationException("DataRelay is misconfigured.  BeginHandleMessages was called without OutMessagesOnRelayThreads enabled.");
							}
							outMessagePort.Post(resultMessage);	
						}
						else
						{
							//post message to async queue
							inMessagePort.Post(message);
							//by wasSync being false we're letting the caller know
							//that complete is being called on the same thread
							const bool wasSynchronous = true;
							resultMessage.CompleteOperation(wasSynchronous);
						}
					}
				}
			}
			catch (Exception exc)
			{
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat("Exception doing BeginHandleMessage: {0}", exc);                    
                }
				resultMessage.Exception = exc;
				const bool wasSynchronous = true;
				resultMessage.CompleteOperation(wasSynchronous);
			}
			return resultMessage;
		}