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 78714102C8 for ; Thu, 27 Aug 2015 10:21:58 +0000 (UTC) Received: (qmail 89841 invoked by uid 500); 27 Aug 2015 10:21:58 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 89806 invoked by uid 500); 27 Aug 2015 10:21:58 -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 89789 invoked by uid 99); 27 Aug 2015 10:21:58 -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, 27 Aug 2015 10:21:58 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 16E5DDFF6B; Thu, 27 Aug 2015 10:21:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Thu, 27 Aug 2015 10:21:58 -0000 Message-Id: <898bbd0390064b8e9a5ad510b7bb8d85@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] ignite git commit: ignite-1300: add ability to register class types outside of the portable context Repository: ignite Updated Branches: refs/heads/master 7c2c02bf0 -> f497e8e2d 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/master Commit: f575ff119d589c04836a3de065e5f958daec8000 Parents: 00b27ce Author: Denis Magda Authored: Thu Aug 27 13:17:35 2015 +0300 Committer: Denis Magda 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 clsNames, + Collection 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