Esempio n. 1
0
        private static RpcClientProxy GetProxyInner <T>(ServerUri solvedUri, ResolvableUri contextUri)
        {
            RpcClientInterface intf = RpcClientInterfaceFactory <T> .GetOne();

            if (_channels.Count == 0)
            {
                throw new Exception("You *MUST* Register at least 1 client channel at first");
            }

            RpcClientChannel channel;

            if (!_channels.TryGetValue(solvedUri.Protocol, out channel))
            {
                throw new Exception(string.Format("{0} protocol:'{1}' not found", solvedUri.ToString(), solvedUri.Protocol));
            }

            ResolvableUri r    = contextUri as ResolvableUri;
            string        role = r != null ? r.Service : "";
            RpcConnection conn = GetConnection(solvedUri, role);

            RpcClientProxy proxy = new RpcClientProxy(conn, intf, contextUri);

            proxy.Timeout = channel.Timeout;
            return(proxy);
        }
Esempio n. 2
0
        private static RpcClientProxy GetProxyInner(ServerUri solvedUri, ResolvableUri toUri, string serviceName)
        {
            if (_channels.Count == 0)
            {
                throw new Exception("You *MUST* Register at least 1 client channel at first");
            }

            IRpcClientChannel channel;

            if (!_channels.TryGetValue(solvedUri.Protocol, out channel))
            {
                throw new Exception(string.Format("{0} protocol:'{1}' not found", solvedUri.ToString(), solvedUri.Protocol));
            }

            RpcProxyNexus nexus;

            lock (_syncRoot) {
                if (!_nexuses.TryGetValue(solvedUri, out nexus))
                {
                    ResolvableUri r           = toUri as ResolvableUri;
                    string        serviceRole = r != null ? r.Service : "";
                    nexus = new RpcProxyNexus(channel, solvedUri, serviceRole);
                    _nexuses.Add(solvedUri, nexus);
                }
            }

            RpcClientProxy proxy = new RpcClientProxy(nexus, serviceName, toUri);

            return(proxy);
        }
Esempio n. 3
0
 internal RpcBatchItem(RpcBatchServerContext ctx, int i)
 {
     _ctx  = ctx;
     _idx  = i;
     _args = ctx.GetArgs <T>(_idx);
     _uri  = ctx.GetContextUri <ResolvableUri>(_idx);
 }
Esempio n. 4
0
        private static RpcClientProxy GetProxyInner <T>(ServerUri solvedUri, ResolvableUri toUri)
        {
            var attr = AttributeHelper.GetAttribute <RpcServiceAttribute>(typeof(T));

            if (attr == null)
            {
                throw new NotSupportedException("RpcInterface MUST markup with [RpcService] Attribute");
            }

            return(GetProxyInner(solvedUri, toUri, attr.ServiceName));
        }
Esempio n. 5
0
        public T GetContextUri <T>(int index) where T : ResolvableUri
        {
            var u = _requests[index].ContextUri;

            if (!string.IsNullOrEmpty(u))
            {
                return((T)ResolvableUri.Parse(u));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 6
0
        public override bool Equals(object obj)
        {
            ResolvableUri rval = obj as ResolvableUri;

            if (rval == null)
            {
                return(false);
            }
            else
            {
                return(this._serviceName == rval._serviceName &&
                       this._method == rval._method &&
                       this.Protocol == rval.Protocol);
            }
        }
Esempio n. 7
0
 internal RpcClientProxy(RpcConnection conn, RpcClientInterface intf, ResolvableUri toUri)
 {
     _conn             = conn;
     _contextUri       = toUri;
     _serviceInterface = intf;
 }
Esempio n. 8
0
 public static Database GetDatabase(ResolvableUri uri)
 {
     return GetDatabase(uri.Resolve(RouteMethod.Database));
 }
Esempio n. 9
0
        /// <summary>
        ///		通过可路由Uri,获取一个Rpc客户端代理
        /// </summary>
        /// <typeparam name="T">Rpc的声明Interface</typeparam>
        /// <param name="uri">一个可用于路由的Uri实体类,例如IdUri或GroupUri</param>
        /// <returns>Rpc客户端代理类</returns>
        public static RpcClientProxy GetProxy <T>(ResolvableUri uri)
        {
            ServerUri solved = uri.Resolve(RouteMethod.Rpc);

            return(GetProxyInner <T>(solved, uri));
        }
Esempio n. 10
0
 public static Database GetDatabase(ResolvableUri uri)
 {
     return(GetDatabase(uri.Resolve(RouteMethod.Database)));
 }