コード例 #1
0
        public MessageSubscriber()
        {
            SessionPolicyAttribute attribute = (SessionPolicyAttribute)this.GetType().GetCustomAttributes(typeof(SessionPolicyAttribute), true)[0];

            _sessionPolicy       = attribute.Policy;
            _config              = ConfigurationManager.GetSection(MessagingSection.SectionKey) as MessagingSection;
            _requestSerializer   = new XmlSerializer(typeof(TRequest));
            _responseSerializer  = new XmlSerializer(typeof(TResponse));
            _exceptionSerializer = new XmlSerializer(typeof(ServerFault));
        }
コード例 #2
0
 public ApplicationAdapterEndPoint(AdapterBase adapter, string applicationName, string sessionId)
     : base(adapter, new UriBuilder("app", sessionId).Uri)
 {
     _config                    = ConfigurationManager.GetSection(MessagingSection.SectionKey) as MessagingSection;
     _sessionId                 = sessionId;
     _applicationName           = applicationName;
     _mutex                     = new Mutex(false, string.Format("IMI_MOBILE_MUTEX_{0}", _sessionId));
     _memoryMappedFile          = MemoryMappedFile.CreateOrOpen(string.Format("IMI_MOBILE_QUEUE_{0}", _sessionId), MemoryMappedFileSize);
     _stream                    = _memoryMappedFile.CreateViewStream(0, 0, MemoryMappedFileAccess.ReadWrite);
     _serverNotifyEvent         = new EventWaitHandle(false, EventResetMode.AutoReset, string.Format("IMI_MOBILE_SERVER_NOTIFY_{0}", _sessionId));
     _serverReceivedNotifyEvent = new EventWaitHandle(false, EventResetMode.AutoReset, string.Format("IMI_MOBILE_SERVER_RECEIVED_NOTIFY_{0}", _sessionId));
     _clientNotifyEvent         = new EventWaitHandle(false, EventResetMode.AutoReset, string.Format("IMI_MOBILE_CLIENT_NOTIFY_{0}", _sessionId));
     _clientReceivedNotifyEvent = new EventWaitHandle(false, EventResetMode.AutoReset, string.Format("IMI_MOBILE_CLIENT_RECEIVED_NOTIFY_{0}", _sessionId));
     _clientProcessedEvent      = new EventWaitHandle(false, EventResetMode.ManualReset, string.Format("IMI_MOBILE_CLIENT_PROCESSED_NOTIFY_{0}", _sessionId));
     _abortEvent                = new EventWaitHandle(false, EventResetMode.ManualReset);
 }
コード例 #3
0
        /// <summary>
        /// Disposes any unmanaged resources used by this adapter.
        /// </summary>
        /// <param name="disposing">True if called from user code.</param>
        protected override void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                try
                {
                    if (disposing)
                    {
                        MessagingSection config = ConfigurationManager.GetSection(MessagingSection.SectionKey) as MessagingSection;

                        _abort = true;

                        if (_serverSocket != null)
                        {
                            _serverSocket.Close(); //This also terminates the accept thread
                        }

                        _acceptWaitEvent.Set();
                        _acceptWaitEvent.Close();
                        _acceptThreadWaitEvent.Close();
                        _timeoutWaitEvent.Set();
                        _timeoutWaitEvent.Close();
                        _timeoutThreadWaitEvent.Close();

                        AdapterEndPoint[] endPoints = GetEndPoints();

                        foreach (TcpAdapterEndPoint endPoint in endPoints)
                        {
                            Disconnect(endPoint);
                        }
                    }
                }
                finally
                {
                    base.Dispose(disposing);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Initializes the instance. Use this method to construct pipelines and subscribe to messages.
        /// </summary>
        public override void Initialize()
        {
            ServerSection    config       = ConfigurationManager.GetSection(ServerSection.SectionKey) as ServerSection;
            MessagingSection engineConfig = ConfigurationManager.GetSection(MessagingSection.SectionKey) as MessagingSection;

            ContextTraceListener contextListener = ((ContextTraceListener)MessageEngine.Instance.Tracing.Listeners["ContextTraceListener"]);

            if (contextListener == null)
            {
                contextListener = new ContextTraceListener(new RollingFileTraceListener(Path.Combine(config.LogPath, InstanceName + ".log"), config.MaxLogSize));
                contextListener.TraceOutputOptions = TraceOptions.ProcessId | TraceOptions.ThreadId | TraceOptions.DateTime;
                contextListener.Name = "ContextTraceListener";
                MessageEngine.Instance.Tracing.Listeners.Add(contextListener);
            }

            PropertyCollection tcpAdapterConfig = new PropertyCollection();

            tcpAdapterConfig.Write("TcpAdapterPort", config.TcpAdapter.Port);
            tcpAdapterConfig.Write("TcpEndPointTimeout", config.TcpAdapter.SocketIdleTimeout * 1000);

            TcpAdapter tcpAdapter = new TcpAdapter(tcpAdapterConfig, "tcp");

            tcpAdapter.MessageReceived += new EventHandler <AdapterReceiveEventArgs>(MessageReceivedEventHandler);

            ComponentPipeline tcpReceivePipeline = new ComponentPipeline(PipelineType.Receive);

            PropertyCollection receiveCfg = new PropertyCollection();

            tcpReceivePipeline.AddComponent(typeof(StreamToMessageDisassembler), receiveCfg);

            PropertyCollection traceCfg = new PropertyCollection();

            traceCfg.Write("MaxLogSize", config.MaxLogSize);
            traceCfg.Write("LogPath", config.LogPath);
            tcpReceivePipeline.AddComponent(typeof(TraceContextComponent), traceCfg);

            ComponentPipeline tcpSendPipeline = new ComponentPipeline(PipelineType.Send);

            PropertyCollection appAdapterConfig = new PropertyCollection();

            appAdapterConfig.Write("ApplicationIdleTimeout", 999999999);

            ApplicationAdapter appAdapter = new ApplicationAdapter(appAdapterConfig, "app");

            appAdapter.EndPointDestroyed += EndPointDestroyedEventHandler;

            ComponentPipeline appReceivePipeline = new ComponentPipeline(PipelineType.Receive);
            ComponentPipeline appSendPipeline    = new ComponentPipeline(PipelineType.Send);

            //Bind adapters to pipelines
            MessageEngine.Instance.Bind(tcpAdapter, tcpReceivePipeline);
            MessageEngine.Instance.Bind(tcpAdapter, tcpSendPipeline);
            MessageEngine.Instance.Bind(appAdapter, appReceivePipeline);
            MessageEngine.Instance.Bind(appAdapter, appSendPipeline);

            MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/mobile/CreateSessionRequest", new CreateSessionSubscriber());
            MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/mobile/StateRequest", new StateSubscriber());
            MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/mobile/EventRequest", new EventSubscriber());
            MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/mobile/Application", new ApplicationSubscriber());
            MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/mobile/ConfigurationRequest", new ConfigurationSubscriber());

            //Add subscriber to reset the trace context after threads have finished
            MessageEngine.Instance.SubscriptionManager.Subscribe(new TraceContextReset());

            _remoteInterface = new RemoteInterfaceProxy(SessionManager.Instance);
            _remoteInterface.Initialize(config.ManagerPort, "IMIServer");
        }
コード例 #5
0
        private void TimeoutThread()
        {
            ServerSection    config       = ConfigurationManager.GetSection(ServerSection.SectionKey) as ServerSection;
            MessagingSection engineConfig = ConfigurationManager.GetSection(MessagingSection.SectionKey) as MessagingSection;

            while (MessageEngine.Instance.IsRunning)
            {
                foreach (ClientSession session in SessionManager.Instance.GetSessions())
                {
                    bool hasLock = false;

                    try
                    {
                        Monitor.TryEnter(session, ref hasLock);

                        if (!hasLock)
                        {
                            continue;
                        }

                        DateTime lastActivityTime;
                        DateTime?killTime;

                        lock (session.SyncLock)
                        {
                            lastActivityTime = session.LastActivityTime;
                            killTime         = session.KillTime;
                        }

                        if (((DateTime.Now - lastActivityTime).TotalSeconds >= config.SessionIdleTimeout) || (killTime != null && DateTime.Now >= killTime))
                        {
                            try
                            {
                                ApplicationAdapterEndPoint endPoint = session.ApplicationEndPoint;

                                if (endPoint != null)
                                {
                                    ApplicationAdapter appAdapter = MessageEngine.Instance.AdapterProxy.ResolveUriToAdapter(endPoint.Uri) as ApplicationAdapter;

                                    if (appAdapter != null)
                                    {
                                        appAdapter.CloseApplication(endPoint);
                                    }
                                }
                            }
                            finally
                            {
                                SessionManager.Instance.DestroySession(session.Id);
                                session.Dispose();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ExceptionHelper.IsCritical(ex))
                        {
                            throw;
                        }
                    }
                    finally
                    {
                        if (hasLock)
                        {
                            Monitor.Exit(session);
                        }
                    }
                }

                Thread.Sleep(5000);
            }
        }
コード例 #6
0
        /// <summary>
        /// Initializes the instance. Use this method to construct pipelines and subscribe to messages.
        /// </summary>
        public override void Initialize()
        {
            VocollectSection config       = ConfigurationManager.GetSection(VocollectSection.SectionKey) as VocollectSection;
            MessagingSection engineConfig = ConfigurationManager.GetSection(MessagingSection.SectionKey) as MessagingSection;

            ContextTraceListener contextListener = ((ContextTraceListener)MessageEngine.Instance.Tracing.Listeners["ContextTraceListener"]);

            if (contextListener == null)
            {
                contextListener = new ContextTraceListener(new RollingFileTraceListener(Path.Combine(config.LogPath, InstanceName + ".log"), config.MaxLogSize));
                contextListener.TraceOutputOptions = TraceOptions.ProcessId | TraceOptions.ThreadId | TraceOptions.DateTime;
                contextListener.Name = "ContextTraceListener";
                MessageEngine.Instance.Tracing.Listeners.Add(contextListener);
            }

            PropertyCollection tcpAdapterConfig = new PropertyCollection();

            tcpAdapterConfig.Write("TcpAdapterPort", config.TcpAdapter.Port);
            tcpAdapterConfig.Write("TcpEndPointTimeout", engineConfig.PendingOperationsTimeout);
            TcpAdapter tcpAdapter = new TcpAdapter(tcpAdapterConfig, "tcp");

            tcpAdapter.EndPointCreated += new EventHandler <AdapterEndPointEventArgs>(EndPointCreatedEventHandler);
            tcpAdapter.MessageReceived += new EventHandler <AdapterReceiveEventArgs>(MessageReceivedEventHandler);

            ComponentPipeline tcpReceivePipeline = new ComponentPipeline(PipelineType.Receive);

            PropertyCollection receiveCfg = new PropertyCollection();

            receiveCfg.Write("CodePageName", config.CodePageName);
            tcpReceivePipeline.AddComponent(typeof(StreamToXmlDisassembler), receiveCfg);

            PropertyCollection traceCfg = new PropertyCollection();

            traceCfg.Write("MaxLogSize", config.MaxLogSize);
            traceCfg.Write("LogPath", config.LogPath);
            tcpReceivePipeline.AddComponent(typeof(TraceContextComponent), traceCfg);

            /*
             * tcpReceivePipeline.AddComponent(typeof(MessageAcknowledgeComponent), ackCfg);
             */

            PropertyCollection transmissionControlCfg = new PropertyCollection();

            transmissionControlCfg.Write("PendingOperationsTimeout", engineConfig.PendingOperationsTimeout);

            tcpReceivePipeline.AddComponent(typeof(TransmissionControlComponent), transmissionControlCfg);

            PropertyCollection xsltCfg = new PropertyCollection();

            xsltCfg.Write("XsltPath", config.XsltPath);

            tcpReceivePipeline.AddComponent(typeof(XslTransformComponent), xsltCfg);

            ComponentPipeline  tcpSendPipeline = new ComponentPipeline(PipelineType.Send);
            PropertyCollection sendCfg         = new PropertyCollection();

            sendCfg.Write("CodePageName", config.CodePageName);
            tcpSendPipeline.AddComponent(typeof(MessageToStreamAssembler), sendCfg);

            PropertyCollection whAdapterConfig = new PropertyCollection();

            //Read connection strings
            foreach (ConnectionStringSettings connection in ConfigurationManager.ConnectionStrings)
            {
                whAdapterConfig.Write(connection.Name, connection.ConnectionString);
            }

            WarehouseAdapter whAdapter = new WarehouseAdapter(whAdapterConfig, "warehouse");

            ComponentPipeline whReceivePipeline = new ComponentPipeline(PipelineType.Receive);
            ComponentPipeline whSendPipeline    = new ComponentPipeline(PipelineType.Send);

            //Bind adapters to pipelines
            MessageEngine.Instance.Bind(tcpAdapter, tcpReceivePipeline);
            MessageEngine.Instance.Bind(tcpAdapter, tcpSendPipeline);
            MessageEngine.Instance.Bind(whAdapter, whReceivePipeline);
            MessageEngine.Instance.Bind(whAdapter, whSendPipeline);

            //Add subscribers
            foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (t.BaseType == typeof(VocollectSubscriber) && t.Namespace == "Imi.Wms.Voice.Vocollect.Subscribers")
                {
                    MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/voice/vocollect/" + t.Name, (SubscriberBase)t.GetConstructor(new Type[] {}).Invoke(new object[] {}));
                }
            }

            //Add subscriber to reset the trace context after threads have finished
            MessageEngine.Instance.SubscriptionManager.Subscribe(new TraceContextReset());
        }