示例#1
0
        /// <summary>
        /// Blocks an waits for messages.
        /// </summary>
        public override void Listen()
        {
            try
            {
                while (IsEnabled)
                {
                    String textMsg;
                    textMsg = PortIn.Receive();

                    if (textMsg == null)
                    {
                        continue;
                    }

                    MethodCallMessage methodCallRequest = Marshaller.UnmarshallObject <MethodCallMessage>(textMsg);
                    if (methodCallRequest.MethodCall.Args == null)
                    {
                        methodCallRequest.MethodCall.Args = new List <Object>();
                    }

                    MethodResultMessage methodReturnMessage = CallMethod(methodCallRequest);
                    if (methodCallRequest.Answer)
                    {
                        string         returnMsg = Marshaller.MarshallObject(methodReturnMessage);
                        JmsDestination dest      = new JmsDestination(Destination);
                        IOutgoingPort  portOut   = new JmsOutgoingPort(JmsDestination.CreateDestinationString(dest.Host, methodCallRequest.CallId), ExceptionHandler, ConnectorId);
                        portOut.Send(returnMsg);
                        portOut.Close();
                        if (methodReturnMessage.Result.Type.Equals(ReturnType.Exception))
                        {
                            throw new BridgeException("A exception occurs, while the message has been created", new BridgeException(methodReturnMessage.Result.Arg.ToString()));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (IsEnabled)
                {
                    ExceptionHandler.Changed += delegate(object[] obj)
                    {
                        Listen();
                        return(null);
                    };
                    ExceptionHandler.HandleException(e);
                }
            }
        }