public static void RegisterService <T>(string serviceName, T service) { lock (_syncRoot) { RpcServiceDecorator <T> realService = new RpcServiceDecorator <T>(service); _services.Add(serviceName, realService); } }
/// <summary> /// 注册继承自rpc interface的服务 /// </summary> /// <typeparam name="T">interface的类型</typeparam> /// <param name="service">服务对象</param> /// <remarks>每个类型的服务对象仅能注册一次</remarks> public static void RegisterService <T>(T service) { // 适配器 RpcServiceDecorator <T> realService = new RpcServiceDecorator <T>(service); _dispatcher.RegisterService(realService); }
public RpcServiceDecorator(T serviceObj) : base(string.Empty) { Type intf = typeof(T); if (!intf.IsInterface) { throw new NotSupportedException(); } RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf); p_serviceName = serviceAttr.ServiceName; _serviceObj = serviceObj; IICPerformanceCounterCategory category = new IICPerformanceCounterCategory("rpc:" + p_serviceName, PerformanceCounterCategoryType.MultiInstance); foreach (MethodInfo method in intf.GetMethods()) { RpcServiceMethodAttribute methodAttr = AttributeHelper.GetAttribute <RpcServiceMethodAttribute>(method); string methodName = method.Name; RpcServiceMethod m = new RpcServiceDecorator <T> .RpcServiceMethod(); m.RatePerSecond = category.CreateCounter(methodName + " /sec.", PerformanceCounterType.RateOfCountsPerSecond32); m.TotalCount = category.CreateCounter(methodName + " Total.", PerformanceCounterType.NumberOfItems32); m.TotalFailed = category.CreateCounter(methodName + " Failed.", PerformanceCounterType.NumberOfItems32); m.Concurrent = category.CreateCounter(methodName + " Concurrent.", PerformanceCounterType.NumberOfItems32); m.Method = method; _methods.Add(methodName, m); } IICPerformanceCounterFactory.GetCounters(category); }
/// <summary> /// 注册继承自rpc interface的服务,并用ServiceName覆盖服务名 /// </summary> /// <typeparam name="T">interface的类型</typeparam> /// <param name="serviceName">服务名></param> /// <param name="service">服务对象</param> /// <remarks>每个类型的服务对象仅能注册一次</remarks> public static void RegisterService <T>(string serviceName, T service) { RpcServiceDecorator <T> realService = new RpcServiceDecorator <T>(service, serviceName); _dispatcher.RegisterService(realService); }