/**
         * Starts all message processors
         *
         * @param newSize the new thread poolsize
         */
        private void fillUpThreadPool(int newSize)
        {
            //make sure we don't resize more than once
            // messageProcessors.ensureCapacity(newSize);

            for (int i = messageProcessors.Count; i < newSize; i++)
            {
                MessageProcessor mp = new MessageProcessor(messageQueue,
                                                           messageEventHandler,
                                                           this);
                messageProcessors.Add(mp);

                mp.Start();
            }
        }
        /**
         * Clears the faulty thread and tries to repair the damage and instanciate
         * a replacement.
         *
         * @param callingThread the thread where the error occurred.
         * @param message       A description of the error
         * @param error         The error itself
         */
        public void HandleFatalError(Runnable callingThread, String message, Exception error)
        {
            if (callingThread is NetAccessPoint)
            {
                NetAccessPoint ap      = (NetAccessPoint)callingThread;
                bool           running = ap.IsRunning();

                //make sure socket is closed
                RemoveNetAccessPoint(ap.GetDescriptor());

                if (running)
                {
                    try
                    {
                        Console.WriteLine("An access point has unexpectedly "
                                          + "stopped. AP: {0}", ap.ToString());

                        InstallNetAccessPoint(ap.GetDescriptor());
                        /** @todo: log fixing the error*/
                    }
                    catch (StunException ex)
                    {
                        //make sure nothing's left and notify user
                        RemoveNetAccessPoint(ap.GetDescriptor());
                        Console.WriteLine("Failed to relaunch accesspoint: {0} {1} {2}", ap, ex.Message, ex.StackTrace);
                        /** @todo notify user and log */
                    }
                }

                return;
            }
            else if (callingThread is MessageProcessor)
            {
                MessageProcessor mp = (MessageProcessor)callingThread;

                //make sure the guy's dead.
                mp.Stop();
                messageProcessors.Remove(mp);

                mp = new MessageProcessor(messageQueue, messageEventHandler, this);
                mp.Start();
                Console.WriteLine("A message processor has been relaunched because of an error.");
            }
            Console.WriteLine("Error was: {0} {1}", error.Message, error.StackTrace);
        }
        /**
         * Clears the faulty thread and tries to repair the damage and instanciate
         * a replacement.
         *
         * @param callingThread the thread where the error occurred.
         * @param message       A description of the error
         * @param error         The error itself
         */
        public void HandleFatalError(Runnable callingThread, String message, Exception error)
        {
            if (callingThread is NetAccessPoint)
            {
                NetAccessPoint ap = (NetAccessPoint)callingThread;
                bool running = ap.IsRunning();

                //make sure socket is closed
                RemoveNetAccessPoint(ap.GetDescriptor());

                if (running)
                {
                    try
                    {
                        Console.WriteLine("An access point has unexpectedly "
                            +"stopped. AP: {0}" , ap.ToString());

                        InstallNetAccessPoint(ap.GetDescriptor());
                        /** @todo: log fixing the error*/
                    }
                    catch (StunException ex)
                    {
                        //make sure nothing's left and notify user
                        RemoveNetAccessPoint(ap.GetDescriptor());
                        Console.WriteLine("Failed to relaunch accesspoint: {0} {1} {2}" , ap, ex.Message, ex.StackTrace);
                        /** @todo notify user and log */
                    }
                }

                return;
            }
            else if( callingThread is MessageProcessor )
            {
                MessageProcessor mp = (MessageProcessor)callingThread;

                //make sure the guy's dead.
                mp.Stop();
                messageProcessors.Remove(mp);

                mp = new MessageProcessor(messageQueue, messageEventHandler, this);
                mp.Start();
                Console.WriteLine("A message processor has been relaunched because of an error.");

            }
            Console.WriteLine("Error was: {0} {1}", error.Message, error.StackTrace);
        }
        /**
         * Starts all message processors
         *
         * @param newSize the new thread poolsize
         */
        private void fillUpThreadPool(int newSize)
        {
            //make sure we don't resize more than once
            // messageProcessors.ensureCapacity(newSize);

            for (int i = messageProcessors.Count; i < newSize; i++)
            {
                MessageProcessor mp = new MessageProcessor(messageQueue,
                    messageEventHandler,
                    this);
                messageProcessors.Add(mp);

                mp.Start();
            }
        }