Example #1
0
 /// <summary>Ctor. </summary>
 /// <param name="services">engine services</param>
 /// <param name="runtime">runtime to process</param>
 /// <param name="handle">statement handle</param>
 /// <param name="callbackObject">callback list</param>
 public TimerUnitMultiple(EPServicesContext services, EPRuntimeImpl runtime, EPStatementAgentInstanceHandle handle, object callbackObject)
 {
     _services       = services;
     _handle         = handle;
     _runtime        = runtime;
     _callbackObject = callbackObject;
 }
Example #2
0
        public void InitThreading(EPServicesContext services, EPRuntimeImpl runtime)
        {
            if (_isInboundThreading)
            {
                _inboundQueue      = MakeQueue(_config.ThreadPoolInboundCapacity, _config.ThreadPoolInboundBlocking);
                _inboundThreadPool = GetThreadPool(services.EngineURI, "Inbound", _inboundQueue, _config.ThreadPoolInboundNumThreads);
            }

            if (_isTimerThreading)
            {
                _timerQueue      = MakeQueue(_config.ThreadPoolTimerExecCapacity, _config.ThreadPoolTimerExecBlocking);
                _timerThreadPool = GetThreadPool(services.EngineURI, "TimerExec", _timerQueue, _config.ThreadPoolTimerExecNumThreads);
            }

            if (_isRouteThreading)
            {
                _routeQueue      = MakeQueue(_config.ThreadPoolRouteExecCapacity, _config.ThreadPoolRouteExecBlocking);
                _routeThreadPool = GetThreadPool(services.EngineURI, "RouteExec", _routeQueue, _config.ThreadPoolRouteExecNumThreads);
            }

            if (_isOutboundThreading)
            {
                _outboundQueue      = MakeQueue(_config.ThreadPoolOutboundCapacity, _config.ThreadPoolOutboundBlocking);
                _outboundThreadPool = GetThreadPool(services.EngineURI, "Outbound", _outboundQueue, _config.ThreadPoolOutboundNumThreads);
            }
        }
Example #3
0
 /// <summary>Ctor. </summary>
 /// <param name="properties">to send</param>
 /// <param name="eventTypeName">type name</param>
 /// <param name="services">to wrap</param>
 /// <param name="runtime">to process</param>
 public InboundUnitSendObjectArray(Object[] properties, String eventTypeName, EPServicesContext services, EPRuntimeImpl runtime)
 {
     _eventTypeName = eventTypeName;
     _properties    = properties;
     _services      = services;
     _runtime       = runtime;
 }
Example #4
0
 /// <summary>Ctor. </summary>
 /// <param name="theEvent">document</param>
 /// <param name="services">for wrapping event</param>
 /// <param name="runtime">runtime to process</param>
 public InboundUnitSendLINQ(XElement theEvent,
                            EPServicesContext services,
                            EPRuntimeImpl runtime)
 {
     _event    = theEvent;
     _services = services;
     _runtime  = runtime;
 }
Example #5
0
 /// <summary>Ctor. </summary>
 /// <param name="theEvent">document</param>
 /// <param name="services">for wrapping event</param>
 /// <param name="runtime">runtime to process</param>
 public InboundUnitSendDOM(XmlNode theEvent,
                           EPServicesContext services,
                           EPRuntimeImpl runtime)
 {
     _event    = theEvent;
     _services = services;
     _runtime  = runtime;
 }
Example #6
0
 /// <summary>Ctor. </summary>
 /// <param name="epRuntime">runtime to process</param>
 /// <param name="callbackList">callback list</param>
 /// <param name="theEvent">event to pass</param>
 /// <param name="handle">statement handle</param>
 /// <param name="filterVersion">version of filter</param>
 public RouteUnitMultiple(EPRuntimeImpl epRuntime, Object callbackList, EventBean theEvent, EPStatementAgentInstanceHandle handle, long filterVersion)
 {
     _epRuntime     = epRuntime;
     _callbackList  = callbackList;
     _theEvent      = theEvent;
     _handle        = handle;
     _filterVersion = filterVersion;
 }
Example #7
0
 /// <summary>Ctor. </summary>
 /// <param name="epRuntime">runtime to process</param>
 /// <param name="handleCallback">callback</param>
 /// <param name="theEvent">event</param>
 /// <param name="filterVersion">version of filter</param>
 public RouteUnitSingle(EPRuntimeImpl epRuntime,
                        EPStatementHandleCallback handleCallback,
                        EventBean theEvent,
                        long filterVersion)
 {
     _epRuntime      = epRuntime;
     _event          = theEvent;
     _handleCallback = handleCallback;
     _filterVersion  = filterVersion;
 }
Example #8
0
 /// <summary>Ctor. </summary>
 /// <param name="map">to send</param>
 /// <param name="eventTypeName">type name</param>
 /// <param name="services">to wrap</param>
 /// <param name="runtime">to process</param>
 public InboundUnitSendMap(DataMap map,
                           String eventTypeName,
                           EPServicesContext services,
                           EPRuntimeImpl runtime)
 {
     _eventTypeName = eventTypeName;
     _map           = map;
     _services      = services;
     _runtime       = runtime;
 }
Example #9
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="genericRecordDotData">to send</param>
 /// <param name="eventTypeName">type name</param>
 /// <param name="services">to wrap</param>
 /// <param name="runtime">to process</param>
 public InboundUnitSendAvro(
     Object genericRecordDotData,
     string eventTypeName,
     EPServicesContext services,
     EPRuntimeImpl runtime)
 {
     this._eventTypeName        = eventTypeName;
     this._genericRecordDotData = genericRecordDotData;
     this._services             = services;
     this._runtime = runtime;
 }
Example #10
0
        public void Run()
        {
            try
            {
                EPRuntimeImpl.ProcessStatementScheduleSingle(_handleCallback, _services);

                _runtime.Dispatch();

                _runtime.ProcessThreadWorkQueue();
            }
            catch (Exception e)
            {
                Log.Error("Unexpected error processing timer execution: " + e.Message, e);
            }
        }
Example #11
0
        public void Run()
        {
            try
            {
                EPRuntimeImpl.ProcessStatementScheduleMultiple(_handle, _callbackObject, _services);

                // Let listeners know of results
                _runtime.Dispatch();

                // Work off the event queue if any events accumulated in there via a Route()
                _runtime.ProcessThreadWorkQueue();
            }
            catch (Exception e)
            {
                Log.Error("Unexpected error processing multiple timer execution: " + e.Message, e);
            }
        }
Example #12
0
 /// <summary>Ctor. </summary>
 /// <param name="services">engine services</param>
 /// <param name="runtime">runtime to process</param>
 /// <param name="handleCallback">callback</param>
 public TimerUnitSingle(EPServicesContext services, EPRuntimeImpl runtime, EPStatementHandleCallback handleCallback)
 {
     _services       = services;
     _runtime        = runtime;
     _handleCallback = handleCallback;
 }
Example #13
0
        private void ProcessScheduleHandles(ArrayBackedCollection <ScheduleHandle> handles)
        {
            if (ThreadLogUtil.ENABLED_TRACE)
            {
                ThreadLogUtil.Trace("Found schedules for", handles.Count);
            }

            if (handles.Count == 0)
            {
                return;
            }

            // handle 1 result separatly for performance reasons
            if (handles.Count == 1)
            {
                Object[] handleArray = handles.Array;
                var      handle      = (EPStatementHandleCallback)handleArray[0];

                EPRuntimeImpl.ProcessStatementScheduleSingle(handle, _unisolatedServices);

                handles.Clear();
                return;
            }

            Object[] matchArray = handles.Array;
            int      entryCount = handles.Count;

            LinkedList <ScheduleHandleCallback> entries;

            // sort multiple matches for the event into statements
            var stmtCallbacks = SchedulePerStmt;

            stmtCallbacks.Clear();
            for (int i = 0; i < entryCount; i++)
            {
                var handleCallback = (EPStatementHandleCallback)matchArray[i];
                var handle         = handleCallback.AgentInstanceHandle;
                var callback       = handleCallback.ScheduleCallback;

                var entry = stmtCallbacks.Get(handle);

                // This statement has not been encountered before
                if (entry == null)
                {
                    stmtCallbacks.Put(handle, callback);
                    continue;
                }

                // This statement has been encountered once before
                if (entry is ScheduleHandleCallback)
                {
                    var existingCallback = (ScheduleHandleCallback)entry;
                    entries = new LinkedList <ScheduleHandleCallback>();
                    entries.AddLast(existingCallback);
                    entries.AddLast(callback);
                    stmtCallbacks.Put(handle, entries);
                    continue;
                }

                // This statement has been encountered more then once before
                entries = (LinkedList <ScheduleHandleCallback>)entry;
                entries.AddLast(callback);
            }
            handles.Clear();

            foreach (var entry in stmtCallbacks)
            {
                var handle         = entry.Key;
                var callbackObject = entry.Value;

                EPRuntimeImpl.ProcessStatementScheduleMultiple(handle, callbackObject, _unisolatedServices);

                if ((_isPrioritized) && (handle.IsPreemptive))
                {
                    break;
                }
            }
        }
Example #14
0
 /// <summary>Ctor. </summary>
 /// <param name="theEvent">to process</param>
 /// <param name="runtime">to process event</param>
 public InboundUnitSendEvent(Object theEvent, EPRuntimeImpl runtime)
 {
     _event   = theEvent;
     _runtime = runtime;
 }
Example #15
0
        /// <summary>
        /// Performs the initialization.
        /// </summary>
        /// <param name="startTime">optional start time</param>
        protected void DoInitialize(long?startTime)
        {
            Log.Info("Initializing engine URI '" + _engineURI + "' version " + Version.VERSION);

            // This setting applies to all engines in a given VM
            ExecutionPathDebugLog.IsEnabled           = _configSnapshot.EngineDefaults.Logging.IsEnableExecutionDebug;
            ExecutionPathDebugLog.IsTimerDebugEnabled = _configSnapshot.EngineDefaults.Logging.IsEnableTimerDebug;

            // This setting applies to all engines in a given VM
            MetricReportingPath.IsMetricsEnabled =
                _configSnapshot.EngineDefaults.MetricsReporting.IsEnableMetricsReporting;

            // This setting applies to all engines in a given VM
            AuditPath.AuditPattern = _configSnapshot.EngineDefaults.Logging.AuditPattern;

            // This setting applies to all engines in a given VM
            ThreadingOption.IsThreadingEnabled = (
                ThreadingOption.IsThreadingEnabled ||
                _configSnapshot.EngineDefaults.Threading.IsThreadPoolTimerExec ||
                _configSnapshot.EngineDefaults.Threading.IsThreadPoolInbound ||
                _configSnapshot.EngineDefaults.Threading.IsThreadPoolRouteExec ||
                _configSnapshot.EngineDefaults.Threading.IsThreadPoolOutbound
                );

            if (_engine != null)
            {
                _engine.Services.TimerService.StopInternalClock(false);
                // Give the timer thread a little moment to catch up
                Thread.Sleep(100);

                if (_configSnapshot.EngineDefaults.MetricsReporting.IsEnableMetricsReporting)
                {
                    DestroyEngineMetrics(_engine.Services.EngineURI);
                }

                _engine.Runtime.Initialize();

                _engine.Services.Dispose();
            }

            // Make EP services context factory
            var epServicesContextFactoryClassName = _configSnapshot.EPServicesContextFactoryClassName;
            EPServicesContextFactory epServicesContextFactory;

            if (epServicesContextFactoryClassName == null)
            {
                // Check system properties
                epServicesContextFactoryClassName =
                    Environment.GetEnvironmentVariable("ESPER_EPSERVICE_CONTEXT_FACTORY_CLASS");
            }
            if (epServicesContextFactoryClassName == null)
            {
                epServicesContextFactory = new EPServicesContextFactoryDefault();
            }
            else
            {
                Type clazz;
                try
                {
                    clazz =
                        TransientConfigurationResolver.ResolveClassForNameProvider(
                            _configSnapshot.TransientConfiguration).ClassForName(epServicesContextFactoryClassName);
                }
                catch (TypeLoadException)
                {
                    throw new ConfigurationException(
                              "Type '" + epServicesContextFactoryClassName + "' cannot be loaded");
                }

                Object obj;
                try
                {
                    obj = Activator.CreateInstance(clazz);
                }
                catch (TypeLoadException)
                {
                    throw new ConfigurationException("Class '" + clazz + "' cannot be instantiated");
                }
                catch (MissingMethodException e)
                {
                    throw new ConfigurationException(
                              "Error instantiating class - Default constructor was not found", e);
                }
                catch (MethodAccessException e)
                {
                    throw new ConfigurationException(
                              "Error instantiating class - Caller does not have permission to use constructor", e);
                }
                catch (ArgumentException e)
                {
                    throw new ConfigurationException("Error instantiating class - Type is not a RuntimeType", e);
                }

                epServicesContextFactory = (EPServicesContextFactory)obj;
            }

            var services = epServicesContextFactory.CreateServicesContext(this, _configSnapshot);

            // New runtime
            EPRuntimeSPI           runtimeSPI;
            InternalEventRouteDest routeDest;
            TimerCallback          timerCallback;
            var runtimeClassName = _configSnapshot.EngineDefaults.AlternativeContext.Runtime;

            if (runtimeClassName == null)
            {
                // Check system properties
                runtimeClassName = Environment.GetEnvironmentVariable("ESPER_EPRUNTIME_CLASS");
            }

            if (runtimeClassName == null)
            {
                var runtimeImpl = new EPRuntimeImpl(services);
                runtimeSPI    = runtimeImpl;
                routeDest     = runtimeImpl;
                timerCallback = runtimeImpl.TimerCallback;
            }
            else
            {
                Type clazz;
                try
                {
                    clazz = TypeHelper.ResolveType(runtimeClassName, true);
                }
                catch (TypeLoadException)
                {
                    throw new ConfigurationException("Class '" + runtimeClassName + "' cannot be loaded");
                }

                Object obj;
                try
                {
                    var c = clazz.GetConstructor(new[] { typeof(EPServicesContext) });
                    obj = c.Invoke(new object[] { services });
                }
                catch (TypeLoadException)
                {
                    throw new ConfigurationException("Class '" + clazz + "' cannot be instantiated");
                }
                catch (MissingMethodException)
                {
                    throw new ConfigurationException(
                              "Class '" + clazz + "' cannot be instantiated, constructor accepting services was not found");
                }
                catch (MethodAccessException)
                {
                    throw new ConfigurationException("Illegal access instantiating class '" + clazz + "'");
                }

                runtimeSPI    = (EPRuntimeSPI)obj;
                routeDest     = (InternalEventRouteDest)obj;
                timerCallback = (TimerCallback)obj;
            }

            routeDest.InternalEventRouter         = services.InternalEventRouter;
            services.InternalEventEngineRouteDest = routeDest;

            // set current time, if applicable
            if (startTime != null)
            {
                services.SchedulingService.Time = startTime.Value;
            }

            // Configure services to use the new runtime
            services.TimerService.Callback = timerCallback;

            // Statement lifecycle init
            services.StatementLifecycleSvc.Init();

            // Filter service init
            services.FilterService.Init();

            // Schedule service init
            services.SchedulingService.Init();

            // New admin
            var configOps = new ConfigurationOperationsImpl(
                services.EventAdapterService, services.EventTypeIdGenerator, services.EngineImportService,
                services.VariableService, services.EngineSettingsService, services.ValueAddEventService,
                services.MetricsReportingService, services.StatementEventTypeRefService,
                services.StatementVariableRefService, services.PlugInViews, services.FilterService,
                services.PatternSubexpressionPoolSvc, services.MatchRecognizeStatePoolEngineSvc, services.TableService,
                _configSnapshot.TransientConfiguration);
            var defaultStreamSelector =
                SelectClauseStreamSelectorEnumExtensions.MapFromSODA(
                    _configSnapshot.EngineDefaults.StreamSelection.DefaultStreamSelector);
            EPAdministratorSPI adminSPI;
            var adminClassName = _configSnapshot.EngineDefaults.AlternativeContext.Admin;
            var adminContext   = new EPAdministratorContext(runtimeSPI, services, configOps, defaultStreamSelector);

            if (adminClassName == null)
            {
                // Check system properties
                adminClassName = Environment.GetEnvironmentVariable("ESPER_EPADMIN_CLASS");
            }
            if (adminClassName == null)
            {
                adminSPI = new EPAdministratorImpl(adminContext);
            }
            else
            {
                Type clazz;
                try
                {
                    clazz = TypeHelper.ResolveType(adminClassName, true);
                }
                catch (TypeLoadException)
                {
                    throw new ConfigurationException(
                              "Class '" + epServicesContextFactoryClassName + "' cannot be loaded");
                }

                Object obj;
                try
                {
                    var c = clazz.GetConstructor(new[] { typeof(EPAdministratorContext) });
                    obj = c.Invoke(new[] { adminContext });
                }
                catch (TypeLoadException)
                {
                    throw new ConfigurationException("Class '" + clazz + "' cannot be instantiated");
                }
                catch (MissingMethodException)
                {
                    throw new ConfigurationException(
                              "Class '" + clazz + "' cannot be instantiated, constructor accepting context was not found");
                }
                catch (MethodAccessException)
                {
                    throw new ConfigurationException("Illegal access instantiating class '" + clazz + "'");
                }

                adminSPI = (EPAdministratorSPI)obj;
            }

            // Start clocking
            if (_configSnapshot.EngineDefaults.Threading.IsInternalTimerEnabled)
            {
                if (_configSnapshot.EngineDefaults.TimeSource.TimeUnit != TimeUnit.MILLISECONDS)
                {
                    throw new ConfigurationException("Internal timer requires millisecond time resolution");
                }
                services.TimerService.StartInternalClock();
            }

            // Give the timer thread a little moment to start up
            Thread.Sleep(100);

            // Save engine instance
            _engine = new EPServiceEngine(services, runtimeSPI, adminSPI);

            // Load and initialize adapter loader classes
            LoadAdapters(services);

            // Initialize extension services
            if (services.EngineLevelExtensionServicesContext != null)
            {
                services.EngineLevelExtensionServicesContext.Init(services, runtimeSPI, adminSPI);
            }

            // Start metrics reporting, if any
            if (_configSnapshot.EngineDefaults.MetricsReporting.IsEnableMetricsReporting)
            {
                services.MetricsReportingService.SetContext(runtimeSPI, services);
            }

            // Start engine metrics report
            if (_configSnapshot.EngineDefaults.MetricsReporting.IsEnableMetricsReporting)
            {
                StartEngineMetrics(services, runtimeSPI);
            }

            // register with the statement lifecycle service
            services.StatementLifecycleSvc.LifecycleEvent += HandleLifecycleEvent;

            // call initialize listeners
            try
            {
                if (ServiceInitialized != null)
                {
                    ServiceInitialized(this, new ServiceProviderEventArgs(this));
                }
            }
            catch (Exception ex)
            {
                Log.Error("Runtime exception caught during an ServiceInitialized event:" + ex.Message, ex);
            }
        }