Esempio n. 1
0
        public void Handle(NetClient netclient, GatewayCommand cmd)
        {
            var keys    = cmd.Content.FromJson <string[]>();
            var service = _gateway.GetServiceById(cmd.Header["ServiceId"]);

            if (service != null && service.Host == ((IPEndPoint)netclient.Socket.RemoteEndPoint).Address.ToString())
            {
                List <string> failed = new List <string>();
                foreach (var key in keys)
                {
                    if (_lockKeyManager.TryLock(key, service, false) == false)
                    {
                        failed.Add(key);
                    }
                }
                SystemEventCenter.OnMicroServiceUploadLockedKeyCompleted(service);
                netclient.WriteServiceData(new InvokeResult
                {
                    Success = true,
                    Data    = failed.ToArray()
                });
            }
            else
            {
                netclient.WriteServiceData(new InvokeResult
                {
                    Success = false
                });
            }
        }
Esempio n. 2
0
        public void Handle(NetClient netclient, GatewayCommand cmd)
        {
            var info = cmd.Content.FromJson <LockKeyInfo>();

            if (info.IsUnlock && info.MicroServiceId == "$$$")
            {
                //强制释放
                _lockKeyManager.UnLock(info.Key, null);
                netclient.WriteServiceData(new InvokeResult
                {
                    Success = true
                });
                return;
            }

            var service = _gateway.GetServiceById(info.MicroServiceId);

            if (service == null)
            {
                netclient.WriteServiceData(new InvokeResult
                {
                    Success = false,
                    Data    = $"找不到注册的服务{info.MicroServiceId}"
                });
                return;
            }

            try
            {
                if (info.IsUnlock)
                {
                    netclient.WriteServiceData(new InvokeResult
                    {
                        Success = _lockKeyManager.UnLock(info.Key, service)
                    });
                    return;
                }

                if (_lockKeyManager.TryLock(info.Key, service))
                {
                    netclient.WriteServiceData(new InvokeResult
                    {
                        Success = true,
                        Data    = _lockKeyManager.KeyTimeout
                    });
                }
                else
                {
                    netclient.WriteServiceData(new InvokeResult
                    {
                        Success = false
                    });
                }
            }
            catch (Exception ex)
            {
                netclient.WriteServiceData(new InvokeResult
                {
                    Success = false,
                    Data    = ex.Message
                });
            }
        }