예제 #1
0
        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);
        }
예제 #2
0
        public RpcServiceDecorator(T serviceObj, string serviceName) : base(string.Empty)
        {
            Type intf = typeof(T);

            if (!intf.IsInterface)
            {
                throw new NotSupportedException();
            }

            RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf);

            if (!string.IsNullOrEmpty(serviceName))
            {
                p_serviceName = serviceName;
            }
            else
            {
                p_serviceName = serviceAttr.ServiceName;
            }

            _serviceObj = serviceObj;
            _methods    = new HybridDictionary <string, RpcServiceMethod>();

            bool enableCounter = serviceAttr.EnableCounters == RpcPerformanceCounterMode.Both || serviceAttr.EnableCounters == RpcPerformanceCounterMode.Server;

            IICPerformanceCounterCategory category = new IICPerformanceCounterCategory("rpc:" + p_serviceName, PerformanceCounterCategoryType.MultiInstance);

            foreach (MethodInfo method in intf.GetMethods())
            {
                string           methodName = method.Name;
                RpcServiceMethod m;

                RpcServiceBatchMethodAttribute battr = AttributeHelper.TryGetAttribute <RpcServiceBatchMethodAttribute>(method);
                if (battr != null)
                {
                    if (!string.IsNullOrEmpty(battr.MethodName))
                    {
                        methodName = battr.MethodName;
                    }

                    m = new RpcServiceBatchMethod(serviceObj, category, methodName, method, enableCounter);
                }
                else
                {
                    RpcServiceMethodAttribute attr = AttributeHelper.GetAttribute <RpcServiceMethodAttribute>(method);
                    if (!string.IsNullOrEmpty(attr.MethodName))
                    {
                        methodName = attr.MethodName;
                    }

                    m = new RpcServiceMethod(serviceObj, category, methodName, method, enableCounter);
                }

                _methods.Add(methodName, m);
            }
            IICPerformanceCounterFactory.GetCounters(category);
        }