Ejemplo n.º 1
0
		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);
		}
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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(); }));
		}
Ejemplo n.º 5
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);
		}