Ejemplo n.º 1
0
        internal short SetWaitHandle(int waitTimeout)
        {
            //this uses GetNextMessageId to generate new ids, but also reuses ids as much as possible. This VASTLY reduces the number of replybuckets needed.
            ResourcePoolItem <short> idItem = idPool.GetItem();
            short       waitId = idItem.Item;
            ReplyBucket bucket = null;

            if (!replies.ContainsKey(waitId)) //we haven't used this waitId yet
            {
                replyLock.Write(() =>
                {
                    if (!replies.ContainsKey(waitId))
                    {
                        if (Log.IsDebugEnabled)
                        {
                            Log.DebugFormat("SetWaitHandle() Creates new ReplyBucket.");
                        }
                        replies.Add(waitId, new ReplyBucket());
                    }
                });
            }

            replyLock.Read(() => { bucket = replies[waitId]; });

            bucket.SetValues(waitTimeout, ReplyEvent, idItem);

            return(waitId);
        }
Ejemplo n.º 2
0
        internal void AggregateCounterTicker()
        {
            int count = _serverDownCounter.Tick();

            if (count != -1)
            {
                _serverDownErrorsLast30Seconds = _serverDownCounter.Tick();
            }
            else
            {
                if (logger.IsDebugEnabled)
                {
                    logger.DebugFormat("Node {0} tried to tick its aggregate counters simultaneously!", this);
                }
            }

            count = _serverUnreachableCounter.Tick();
            if (count != -1)
            {
                _serverUnreachableErrorsLast2WaitPeriods = _serverUnreachableCounter.Tick();
            }
            else
            {
                if (logger.IsDebugEnabled)
                {
                    logger.DebugFormat("Node {0} tried to tick its aggregate counters simultaneously!", this);
                }
            }
        }
Ejemplo n.º 3
0
 internal void ReleaseWait()
 {
     if (Log.IsDebugEnabled)
     {
         Log.DebugFormat("[{0}] {1}: {2}:ReleaseWait() Reply Recieved");
     }
     waitHandle.Set();
 }
Ejemplo n.º 4
0
        private static void FrequencyBoundLogDebug(string message)
        {
            ParameterlessDelegate logDelegate;

            if (!_errorLogDelegates.TryGetValue(message, out logDelegate))
            {
                lock (ErrorLogSync)
                {
                    if (!_errorLogDelegates.TryGetValue(message, out logDelegate))
                    {
                        var errorDelegates = new Dictionary <string, ParameterlessDelegate>(_errorLogDelegates);
                        logDelegate = Algorithm.FrequencyBoundMethod(
                            count =>
                        {
                            if (count > 1)
                            {
                                log.DebugFormat("{0} occurances: {1}", count + 1, message);
                            }
                            else
                            {
                                log.Debug(message);
                            }
                        }
                            , TimeSpan.FromMinutes(1));

                        errorDelegates[message] = logDelegate;
                        Interlocked.Exchange(ref _errorLogDelegates, errorDelegates);
                    }
                }
            }
            logDelegate();
        }
Ejemplo n.º 5
0
        public void Debug_1Arg_Fact()
        {
            _wrapper.DebugFormat("This is a {0}", "Fact");

            _eventArgs.Should().NotBeNull();
            _eventArgs.Name.Should().Be("This is a Fact");
            _eventArgs.Level.Should().Be(LogLevel.Debug);
        }
Ejemplo n.º 6
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.º 7
0
        public void Post(RelayMessage message, short waitId)
        {
            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Post() Port posts message to DispatcherQueue '{0}' (TypeId={1}, MessageId={2})"
                                , dispatcherQueue.Name, message.TypeId, message.Id);
            }
            QueueItem queueItem = new QueueItem();

            queueItem.WaitId  = waitId;
            queueItem.Message = message;
            messagePort.Post(queueItem);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Handles the case when the Assembly Directory's contents changes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AssemblyDirChanged(object sender, FileSystemEventArgs e)
        {
            if (!_reloadOnAssemblyChanges)
            {
                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("File {0} changed but reloads are disabled.", e.Name);
                }
                return;
            }

            if (!FileCausesRestart(e.Name))
            {
                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Ignored file {0} changed", e.Name);
                }
                return;
            }

            string thisMinute = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString();

            lock (_resourceLock)
            {
                if (_log.IsInfoEnabled)
                {
                    if (_pendingAssemblyFileNames.Add(e.Name) == false) //returns false if the item didn't already exist
                    {
                        _log.InfoFormat(
                            "Got change for {0} during {1}. Processing {2} seconds after the last file change hasn't occured for {2} seconds",
                            e.Name,
                            thisMinute,
                            _reloadWindowSeconds);
                    }
                }
                _currentFileSetChangeTime = DateTime.UtcNow;
            }
        }
Ejemplo n.º 9
0
        public void Initialize(string instanceName)
        {
            if (!PerformanceCounterCategory.Exists(PerformanceCategoryName))
            {
                CreatePerformanceCounterCategory();
            }
            BdbInstanceInfo bdbInstanceInfo;

            if (Instances.TryGetValue(instanceName, out bdbInstanceInfo))
            {
                Log.Info("Performance counters instance " + instanceName + " is already exists, instance will not be re-initialized.");
            }
            else
            {
                try
                {
                    bdbInstanceInfo = new BdbInstanceInfo();
                    int numCounters = PerformanceCounterNames.Length;
                    bdbInstanceInfo.counters = new PerformanceCounter[numCounters];
                    for (int i = 0; i < numCounters; i++)
                    {
                        bdbInstanceInfo.counters[i] = new PerformanceCounter(
                            PerformanceCategoryName,
                            PerformanceCounterNames[i],
                            instanceName,
                            false
                            );
                    }

                    bdbInstanceInfo.getHitCounter      = new MinuteAggregateCounter();
                    bdbInstanceInfo.getAttemptCounter  = new MinuteAggregateCounter();
                    bdbInstanceInfo.saveHitCounter     = new MinuteAggregateCounter();
                    bdbInstanceInfo.saveAttemptCounter = new MinuteAggregateCounter();

                    Instances.Add(instanceName, bdbInstanceInfo);

                    ResetCounters(bdbInstanceInfo.counters);
                    StartTimer();
                }
                catch (Exception ex)
                {
                    if (Log.IsErrorEnabled)
                    {
                        Log.ErrorFormat("BerkeleyDbCounters:Initialize() Exception creating Memory Store Counters: {0}. The counters might need to be reinstalled via InstallUtil."
                                        , ex);
                    }
                }
                Log.DebugFormat("Performance counters instance {0} initialized.", instanceName);
            }
        }
Ejemplo n.º 10
0
        private PerformanceCounter TryCreateCounter(string name)
        {
            if (!IsInitialized)
            {
                throw new InvalidOperationException("This PerfCounter instance has not been initialized");
            }
            try
            {
                if (!PerformanceCounterCategory.Exists(CategoryName))
                {
                    // the category doesn't exist.  This means that the counters were never installed, or previous errors have occurred.
                    return(null);
                }
                if (!PerformanceCounterCategory.CounterExists(name, CategoryName))
                {
                    // the category exists, but the counter does not.
                    return(null);
                }

                return(new PerformanceCounter(CategoryName, name, InstanceName, false));
            }
            catch (InvalidOperationException ioex)
            {
                // Counter not installed.
                Log.DebugFormat(
                    "PerfCounter {0} of {1} in {2} could not be initialized, and will not be available. {3}", name,
                    InstanceName, CategoryName, ioex);
            }
            catch (UnauthorizedAccessException uae)
            {
                // if the account doesn't have privileges to use counters, this exception is thrown.  The account has to be in the
                // Perfmormance Monitor Users group or be admin.
                Log.DebugFormat("The process does not have the privilege to initialze PerfCounter {0} of {1} in {2}. {3}", name, InstanceName, CategoryName, uae);
            }
            return(null);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// debug
 /// </summary>
 /// <param name="info"></param>
 public static void DebugFormat(string info, params object[] args)
 {
     _log.DebugFormat(info, args);
 }