public void SendInMessage(Message message) { if (!IsOpened) { Open(); } _messageQueue.Enqueue(new KeyValuePair <DateTimeOffset, Message>(message.LocalTime, message)); }
public void TakeTest_EnqueueMessage() { BlockingPriorityQueue <PeerMessageReceivedArgs> prioQ = new BlockingPriorityQueue <PeerMessageReceivedArgs>(); PeerMessageReceivedArgs higherPriorityMsg = new PeerMessageReceivedArgs(); PeerMessageReceivedArgs msg = new PeerMessageReceivedArgs(); prioQ.Enqueue(msg, 1); prioQ.Enqueue(higherPriorityMsg, 0); var out01 = prioQ.Take(); Assert.NotNull(out01); Assert.Equal(out01, higherPriorityMsg); var out02 = prioQ.Take(); Assert.NotNull(out02); Assert.Equal(out02, msg); }
public void DequeueTest() { var threads = new List <Thread>(); threads.Add(new Thread(() => intQueue.Enqueue(1, 5))); threads.Add(new Thread(() => intQueue.Enqueue(2, 4))); threads.Add(new Thread(() => intQueue.Enqueue(3, 6))); foreach (var thread in threads) { thread.Start(); } foreach (var thread in threads) { thread.Join(); } Assert.AreEqual(3, intQueue.Dequeue()); Assert.AreEqual(1, intQueue.Dequeue()); Assert.AreEqual(2, intQueue.Dequeue()); }
/// <summary> /// Send message. /// </summary> /// <param name="message">Message.</param> public void SendInMessage(Message message) { if (!IsOpened) { throw new InvalidOperationException(); } //if (!(message is TimeMessage) && message.GetType().Name != "BasketMessage") // Console.WriteLine(">> ({0}) {1}", System.Threading.Thread.CurrentThread.Name, message); _msgStat.Add(message); _messageQueue.Enqueue(new KeyValuePair <DateTimeOffset, Message>(message.LocalTime, message)); }
private void HandleNewMessage(object sender, EventArgs e) { if (e is PeerMessageReceivedArgs args) { if (args.Message.Type == (int)AElfProtocolMsgType.Block) { // If we get a block deserialize it here to stop the request timer asap var block = HandleBlockReception(args.Message.Payload, args.Peer); if (block == null) { return; } args.Block = block; } else if (CurrentSyncSource != null && CurrentSyncSource.IsSyncingHistory && args.Message.Type == (int)AElfProtocolMsgType.NewTransaction) { return; } _incomingJobs.Enqueue(args, 0); } }
private void EnqueueMessage(Message message) { _messageQueue.Enqueue(new KeyValuePair <DateTimeOffset, Message>(message.LocalTime, message)); }
void IMessageProcessor.EnqueueMessage(Message message, IMessageAdapter adapter, bool force) { _msgStat.Add(message); _messageQueue.Enqueue(new Pair(message.LocalTime, new MessageItem(message, adapter)), force); }
/// <summary> /// Adds the specified event to the simulation. /// </summary> /// <param name="ev">The event instance to add to the simulation.</param> public static void AddEvent(Event ev) { WriteLine(OutputLevel.Simulation, "Adding \"" + ev + "\" with expiry time = " + ev.Time + " ns."); events.Enqueue(ev); }