public bool UpdateOutputCondition(int newEventsCount, int oldEventsCount) { if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled)) { Log.Debug( ".updateOutputCondition, " + " newEventsCount==" + newEventsCount + " oldEventsCount==" + oldEventsCount); } var output = false; var currentTime = _agentInstanceContext.StatementContext.SchedulingService.Time; if (_currentReferencePoint == null) { _currentReferencePoint = currentTime; _nextScheduledTime = ScheduleComputeHelper.ComputeNextOccurance(_scheduleSpec, currentTime, _agentInstanceContext.StatementContext.MethodResolutionService.EngineImportService.TimeZone); output = true; } if (_nextScheduledTime <= currentTime) { _nextScheduledTime = ScheduleComputeHelper.ComputeNextOccurance(_scheduleSpec, currentTime, _agentInstanceContext.StatementContext.MethodResolutionService.EngineImportService.TimeZone); output = true; } return(output); }
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); }
protected bool DetermineCurrentlyRunning(ContextControllerCondition startCondition) { // we are not currently running if either of the endpoints is not crontab-triggered var contextDetailInitiatedTerminated = _factory.ContextDetailInitiatedTerminated; if ((contextDetailInitiatedTerminated.Start is ContextDetailConditionCrontab) && ((contextDetailInitiatedTerminated.End is ContextDetailConditionCrontab))) { var scheduleStart = ((ContextDetailConditionCrontab)contextDetailInitiatedTerminated.Start).Schedule; var scheduleEnd = ((ContextDetailConditionCrontab)contextDetailInitiatedTerminated.End).Schedule; var nextScheduledStartTime = ScheduleComputeHelper.ComputeNextOccurance(scheduleStart, _factory.TimeProvider.Time, _factory.StatementContext.MethodResolutionService.EngineImportService.TimeZone); var nextScheduledEndTime = ScheduleComputeHelper.ComputeNextOccurance(scheduleEnd, _factory.TimeProvider.Time, _factory.StatementContext.MethodResolutionService.EngineImportService.TimeZone); return(nextScheduledStartTime >= nextScheduledEndTime); } if (startCondition is ContextControllerConditionTimePeriod) { var condition = (ContextControllerConditionTimePeriod)startCondition; var endTime = condition.ExpectedEndTime; if (endTime != null && endTime <= 0) { return(true); } } return(startCondition is ContextControllerConditionImmediate); }
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 long? GetExpectedEndTime( ContextManagerRealization realization, ScheduleSpec scheduleSpec) { var classpathImportService = realization.AgentInstanceContextCreate.ImportServiceRuntime; return ScheduleComputeHelper.ComputeNextOccurance( scheduleSpec, realization.AgentInstanceContextCreate.TimeProvider.Time, classpathImportService.TimeZone, classpathImportService.TimeAbacus); }
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 static bool DetermineCurrentlyRunning( ContextControllerCondition startCondition, ContextControllerInitTerm controller) { if (startCondition.IsImmediate) { return true; } var factory = controller.InitTermFactory; var spec = factory.InitTermSpec; if (spec.IsOverlapping) { return false; } // we are not currently running if either of the endpoints is not crontab-triggered if (spec.StartCondition is ContextConditionDescriptorCrontab && spec.EndCondition is ContextConditionDescriptorCrontab) { var scheduleStart = ((ContextControllerConditionCrontab) startCondition).Schedule; var endCron = (ContextConditionDescriptorCrontab) spec.EndCondition; var scheduleEnd = ScheduleExpressionUtil.CrontabScheduleBuild( endCron.Evaluators, controller.Realization.AgentInstanceContextCreate); var importService = controller.Realization.AgentInstanceContextCreate.ImportServiceRuntime; var time = controller.Realization.AgentInstanceContextCreate.SchedulingService.Time; var nextScheduledStartTime = ScheduleComputeHelper.ComputeNextOccurance( scheduleStart, time, importService.TimeZone, importService.TimeAbacus); var nextScheduledEndTime = ScheduleComputeHelper.ComputeNextOccurance( scheduleEnd, time, importService.TimeZone, importService.TimeAbacus); return nextScheduledStartTime >= nextScheduledEndTime; } if (startCondition.Descriptor is ContextConditionDescriptorTimePeriod) { var descriptor = (ContextConditionDescriptorTimePeriod) startCondition.Descriptor; var endTime = descriptor.GetExpectedEndTime(controller.Realization); if (endTime != null && endTime <= 0) { return true; } } return startCondition is ContextConditionDescriptorImmediate; }
public void TestAddTwice() { service.Add(100, callbacks[0], slots[0][0]); Assert.IsTrue(service.IsScheduled(callbacks[0])); service.Add(100, callbacks[0], slots[0][0]); service.Add( ScheduleComputeHelper.ComputeNextOccurance(new ScheduleSpec(), service.Time, TimeZoneInfo.Utc, TimeAbacusMilliseconds.INSTANCE), callbacks[1], slots[0][0]); service.Add( ScheduleComputeHelper.ComputeNextOccurance(new ScheduleSpec(), service.Time, TimeZoneInfo.Utc, TimeAbacusMilliseconds.INSTANCE), callbacks[1], slots[0][0]); }
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 }); }