private void ScheduleCallback() { isCallbackScheduled = true; ScheduleHandleCallback callback = new ProxyScheduleHandleCallback { ProcScheduledTrigger = () => { context.InstrumentationProvider.QOutputRateConditionScheduledEval(); context.AuditProvider.ScheduleFire( context, ScheduleObjectType.outputratelimiting, NAME_AUDITPROVIDER_SCHEDULE); isCallbackScheduled = false; outputCallback.Invoke(DO_OUTPUT, FORCE_UPDATE); ScheduleCallback(); context.InstrumentationProvider.AOutputRateConditionScheduledEval(); } }; var handle = new EPStatementHandleCallbackSchedule(context.EpStatementAgentInstanceHandle, callback); var schedulingService = context.StatementContext.SchedulingService; var classpathImportService = context.StatementContext.ImportServiceRuntime; long nextScheduledTime = ScheduleComputeHelper.ComputeDeltaNextOccurance( scheduleSpec, schedulingService.Time, classpathImportService.TimeZone, classpathImportService.TimeAbacus); context.AuditProvider.ScheduleAdd( nextScheduledTime, context, handle, ScheduleObjectType.outputratelimiting, NAME_AUDITPROVIDER_SCHEDULE); schedulingService.Add(nextScheduledTime, handle, scheduleSlot); }
private void ScheduleCallback() { _isCallbackScheduled = true; var current = _context.StatementContext.SchedulingService.Time; if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled)) { Log.Debug( ".scheduleCallback Scheduled new callback for " + " now=" + current + " currentReferencePoint=" + _currentReferencePoint + " spec=" + _factory.ScheduleSpec); } var callback = new ProxyScheduleHandleCallback { ProcScheduledTrigger = extensionServicesContext => Instrument.With( i => i.QOutputRateConditionScheduledEval(), i => i.AOutputRateConditionScheduledEval(), () => { _isCallbackScheduled = false; OutputCallback.Invoke(DO_OUTPUT, FORCE_UPDATE); ScheduleCallback(); }) }; var handle = new EPStatementHandleCallback(_context.EpStatementAgentInstanceHandle, callback); var schedulingService = _context.StatementContext.SchedulingService; var nextScheduledTime = ScheduleComputeHelper.ComputeDeltaNextOccurance( _factory.ScheduleSpec, schedulingService.Time, _context.StatementContext.MethodResolutionService.EngineImportService.TimeZone); schedulingService.Add(nextScheduledTime, handle, _scheduleSlot); }
private void StartContextCallback() { var scheduleCallback = new ProxyScheduleHandleCallback { ProcScheduledTrigger = (extensionServicesContext) => { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QContextScheduledEval(_statementContext.ContextDescriptor); } _scheduleHandle = null; // terminates automatically unless scheduled again _callback.RangeNotification(Collections.EmptyDataMap, this, null, null, _filterAddendum); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AContextScheduledEval(); } } }; var agentHandle = new EPStatementAgentInstanceHandle(_statementContext.EpStatementHandle, _statementContext.DefaultAgentInstanceLock, -1, new StatementAgentInstanceFilterVersion(), _statementContext.FilterFaultHandlerFactory); _scheduleHandle = new EPStatementHandleCallback(agentHandle, scheduleCallback); var schedulingService = _statementContext.SchedulingService; var engineImportService = _statementContext.EngineImportService; var nextScheduledTime = ScheduleComputeHelper.ComputeDeltaNextOccurance(_spec.Schedule, schedulingService.Time, engineImportService.TimeZone, engineImportService.TimeAbacus); _statementContext.SchedulingService.Add(nextScheduledTime, _scheduleHandle, _scheduleSlot); }
public void StartObserve() { if (_isTimerActive) { throw new IllegalStateException("Timer already active"); } _scheduleHandle = new EPStatementHandleCallback(_observerEventEvaluator.Context.AgentInstanceContext.EpStatementAgentInstanceHandle, this); SchedulingService schedulingService = _observerEventEvaluator.Context.PatternContext.SchedulingService; long nextScheduledTime = ScheduleComputeHelper.ComputeDeltaNextOccurance(_scheduleSpec, schedulingService.Time, _observerEventEvaluator.Context.StatementContext.MethodResolutionService.EngineImportService.TimeZone); schedulingService.Add(nextScheduledTime, _scheduleHandle, _scheduleSlot); _isTimerActive = true; }
public static long ComputeScheduleMinimumDelta(ScheduleSpec[] schedules, long time, ImportServiceRuntime classpathImportService) { var value = Int64.MaxValue; foreach (ScheduleSpec spec in schedules) { long computed = ScheduleComputeHelper.ComputeDeltaNextOccurance( spec, time, classpathImportService.TimeZone, classpathImportService.TimeAbacus); if (computed < value) { value = computed; } } return value; }
public bool Activate( EventBean optionalTriggeringEvent, ContextControllerEndConditionMatchEventProvider endConditionMatchEventProvider) { ScheduleHandleCallback scheduleCallback = new ProxyScheduleHandleCallback { ProcScheduledTrigger = () => { var inProcAgentInstanceContext = controller.Realization.AgentInstanceContextCreate; inProcAgentInstanceContext.InstrumentationProvider.QContextScheduledEval( inProcAgentInstanceContext.StatementContext.ContextRuntimeDescriptor); scheduleHandle = null; // terminates automatically unless scheduled again inProcAgentInstanceContext.AuditProvider.ScheduleFire( inProcAgentInstanceContext, ScheduleObjectType.context, NAME_AUDITPROVIDER_SCHEDULE); callback.RangeNotification(conditionPath, this, null, null, null, null); inProcAgentInstanceContext.InstrumentationProvider.AContextScheduledEval(); } }; var agentInstanceContext = controller.Realization.AgentInstanceContextCreate; scheduleHandle = new EPStatementHandleCallbackSchedule( agentInstanceContext.EpStatementAgentInstanceHandle, scheduleCallback); long nextScheduledTime = ScheduleComputeHelper.ComputeDeltaNextOccurance( Schedule, agentInstanceContext.TimeProvider.Time, agentInstanceContext.ImportServiceRuntime.TimeZone, agentInstanceContext.ImportServiceRuntime.TimeAbacus); agentInstanceContext.AuditProvider.ScheduleAdd( nextScheduledTime, agentInstanceContext, scheduleHandle, ScheduleObjectType.context, NAME_AUDITPROVIDER_SCHEDULE); agentInstanceContext.SchedulingService.Add(nextScheduledTime, scheduleHandle, scheduleSlot); return false; }
private void StartContextCallback() { ScheduleHandleCallback scheduleCallback = new ProxyScheduleHandleCallback { ProcScheduledTrigger = extensionServicesContext => Instrument.With( i => i.QContextScheduledEval(_statementContext.ContextDescriptor), i => i.AContextScheduledEval(), () => { _scheduleHandle = null; // terminates automatically unless scheduled again _callback.RangeNotification( Collections.GetEmptyMap <String, Object>(), this, null, null, _filterAddendum); }) }; var agentHandle = new EPStatementAgentInstanceHandle(_statementContext.EpStatementHandle, _statementContext.DefaultAgentInstanceLock, -1, new StatementAgentInstanceFilterVersion()); _scheduleHandle = new EPStatementHandleCallback(agentHandle, scheduleCallback); var schedulingService = _statementContext.SchedulingService; var nextScheduledTime = ScheduleComputeHelper.ComputeDeltaNextOccurance(_spec.Schedule, schedulingService.Time, _statementContext.MethodResolutionService.EngineImportService.TimeZone); _statementContext.SchedulingService.Add(nextScheduledTime, _scheduleHandle, _scheduleSlot); }
public void TestWaitAndSpecTogether() { var dateTimeEx = DateTimeEx.GetInstance( TimeZoneInfo.Utc, new DateTime(2004, 12, 9, 15, 27, 10, DateTimeKind.Utc)); dateTimeEx.SetMillis(500); var startTime = dateTimeEx.UtcMillis; service.Time = startTime; // Add a specification var spec = new ScheduleSpec(); spec.AddValue(ScheduleUnit.MONTHS, 12); spec.AddValue(ScheduleUnit.DAYS_OF_MONTH, 9); spec.AddValue(ScheduleUnit.HOURS, 15); spec.AddValue(ScheduleUnit.MINUTES, 27); spec.AddValue(ScheduleUnit.SECONDS, 20); service.Add( ScheduleComputeHelper.ComputeDeltaNextOccurance(spec, service.Time, TimeZoneInfo.Utc, TimeAbacusMilliseconds.INSTANCE), callbacks[3], slots[1][1]); spec.AddValue(ScheduleUnit.SECONDS, 15); service.Add( ScheduleComputeHelper.ComputeDeltaNextOccurance(spec, service.Time, TimeZoneInfo.Utc, TimeAbacusMilliseconds.INSTANCE), callbacks[4], slots[2][0]); // Add some more callbacks service.Add(5000, callbacks[0], slots[0][0]); service.Add(10000, callbacks[1], slots[0][1]); service.Add(15000, callbacks[2], slots[1][0]); // Now send a times reflecting various seconds later and check who got a callback service.Time = startTime + 1000; SupportScheduleCallback.SetCallbackOrderNum(0); EvaluateSchedule(); CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 }); service.Time = startTime + 2000; EvaluateSchedule(); CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 }); service.Time = startTime + 4000; EvaluateSchedule(); CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 }); service.Time = startTime + 5000; EvaluateSchedule(); CheckCallbacks(callbacks, new[] { 1, 0, 0, 0, 2 }); service.Time = startTime + 9000; EvaluateSchedule(); CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 }); service.Time = startTime + 10000; EvaluateSchedule(); CheckCallbacks(callbacks, new[] { 0, 3, 0, 4, 0 }); service.Time = startTime + 11000; EvaluateSchedule(); CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 }); service.Time = startTime + 15000; EvaluateSchedule(); CheckCallbacks(callbacks, new[] { 0, 0, 5, 0, 0 }); service.Time = startTime + int.MaxValue; EvaluateSchedule(); CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 }); }