/*public bool CommitReconfiguration ()
         * {
         *      Thread commit = new Thread(new ThreadStart(Commit));
         *      commit.Priority = ThreadPriority.Highest;
         *      commit.Start();
         *
         *      return true;
         * }*/

        public bool CommitReconfiguration()
        {
            Configuration protocol;

            Console.WriteLine("[ConfigurationManager.Commit] Aplicando a reconfiguração...");
            lock (thisLock) {
                if (reconfiguring)
                {
                    foreach (ExecutionStateEvaluation es in evaluations)
                    {
                        protocol = unit.Actions [es.ActionName].Protocol;
                        protocol.stopStates(es.StatesToStop);
                        WaitForSafeState(protocol.ReconfigMonitor, es);
                        Console.WriteLine("[ConfigurationManager.Commit] Estado seguro para reconfiguração!");

                        if (request.StructuralRequest != null && request.StructuralRequest.Changes != null)
                        {
                            Console.WriteLine("[ConfigurationManager.Commit] Aplicando reconfigurações estruturais...");
                            foreach (StructuralChange sc in request.StructuralRequest.Changes)
                            {
                                if (SecurityAnalyzer.isChangeConcrete(sc))
                                {
                                    Console.WriteLine("[ConfigurationManager.Commit] Reconfigurando a unidade {0}", sc.Old.Name);
                                    createConcreteUnit(sc.New, ((IUnit)sc.Old.Entity).CID.getInstanceName() /*+ "(new)"*/);
                                    SubstituteUnit(sc.Old, sc.New);
                                }
                            }
                        }
                        BehavioralReconfigurationRequest behavioralRequest = request.BehavioralRequest;

                        if (behavioralRequest != null)
                        {
                            foreach (BehavioralChange bc in behavioralRequest.Changes)
                            {
                                if (bc.NewSlices != null)
                                {
                                    //Console.WriteLine("[ConfigurationManager.Commit] Adicionando novas fatias");
                                    foreach (MetaSlice slice in bc.NewSlices.Values)
                                    {
                                        if (!unit.Slices.ContainsKey(slice.Inner))
                                        {
                                            Console.WriteLine("[ConfigurationManager.Commit] Adicionando fatia '{0}'...", slice.Inner);
                                            createConcreteUnit(slice.Unit, slice.Inner /*+ "(new)"*/);
                                            unit.AddSlice(slice.Inner, slice);
                                        }
                                    }
                                }

                                unit.Actions [bc.Action].Protocol.generateAutomaton(bc.Transitions);
                            }
                        }
                    }

                    foreach (ExecutionStateEvaluation es in evaluations)
                    {
                        foreach (MetaAction action in unit.Actions.Values)
                        {
                            if (!action.IsNative && action.Name.Equals(es.ActionName))
                            {
                                action.Protocol.runStates(es.StatesToStop);
                            }
                        }
                    }

                    this.reconfiguring = false;
                    this.evaluations   = null;
                    this.request       = null;

                    Console.WriteLine("[ConfigurationManager.Commit] Reconfiguração aplicada!");

                    return(true);
                }
            }
            return(false);
        }