/// <summary> /// Connects to the master and enables this node to receive build requests /// </summary> /// <param name="schedule">the engine schedule</param> /// <returns>true if the operation was successful</returns> internal async Task <bool> ConnectToMasterAsync(EngineSchedule schedule) { Contract.Requires(schedule != null); Contract.Requires(schedule.Scheduler != null); Contract.Requires(schedule.SchedulingQueue != null); Contract.Assert(AttachCompletion.IsCompleted && AttachCompletion.GetAwaiter().GetResult(), "ProcessBuildRequests called before finishing attach on worker"); m_workerPipStateManager = new WorkerServicePipStateManager(this); m_pipTable = schedule.PipTable; m_pipQueue = schedule.SchedulingQueue; m_scheduler = schedule.Scheduler; m_operationTracker = m_scheduler.OperationTracker; m_environment = m_scheduler; m_environment.ContentFingerprinter.FingerprintSalt = BuildStartData.FingerprintSalt; m_environment.State.PipEnvironment.MasterEnvironmentVariables = BuildStartData.EnvironmentVariables; m_resultSerializer = new ExecutionResultSerializer(maxSerializableAbsolutePathIndex: schedule.MaxSerializedAbsolutePath, executionContext: m_scheduler.Context); m_forwardingEventListener = new ForwardingEventListener(this); bool success = await SendAttachCompletedAfterProcessBuildRequestStartedAsync(); // Wait until the build finishes or we discovered that the master is dead success &= await ExitCompletion; success &= !m_hasFailures; if (m_masterFailureMessage != null) { Logger.Log.DistributionWorkerExitFailure(m_appLoggingContext, m_masterFailureMessage); } m_pipQueue.SetAsFinalized(); return(success); }
public async Task RescheduleOnStart() { // Schedule = every 0.1 second // Run for 1 second // Execution takes 1.1 seconds // Total runs should be 1 var count = 0; int workerThreads, portThreads; ThreadPool.GetMaxThreads(out workerThreads, out portThreads); ThreadPool.SetMaxThreads(100, 100); var runTimes = new List <DateTime>(); Action action = () => { runTimes.Add(DateTime.Now); count++; Thread.Sleep(10000); }; var job = JobBuilder.For(action).Repeat.OnInterval(DateTime.Now, TimeSpan.FromSeconds(1), ReschedulePolicy.OnStart).Build(); var scheduler = new Scheduler.Scheduler(); scheduler.AddJob(job); scheduler.Start(); await Task.Delay(TimeSpan.FromSeconds(3.8)); scheduler.Stop(); ThreadPool.SetMaxThreads(workerThreads, portThreads); Assert.AreEqual(3, count); // Starts straight away }
public void Overflow(Event sender, Scheduler.Scheduler scheduler) { this.HasOverflowEvent = false; this.Data.Restart(this.Control.CountUpTiming); // with event handling, we have already covered timers being turned off / countup if (this.Next?.Control.CountUpTiming ?? false && this.Next.Control.Enabled) { // tick countup timers "normally" (not scheduled) if (this.Next?.TickDirect(1) ?? false) { this.Next?.Overflow(null, scheduler); } } if (this.IsSound) { this.FIFO[0]?.TimerOverflow(); this.FIFO[1]?.TimerOverflow(); } if (this.Control.TimerIRQEnable) { this.cpu.IO.IF.Request((Interrupt)((ushort)Interrupt.TimerOverflow << this.index)); } if (!this.Control.CountUpTiming) { this.Trigger(); } }
private void TickFrameSequencer(Event sender, Scheduler.Scheduler scheduler) { this.FrameSequencer++; switch (this.FrameSequencer & 7) { case 0: case 4: foreach (Channel ch in this.Channels) { ch.TickLengthCounter(); } break; case 2: case 6: foreach (Channel ch in this.Channels) { ch.TickLengthCounter(); } this.sq1.DoSweep(); break; case 7: this.sq1.DoEnvelope(); this.sq2.DoEnvelope(); this.noise.DoEnvelope(); break; } sender.Time += FrameSequencerPeriod; scheduler.Push(sender); }
private void InitTimers(Scheduler.Scheduler scheduler) { this.Timers = new cTimer[4]; this.Timers[3] = new cTimer(this, scheduler, 3); this.Timers[2] = new cTimer(this, scheduler, 2, this.Timers[3]); this.Timers[1] = new cTimer(this, scheduler, 1, this.Timers[2]); this.Timers[0] = new cTimer(this, scheduler, 0, this.Timers[1]); }
public cTimer(ARM7TDMI cpu, Scheduler.Scheduler scheduler, int index) { this.cpu = cpu; this.scheduler = scheduler; this.OverflowEvent = new Event(0, this.Overflow); this.index = index; this.Data = new cTMCNT_L(cpu); this.Control = new cTMCNT_H(this, this.Data); this.IsSound = index == 0 || index == 1; }
public async Task AwaitsCorrectly_Complex() { var count1 = 0; var count2 = 0; var count3 = 0; var count4 = 0; var count5 = 0; var count6 = 0; var count7 = 0; var count8 = 0; var count9 = 0; Action action1 = () => count1++; Action action2 = () => count2++; Action action3 = () => count3++; Action action4 = () => count4++; Action action5 = () => count5++; Action action6 = () => count6++; Action action7 = () => count7++; Action action8 = () => count8++; Action action9 = () => count9++; var job1 = JobBuilder.For(action1).Repeat.OnInterval(TimeSpan.FromSeconds(1)).Build(); var job2 = JobBuilder.For(action2).Repeat.OnInterval(TimeSpan.FromSeconds(2)).Build(); var job3 = JobBuilder.For(action3).Repeat.OnInterval(TimeSpan.FromSeconds(3)).Build(); var job4 = JobBuilder.For(action4).Repeat.OnInterval(TimeSpan.FromSeconds(4)).Build(); var job5 = JobBuilder.For(action5).Repeat.OnInterval(TimeSpan.FromSeconds(5)).Build(); var job6 = JobBuilder.For(action6).Repeat.OnInterval(TimeSpan.FromSeconds(6)).Build(); var job7 = JobBuilder.For(action7).Repeat.OnInterval(TimeSpan.FromSeconds(7)).Build(); var job8 = JobBuilder.For(action8).Repeat.OnInterval(TimeSpan.FromSeconds(8)).Build(); var job9 = JobBuilder.For(action9).Repeat.OnInterval(TimeSpan.FromSeconds(9)).Build(); var scheduler = new Scheduler.Scheduler(); scheduler.AddJob(job1); scheduler.AddJob(job2); scheduler.AddJob(job3); scheduler.AddJob(job4); scheduler.AddJob(job5); scheduler.AddJob(job6); scheduler.AddJob(job7); scheduler.AddJob(job8); scheduler.AddJob(job9); scheduler.Start(); var secondsToTest = 20; await Task.Delay(TimeSpan.FromSeconds(secondsToTest).Add(TimeSpan.FromMilliseconds(800))); scheduler.Stop(); Assert.AreEqual(secondsToTest / 1, count1); Assert.AreEqual(secondsToTest / 2, count2); Assert.AreEqual(secondsToTest / 3, count3); Assert.AreEqual(secondsToTest / 4, count4); Assert.AreEqual(secondsToTest / 5, count5); Assert.AreEqual(secondsToTest / 6, count6); Assert.AreEqual(secondsToTest / 7, count7); Assert.AreEqual(secondsToTest / 8, count8); Assert.AreEqual(secondsToTest / 9, count9); }
/// <nodoc /> public SidebandExaminer(LoggingContext loggingContext, Scheduler.Scheduler scheduler, IConfiguration configuration, RootFilter filter) { Contract.Requires(loggingContext != null); Contract.Requires(scheduler != null); Contract.Requires(configuration != null); LoggingContext = loggingContext; Scheduler = scheduler; Configuration = configuration; RootFilter = filter; }
public DataImportBackgroundService(HistoricalPriceImporter historicalPriceImporter, LivePriceImporter livePriceImporter, TradingDayImporter tradingDayImporter) { _HistoricalPriceImporter = historicalPriceImporter; _LivePriceImporter = livePriceImporter; _TradingDayImporter = tradingDayImporter; _Scheduler = new Scheduler.Scheduler(); _Scheduler.AddJob("Import Historical Prices", () => ImportHistoricalPrices(), Schedule.EveryDay().At(20, 00), DateTime.Now); _Scheduler.AddJob("Import Live Prices", () => ImportLivePrices(), Schedule.EveryWeek().OnWeekdays().EveryMinutes(5).From(9, 30).Until(17, 00), DateTime.Now); _Scheduler.AddJob("Import Trading Days", () => ImportTradingDays(), Schedule.EveryMonth().OnLastDay().At(18, 00), DateTime.Now); }
protected override void OnStart(string[] args) { // Initialize the Parse client with your Application ID and .NET Key found on ParseClient.Initialize(Config.ApplicationId, Config.DotNetKey); int dueTo = Config.CurrentContext.AppSettings.SuggestionDueTo; int period = Config.CurrentContext.AppSettings.SuggestionPeriod; int workerAmounts = Config.CurrentContext.AppSettings.SuggestionWorkersAmount; _scheduler = new Scheduler.Scheduler <User>(workerAmounts, dueTo, period); _scheduler.Start(); }
/// <nodoc/> public WorkerNotificationManager(WorkerService workerService, EngineSchedule schedule, IPipExecutionEnvironment environment, DistributionServices services) { WorkerService = workerService; DistributionServices = services; m_scheduler = schedule.Scheduler; m_environment = environment; m_forwardingEventListener = new ForwardingEventListener(this); m_sendCancellationSource = new CancellationTokenSource(); m_pipResultListener = new PipResultListener(this, schedule, environment); m_sendThread = new Thread(() => SendNotifications(m_sendCancellationSource.Token)); }
protected override void OnStart(string[] args) { //LogFactory.Log.Info("Start crawler service"); // Initialize the Parse client with your Application ID and .NET Key found on ParseClient.Initialize(Config.ApplicationId, Config.DotNetKey); int dueTo = Config.CurrentContext.AppSettings.CreawlerDueTo; int period = Config.CurrentContext.AppSettings.CreawlerPeriod; int workerAmounts = Config.CurrentContext.AppSettings.CreawlerWorkersAmount; _scheduler = new Scheduler.Scheduler <Artist>(workerAmounts, dueTo, period); _scheduler.Start(); }
public async Task StartOn_UtcTime() { var count = 0; Action action = () => count++; var job = JobBuilder.For(action).RunOnce(DateTime.UtcNow.Add(TimeSpan.FromSeconds(1))).Build(); var scheduler = new Scheduler.Scheduler(); scheduler.AddJob(job); scheduler.Start(); await Task.Delay(TimeSpan.FromSeconds(1.1)); scheduler.Stop(); Assert.AreEqual(1, count); }
public async Task RepeatWithoutStartTime() { var count = 0; Action action = () => count++; var job = JobBuilder.For(action).Repeat.OnInterval(TimeSpan.FromSeconds(1)).Build(); var scheduler = new Scheduler.Scheduler(); scheduler.AddJob(job); scheduler.Start(); await Task.Delay(TimeSpan.FromSeconds(1.1)); scheduler.Stop(); Assert.AreEqual(1, count); // does not start straight away }
public void CalculateTimeToRunInSeconds() { //arrange Scheduler.Scheduler scheduler = new Scheduler.Scheduler(); DateTime currentDateTime = new DateTime(2018, 06, 11, 21, 30, 00); DateTime expectedDateTime = new DateTime(2018, 06, 11, 21, 30, 30); int interval = 30; //act var actualDateTime = scheduler.CalculateTimeToRunInSeconds(interval, currentDateTime); //assert Assert.AreEqual(expectedDateTime, actualDateTime); }
public async Task AwaitsCorrectly_Simple() { var count = 0; Action action = () => count++; var job = JobBuilder.For(action).Repeat.OnInterval(DateTime.Now, TimeSpan.FromSeconds(1)).Build(); var scheduler = new Scheduler.Scheduler(); scheduler.AddJob(job); scheduler.Start(); await Task.Delay(TimeSpan.FromSeconds(5.8)); scheduler.Stop(); Assert.AreEqual(1 + 5, count); // Starts straight away }
public void Tick(Event sender, Scheduler.Scheduler scheduler) { this.OnTick(); if (!this.SoundOn()) { this.CurrentSample = 0; } else { this.CurrentSample = this.GetSample(); } sender.Time += this.Period; scheduler.Push(sender); }
public APU(ARM7TDMI cpu, Scheduler.Scheduler scheduler) { this.Channels = new Channel[] { sq1, sq2, wave, noise }; this.FIFO[0] = this.FIFOA = new FIFOChannel(cpu, 0x0400_00a0); this.FIFO[1] = this.FIFOB = new FIFOChannel(cpu, 0x0400_00a4); // initial APU events scheduler.Push(new Event(FrameSequencerPeriod, this.TickFrameSequencer)); foreach (Channel ch in this.Channels) { scheduler.Push(new Event(ch.Period, ch.Tick)); } scheduler.Push(new Event(SamplePeriod, this.ProvideSample)); }
/// <summary> /// Runs Scheduler if is actived. /// </summary> public static void RunSchedule() { try { Scheduler.Scheduler scheduler = new Scheduler.Scheduler(1); Scheduler.Scheduler.KeepRunning = true; Scheduler.Scheduler.KeepThreadAlive = true; System.Threading.Thread RequestScheduleThread = null; RequestScheduleThread = new System.Threading.Thread(Scheduler.Scheduler.Start); RequestScheduleThread.IsBackground = true; RequestScheduleThread.Start(); } catch { } }
protected override void OnStart(string[] args) { log.Info("Starting..."); try { //Set current directory to assembly folder System.Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); ServerStateService svcState = new ServerStateService(); RemotingServices.Marshal(svcState, "rServerStateService"); svcState.AfterPropertiesSet(); // Force Spring to load configuration ContextRegistry.GetContext(); // Define channel security IEnumerator channelEnum = ChannelServices.RegisteredChannels.GetEnumerator(); while (channelEnum.MoveNext()) { BasicChannelWithSecurity channel = channelEnum.Current as BasicChannelWithSecurity; if (channel != null) { channel.ITransportContext.IKeyStore.SetKey("/BAUMAX/SES", new KeyProvider_SelfEstablishingSymmetric()); } } Baumax.AppServer.Environment.ServerEnvironment.Configure(); Scheduler.Scheduler sch = new Scheduler.Scheduler(); sch.AfterPropertiesSet(); svcState.ServerReady = true; log.Info("Server listening..."); } catch (Exception e) { log.Fatal(e); // how to (should we) inform starter about failure during startup? // currently starting from service explorer causes just message // that service was started and then ended right after that throw; } }
internal void Start(EngineSchedule schedule) { Contract.Requires(schedule != null); Contract.Requires(schedule.Scheduler != null); Contract.Requires(schedule.SchedulingQueue != null); Contract.Assert(AttachCompletion.IsCompleted && AttachCompletion.GetAwaiter().GetResult(), "ProcessBuildRequests called before finishing attach on worker"); m_workerPipStateManager = new WorkerServicePipStateManager(this); m_pipTable = schedule.PipTable; m_pipQueue = schedule.SchedulingQueue; m_scheduler = schedule.Scheduler; m_operationTracker = m_scheduler.OperationTracker; m_environment = m_scheduler; m_environment.ContentFingerprinter.FingerprintSalt = BuildStartData.FingerprintSalt; m_environment.State.PipEnvironment.MasterEnvironmentVariables = BuildStartData.EnvironmentVariables; m_resultSerializer = new ExecutionResultSerializer(maxSerializableAbsolutePathIndex: schedule.MaxSerializedAbsolutePath, executionContext: m_scheduler.Context); m_forwardingEventListener = new ForwardingEventListener(this); }
/// <summary> /// Returns a new EngineState updating the SchedulerState with new RootFilter and FilterPassingNodes /// The current instance becomes unusable after this call. /// </summary> /// <returns>The updated engine state </returns> public EngineState WithUpdatedSchedulerState(Scheduler.Scheduler scheduler) { Contract.Requires(!IsDisposed); m_schedulerState?.Dispose(); IsDisposed = true; return(new EngineState( m_graphId, m_stringTable, m_pathTable, m_symbolTable, m_qualifierTable, m_pipTable, m_pipGraph, m_mountPathExpander, new SchedulerState(scheduler), m_historicTableSizes, m_fileContentTable)); }
static void Main(string[] args) { log.Info("Starting..."); try { ServerStateService svcState = new ServerStateService(); RemotingServices.Marshal(svcState, "rServerStateService"); svcState.AfterPropertiesSet(); // Force Spring to load configuration IApplicationContext ctx = ContextRegistry.GetContext(); // Define channel security IEnumerator channelEnum = ChannelServices.RegisteredChannels.GetEnumerator(); while (channelEnum.MoveNext()) { BasicChannelWithSecurity channel = channelEnum.Current as BasicChannelWithSecurity; if (channel != null) { channel.ITransportContext.IKeyStore.SetKey("/BAUMAX/SES", new KeyProvider_SelfEstablishingSymmetric()); } } Baumax.AppServer.Environment.ServerEnvironment.Configure(); Scheduler.Scheduler sch = new Scheduler.Scheduler(); sch.AfterPropertiesSet(); svcState.ServerReady = true; log.Info("Server listening..."); } catch (Exception e) { log.Fatal(e); } finally { System.Console.Out.WriteLine("--- Press <return> to quit ---"); System.Console.ReadLine(); } }
public async Task RescheduleOnFinish() { // Schedule = every 0.1 second // Run for 1 second // Execution takes 1.1 seconds // Total runs should be 1 var runTimes = new List <DateTime>(); var count = 0; Action action = () => { runTimes.Add(DateTime.Now); count++; Thread.Sleep(1100); }; var job = JobBuilder.For(action).Repeat.OnInterval(TimeSpan.FromSeconds(0.1)).Build(); var scheduler = new Scheduler.Scheduler(); scheduler.AddJob(job); scheduler.Start(); await Task.Delay(TimeSpan.FromSeconds(1)); scheduler.Stop(); Assert.AreEqual(1, count); // Starts straight away }
public ARM7TDMI(GBA gba, Scheduler.Scheduler scheduler) { this.gba = gba; this.Pipeline = new cPipeline(this); this.InitARM(); this.InitTHUMB(); this.InitTimers(scheduler); // IO requires bus to be initialized this.bus = new BUS(this); this.IO = new IORAMSection(); // DMAChannels require bus AND IO to be initialized this.DMAChannels[0] = new DMAChannel(this, 0); this.DMAChannels[1] = new DMAChannel(this, 1); this.DMAChannels[2] = new DMAChannel(this, 2); this.DMAChannels[3] = new DMAChannel(this, 3); // mem requires IO AND DMAChannels to be initialized this.mem = new MEM(this); this.SystemBank = new uint[16]; this.FIQBank = new uint[16]; this.SupervisorBank = new uint[16]; // this.AbortBank = new uint[16]; this.IRQBank = new uint[16]; // this.UndefinedBank = new uint[16]; this.state = State.ARM; // need banked registers for CPSR initialization this.CPSR = 0x0000005F; this.PipelineFlush(); this.PC += 4; }
/// <summary> /// Updates the SchedulerState with new RootFilter and FilterPassingNodes /// </summary> public void UpdateSchedulerState(Scheduler.Scheduler scheduler) { m_schedulerState.Dispose(); m_schedulerState = new SchedulerState(scheduler); }
private static Scheduler.Scheduler CreateScheduler( IWaitGroupFactory waitGroupFactory ) { if (waitGroupFactory == null) { throw new ArgumentNullException("waitGroupFactory"); } var tf = new HighestPriorityThreadFactory( ); var l = new TextSchedulerLogger( Console.WriteLine ); var scheduler = new Scheduler.Scheduler( waitGroupFactory, tf, l ); return scheduler; }
public static void RunSchedule() { try { Scheduler.Scheduler scheduler = new Scheduler.Scheduler(1); Scheduler.Scheduler.KeepRunning = true; Scheduler.Scheduler.KeepThreadAlive = true; System.Threading.Thread RequestScheduleThread = null; RequestScheduleThread = new System.Threading.Thread(Scheduler.Scheduler.Start); RequestScheduleThread.IsBackground = true; RequestScheduleThread.Start(); } catch { } }
public ServerInformationToConsoleTask(Scheduler.Scheduler scheduler) : base(scheduler) { }
internal NotifyOrchestratorExecutionLogTarget(WorkerNotificationManager notificationManager, EngineSchedule engineSchedule) : this(new NotifyStream(notificationManager), engineSchedule.Context, engineSchedule.Scheduler.PipGraph.GraphId, engineSchedule.Scheduler.PipGraph.MaxAbsolutePathIndex) { m_scheduler = engineSchedule?.Scheduler; m_scheduler?.AddExecutionLogTarget(this); }
public cTimer(ARM7TDMI cpu, Scheduler.Scheduler scheduler, int index, cTimer Next) : this(cpu, scheduler, index) { this.Next = Next; }
private void ProvideSample(Event sender, Scheduler.Scheduler scheduler) { int SampleLeft = 0, SampleRight = 0; for (int i = 0; i < 4; i++) { if (!ExternalChannelEnable[i]) { continue; } if (this.MasterEnableRight[i]) { SampleRight += this.Channels[i].CurrentSample; } if (this.MasterEnableLeft[i]) { SampleLeft += this.Channels[i].CurrentSample; } } // SOUNDCNT_L volume control does not affect FIFO channels SampleRight = (int)((SampleRight * this.MasterVolumeRight) / 8); SampleLeft = (int)((SampleLeft * this.MasterVolumeLeft) / 8); switch (this.Sound1_4Volume) { case 0: // 25% SampleLeft >>= 2; SampleRight >>= 2; break; case 1: // 50% SampleLeft >>= 1; SampleRight >>= 1; break; default: // 100% / prohibited break; } /* * GBATek: * Each of the two FIFOs can span the FULL output range (+/-200h). * Each of the four PSGs can span one QUARTER of the output range (+/-80h). * So we multiply the output of the FIFO by 4 */ for (int i = 0; i < 2; i++) { if (!ExternalFIFOEnable[i]) { continue; } if (this.DMAEnableRight[i]) { SampleRight += this.FIFO[i].CurrentSample << (this.DMASoundVolume[i] ? 1 : 2); // false = 50%, true = 100% } if (this.DMAEnableLeft[i]) { SampleLeft += this.FIFO[i].CurrentSample << (this.DMASoundVolume[i] ? 1 : 2); // false = 50%, true = 100% } } SampleRight = (int)(SampleRight * Amplitude); SampleLeft = (int)(SampleLeft * Amplitude); if (this.ExternalEnable) { SpinWait.SpinUntil(() => this.speaker.NeedMoreSamples); // prevent buffer overflow this.speaker.AddSample((short)SampleLeft, (short)SampleRight); } sender.Time += SamplePeriod; scheduler.Push(sender); }