Example #1
0
        /// <summary>
        /// Default constructor for the Router class
        /// </summary>
        public Router()
        {
            CounterCreationDataCollection CCDC;

            categoryName = "WspEventRouter";
            communicationCategoryName = "WspEventRouterCommunication";
            categoryHelp = "WspEventRouter counters showing internal performance of the router.";
            communicationCategoryHelp = "WspEventRouter counters showing communication queues to other servers";
            subscriptionQueueSizeName = "SubscriptionQueueSize";
            rePublisherQueueSizeName  = "RePublisherQueueSize";
            persisterQueueSizeName    = "PersisterQueueSize";
            forwarderQueueSizeName    = "ForwarderQueueSize";
            mgmtQueueSizeName         = "MgmtQueueSize";
            cmdQueueSizeName          = "CmdQueueSize";
            subscriptionEntriesName   = "SubscriptionEntries";
            eventsProcessedName       = "EventsProcessed";
            eventsProcessedBytesName  = "EventsProcessedBytes";
            baseInstance = "BaseInstance";

            subscriptionQueueSize = new PerformanceCounter(categoryName, subscriptionQueueSizeName, string.Empty, false);
            rePublisherQueueSize  = new PerformanceCounter(categoryName, rePublisherQueueSizeName, string.Empty, false);
            persisterQueueSize    = new PerformanceCounter(categoryName, persisterQueueSizeName, string.Empty, false);
            mgmtQueueSize         = new PerformanceCounter(categoryName, mgmtQueueSizeName, string.Empty, false);
            cmdQueueSize          = new PerformanceCounter(categoryName, cmdQueueSizeName, string.Empty, false);
            subscriptionEntries   = new PerformanceCounter(categoryName, subscriptionEntriesName, string.Empty, false);
            eventsProcessed       = new PerformanceCounter(categoryName, eventsProcessedName, string.Empty, false);
            eventsProcessedBytes  = new PerformanceCounter(categoryName, eventsProcessedBytesName, string.Empty, false);

            if (PerformanceCounterCategory.Exists(communicationCategoryName) == false)
            {
                CCDC = new CounterCreationDataCollection();

                CounterCreationData forwarderQueueCounter = new CounterCreationData();
                forwarderQueueCounter.CounterType = PerformanceCounterType.NumberOfItems32;
                forwarderQueueCounter.CounterName = forwarderQueueSizeName;
                CCDC.Add(forwarderQueueCounter);

                PerformanceCounterCategory.Create(communicationCategoryName, communicationCategoryHelp,
                                                  PerformanceCounterCategoryType.MultiInstance, CCDC);
            }

            forwarderQueueSize = new PerformanceCounter(communicationCategoryName, forwarderQueueSizeName, baseInstance, false);

            subscriptionQueueSize.RawValue = 0;
            rePublisherQueueSize.RawValue  = 0;
            persisterQueueSize.RawValue    = 0;
            forwarderQueueSize.RawValue    = 0;
            mgmtQueueSize.RawValue         = 0;
            cmdQueueSize.RawValue          = 0;
            subscriptionEntries.RawValue   = 0;
            eventsProcessed.RawValue       = 0;
            eventsProcessedBytes.RawValue  = 0;
            //eventQueueSize = 10240;
            //averageEventSize = 10240;

            //eventQueueName = @"WspEventQueue";

            //thisBufferSize = 1024000;
            //thisTimeout = 10000;

            listener         = new Listener();
            rePublisher      = new RePublisher();
            subscriptionMgr  = new SubscriptionMgr();
            persister        = new Persister();
            communicator     = new Communicator();
            configurator     = new Configurator();
            commandProcessor = new CommandProcessor();
            manager          = new Manager();

            subscriptionMgrQueue = new SynchronizationQueue <QueueElement>(2000, subscriptionQueueSize);
            rePublisherQueue     = new SynchronizationQueue <QueueElement>(2000, rePublisherQueueSize);
            persisterQueue       = new SynchronizationQueue <QueueElement>(2000, persisterQueueSize);
            forwarderQueue       = new SynchronizationQueue <QueueElement>(2000, forwarderQueueSize);
            mgmtQueue            = new SynchronizationQueue <QueueElement>(100, mgmtQueueSize);
            cmdQueue             = new SynchronizationQueue <QueueElement>(100, cmdQueueSize);

            workerThreads = new Dictionary <Type, Thread>();

            workerThreads.Add(listener.GetType(), null);
            workerThreads.Add(rePublisher.GetType(), null);
            workerThreads.Add(subscriptionMgr.GetType(), null);
            workerThreads.Add(persister.GetType(), null);
            workerThreads.Add(communicator.GetType(), null);
            workerThreads.Add(configurator.GetType(), null);
            workerThreads.Add(commandProcessor.GetType(), null);
            workerThreads.Add(manager.GetType(), null);

            try
            {
                Configurator.LoadConfiguration();
            }
            catch
            {
                // We'll load the config later
            }

            this.ServiceName = "WspEventRouter";
        }