Ejemplo n.º 1
0
        private async Task <object> Exec(string serviceName, string route, object[] args, Dictionary <string, string> meta, Type returnValueType)
        {
            ServiceNodeInfo node;

            if (UraganoSettings.IsDevelopment)
            {
                node = new ServiceNodeInfo {
                    Address = UraganoSettings.ServerSettings.IP.ToString(), Port = UraganoSettings.ServerSettings.Port
                }
            }
            ;
            else
            {
                node = await LoadBalancing.GetNextNode(serviceName);
            }
            var client = await ClientFactory.CreateClientAsync(node.Address, node.Port);

            var result = await client.SendAsync(new InvokeMessage(route, args, meta));

            if (result.Status != RemotingStatus.Ok)
            {
                throw new RemoteInvokeException(route, result.Result?.ToString(), result.Status);
            }
            if (returnValueType == null)
            {
                return(null);
            }
            return(result.Result);
        }
Ejemplo n.º 2
0
        private static ServiceNodeInfo[] ParseServiceNodes(GraphNode[] nodes)
        {
            if (nodes == null)
            {
                return(null);
            }

            List <ServiceNodeInfo> serviceNodes = new List <ServiceNodeInfo>();

            for (int i = 0; i < nodes.Length; i++)
            {
                ComponentModel node = (ComponentModel)nodes[i];
                if (typeof(IService).IsAssignableFrom(node.Service))
                {
                    ServiceNodeInfo serviceNode = new ServiceNodeInfo();
                    serviceNode.Key            = node.Name;
                    serviceNode.Sevice         = node.Service.FullName;
                    serviceNode.Implementation = node.Implementation.FullName;
                    serviceNodes.Add(serviceNode);
                }
            }

            return(serviceNodes.ToArray());
        }
Ejemplo n.º 3
0
 private static int GetCurrentWeightValue(ServiceNodeInfo node)
 {
     return(!node.Attach.TryGetValue(Key, out var val) ? 0 : Convert.ToInt32(val));
 }