Inheritance: IPerformanceMonitor
        /// <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>
        /// <param name="serviceProvider">A container for service objects.</param>
        public DefaultBootstrap(IRootConfig rootConfig, IEnumerable <IWorkItem> appServers, ILogFactory logFactory, IServiceProvider serviceProvider)
            : this(serviceProvider)
        {
            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;
        }
        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!");
            }
        }
Exemplo n.º 3
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;

            m_AppServers = appServers.ToList();

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

            if (!rootConfig.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(rootConfig, m_AppServers, 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;
        }
Exemplo n.º 4
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");
            }

            if (logFactory == null)
            {
                logFactory = GetBootstrapLogFactory(m_Config.LogFactory);
            }

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

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

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

            IManagedApp serverManager = null;

            //Initialize servers
            foreach (var config in m_Config.Servers)
            {
                var serverConfig = config;

                if (serverConfigResolver != null)
                {
                    serverConfig = serverConfigResolver(config);
                }

                IManagedApp appServer;

                try
                {
                    var serverType = serverConfig.ServerType;

                    if (string.IsNullOrEmpty(serverType) && !string.IsNullOrEmpty(serverConfig.ServerTypeName))
                    {
                        var serverTypeProvider = m_Config.ServerTypes.FirstOrDefault(
                            t => t.Name.Equals(serverConfig.ServerTypeName, StringComparison.OrdinalIgnoreCase));

                        if (serverTypeProvider != null)
                        {
                            serverType = serverTypeProvider.Type;
                        }
                    }

                    if (string.IsNullOrEmpty(serverType))
                    {
                        throw new Exception("No server type configured or the configured server type was not found.");
                    }

                    appServer = CreateWorkItemInstance(serverType);

                    var serverMetadata = appServer.GetAppServerMetadata();

                    if (serverMetadata.IsServerManager)
                    {
                        serverManager = appServer;
                    }

                    if (m_GlobalLog.IsDebugEnabled)
                    {
                        m_GlobalLog.DebugFormat("The server instance {0} has been created!", serverConfig.Name);
                    }
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error(string.Format("Failed to create server instance {0}!", serverConfig.Name), e);
                    }
                    return(false);
                }

                var exceptionSource = appServer as IExceptionSource;

                if (exceptionSource != null)
                {
                    exceptionSource.ExceptionThrown += new EventHandler <ErrorEventArgs>(exceptionSource_ExceptionThrown);
                }


                var setupResult = false;

                try
                {
                    setupResult = SetupWorkItemInstance(appServer, serverConfig);

                    if (m_GlobalLog.IsDebugEnabled)
                    {
                        m_GlobalLog.DebugFormat("The server instance {0} has been initialized!", appServer.Name);
                    }
                }
                catch (Exception e)
                {
                    m_GlobalLog.Error(e);
                    setupResult = false;
                }

                if (!setupResult)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error("Failed to setup server instance!");
                    }
                    return(false);
                }

                m_AppServers.Add(appServer);
            }

            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);
        }
Exemplo n.º 5
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);

                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());
            //Initialize servers
            foreach (var factoryInfo in workItemFactories)
            {
                IWorkItem appServer;

                try
                {
                    appServer = CreateWorkItemInstance(factoryInfo.ServerType);

                    if (m_GlobalLog.IsDebugEnabled)
                    {
                        m_GlobalLog.DebugFormat("The server instance {0} has been created!", factoryInfo.Config.Name);
                    }
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error(string.Format("Failed to create server instance {0}!", factoryInfo.Config.Name), e);
                    }
                    return(false);
                }


                var setupResult = false;

                try
                {
                    setupResult = SetupWorkItemInstance(appServer, factoryInfo);

                    if (m_GlobalLog.IsDebugEnabled)
                    {
                        m_GlobalLog.DebugFormat("The server instance {0} has been initialized!", appServer.Name);
                    }
                }
                catch (Exception e)
                {
                    m_GlobalLog.Error(e);
                    setupResult = false;
                }

                if (!setupResult)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error("Failed to setup server instance!");
                    }
                    return(false);
                }

                m_AppServers.Add(appServer);
            }

            if (!m_Config.DisablePerformanceDataCollector)
            {
                m_PerfMonitor = new PerformanceMonitor(m_Config, m_AppServers, 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;

            return(true);
        }
        /// <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);
        }