Beispiel #1
0
        internal NodeGroup(RelayNodeGroupDefinition groupDefinition, RelayNodeConfig nodeConfig, ForwardingConfig forwardingConfig)
        {
            GroupDefinition   = groupDefinition;
            Activated         = groupDefinition.Activated;
            _clusterByRange   = groupDefinition.UseIdRanges;
            _forwardingConfig = forwardingConfig;

            RelayNodeClusterDefinition myClusterDefinition = NodeManager.Instance.GetMyNodeClusterDefinition();

            foreach (RelayNodeClusterDefinition clusterDefintion in groupDefinition.RelayNodeClusters)
            {
                NodeCluster nodeCluster = new NodeCluster(clusterDefintion, nodeConfig, this, forwardingConfig);
                if (clusterDefintion == myClusterDefinition)
                {
                    MyCluster = nodeCluster;
                }
                Clusters.Add(nodeCluster);
            }

            _nodeReselectTimerCallback = new System.Threading.TimerCallback(NodeReselectTimer_Elapsed);
            if (_nodeReselectTimer == null)
            {
                _nodeReselectTimer = new System.Threading.Timer(_nodeReselectTimerCallback);
            }
            _nodeReselectTimer.Change(NodeReselectIntervalMilliseconds, NodeReselectIntervalMilliseconds);

            QueueTimerCallback = new System.Threading.TimerCallback(QueueTimer_Elapsed);
            if (QueueTimer == null)
            {
                QueueTimer = new System.Threading.Timer(QueueTimerCallback);
            }
            QueueTimer.Change(DequeueIntervalMilliseconds, DequeueIntervalMilliseconds);
        }
		internal NodeGroup(RelayNodeGroupDefinition groupDefinition, RelayNodeConfig nodeConfig, ForwardingConfig forwardingConfig)
		{   
			GroupDefinition = groupDefinition;
			Activated = groupDefinition.Activated;
			_clusterByRange = groupDefinition.UseIdRanges;
			_forwardingConfig = forwardingConfig;
			NodeSelectionHopWindowSize = groupDefinition.NodeSelectionHopWindowSize;
			RelayNodeClusterDefinition myClusterDefinition = NodeManager.Instance.GetMyNodeClusterDefinition();

			foreach (RelayNodeClusterDefinition clusterDefintion in groupDefinition.RelayNodeClusters)
			{
				NodeCluster nodeCluster = new NodeCluster(clusterDefintion, nodeConfig, this, forwardingConfig);
				if (clusterDefintion == myClusterDefinition)
				{
					MyCluster = nodeCluster;
				}
				Clusters.Add(nodeCluster);
			}

			_nodeReselectTimerCallback = new System.Threading.TimerCallback(NodeReselectTimer_Elapsed);
			if (_nodeReselectTimer == null)
			{
				_nodeReselectTimer = new System.Threading.Timer(_nodeReselectTimerCallback);
			}
			_nodeReselectTimer.Change(NodeReselectIntervalMilliseconds, NodeReselectIntervalMilliseconds);

			QueueTimerCallback = new System.Threading.TimerCallback(QueueTimer_Elapsed);
			if (QueueTimer == null)
			{
				QueueTimer = new System.Threading.Timer(QueueTimerCallback);
			}
			QueueTimer.Change(DequeueIntervalMilliseconds, DequeueIntervalMilliseconds);
		}
        private void InitializeInstance(RelayNodeConfig config, ForwardingConfig forwardingConfig, Dictionary <string, Dictionary <string, MessageQueue> > errorQueues)
        {
            Counters = new ForwardingCounters();

            if (config != null)
            {
                //without this we'll get a null ref exception
                if (forwardingConfig == null)
                {
                    throw new ArgumentNullException("forwardingConfig", "Requires a forwardingConfig to initialize");
                }

                Config           = config;
                ForwardingConfig = forwardingConfig;
                _zoneDefinitions = config.RelayNodeMapping.ZoneDefinitions;
                Counters.Initialize(Config.InstanceName);

                if (InMessageDispatcher != null)
                {
                    if (_log.IsInfoEnabled)
                    {
                        _log.Info("Relay Forwarder Node Manager Initialized with non-null Dispatcher.");
                    }
                }
                else
                {
                    InMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfThreads, ThreadPriority.Normal, true, "Relay Forwarder");
                }

                if (OutMessageDispatcher == null)
                {
                    OutMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfOutMessageThreads, ThreadPriority.Normal, true, "Relay Forwader Out Messages");
                }

                NodeGroup.MaximumQueuedItems = forwardingConfig.MaximumTaskQueueDepth;

                BuildNodeGroups(config, errorQueues);

                if (config.MyAddresses != null && config.MyAddresses.Count > 0)
                {
                    for (int i = 0; i < config.MyAddresses.Count; i++)
                    {
                        AddressFamily family = config.MyAddresses[i].AddressFamily;
                        if (family == AddressFamily.InterNetwork &&
                            !IPAddress.Loopback.Equals(config.MyAddresses[i])
                            )
                        {
                            MyIpAddress = config.MyAddresses[i];
                            break;
                        }
                    }
                }

                _queuedMessageCounterTimer = new Timer(CountQueuedMessages, null, 5000, 5000);

                _aggregateCounterTickTimer = new Timer(AggregateCounterTicker, null, 500, 500);
                _myNodeDefinition          = GetMyNodeDefinition();
            }
        }
Beispiel #4
0
        internal void ReloadMapping(RelayNodeGroupDefinition groupDefinition, RelayNodeConfig newConfig, ForwardingConfig newForwardingConfig)
        {
            RelayNodeClusterDefinition myClusterDefinition = newConfig.GetMyCluster();

            Activated         = groupDefinition.Activated;
            GroupDefinition   = groupDefinition;
            _clusterByRange   = groupDefinition.UseIdRanges;
            _forwardingConfig = newForwardingConfig;

            if (groupDefinition.RelayNodeClusters.Length == Clusters.Count)
            {
                //same number of clusters, just let the clusters rebuild themselves. the clusters will entirely rebuild, so shuffinling around servers should be okay
                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Rebuilding existing clusters in group {0}.", groupDefinition.Name);
                }
                for (int i = 0; i < groupDefinition.RelayNodeClusters.Length; i++)
                {
                    Clusters[i].ReloadMapping(groupDefinition.RelayNodeClusters[i], newConfig, newForwardingConfig);
                    if (groupDefinition.RelayNodeClusters[i] == myClusterDefinition)
                    {
                        MyCluster = Clusters[i];
                    }
                }
                if (myClusterDefinition == null && MyCluster != null)
                {
                    if (_log.IsInfoEnabled)
                    {
                        _log.InfoFormat("Group {0} no longer contains this server. Removing.", GroupName);
                    }
                    //this group no longer contains "me". If it DID contain "me", it would've been set above.
                    MyCluster = null;
                }
            }
            else
            {
                //build new clusters and replace the existing ones with them
                if (_log.IsInfoEnabled)
                {
                    _log.InfoFormat("Number of clusters in group {0} changed, rebuilding.", groupDefinition.Name);
                }
                NodeCluster        myCluster   = null;
                List <NodeCluster> newClusters = new List <NodeCluster>();
                foreach (RelayNodeClusterDefinition clusterDefintion in groupDefinition.RelayNodeClusters)
                {
                    NodeCluster nodeCluster = new NodeCluster(clusterDefintion, newConfig, this, newForwardingConfig);
                    if (clusterDefintion == myClusterDefinition)
                    {
                        myCluster = nodeCluster;
                    }
                    newClusters.Add(nodeCluster);
                }
                Clusters  = newClusters;
                MyCluster = myCluster;
            }
            _nodeReselectTimer.Change(NodeReselectIntervalMilliseconds, NodeReselectIntervalMilliseconds);
        }
		private void InitializeInstance(RelayNodeConfig config, ForwardingConfig forwardingConfig, Dictionary<string, Dictionary<string, MessageQueue>> errorQueues)
		{
			Counters = new ForwardingCounters();

			if (config != null)
			{
				//without this we'll get a null ref exception
				if (forwardingConfig == null) throw new ArgumentNullException("forwardingConfig", "Requires a forwardingConfig to initialize");
				  
				Config = config;
				ForwardingConfig = forwardingConfig;
				_zoneDefinitions = config.RelayNodeMapping.ZoneDefinitions;		
				Counters.Initialize(Config.InstanceName);

				if (InMessageDispatcher != null)
				{
					if (_log.IsInfoEnabled)
						_log.Info("Relay Forwarder Node Manager Initialized with non-null Dispatcher.");                    
				}
				else
				{
					InMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfThreads, ThreadPriority.Normal, true, "Relay Forwarder");
				}

				if (OutMessageDispatcher == null)
				{
					OutMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfOutMessageThreads, ThreadPriority.Normal, true, "Relay Forwader Out Messages");
				}
				
				NodeGroup.MaximumQueuedItems = forwardingConfig.MaximumTaskQueueDepth;

				BuildNodeGroups(config, errorQueues);

				if (config.MyAddresses != null && config.MyAddresses.Count > 0)
				{	
					for (int i = 0; i < config.MyAddresses.Count; i++)
					{
						AddressFamily family = config.MyAddresses[i].AddressFamily;
						if (family == AddressFamily.InterNetwork &&
							!IPAddress.Loopback.Equals(config.MyAddresses[i])
							)
						{
							MyIpAddress = config.MyAddresses[i];
							break;
						}
					}
				}

				_queuedMessageCounterTimer = new Timer(CountQueuedMessages, null, 5000, 5000);

				_aggregateCounterTickTimer = new Timer(AggregateCounterTicker, null, 500, 500);
				_myNodeDefinition = GetMyNodeDefinition();
			}
		}
 internal static void Initialize(RelayNodeConfig config, ForwardingConfig forwardingConfig, Dictionary <string, Dictionary <string, MessageQueue> > errorQueues)
 {
     lock (_instanceLock)
     {
         if (!_initialized)
         {
             Instance.InitializeInstance(config, forwardingConfig, errorQueues);
             _initialized = true;
         }
     }
 }
		internal static void Initialize(RelayNodeConfig config, ForwardingConfig forwardingConfig, Dictionary<string, Dictionary<string, MessageQueue>> errorQueues)
		{
			lock (_instanceLock)
			{
				if (!_initialized)
				{
					Instance.InitializeInstance(config, forwardingConfig, errorQueues);
					_initialized = true;
				}                
			}
		}
Beispiel #8
0
 /// <summary>
 /// this (or <see cref="ReloadConfig"/>) gets called (depending) when the TypeSettings.Config file
 /// are changed.
 /// </summary>
 /// <remarks>
 /// Added: craigbro
 /// cachedTypeSettings now held with the forwarder for reference of
 /// exceptions on Synchronous "in" messages.
 /// To reload, we just null out the cached TypeSettingsCollection object and the
 /// accessor will reload it on next call
 /// While ConfigurationManager.GetSection is quite performant after the 1st hit,
 /// keeping them cached is about twice as fast.
 /// </remarks>
 /// <param name="config"></param>
 /// <param name="runState"></param>
 private void LoadConfig(RelayNodeConfig config, ComponentRunState runState)
 {
     if (config != null)
     {
         if (config.RelayComponents != null)
         {
             object           configObject     = config.RelayComponents.GetConfigFor(GetComponentName());
             ForwardingConfig forwardingConfig = configObject as ForwardingConfig;
             if (forwardingConfig == null)
             {
                 if (log.IsInfoEnabled)
                 {
                     log.Info("No forwarding configuration supplied. Using defaults.");
                 }
                 forwardingConfig = new ForwardingConfig();
             }
             NodeManager.Initialize(config, forwardingConfig, GetErrorQueues(runState));
             TypeSettingCollection typeSettingCollection = null;
             if (NodeManager.Instance.Config != null)
             {
                 if (NodeManager.Instance.Config.TypeSettings != null)
                 {
                     typeSettingCollection = NodeManager.Instance.Config.TypeSettings.TypeSettingCollection;
                 }
             }
             TypeSpecificStatisticsManager.Initialize(typeSettingCollection);
             _enableAsyncBulkGets = forwardingConfig.EnableAsyncBulkGets;
             _myNodeDefinition    = NodeManager.Instance.GetMyNodeDefinition();
             _myZone = Node.DetermineZone(_myNodeDefinition);
             short maxTypeId = 0;
             if (config.TypeSettings != null)
             {
                 maxTypeId = config.TypeSettings.MaxTypeId;
             }
             DebugWriter.SetTraceSettings(maxTypeId, forwardingConfig.TraceSettings);
             DebugWriter.WriteCallingMethod = forwardingConfig.WriteCallingMethod;
             DebugWriter.WriteMessageTrace  = forwardingConfig.WriteMessageTrace;
         }
         else
         {
             NodeManager.Initialize(null, null, null);
             TypeSpecificStatisticsManager.Initialize(null);
         }
     }
     else
     {
         NodeManager.Initialize(null, null, null);
         TypeSpecificStatisticsManager.Initialize(null);
     }
 }
Beispiel #9
0
		internal Node(RelayNodeDefinition nodeDefinition, NodeGroup ownerGroup, NodeCluster ownerCluster, ForwardingConfig forwardingConfig, DispatcherQueue inMessageQueue, DispatcherQueue outMessageQueue)
		{
			DetectedZone = 0;
			NodeDefinition = nodeDefinition;
			NodeGroup = ownerGroup;
			NodeCluster = ownerCluster;
			_messageCounts = new int[RelayMessage.NumberOfTypes];
			_lastMessageTimes = new double[RelayMessage.NumberOfTypes];
			_averageMessageTimes = new double[RelayMessage.NumberOfTypes];
			if (EndPoint != null)
			{
				_transport = TransportFactory.CreateTransportForNode(nodeDefinition, ownerGroup.GroupDefinition, forwardingConfig.MessageChunkLength);
				DetectedZone = NodeManager.Instance.GetZoneForAddress(EndPoint.Address);
				if (forwardingConfig.MapNetwork)
				{
					HopsFromHere = HowManyHopsFromHere();
				}
				else
				{
					HopsFromHere = 0;
				}
			}
			else
			{
				_transport = new NullTransport();
			}

			_inMessageQueue = inMessageQueue;
			_outMessageQueue = outMessageQueue;

			if (forwardingConfig != null)
			{
				_messageBurstLength = forwardingConfig.MessageBurstLength;
				_messageBurstTimeout = forwardingConfig.MessageBurstTimeout;
				_messageBurstTimeoutSpan = TimeSpan.FromMilliseconds(_messageBurstTimeout);
				MessageErrorQueue = new MessageQueue(ownerGroup.GetQueueConfig());
				_repostMessageLists = forwardingConfig.RepostMessageLists;
			}

			ActivateBurstReceive(1); //the burst length will be used after the first message is received

			// async, no skipping of the error queue (duh)
			Arbiter.Activate(_inMessageQueue,
				Arbiter.Receive<List<SerializedRelayMessage>>(true, _inMessagesPort,
															  messages => DoHandleInMessages(messages, false)));

			Arbiter.Activate(_outMessageQueue,
				Arbiter.Receive<MessagesWithLock>(true, _outMessagesPort,
				delegate(MessagesWithLock messages) { HandleOutMessages(messages.Messages); messages.Locker.Decrement(); }));
		}
Beispiel #10
0
 /// <summary>
 /// this (or <see cref="LoadConfig"/>) gets called (depending) when the TypeSettings.Config file
 /// are changed.
 /// </summary>
 /// <remarks>
 /// Added: craigbro
 /// cachedTypeSettings now held with the forwarder for reference of
 /// exceptions on Synchronous "in" messages.
 /// To reload, we just null out the cached TypeSettingsCollection object and the
 /// accessor will reload it on next call
 /// While ConfigurationManager.GetSection is quite performant after the 1st hit,
 /// keeping them cached is about twice as fast.
 /// </remarks>
 /// <param name="config">The config to reload</param>
 public void ReloadConfig(RelayNodeConfig config)
 {
     lock (reloadLock)
     {
         if (config != null)
         {
             try
             {
                 object           configObject     = config.RelayComponents.GetConfigFor(GetComponentName());
                 ForwardingConfig forwardingConfig = configObject as ForwardingConfig;
                 if (forwardingConfig == null)
                 {
                     if (log.IsInfoEnabled)
                     {
                         log.InfoFormat("No forwarding configuration supplied. Reloading using defaults.");
                     }
                     forwardingConfig = new ForwardingConfig();
                 }
                 NodeManager.Instance.ReloadConfig(config, forwardingConfig);
                 if (NodeManager.Instance.Config != null)
                 {
                     if (NodeManager.Instance.Config.TypeSettings != null)
                     {
                         TypeSpecificStatisticsManager.Instance.ReloadMapping(
                             NodeManager.Instance.Config.TypeSettings.TypeSettingCollection);
                     }
                 }
                 _enableAsyncBulkGets = forwardingConfig.EnableAsyncBulkGets;
                 _myNodeDefinition    = NodeManager.Instance.GetMyNodeDefinition();
                 _myZone = Node.DetermineZone(_myNodeDefinition);
                 short maxTypeId = 0;
                 if (config.TypeSettings != null)
                 {
                     maxTypeId = config.TypeSettings.MaxTypeId;
                 }
                 DebugWriter.SetTraceSettings(maxTypeId, forwardingConfig.TraceSettings);
                 DebugWriter.WriteCallingMethod = forwardingConfig.WriteCallingMethod;
                 DebugWriter.WriteMessageTrace  = forwardingConfig.WriteMessageTrace;
             }
             catch (Exception ex)
             {
                 if (log.IsErrorEnabled)
                 {
                     log.ErrorFormat("Exception reloading config: {0}", ex);
                 }
             }
         }
     }
 }
Beispiel #11
0
        private void InitializeInstance(RelayNodeConfig config, ForwardingConfig forwardingConfig, Dictionary <string, Dictionary <string, ErrorQueue> > errorQueues)
        {
            Counters = new ForwardingCounters();

            if (config != null)
            {
                //without this we'll get a null ref exception
                if (forwardingConfig == null)
                {
                    throw new ArgumentNullException("forwardingConfig", "Requires a forwardingConfig to initialize");
                }

                Config           = config;
                ForwardingConfig = forwardingConfig;
                _zoneDefinitions = config.RelayNodeMapping.ZoneDefinitions;
                Counters.Initialize(Config.InstanceName);

                ExtractCommonConfigValues(forwardingConfig);

                if (InMessageDispatcher != null)
                {
                    if (_log.IsInfoEnabled)
                    {
                        _log.Info("Relay Forwarder Node Manager Initialized with non-null Dispatcher.");
                    }
                }
                else
                {
                    InMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfThreads, ThreadPriority.Normal, true, "Relay Forwarder");
                }

                if (OutMessageDispatcher == null)
                {
                    OutMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfOutMessageThreads, ThreadPriority.Normal, true, "Relay Forwader Out Messages");
                }



                BuildNodeGroups(config, errorQueues);

                MyIpAddress = config.GetAddressToUse();

                _queuedMessageCounterTimer = new Timer(CountQueuedMessages, null, 5000, 5000);

                _aggregateCounterTickTimer = new Timer(AggregateCounterTicker, null, 500, 500);
                _myNodeDefinition          = GetMyNodeDefinition();
                _myZone = Node.DetermineZone(_myNodeDefinition);
            }
        }
Beispiel #12
0
        private void ExtractCommonConfigValues(ForwardingConfig config)
        {
            NodeGroup.MaximumQueuedItems = config.MaximumTaskQueueDepth;

            if (config.QueueConfig != null)
            {
                _log.InfoFormat("Error queue config:  Enabled={0} DequeueInterval={1} ItemsPerDequeue={2} MaxCount={3} PersistenceFolder={4} MaxPersistedMB={5} PersistenceFileSize={6}",
                                config.QueueConfig.Enabled,
                                config.QueueConfig.DequeueIntervalSeconds,
                                config.QueueConfig.ItemsPerDequeue,
                                config.QueueConfig.MaxCount,
                                config.QueueConfig.PersistenceFolder,
                                config.QueueConfig.MaxPersistedMB,
                                config.QueueConfig.PersistenceFileSize);
            }
        }
        internal void ReloadMapping(RelayNodeConfig newConfig, ForwardingConfig forwardingConfig)
        {
            RelayNodeMapping relayNodeMapping = newConfig.RelayNodeMapping;
            RelayNodeGroupDefinitionCollection groupDefinitions = relayNodeMapping.RelayNodeGroups;

            foreach (RelayNodeGroupDefinition groupDefinition in groupDefinitions)
            {
                if (Contains(groupDefinition.Name))
                {
                    this[groupDefinition.Name].ReloadMapping(groupDefinition, newConfig, forwardingConfig);
                }
                else
                {
                    if (_log.IsInfoEnabled)
                    {
                        _log.InfoFormat("Adding new node group {0}", groupDefinition.Name);
                    }
                    Add(new NodeGroup(groupDefinition, newConfig, forwardingConfig));
                }
            }

            bool removedOne;

            //make sure if any groups have been removed they are removed!
            do
            {
                removedOne = false;
                foreach (NodeGroup group in this)
                {
                    if (!groupDefinitions.Contains(group.GroupName))
                    {
                        if (_log.IsInfoEnabled)
                        {
                            _log.InfoFormat("Removing node group {0}", group.GroupName);
                        }
                        Remove(group.GroupName);
                        removedOne = true;
                        break;                         //collection modified can't continue with foreach!
                    }
                }
            } while (removedOne);

            _groupsByTypeId = GenerateGroupsByTypeId(newConfig.TypeSettings);
        }
Beispiel #14
0
		/// <summary>
		/// this (or <see cref="ReloadConfig"/>) gets called (depending) when the TypeSettings.Config file
		/// are changed.  
		/// </summary>
		/// <remarks>
		/// Added: craigbro
		/// cachedTypeSettings now held with the forwarder for reference of
		/// exceptions on Synchronous "in" messages.  
		/// To reload, we just null out the cached TypeSettingsCollection object and the
		/// accessor will reload it on next call
		/// While ConfigurationManager.GetSection is quite performant after the 1st hit,
		/// keeping them cached is about twice as fast.		
		/// </remarks>
		/// <param name="config"></param>
		/// <param name="runState"></param>
		private void LoadConfig(RelayNodeConfig config, ComponentRunState runState)
		{
			if (config != null)
			{
				if (config.RelayComponents != null)
				{
					object configObject = config.RelayComponents.GetConfigFor(GetComponentName());
					ForwardingConfig forwardingConfig = configObject as ForwardingConfig;
					if(forwardingConfig == null)
					{
						if(_log.IsInfoEnabled)
						{
							_log.Info("No forwarding configuration supplied. Using defaults.");
						}
						forwardingConfig = new ForwardingConfig();

					}
					NodeManager.Initialize(config, forwardingConfig, GetErrorQueues(runState));
					_enableAsyncBulkGets = forwardingConfig.EnableAsyncBulkGets;
					_myNodeDefinition = NodeManager.Instance.GetMyNodeDefinition();
                    
					short maxTypeId = 0;
					if(config.TypeSettings != null)
					{
						maxTypeId = config.TypeSettings.MaxTypeId;
					}
					DebugWriter.SetTraceSettings(maxTypeId,forwardingConfig.TraceSettings);
					DebugWriter.WriteCallingMethod = forwardingConfig.WriteCallingMethod;
					DebugWriter.WriteMessageTrace = forwardingConfig.WriteMessageTrace;
				}
				else
				{
					NodeManager.Initialize(null, null, null);
				}
			}
			else
			{
				NodeManager.Initialize(null, null, null);
			}
		}
		internal void ReloadConfig(RelayNodeConfig config, ForwardingConfig newForwardingConfig)
		{

			if (config.RelayNodeMapping == null)
			{
				if (_log.IsErrorEnabled)
					_log.Error("Got new config with no defined groups.");
			}
			else
			{
				if (config.RelayNodeMapping.Validate())
				{
					_zoneDefinitions = config.RelayNodeMapping.ZoneDefinitions;	//make sure this is set before reloading the mapping so any changes propogate	
					Dictionary<string, Dictionary<string, MessageQueue>> errorQueues = GetErrorQueues();
					NodeGroups.ReloadMapping(config, newForwardingConfig);
					//note that if a node changes groups, the error queue won't make it!
					NodeGroups.PopulateQueues(errorQueues, false);
				}
				else
				{
					if (_log.IsErrorEnabled)
						_log.Error("Forwarder not reloading invalid config.");
				}
			}

			Config = config;

			_myNodeDefinition = GetMyNodeDefinition();
			bool doNewInDispatcher, doNewOutDispatcher;
			if (newForwardingConfig.NumberOfThreads != ForwardingConfig.NumberOfThreads)
			{
				doNewInDispatcher = true;
			}
			else
			{
				doNewInDispatcher = false;
			}
			if (newForwardingConfig.NumberOfOutMessageThreads != ForwardingConfig.NumberOfOutMessageThreads)
			{
				doNewOutDispatcher = true;
			}
			else
			{
				doNewOutDispatcher = false;
			}


			if (doNewInDispatcher || doNewOutDispatcher)
			{
				Dispatcher oldInDispatcher = null, newInDispatcher, oldOutDispatcher = null, newOutDispatcher;

				if (doNewInDispatcher)
				{
					if (_log.IsInfoEnabled)
						_log.InfoFormat("Changing number of messaging threads from {0} to {1}", ForwardingConfig.NumberOfThreads, newForwardingConfig.NumberOfThreads);
					oldInDispatcher = InMessageDispatcher;
					newInDispatcher = new Dispatcher(newForwardingConfig.NumberOfThreads, ThreadPriority.Normal, true, "Relay Forwarder");

				}
				else
				{
					newInDispatcher = InMessageDispatcher;
				}
				if (doNewOutDispatcher)
				{
					if (_log.IsInfoEnabled)
						_log.InfoFormat("Changing number of out message threads from {0} to {1}", ForwardingConfig.NumberOfOutMessageThreads, newForwardingConfig.NumberOfOutMessageThreads);
					oldOutDispatcher = OutMessageDispatcher;
					newOutDispatcher = new Dispatcher(newForwardingConfig.NumberOfOutMessageThreads, ThreadPriority.Normal, true, "Relay Forwarder");
				}
				else
				{
					newOutDispatcher = OutMessageDispatcher;
				}

				InMessageDispatcher = newInDispatcher;
				OutMessageDispatcher = newOutDispatcher;

				NodeGroups.SetNewDispatchers(newInDispatcher, newOutDispatcher);

				ForwardingConfig = newForwardingConfig;

				if (doNewInDispatcher)
				{
					if (_log.IsInfoEnabled)
						_log.Info("Disposing old in message Dispatcher");
					oldInDispatcher.Dispose();
				}
				if (doNewOutDispatcher)
				{
					if (_log.IsInfoEnabled)
						_log.Info("Disposing old out message Dispatcher");
					oldOutDispatcher.Dispose();
				}
			}
			else
			{
				ForwardingConfig = newForwardingConfig;
			}
		}
		internal void ReloadMapping(RelayNodeClusterDefinition relayNodeClusterDefinition, RelayNodeConfig newConfig, ForwardingConfig forwardingConfig)
		{
			_minimumId = relayNodeClusterDefinition.MinId;
			_maximumId = relayNodeClusterDefinition.MaxId;
			_mapNetwork = forwardingConfig.MapNetwork;
			
			//figure out if anything changed. if it did, rebuild
			
			bool rebuild = false;

			ushort newLocalZone = newConfig.GetLocalZone();
			if (newLocalZone != _localZone)
			{
				rebuild = true;
				_localZone = newLocalZone;
			}
			else
			{
				if((_zoneDefinitions == null && newConfig.RelayNodeMapping.ZoneDefinitions != null) ||
				(_zoneDefinitions != null && newConfig.RelayNodeMapping.ZoneDefinitions == null) ||
				(_zoneDefinitions != null && !_zoneDefinitions.Equals(newConfig.RelayNodeMapping.ZoneDefinitions)))
				{
					rebuild = true;
					_zoneDefinitions = newConfig.RelayNodeMapping.ZoneDefinitions;
				}
				
			}
			

			int effectiveSize = (!_meInThisCluster ? Nodes.Count : Nodes.Count + 1);
			
			//if there's a different number of nodes, we definitely have to rebuild
			if (relayNodeClusterDefinition.RelayNodes.Length != effectiveSize)
			{
				if(_log.IsInfoEnabled)
					_log.InfoFormat("Number of nodes in a cluster in group {0} changed from {1} to {2}, rebuilding", _nodeGroup.GroupName, effectiveSize, relayNodeClusterDefinition.RelayNodes.Length);				
				rebuild = true;
			}
			else
			{
				//if any of the nodes we do have aren't in the config, rebuild				
				foreach (Node node in Nodes)
				{
					if (!relayNodeClusterDefinition.ContainsNode(node.EndPoint.Address, node.EndPoint.Port))
					{
						if (_log.IsInfoEnabled)
							_log.InfoFormat("Node {0} is no longer found in its cluster in group {1}, rebuilding.",
								node, _nodeGroup.GroupName);
						rebuild = true;						
						break;
					}
				}
				if (!rebuild && _nodeGroup.NodeSelectionHopWindowSize != NodeSelectionHopWindowSize)
				{
					NodeSelectionHopWindowSize = _nodeGroup.NodeSelectionHopWindowSize;
					rebuild = true;                    
				}

				if (!rebuild && _meInThisCluster)
				{
					if (!relayNodeClusterDefinition.ContainsNode(Me.EndPoint.Address, Me.EndPoint.Port))
					{
						if (_log.IsInfoEnabled)
							_log.InfoFormat("Node {0} (this machine) is no longer found in its cluster in group {1}, rebuilding.",
								Me, _nodeGroup.GroupName);
						rebuild = true;						
					}
				}

				//or if there are any nodes in the config that aren't here, rebuild
				if (!rebuild)
				{
					foreach(RelayNodeDefinition nodeDefinition in relayNodeClusterDefinition.RelayNodes)
					{
						if (!ContainsNode(nodeDefinition))
						{
							if (_log.IsInfoEnabled)
								_log.InfoFormat("Node {0} is defined in the new config but does not exist in this cluster in group {1}, rebuilding.",
									nodeDefinition, _nodeGroup.GroupName);
							rebuild = true;
							break;
						}
					}
				}
			}

			if (rebuild)
			{				
				Dictionary<ushort, List<Node>> newZoneNodes = new Dictionary<ushort, List<Node>>();		
				List<Node> newNodes = new List<Node>();

				RelayNodeDefinition meDefinition = newConfig.GetMyNode();
				DispatcherQueue nodeInQueue, nodeOutQueue;
				
				if (meDefinition != null)
				{                    
					GetMessageQueuesFor(meDefinition, relayNodeClusterDefinition,
						NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher,
						out nodeInQueue, out nodeOutQueue);
					//Me is in the new config
					//Either create it new or overwrite the old one					
					Me = new Node(meDefinition, _nodeGroup, this, forwardingConfig, 
						nodeInQueue, nodeOutQueue);

				}
				else
				{
					//me is NOT in the new config.
					Me = null;
				}
				ushort maxDetectedZone = _localZone;
				foreach (RelayNodeDefinition nodeDefinition in relayNodeClusterDefinition.RelayNodes)
				{					
					if (nodeDefinition != meDefinition)
					{
						GetMessageQueuesFor(nodeDefinition, relayNodeClusterDefinition,
						NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher,
						out nodeInQueue, out nodeOutQueue);

						Node node = new Node(nodeDefinition, _nodeGroup, this, forwardingConfig,
							nodeInQueue, nodeOutQueue);

						newNodes.Add(node);
						if (node.DetectedZone > maxDetectedZone)
						{
							maxDetectedZone = node.DetectedZone;
						}
						if (node.Zone > maxDetectedZone)
						{
							maxDetectedZone = node.Zone;
						}
						if (!newZoneNodes.ContainsKey(nodeDefinition.Zone))
						{
							newZoneNodes[nodeDefinition.Zone] = new List<Node>();
						}

						newZoneNodes[nodeDefinition.Zone].Add(node);

					}
				}
				Nodes = newNodes;
				ZoneNodes = newZoneNodes;
				_nodesByNumberOfHops = CalculateTopography(Nodes, MaximumHops);                
				_nodeLayers = CalculateNodeLayers(_nodesByNumberOfHops, NodeSelectionHopWindowSize);
				_nodesByDetectedZone = CalculateNodesByDetectedZone(Nodes, maxDetectedZone);
				lock (_chooseLock)
				{
					ChosenNode = null;
				}
				ChosenZoneNodes = new Dictionary<ushort, Node>();
			}
			else
			{	
				//just reload the configs to get any new network or queue settings
				bool hitMe = false;
				string meString = String.Empty;
				if (Me != null)
				{
					meString = Me.ToString();
				}
				for (int i = 0; i < relayNodeClusterDefinition.RelayNodes.Length; i++)
				{
					string definitionString = relayNodeClusterDefinition.RelayNodes[i].Host + ":" + relayNodeClusterDefinition.RelayNodes[i].Port;
					if (definitionString == meString)
					{
						hitMe = true;
						Me.ReloadMapping(relayNodeClusterDefinition.RelayNodes[i], forwardingConfig);
					}
					else
					{						
						Nodes[(hitMe ? i - 1 : i)].ReloadMapping(relayNodeClusterDefinition.RelayNodes[i],forwardingConfig);						
					}
				}
				lock (_chooseLock)
				{
					ChosenNode = null;
				}
			}
		}
Beispiel #17
0
		/// <summary>
		/// this (or <see cref="LoadConfig"/>) gets called (depending) when the TypeSettings.Config file
		/// are changed.  
		/// </summary>
		/// <remarks>
		/// Added: craigbro
		/// cachedTypeSettings now held with the forwarder for reference of
		/// exceptions on Synchronous "in" messages.  
		/// To reload, we just null out the cached TypeSettingsCollection object and the
		/// accessor will reload it on next call
		/// While ConfigurationManager.GetSection is quite performant after the 1st hit,
		/// keeping them cached is about twice as fast.		
		/// </remarks>
		/// <param name="config">The config to reload</param>
		public void ReloadConfig(RelayNodeConfig config)
		{
			lock (_reloadLock)
			{
				if (config != null)
				{
					try
					{
						object configObject = config.RelayComponents.GetConfigFor(GetComponentName());
						ForwardingConfig forwardingConfig = configObject as ForwardingConfig;
						if (forwardingConfig == null)
						{
							if(_log.IsInfoEnabled)
							{
								_log.InfoFormat("No forwarding configuration supplied. Reloading using defaults.");
							}
							forwardingConfig = new ForwardingConfig();
						}
						NodeManager.Instance.ReloadConfig(config, forwardingConfig);
						
						_enableAsyncBulkGets = forwardingConfig.EnableAsyncBulkGets;
						_myNodeDefinition = NodeManager.Instance.GetMyNodeDefinition();

						short maxTypeId = 0;
						if (config.TypeSettings != null)
						{
							maxTypeId = config.TypeSettings.MaxTypeId;
						}
						DebugWriter.SetTraceSettings(maxTypeId, forwardingConfig.TraceSettings);
						DebugWriter.WriteCallingMethod = forwardingConfig.WriteCallingMethod;
						DebugWriter.WriteMessageTrace = forwardingConfig.WriteMessageTrace;
					}
					catch (Exception ex)
					{
						if (_log.IsErrorEnabled)
							_log.ErrorFormat("Exception reloading config: {0}", ex);
					}
				}
			}
		}
		internal NodeGroupCollection(RelayNodeGroupDefinitionCollection groupDefinitions, RelayNodeConfig nodeConfig, ForwardingConfig forwardingConfig) : base()
		{
			foreach (RelayNodeGroupDefinition groupDefinition in groupDefinitions)
			{
				Add(new NodeGroup(groupDefinition, nodeConfig, forwardingConfig));
			}
		}
        internal NodeGroupCollection(IEnumerable <RelayNodeGroupDefinition> groupDefinitions, RelayNodeConfig nodeConfig, ForwardingConfig forwardingConfig)
        {
            foreach (RelayNodeGroupDefinition groupDefinition in groupDefinitions)
            {
                Add(new NodeGroup(groupDefinition, nodeConfig, forwardingConfig));
            }

            _groupsByTypeId = GenerateGroupsByTypeId(nodeConfig.TypeSettings);
        }
		internal NodeCluster(RelayNodeClusterDefinition clusterDefinition, RelayNodeConfig nodeConfig, NodeGroup nodeGroup, ForwardingConfig forwardingConfig)
		{
			_nodeGroup = nodeGroup;
			_clusterDefinition = clusterDefinition;
			_minimumId = clusterDefinition.MinId;
			_maximumId = clusterDefinition.MaxId;
			NodeSelectionHopWindowSize = nodeGroup.NodeSelectionHopWindowSize;
			RelayNodeDefinition meDefinition = nodeConfig.GetMyNode();
			_meInThisCluster = false;
			_mapNetwork = forwardingConfig.MapNetwork;
			_localZone = nodeConfig.GetLocalZone();
			_zoneDefinitions = nodeConfig.RelayNodeMapping.ZoneDefinitions;
			foreach (RelayNodeDefinition nodeDefinition in clusterDefinition.RelayNodes)
			{
				if (meDefinition == nodeDefinition)
				{
					_meInThisCluster = true;
				}
			}
			
			DispatcherQueue nodeInQueue, nodeOutQueue;

			if (_meInThisCluster)
			{
				GetMessageQueuesFor(meDefinition, clusterDefinition,
					NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher,
					out nodeInQueue, out nodeOutQueue);

				Me = new Node(meDefinition, nodeGroup, this, forwardingConfig,
						nodeInQueue, nodeOutQueue);
			}			

			ushort maxDetectedZone = _localZone;
			foreach (RelayNodeDefinition nodeDefinition in clusterDefinition.RelayNodes)
			{
				if (nodeDefinition != meDefinition)
				{
					GetMessageQueuesFor(nodeDefinition, clusterDefinition,
						NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher,
						out nodeInQueue, out nodeOutQueue);
					Node node = new Node(nodeDefinition, nodeGroup, this, forwardingConfig,
						nodeInQueue, nodeOutQueue);

					Nodes.Add(node);

					if (node.DetectedZone > maxDetectedZone)
					{
						maxDetectedZone = node.DetectedZone;
					}
					if (node.Zone > maxDetectedZone)
					{
						maxDetectedZone = node.Zone;
					}

					if (!ZoneNodes.ContainsKey(nodeDefinition.Zone))
					{
						ZoneNodes[nodeDefinition.Zone] = new List<Node>();
					}

					ZoneNodes[nodeDefinition.Zone].Add(node);
				}				
			}

			_nodesByNumberOfHops = CalculateTopography(Nodes, MaximumHops);
			_nodeLayers = CalculateNodeLayers(_nodesByNumberOfHops, NodeSelectionHopWindowSize);
			_nodesByDetectedZone = CalculateNodesByDetectedZone(Nodes, maxDetectedZone);
		}
        internal void ReloadConfig(RelayNodeConfig config, ForwardingConfig newForwardingConfig)
        {
            if (config.RelayNodeMapping == null)
            {
                if (_log.IsErrorEnabled)
                {
                    _log.Error("Got new config with no defined groups.");
                }
            }
            else
            {
                if (config.RelayNodeMapping.Validate())
                {
                    _zoneDefinitions = config.RelayNodeMapping.ZoneDefinitions;                         //make sure this is set before reloading the mapping so any changes propogate
                    Dictionary <string, Dictionary <string, MessageQueue> > errorQueues = GetErrorQueues();
                    NodeGroups.ReloadMapping(config, newForwardingConfig);
                    //note that if a node changes groups, the error queue won't make it!
                    NodeGroups.PopulateQueues(errorQueues, false);
                }
                else
                {
                    if (_log.IsErrorEnabled)
                    {
                        _log.Error("Forwarder not reloading invalid config.");
                    }
                }
            }

            Config = config;

            _myNodeDefinition = GetMyNodeDefinition();
            bool doNewInDispatcher, doNewOutDispatcher;

            if (newForwardingConfig.NumberOfThreads != ForwardingConfig.NumberOfThreads)
            {
                doNewInDispatcher = true;
            }
            else
            {
                doNewInDispatcher = false;
            }
            if (newForwardingConfig.NumberOfOutMessageThreads != ForwardingConfig.NumberOfOutMessageThreads)
            {
                doNewOutDispatcher = true;
            }
            else
            {
                doNewOutDispatcher = false;
            }


            if (doNewInDispatcher || doNewOutDispatcher)
            {
                Dispatcher oldInDispatcher = null, newInDispatcher, oldOutDispatcher = null, newOutDispatcher;

                if (doNewInDispatcher)
                {
                    if (_log.IsInfoEnabled)
                    {
                        _log.InfoFormat("Changing number of messaging threads from {0} to {1}", ForwardingConfig.NumberOfThreads, newForwardingConfig.NumberOfThreads);
                    }
                    oldInDispatcher = InMessageDispatcher;
                    newInDispatcher = new Dispatcher(newForwardingConfig.NumberOfThreads, ThreadPriority.Normal, true, "Relay Forwarder");
                }
                else
                {
                    newInDispatcher = InMessageDispatcher;
                }
                if (doNewOutDispatcher)
                {
                    if (_log.IsInfoEnabled)
                    {
                        _log.InfoFormat("Changing number of out message threads from {0} to {1}", ForwardingConfig.NumberOfOutMessageThreads, newForwardingConfig.NumberOfOutMessageThreads);
                    }
                    oldOutDispatcher = OutMessageDispatcher;
                    newOutDispatcher = new Dispatcher(newForwardingConfig.NumberOfOutMessageThreads, ThreadPriority.Normal, true, "Relay Forwarder");
                }
                else
                {
                    newOutDispatcher = OutMessageDispatcher;
                }

                InMessageDispatcher  = newInDispatcher;
                OutMessageDispatcher = newOutDispatcher;

                NodeGroups.SetNewDispatchers(newInDispatcher, newOutDispatcher);

                ForwardingConfig = newForwardingConfig;

                if (doNewInDispatcher)
                {
                    if (_log.IsInfoEnabled)
                    {
                        _log.Info("Disposing old in message Dispatcher");
                    }
                    oldInDispatcher.Dispose();
                }
                if (doNewOutDispatcher)
                {
                    if (_log.IsInfoEnabled)
                    {
                        _log.Info("Disposing old out message Dispatcher");
                    }
                    oldOutDispatcher.Dispose();
                }
            }
            else
            {
                ForwardingConfig = newForwardingConfig;
            }
        }
Beispiel #22
0
        internal NodeCluster(RelayNodeClusterDefinition clusterDefinition, RelayNodeConfig nodeConfig, NodeGroup nodeGroup, ForwardingConfig forwardingConfig)
        {
            _nodeGroup                 = nodeGroup;
            _clusterDefinition         = clusterDefinition;
            _minimumId                 = clusterDefinition.MinId;
            _maximumId                 = clusterDefinition.MaxId;
            NodeSelectionHopWindowSize = nodeGroup.NodeSelectionHopWindowSize;
            RelayNodeDefinition meDefinition = nodeConfig.GetMyNode();

            _meInThisCluster = false;
            _mapNetwork      = forwardingConfig.MapNetwork;
            _localZone       = nodeConfig.GetLocalZone();
            _zoneDefinitions = nodeConfig.RelayNodeMapping.ZoneDefinitions;
            foreach (RelayNodeDefinition nodeDefinition in clusterDefinition.RelayNodes)
            {
                if (meDefinition == nodeDefinition)
                {
                    _meInThisCluster = true;
                }
            }

            DispatcherQueue nodeInQueue, nodeOutQueue;

            if (_meInThisCluster)
            {
                GetMessageQueuesFor(meDefinition, clusterDefinition,
                                    NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher,
                                    out nodeInQueue, out nodeOutQueue);

                Me = new Node(meDefinition, nodeGroup, this, forwardingConfig,
                              nodeInQueue, nodeOutQueue);
            }

            ushort maxDetectedZone = _localZone;

            foreach (RelayNodeDefinition nodeDefinition in clusterDefinition.RelayNodes)
            {
                if (nodeDefinition != meDefinition)
                {
                    GetMessageQueuesFor(nodeDefinition, clusterDefinition,
                                        NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher,
                                        out nodeInQueue, out nodeOutQueue);
                    Node node = new Node(nodeDefinition, nodeGroup, this, forwardingConfig,
                                         nodeInQueue, nodeOutQueue);

                    Nodes.Add(node);

                    if (node.DetectedZone > maxDetectedZone)
                    {
                        maxDetectedZone = node.DetectedZone;
                    }
                    if (node.Zone > maxDetectedZone)
                    {
                        maxDetectedZone = node.Zone;
                    }

                    if (!ZoneNodes.ContainsKey(nodeDefinition.Zone))
                    {
                        ZoneNodes[nodeDefinition.Zone] = new List <Node>();
                    }

                    ZoneNodes[nodeDefinition.Zone].Add(node);
                }
            }

            _nodesByNumberOfHops = CalculateTopography(Nodes, MaximumHops);
            _nodeLayers          = CalculateNodeLayers(_nodesByNumberOfHops, NodeSelectionHopWindowSize);
            _nodesByDetectedZone = CalculateNodesByDetectedZone(Nodes, maxDetectedZone);
        }
Beispiel #23
0
        internal void ReloadMapping(RelayNodeClusterDefinition relayNodeClusterDefinition, RelayNodeConfig newConfig, ForwardingConfig forwardingConfig)
        {
            _minimumId  = relayNodeClusterDefinition.MinId;
            _maximumId  = relayNodeClusterDefinition.MaxId;
            _mapNetwork = forwardingConfig.MapNetwork;

            //figure out if anything changed. if it did, rebuild

            bool rebuild = false;

            ushort newLocalZone = newConfig.GetLocalZone();

            if (newLocalZone != _localZone)
            {
                rebuild    = true;
                _localZone = newLocalZone;
            }
            else
            {
                if ((_zoneDefinitions == null && newConfig.RelayNodeMapping.ZoneDefinitions != null) ||
                    (_zoneDefinitions != null && newConfig.RelayNodeMapping.ZoneDefinitions == null) ||
                    (_zoneDefinitions != null && !_zoneDefinitions.Equals(newConfig.RelayNodeMapping.ZoneDefinitions)))
                {
                    rebuild          = true;
                    _zoneDefinitions = newConfig.RelayNodeMapping.ZoneDefinitions;
                }
            }


            int effectiveSize = (!_meInThisCluster ? Nodes.Count : Nodes.Count + 1);

            //if there's a different number of nodes, we definitely have to rebuild
            if (relayNodeClusterDefinition.RelayNodes.Length != effectiveSize)
            {
                if (_log.IsInfoEnabled)
                {
                    _log.InfoFormat("Number of nodes in a cluster in group {0} changed from {1} to {2}, rebuilding", _nodeGroup.GroupName, effectiveSize, relayNodeClusterDefinition.RelayNodes.Length);
                }
                rebuild = true;
            }
            else
            {
                //if any of the nodes we do have aren't in the config, rebuild
                foreach (Node node in Nodes)
                {
                    if (!relayNodeClusterDefinition.ContainsNode(node.EndPoint.Address, node.EndPoint.Port))
                    {
                        if (_log.IsInfoEnabled)
                        {
                            _log.InfoFormat("Node {0} is no longer found in its cluster in group {1}, rebuilding.",
                                            node, _nodeGroup.GroupName);
                        }
                        rebuild = true;
                        break;
                    }
                }
                if (!rebuild && _nodeGroup.NodeSelectionHopWindowSize != NodeSelectionHopWindowSize)
                {
                    NodeSelectionHopWindowSize = _nodeGroup.NodeSelectionHopWindowSize;
                    rebuild = true;
                }

                if (!rebuild && _meInThisCluster)
                {
                    if (!relayNodeClusterDefinition.ContainsNode(Me.EndPoint.Address, Me.EndPoint.Port))
                    {
                        if (_log.IsInfoEnabled)
                        {
                            _log.InfoFormat("Node {0} (this machine) is no longer found in its cluster in group {1}, rebuilding.",
                                            Me, _nodeGroup.GroupName);
                        }
                        rebuild = true;
                    }
                }

                //or if there are any nodes in the config that aren't here, rebuild
                if (!rebuild)
                {
                    foreach (RelayNodeDefinition nodeDefinition in relayNodeClusterDefinition.RelayNodes)
                    {
                        if (!ContainsNode(nodeDefinition))
                        {
                            if (_log.IsInfoEnabled)
                            {
                                _log.InfoFormat("Node {0} is defined in the new config but does not exist in this cluster in group {1}, rebuilding.",
                                                nodeDefinition, _nodeGroup.GroupName);
                            }
                            rebuild = true;
                            break;
                        }
                    }
                }
            }

            if (rebuild)
            {
                Dictionary <ushort, List <Node> > newZoneNodes = new Dictionary <ushort, List <Node> >();
                List <Node> newNodes = new List <Node>();

                RelayNodeDefinition meDefinition = newConfig.GetMyNode();
                DispatcherQueue     nodeInQueue, nodeOutQueue;

                if (meDefinition != null)
                {
                    GetMessageQueuesFor(meDefinition, relayNodeClusterDefinition,
                                        NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher,
                                        out nodeInQueue, out nodeOutQueue);
                    //Me is in the new config
                    //Either create it new or overwrite the old one
                    Me = new Node(meDefinition, _nodeGroup, this, forwardingConfig,
                                  nodeInQueue, nodeOutQueue);
                }
                else
                {
                    //me is NOT in the new config.
                    Me = null;
                }
                ushort maxDetectedZone = _localZone;
                foreach (RelayNodeDefinition nodeDefinition in relayNodeClusterDefinition.RelayNodes)
                {
                    if (nodeDefinition != meDefinition)
                    {
                        GetMessageQueuesFor(nodeDefinition, relayNodeClusterDefinition,
                                            NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher,
                                            out nodeInQueue, out nodeOutQueue);

                        Node node = new Node(nodeDefinition, _nodeGroup, this, forwardingConfig,
                                             nodeInQueue, nodeOutQueue);

                        newNodes.Add(node);
                        if (node.DetectedZone > maxDetectedZone)
                        {
                            maxDetectedZone = node.DetectedZone;
                        }
                        if (node.Zone > maxDetectedZone)
                        {
                            maxDetectedZone = node.Zone;
                        }
                        if (!newZoneNodes.ContainsKey(nodeDefinition.Zone))
                        {
                            newZoneNodes[nodeDefinition.Zone] = new List <Node>();
                        }

                        newZoneNodes[nodeDefinition.Zone].Add(node);
                    }
                }
                Nodes                = newNodes;
                ZoneNodes            = newZoneNodes;
                _nodesByNumberOfHops = CalculateTopography(Nodes, MaximumHops);
                _nodeLayers          = CalculateNodeLayers(_nodesByNumberOfHops, NodeSelectionHopWindowSize);
                _nodesByDetectedZone = CalculateNodesByDetectedZone(Nodes, maxDetectedZone);
                lock (_chooseLock)
                {
                    ChosenNode = null;
                }
                ChosenZoneNodes = new Dictionary <ushort, Node>();
            }
            else
            {
                //just reload the configs to get any new network or queue settings
                bool   hitMe    = false;
                string meString = String.Empty;
                if (Me != null)
                {
                    meString = Me.ToString();
                }
                for (int i = 0; i < relayNodeClusterDefinition.RelayNodes.Length; i++)
                {
                    string definitionString = relayNodeClusterDefinition.RelayNodes[i].Host + ":" + relayNodeClusterDefinition.RelayNodes[i].Port;
                    if (definitionString == meString)
                    {
                        hitMe = true;
                        Me.ReloadMapping(relayNodeClusterDefinition.RelayNodes[i], forwardingConfig);
                    }
                    else
                    {
                        Nodes[(hitMe ? i - 1 : i)].ReloadMapping(relayNodeClusterDefinition.RelayNodes[i], forwardingConfig);
                    }
                }
                lock (_chooseLock)
                {
                    ChosenNode = null;
                }
            }
        }
Beispiel #24
0
        internal NodeCluster(RelayNodeClusterDefinition clusterDefinition, RelayNodeConfig nodeConfig, NodeGroup nodeGroup, ForwardingConfig forwardingConfig)
        {
            _nodeGroup         = nodeGroup;
            _clusterDefinition = clusterDefinition;
            _minimumId         = clusterDefinition.MinId;
            _maximumId         = clusterDefinition.MaxId;

            RelayNodeDefinition meDefinition = nodeConfig.GetMyNode();

            _meInThisCluster = false;

            _localZone       = nodeConfig.GetLocalZone();
            _zoneDefinitions = nodeConfig.RelayNodeMapping.ZoneDefinitions;
            foreach (RelayNodeDefinition nodeDefinition in clusterDefinition.RelayNodes)
            {
                if (meDefinition == nodeDefinition)
                {
                    _meInThisCluster = true;
                }
            }

            DispatcherQueue nodeInQueue, nodeOutQueue;

            if (_meInThisCluster)
            {
                GetMessageQueuesFor(GetMessageQueueNameFor(meDefinition), clusterDefinition,
                                    NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher,
                                    out nodeInQueue, out nodeOutQueue);

                Me = new Node(meDefinition, nodeGroup, this, forwardingConfig,
                              nodeInQueue, nodeOutQueue);
            }

            ushort maxDetectedZone = _localZone;

            foreach (RelayNodeDefinition nodeDefinition in clusterDefinition.RelayNodes)
            {
                if (nodeDefinition != meDefinition)
                {
                    GetMessageQueuesFor(GetMessageQueueNameFor(nodeDefinition), clusterDefinition,
                                        NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher,
                                        out nodeInQueue, out nodeOutQueue);
                    Node node = new Node(nodeDefinition, nodeGroup, this, forwardingConfig,
                                         nodeInQueue, nodeOutQueue);

                    Nodes.Add(node);

                    if (node.Zone > maxDetectedZone)
                    {
                        maxDetectedZone = node.Zone;
                    }
                }
            }

            _nodesByZone = CalculateNodesByZone(Nodes, maxDetectedZone);
        }
Beispiel #25
0
		internal void ReloadMapping(RelayNodeGroupDefinition groupDefinition, RelayNodeConfig newConfig, ForwardingConfig newForwardingConfig)
		{
			RelayNodeClusterDefinition myClusterDefinition = newConfig.GetMyCluster();
			Activated = groupDefinition.Activated;
			GroupDefinition = groupDefinition;
			_clusterByRange = groupDefinition.UseIdRanges;
			_forwardingConfig = newForwardingConfig;
			NodeSelectionHopWindowSize = groupDefinition.NodeSelectionHopWindowSize;
			if (groupDefinition.RelayNodeClusters.Length == Clusters.Count)
			{
				//same number of clusters, just let the clusters rebuild themselves. the clusters will entirely rebuild, so shuffinling around servers should be okay
				if (_log.IsInfoEnabled)
					_log.InfoFormat("Rebuilding existing clusters in group {0}.", groupDefinition.Name);
				for (int i = 0; i < groupDefinition.RelayNodeClusters.Length; i++)
				{
					Clusters[i].ReloadMapping(groupDefinition.RelayNodeClusters[i], newConfig, newForwardingConfig);
					if (groupDefinition.RelayNodeClusters[i] == myClusterDefinition)
					{
						MyCluster = Clusters[i];
					}
				}
				if (myClusterDefinition == null && MyCluster != null)
				{
					if (_log.IsInfoEnabled)
						_log.InfoFormat("Group {0} no longer contains this server. Removing.", GroupName);
					//this group no longer contains "me". If it DID contain "me", it would've been set above.
					MyCluster = null;
				}
			}
			else
			{
				//build new clusters and replace the existing ones with them
				if (_log.IsInfoEnabled)
					_log.InfoFormat("Number of clusters in group {0} changed, rebuilding.", groupDefinition.Name);
				NodeCluster myCluster = null;
				List<NodeCluster> newClusters = new List<NodeCluster>();
				foreach (RelayNodeClusterDefinition clusterDefintion in groupDefinition.RelayNodeClusters)
				{
					NodeCluster nodeCluster = new NodeCluster(clusterDefintion, newConfig, this, newForwardingConfig);
					if (clusterDefintion == myClusterDefinition)
					{
						myCluster = nodeCluster;
					}
					newClusters.Add(nodeCluster);
				}
				Clusters = newClusters;
				MyCluster = myCluster;
			}
			_nodeReselectTimer.Change(NodeReselectIntervalMilliseconds, NodeReselectIntervalMilliseconds);
		}
Beispiel #26
0
		internal void ReloadMapping(RelayNodeDefinition relayNodeDefinition, ForwardingConfig forwardingConfig)
		{
			NodeDefinition = relayNodeDefinition;
			Interlocked.Exchange(ref _messageBurstLength, forwardingConfig.MessageBurstLength);
			Interlocked.Exchange(ref _messageBurstTimeout, forwardingConfig.MessageBurstTimeout);
			_repostMessageLists = forwardingConfig.RepostMessageLists;
			if (EndPoint != null)
			{
				DetectedZone = NodeManager.Instance.GetZoneForAddress(EndPoint.Address);
			}
			else
			{
				DetectedZone = 0;
			}
			_messageBurstTimeoutSpan = TimeSpan.FromMilliseconds(_messageBurstTimeout);

			if (MessageErrorQueue == null)
			{
				MessageErrorQueue = new MessageQueue(NodeGroup.GetQueueConfig());
			}
			else
			{
				MessageErrorQueue.ReloadConfig(NodeGroup.GetQueueConfig());
			}

			SocketTransportAdapter socketTransport = _transport as SocketTransportAdapter;

			if (socketTransport != null)
			{
				socketTransport.LoadSettings(NodeDefinition, NodeGroup.GroupDefinition);
			}

			//changes in other forwarding settings are handled by the nodemanager using the Set & Start NewDispatcher methods.		
		}