/// <summary> /// Libera a instancia. /// </summary> /// <param name="disposing"></param> private void Dispose(bool disposing) { lock (this) { if (this.SerializationContext != null) { CompactFormatterServices.UnregisterAllCustomCompactTypes(this.SerializationContext); } if (this.ExpiryMgr != null) { this.ExpiryMgr.Dispose(); this.ExpiryMgr = null; } if (this.CacheImpl != null) { this.CacheImpl.Dispose(); this.CacheImpl = null; } if (this.TimeSched != null) { this.TimeSched.Dispose(); this.TimeSched = null; } if (this.AsyncProc != null) { this.AsyncProc.Stop(); this.AsyncProc = null; } if (disposing) { GC.SuppressFinalize(this); } } }
public Battle(BattleParams param, Navmesh navmesh, LuaEnv luaEnv) { this.rid = param.id; this.data = ModelFactory.GetBattleData(Utils.GetIDFromRID(this.rid)); this._luaEnv = luaEnv; this._context = new UpdateContext(); this._entityManager = new EntityManager(this); this._buffManager = new BuffManager(this); this._random = new ConsistentRandom(param.rndSeed); this._pathManager = new NavMeshProxy(); this._timer0 = new TimeScheduler(); this._pathManager.Create(navmesh); if (!string.IsNullOrEmpty(this.data.script)) { this._script = new Script(this, this._luaEnv, this.data.script); this._script.Call(Script.S_ON_BATTLE_INITIALIZED); } this.CreatePlayers(param); foreach (KeyValuePair <string, BattleData.Structure> kv in this.data.structures) { BattleData.Structure def = this.data.structures[kv.Key]; this.CreateBio(def.id, def.pos, def.dir, def.team); } foreach (KeyValuePair <string, BattleData.Neutral> kv in this.data.neutrals) { BattleData.Neutral def = this.data.neutrals[kv.Key]; this.CreateBio(def.id, def.pos, def.dir, def.team); } }
/// <remarks> /// The reason for waiting a random amount of time is that, in the worst case, all members receive a /// STABLE_GOSSIP message from the last outstanding member at the same time and would therefore mcast the /// STABILITY message at the same time too. To avoid this, each member waits random N msecs. If, before N /// elapses, some other member sent the STABILITY message, we just cancel our own message. If, during /// waiting for N msecs to send STABILITY message S1, another STABILITY message S2 is to be sent, we just /// discard S2. /// </remarks> /// <summary> /// Schedules a stability message to be mcast after a random number of milliseconds. /// </summary> /// <param name="tmp">Stable Digest</param> private void sendStabilityMessage(Digest tmp) { long delay; if (timer == null) { if (Trace.trace) { Trace.error("STABLE.sendStabilityMessage()", "timer is null, cannot schedule " + "stability message to be sent"); } timer = stack != null ? stack.timer : null; return; } // give other members a chance to mcast STABILITY message. if we receive STABILITY by the end of // our random sleep, we will not send the STABILITY msg. this prevents that all mbrs mcast a // STABILITY msg at the same time delay = random.Next((int)stability_delay); if (Trace.trace) { Trace.info("STABLE.sendStabilityMessage()", "stability_task=" + stability_task + ", delay is " + delay); } lock (stability_mutex) { if (stability_task != null && !stability_task.cancelled()) // schedule only if not yet running { return; } stability_task = new StabilitySendTask(this, tmp, delay); timer.add(stability_task, true); // run it 1x after delay msecs. use fixed-rate scheduling } }
//TODO: Enable stop on ModelTimeSpan, not just 'tick number' public Task Run(Action <ModelTime> onLoopStep, int stop = -1) { var ct = CancellationTokenSource.Token; var simulationTask = new Task(() => { var aborted = (object)false; var trueBoxed = (object)true; ct.Register(() => { Interlocked.Exchange(ref aborted, trueBoxed); }); while (!(bool)aborted && stop > 0 && stop >= TimeScheduler.CurrentTime.Ticks) { TimeScheduler.SetTime(new ModelTime( TimeScheduler.CurrentTime.Ticks + 1, TimeScheduler.TimeStep, TimeScheduler.CurrentTime.Begin) ); onLoopStep(TimeScheduler.CurrentTime); } Dispose(); }); simulationTask.Start(); return(simulationTask); }
/* ------------------------------- Private Methods -------------------------------------- */ /// <summary> /// Initialises this object /// </summary> /// <param name="sender">The address from which retransmissions are expected</param> /// <param name="cmd">The retransmission callback reference</param> /// <param name="sched">Schedular for retransmit tasks</param> /// <param name="sched_owned">sched_owned whether the scheduler parameter is owned by this object or is externally provided</param> private void init(Address sender, RetransmitCommand cmd, TimeScheduler sched, bool sched_owned) { this.sender = sender; this.cmd = cmd; retransmitter_owned = sched_owned; retransmitter = sched; }
private void UpdateTimeScheduler() { for (var i = 0; i < _timeSchedulers.Count;) { TimeScheduler obj = _timeSchedulers[i]; if (obj.RealTime <= Time.time) { if (obj.Callback != null) { obj.Callback(); } else { _timeSchedulers.RemoveAt(i); continue; } if (obj.IsLoop) { obj.RealTime += obj.Time; } else { _timeSchedulers.RemoveAt(i); continue; } } ++i; } }
private async Task <TimeSpan> LoadFromExternalDatabase() { var table = await _externalDb.FetchAllMembers(Settings.UserName); _logger.LogInfo("Found " + table.Count + " members in databse"); foreach (var member in table) { Members.Add(member.ProfileId, member); switch (member.Status) { case IEMember.MEMBER_NEW: NewItems.Add(member); break; case IEMember.MEMBER_REJECTED: RejectedItems.Add(member); break; default: ActiveItems.Add(member); break; } } NewItems.Sort(); RejectedItems.Sort(); ActiveItems.Sort(); TimeScheduler.GetTimeScheduler().AddTask(DS_TASK_NAME, TimeSpan.FromSeconds(INITIAL_DELAY), () => OnTimedEvent()); return(TimeScheduler.STOP_TIMER); // This stops us being re-scheduled }
/// <summary> /// Uses TimeScheduler from ProtocolSinkStack. /// </summary> public override void start() { timer = stack != null ? stack.timer : null; if (timer == null) { throw new Exception("NAKACK.up(): timer is null"); } }
public void StartDataSource() { // // Start our main scheduler.... // TimeScheduler.GetTimeScheduler().AddTask(DS_TASK_NAME, TimeSpan.FromSeconds(INITIAL_DELAY), () => LoadFromExternalDatabase()); Running = true; }
public TimeScheduler GetTimeScheduler() { var config = new Config(); AppModel appModel = new AppModel(config); var timeScheduler = new TimeScheduler(appModel, config.IntervalInMilliseconds); return(timeScheduler); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or /// resetting unmanaged resources. /// </summary> /// <param name="disposing"></param> private void Dispose(bool disposing) { lock (this) { if (SerializationContext != null) { CompactFormatterServices.UnregisterAllCustomCompactTypes(SerializationContext); } if (PerfStatsColl != null) { PerfStatsColl.Dispose(); PerfStatsColl = null; } if (ExpiryMgr != null) { ExpiryMgr.Dispose(); ExpiryMgr = null; } if (MessageManager != null) { MessageManager.StopMessageProcessing(); MessageManager = null; } if (CacheImpl != null) { CacheImpl.Dispose(); CacheImpl = null; } if (TimeSched != null) { TimeSched.Dispose(); TimeSched = null; } if (AsyncProc != null) { AsyncProc.Stop(); AsyncProc = null; } if (HealthCollectorTimeSched != null) { HealthCollectorTimeSched.Dispose(); HealthCollectorTimeSched = null; } if (disposing) { GC.SuppressFinalize(this); } } }
private void RemoveScheduler(TimeScheduler p_scheduler) { if (p_scheduler != null) { if (SchedulersList.Contains(p_scheduler)) { SchedulersList.Remove(p_scheduler); } Object.Destroy(p_scheduler); } }
/// <summary> /// Sets the Scheduler to the Scheduler present in the ProtocolSinkStack /// </summary> public override void start() { if (stack != null && stack.timer != null) { timer = stack.timer; } else { throw new Exception("STABLE.up(): timer cannot be retrieved from protocol stack"); } }
/// <summary> /// Sets the Scheduler to the Scheduler present in the ProtocolSinkStack /// </summary> public override void start() { timer = stack != null ? stack.timer : null; if (timer == null) { if (Trace.trace) { Trace.error("UNICAST.up()", "[START] timer is null"); } } }
/// <summary> /// Sets the <c>TimeScheduler</c> to be used to the one present in the <c>ProtocolSinkStack</c> /// </summary> public override void init() { if (stack != null && stack.timer != null) { timer = stack.timer; } else if (Trace.trace) { Trace.error("FD.up()", "[START]: timer cannot be retrieved from protocol stack"); } }
/// <summary> /// Sets the TimeScheduler to the instance in the ProtocolSinkStack and /// initialises the GMS implementation if possible. /// </summary> public override void init() { timer = stack != null? stack.timer : null; if (timer == null) { throw new Exception("GMS.init(): timer is null"); } if (impl != null) { impl.init(); } }
public void DevelopTask(string taskToDo) { Console.WriteLine($"{Name} начал делать {taskToDo} в {TimeScheduler.CurrentTime}"); var abort = TimeScheduler.Schedule(ModelTimeSpan.FromModelTimeUnits(3), () => { Console.WriteLine($"{Name} завершил работу над {taskToDo}"); }); AbortCurrentJob = TimeScheduler.Schedule(ModelTimeSpan.FromModelTimeUnits(5), () => { Console.WriteLine($"Остановлена работа над {taskToDo} в {TimeScheduler.CurrentTime}"); }); }
public virtual void TestMorningTime() { IDateTimeProvider dateTimeProvider = new MorningTime(); timeScheduler = new TimeScheduler(dateTimeProvider); bool shallIwork = timeScheduler.ShallIWork01(); Assert.AreEqual(true, shallIwork); shallIwork = (new TimeScheduler(new EveningTime())).ShallIWork01(); Assert.AreEqual(false, shallIwork); }
public void AddTimer(float time, bool loop, System.Action callback) { ++_curAllotID; var timeScheduler = new TimeScheduler { ID = _curAllotID, Time = time, RealTime = time + Time.time, IsLoop = loop, Callback = callback }; _timeSchedulers.Add(timeScheduler); }
/// <summary> /// Constructor: Creates a new instance with the given retransmit command /// </summary> /// <param name="sender">The sender associated with this instance</param> /// <param name="cmd">The command used to retransmit a missing message</param> /// <param name="start_seqno">The first sequence number to be received</param> /// <param name="sched">The external scheduler to use for retransmission</param> public NakReceiverWindow(Address sender, Retransmitter.RetransmitCommand cmd, long start_seqno, TimeScheduler sched) { this.sender = sender; this.cmd = cmd; head = start_seqno; tail = head; if (cmd != null) { retransmitter = sched == null ? new Retransmitter(sender, cmd): new Retransmitter(sender, cmd, sched); } }
/// <summary> Setup this object's state /// /// </summary> /// <param name="cmd">the callback object for retranmissions /// </param> /// <param name="retransmit_timeout">the interval between two consecutive /// retransmission attempts /// </param> /// <param name="sched">the external scheduler to use to schedule retransmissions /// </param> /// <param name="sched_owned">if true, the scheduler is owned by this object and /// can be started/stopped/destroyed. If false, the scheduler is shared /// among multiple objects and start()/stop() should not be called from /// within this object /// /// </param> /// <throws> IllegalArgumentException if <code>cmd</code> is null </throws> private void init(RetransmitCommand cmd, long[] retransmit_intervals, TimeScheduler sched, bool sched_owned) { if (cmd == null) { NCacheLog.Error("AckMcastSenderWindow.init", "command is null. Cannot retransmit " + "messages !"); throw new System.ArgumentException("Command is null."); } retransmitter_owned = sched_owned; retransmitter = sched; this.retransmit_intervals = retransmit_intervals; this.cmd = cmd; start(); }
public void Run(params string[] parameters) { var whiteTime = GetParameter(parameters, "wtime", int.MaxValue); var blackTime = GetParameter(parameters, "btime", int.MaxValue); var colorTime = _uciClient.BoardState.ColorToMove == Color.White ? whiteTime : blackTime; var whiteIncTime = GetParameter(parameters, "winc", 0); var blackIncTime = GetParameter(parameters, "binc", 0); var incTime = _uciClient.BoardState.ColorToMove == Color.White ? whiteIncTime : blackIncTime; var maxColorTime = TimeScheduler.CalculateTimeForMove(colorTime, incTime, _uciClient.BoardState.MovesCount); var depth = GetParameter(parameters, "depth", SearchConstants.MaxDepth - 1); var moveTime = GetParameter(parameters, "movetime", 0); var nodesCount = GetParameter(parameters, "nodes", ulong.MaxValue); var searchMoves = GetParameterWithMoves(parameters, "searchmoves"); var infiniteFlag = GetFlag(parameters, "infinite"); _uciClient.SearchContext = new SearchContext(_uciClient.BoardState) { HelperTasksCancellationTokenSource = new CancellationTokenSource(), MaxDepth = depth + 1, MaxNodesCount = nodesCount, MoveRestrictions = searchMoves }; if (moveTime == 0) { RunAbortTask((int)(maxColorTime * SearchConstants.DeadlineFactor), _uciClient.SearchContext.HelperTasksCancellationTokenSource.Token); } else { _uciClient.SearchContext.WaitForStopCommand = true; maxColorTime = int.MaxValue; RunAbortTask(moveTime, _uciClient.SearchContext.HelperTasksCancellationTokenSource.Token); } if (infiniteFlag) { _uciClient.SearchContext.WaitForStopCommand = true; maxColorTime = int.MaxValue; } _uciClient.SearchContext.MaxTime = maxColorTime; Task.Run(SearchEntryPoint); }
private void testTimeScheduler() { TimeScheduler timer = new TimeScheduler(); TimerTask[] array = new TimerTask[5]; for (int i = 0; i < 5; i++) { array[i] = new TimerTask((i + 1) * 1000, "TimerTask:" + i, 0, 1); timer.add(array[i]); } timer.start(); Console.WriteLine("timer Started."); int seconds = 0; bool running = true; while (running) { seconds++; System.Threading.Thread.Sleep(1000); Console.WriteLine(""); Console.WriteLine("-=-=-=-=- Seconds = " + seconds + "-=-=-=-=-=-=-"); if (seconds == 5) { timer.stop(); System.Threading.Thread.Sleep(3000); timer.start(); } Console.WriteLine(array[0].getName() + " Value = "+ array[0].start); Console.WriteLine(array[1].getName() + " Value = "+ array[1].start); Console.WriteLine(array[2].getName() + " Value = "+ array[2].start); Console.WriteLine(array[3].getName() + " Value = "+ array[3].start); Console.WriteLine(array[4].getName() + " Value = "+ array[4].start); running = false; for (int i = 0; i < 5; i++) { if (!array[i].cancelled()) { running = true; } } } Console.ReadLine(); }
/// <summary> /// Constructor: Create a new Retransmitter associated with the given sender address /// </summary> /// <param name="sender">The address from which retransmissions are expected or to which retransmissions are sent</param> /// <param name="cmd">The retransmission callback reference</param> /// <param name="sched">The retransmissions scheduler</param> public Retransmitter(Address sender, RetransmitCommand cmd, TimeScheduler sched) { init(sender, cmd, sched, false); }
public void StopDataSource() { TimeScheduler.GetTimeScheduler().RemoveTask(DS_TASK_NAME); Running = false; }
static ConnectedClientsLedger() { s_scheduler = new TimeScheduler(true); }
static ClientDeathDetector() { s_scheduler = new TimeScheduler(true); }
public void GetMemberProfile(IEMember member) { TimeScheduler.GetTimeScheduler().AddTask(DS_TASK_NAME + member.ProfileId, TimeSpan.FromSeconds(0), () => InternalGetMemberProfile(member)); }
/// <summary> Create and <b>start</b> the retransmitter /// /// </summary> /// <param name="cmd">the callback object for retranmissions /// </param> /// <param name="sched">the external scheduler to use to schedule retransmissions /// /// </param> /// <throws> IllegalArgumentException if <code>cmd</code> is null </throws> public AckMcastSenderWindow(RetransmitCommand cmd, TimeScheduler sched, ILogger NCacheLog) { this._ncacheLog = NCacheLog; init(cmd, RETRANSMIT_TIMEOUTS, sched, false); }
public void DoNameSearch(string username) { TimeScheduler.GetTimeScheduler().AddTask(DS_TASK_NAME + username, TimeSpan.FromSeconds(0), () => InternalDoNameSearch(username)); }