public void AddChannelListener(int channel, ChatDelegate chatListener) { _factoryQ.QWork("Add chat listener to channel " + channel + ".", () => { lock (_chatListeners) { if (!_chatListeners.ContainsKey(channel)) { _chatListeners.Add(channel, new List <ChatDelegate>()); } _chatListeners[channel].Add(chatListener); } }); }
public VPacket(IPacket packet, IVNode from, IVNode to, IVLink link, IPrimFactory primFactory, IAsynchQueue queue, View view) : base(primFactory, from.Pos, packet.Name, packet.Colour, packet.Selected, packet.Parameters) { Prim.Editable = false; _packet = packet; _from = from; _to = to; _link = link; _step = 0; _view = view; Selected = packet.Selected; Configure(); _deleteListener = id => Dropped("Visualisation layer dropped " + Name + "."); _from.OnWorldMove += (id, oldPos, newPos) => Reconfigure(); _to.OnWorldMove += (id, oldPos, newPos) => Reconfigure(); _from.OnAPIMove += (id, oldPos, newPos) => Reconfigure(); _to.OnAPIMove += (id, oldPos, newPos) => Reconfigure(); link.OnWeightChanged += (id, weight) => Reconfigure(); link.OnWorldDelete += _deleteListener; link.OnSystemDelete += _deleteListener; //_tickListener = () => queue.QueueWorkItem(state => UpdatePosition()); _tickListener = () => queue.QWork("Move Packet", () => UpdatePosition()); view.OnTick += _tickListener; }
private void OnChange(string reason, UUID l, int evt, bool visualise) { _processedEvents.Add(evt); if (Model.IsPaused && IsCurrentAlgorithm) { _eventQ.QWork(Name + " Link State " + reason, () => { Say(reason + ". Link State running Dijkstra's algorithm."); RunAlgorithm(Name + " Link State " + reason + ".", null, Equals(DijkstraNode.VisualisedNode)); QueueUpdateBroadcast(l, reason, evt, visualise); }); } else { RunAlgorithm(Name + "Link State " + reason + ".", null, Equals(DijkstraNode.VisualisedNode)); QueueUpdateBroadcast(l, reason, evt, visualise); } }
private void ProcessRemoteCall(string methodName, int id, object[] parameters) { _methodProcessingQueue.QWork("Call " + methodName, () => { MethodInfo method = WrappedInstance.GetType().GetMethod(methodName, GetTypes(parameters)); if (method.ReturnParameter.Equals(typeof(void))) { method.Invoke(WrappedInstance, parameters); } else { _returnValues.Add(id, method.Invoke(WrappedInstance, parameters)); } }); }
private void QueueNextEvent() { if (_stopped || !_reader.HasNextEvent || _controlUtil.Paused) { return; } _queue.QWork("Process sequenceEvent", () => { JM726.Lib.Static.Util.Wait(_reader.NextEventWait, !_stopped && _reader.NextEventWait > 0, _reader); if (!_stopped && !_controlUtil.Paused) { _reader.PlayNextEvent(false); QueueNextEvent(); } }); }
internal void RunAlgorithm(string description, IMNodeInternal to, bool visualise) { _visualise = visualise; ResetAlgorithm(); if (_visualise && IsCurrentAlgorithm) { _visualiseThread = new Thread(() => RunAlgorithm(to)); _visualiseThread.Name = description; _visualiseThread.Start(); } else { _queue.QWork(GetType().Name + " " + description, () => RunAlgorithm(to)); } }
/// <summary> /// Find the shortest path to every other node. TTL is specified so that if the request was started by receiving a packet it won't be propogated forever. /// </summary> /// <param name="TTL"></param> private void findShortestPaths(int TTL, string msg, bool visualise) { _queue.QWork(Name + " recalculating shortest paths.", () => { Logger.Debug(Name + " " + msg + ". Processing."); List <string> changes = new List <string>(); foreach (IMNodeInternal n in KnownNodes) { if (!n.ID.Equals(ID)) { findShortestPath(n, changes); } } bool step = false; if (Model.IsPaused && IsCurrentAlgorithm) { if (changes.Count > 0) { Say("DV processing routes after " + msg + ". " + changes.Count + " changes necessary."); foreach (var change in changes) { Say(change); } } else { step = true; } } if (ShouldPrint(visualise)) { PrintDistanceVector(msg); } Logger.Info(Name + " processed " + msg + " " + changes.Count + " changes made to the forwarding table."); if (changes.Count > 0 && TTL > 0) { QueueBroadcastUpdate(TTL, msg, visualise); } if (step) { new Thread(() => _queue.Step()).Start(); } }); }