Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class.
        /// </summary>
        /// <param name="rootConfig">The root config.</param>
        /// <param name="appServers">The app servers.</param>
        /// <param name="logFactory">The log factory.</param>
        public DefaultBootstrap(IRootConfig rootConfig, IEnumerable <IWorkItem> appServers, ILogFactory logFactory)
        {
            if (rootConfig == null)
            {
                throw new ArgumentNullException("rootConfig");
            }

            if (appServers == null)
            {
                throw new ArgumentNullException("appServers");
            }

            if (!appServers.Any())
            {
                throw new ArgumentException("appServers must have one item at least", "appServers");
            }

            if (logFactory == null)
            {
                throw new ArgumentNullException("logFactory");
            }

            m_RootConfig = rootConfig;

            SetDefaultCulture(rootConfig);

            m_AppServers = appServers.ToList();

            m_GlobalLog = logFactory.GetLog(this.GetType().Name);

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (!rootConfig.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(rootConfig, m_AppServers, null, logFactory);

                if (m_GlobalLog.IsDebugEnabled)
                {
                    m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
                }
            }

            if (m_GlobalLog.IsDebugEnabled)
            {
                m_GlobalLog.Debug("The Bootstrap has been initialized!");
            }

            m_Initialized = true;
        }
Exemple #2
0
        private void ResetPerfMoniter()
        {
            if (m_PerfMonitor != null)
            {
                m_PerfMonitor.Stop();
                m_PerfMonitor.Dispose();
                m_PerfMonitor = null;
            }

            m_PerfMonitor = new PerformanceMonitor(m_Config, m_AppServers, m_ServerManager, LogFactory);
            m_PerfMonitor.Start();

            if (m_GlobalLog.IsDebugEnabled)
            {
                m_GlobalLog.Debug("The PerformanceMonitor has been reset for new server has been added!");
            }
        }
Exemple #3
0
        /// <summary>
        /// Initializes the bootstrap with the configuration, config resolver and log factory.
        /// </summary>
        /// <param name="serverConfigResolver">The server config resolver.</param>
        /// <param name="logFactory">The log factory.</param>
        /// <returns></returns>
        public virtual bool Initialize(Func <IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory)
        {
            if (m_Initialized)
            {
                throw new Exception("The server had been initialized already, you cannot initialize it again!");
            }

            if (logFactory != null && !string.IsNullOrEmpty(m_Config.LogFactory))
            {
                throw new ArgumentException("You cannot pass in a logFactory parameter, if you have configured a root log factory.", "logFactory");
            }

            IEnumerable <WorkItemFactoryInfo> workItemFactories;

            using (var factoryInfoLoader = GetWorkItemFactoryInfoLoader(m_Config, logFactory))
            {
                var bootstrapLogFactory = factoryInfoLoader.GetBootstrapLogFactory();

                logFactory = bootstrapLogFactory.ExportFactory.CreateExport <ILogFactory>();

                LogFactory  = logFactory;
                m_GlobalLog = logFactory.GetLog(this.GetType().Name);

                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                try
                {
                    workItemFactories = factoryInfoLoader.LoadResult(serverConfigResolver);
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error(e);
                    }

                    return(false);
                }
            }

            m_AppServers = new List <IWorkItem>(m_Config.Servers.Count());

            IWorkItem serverManager = null;

            //Initialize servers
            foreach (var factoryInfo in workItemFactories)
            {
                IWorkItem appServer = InitializeAndSetupWorkItem(factoryInfo);

                if (appServer == null)
                {
                    return(false);
                }

                if (factoryInfo.IsServerManager)
                {
                    serverManager = appServer;
                }
                else if (!(appServer is IsolationAppServer))//No isolation
                {
                    //In isolation mode, cannot check whether is server manager in the factory info loader
                    if (TypeValidator.IsServerManagerType(appServer.GetType()))
                    {
                        serverManager = appServer;
                    }
                }

                m_AppServers.Add(appServer);
            }

            if (serverManager != null)
            {
                m_ServerManager = serverManager;
            }

            if (!m_Config.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(m_Config, m_AppServers, serverManager, logFactory);

                if (m_GlobalLog.IsDebugEnabled)
                {
                    m_GlobalLog.Debug("The PerformanceMonitor has been initialized!");
                }
            }

            if (m_GlobalLog.IsDebugEnabled)
            {
                m_GlobalLog.Debug("The Bootstrap has been initialized!");
            }

            try
            {
                RegisterRemotingService();
            }
            catch (Exception e)
            {
                if (m_GlobalLog.IsErrorEnabled)
                {
                    m_GlobalLog.Error("Failed to register remoting access service!", e);
                }

                return(false);
            }

            m_Initialized = true;

            return(true);
        }