天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB

using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Text;
using QM.Exchange.Interface;
namespace QM.Exchange.Core
{
/// <summary>
/// 注册中心
/// </summary>
public class RegisterCenter
{
private static ConcurrentDictionary<string, Worker> WorkerList = new ConcurrentDictionary<string, Worker>();
/// <summary>
/// 注册工作节点
/// </summary>
public static void RegisterWorker(string sessionID, string clientHostName,Worker info)
{
//注册列表
Worker workNode = info;
workNode.SessionID = sessionID;
workNode.HostName = clientHostName;
WorkerList.TryAdd(sessionID, workNode);
}
/// <summary>
/// 获取工作节点列表
/// </summary>
public static List<Worker> GetWokerList()
{
List<Worker> workers = new List<Worker>();
foreach (Worker w in WorkerList.Values)
{
workers.Add(w);
}
return workers;
}
/// <summary>
/// 注销工作节点
/// </summary>
/// <param name="sessionIDArray">会话ID列表</param>
public static void LogoffWorker(List<string> sessionIDArray)
{
Worker w = null;
foreach (string sessionID in sessionIDArray)
{
WorkerList.TryRemove(sessionID, out w);
}
}
}
}