Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 04EC217B14 for ; Thu, 3 Sep 2015 02:16:42 +0000 (UTC) Received: (qmail 25262 invoked by uid 500); 3 Sep 2015 02:16:41 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 25179 invoked by uid 500); 3 Sep 2015 02:16:41 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 24990 invoked by uid 99); 3 Sep 2015 02:16:41 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Sep 2015 02:16:41 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 864D0E7E2D; Thu, 3 Sep 2015 02:16:41 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akuznetsov@apache.org To: commits@ignite.apache.org Date: Thu, 03 Sep 2015 02:16:46 -0000 Message-Id: <5cb578a0345a4ecf84a6cb9afb6f0074@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [06/15] ignite git commit: IGNITE-1356: Moved platforms Java public API to Ignite. IGNITE-1356: Moved platforms Java public API to Ignite. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/86ab3a73 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/86ab3a73 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/86ab3a73 Branch: refs/heads/ignite-843 Commit: 86ab3a7349c1bb46d88eb375866a00fc8f048c06 Parents: da29a70 Author: vozerov-gridgain Authored: Wed Sep 2 13:54:28 2015 +0300 Committer: vozerov-gridgain Committed: Wed Sep 2 13:54:28 2015 +0300 ---------------------------------------------------------------------- .../configuration/PlatformConfiguration.java | 2 +- .../dotnet/PlatformDotNetCacheStore.java | 497 +++++++++++++++++++ .../platform/cpp/PlatformCppConfiguration.java | 47 ++ .../dotnet/PlatformDotNetCacheStoreFactory.java | 139 ++++++ .../dotnet/PlatformDotNetConfiguration.java | 119 +++++ .../dotnet/PlatformDotNetLifecycleBean.java | 109 ++++ .../PlatformDotNetPortableConfiguration.java | 228 +++++++++ ...PlatformDotNetPortableTypeConfiguration.java | 248 +++++++++ 8 files changed, 1388 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/86ab3a73/modules/core/src/main/java/org/apache/ignite/configuration/PlatformConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/PlatformConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/PlatformConfiguration.java index 20eb124..2b142d1 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/PlatformConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/PlatformConfiguration.java @@ -20,6 +20,6 @@ package org.apache.ignite.configuration; /** * Platform configuration marker interface. */ -public class PlatformConfiguration { +public interface PlatformConfiguration { // No-op. } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/86ab3a73/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java new file mode 100644 index 0000000..c86de5d --- /dev/null +++ b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java @@ -0,0 +1,497 @@ +/* + * 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. + */ + +package org.apache.ignite.internal.processors.platform.dotnet; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.store.CacheStore; +import org.apache.ignite.cache.store.CacheStoreSession; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.portable.PortableRawReaderEx; +import org.apache.ignite.internal.portable.PortableRawWriterEx; +import org.apache.ignite.internal.processors.platform.PlatformContext; +import org.apache.ignite.internal.processors.platform.cache.store.PlatformCacheStore; +import org.apache.ignite.internal.processors.platform.cache.store.PlatformCacheStoreCallback; +import org.apache.ignite.internal.processors.platform.memory.PlatformMemory; +import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream; +import org.apache.ignite.internal.processors.platform.utils.PlatformUtils; +import org.apache.ignite.internal.util.lang.GridMapEntry; +import org.apache.ignite.internal.util.lang.GridTuple; +import org.apache.ignite.internal.util.lang.IgniteInClosureX; +import org.apache.ignite.internal.util.typedef.C1; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.A; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiInClosure; +import org.apache.ignite.resources.CacheStoreSessionResource; +import org.jetbrains.annotations.Nullable; + +import javax.cache.Cache; +import javax.cache.integration.CacheLoaderException; +import javax.cache.integration.CacheWriterException; +import java.util.AbstractMap; +import java.util.AbstractSet; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * Wrapper for .NET cache store implementations. + *

+ * This wrapper should be used if you have an implementation of + * {@code GridGain.Cache.IGridCacheStore} interface in .NET and + * would like to configure it a persistence storage for your cache. + * If properly configured, this wrapper will instantiate an instance + * of your cache store in .NET and delegate all calls to that instance. + * To create an instance, assembly name and class name are passed to + * System.Activator.CreateInstance(String, String) + * method in .NET during node startup. Refer to its documentation for + * details. + */ +public class PlatformDotNetCacheStore implements CacheStore, PlatformCacheStore { + /** Load cache operation code. */ + private static final byte OP_LOAD_CACHE = (byte)0; + + /** Load operation code. */ + private static final byte OP_LOAD = (byte)1; + + /** Load all operation code. */ + private static final byte OP_LOAD_ALL = (byte)2; + + /** Put operation code. */ + private static final byte OP_PUT = (byte)3; + + /** Put all operation code. */ + private static final byte OP_PUT_ALL = (byte)4; + + /** Remove operation code. */ + private static final byte OP_RMV = (byte)5; + + /** Remove all operation code. */ + private static final byte OP_RMV_ALL = (byte)6; + + /** Tx end operation code. */ + private static final byte OP_SES_END = (byte)7; + + /** Key used to distinguish session deployment. */ + private static final Object KEY_SES = new Object(); + + /** */ + @CacheStoreSessionResource + private CacheStoreSession ses; + + /** .Net assembly name. */ + private String assemblyName; + + /** .Net class name. */ + private String clsName; + + /** Properties. */ + private Map props; + + /** Interop processor. */ + protected PlatformContext platformCtx; + + /** Pointer to native store. */ + protected long ptr; + + /** + * Gets .NET assembly name. + * + * @return .NET assembly name. + */ + public String getAssemblyName() { + return assemblyName; + } + + /** + * Set .NET assembly name. + * + * @param assemblyName .NET assembly name. + */ + public void setAssemblyName(String assemblyName) { + this.assemblyName = assemblyName; + } + + /** + * Gets .NET class name. + * + * @return .NET class name. + */ + public String getClassName() { + return clsName; + } + + /** + * Sets .NET class name. + * + * @param clsName .NET class name. + */ + public void setClassName(String clsName) { + this.clsName = clsName; + } + + /** + * Get properties. + * + * @return Properties. + */ + public Map getProperties() { + return props; + } + + /** + * Set properties. + * + * @param props Properties. + */ + public void setProperties(Map props) { + this.props = props; + } + + /** {@inheritDoc} */ + @Nullable @Override public V load(final K key) { + try { + final GridTuple val = new GridTuple<>(); + + doInvoke(new IgniteInClosureX() { + @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException { + writer.writeByte(OP_LOAD); + writer.writeLong(session()); + writer.writeString(ses.cacheName()); + writer.writeObject(key); + } + }, new LoadCallback<>(platformCtx, val)); + + return val.get(); + } + catch (IgniteCheckedException e) { + throw new CacheLoaderException(e); + } + } + + /** {@inheritDoc} */ + @Override public Map loadAll(final Iterable keys) { + try { + final Map loaded = new HashMap<>(); + + doInvoke(new IgniteInClosureX() { + @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException { + writer.writeByte(OP_LOAD_ALL); + writer.writeLong(session()); + writer.writeString(ses.cacheName()); + writer.writeCollection((Collection) keys); + } + }, new LoadAllCallback<>(platformCtx, loaded)); + + return loaded; + } + catch (IgniteCheckedException e) { + throw new CacheLoaderException(e); + } + } + + /** {@inheritDoc} */ + @Override public void loadCache(final IgniteBiInClosure clo, final @Nullable Object... args) { + try { + doInvoke(new IgniteInClosureX() { + @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException { + writer.writeByte(OP_LOAD_CACHE); + writer.writeLong(session()); + writer.writeString(ses.cacheName()); + writer.writeObjectArray(args); + } + }, new LoadCacheCallback<>(platformCtx, clo)); + } + catch (IgniteCheckedException e) { + throw new CacheLoaderException(e); + } + } + + /** {@inheritDoc} */ + @Override public void write(final Cache.Entry entry) { + try { + doInvoke(new IgniteInClosureX() { + @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException { + writer.writeByte(OP_PUT); + writer.writeLong(session()); + writer.writeString(ses.cacheName()); + writer.writeObject(entry.getKey()); + writer.writeObject(entry.getValue()); + } + }, null); + } + catch (IgniteCheckedException e) { + throw new CacheWriterException(U.convertExceptionNoWrap(e)); + } + } + + /** {@inheritDoc} */ + @SuppressWarnings({"NullableProblems", "unchecked"}) + @Override public void writeAll(final Collection> entries) { + try { + doInvoke(new IgniteInClosureX() { + @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException { + Map map = new AbstractMap() { + @Override public int size() { + return entries.size(); + } + + @Override public Set> entrySet() { + return new AbstractSet>() { + @Override public Iterator> iterator() { + return F.iterator(entries, new C1, Entry>() { + private static final long serialVersionUID = 0L; + + @Override public Entry apply(Cache.Entry entry) { + return new GridMapEntry<>(entry.getKey(), entry.getValue()); + } + }, true); + } + + @Override public int size() { + return entries.size(); + } + }; + } + }; + + writer.writeByte(OP_PUT_ALL); + writer.writeLong(session()); + writer.writeString(ses.cacheName()); + writer.writeMap(map); + } + }, null); + } + catch (IgniteCheckedException e) { + throw new CacheWriterException(U.convertExceptionNoWrap(e)); + } + } + + /** {@inheritDoc} */ + @Override public void delete(final Object key) { + try { + doInvoke(new IgniteInClosureX() { + @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException { + writer.writeByte(OP_RMV); + writer.writeLong(session()); + writer.writeString(ses.cacheName()); + writer.writeObject(key); + } + }, null); + } + catch (IgniteCheckedException e) { + throw new CacheWriterException(U.convertExceptionNoWrap(e)); + } + } + + /** {@inheritDoc} */ + @Override public void deleteAll(final Collection keys) { + try { + doInvoke(new IgniteInClosureX() { + @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException { + writer.writeByte(OP_RMV_ALL); + writer.writeLong(session()); + writer.writeString(ses.cacheName()); + writer.writeCollection(keys); + } + }, null); + } + catch (IgniteCheckedException e) { + throw new CacheWriterException(U.convertExceptionNoWrap(e)); + } + } + + /** {@inheritDoc} */ + @Override public void sessionEnd(final boolean commit) { + try { + doInvoke(new IgniteInClosureX() { + @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException { + writer.writeByte(OP_SES_END); + writer.writeLong(session()); + writer.writeString(ses.cacheName()); + writer.writeBoolean(commit); + } + }, null); + } + catch (IgniteCheckedException e) { + throw new CacheWriterException(U.convertExceptionNoWrap(e)); + } + } + + /** + * Initialize the store. + * + * @param ctx Context. + * @param convertPortable Convert portable flag. + * @throws org.apache.ignite.IgniteCheckedException + */ + public void initialize(GridKernalContext ctx, boolean convertPortable) throws IgniteCheckedException { + A.notNull(assemblyName, "assemblyName"); + A.notNull(clsName, "clsName"); + + platformCtx = PlatformUtils.platformContext(ctx.grid()); + + try (PlatformMemory mem = platformCtx.memory().allocate()) { + PlatformOutputStream out = mem.output(); + + PortableRawWriterEx writer = platformCtx.writer(out); + + writer.writeString(assemblyName); + writer.writeString(clsName); + writer.writeBoolean(convertPortable); + writer.writeMap(props); + + out.synchronize(); + + ptr = platformCtx.gateway().cacheStoreCreate(mem.pointer()); + } + } + + /** + * Gets session pointer created in native platform. + * + * @return Session pointer. + * @throws org.apache.ignite.IgniteCheckedException If failed. + */ + private long session() throws IgniteCheckedException { + Long sesPtr = (Long)ses.properties().get(KEY_SES); + + if (sesPtr == null) { + // Session is not deployed yet, do that. + sesPtr = platformCtx.gateway().cacheStoreSessionCreate(ptr); + + ses.properties().put(KEY_SES, sesPtr); + } + + return sesPtr; + } + + /** + * Perform actual invoke. + * + * @param task Task. + * @param cb Optional callback. + * @return Result. + * @throws org.apache.ignite.IgniteCheckedException If failed. + */ + protected int doInvoke(IgniteInClosureX task, @Nullable PlatformCacheStoreCallback cb) + throws IgniteCheckedException{ + try (PlatformMemory mem = platformCtx.memory().allocate()) { + PlatformOutputStream out = mem.output(); + + PortableRawWriterEx writer = platformCtx.writer(out); + + task.apply(writer); + + out.synchronize(); + + return platformCtx.gateway().cacheStoreInvoke(ptr, mem.pointer(), cb); + } + } + + /** + * Destroys interop-aware component. + * + * @param ctx Context. + */ + public void destroy(GridKernalContext ctx) { + assert ctx != null; + + platformCtx.gateway().cacheStoreDestroy(ptr); + } + + /** + * Load callback. + */ + private static class LoadCallback extends PlatformCacheStoreCallback { + /** Value. */ + private final GridTuple val; + + /** + * Constructor. + * + * @param ctx Context. + * @param val Value. + */ + public LoadCallback(PlatformContext ctx, GridTuple val) { + super(ctx); + + this.val = val; + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override protected void invoke0(PortableRawReaderEx reader) { + val.set((V)reader.readObjectDetached()); + } + } + + /** + * Load callback. + */ + private static class LoadAllCallback extends PlatformCacheStoreCallback { + /** Value. */ + private final Map loaded; + + /** + * Constructor. + * + * @param ctx Context. + * @param loaded Map with loaded values. + */ + public LoadAllCallback(PlatformContext ctx, Map loaded) { + super(ctx); + + this.loaded = loaded; + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override protected void invoke0(PortableRawReaderEx reader) { + loaded.put((K) reader.readObjectDetached(), (V) reader.readObjectDetached()); + } + } + + /** + * Load callback. + */ + private static class LoadCacheCallback extends PlatformCacheStoreCallback { + /** Value. */ + private final IgniteBiInClosure clo; + + /** + * Constructor. + * + * @param ctx Context. + * @param clo Closure. + */ + public LoadCacheCallback(PlatformContext ctx, IgniteBiInClosure clo) { + super(ctx); + + this.clo = clo; + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override protected void invoke0(PortableRawReaderEx reader) { + clo.apply((K) reader.readObjectDetached(), (V) reader.readObjectDetached()); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/86ab3a73/modules/platform/src/main/java/org/apache/ignite/platform/cpp/PlatformCppConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/java/org/apache/ignite/platform/cpp/PlatformCppConfiguration.java b/modules/platform/src/main/java/org/apache/ignite/platform/cpp/PlatformCppConfiguration.java new file mode 100644 index 0000000..18f8a43 --- /dev/null +++ b/modules/platform/src/main/java/org/apache/ignite/platform/cpp/PlatformCppConfiguration.java @@ -0,0 +1,47 @@ +/* + * 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. + */ + +package org.apache.ignite.platform.cpp; + +import org.apache.ignite.configuration.PlatformConfiguration; +import org.apache.ignite.internal.util.typedef.internal.S; + +/** + * Platform CPP configuration. + */ +public class PlatformCppConfiguration implements PlatformConfiguration { + /** + * Default constructor. + */ + public PlatformCppConfiguration() { + // No-op. + } + + /** + * Copying constructor. + * + * @param cfg Configuration to copy. + */ + public PlatformCppConfiguration(PlatformConfiguration cfg) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(PlatformConfiguration.class, this); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/86ab3a73/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetCacheStoreFactory.java ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetCacheStoreFactory.java b/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetCacheStoreFactory.java new file mode 100644 index 0000000..97f0dce --- /dev/null +++ b/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetCacheStoreFactory.java @@ -0,0 +1,139 @@ +/* + * 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. + */ + +package org.apache.ignite.platform.dotnet; + +import org.apache.ignite.internal.processors.platform.dotnet.PlatformDotNetCacheStore; + +import javax.cache.configuration.Factory; +import java.util.Map; + +/** + * Wrapper for .NET cache store implementations. + *

+ * This wrapper should be used if you have an implementation of + * {@code GridGain.Cache.IGridCacheStore} interface in .NET and + * would like to configure it a persistence storage for your cache. + * To do tis you will need to configure the wrapper via + * {@link org.apache.ignite.configuration.CacheConfiguration#setCacheStoreFactory(javax.cache.configuration.Factory)} property + * and provide assembly name and class name of your .NET store + * implementation (both properties are mandatory): + *

+ * <bean class="org.apache.ignite.cache.CacheConfiguration">
+ *     ...
+ *     <property name="cacheStoreFactory">
+ *         <bean class="org.gridgain.grid.interop.dotnet.InteropDotNetCacheStoreFactory">
+ *             <property name="assemblyName" value="MyAssembly"/>
+ *             <property name="className" value="MyApp.MyCacheStore"/>
+ *         </bean>
+ *     </property>
+ *     ...
+ * </bean>
+ * 
+ * If properly configured, this wrapper will instantiate an instance + * of your cache store in .NET and delegate all calls to that instance. + * To create an instance, assembly name and class name are passed to + * System.Activator.CreateInstance(String, String) + * method in .NET during node startup. Refer to its documentation for + * details. + */ +public class PlatformDotNetCacheStoreFactory implements Factory { + /** */ + private static final long serialVersionUID = 0L; + + /** .Net assembly name. */ + private String assemblyName; + + /** .Net class name. */ + private String clsName; + + /** Properties. */ + private Map props; + + /** Instance. */ + private transient PlatformDotNetCacheStore instance; + + /** + * Gets .NET assembly name. + * + * @return .NET assembly name. + */ + public String getAssemblyName() { + return assemblyName; + } + + /** + * Set .NET assembly name. + * + * @param assemblyName .NET assembly name. + */ + public void setAssemblyName(String assemblyName) { + this.assemblyName = assemblyName; + } + + /** + * Gets .NET class name. + * + * @return .NET class name. + */ + public String getClassName() { + return clsName; + } + + /** + * Sets .NET class name. + * + * @param clsName .NET class name. + */ + public void setClassName(String clsName) { + this.clsName = clsName; + } + + /** + * Get properties. + * + * @return Properties. + */ + public Map getProperties() { + return props; + } + + /** + * Set properties. + * + * @param props Properties. + */ + public void setProperties(Map props) { + this.props = props; + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override public PlatformDotNetCacheStore create() { + synchronized (this) { + if (instance == null) { + instance = new PlatformDotNetCacheStore(); + + instance.setAssemblyName(assemblyName); + instance.setClassName(clsName); + instance.setProperties(props); + } + + return instance; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/86ab3a73/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetConfiguration.java b/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetConfiguration.java new file mode 100644 index 0000000..80f4b26 --- /dev/null +++ b/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetConfiguration.java @@ -0,0 +1,119 @@ +/* + * 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. + */ + +package org.apache.ignite.platform.dotnet; + +import org.apache.ignite.configuration.PlatformConfiguration; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.portable.PortableException; +import org.apache.ignite.portable.PortableMarshalAware; +import org.apache.ignite.portable.PortableRawReader; +import org.apache.ignite.portable.PortableRawWriter; +import org.apache.ignite.portable.PortableReader; +import org.apache.ignite.portable.PortableWriter; + +import java.util.ArrayList; +import java.util.List; + +/** + * Mirror of .Net class Configuration.cs + */ +public class PlatformDotNetConfiguration implements PlatformConfiguration, PortableMarshalAware { + /** */ + private PlatformDotNetPortableConfiguration portableCfg; + + /** */ + private List assemblies; + + /** + * Default constructor. + */ + public PlatformDotNetConfiguration() { + // No-op. + } + + /** + * Copy constructor. + * + * @param cfg Configuration to copy. + */ + public PlatformDotNetConfiguration(PlatformDotNetConfiguration cfg) { + if (cfg.getPortableConfiguration() != null) + portableCfg = new PlatformDotNetPortableConfiguration(cfg.getPortableConfiguration()); + + if (cfg.getAssemblies() != null) + assemblies = new ArrayList<>(cfg.getAssemblies()); + } + + /** + * @return Configuration. + */ + public PlatformDotNetPortableConfiguration getPortableConfiguration() { + return portableCfg; + } + + /** + * @param portableCfg Configuration. + */ + public void setPortableConfiguration(PlatformDotNetPortableConfiguration portableCfg) { + this.portableCfg = portableCfg; + } + + /** + * @return Assemblies. + */ + public List getAssemblies() { + return assemblies; + } + + /** + * + * @param assemblies Assemblies. + */ + public void setAssemblies(List assemblies) { + this.assemblies = assemblies; + } + + /** + * @return Configuration copy. + */ + @SuppressWarnings("UnusedDeclaration") + private PlatformDotNetConfiguration copy() { + return new PlatformDotNetConfiguration(this); + } + + /** {@inheritDoc} */ + @Override public void writePortable(PortableWriter writer) throws PortableException { + PortableRawWriter rawWriter = writer.rawWriter(); + + rawWriter.writeObject(portableCfg); + rawWriter.writeCollection(assemblies); + } + + /** {@inheritDoc} */ + @Override public void readPortable(PortableReader reader) throws PortableException { + PortableRawReader rawReader = reader.rawReader(); + + portableCfg = rawReader.readObject(); + assemblies = (List)rawReader.readCollection(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(PlatformDotNetConfiguration.class, this); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/86ab3a73/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetLifecycleBean.java ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetLifecycleBean.java b/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetLifecycleBean.java new file mode 100644 index 0000000..8e4b590 --- /dev/null +++ b/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetLifecycleBean.java @@ -0,0 +1,109 @@ +/* + * 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. + */ + +package org.apache.ignite.platform.dotnet; + +import org.apache.ignite.internal.processors.platform.lifecycle.PlatformLifecycleBean; +import org.apache.ignite.lifecycle.LifecycleBean; + +import java.util.Map; + +/** + * Lifecycle bean implementation which can be used to configure .Net lifecycle beans in Java Spring configuration. + */ +public class PlatformDotNetLifecycleBean extends PlatformLifecycleBean implements LifecycleBean { + /** Assembly name. */ + private String assemblyName; + + /** Class name. */ + private String clsName; + + /** Properties. */ + private Map props; + + /** + * Constructor. + */ + public PlatformDotNetLifecycleBean() { + // No-op. + } + + /** + * Constructor. + * + * @param assemblyName Assembly name. + * @param clsName Class name. + */ + public PlatformDotNetLifecycleBean(String assemblyName, String clsName) { + this.assemblyName = assemblyName; + this.clsName = clsName; + } + + /** + * Get assembly name. + * + * @return Assembly name. + */ + public String getAssemblyName() { + return assemblyName; + } + + /** + * Set assembly name. + * + * @param assemblyName Assembly name. + */ + public void setAssemblyName(String assemblyName) { + this.assemblyName = assemblyName; + } + + /** + * Get class name. + * + * @return Class name. + */ + public String getClassName() { + return clsName; + } + + /** + * Set class name. + * + * @param clsName Class name. + */ + public void setClassName(String clsName) { + this.clsName = clsName; + } + + /** + * Get properties. + * + * @return Properties. + */ + public Map getProperties() { + return props; + } + + /** + * Set properties. + * + * @param props Properties. + */ + public void setProperties(Map props) { + this.props = props; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/86ab3a73/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetPortableConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetPortableConfiguration.java b/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetPortableConfiguration.java new file mode 100644 index 0000000..644a8e6 --- /dev/null +++ b/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetPortableConfiguration.java @@ -0,0 +1,228 @@ +/* + * 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. + */ + +package org.apache.ignite.platform.dotnet; + +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.portable.PortableException; +import org.apache.ignite.portable.PortableMarshalAware; +import org.apache.ignite.portable.PortableRawReader; +import org.apache.ignite.portable.PortableRawWriter; +import org.apache.ignite.portable.PortableReader; +import org.apache.ignite.portable.PortableWriter; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * Mirror of .Net class PortableConfiguration.cs + */ +public class PlatformDotNetPortableConfiguration implements PortableMarshalAware { + /** Type cfgs. */ + private Collection typesCfg; + + /** Types. */ + private Collection types; + + /** Default name mapper. */ + private String dfltNameMapper; + + /** Default id mapper. */ + private String dfltIdMapper; + + /** Default serializer. */ + private String dfltSerializer; + + /** Default metadata enabled. */ + private boolean dfltMetadataEnabled = true; + + /** Whether to cache deserialized value in IGridPortableObject */ + private boolean dfltKeepDeserialized = true; + + /** + * Default constructor. + */ + public PlatformDotNetPortableConfiguration() { + // No-op. + } + + /** + * Copy constructor. + * @param cfg configuration to copy. + */ + public PlatformDotNetPortableConfiguration(PlatformDotNetPortableConfiguration cfg) { + if (cfg.getTypesConfiguration() != null) { + typesCfg = new ArrayList<>(); + + for (PlatformDotNetPortableTypeConfiguration typeCfg : cfg.getTypesConfiguration()) + typesCfg.add(new PlatformDotNetPortableTypeConfiguration(typeCfg)); + } + + if (cfg.getTypes() != null) + types = new ArrayList<>(cfg.getTypes()); + + dfltNameMapper = cfg.getDefaultNameMapper(); + dfltIdMapper = cfg.getDefaultIdMapper(); + dfltSerializer = cfg.getDefaultSerializer(); + dfltMetadataEnabled = cfg.isDefaultMetadataEnabled(); + dfltKeepDeserialized = cfg.isDefaultKeepDeserialized(); + } + + /** + * @return Type cfgs. + */ + public Collection getTypesConfiguration() { + return typesCfg; + } + + /** + * @param typesCfg New type cfgs. + */ + public void setTypesConfiguration(Collection typesCfg) { + this.typesCfg = typesCfg; + } + + /** + * @return Types. + */ + public Collection getTypes() { + return types; + } + + /** + * @param types New types. + */ + public void setTypes(Collection types) { + this.types = types; + } + + /** + * @return Default name mapper. + */ + public String getDefaultNameMapper() { + return dfltNameMapper; + } + + /** + * @param dfltNameMapper New default name mapper. + */ + public void setDefaultNameMapper(String dfltNameMapper) { + this.dfltNameMapper = dfltNameMapper; + } + + /** + * @return Default id mapper. + */ + public String getDefaultIdMapper() { + return dfltIdMapper; + } + + /** + * @param dfltIdMapper New default id mapper. + */ + public void setDefaultIdMapper(String dfltIdMapper) { + this.dfltIdMapper = dfltIdMapper; + } + + /** + * @return Default serializer. + */ + public String getDefaultSerializer() { + return dfltSerializer; + } + + /** + * @param dfltSerializer New default serializer. + */ + public void setDefaultSerializer(String dfltSerializer) { + this.dfltSerializer = dfltSerializer; + } + + /** + * Gets default metadata enabled flag. See {@link #setDefaultMetadataEnabled(boolean)} for more information. + * + * @return Default metadata enabled flag. + */ + public boolean isDefaultMetadataEnabled() { + return dfltMetadataEnabled; + } + + /** + * Sets default metadata enabled flag. When set to {@code true} all portable types will save it's metadata to + * cluster. + *

+ * Can be overridden for particular type using + * {@link PlatformDotNetPortableTypeConfiguration#setMetadataEnabled(Boolean)}. + * + * @param dfltMetadataEnabled Default metadata enabled flag. + */ + public void setDefaultMetadataEnabled(boolean dfltMetadataEnabled) { + this.dfltMetadataEnabled = dfltMetadataEnabled; + } + + /** + * Gets default keep deserialized flag. See {@link #setDefaultKeepDeserialized(boolean)} for more information. + * + * @return Flag indicates whether to cache deserialized value in IGridPortableObject. + */ + public boolean isDefaultKeepDeserialized() { + return dfltKeepDeserialized; + } + + /** + * Sets default keep deserialized flag. + *

+ * Can be overridden for particular type using + * {@link PlatformDotNetPortableTypeConfiguration#setKeepDeserialized(Boolean)}. + * + * @param keepDeserialized Keep deserialized flag. + */ + public void setDefaultKeepDeserialized(boolean keepDeserialized) { + this.dfltKeepDeserialized = keepDeserialized; + } + + /** {@inheritDoc} */ + @Override public void writePortable(PortableWriter writer) throws PortableException { + PortableRawWriter rawWriter = writer.rawWriter(); + + rawWriter.writeCollection(typesCfg); + rawWriter.writeCollection(types); + rawWriter.writeString(dfltNameMapper); + rawWriter.writeString(dfltIdMapper); + rawWriter.writeString(dfltSerializer); + rawWriter.writeBoolean(dfltMetadataEnabled); + rawWriter.writeBoolean(dfltKeepDeserialized); + } + + /** {@inheritDoc} */ + @Override public void readPortable(PortableReader reader) throws PortableException { + PortableRawReader rawReader = reader.rawReader(); + + typesCfg = rawReader.readCollection(); + types = rawReader.readCollection(); + dfltNameMapper = rawReader.readString(); + dfltIdMapper = rawReader.readString(); + dfltSerializer = rawReader.readString(); + dfltMetadataEnabled = rawReader.readBoolean(); + dfltKeepDeserialized = rawReader.readBoolean(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(PlatformDotNetPortableConfiguration.class, this); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/86ab3a73/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetPortableTypeConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetPortableTypeConfiguration.java b/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetPortableTypeConfiguration.java new file mode 100644 index 0000000..b6fdbde --- /dev/null +++ b/modules/platform/src/main/java/org/apache/ignite/platform/dotnet/PlatformDotNetPortableTypeConfiguration.java @@ -0,0 +1,248 @@ +/* + * 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. + */ + +package org.apache.ignite.platform.dotnet; + +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.portable.PortableException; +import org.apache.ignite.portable.PortableMarshalAware; +import org.apache.ignite.portable.PortableRawReader; +import org.apache.ignite.portable.PortableRawWriter; +import org.apache.ignite.portable.PortableReader; +import org.apache.ignite.portable.PortableWriter; +import org.jetbrains.annotations.Nullable; + +/** + * Mirror of .Net class GridDotNetPortableTypeConfiguration.cs + */ +public class PlatformDotNetPortableTypeConfiguration implements PortableMarshalAware { + /** Assembly name. */ + private String assemblyName; + + /** Type name. */ + private String typeName; + + /** Name mapper. */ + private String nameMapper; + + /** Id mapper. */ + private String idMapper; + + /** Serializer. */ + private String serializer; + + /** Affinity key field name. */ + private String affinityKeyFieldName; + + /** Metadata enabled. */ + private Boolean metadataEnabled; + + /** Whether to cache deserialized value in IGridPortableObject. */ + private Boolean keepDeserialized; + + /** + * Default constructor. + */ + public PlatformDotNetPortableTypeConfiguration() { + // No-op. + } + + /** + * Copy constructor. + * @param cfg configuration to copy. + */ + public PlatformDotNetPortableTypeConfiguration(PlatformDotNetPortableTypeConfiguration cfg) { + assemblyName = cfg.getAssemblyName(); + typeName = cfg.getTypeName(); + nameMapper = cfg.getNameMapper(); + idMapper = cfg.getIdMapper(); + serializer = cfg.getSerializer(); + affinityKeyFieldName = cfg.getAffinityKeyFieldName(); + metadataEnabled = cfg.getMetadataEnabled(); + keepDeserialized = cfg.isKeepDeserialized(); + } + + /** + * @return Assembly name. + */ + public String getAssemblyName() { + return assemblyName; + } + + /** + * @param assemblyName New assembly name. + */ + public void setAssemblyName(String assemblyName) { + this.assemblyName = assemblyName; + } + + /** + * @return Type name. + */ + public String getTypeName() { + return typeName; + } + + /** + * @param typeName New type name. + */ + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + /** + * @return Name mapper. + */ + public String getNameMapper() { + return nameMapper; + } + + /** + * @param nameMapper New name mapper. + */ + public void setNameMapper(String nameMapper) { + this.nameMapper = nameMapper; + } + + /** + * @return Id mapper. + */ + public String getIdMapper() { + return idMapper; + } + + /** + * @param idMapper New id mapper. + */ + public void setIdMapper(String idMapper) { + this.idMapper = idMapper; + } + + /** + * @return Serializer. + */ + public String getSerializer() { + return serializer; + } + + /** + * @param serializer New serializer. + */ + public void setSerializer(String serializer) { + this.serializer = serializer; + } + + /** + * Gets metadata enabled flag. See {@link #setMetadataEnabled(Boolean)} for more information. + * + * @return Metadata enabled flag. + */ + public Boolean getMetadataEnabled() { + return metadataEnabled; + } + + /** + * Sets metadata enabled flag. + *

+ * When set to {@code null} default value taken from + * {@link PlatformDotNetPortableConfiguration#isDefaultMetadataEnabled()} will be used. + * + * @param metadataEnabled New metadata enabled. + */ + public void setMetadataEnabled(Boolean metadataEnabled) { + this.metadataEnabled = metadataEnabled; + } + + /** + * @return Affinity key field name. + */ + public String getAffinityKeyFieldName() { + return affinityKeyFieldName; + } + + /** + * @param affinityKeyFieldName Affinity key field name. + */ + public void setAffinityKeyFieldName(String affinityKeyFieldName) { + this.affinityKeyFieldName = affinityKeyFieldName; + } + + /** + * Gets keep deserialized flag. + * + * @return Flag indicates whether to cache deserialized value in IGridPortableObject. + * @deprecated Use {@link #getKeepDeserialized()} instead. + */ + @Deprecated + @Nullable public Boolean isKeepDeserialized() { + return keepDeserialized; + } + + /** + * Gets keep deserialized flag. See {@link #setKeepDeserialized(Boolean)} for more information. + * + * @return Flag indicates whether to cache deserialized value in IGridPortableObject. + */ + @Nullable public Boolean getKeepDeserialized() { + return keepDeserialized; + } + + /** + * Sets keep deserialized flag. + *

+ * When set to {@code null} default value taken from + * {@link PlatformDotNetPortableConfiguration#isDefaultKeepDeserialized()} will be used. + * + * @param keepDeserialized Keep deserialized flag. + */ + public void setKeepDeserialized(@Nullable Boolean keepDeserialized) { + this.keepDeserialized = keepDeserialized; + } + + /** {@inheritDoc} */ + @Override public void writePortable(PortableWriter writer) throws PortableException { + PortableRawWriter rawWriter = writer.rawWriter(); + + rawWriter.writeString(assemblyName); + rawWriter.writeString(typeName); + rawWriter.writeString(nameMapper); + rawWriter.writeString(idMapper); + rawWriter.writeString(serializer); + rawWriter.writeString(affinityKeyFieldName); + rawWriter.writeObject(metadataEnabled); + rawWriter.writeObject(keepDeserialized); + } + + /** {@inheritDoc} */ + @Override public void readPortable(PortableReader reader) throws PortableException { + PortableRawReader rawReader = reader.rawReader(); + + assemblyName = rawReader.readString(); + typeName = rawReader.readString(); + nameMapper = rawReader.readString(); + idMapper = rawReader.readString(); + serializer = rawReader.readString(); + affinityKeyFieldName = rawReader.readString(); + metadataEnabled = rawReader.readObject(); + keepDeserialized = rawReader.readObject(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(PlatformDotNetPortableTypeConfiguration.class, this); + } +}