Exemple #1
0
            public Consumer(IAdapter adapter, Action <Exception> exceptionAction)
            {
                IActionAdapter actionAdapter = adapter as IActionAdapter;
                IOutputAdapter outputAdapter;

                Adapter = adapter;

                if ((object)actionAdapter != null)
                {
                    Manager = new DoubleBufferedQueueManager <IMeasurement>(measurements => actionAdapter.QueueMeasurementsForProcessing(new List <IMeasurement>(measurements)), exceptionAction);
                }
                else
                {
                    outputAdapter = adapter as IOutputAdapter;

                    if ((object)outputAdapter != null)
                    {
                        Manager = new DoubleBufferedQueueManager <IMeasurement>(measurements => outputAdapter.QueueMeasurementsForProcessing(new List <IMeasurement>(measurements)), exceptionAction);
                    }
                    else
                    {
                        Manager = new DoubleBufferedQueueManager <IMeasurement>(() => { });
                    }
                }
            }
Exemple #2
0
        /// <summary>
        /// Method for distributing new measurements in a routed fashion.
        /// </summary>
        /// <param name="newMeasurements">Collection of new measurements.</param>
        /// <remarks>
        /// Time-series framework uses this handler to directly route new measurements to the action and output adapters.
        /// </remarks>
        public virtual void RoutedMeasurementsHandler(IEnumerable <IMeasurement> newMeasurements)
        {
            if ((object)m_actionRoutes == null || (object)m_outputRoutes == null)
            {
                return;
            }

            List <IActionAdapter> actionRoutes;
            List <IOutputAdapter> outputRoutes;
            Dictionary <IActionAdapter, List <IMeasurement> > actionMeasurements = new Dictionary <IActionAdapter, List <IMeasurement> >();
            Dictionary <IOutputAdapter, List <IMeasurement> > outputMeasurements = new Dictionary <IOutputAdapter, List <IMeasurement> >();
            List <IMeasurement> measurements;
            MeasurementKey      key;

            m_adapterRoutesCacheLock.EnterReadLock();

            try
            {
                // Loop through each new measurement and look for destination routes
                foreach (IMeasurement measurement in newMeasurements)
                {
                    key = measurement.Key;

                    if (m_actionRoutes.TryGetValue(key, out actionRoutes))
                    {
                        // Add measurements for each destination action adapter route
                        foreach (IActionAdapter actionAdapter in actionRoutes)
                        {
                            if (!actionMeasurements.TryGetValue(actionAdapter, out measurements))
                            {
                                measurements = new List <IMeasurement>();
                                actionMeasurements.Add(actionAdapter, measurements);
                            }

                            measurements.Add(measurement);
                        }
                    }

                    if (m_outputRoutes.TryGetValue(key, out outputRoutes))
                    {
                        // Add measurements for each destination output adapter route
                        foreach (IOutputAdapter outputAdapter in outputRoutes)
                        {
                            if (!outputMeasurements.TryGetValue(outputAdapter, out measurements))
                            {
                                measurements = new List <IMeasurement>();
                                outputMeasurements.Add(outputAdapter, measurements);
                            }

                            measurements.Add(measurement);
                        }
                    }
                }

                // Send broadcast action measurements
                foreach (IActionAdapter actionAdapter in m_actionBroadcastRoutes)
                {
                    if (actionAdapter.Enabled)
                    {
                        actionAdapter.QueueMeasurementsForProcessing(newMeasurements);
                    }
                }

                // Send broadcast output measurements
                foreach (IOutputAdapter outputAdapter in m_outputBroadcastRoutes)
                {
                    if (outputAdapter.Enabled)
                    {
                        outputAdapter.QueueMeasurementsForProcessing(newMeasurements);
                    }
                }
            }
            finally
            {
                m_adapterRoutesCacheLock.ExitReadLock();
            }

            // Send routed action measurements
            foreach (KeyValuePair <IActionAdapter, List <IMeasurement> > actionAdapterMeasurements in actionMeasurements)
            {
                IActionAdapter actionAdapter = actionAdapterMeasurements.Key;

                if (actionAdapter.Enabled)
                {
                    actionAdapter.QueueMeasurementsForProcessing(actionAdapterMeasurements.Value);
                }
            }

            // Send routed output measurements
            foreach (KeyValuePair <IOutputAdapter, List <IMeasurement> > outputAdapterMeasurements in outputMeasurements)
            {
                IOutputAdapter outputAdapter = outputAdapterMeasurements.Key;

                if (outputAdapter.Enabled)
                {
                    outputAdapter.QueueMeasurementsForProcessing(outputAdapterMeasurements.Value);
                }
            }
        }