/// <summary> /// 启动TCP注册服务客户端 /// </summary> internal void Start() { bool isStart = false; Monitor.Enter(clientLock); try { if (registerReaderClient != null) { close(); if ((clientId = registerReaderClient.register().Value).Tick != 0) { isStart = getLog(); } } } catch (Exception error) { fastCSharp.log.Error.Add(error, null, false); } finally { Monitor.Exit(clientLock); } fastCSharp.log.Default.Add("TCP注册客户端启动 " + (isStart ? "成功" : "失败"), new System.Diagnostics.StackFrame(), false); if (!isStart && registerReaderClient != null) { fastCSharp.threading.timerTask.Default.Add(this, thread.callType.TcpRegisterClientStart, fastCSharp.date.nowTime.Now.AddSeconds(2)); } }
private void removeRegister(clientId clientId) { if (clientId.Tick == logStream.Ticks && clientPool.Enter()) { if (clientPool.Pool[clientId.Identity.Index].Free(clientId.Identity.Identity)) { clientPool.FreeExit(clientId.Identity.Index); subArray <string> removeNames = default(subArray <string>); Monitor.Enter(serviceLock); try { foreach (services service in serviceCache.Values.getArray()) { hashString serviceName = service.Name; if (removeRegister(clientId.Identity, service, ref serviceName)) { removeNames.Add(service.Name); } } } finally { Monitor.Exit(serviceLock); } if (removeNames.length != 0) { fastCSharp.log.Default.Add("TCP服务 " + removeNames.ToArray().joinString(',') + " 被注销", null, false); } } else { clientPool.Exit(); } } }
private registerResult register(clientId clientId, service service) { if (getClient(ref clientId) == null) { return new registerResult { State = registerState.ClientError } } ; if (!service.Host.HostToIpAddress()) { return new registerResult { State = registerState.HostError } } ; services services; hashString serviceName = service.Name; Monitor.Enter(serviceLock); try { if (serviceCache.TryGetValue(serviceName, out services)) { return(register(clientId.Identity, service, services, ref serviceName)); } getPort(clientId.Identity, ref service.Host, true); if (service.Host.Port == 0) { return new registerResult { State = registerState.PortError } } ; if (service.IsCheck && hostClients.ContainsKey(service.Host)) { return new registerResult { State = registerState.HostExists } } ; hostClients[service.Host] = clientId.Identity; services = new services { Name = service.Name, Hosts = new host[] { service.Host }, IsSingle = service.IsSingle }; serviceCache.Add(serviceName, services); appendLog(new log { Type = log.type.HostChanged, Services = new services { Name = service.Name, Hosts = new host[] { service.Host } } }); } finally { Monitor.Exit(serviceLock); } return(new registerResult { State = registerState.Success, Service = service }); }
/// <summary> /// TCP服务端轮询 /// </summary> /// <param name="clientId">TCP服务端标识</param> /// <param name="logIdentity">日志编号</param> /// <param name="onLog">TCP服务注册通知委托</param> internal void GetLog(ref clientId clientId, int logIdentity, Func <fastCSharp.net.returnValue <log>, bool> onLog) { clientInfo client = getClient(ref clientId); if (client != null) { onLog = Interlocked.Exchange(ref client.OnLog, onLog); if (onLog == null) { logStream.Get(logIdentity, client.OnLogHandle); } else { onLog(log.NewGetter); } return; } onLog(log.ClientError); }
private void removeRegister(clientId clientId, string serviceName) { if (getClient(ref clientId) != null) { services services; hashString nameKey = serviceName; bool isRemove = false; Monitor.Enter(serviceLock); try { if (serviceCache.TryGetValue(nameKey, out services)) { isRemove = removeRegister(clientId.Identity, services, ref nameKey); } } finally { Monitor.Exit(serviceLock); } if (isRemove) { fastCSharp.log.Default.Add("TCP服务 " + serviceName + " 被注销", new System.Diagnostics.StackFrame(), false); } } }
private void getLog(clientId clientId, int logIdentity, Func <fastCSharp.net.returnValue <log>, bool> onLog) { TcpRegister.GetLog(ref clientId, logIdentity, onLog); }
/// <summary> /// 获取客户端 /// </summary> /// <param name="clientId"></param> /// <returns></returns> private clientInfo getClient(ref clientId clientId) { return(clientId.Tick == logStream.Ticks ? getClient(clientId.Identity) : null); }
var entry = await _index.Get(clientId, CreateClientInfo).ConfigureAwait(false);
=> await repository.CreateWithCheck(clientId, appointmentEntity);
=> Apply(new LogCreated(logLevel, message, clientId, LogId));