Exemplo n.º 1
0
        private void ScheduleNextCallback()
        {
            var nextScheduleCallback = new ProxyScheduleHandleCallback(delegate { ContinueSendingEvents(); });
            var spi                 = (EPServiceProviderSPI)_epService;
            var metricsHandle       = spi.MetricReportingService.GetStatementHandle(-1, "AbstractCoordinatedAdapter");
            var lockImpl            = ReaderWriterLockManager.CreateLock("CSV");
            var stmtHandle          = new EPStatementHandle(-1, "AbstractCoordinatedAdapter", null, StatementType.ESPERIO, "AbstractCoordinatedAdapter", false, metricsHandle, 0, false, false, spi.ServicesContext.MultiMatchHandlerFactory.GetDefaultHandler());
            var agentInstanceHandle = new EPStatementAgentInstanceHandle(stmtHandle, lockImpl, -1, new StatementAgentInstanceFilterVersion(), null);
            var scheduleCSVHandle   = new EPStatementHandleCallback(agentInstanceHandle, nextScheduleCallback);

            ScheduleSlot nextScheduleSlot;

            if (EventsToSend.IsEmpty())
            {
                if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
                {
                    Log.Debug(".scheduleNextCallback no events to send, scheduling callback in 100 ms");
                }
                nextScheduleSlot = new ScheduleSlot(0, 0);
                _schedulingService.Add(100, scheduleCSVHandle, nextScheduleSlot);
            }
            else
            {
                // Offset is not a function of the currentTime alone.
                var  first     = EventsToSend.First();
                long baseMsec  = _currentTime - _startTime;
                long afterMsec = first.SendTime - baseMsec;
                nextScheduleSlot = first.ScheduleSlot;
                if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
                {
                    Log.Debug(".scheduleNextCallback schedulingCallback in " + afterMsec + " milliseconds");
                }
                _schedulingService.Add(afterMsec, scheduleCSVHandle, nextScheduleSlot);
            }
        }
Exemplo n.º 2
0
        public void Update_updates_item_from_database()
        {
            var options = new DbContextOptionsBuilder <DatabaseContext>()
                          .UseInMemoryDatabase(databaseName: "Update_updates_item_from_database")
                          .Options;

            using (var context = new DatabaseContext(options))
            {
                var scheduling = new Scheduling
                {
                    Day    = DateTime.Today,
                    Hour   = 12,
                    Id     = 1,
                    Status = SchedulingStatus.Active
                };

                var service = new SchedulingService(context, new SchedulingRepository(context));
                service.Add(scheduling);
                Assert.Single(context.Set <Scheduling>().ToList());
                Assert.Equal(12, context.Set <Scheduling>().Single().Hour);

                scheduling.Hour = 13;
                service.Update(1, scheduling);
                Assert.Equal(13, context.Set <Scheduling>().Single().Hour);
            }
        }
Exemplo n.º 3
0
        public void Delete_deletes_from_database()
        {
            var options = new DbContextOptionsBuilder <DatabaseContext>()
                          .UseInMemoryDatabase(databaseName: "Delete_deletes_from_database")
                          .Options;

            using (var context = new DatabaseContext(options))
            {
                var scheduling = new Scheduling
                {
                    Day    = DateTime.Today,
                    Hour   = 12,
                    Status = SchedulingStatus.Active
                };

                var service = new SchedulingService(context, new SchedulingRepository(context));
                service.Add(scheduling);
                Assert.Single(context.Set <Scheduling>().ToList());

                var insertedScheduling = service.GetAll().First();

                service.Delete(insertedScheduling.Id);
                Assert.Empty(context.Set <Scheduling>().ToList());
            }
        }
Exemplo n.º 4
0
        public void Add_writes_to_database()
        {
            var options = new DbContextOptionsBuilder <DatabaseContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            using (var context = new DatabaseContext(options))
            {
                var scheduling = new Scheduling
                {
                    Day    = DateTime.Today,
                    Hour   = 12,
                    Id     = 1,
                    Status = SchedulingStatus.Active,
                    SchedulingRequestId = 1
                };

                var service = new SchedulingService(context, new SchedulingRepository(context));
                service.Add(scheduling);
            }

            using (var context = new DatabaseContext(options))
            {
                Assert.Single(context.Set <Scheduling>().ToList());

                Assert.Equal(1, context.Set <Scheduling>().Single().Id);
            }
        }
Exemplo n.º 5
0
        private void ScheduleNextCallback()
        {
            var nextScheduleCallback = new ProxyScheduleHandleCallback(delegate { ContinueSendingEvents(); });
            var spi           = (EPRuntimeSPI)_runtime;
            var deploymentId  = "CSV-adapter-" + UuidGenerator.Generate();
            var metricsHandle = spi.ServicesContext.MetricReportingService.GetStatementHandle(-1, deploymentId, "AbstractCoordinatedAdapter");
            var lockImpl      = _container.RWLockManager().CreateLock("CSV");
            var stmtHandle    = new EPStatementHandle(
                "AbstractCoordinatedAdapter", deploymentId, -1, null, 0, false, false,
                spi.ServicesContext.MultiMatchHandlerFactory.Make(false, false), false, false, metricsHandle, null, null);
            var agentInstanceHandle = new EPStatementAgentInstanceHandle(stmtHandle, -1, lockImpl);
            var scheduleCSVHandle   = new EPStatementHandleCallbackSchedule(agentInstanceHandle, nextScheduleCallback);

            long nextScheduleSlot;

            if (EventsToSend.IsEmpty())
            {
                if ((ExecutionPathDebugLog.IsDebugEnabled) && (Log.IsDebugEnabled))
                {
                    Log.Debug(".scheduleNextCallback no events to send, scheduling callback in 100 ms");
                }
                nextScheduleSlot = 0L;
                _schedulingService.Add(100, scheduleCSVHandle, nextScheduleSlot);
            }
            else
            {
                // Offset is not a function of the currentTime alone.
                var  first     = EventsToSend.First();
                long baseMsec  = _currentTime - _startTime;
                long afterMsec = first.SendTime - baseMsec;
                nextScheduleSlot = first.ScheduleSlot;
                if ((ExecutionPathDebugLog.IsDebugEnabled) && (Log.IsDebugEnabled))
                {
                    Log.Debug(".scheduleNextCallback schedulingCallback in " + afterMsec + " milliseconds");
                }
                _schedulingService.Add(afterMsec, scheduleCSVHandle, nextScheduleSlot);
            }
        }
Exemplo n.º 6
0
        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;
        }