Exemple #1
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="IaonSession"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        DataSet dataSource = DataSource;

                        // Dispose filter adapters collection
                        if ((object)m_filterAdapters != null)
                        {
                            m_filterAdapters.Stop();
                            m_filterAdapters.Dispose();
                        }
                        m_filterAdapters = null;

                        // Dispose input adapters collection
                        if ((object)m_inputAdapters != null)
                        {
                            m_inputAdapters.Stop();
                            m_inputAdapters.NewMeasurements    -= NewMeasurementsHandler;
                            m_inputAdapters.ProcessingComplete -= ProcessingCompleteHandler;
                            m_inputAdapters.Dispose();
                        }
                        m_inputAdapters = null;

                        // Dispose action adapters collection
                        if ((object)m_actionAdapters != null)
                        {
                            m_actionAdapters.Stop();
                            m_actionAdapters.NewMeasurements        -= NewMeasurementsHandler;
                            m_actionAdapters.UnpublishedSamples     -= UnpublishedSamplesHandler;
                            m_actionAdapters.RequestTemporalSupport -= RequestTemporalSupportHandler;
                            m_actionAdapters.Dispose();
                        }
                        m_actionAdapters = null;

                        // Dispose output adapters collection
                        if ((object)m_outputAdapters != null)
                        {
                            m_outputAdapters.Stop();
                            m_outputAdapters.UnprocessedMeasurements -= UnprocessedMeasurementsHandler;
                            m_outputAdapters.Dispose();
                        }
                        m_outputAdapters = null;

                        // Dispose all adapters collection
                        if (m_allAdapters != null)
                        {
                            m_allAdapters.StatusMessage               -= StatusMessageHandler;
                            m_allAdapters.ProcessException            -= ProcessExceptionHandler;
                            m_allAdapters.InputMeasurementKeysUpdated -= InputMeasurementKeysUpdatedHandler;
                            m_allAdapters.OutputMeasurementsUpdated   -= OutputMeasurementsUpdatedHandler;
                            m_allAdapters.ConfigurationChanged        -= ConfigurationChangedHandler;
                            m_allAdapters.Disposed -= DisposedHandler;
                            m_allAdapters.Dispose();
                        }
                        m_allAdapters = null;

                        // Dispose of routing tables
                        if (m_routingTables != null)
                        {
                            m_routingTables.StatusMessage    -= m_routingTables_StatusMessage;
                            m_routingTables.ProcessException -= m_routingTables_ProcessException;
                            m_routingTables.Dispose();
                        }
                        m_routingTables = null;

                        if ((object)dataSource != null)
                        {
                            dataSource.Dispose();
                        }
                    }
                }
                finally
                {
                    m_disposed = true; // Prevent duplicate dispose.

                    if (Disposed != null)
                    {
                        Disposed(this, EventArgs.Empty);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates a new <see cref="IaonSession"/>.
        /// </summary>
        public IaonSession()
        {
            ConfigurationFile configFile = ConfigurationFile.Current;

            // Initialize system settings
            CategorizedSettingsElementCollection systemSettings = configFile.Settings["systemSettings"];

            systemSettings.Add("NodeID", Guid.NewGuid().ToString(), "Unique Node ID");
            m_nodeID = systemSettings["NodeID"].ValueAs <Guid>();

            // Initialize threshold settings
            CategorizedSettingsElementCollection thresholdSettings = configFile.Settings["thresholdSettings"];

            thresholdSettings.Add("MeasurementWarningThreshold", "100000", "Number of unarchived measurements allowed in any output adapter queue before displaying a warning message");
            thresholdSettings.Add("MeasurementDumpingThreshold", "500000", "Number of unarchived measurements allowed in any output adapter queue before taking evasive action and dumping data");
            thresholdSettings.Add("DefaultSampleSizeWarningThreshold", "10", "Default number of unpublished samples (in seconds) allowed in any action adapter queue before displaying a warning message");

            m_measurementWarningThreshold       = thresholdSettings["MeasurementWarningThreshold"].ValueAsInt32();
            m_measurementDumpingThreshold       = thresholdSettings["MeasurementDumpingThreshold"].ValueAsInt32();
            m_defaultSampleSizeWarningThreshold = thresholdSettings["DefaultSampleSizeWarningThreshold"].ValueAsInt32();

            using (Logger.AppendStackMessages("HostAdapter", "IaonSession"))
            {
                // Create a new set of routing tables
                switch (OptimizationOptions.DefaultRoutingMethod)
                {
                case OptimizationOptions.RoutingMethod.HighLatencyLowCpu:
                    m_routingTables = new RoutingTables(new RouteMappingHighLatencyLowCpu());
                    break;

                default:
                    m_routingTables = new RoutingTables();
                    break;
                }
            }
            m_routingTables.StatusMessage    += m_routingTables_StatusMessage;
            m_routingTables.ProcessException += m_routingTables_ProcessException;

            // Create a collection to manage all input, action and output adapter collections as a unit
            m_allAdapters = new AllAdaptersCollection();

            // Attach to common adapter events
            m_allAdapters.StatusMessage               += StatusMessageHandler;
            m_allAdapters.ProcessException            += ProcessExceptionHandler;
            m_allAdapters.InputMeasurementKeysUpdated += InputMeasurementKeysUpdatedHandler;
            m_allAdapters.OutputMeasurementsUpdated   += OutputMeasurementsUpdatedHandler;
            m_allAdapters.ConfigurationChanged        += ConfigurationChangedHandler;
            m_allAdapters.Disposed += DisposedHandler;

            // Create filter adapters collection
            m_filterAdapters = new FilterAdapterCollection();

            // Create input adapters collection
            m_inputAdapters = new InputAdapterCollection();
            m_inputAdapters.NewMeasurements    += NewMeasurementsHandler;
            m_inputAdapters.ProcessingComplete += ProcessingCompleteHandler;

            // Create action adapters collection
            m_actionAdapters = new ActionAdapterCollection();
            m_actionAdapters.NewMeasurements        += NewMeasurementsHandler;
            m_actionAdapters.UnpublishedSamples     += UnpublishedSamplesHandler;
            m_actionAdapters.RequestTemporalSupport += RequestTemporalSupportHandler;

            // Create output adapters collection
            m_outputAdapters = new OutputAdapterCollection();
            m_outputAdapters.UnprocessedMeasurements += UnprocessedMeasurementsHandler;

            // Associate adapter collections with routing tables
            m_routingTables.InputAdapters  = m_inputAdapters;
            m_routingTables.ActionAdapters = m_actionAdapters;
            m_routingTables.OutputAdapters = m_outputAdapters;

            // We group these adapters such that they are initialized in the following order: output, filter, input, action.
            // This is done so that the archival capabilities will be setup before we start receiving input and the input
            // data will be flowing before any actions get established for the input - at least generally.
            m_allAdapters.Add(m_outputAdapters);
            m_allAdapters.Add(m_filterAdapters);
            m_allAdapters.Add(m_inputAdapters);
            m_allAdapters.Add(m_actionAdapters);

            m_requestTemporalSupportLock = new object();
        }