Ejemplo n.º 1
0
 /// <summary>Used internally. If overridden, call this method first. Only creates the up_handler thread
 /// if down_thread is true
 /// </summary>
 public virtual void  startUpHandler()
 {
     if (up_thread)
     {
         if (up_handler == null)
         {
             up_queue   = new Alachisoft.NCache.Common.DataStructures.Queue();
             up_handler = new ProtocolUpHandler(up_queue, this);
             if (up_thread_prio >= 0)
             {
                 try
                 {
                     //up_handler.Priority = System.Threading.ThreadPriority.AboveNormal;
                 }
                 catch (System.Exception t)
                 {
                     stack.NCacheLog.Error("Protocol", "priority " + up_thread_prio + " could not be set for thread: " + t.StackTrace);
                 }
             }
             up_handler.Start();
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>Used internally. If overridden, call parent's method first </summary>
        public virtual void  stopInternal()
        {
            if (up_queue != null)
            {
                up_queue.close(false); // this should terminate up_handler thread
            }
            if (up_handler != null && up_handler.IsAlive)
            {
                try
                {
                    up_handler.Join(THREAD_JOIN_TIMEOUT);
                }
                catch (System.Exception e)
                {
                    stack.NCacheLog.Error("Protocol.stopInternal()", "up_handler.Join " + e.Message);
                }
                if (up_handler != null && up_handler.IsAlive)
                {
                    up_handler.Interrupt();                     // still alive ? let's just kill it without mercy...
                    try
                    {
                        up_handler.Join(THREAD_JOIN_TIMEOUT);
                    }
                    catch (System.Exception e)
                    {
                        stack.NCacheLog.Error("Protocol.stopInternal()", "up_handler.Join " + e.Message);
                    }
                    if (up_handler != null && up_handler.IsAlive)
                    {
                        stack.NCacheLog.Error("Protocol", "up_handler thread for " + Name + " was interrupted (in order to be terminated), but is still alive");
                    }
                }
            }
            up_handler = null;

            if (down_queue != null)
            {
                down_queue.close(false); // this should terminate down_handler thread
            }
            if (down_handler != null && down_handler.IsAlive)
            {
                try
                {
                    down_handler.Join(THREAD_JOIN_TIMEOUT);
                }
                catch (System.Exception e)
                {
                    stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message);
                }
                if (down_handler != null && down_handler.IsAlive)
                {
                    down_handler.Interrupt();                     // still alive ? let's just kill it without mercy...
                    try
                    {
                        down_handler.Join(THREAD_JOIN_TIMEOUT);
                    }
                    catch (System.Exception e)
                    {
                        stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message);
                    }
                    if (down_handler != null && down_handler.IsAlive)
                    {
                        stack.NCacheLog.Error("Protocol", "down_handler thread for " + Name + " was interrupted (in order to be terminated), but is is still alive");
                    }
                }
            }
            down_handler = null;
        }