Exemple #1
0
        protected override void DoStart()
        {
            const string FROM  = "GlueService.DoStart()";
            const string START = "starting";
            const string STOP  = "stopping";

            base.DoStart();

            try
            {
                m_ServerHandler = new ServerHandler(this);

                m_Calls = new Calls(0);

                run(() => m_ServerHandler.Start(), START, "server handler", m_ServerHandler.Name, m_ServerHandler.GetType());

                //todo  Add partial failure handling, i.e. what if 2nd binding fails? then Providers that have started already need to stop
                foreach (var p in m_Providers)
                {
                    run(() => p.Start(), START, "provider", p.Name, p.GetType());
                }
                foreach (var b in m_Bindings)
                {
                    run(() => b.Start(), START, "binding", b.Name, b.GetType());
                }
                foreach (var s in m_Servers)
                {
                    run(() => s.Open(), START, "server", s.Name, s.GetType());
                }

                m_Thread      = new Thread(threadSpin);
                m_Thread.Name = THREAD_NAME;
                m_Thread.Start();

                log(MessageType.Info, "Started OK", FROM);
            }
            catch (Exception error)
            {
                AbortStart();

                log(MessageType.CatastrophicError, "Exception: " + error.ToMessageWithType(), FROM);

                if (m_Thread != null)
                {
                    m_Thread.Join();
                    m_Thread = null;
                }

                foreach (var s in m_Servers)
                {
                    run(() => s.Close(), STOP, "server", s.Name, s.GetType(), false);
                }
                foreach (var b in m_Bindings)
                {
                    run(() => b.WaitForCompleteStop(), STOP, "binding", b.Name, b.GetType(), false);
                }
                foreach (var p in m_Providers)
                {
                    run(() => p.WaitForCompleteStop(), STOP, "provider", p.Name, p.GetType(), false);
                }

                if (m_ServerHandler != null)
                {
                    run(() => m_ServerHandler.Dispose(), STOP, "server handler", m_ServerHandler.Name, m_ServerHandler.GetType(), false);
                    m_ServerHandler = null;
                }

                throw error;
            }
        }
Exemple #2
0
        protected override void DoWaitForCompleteStop()
        {
            const string FROM = "GlueService.DoWaitForCompleteStop()";
            const string STOP = "stopping";

            base.DoWaitForCompleteStop();

            try
            {
                m_Thread.Join();
                m_Thread = null;

                foreach (var s in m_Servers)
                {
                    run(() => s.Close(), STOP, "server", s.Name, s.GetType(), false);
                }
                foreach (var b in m_Bindings)
                {
                    run(() => b.WaitForCompleteStop(), STOP, "binding", b.Name, b.GetType(), false);
                }
                foreach (var p in m_Providers)
                {
                    run(() => p.WaitForCompleteStop(), STOP, "provider", p.Name, p.GetType(), false);
                }

                run(() => m_ServerHandler.WaitForCompleteStop(), STOP, "server handler", m_ServerHandler.Name, m_ServerHandler.GetType(), false);

                m_ServerHandler.Dispose();
                m_ServerHandler = null;

                m_Calls = null;
            }
            catch (Exception error)
            {
                if (m_ServerHandler != null)
                {
                    try
                    {
                        m_ServerHandler.Dispose();
                        m_ServerHandler = null;
                    }
                    catch
                    {
                    }
                }

                log(MessageType.CatastrophicError, "Exception: " + error.ToMessageWithType(), FROM);
                throw error;
            }
        }
Exemple #3
0
            protected override void DoStart()
            {
                const string FROM  = "GlueService.DoStart()";
                const string START = "starting";
                const string STOP  = "stopping";

                base.DoStart();

                try
                {
                  m_ServerHandler = new ServerHandler(this);

                  m_Calls = new Calls(0);

                  run(() => m_ServerHandler.Start(), START, "server handler", m_ServerHandler.Name, m_ServerHandler.GetType());
                  
                  //todo  Add partial failure handling, i.e. what if 2nd binding fails? then Providers that have started already need to stop
                  foreach(var p in m_Providers) run(() => p.Start(), START, "provider", p.Name, p.GetType());
                  foreach(var b in m_Bindings)  run(() => b.Start(), START, "binding",  b.Name, b.GetType());
                  foreach(var s in m_Servers)   run(() => s.Open(),  START, "server",   s.Name, s.GetType());

                  m_Thread = new Thread(threadSpin);
                  m_Thread.Name = THREAD_NAME;
                  m_Thread.Start();

                  log(MessageType.Info, "Started OK", FROM); 
                }
                catch(Exception error)
                {
                  AbortStart();

                  log(MessageType.CatastrophicError, "Exception: " + error.ToMessageWithType(), FROM);

                  if (m_Thread != null)
                  {
                      m_Thread.Join();
                      m_Thread = null;
                  }

                  foreach (var s in m_Servers)   run(() => s.Close(),               STOP, "server",   s.Name, s.GetType(), false);
                  foreach (var b in m_Bindings)  run(() => b.WaitForCompleteStop(), STOP, "binding",  b.Name, b.GetType(), false);
                  foreach (var p in m_Providers) run(() => p.WaitForCompleteStop(), STOP, "provider", p.Name, p.GetType(), false);

                  if (m_ServerHandler != null)
                  {
                      run(() => m_ServerHandler.Dispose(), STOP, "server handler", m_ServerHandler.Name, m_ServerHandler.GetType(), false);
                      m_ServerHandler = null;
                  }

                  throw error;
                }
            }