Example #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);
        }
Example #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);
        }
Example #3
0
        internal static RpcClientChannel GetChannel(ServerUri serverUri)
        {
            RpcClientChannel channel;

            if (!_channels.TryGetValue(serverUri.Protocol, out channel))
            {
                throw new Exception(string.Format("{0} protocol:'{1}' not found", serverUri.ToString(), serverUri.Protocol));
            }
            return(channel);
        }
Example #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));
        }
Example #5
0
        /// <summary>
        ///		获取一个连接
        /// </summary>
        /// <param name="serverUri"></param>
        /// <param name="serviceRole"></param>
        /// <returns></returns>
        public static RpcConnection GetConnection(ServerUri serverUri, string serviceRole)
        {
            RpcClientChannel channel = GetChannel(serverUri);

            RpcConnection conn;

            lock (_syncRoot) {
                if (!_connections.TryGetValue(serverUri, out conn))
                {
                    conn = channel.CreateConnection(serverUri, RpcConnectionMode.Simplex);
                    // conn.ServiceRole =
                    _connections.Add(serverUri, conn);
                }
            }
            return(conn);
        }
Example #6
0
 public static Database GetDatabase(ServerUri uri)
 {
     throw new NotImplementedException();
 }
Example #7
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));
        }
Example #8
0
 /// <summary>
 ///		获取一个Rpc客户端代理
 /// </summary>
 /// <typeparam name="T">Rpc的声明Interface</typeparam>
 /// <param name="uri">服务器的具体网络地址实体类,如: sipc://192.168.1.100:5700</param>
 /// <returns>Rpc客户端代理类</returns>
 public static RpcClientProxy GetProxy <T>(ServerUri uri)
 {
     return(GetProxyInner <T>(uri, null));
 }
Example #9
0
        /// <summary>
        ///		获取一个Rpc客户端代理
        /// </summary>
        /// <typeparam name="T">Rpc的声明Interface</typeparam>
        /// <param name="uri">服务器的具体网络地址,如: sipc://192.168.1.100:5700</param>
        /// <returns>Rpc客户端代理了类</returns>
        public static RpcClientProxy GetProxy <T>(string uri)
        {
            ServerUri u = ServerUri.Parse(uri);

            return(GetProxyInner <T>(u, null));
        }
Example #10
0
        public static RpcClientProxy GetProxyDirect(string uri, string serviceName)
        {
            ServerUri u = ServerUri.Parse(uri);

            return(GetProxyInner(u, null, serviceName));
        }
Example #11
0
 public static Database GetDatabase(ServerUri uri)
 {
     throw new NotImplementedException();
 }