You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2015/11/23 15:02:28 UTC
[17/17] ignite git commit: Make binary marshaller default.
Make binary marshaller default.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3ca58d7b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3ca58d7b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3ca58d7b
Branch: refs/heads/ignite-1282
Commit: 3ca58d7b5edd0354c73450ff9fff3acf8a2da2cd
Parents: 7ea000a
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Mon Nov 23 16:49:53 2015 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Mon Nov 23 16:49:53 2015 +0300
----------------------------------------------------------------------
examples/config/example-ignite.xml | 10 +--
.../ignite/examples/binary/EmployeeKey.java | 3 +
.../configuration/CacheConfiguration.java | 26 --------
.../org/apache/ignite/internal/IgnitionEx.java | 6 +-
.../internal/portable/BinaryMarshaller.java | 68 ++++++++++----------
.../internal/portable/PortableContext.java | 23 ++++++-
6 files changed, 62 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/examples/config/example-ignite.xml
----------------------------------------------------------------------
diff --git a/examples/config/example-ignite.xml b/examples/config/example-ignite.xml
index d842a6d..a3e7e22 100644
--- a/examples/config/example-ignite.xml
+++ b/examples/config/example-ignite.xml
@@ -27,13 +27,5 @@
<!-- Imports default Ignite configuration -->
<import resource="example-default.xml"/>
- <bean parent="ignite.cfg">
- <!-- Enabled optimized marshaller -->
- <property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
- <!-- Set to false to allow non-serializable objects in examples, default is true. -->
- <property name="requireSerializable" value="false"/>
- </bean>
- </property>
- </bean>
+ <bean parent="ignite.cfg"/>
</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java b/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java
index 2794230..7614f2c 100644
--- a/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java
@@ -17,6 +17,8 @@
package org.apache.ignite.examples.binary;
+import org.apache.ignite.cache.affinity.AffinityKeyMapped;
+
/**
* This class represents key for employee object.
* <p>
@@ -28,6 +30,7 @@ public class EmployeeKey {
private int id;
/** Organization ID. */
+ @AffinityKeyMapped
private int organizationId;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index e7dd9c3..8c3ea19 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -389,9 +389,6 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
/** Query entities. */
private Collection<QueryEntity> qryEntities;
- /** Cache */
- private Collection<CacheKeyConfiguration> cacheKeyCfgs;
-
/** Empty constructor (all values are initialized to their defaults). */
public CacheConfiguration() {
/* No-op. */
@@ -426,7 +423,6 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
atomicityMode = cc.getAtomicityMode();
atomicWriteOrderMode = cc.getAtomicWriteOrderMode();
backups = cc.getBackups();
- cacheKeyCfgs = cc.getCacheKeyConfiguration();
cacheLoaderFactory = cc.getCacheLoaderFactory();
cacheMode = cc.getCacheMode();
cacheWriterFactory = cc.getCacheWriterFactory();
@@ -997,28 +993,6 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
}
/**
- * Gets cache key configuration. Cache key configuration allows to override default cache key affinity
- * by specifying affinity field name.
- *
- * @return Cache key configuration.
- */
- public Collection<CacheKeyConfiguration> getCacheKeyConfiguration() {
- return cacheKeyCfgs;
- }
-
- /**
- * Sets cache key configuration.
- *
- * @param cacheKeyCfgs Collection of cache key configurations.
- */
- public void setCacheKeyConfiguration(Collection<CacheKeyConfiguration> cacheKeyCfgs) {
- if (this.cacheKeyCfgs != null)
- this.cacheKeyCfgs.addAll(cacheKeyCfgs);
- else
- this.cacheKeyCfgs = cacheKeyCfgs;
- }
-
- /**
* Gets cache atomicity mode.
* <p>
* Default value is defined by {@link #DFLT_CACHE_ATOMICITY_MODE}.
http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index 7d2b2dc..a83ddcc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -61,6 +61,7 @@ import org.apache.ignite.configuration.DeploymentMode;
import org.apache.ignite.configuration.FileSystemConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.TransactionConfiguration;
+import org.apache.ignite.internal.portable.BinaryMarshaller;
import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
import org.apache.ignite.internal.util.GridConcurrentHashSet;
import org.apache.ignite.internal.util.IgniteUtils;
@@ -76,7 +77,6 @@ import org.apache.ignite.logger.LoggerNodeIdAware;
import org.apache.ignite.logger.java.JavaLogger;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.marshaller.jdk.JdkMarshaller;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.mxbean.IgnitionMXBean;
import org.apache.ignite.plugin.segmentation.SegmentationPolicy;
import org.apache.ignite.resources.SpringApplicationContextResource;
@@ -1793,7 +1793,7 @@ public class IgnitionEx {
Marshaller marsh = myCfg.getMarshaller();
if (marsh == null) {
- if (!OptimizedMarshaller.available()) {
+ if (!BinaryMarshaller.available()) {
U.warn(log, "OptimizedMarshaller is not supported on this JVM " +
"(only recent 1.6 and 1.7 versions HotSpot VMs are supported). " +
"To enable fast marshalling upgrade to recent 1.6 or 1.7 HotSpot VM release. " +
@@ -1804,7 +1804,7 @@ public class IgnitionEx {
marsh = new JdkMarshaller();
}
else
- marsh = new OptimizedMarshaller();
+ marsh = new BinaryMarshaller();
}
myCfg.setMarshaller(marsh);
http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java
index 4f8c83c..759d802 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java
@@ -24,54 +24,54 @@ import java.io.OutputStream;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.GridUnsafe;
import org.apache.ignite.marshaller.AbstractMarshaller;
import org.apache.ignite.marshaller.MarshallerContext;
import org.jetbrains.annotations.Nullable;
+import sun.misc.Unsafe;
/**
* Implementation of {@link org.apache.ignite.marshaller.Marshaller} that lets to serialize and deserialize all objects
- * in the portable format.
+ * in the binary format.
* <p>
* {@code PortableMarshaller} is tested only on Java HotSpot VM on other VMs it could yield unexpected results.
- * <p>
- * <h1 class="header">Configuration</h1>
- * <h2 class="header">Mandatory</h2>
- * This marshaller has no mandatory configuration parameters.
- * <h2 class="header">Java Example</h2>
- * <pre name="code" class="java">
- * PortableMarshaller marshaller = new PortableMarshaller();
- *
- * IgniteConfiguration cfg = new IgniteConfiguration();
- *
- * // Override marshaller.
- * cfg.setMarshaller(marshaller);
- *
- * // Starts grid.
- * G.start(cfg);
- * </pre>
- * <h2 class="header">Spring Example</h2>
- * PortableMarshaller can be configured from Spring XML configuration file:
- * <pre name="code" class="xml">
- * <bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true">
- * ...
- * <property name="marshaller">
- * <bean class="org.apache.ignite.marshaller.portable.PortableMarshaller">
- * ...
- * </bean>
- * </property>
- * ...
- * </bean>
- * </pre>
- * <p>
- * <img src="http://ignite.apache.org/images/spring-small.png">
- * <br>
- * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a>
*/
public class BinaryMarshaller extends AbstractMarshaller {
/** */
private GridPortableMarshaller impl;
/**
+ * Checks whether {@code BinaryMarshaller} is able to work on the current JVM.
+ * <p>
+ * As long as {@code BinaryMarshaller} uses JVM-private API, which is not guaranteed
+ * to be available on all JVM, this method should be called to ensure marshaller could work properly.
+ * <p>
+ * Result of this method is automatically checked in constructor.
+ *
+ * @return {@code true} if {@code BinaryMarshaller} can work on the current JVM or
+ * {@code false} if it can't.
+ */
+ @SuppressWarnings({"TypeParameterExtendsFinalClass", "ErrorNotRethrown"})
+ public static boolean available() {
+ try {
+ Unsafe unsafe = GridUnsafe.unsafe();
+
+ Class<? extends Unsafe> unsafeCls = unsafe.getClass();
+
+ unsafeCls.getMethod("allocateInstance", Class.class);
+ unsafeCls.getMethod("copyMemory", Object.class, long.class, Object.class, long.class, long.class);
+
+ return true;
+ }
+ catch (Exception ignored) {
+ return false;
+ }
+ catch (NoClassDefFoundError ignored) {
+ return false;
+ }
+ }
+
+ /**
* Returns currently set {@link MarshallerContext}.
*
* @return Marshaller context.
http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
index 8f37517..1ff459e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
@@ -24,6 +24,7 @@ import java.io.InvalidObjectException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.ObjectStreamException;
+import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.net.URISyntaxException;
import java.net.URL;
@@ -52,6 +53,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.CacheKeyConfiguration;
+import org.apache.ignite.cache.affinity.AffinityKeyMapped;
import org.apache.ignite.configuration.BinaryConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.binary.BinaryTypeConfiguration;
@@ -503,12 +505,14 @@ public class PortableContext implements Externalizable {
throw new BinaryObjectException("Failed to register class.", e);
}
+ String affFieldName = affinityFieldName(cls);
+
PortableClassDescriptor desc = new PortableClassDescriptor(this,
cls,
true,
typeId,
typeName,
- null,
+ affFieldName,
idMapper,
null,
true,
@@ -518,7 +522,7 @@ public class PortableContext implements Externalizable {
Collection<PortableSchema> schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
- metaHnd.addMeta(typeId, new BinaryMetadata(typeId, typeName, desc.fieldsMeta(), null, schemas).wrap(this));
+ metaHnd.addMeta(typeId, new BinaryMetadata(typeId, typeName, desc.fieldsMeta(), affFieldName, schemas).wrap(this));
// perform put() instead of putIfAbsent() because "registered" flag might have been changed or class loader
// might have reloaded described class.
@@ -606,6 +610,21 @@ public class PortableContext implements Externalizable {
return idMapper != null ? idMapper : BinaryInternalIdMapper.defaultInstance();
}
+ /**
+ * @param cls Class to get affinity field for.
+ * @return Affinity field name or {@code null} if field name was not found.
+ */
+ private String affinityFieldName(Class cls) {
+ for (; cls != Object.class; cls = cls.getSuperclass()) {
+ for (Field f : cls.getDeclaredFields()) {
+ if (f.getAnnotation(AffinityKeyMapped.class) != null)
+ return f.getName();
+ }
+ }
+
+ return null;
+ }
+
/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
U.writeString(out, igniteCfg.getGridName());