/// <summary>
        /// ディープクローンを生成します。
        /// </summary>
        /// <returns></returns>
        internal GrpcServiceBuilderSettings CreateDeepClone()
        {
            GrpcServiceBuilderSettings clone = this.MemberwiseClone() as GrpcServiceBuilderSettings;

            clone.m_InvokingInterceptors = new List <IGrpcServerMethodInvokingInterceptor>();
            clone.m_InvokingInterceptors.AddRange(m_InvokingInterceptors);

            clone.m_InvokedInterceptors = new List <IGrpcServerMethodInvokedInterceptor>();
            clone.m_InvokedInterceptors.AddRange(m_InvokedInterceptors);

            clone.m_ExceptionHandlers = new List <IGrpcServerMethodExceptionHandler>();
            clone.m_ExceptionHandlers.AddRange(m_ExceptionHandlers);

            return(clone);
        }
Ejemplo n.º 2
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="serviceName">サービス名</param>
            /// <param name="serviceType">サービスの型</param>
            /// <param name="serviceInstance">サービスインスタンス</param>
            /// <param name="methodType">サービスメソッドの種類</param>
            /// <param name="requestType">リクエストの型</param>
            /// <param name="responseType">レスポンスの型</param>
            /// <param name="methodImpl">メソッド実装</param>
            /// <param name="settings">動作設定</param>
            /// <param name="invokingInterceptors">メソッド呼び出し前の割込処理</param>
            /// <param name="invokedInterceptors">メソッド呼び出し後の割込処理</param>
            /// <param name="exceptionHandlers">例外ハンドラ</param>
            internal MethodBuildContext(string serviceName, Type serviceType, object serviceInstance, MethodType methodType, Type requestType, Type responseType, MethodInfo methodImpl, GrpcServiceBuilderSettings settings
                                        , IEnumerable <IGrpcServerMethodInvokingInterceptor> invokingInterceptors, IEnumerable <IGrpcServerMethodInvokedInterceptor> invokedInterceptors, IEnumerable <IGrpcServerMethodExceptionHandler> exceptionHandlers)
            {
                m_ServiceName          = serviceName;
                m_ServiceType          = serviceType;
                m_ServiceInstance      = serviceInstance;
                m_MethodImpl           = methodImpl;
                m_MethodType           = methodType;
                m_RequestType          = requestType;
                m_ResponseType         = responseType;
                m_Settings             = settings;
                m_InvokingInterceptors = invokingInterceptors;
                m_InvokedInterceptors  = invokedInterceptors;
                m_ExceptionHandlers    = exceptionHandlers;

                m_NeedNotifyPerformanceLog = GetNeedNotifyPerformanceLog(methodImpl);
            }
Ejemplo n.º 3
0
        /// <summary>
        /// 指定された型に対するサービス定義を生成します。
        /// </summary>
        /// <param name="serviceName">サービス名</param>
        /// <param name="serviceType">サービスの型</param>
        /// <param name="serviceInstance">サービスインスタンス</param>
        /// <param name="settings">動作設定</param>
        /// <returns></returns>
        public ServerServiceDefinition BuildService(string serviceName, Type serviceType, object serviceInstance, GrpcServiceBuilderSettings settings)
        {
            settings = settings ?? new GrpcServiceBuilderSettings();

            ServerServiceDefinition.Builder builder = ServerServiceDefinition.CreateBuilder();

            Type implType = serviceInstance.GetType();

            IList <IGrpcServerMethodInvokingInterceptor> classInvokingInterceptors = GetInvokingInterceptors(implType);
            IList <IGrpcServerMethodInvokedInterceptor>  classInvokedInterceptors  = GetInvokedInterceptors(implType);

            foreach (GrpcMethodHandlerInfo method in GrpcReflection.EnumerateServiceMethods(implType))
            {
                IList <IGrpcServerMethodInvokingInterceptor> methodInvokingInterceptors = GetInvokingInterceptors(method.Handler);
                IList <IGrpcServerMethodInvokedInterceptor>  methodInvokedInterceptors  = GetInvokedInterceptors(method.Handler);

                MethodBuildContext context = new MethodBuildContext(serviceName, serviceType, serviceInstance, method.MethodType, method.RequestType, method.ResponseType, method.Handler, settings
                                                                    , Sort <IGrpcServerMethodInvokingInterceptor>(CompareInterceptor, new IEnumerable <IGrpcServerMethodInvokingInterceptor>[] { settings.InvokingInterceptors, classInvokingInterceptors, methodInvokingInterceptors })
                                                                    , Sort <IGrpcServerMethodInvokedInterceptor>(CompareInterceptor, new IEnumerable <IGrpcServerMethodInvokedInterceptor>[] { settings.InvokedInterceptors, classInvokedInterceptors, methodInvokedInterceptors })
                                                                    , Sort <IGrpcServerMethodExceptionHandler>(CompareInterceptor, new IEnumerable <IGrpcServerMethodExceptionHandler>[] { settings.ExceptionHandlers })
                                                                    );

                AddServiceMethod(builder, context);
            }

            return(builder.Build());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 指定されたメソッドに対するマーシャラーを生成します。
        /// </summary>
        /// <typeparam name="T">オブジェクトの型</typeparam>
        /// <param name="serviceName">サービス名</param>
        /// <param name="methodName">メソッド名</param>
        /// <param name="performanceListener">パフォーマンスリスナー</param>
        /// <param name="settings">動作設定</param>
        /// <returns>マーシャラ</returns>
        private Marshaller <T> CreateMethodMarshaller <T>(string serviceName, string methodName, GrpcServerPerformanceListener performanceListener, GrpcServiceBuilderSettings settings)
        {
            Marshaller <T> marshaller = settings.GetMarshallerFactoryOrDefault().GetMarshaller <T>();

            if (performanceListener == null)
            {
                return(marshaller);
            }

            string typeName = typeof(T).Name;

            return(new Marshaller <T>(

                       delegate(T arg)
            {
                try
                {
                    Stopwatch watch = Stopwatch.StartNew();
                    byte[] data = marshaller.Serializer(arg);
                    performanceListener.NotifySerialized(serviceName, methodName, typeName, GrpcPerformanceListener.GetMilliseconds(watch), data == null ? 0 : data.Length);
                    return data;
                }
                catch (Exception ex)
                {
                    GrpcExceptionListener.NotifyCatchSerializerException(serviceName, methodName, typeof(T), ex);
                    throw new GrpcSerializerException(ex.Message, ex, serviceName, methodName, typeName);
                }
            }

                       , delegate(byte[] data)
            {
                try
                {
                    Stopwatch watch = Stopwatch.StartNew();
                    T arg = marshaller.Deserializer(data);
                    performanceListener.NotifyDeserialized(serviceName, methodName, typeName, GrpcPerformanceListener.GetMilliseconds(watch), data == null ? 0 : data.Length);
                    return arg;
                }
                catch (Exception ex)
                {
                    GrpcExceptionListener.NotifyCatchSerializerException(serviceName, methodName, typeof(T), ex);
                    throw new GrpcSerializerException(ex.Message, ex, serviceName, methodName, typeName);
                }
            }

                       ));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 指定された型に対するサービス定義を生成します。
 /// </summary>
 /// <param name="serviceType">サービスの型</param>
 /// <param name="serviceInstance">サービスインスタンス</param>
 /// <param name="settings">動作設定</param>
 /// <returns></returns>
 public ServerServiceDefinition BuildService(Type serviceType, object serviceInstance, GrpcServiceBuilderSettings settings)
 {
     return(BuildService(null, serviceType, serviceInstance, settings));
 }