public static bool Remove(K key, Action <V> value, string groupId = "") { var group = BroadcastTunnel <K, V> .GetGroup(groupId); if (null == group) { return(false); } Manager mgr; if (!group.TryGetValue(key, out mgr)) { return(false); } bool ret = mgr.container.Remove(value); if (0 == mgr.container.Count) { group.Remove(key); if (0 == group.Count) { BroadcastTunnel <K, V> .RemoveGroup(groupId); } } return(ret); }
public static void ChangeGroup(string groupId, string newGroupId) { var group = BroadcastTunnel <K, V> .GetGroup(groupId); if (null == group) { return; } var groups = BroadcastTunnel <K, V> .groups; groups.Remove(groupId); groups[newGroupId] = group; }
public static void RemoveAll() { var groupIds = BroadcastTunnel <K, V> .GetGroupIds(); if (null == groupIds) { return; } foreach (var groupId in groupIds) { BroadcastTunnel <K, V> .RemoveGroup(groupId); } }
public static void Notify(K key, V arg, string groupId = "") { var group = BroadcastTunnel <K, V> .GetGroup(groupId); if (null == group) { return; } Manager mgr; if (group.TryGetValue(key, out mgr)) { BroadcastTunnel <K, V> .DoNotify(mgr, arg); } }
public static bool RemoveAllByKey(K key, string groupId = "") { var group = BroadcastTunnel <K, V> .GetGroup(groupId); if (null == group) { return(false); } bool ret = group.Remove(key); if (0 == group.Count) { BroadcastTunnel <K, V> .RemoveGroup(groupId); } return(ret); }
static void RemoveGroup(string groupId) { var group = BroadcastTunnel <K, V> .GetGroup(groupId); if (null == group) { return; } foreach (var mgr in group.Values) { mgr.container.Clear(); } group.Clear(); var groups = BroadcastTunnel <K, V> .groups; groups.Remove(groupId); }
static void DoNotify(Manager mgr, V arg) { var queue = mgr.queue; if (0 < queue.Count) { mgr.nextCall.AddLast(arg); return; } var enumerator = mgr.container.GetEnumerator(); while (enumerator.MoveNext()) { queue.AddLast(enumerator.Current); } var node = queue.First; var nodeTemp = node; while (null != node) { var action = node.Value; nodeTemp = node; node = node.Next; queue.Remove(nodeTemp); if (null != action) { action(arg); } } if (0 < mgr.nextCall.Count) { var nextCallNode = mgr.nextCall.First; var nextCallArg = nextCallNode.Value; mgr.nextCall.Remove(nextCallNode); BroadcastTunnel <K, V> .DoNotify(mgr, nextCallArg); } }
public static void Add(K key, Action <V> receiver, string groupId = "") { var group = BroadcastTunnel <K, V> .GetGroup(groupId); if (null == group) { group = BroadcastTunnel <K, V> .AddGroup(groupId); } Manager mgr; if (!group.TryGetValue(key, out mgr)) { group.Add(key, mgr = new Manager()); } if (!mgr.container.Contains(receiver)) { mgr.container.Add(receiver); } }
public static void Adds(K key, Action <V>[] receivers, string groupId = "") { var group = BroadcastTunnel <K, V> .GetGroup(groupId); if (null == group) { group = BroadcastTunnel <K, V> .AddGroup(groupId); } Manager mgr; if (!group.TryGetValue(key, out mgr)) { group.Add(key, mgr = new Manager()); } for (int n = 0, cnt = receivers.Length; n < cnt; ++n) { if (!mgr.container.Contains(receivers[n])) { mgr.container.Add(receivers[n]); } } }
public static void RemoveAllByGroup(string groupId = "") { BroadcastTunnel <K, V> .RemoveGroup(groupId); }