예제 #1
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);
     }
 }
예제 #2
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);
                 }
             }
         }
     }
 }
예제 #3
0
        private static LinkedListStack <Node> PrepareMessage(RelayMessage message)
        {
            LinkedListStack <Node> nodes = NodeManager.Instance.GetNodesForMessage(message);

            message.RelayTTL--;
            SetHydrationPolicy(message);

            if (nodes.Count > 0)
            {
                System.Net.IPAddress myAddress = NodeManager.Instance.MyIpAddress;
                if (myAddress != null)
                {
                    message.AddAddressToHistory(myAddress);
                }
            }

            DebugWriter.WriteDebugInfo(message, nodes);
            return(nodes);
        }
예제 #4
0
        private SimpleLinkedList <Node> PrepareMessage(RelayMessage message, bool isRetry)
        {
            if (isRetry)
            {
                message.RelayTTL++;
            }
            SimpleLinkedList <Node> nodes = NodeManager.Instance.GetNodesForMessage(message);

            message.RelayTTL--;
            SetHydrationPolicy(message);

            if (nodes.Count > 0 && !isRetry)
            {
                System.Net.IPAddress myAddress = NodeManager.Instance.MyIpAddress;
                if (myAddress != null)
                {
                    message.AddressHistory.Add(myAddress);
                }
            }
            DebugWriter.WriteDebugInfo(message, nodes);
            return(nodes);
        }
        /// <summary>
        /// Splits messages into various lists of in and out message destined for different nodes.
        /// </summary>
        /// <param name="messages"></param>
        /// <returns></returns>
        internal NodeWithMessagesCollection DistributeMessages(IList <RelayMessage> messages)
        {
            NodeWithMessagesCollection distribution = new NodeWithMessagesCollection();
            RelayMessage message;
            Node         node;

            for (int i = 0; i < messages.Count; i++)
            {
                if (messages[i] != null)
                {
                    message = messages[i];

                    RelayMessage interZoneMessage = null;

                    SimpleLinkedList <Node> nodesForMessage          = GetNodesForMessage(message);
                    SimpleLinkedList <Node> nodesForInterZoneMessage = null;

                    if (nodesForMessage.Count > 0)
                    {
                        message.AddressHistory.Add(MyIpAddress);
                    }
                    message.RelayTTL--;

                    #region Identify InterZone Messages
                    if (message.IsTwoWayMessage == false)
                    {
                        message.ResultOutcome = RelayOutcome.Queued;                         //will be queued, if sync will not get overwritten

                        // Identify nodes in foreign zones
                        int nodeCount = nodesForMessage.Count;
                        for (int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
                        {
                            nodesForMessage.Pop(out node);
                            if (_myNodeDefinition != null && _myNodeDefinition.Zone != node.NodeDefinition.Zone)
                            {
                                // Message needs to cross Zone bounderies
                                if (interZoneMessage == null)
                                {
                                    interZoneMessage         = RelayMessage.CreateInterZoneMessageFrom(message);
                                    nodesForInterZoneMessage = new SimpleLinkedList <Node>();
                                }
                                nodesForInterZoneMessage.Push(node);
                            }
                            else
                            {
                                nodesForMessage.Push(node);
                            }
                        }
                    }
                    #endregion

                    if (nodesForMessage.Count > 0)
                    {
                        DebugWriter.WriteDebugInfo(message, nodesForMessage);
                        distribution.Add(message, nodesForMessage);
                    }

                    if (nodesForInterZoneMessage != null && nodesForInterZoneMessage.Count > 0)
                    {
                        DebugWriter.WriteDebugInfo(interZoneMessage, nodesForInterZoneMessage);
                        distribution.Add(interZoneMessage, nodesForInterZoneMessage);
                    }
                }
            }

            return(distribution);
        }