示例#1
0
        private static void FillSubConfigs(RelayNodeConfig mainConfig)
        {
            if (mainConfig.SectionXml == null)
            {
                throw new ConfigurationErrorsException("Section Xml on RelayNodeConfig was not available; can't fill sub configs!");
            }

            //TODO: implement defaults for subsections.
            foreach (XmlNode node in mainConfig.SectionXml.ChildNodes)
            {
                switch (node.Name)
                {
                case "RelayComponents":

                    RelayComponents comps = GetSubConfig <RelayComponents>(node);
                    if (comps != null)
                    {
                        mainConfig.RelayComponents = comps.RelayComponentCollection;
                    }
                    else
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("No relay component config found.");
                        }
                    }
                    break;

                case "TypeSettings":
                    mainConfig.TypeSettings = GetSubConfig <TypeSettings>(node);
                    break;

                case "RelayNodeMapping":
                    mainConfig.RelayNodeMapping = GetSubConfig <RelayNodeMapping>(node);
                    break;

                case "TransportSettings":
                    mainConfig.TransportSettings = GetSubConfig <TransportSettings>(node);
                    break;
                }
            }
        }
示例#2
0
		/// <summary>
		/// Initializes the <see cref="RelayNode"/> with the given <see cref="ComponentRunState"/>s,
		/// must be called before calling <see cref="Start"/>
		/// </summary>
		/// <param name="componentRunStates"></param>
		public void Initialize(ComponentRunState[] componentRunStates)
		{
			try
			{
                if (log.IsInfoEnabled)
                {
                    if (componentRunStates == null)
                    {
                        log.Info("Initializing Relay Node.");
                    }
                    else
                    {
                        log.Info("Initialzing Relay Node with Component Run States.");
                    }
                }

				EnvironmentManager.EnvironmentChanged += EnvironmentChangedHandler;

                GetConfig();
				
				if (configuration == null) throw new ConfigurationErrorsException("config failed to load, is null");

				SetClusterAddresses(configuration);

				fatalFailureTimeout = configuration.FatalShutdownTimeout < 0
					? TimeSpan.FromMinutes(5)
					: TimeSpan.FromSeconds(configuration.FatalShutdownTimeout);

				components = new RelayComponents(configuration);

				if (configuration != null)
				{
					messageTracer = new MessageTracer(configuration.TypeSettings.MaxTypeId, configuration.TraceSettings);
					messageTracer.Activated = configuration.OutputTraceInfo;

					const string inThreadsName = "DataRelayNode";
					if (configuration.NumberOfThreads > 0)
					{
						inDispatcher = new Dispatcher(configuration.NumberOfThreads, ThreadPriority.Normal, true, inThreadsName);
					}
					else
					{
						inDispatcher = new Dispatcher() { Name = inThreadsName } ;
					}

					const string outThreadsName = "DataRelayNodeOUT";
					if (configuration.OutMessagesOnRelayThreads)
					{
						if (configuration.NumberOfOutMessageThreads > 0)
						{
							outDispatcher = new Dispatcher(configuration.NumberOfOutMessageThreads, ThreadPriority.Normal, true, outThreadsName);
						}
						else
						{
							outDispatcher = new Dispatcher { Name = outThreadsName };
						}

						outMessagePort = new Port<RelayMessageAsyncResult>();
						outMessagesPort = new Port<RelayMessageListAsyncResult>();

						outMessageQueue = new DispatcherQueue("DataRelayDispatcherQueueOUT", outDispatcher, TaskExecutionPolicy.ConstrainQueueDepthThrottleExecution, configuration.MaximumOutMessageQueueDepth);
						Arbiter.Activate(outMessageQueue,
								Arbiter.ReceiveWithIterator(true, outMessagePort, HandleOutMessage));
						Arbiter.Activate(outMessageQueue,
								Arbiter.ReceiveWithIterator(true, outMessagesPort, HandleOutMessages));
					}

					inMessageQueue = new DispatcherQueue("DataRelayDispatcherQueue", inDispatcher, TaskExecutionPolicy.ConstrainQueueDepthThrottleExecution, configuration.MaximumMessageQueueDepth);
					
					queuedTaskThreshold = (int)Math.Floor(0.9 * configuration.MaximumMessageQueueDepth);
					
					
					// setup RelayServicesClient before initalizing components
					RelayServicesClient.Instance.RelayNodeServices = this;
					
					Arbiter.Activate(inMessageQueue,
						Arbiter.Receive<RelayMessage>(true, inMessagePort, HandleInMessage));
					Arbiter.Activate(inMessageQueue,
								Arbiter.Receive<RelayMessageWithContext>(true, inMessageWithContextPort, HandleInMessage));
					Arbiter.Activate(inMessageQueue,
								Arbiter.Receive<IList<RelayMessage>>(true, inMessagesPort, HandleInMessages));
					

					//by having after the Arbiter.Activate it allows Initialize components to use 
					//IRelayNodeServices that require Message handling
					components.Initialize(componentRunStates, configuration.IgnoredMessageTypes);

					queuedMessageCounterTimer = new Timer(CountQueuedMessages, null, 5000, 5000);
				}
			}
			catch (Exception ex)
			{
                if (log.IsErrorEnabled)
                    log.ErrorFormat("Exception initializing relay node: {0}", ex);
				throw; //should bring server down
			}
		}
示例#3
0
        /// <summary>
        /// Initializes the <see cref="RelayNode"/> with the given <see cref="ComponentRunState"/>s,
        /// must be called before calling <see cref="Start"/>
        /// </summary>
        /// <param name="componentRunStates"></param>
        public void Initialize(ComponentRunState[] componentRunStates)
        {
            try
            {
                if (log.IsInfoEnabled)
                {
                    if (componentRunStates == null)
                    {
                        log.Info("Initializing Relay Node.");
                    }
                    else
                    {
                        log.Info("Initialzing Relay Node with Component Run States.");
                    }
                }

                EnvironmentManager.EnvironmentChanged += EnvironmentChangedHandler;

                GetConfig();

                if (configuration == null)
                {
                    throw new ConfigurationErrorsException("config failed to load, is null");
                }

                SetClusterAddresses(configuration);

                fatalFailureTimeout = configuration.FatalShutdownTimeout < 0
                                        ? TimeSpan.FromMinutes(5)
                                        : TimeSpan.FromSeconds(configuration.FatalShutdownTimeout);

                components = new RelayComponents(configuration);

                if (configuration != null)
                {
                    messageTracer           = new MessageTracer(configuration.TypeSettings.MaxTypeId, configuration.TraceSettings);
                    messageTracer.Activated = configuration.OutputTraceInfo;

                    const string inThreadsName = "DataRelayNode";
                    if (configuration.NumberOfThreads > 0)
                    {
                        inDispatcher = new Dispatcher(configuration.NumberOfThreads, ThreadPriority.Normal, true, inThreadsName);
                    }
                    else
                    {
                        inDispatcher = new Dispatcher()
                        {
                            Name = inThreadsName
                        };
                    }

                    const string outThreadsName = "DataRelayNodeOUT";
                    if (configuration.OutMessagesOnRelayThreads)
                    {
                        if (configuration.NumberOfOutMessageThreads > 0)
                        {
                            outDispatcher = new Dispatcher(configuration.NumberOfOutMessageThreads, ThreadPriority.Normal, true, outThreadsName);
                        }
                        else
                        {
                            outDispatcher = new Dispatcher {
                                Name = outThreadsName
                            };
                        }

                        outMessagePort  = new Port <RelayMessageAsyncResult>();
                        outMessagesPort = new Port <RelayMessageListAsyncResult>();

                        outMessageQueue = new DispatcherQueue("DataRelayDispatcherQueueOUT", outDispatcher, TaskExecutionPolicy.ConstrainQueueDepthThrottleExecution, configuration.MaximumOutMessageQueueDepth);
                        Arbiter.Activate(outMessageQueue,
                                         Arbiter.ReceiveWithIterator(true, outMessagePort, HandleOutMessage));
                        Arbiter.Activate(outMessageQueue,
                                         Arbiter.ReceiveWithIterator(true, outMessagesPort, HandleOutMessages));
                    }

                    inMessageQueue = new DispatcherQueue("DataRelayDispatcherQueue", inDispatcher, TaskExecutionPolicy.ConstrainQueueDepthThrottleExecution, configuration.MaximumMessageQueueDepth);

                    queuedTaskThreshold = (int)Math.Floor(0.9 * configuration.MaximumMessageQueueDepth);


                    // setup RelayServicesClient before initalizing components
                    RelayServicesClient.Instance.RelayNodeServices = this;

                    Arbiter.Activate(inMessageQueue,
                                     Arbiter.Receive <RelayMessage>(true, inMessagePort, HandleInMessage));
                    Arbiter.Activate(inMessageQueue,
                                     Arbiter.Receive <RelayMessageWithContext>(true, inMessageWithContextPort, HandleInMessage));
                    Arbiter.Activate(inMessageQueue,
                                     Arbiter.Receive <IList <RelayMessage> >(true, inMessagesPort, HandleInMessages));


                    //by having after the Arbiter.Activate it allows Initialize components to use
                    //IRelayNodeServices that require Message handling
                    components.Initialize(componentRunStates, configuration.IgnoredMessageTypes);

                    queuedMessageCounterTimer = new Timer(CountQueuedMessages, null, 5000, 5000);
                }
            }
            catch (Exception ex)
            {
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat("Exception initializing relay node: {0}", ex);
                }
                throw;                 //should bring server down
            }
        }
示例#4
0
        internal static RelayNodeConfig GetRelayNodeConfig(XmlNode section)
        {
            //XPathNavigator nav = section.CreateNavigator();
            XmlSerializer ser = new XmlSerializer(typeof(RelayNodeConfig));
            object        configurationObject;

            configurationObject = ser.Deserialize(new XmlNodeReader(section));
            RelayNodeConfig typedConfig = configurationObject as RelayNodeConfig;

            System.Configuration.Configuration confFile = GetConfigurationFile();

            string basePath = confFile.FilePath;

            if (typedConfig != null)
            {
                #region Get Sub Configs
                foreach (XmlNode node in section.ChildNodes)
                {
                    switch (node.Name)
                    {
                    case "RelayComponents":
                        RelayComponents comps = GetSourcedObject <RelayComponents>(basePath, node);
                        if (comps != null)
                        {
                            typedConfig.RelayComponents = comps.RelayComponentCollection;
                        }
                        else
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("No relay component config found.");
                            }
                        }
                        break;

                    case "TypeSettings":
                        TypeSettings typeSettings = GetSourcedObject <TypeSettings>(basePath, node);
                        if (typeSettings.TypeSettingCollection.Count == 0)
                        {
                            // attempt custom load
                            typeSettings = TypeSettingsConfigLoader.Load(basePath, node);
                        }
                        typedConfig.TypeSettings = typeSettings;

                        break;

                    case "RelayNodeMapping":
                        RelayNodeMapping nodeMapping = GetSourcedObject <RelayNodeMapping>(basePath, node);
                        typedConfig.RelayNodeMapping = nodeMapping;
                        break;

                    case "TransportSettings":
                        TransportSettings transportSettings = GetSourcedObject <TransportSettings>(basePath, node);
                        typedConfig.TransportSettings = transportSettings;
                        break;
                    }
                }
                #endregion

                if (System.Web.HttpContext.Current == null)                 //not a web project, doesn't apply
                {
                    WatchConfigFiles();
                }
                else
                {
                    SectionInformation info = confFile.GetSection(RelayNodeSectionHandler.ConfigSectionName).SectionInformation;
                    if (!info.RestartOnExternalChanges)
                    {
                        WatchConfigFiles();
                    }
                }
            }

            return(typedConfig);
        }