thread safe message manager
parent
539d6de247
commit
f3a7331ae9
|
@ -1,3 +1,4 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -6,12 +7,12 @@ namespace Encompass
|
|||
{
|
||||
internal class MessageManager
|
||||
{
|
||||
private readonly Dictionary<Type, List<IMessage>> messageTypeToMessages = new Dictionary<Type, List<IMessage>>();
|
||||
private readonly Dictionary<Type, ConcurrentStack<IMessage>> messageTypeToMessages = new Dictionary<Type, ConcurrentStack<IMessage>>();
|
||||
|
||||
internal void RegisterMessageType(Type messageType)
|
||||
{
|
||||
if (!messageTypeToMessages.ContainsKey(messageType)) {
|
||||
messageTypeToMessages.Add(messageType, new List<IMessage>());
|
||||
messageTypeToMessages.Add(messageType, new ConcurrentStack<IMessage>());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,12 +20,12 @@ namespace Encompass
|
|||
{
|
||||
var type = message.GetType();
|
||||
|
||||
messageTypeToMessages[type].Add(message);
|
||||
messageTypeToMessages[type].Push(message);
|
||||
}
|
||||
|
||||
internal void AddMessage<TMessage>(TMessage message) where TMessage : struct, IMessage
|
||||
{
|
||||
messageTypeToMessages[typeof(TMessage)].Add(message);
|
||||
messageTypeToMessages[typeof(TMessage)].Push(message);
|
||||
}
|
||||
|
||||
internal void ClearMessages()
|
||||
|
|
Loading…
Reference in New Issue