Example #1
0
        public void Run()
        {
            while (true)
            {
                var key = Console.ReadKey();
                switch (key.Key)
                {
                case ConsoleKey.UpArrow:
                    UpHandler?.Invoke();
                    break;

                case ConsoleKey.DownArrow:
                    DownHandler?.Invoke();
                    break;

                case ConsoleKey.LeftArrow:
                    LeftHandler?.Invoke();
                    break;

                case ConsoleKey.RightArrow:
                    RightHandler?.Invoke();
                    break;

                case ConsoleKey.Escape:
                    return;
                }
            }
        }
Example #2
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 UpHandler(up_queue, this);
             up_handler.Start();
         }
     }
 }
Example #3
0
        /// <summary>
        /// Class for moving by pressing arrow buttons
        /// </summary>
        public void Move()
        {
            while (true)
            {
                var key = Console.ReadKey(true);
                switch (key.Key)
                {
                case ConsoleKey.LeftArrow:
                {
                    LeftHandler?.Invoke(this, EventArgs.Empty);
                    break;
                }

                case ConsoleKey.RightArrow:
                {
                    RightHandler?.Invoke(this, EventArgs.Empty);
                    break;
                }

                case ConsoleKey.UpArrow:
                {
                    UpHandler?.Invoke(this, EventArgs.Empty);
                    break;
                }

                case ConsoleKey.DownArrow:
                {
                    DownHandler?.Invoke(this, EventArgs.Empty);
                    break;
                }

                default:
                {
                    Console.WriteLine("Wrong key was pressed");
                    break;
                }
                }
            }
        }
Example #4
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 UpHandler(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();
         }
     }
 }
Example #5
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;
		}
Example #6
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 UpHandler(up_queue, this);
					up_handler.Start();
				}
			}
		}
Example #7
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;
        }
Example #8
0
 /// <summary>
 /// Sets the UpHandler that will receive all Events from the Channel
 /// </summary>
 /// <param name="up_handler">The Uphandler object to receive the events</param>
 public void setUpHandler(UpHandler up_handler)
 {
     this.up_handler = up_handler;
 }
Example #9
0
        public override void stopInternal()
        {

            //stop up handlers
            if (_sequencelessMsgUpQueue != null)
                _sequencelessMsgUpQueue.close(false); // this should terminate up_handler thread

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

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

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

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

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

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

        }
Example #10
0
        public override void startUpHandler()
        {
            if (up_thread)
            {

                if (_tokenSeekingUpHandler == null)
                {
                    _tokenMsgUpQueue = new Alachisoft.NCache.Common.DataStructures.Queue();
                    _tokenSeekingUpHandler = new UpHandler(_tokenMsgUpQueue, this, Name + ".token.UpHandler", 3);
                    if (up_thread_prio >= 0)
                    {
                        try
                        {
                            
                        }
                        catch (System.Exception t)
                        {
                            Stack.NCacheLog.Error("Protocol", "priority " + up_thread_prio + " could not be set for thread: " + t.StackTrace);
                        }
                    }
                    _tokenSeekingUpHandler.Start();
                }

                if (_sequencedMsgUpHandler == null)
                {
                    _sequenecedMsgUpQueue = new Alachisoft.NCache.Common.DataStructures.Queue();
                    _sequencedMsgUpHandler = new UpHandler(_sequenecedMsgUpQueue, this, Name + ".seq.UpHandler", 2);
                    if (up_thread_prio >= 0)
                    {
                        try
                        {
                            
                        }
                        catch (System.Exception t)
                        {
                            Stack.NCacheLog.Error("Protocol", "priority " + up_thread_prio + " could not be set for thread: " + t.StackTrace);
                        }
                    }
                    _sequencedMsgUpHandler.Start();
                }

                if (_sequencelessMsgUpHandler == null)
                {
                    _sequencelessMsgUpQueue = new Alachisoft.NCache.Common.DataStructures.Queue();
                    _sequencelessMsgUpHandler = new UpHandler(_sequencelessMsgUpQueue, this, Name + ".seqless.UpHandler", 1);
                    if (up_thread_prio >= 0)
                    {
                        try
                        {
                            
                        }
                        catch (System.Exception t)
                        {
                            Stack.NCacheLog.Error("Protocol", "priority " + up_thread_prio + " could not be set for thread: " + t.StackTrace);
                        }
                    }
                    _sequencelessMsgUpHandler.Start();
                }
            }
        }
Example #11
0
 /// <summary>
 /// Sets the UpHandler that will receive all Events from the Channel
 /// </summary>
 /// <param name="up_handler">The Uphandler object to receive the events</param>
 public void setUpHandler(UpHandler up_handler)
 {
     this.up_handler=up_handler;
 }