http://git-wip-us.apache.org/repos/asf/ignite/blob/4e34f58e/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 new file mode 100644 index 0000000..10746a3 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/JavaObjects/JavaCacheEntryEventFilter.cs @@ -0,0 +1,48 @@ +/* + * 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.Common.JavaObjects +{ + using System; + using System.Collections.Generic; + using Apache.Ignite.Core.Cache.Event; + + /// <summary> + /// Cache entry event filter that delegates to Java. + /// </summary> + /// <typeparam name="TK">Key type.</typeparam> + /// <typeparam name="TV">Value type.</typeparam> + internal class JavaCacheEntryEventFilter<TK, TV> : PlatformJavaObjectFactoryProxy, ICacheEntryEventFilter<TK, TV> + { + /** <inheritdoc /> */ + public bool Evaluate(ICacheEntryEvent<TK, TV> evt) + { + throw new InvalidOperationException(GetType() + " cannot be invoked directly."); + } + + /// <summary> + /// Initializes a new instance of the <see cref="JavaCacheEntryEventFilter{TK, TV}"/> class. + /// </summary> + /// <param name="factoryClassName">Name of the factory class.</param> + /// <param name="properties">The properties.</param> + 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/4e34f58e/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/PlatformJavaObjectFactoryProxy.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/PlatformJavaObjectFactoryProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/PlatformJavaObjectFactoryProxy.cs new file mode 100644 index 0000000..89b2891 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/PlatformJavaObjectFactoryProxy.cs @@ -0,0 +1,106 @@ +/* + * 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.Common +{ + using System; + using System.Collections.Generic; + using Apache.Ignite.Core.Binary; + using Apache.Ignite.Core.Impl.Binary; + + /// <summary> + /// Maps to PlatformJavaObjectFactoryProxy in Java. + /// </summary> + internal class PlatformJavaObjectFactoryProxy : IBinaryWriteAware + { + /// <summary> + /// Represents the factory type. + /// </summary> + internal enum FactoryType + { + User = 0, + Default = 1 + } + + /** Type code. */ + private readonly FactoryType _factoryType; + + /** Java class name */ + private readonly string _factoryClassName; + + /** Optional payload. */ + private readonly object _payload; + + /** Properties to set */ + private readonly IDictionary<string, object> _properties; + + /// <summary> + /// Initializes a new instance of the <see cref="PlatformJavaObjectFactoryProxy" /> 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> + protected PlatformJavaObjectFactoryProxy(FactoryType type, string factoryClassName, object payload, + IDictionary<string, object> properties) + { + _factoryType = type; + _factoryClassName = factoryClassName; + _payload = payload; + _properties = properties; + } + + /// <summary> + /// Initializes a new instance of the <see cref="PlatformJavaObjectFactoryProxy"/> class. + /// </summary> + public PlatformJavaObjectFactoryProxy() + { + throw new InvalidOperationException(GetType() + " should never be deserialized on .NET side."); + } + + /** <inheritdoc /> */ + public void WriteBinary(IBinaryWriter writer) + { + var w = writer.GetRawWriter(); + + w.WriteInt((int) _factoryType); + w.WriteString(_factoryClassName); + w.WriteObject(_payload); + + if (_properties != null) + { + w.WriteInt(_properties.Count); + + foreach (var pair in _properties) + { + w.WriteString(pair.Key); + w.WriteObject(pair.Value); + } + } + else + w.WriteInt(0); + } + + /// <summary> + /// Gets the raw proxy (not the derived type) for serialization. + /// </summary> + public PlatformJavaObjectFactoryProxy GetRawProxy() + { + return new PlatformJavaObjectFactoryProxy(_factoryType, _factoryClassName, _payload, _properties); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/4e34f58e/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..3550ef7 --- /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 readonly string _className; + + /** Properties. */ + private readonly IDictionary<string, object> _properties = new Dictionary<string, object>(); + + /// <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 ?? _properties; + } + + /// <summary> + /// Gets the Java class name. + /// </summary> + public string ClassName + { + get { return _className; } + } + + /// <summary> + /// Gets the properties to be set on the Java object. + /// </summary> + public IDictionary<string, object> Properties + { + get { return _properties; } + } + + /// <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); + } + } +}
