ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [26/50] [abbrv] ignite git commit: ignite-1300: add ability to register class types outside of the portable context
Date Mon, 31 Aug 2015 02:01:09 GMT
ignite-1300: add ability to register class types outside of the portable context


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

Branch: refs/heads/ignite-843
Commit: f575ff119d589c04836a3de065e5f958daec8000
Parents: 00b27ce
Author: Denis Magda <dmagda@gridgain.com>
Authored: Thu Aug 27 13:17:35 2015 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Thu Aug 27 13:17:35 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/PortableContext.java      | 115 +++++++++++--------
 1 file changed, 67 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f575ff11/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 a9d64d9..723113e 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
@@ -114,10 +114,19 @@ public class PortableContext implements Externalizable {
     private String gridName;
 
     /** */
-    private PortableMarshaller marsh;
+    private final OptimizedMarshaller optmMarsh = new OptimizedMarshaller();
 
     /** */
-    private final OptimizedMarshaller optmMarsh = new OptimizedMarshaller();
+    private boolean convertStrings;
+
+    /** */
+    private boolean useTs;
+
+    /** */
+    private boolean metaDataEnabled;
+
+    /** */
+    private boolean keepDeserialized;
 
     /**
      * For {@link Externalizable}.
@@ -199,18 +208,6 @@ public class PortableContext implements Externalizable {
         registerPredefinedType(PortableObjectImpl.class, 63);
 
         registerPredefinedType(PortableMetaDataImpl.class, 64);
-
-// TODO: IGNITE-1258
-//        registerPredefinedType(DrSenderAttributes.class, 65);
-//        registerPredefinedType(DrSenderRemoteAttributes.class, 66);
-//
-//        registerPredefinedType(InteropMetadata.class, 70);
-//
-//        registerPredefinedType(InteropDotNetConfiguration.class, 71);
-//        registerPredefinedType(InteropDotNetPortableConfiguration.class, 72);
-//        registerPredefinedType(InteropDotNetPortableTypeConfiguration.class, 73);
-//        registerPredefinedType(InteropIgniteProxy.class, 74);
-//        registerPredefinedType(InteropProductLicence.class, 78);
     }
 
     /**
@@ -221,40 +218,68 @@ public class PortableContext implements Externalizable {
         if (marsh == null)
             return;
 
-        this.marsh = marsh;
+        convertStrings = marsh.isConvertStringToBytes();
+        useTs = marsh.isUseTimestamp();
+        metaDataEnabled = marsh.isMetaDataEnabled();
+        keepDeserialized = marsh.isKeepDeserialized();
+
         marshCtx = marsh.getContext();
 
         assert marshCtx != null;
 
         optmMarsh.setContext(marshCtx);
 
-        PortableIdMapper globalIdMapper = marsh.getIdMapper();
-        PortableSerializer globalSerializer = marsh.getSerializer();
-        boolean globalUseTs = marsh.isUseTimestamp();
-        boolean globalMetaDataEnabled = marsh.isMetaDataEnabled();
-        boolean globalKeepDeserialized = marsh.isKeepDeserialized();
+        configure(
+            marsh.getIdMapper(),
+            marsh.getSerializer(),
+            marsh.isUseTimestamp(),
+            marsh.isMetaDataEnabled(),
+            marsh.isKeepDeserialized(),
+            marsh.getClassNames(),
+            marsh.getTypeConfigurations()
+        );
+    }
 
+    /**
+     * @param globalIdMapper ID mapper.
+     * @param globalSerializer Serializer.
+     * @param globalUseTs Use timestamp flag.
+     * @param globalMetaDataEnabled Metadata enabled flag.
+     * @param globalKeepDeserialized Keep deserialized flag.
+     * @param clsNames Class names.
+     * @param typeCfgs Type configurations.
+     * @throws PortableException In case of error.
+     */
+    private void configure(
+        PortableIdMapper globalIdMapper,
+        PortableSerializer globalSerializer,
+        boolean globalUseTs,
+        boolean globalMetaDataEnabled,
+        boolean globalKeepDeserialized,
+        Collection<String> clsNames,
+        Collection<PortableTypeConfiguration> typeCfgs
+    ) throws PortableException {
         TypeDescriptors descs = new TypeDescriptors();
 
-        if (marsh.getClassNames() != null) {
+        if (clsNames != null) {
             PortableIdMapper idMapper = new IdMapperWrapper(globalIdMapper);
 
-            for (String clsName : marsh.getClassNames()) {
+            for (String clsName : clsNames) {
                 if (clsName.endsWith(".*")) { // Package wildcard
                     String pkgName = clsName.substring(0, clsName.length() - 2);
 
                     for (String clsName0 : classesInPackage(pkgName))
                         descs.add(clsName0, idMapper, null, null, globalUseTs, globalMetaDataEnabled,
-                                  globalKeepDeserialized, true);
+                            globalKeepDeserialized, true);
                 }
                 else // Regular single class
                     descs.add(clsName, idMapper, null, null, globalUseTs, globalMetaDataEnabled,
-                              globalKeepDeserialized, true);
+                        globalKeepDeserialized, true);
             }
         }
 
-        if (marsh.getTypeConfigurations() != null) {
-            for (PortableTypeConfiguration typeCfg : marsh.getTypeConfigurations()) {
+        if (typeCfgs != null) {
+            for (PortableTypeConfiguration typeCfg : typeCfgs) {
                 String clsName = typeCfg.getClassName();
 
                 if (clsName == null)
@@ -283,17 +308,18 @@ public class PortableContext implements Externalizable {
 
                     for (String clsName0 : classesInPackage(pkgName))
                         descs.add(clsName0, idMapper, serializer, typeCfg.getAffinityKeyFieldName(),
useTs,
-                                  metaDataEnabled, keepDeserialized, true);
+                            metaDataEnabled, keepDeserialized, true);
                 }
                 else
                     descs.add(clsName, idMapper, serializer, typeCfg.getAffinityKeyFieldName(),
useTs,
-                              metaDataEnabled, keepDeserialized, false);
+                        metaDataEnabled, keepDeserialized, false);
             }
         }
 
-        for (TypeDescriptor desc : descs.descriptors())
+        for (TypeDescriptor desc : descs.descriptors()) {
             registerUserType(desc.clsName, desc.idMapper, desc.serializer, desc.affKeyFieldName,
desc.useTs,
-                             desc.metadataEnabled, desc.keepDeserialized);
+                desc.metadataEnabled, desc.keepDeserialized);
+        }
     }
 
     /**
@@ -437,9 +463,9 @@ public class PortableContext implements Externalizable {
                 clsName,
                 BASIC_CLS_ID_MAPPER,
                 null,
-                marsh.isUseTimestamp(),
-                marsh.isMetaDataEnabled(),
-                marsh.isKeepDeserialized());
+                useTs,
+                metaDataEnabled,
+                keepDeserialized);
 
             PortableClassDescriptor old = descByCls.putIfAbsent(cls, desc);
 
@@ -483,9 +509,9 @@ public class PortableContext implements Externalizable {
             typeName,
             idMapper,
             null,
-            marsh.isUseTimestamp(),
-            marsh.isMetaDataEnabled(),
-            marsh.isKeepDeserialized(),
+            useTs,
+            metaDataEnabled,
+            keepDeserialized,
             registered);
 
         // perform put() instead of putIfAbsent() because "registered" flag may have been
changed.
@@ -632,9 +658,9 @@ public class PortableContext implements Externalizable {
     /**
      * @param cls Class.
      * @param id Type ID.
-     * @return PortableClassDescriptor.
+     * @return GridPortableClassDescriptor.
      */
-    private PortableClassDescriptor registerPredefinedType(Class<?> cls, int id) {
+    public PortableClassDescriptor registerPredefinedType(Class<?> cls, int id) {
         PortableClassDescriptor desc = new PortableClassDescriptor(
             this,
             cls,
@@ -734,13 +760,6 @@ public class PortableContext implements Externalizable {
     }
 
     /**
-     * @return Whether meta data is globally enabled.
-     */
-    boolean isMetaDataEnabled() {
-        return marsh.isMetaDataEnabled();
-    }
-
-    /**
      * @param typeId Type ID.
      * @return Whether meta data is enabled.
      */
@@ -794,7 +813,7 @@ public class PortableContext implements Externalizable {
      * @return Use timestamp flag.
      */
     public boolean isUseTimestamp() {
-        return marsh.isUseTimestamp();
+        return useTs;
     }
 
     /**
@@ -809,7 +828,7 @@ public class PortableContext implements Externalizable {
      * @return Whether to convert string to UTF8 bytes.
      */
     public boolean isConvertString() {
-        return marsh.isConvertStringToBytes();
+        return convertStrings;
     }
 
     /**
@@ -1082,4 +1101,4 @@ public class PortableContext implements Externalizable {
             return registered;
         }
     }
-}
+}
\ No newline at end of file


Mime
View raw message