You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/07/14 17:19:21 UTC

[GitHub] [ignite] ptupitsyn commented on a diff in pull request #10145: IGNITE-17296 .NET: Platform service interceptor.

ptupitsyn commented on code in PR #10145:
URL: https://github.com/apache/ignite/pull/10145#discussion_r921342159


##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/PlatformTestServiceInterceptor.cs:
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Tests.Services
+{
+    using System;
+    using Apache.Ignite.Core.Services;
+
+    /** Test service call interceptor. */
+    [Serializable]

Review Comment:
   Not necessary, let's remove.



##########
modules/platforms/dotnet/Apache.Ignite.Core/Services/ServiceConfiguration.cs:
##########
@@ -66,6 +69,12 @@ public class ServiceConfiguration
         /// </summary>
         public IClusterNodeFilter NodeFilter { get; set; }
         
+        /// <summary>
+        /// Gets or sets service call interceptors.
+        /// </summary>
+        [IgniteExperimental]
+        public IReadOnlyCollection<IServiceCallInterceptor> Interceptors { get; set; }

Review Comment:
   ```suggestion
           public ICollection<IServiceCallInterceptor> Interceptors { get; set; }
   ```
   
   1. Consistent with other configuration APIs.
   2. No need for read-only here.



##########
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/CompositeServiceCallInterceptor.cs:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl.Services
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Diagnostics;
+    using Apache.Ignite.Core.Impl.Common;
+    using Apache.Ignite.Core.Services;
+
+    /// <summary>
+    /// Composite service call interceptor.
+    /// </summary>
+    /// <seealso cref="IServiceCallInterceptor"/>
+    [Serializable]
+    internal class CompositeServiceCallInterceptor : IServiceCallInterceptor
+    {
+        // Service call interceptors.
+        private readonly IEnumerable<IServiceCallInterceptor> _interceptors;

Review Comment:
   ```suggestion
           private readonly ICollection<IServiceCallInterceptor> _interceptors;
   ```
   
   `IEnumerable` may be lazily evaluated. To make the intent cleaner, let's require `ICollection` in constructor and store it this way.



##########
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs:
##########
@@ -1021,18 +1022,21 @@ private long ServiceInit(long memPtr)
 
                     var srvKeepBinary = reader.ReadBoolean();
                     var svc = reader.ReadObject<IService>();
+                    var interceptors = reader.ReadCollection();

Review Comment:
   ```suggestion
                       var interceptors = reader.ReadCollectionAsList<IServiceCallInterceptor>();
   ```



##########
modules/platforms/dotnet/Apache.Ignite.Core/Services/ServiceConfiguration.cs:
##########
@@ -91,6 +100,11 @@ internal void Write(IBinaryRawWriter w)
                 w.WriteObject(NodeFilter);
             else
                 w.WriteObject<object>(null);
+            
+            if (Interceptors != null)
+                w.WriteCollection(Interceptors as ICollection);
+            else
+                w.WriteObject<object>(null);;

Review Comment:
   ```suggestion
                   w.WriteObject<object>(null);
   ```



##########
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs:
##########
@@ -1051,22 +1055,37 @@ private long ServiceInit(long memPtr)
             }
         }
 
+        /// <summary>
+        /// Wraps a collection of interceptors into a composite interceptor.
+        /// </summary>
+        /// <param name="interceptors">Service call interceptors.</param>
+        /// <returns>Composite service call interceptor or null.</returns>
+        private IServiceCallInterceptor WrapInterceptors(ICollection interceptors)

Review Comment:
   ```suggestion
           private IServiceCallInterceptor WrapInterceptors(IList<IServiceCallInterceptor> interceptors)
   ```



##########
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/CompositeServiceCallInterceptor.cs:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl.Services
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Diagnostics;
+    using Apache.Ignite.Core.Impl.Common;
+    using Apache.Ignite.Core.Services;
+
+    /// <summary>
+    /// Composite service call interceptor.
+    /// </summary>
+    /// <seealso cref="IServiceCallInterceptor"/>
+    [Serializable]

Review Comment:
   Not necessary, please remove.



##########
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs:
##########
@@ -1051,22 +1055,37 @@ private long ServiceInit(long memPtr)
             }
         }
 
+        /// <summary>
+        /// Wraps a collection of interceptors into a composite interceptor.
+        /// </summary>
+        /// <param name="interceptors">Service call interceptors.</param>
+        /// <returns>Composite service call interceptor or null.</returns>
+        private IServiceCallInterceptor WrapInterceptors(ICollection interceptors)
+        {
+            if (interceptors == null)
+                return null;
+            
+            // Inject Ignite instance resource.
+            foreach (var interceptor in interceptors)
+                ResourceProcessor.Inject(interceptor, _ignite);
+
+            // Wrap into a composite interceptor if necessary.
+            return interceptors.Count == 1 ? interceptors.OfType<IServiceCallInterceptor>().First() :
+                new CompositeServiceCallInterceptor(interceptors.OfType<IServiceCallInterceptor>());

Review Comment:
   ```suggestion
               return interceptors.Count == 1 ? interceptors[0] : new CompositeServiceCallInterceptor(interceptors);
   ```



##########
modules/platforms/dotnet/Apache.Ignite.Core/Services/ServiceConfiguration.cs:
##########
@@ -91,6 +100,11 @@ internal void Write(IBinaryRawWriter w)
                 w.WriteObject(NodeFilter);
             else
                 w.WriteObject<object>(null);
+            
+            if (Interceptors != null)
+                w.WriteCollection(Interceptors as ICollection);

Review Comment:
   This cast can return null when, because `ICollection<T>` does not inherit from `ICollection`.
   Let's add a generic overload for `WriteCollection` to avoid this cast.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org