Refactor public API

Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/282af980
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/282af980
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/282af980

Branch: refs/heads/ignite-2977
Commit: 282af9808c9f53fd67fff6f3322c264f5afdd1d6
Parents: 0f376d7
Author: Pavel Tupitsyn <[email protected]>
Authored: Wed Apr 13 12:43:14 2016 +0300
Committer: Pavel Tupitsyn <[email protected]>
Committed: Wed Apr 13 12:43:14 2016 +0300

----------------------------------------------------------------------
 .../Continuous/ContinuousQueryJavaFilterTest.cs | 15 ++--
 .../Apache.Ignite.Core.csproj                   |  2 +-
 .../Common/JavaObjectFactory.cs                 | 79 -----------------
 .../JavaObjects/JavaCacheEntryEventFilter.cs    |  6 +-
 .../Apache.Ignite.Core/Interop/JavaObject.cs    | 92 ++++++++++++++++++++
 5 files changed, 105 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/282af980/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
----------------------------------------------------------------------
diff --git 
a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
 
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
index 9febfa90..580d19f 100644
--- 
a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
+++ 
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
@@ -23,6 +23,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous
     using Apache.Ignite.Core.Cache.Event;
     using Apache.Ignite.Core.Cache.Query.Continuous;
     using Apache.Ignite.Core.Common;
+    using Apache.Ignite.Core.Interop;
     using NUnit.Framework;
 
     /// <summary>
@@ -94,9 +95,12 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous
         [Test]
         public void TestFilter()
         {
-            var filter = JavaObjectFactory.CreateCacheEntryEventFilter<int, 
string>(
-                "org.apache.ignite.platform.PlatformCacheEntryEventFilter",
-                new Dictionary<string, object> {{"startsWith", "valid"}});
+            var javaObj = new 
JavaObject("org.apache.ignite.platform.PlatformCacheEntryEventFilter")
+            {
+                Properties = new Dictionary<string, object> {{"startsWith", 
"valid"}}
+            };
+
+            var filter = javaObj.ToCacheEntryEventFilter<int, string>();
 
             TestFilter(filter);
         }
@@ -107,10 +111,11 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous
         [Test]
         public void TestFactory()
         {
-            var filter = 
JavaObjectFactory.CreateCacheEntryEventFilterFactory<int, string>(
-                
"org.apache.ignite.platform.PlatformCacheEntryEventFilterFactory",
+            var javaObj = new 
JavaObject("org.apache.ignite.platform.PlatformCacheEntryEventFilterFactory",
                 new Dictionary<string, object> {{"startsWith", "valid"}});
 
+            var filter = javaObj.ToCacheEntryEventFilter<int, string>();
+
             TestFilter(filter);
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/282af980/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
----------------------------------------------------------------------
diff --git 
a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj 
b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
index 6b42e7e..fcb3c44 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
@@ -92,7 +92,6 @@
     <Compile Include="Cache\CacheException.cs" />
     <Compile Include="Cache\CachePartialUpdateException.cs" />
     <Compile Include="Cache\CachePeekMode.cs" />
-    <Compile Include="Common\JavaObjectFactory.cs" />
     <Compile Include="DataStructures\Configuration\AtomicConfiguration.cs" />
     <Compile Include="Cache\Configuration\QueryAlias.cs" />
     <Compile Include="Cache\Configuration\QueryTextFieldAttribute.cs" />
@@ -397,6 +396,7 @@
     <Compile Include="Impl\Unmanaged\UnmanagedNonReleaseableTarget.cs" />
     <Compile Include="Impl\Unmanaged\UnmanagedTarget.cs" />
     <Compile Include="Impl\Unmanaged\UnmanagedUtils.cs" />
+    <Compile Include="Interop\JavaObject.cs" />
     <Compile Include="Lifecycle\Package-Info.cs" />
     <Compile Include="Messaging\Package-Info.cs" />
     <Compile Include="Package-Info.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/282af980/modules/platforms/dotnet/Apache.Ignite.Core/Common/JavaObjectFactory.cs
----------------------------------------------------------------------
diff --git 
a/modules/platforms/dotnet/Apache.Ignite.Core/Common/JavaObjectFactory.cs 
b/modules/platforms/dotnet/Apache.Ignite.Core/Common/JavaObjectFactory.cs
deleted file mode 100644
index 2c0faac..0000000
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Common/JavaObjectFactory.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.Common
-{
-    using System.Collections.Generic;
-    using Apache.Ignite.Core.Cache.Event;
-    using Apache.Ignite.Core.Impl.Common;
-    using Apache.Ignite.Core.Impl.Common.JavaObjects;
-
-    /// <summary>
-    /// Creates Java object wrappers.
-    /// Resulting predicates and filters delegate to specified Java classes, 
and can be used on non-.NET nodes.
-    /// </summary>
-    public static class JavaObjectFactory
-    {
-        /// <summary>
-        /// Creates the cache event filter that delegates to specified Java 
class.
-        /// </summary>
-        /// <typeparam name="TK">Key type.</typeparam>
-        /// <typeparam name="TV">Value type.</typeparam>
-        /// <param name="className">Name of the class.</param>
-        /// <returns>
-        /// Cache event filter that delegates to specified Java class.
-        /// </returns>
-        public static ICacheEntryEventFilter<TK, TV> 
CreateCacheEntryEventFilter<TK, TV>(string className)
-        {
-            return CreateCacheEntryEventFilter<TK, TV>(className, null);
-        }
-
-        /// <summary>
-        /// Creates the cache event filter that delegates to specified Java 
class.
-        /// </summary>
-        /// <typeparam name="TK">Key type.</typeparam>
-        /// <typeparam name="TV">Value type.</typeparam>
-        /// <param name="className">Name of the class.</param>
-        /// <param name="properties">The properties to set on the Java 
object.</param>
-        /// <returns>
-        /// Cache event filter that delegates to specified Java class.
-        /// </returns>
-        public static ICacheEntryEventFilter<TK, TV> 
CreateCacheEntryEventFilter<TK, TV>(string className, 
-            IDictionary<string, object> properties)
-        {
-            return new JavaCacheEntryEventFilter<TK, 
TV>(PlatformJavaObjectFactoryProxy.FactoryType.Default, null, 
-                className, properties);
-        }
-
-        /// <summary>
-        /// Creates the cache event filter that delegates to specified Java 
filter factory.
-        /// </summary>
-        /// <typeparam name="TK">Key type.</typeparam>
-        /// <typeparam name="TV">Value type.</typeparam>
-        /// <param name="className">Name of the factory class.</param>
-        /// <param name="properties">The properties to set on the Java factory 
object.</param>
-        /// <returns>
-        /// Cache event filter that delegates to specified Java factory class.
-        /// </returns>
-        public static ICacheEntryEventFilter<TK, TV> 
CreateCacheEntryEventFilterFactory<TK, TV>(string className, 
-            IDictionary<string, object> properties)
-        {
-            return new JavaCacheEntryEventFilter<TK, 
TV>(PlatformJavaObjectFactoryProxy.FactoryType.User, className,
-                null, properties);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/282af980/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/JavaObjects/JavaCacheEntryEventFilter.cs
----------------------------------------------------------------------
diff --git 
a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/JavaObjects/JavaCacheEntryEventFilter.cs
 
b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/JavaObjects/JavaCacheEntryEventFilter.cs
index 56ebfca..10746a3 100644
--- 
a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/JavaObjects/JavaCacheEntryEventFilter.cs
+++ 
b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/JavaObjects/JavaCacheEntryEventFilter.cs
@@ -37,12 +37,10 @@ namespace Apache.Ignite.Core.Impl.Common.JavaObjects
         /// <summary>
         /// Initializes a new instance of the <see 
cref="JavaCacheEntryEventFilter{TK, TV}"/> class.
         /// </summary>
-        /// <param name="type">The type.</param>
         /// <param name="factoryClassName">Name of the factory class.</param>
-        /// <param name="payload">The payload.</param>
         /// <param name="properties">The properties.</param>
-        public JavaCacheEntryEventFilter(FactoryType type, string 
factoryClassName, object payload,
-            IDictionary<string, object> properties) : base(type, 
factoryClassName, payload, properties)
+        public JavaCacheEntryEventFilter(string factoryClassName, 
IDictionary<string, object> properties) 
+            : base(FactoryType.User, factoryClassName, null, properties)
         {
             // No-op.
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/282af980/modules/platforms/dotnet/Apache.Ignite.Core/Interop/JavaObject.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Interop/JavaObject.cs 
b/modules/platforms/dotnet/Apache.Ignite.Core/Interop/JavaObject.cs
new file mode 100644
index 0000000..97f536a
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Interop/JavaObject.cs
@@ -0,0 +1,92 @@
+/*
+ * 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.Interop
+{
+    using System.Collections.Generic;
+    using Apache.Ignite.Core.Cache.Event;
+    using Apache.Ignite.Core.Impl.Common;
+    using Apache.Ignite.Core.Impl.Common.JavaObjects;
+
+    /// <summary>
+    /// Represents a Java object wrapper.
+    /// <para />
+    /// <see cref="JavaObject"/> can be converted to Ignite filters and 
predicates 
+    /// which can be used on non-.NET Ignite nodes.
+    /// <para />
+    /// Workflow is as follows:
+    /// Instantiate specified Java class;
+    /// Set property values;
+    /// If the resulting object implements PlatformJavaObjectFactory, call 
create() method and use the result,
+    /// otherwise use the original object.
+    /// </summary>
+    public class JavaObject
+    {
+        /** Java class name. */
+        private string _className;
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="JavaObject"/> class.
+        /// </summary>
+        /// <param name="className">Name of the Java class.</param>
+        public JavaObject(string className)
+        {
+            IgniteArgumentCheck.NotNullOrEmpty(className, "className");
+
+            ClassName = className;
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="JavaObject"/> class.
+        /// </summary>
+        /// <param name="className">Name of the Java class.</param>
+        /// <param name="properties">The properties to set on the Java 
object.</param>
+        public JavaObject(string className, IDictionary<string, object> 
properties) : this(className)
+        {
+            Properties = properties;
+        }
+
+        /// <summary>
+        /// Gets or sets the Java class name.
+        /// </summary>
+        public string ClassName
+        {
+            get { return _className; }
+            set
+            {
+                IgniteArgumentCheck.NotNullOrEmpty(value, "value");
+
+                _className = value;
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets the properties to be set on the Java object.
+        /// </summary>
+        public IDictionary<string, object> Properties { get; set; }
+
+        /// <summary>
+        /// Creates the cache event filter that delegates to the corresponding 
Java object.
+        /// </summary>
+        /// <typeparam name="TK">Key type.</typeparam>
+        /// <typeparam name="TV">Value type.</typeparam>
+        public ICacheEntryEventFilter<TK, TV> ToCacheEntryEventFilter<TK, TV>()
+        {
+            return new JavaCacheEntryEventFilter<TK, TV>(ClassName, 
Properties);
+        }
+    }
+}

Reply via email to