Exemplo n.º 1
0
        /// <summary>
        /// Send a port deregisterd message to all active modules
        /// </summary>
        /// <param name="port"></param>
        /// <param name="owner"></param>
        public void BroadcastPortDeregistration(VPort port, VModule owner)
        {
            Dictionary<String, SafeThread> listOfThreads = new Dictionary<string, SafeThread>() ;
            lock (this)
            {
                foreach (VModule module in runningModules.Keys)
                {
                    if (!module.Equals(owner))
                    {
                     

                        //***< Thread that monitors and timesout the port deregistered thread
                       SafeThread mPortDeregThreadControl = new SafeThread(delegate()
                            {
                                //***< Thread that invokes port deregistered on the module 
                                SafeThread mPortDeregThread = new SafeThread(delegate()
                                {
                                    InvokePortDeregistered(module, port);
                                }, module + ".PortDeregistered(" + port + ")", logger);

                                //***>
                                mPortDeregThread.Start();
                                mPortDeregThread.Join(TimeSpan.FromMilliseconds(Settings.MaxPortDeregisteredExecutionTime));
                                try
                                {
                                    if (mPortDeregThread.IsAlive())
                                       mPortDeregThread.Abort();
                                }
                                catch (Exception)
                                {
                                    //The PortDeregistered() calls when aborted (if so) will raise an exception
                                }
                            } , module + ".PortDeregistered(" + port + ") - Control" , logger);
                        
                        //***

                        listOfThreads[mPortDeregThreadControl.Name()] = mPortDeregThreadControl; //store the list because we want to wait on these later
                        mPortDeregThreadControl.Start();
                            }
                    }
                }
           
                foreach (SafeThread t in listOfThreads.Values)
                {
                    t.Join();
            }
 
        }
Exemplo n.º 2
0
        private void AddInCleanup(VModule moduleStopped)
        {

            //cleanup 
            if (Constants.ModuleIsolationLevel == ModuleIsolationModes.AppDomain)
            {
                logger.Log("AppDomain cleanup for "+ moduleStopped.GetInfo().AppName());
                bool done = false;
                AddInController aiController = AddInController.GetAddInController(moduleStopped);
                SafeThread t = new SafeThread(delegate()
                {
                    while (!done)
                    {
                        try
                        {
                            aiController.Shutdown();
                            done = true;
                        }
                        catch (CannotUnloadAppDomainException)
                        {
                            logger.Log("AppDomain Unload did not succeed. Retrying.");
                            System.Threading.Thread.Sleep(1000);
                            // keep trying to unload until it gets unloaded
                        }
                    }
                }, moduleStopped.ToString()+"-UnloadingAppDomain", logger);
                t.Start();
                t.Join(TimeSpan.FromMilliseconds(Settings.MaxFinallyBlockExecutionTime));
                if(t.IsAlive())
                    t.Abort();
            }
            else if (Constants.ModuleIsolationLevel == ModuleIsolationModes.Process)
            {
                //TODO: test this
                AddInController aiController = AddInController.GetAddInController(moduleStopped);
                aiController.Shutdown();
            }
            else if (Constants.ModuleIsolationLevel == ModuleIsolationModes.NoAddInAppDomain)
            {
                // TODO handle cleanup here
            }
            else
            {// Globals.ModuleIsolationLevel == ModuleIsolationModes.None
                // TODO handle cleanup here
            }

        }
Exemplo n.º 3
0
        public bool StopModule(VModule moduleToStop)
        {
            //***
            try
            {

                SafeThread t = new SafeThread(delegate() { moduleToStop.Stop(); }, moduleToStop.GetInfo().AppName() + "stop thread", logger); // invoke stop on the module
                t.Start();
                t.Join(TimeSpan.FromMilliseconds(Settings.MaxStopExecutionTime));
                if (t.IsAlive())
                    t.Abort();

                ModuleFinished(moduleToStop); // dereg its ports broadcast ports' dereg; wipe module off data structures
                AddInCleanup(moduleToStop); // addin cleanup

                return true;
            }
            catch (Exception e)
            {
                logger.Log("Exception in stopping of module: " + e);

                return false;
            }

            //***
        }