Exemplo n.º 1
0
        private IWorkItem InitializeAndSetupWorkItem(WorkItemFactoryInfo factoryInfo)
        {
            IWorkItem appServer;

            try
            {
                appServer = CreateWorkItemInstance(factoryInfo.ServerType, factoryInfo.StatusInfoMetadata);

                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(null);
            }

            var exceptionSource = appServer as IExceptionSource;

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


            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(null);
            }

            return(appServer);
        }
Exemplo n.º 2
0
        internal virtual bool SetupWorkItemInstance(IWorkItem workItem, WorkItemFactoryInfo factoryInfo)
        {
            try
            {
                //Share AppDomain AppServers also share same socket server factory and log factory instances
                factoryInfo.SocketServerFactory.ExportFactory.EnsureInstance();
                factoryInfo.LogFactory.ExportFactory.EnsureInstance();
            }
            catch (Exception e)
            {
                if (m_GlobalLog.IsErrorEnabled)
                {
                    m_GlobalLog.Error(e);
                }

                return(false);
            }

            return(workItem.Setup(this, factoryInfo.Config, factoryInfo.ProviderFactories.ToArray()));
        }
Exemplo n.º 3
0
 internal override bool SetupWorkItemInstance(IWorkItem workItem, WorkItemFactoryInfo factoryInfo)
 {
     return(workItem.Setup(m_Bootstrap, factoryInfo.Config, factoryInfo.ProviderFactories.ToArray()));
 }
Exemplo n.º 4
0
        public List <WorkItemFactoryInfo> LoadResult(Func <IServerConfig, IServerConfig> serverConfigResolver)
        {
            var workItemFactories = new List <WorkItemFactoryInfo>(m_Config.Servers.Count());

            //var providerFactories = new List<ProviderFactoryInfo>();

            //Initialize server types
            var serverTypeFactories = InitializeProviderFactories(ProviderKey.ServerType, m_Config.ServerTypes);

            //Initialize connection filters
            var connectionFilterFactories = InitializeProviderFactories(ProviderKey.ConnectionFilter, m_Config.ConnectionFilters);

            //Initialize log factories
            var logFactoryFactories = InitializeProviderFactories(ProviderKey.LogFactory, m_Config.LogFactories, m_DefaultLogFactory);

            //Initialize Receive filter factories
            var receiveFilterFactories = InitializeProviderFactories(ProviderKey.ReceiveFilterFactory, m_Config.ReceiveFilterFactories);


            //Initialize command loader factories
            var commandLoaderFactories = InitializeProviderFactories(ProviderKey.CommandLoader, m_Config.CommandLoaders);

            //Initialize servers
            foreach (var c in m_Config.Servers.OrderBy(s => s.StartupOrder))
            {
                var serverConfig = serverConfigResolver(c);

                if (string.IsNullOrEmpty(serverConfig.Name))
                {
                    throw new Exception("The name attribute of server node is required!");
                }

                string serverType;

                if (string.IsNullOrEmpty(serverConfig.ServerTypeName))
                {
                    if (string.IsNullOrEmpty(serverConfig.ServerType))
                    {
                        throw new Exception("Either serverTypeName or serverType attribute of the server node is required!");
                    }

                    serverType = ValidateProviderType(serverConfig.ServerType);
                }
                else
                {
                    var serviceFactory = serverTypeFactories.FirstOrDefault(p => p.Name.Equals(serverConfig.ServerTypeName, StringComparison.OrdinalIgnoreCase));

                    if (serviceFactory == null)
                    {
                        throw new Exception(string.Format("Failed to find a service for server {0}!", serverConfig.Name));
                    }

                    serverType = serviceFactory.ExportFactory.TypeName;
                }

                var workItemFactory = new WorkItemFactoryInfo();
                workItemFactory.Config     = serverConfig;
                workItemFactory.ServerType = serverType;

                var serverTypeMeta = GetServerTypeMetadata(serverType);
                if (serverTypeMeta != null)
                {
                    workItemFactory.StatusInfoMetadata = serverTypeMeta.StatusInfoMetadata;
                    workItemFactory.IsServerManager    = serverTypeMeta.IsServerManager;
                }

                var factories = new List <ProviderFactoryInfo>();

                workItemFactory.SocketServerFactory = new ProviderFactoryInfo(ProviderKey.SocketServerFactory, string.Empty, typeof(SocketServerFactory));

                factories.Add(workItemFactory.SocketServerFactory);

                //Initialize connection filters
                if (!string.IsNullOrEmpty(serverConfig.ConnectionFilter))
                {
                    var currentFactories = GetSelectedFactories(connectionFilterFactories, serverConfig.ConnectionFilter);

                    if (currentFactories.Any())
                    {
                        factories.AddRange(currentFactories);
                    }
                }

                //Initialize command loaders
                if (!string.IsNullOrEmpty(serverConfig.CommandLoader))
                {
                    var currentFactories = GetSelectedFactories(commandLoaderFactories, serverConfig.CommandLoader);

                    if (currentFactories.Any())
                    {
                        factories.AddRange(currentFactories);
                    }
                }

                var logFactoryName = serverConfig.LogFactory;

                if (!string.IsNullOrEmpty(logFactoryName))
                {
                    logFactoryName = logFactoryName.Trim();

                    var logProviderFactory = logFactoryFactories.FirstOrDefault(p => p.Name.Equals(logFactoryName, StringComparison.OrdinalIgnoreCase));

                    if (logProviderFactory == null)
                    {
                        throw new Exception(string.Format("the specific log factory '{0}' cannot be found!", logFactoryName));
                    }

                    workItemFactory.LogFactory = logProviderFactory;
                }
                else
                {
                    workItemFactory.LogFactory = m_DefaultLogFactory;
                }

                factories.Add(workItemFactory.LogFactory);

                //Initialize Receive filter factory
                if (!string.IsNullOrEmpty(serverConfig.ReceiveFilterFactory))
                {
                    var currentReceiveFilterFactory = receiveFilterFactories.FirstOrDefault(p => p.Name.Equals(serverConfig.ReceiveFilterFactory, StringComparison.OrdinalIgnoreCase));

                    if (currentReceiveFilterFactory == null)
                    {
                        throw new Exception(string.Format("the specific Receive filter factory '{0}' cannot be found!", serverConfig.ReceiveFilterFactory));
                    }

                    factories.Add(currentReceiveFilterFactory);
                }

                workItemFactory.ProviderFactories = factories;

                workItemFactories.Add(workItemFactory);
            }

            return(workItemFactories);
        }