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 D9232187DF for ; Thu, 22 Oct 2015 10:31:13 +0000 (UTC) Received: (qmail 11894 invoked by uid 500); 22 Oct 2015 10:31:13 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 11848 invoked by uid 500); 22 Oct 2015 10:31:13 -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 11834 invoked by uid 99); 22 Oct 2015 10:31:13 -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, 22 Oct 2015 10:31:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8181DE3916; Thu, 22 Oct 2015 10:31:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agoncharuk@apache.org To: commits@ignite.apache.org Date: Thu, 22 Oct 2015 10:31:13 -0000 Message-Id: <62ffa1255bd547b4b95f540c551d9ce7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/5] ignite git commit: ignite-950 - Merge portable API changes. Repository: ignite Updated Branches: refs/heads/ignite-950-new [created] 54e0b63a3 ignite-950 - Merge portable API changes. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/80c71a89 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/80c71a89 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/80c71a89 Branch: refs/heads/ignite-950-new Commit: 80c71a89695008999203c9be21673c073bcd3be4 Parents: 962fcce e7eb2b3 Author: Alexey Goncharuk Authored: Thu Oct 15 12:02:37 2015 +0300 Committer: Alexey Goncharuk Committed: Thu Oct 15 12:02:37 2015 +0300 ---------------------------------------------------------------------- examples/config/example-default.xml | 76 + examples/config/example-ignite.xml | 56 +- .../config/portable/example-ignite-portable.xml | 44 + .../ignite/examples/portable/Address.java | 72 + .../ignite/examples/portable/Employee.java | 93 + .../ignite/examples/portable/EmployeeKey.java | 90 + .../portable/ExamplePortableNodeStartup.java | 36 + .../ignite/examples/portable/Organization.java | 93 + .../examples/portable/OrganizationType.java | 32 + ...mputeClientPortableTaskExecutionExample.java | 154 + .../portable/computegrid/ComputeClientTask.java | 116 + .../portable/computegrid/package-info.java | 21 + .../CacheClientPortablePutGetExample.java | 230 ++ .../CacheClientPortableQueryExample.java | 325 ++ .../portable/datagrid/package-info.java | 21 + .../ignite/examples/portable/package-info.java | 21 + .../CacheClientPortableExampleTest.java | 46 + .../ComputeClientPortableExampleTest.java | 37 + .../testsuites/IgniteExamplesSelfTestSuite.java | 6 + modules/core/pom.xml | 21 + .../src/main/java/org/apache/ignite/Ignite.java | 7 + .../java/org/apache/ignite/IgniteCache.java | 44 +- .../java/org/apache/ignite/IgnitePortables.java | 370 ++ .../configuration/CacheConfiguration.java | 62 +- .../org/apache/ignite/internal/IgniteEx.java | 9 - .../apache/ignite/internal/IgniteKernal.java | 6 + .../ignite/internal/IgniteNodeAttributes.java | 5 +- .../discovery/GridDiscoveryManager.java | 10 + .../portable/GridPortableMarshaller.java | 2 +- .../portable/PortableClassDescriptor.java | 10 +- .../internal/portable/PortableContext.java | 14 +- .../portable/PortableMetaDataCollector.java | 6 +- .../portable/PortableMetaDataHandler.java | 4 +- .../internal/portable/PortableMetaDataImpl.java | 14 +- .../internal/portable/PortableObjectEx.java | 6 +- .../internal/portable/PortableObjectImpl.java | 6 +- .../portable/PortableObjectOffheapImpl.java | 6 +- .../internal/portable/PortableRawReaderEx.java | 4 +- .../internal/portable/PortableRawWriterEx.java | 4 +- .../portable/PortableReaderContext.java | 2 +- .../internal/portable/PortableReaderExImpl.java | 10 +- .../ignite/internal/portable/PortableUtils.java | 2 +- .../internal/portable/PortableWriterExImpl.java | 11 +- .../internal/portable/api/IgnitePortables.java | 362 -- .../internal/portable/api/PortableBuilder.java | 136 - .../portable/api/PortableException.java | 57 - .../internal/portable/api/PortableIdMapper.java | 54 - .../api/PortableInvalidClassException.java | 58 - .../portable/api/PortableMarshalAware.java | 48 - .../portable/api/PortableMarshaller.java | 352 -- .../internal/portable/api/PortableMetadata.java | 60 - .../internal/portable/api/PortableObject.java | 152 - .../portable/api/PortableProtocolVersion.java | 41 - .../portable/api/PortableRawReader.java | 234 -- .../portable/api/PortableRawWriter.java | 219 - .../internal/portable/api/PortableReader.java | 284 -- .../portable/api/PortableSerializer.java | 47 - .../portable/api/PortableTypeConfiguration.java | 195 - .../internal/portable/api/PortableWriter.java | 266 -- .../portable/builder/PortableBuilderEnum.java | 2 +- .../portable/builder/PortableBuilderImpl.java | 14 +- .../portable/builder/PortableBuilderReader.java | 2 +- .../builder/PortableBuilderSerializer.java | 2 +- .../builder/PortableEnumArrayLazyValue.java | 4 +- .../builder/PortableObjectArrayLazyValue.java | 2 +- .../builder/PortablePlainPortableObject.java | 2 +- .../streams/PortableAbstractInputStream.java | 2 +- .../processors/cache/GridCacheProcessor.java | 7 + .../processors/cache/IgniteCacheProxy.java | 5 + .../CacheDefaultPortableAffinityKeyMapper.java | 2 +- .../portable/CacheObjectPortableContext.java | 2 +- .../portable/CacheObjectPortableProcessor.java | 8 +- .../CacheObjectPortableProcessorImpl.java | 12 +- .../cache/portable/IgnitePortablesImpl.java | 10 +- .../cache/store/CacheOsStoreManager.java | 4 +- .../dotnet/PlatformDotNetConfiguration.java | 12 +- .../PlatformDotNetPortableConfiguration.java | 12 +- ...PlatformDotNetPortableTypeConfiguration.java | 12 +- .../marshaller/portable/PortableMarshaller.java | 358 ++ .../marshaller/portable/package-info.java | 22 + .../apache/ignite/portable/PortableBuilder.java | 137 + .../ignite/portable/PortableException.java | 57 + .../ignite/portable/PortableIdMapper.java | 56 + .../portable/PortableInvalidClassException.java | 58 + .../ignite/portable/PortableMarshalAware.java | 48 + .../ignite/portable/PortableMetadata.java | 61 + .../apache/ignite/portable/PortableObject.java | 154 + .../portable/PortableProtocolVersion.java | 41 + .../ignite/portable/PortableRawReader.java | 234 ++ .../ignite/portable/PortableRawWriter.java | 219 + .../apache/ignite/portable/PortableReader.java | 284 ++ .../ignite/portable/PortableSerializer.java | 49 + .../portable/PortableTypeConfiguration.java | 196 + .../apache/ignite/portable/PortableWriter.java | 266 ++ .../apache/ignite/portable/package-info.java | 22 + .../resources/META-INF/classnames.properties | 8 +- .../GridDiscoveryManagerAttributesSelfTest.java | 45 + .../GridPortableAffinityKeySelfTest.java | 218 + .../GridPortableBuilderAdditionalSelfTest.java | 1226 ++++++ .../portable/GridPortableBuilderSelfTest.java | 1021 +++++ ...eBuilderStringAsCharsAdditionalSelfTest.java | 28 + ...ridPortableBuilderStringAsCharsSelfTest.java | 28 + ...idPortableMarshallerCtxDisabledSelfTest.java | 256 ++ .../GridPortableMarshallerSelfTest.java | 3807 ++++++++++++++++++ .../GridPortableMetaDataDisabledSelfTest.java | 238 ++ .../portable/GridPortableMetaDataSelfTest.java | 371 ++ .../portable/GridPortableWildcardsSelfTest.java | 482 +++ .../GridPortableMarshalerAwareTestClass.java | 67 + .../mutabletest/GridPortableTestClasses.java | 434 ++ .../portable/mutabletest/package-info.java | 22 + .../ignite/internal/portable/package-info.java | 22 + .../portable/test/GridPortableTestClass1.java | 28 + .../portable/test/GridPortableTestClass2.java | 24 + .../internal/portable/test/package-info.java | 22 + .../test/subpackage/GridPortableTestClass3.java | 24 + .../portable/test/subpackage/package-info.java | 22 + ...ClientNodePortableMetadataMultinodeTest.java | 295 ++ ...GridCacheClientNodePortableMetadataTest.java | 286 ++ ...ableObjectsAbstractDataStreamerSelfTest.java | 190 + ...bleObjectsAbstractMultiThreadedSelfTest.java | 231 ++ ...ridCachePortableObjectsAbstractSelfTest.java | 978 +++++ .../GridCachePortableStoreAbstractSelfTest.java | 297 ++ .../GridCachePortableStoreObjectsSelfTest.java | 55 + ...GridCachePortableStorePortablesSelfTest.java | 66 + ...ridPortableCacheEntryMemorySizeSelfTest.java | 55 + ...leDuplicateIndexObjectsAbstractSelfTest.java | 158 + .../DataStreamProcessorPortableSelfTest.java | 66 + .../GridDataStreamerImplSelfTest.java | 345 ++ ...ridCacheAffinityRoutingPortableSelfTest.java | 47 + ...lyPortableDataStreamerMultiNodeSelfTest.java | 29 + ...rtableDataStreamerMultithreadedSelfTest.java | 47 + ...artitionedOnlyPortableMultiNodeSelfTest.java | 28 + ...tionedOnlyPortableMultithreadedSelfTest.java | 47 + .../GridCacheMemoryModePortableSelfTest.java | 36 + ...acheOffHeapTieredAtomicPortableSelfTest.java | 47 + ...eapTieredEvictionAtomicPortableSelfTest.java | 95 + ...heOffHeapTieredEvictionPortableSelfTest.java | 95 + .../GridCacheOffHeapTieredPortableSelfTest.java | 47 + ...ateIndexObjectPartitionedAtomicSelfTest.java | 38 + ...xObjectPartitionedTransactionalSelfTest.java | 41 + ...AtomicNearDisabledOffheapTieredSelfTest.java | 29 + ...rtableObjectsAtomicNearDisabledSelfTest.java | 51 + ...tableObjectsAtomicOffheapTieredSelfTest.java | 29 + .../GridCachePortableObjectsAtomicSelfTest.java | 51 + ...tionedNearDisabledOffheapTieredSelfTest.java | 30 + ...eObjectsPartitionedNearDisabledSelfTest.java | 51 + ...ObjectsPartitionedOffheapTieredSelfTest.java | 30 + ...CachePortableObjectsPartitionedSelfTest.java | 51 + ...sNearPartitionedByteArrayValuesSelfTest.java | 41 + ...sPartitionedOnlyByteArrayValuesSelfTest.java | 42 + ...dCachePortableObjectsReplicatedSelfTest.java | 51 + ...CachePortableObjectsAtomicLocalSelfTest.java | 32 + ...rtableObjectsLocalOffheapTieredSelfTest.java | 29 + .../GridCachePortableObjectsLocalSelfTest.java | 51 + .../ignite/testframework/junits/IgniteMock.java | 8 +- .../multijvm/IgniteCacheProcessProxy.java | 7 +- .../junits/multijvm/IgniteProcessProxy.java | 2 +- .../IgnitePortableCacheFullApiTestSuite.java | 37 + .../IgnitePortableCacheTestSuite.java | 103 + .../IgnitePortableObjectsTestSuite.java | 92 + .../ignite/portable/test1/1.1/test1-1.1.jar | Bin 0 -> 2548 bytes .../ignite/portable/test1/1.1/test1-1.1.pom | 9 + .../portable/test1/maven-metadata-local.xml | 12 + .../ignite/portable/test2/1.1/test2-1.1.jar | Bin 0 -> 1361 bytes .../ignite/portable/test2/1.1/test2-1.1.pom | 9 + .../portable/test2/maven-metadata-local.xml | 12 + .../HadoopDefaultMapReducePlannerSelfTest.java | 6 - .../IgnitePortableCacheQueryTestSuite.java | 117 + .../platform/PlatformContextImpl.java | 4 +- .../platform/compute/PlatformCompute.java | 2 +- .../cpp/PlatformCppConfigurationClosure.java | 2 +- .../PlatformDotNetConfigurationClosure.java | 6 +- .../Config/Compute/compute-grid1.xml | 8 +- .../PlatformComputePortableArgTask.java | 8 +- .../org/apache/ignite/IgniteSpringBean.java | 7 + parent/pom.xml | 10 + 176 files changed, 17425 insertions(+), 2763 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/80c71a89/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java ---------------------------------------------------------------------- diff --cc modules/core/src/main/java/org/apache/ignite/IgnitePortables.java index 0000000,ee0a4ec..1c63df7 mode 000000,100644..100644 --- a/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java +++ b/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java @@@ -1,0 -1,370 +1,370 @@@ + /* + * 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; + + import java.sql.Timestamp; + import java.util.ArrayList; + import java.util.Collection; + import java.util.Date; + import java.util.HashMap; + import java.util.LinkedList; + import java.util.TreeMap; + import java.util.UUID; + import org.apache.ignite.marshaller.portable.PortableMarshaller; + import org.apache.ignite.portable.PortableBuilder; + import org.apache.ignite.portable.PortableException; + import org.apache.ignite.portable.PortableIdMapper; + import org.apache.ignite.portable.PortableMarshalAware; + import org.apache.ignite.portable.PortableMetadata; + import org.apache.ignite.portable.PortableObject; + import org.apache.ignite.portable.PortableSerializer; + import org.apache.ignite.portable.PortableTypeConfiguration; + import org.jetbrains.annotations.Nullable; + + /** + * Defines portable objects functionality. With portable objects you are able to: + *
    + *
  • Seamlessly interoperate between Java, .NET, and C++.
  • + *
  • Make any object portable with zero code change to your existing code.
  • + *
  • Nest portable objects within each other.
  • + *
  • Automatically handle {@code circular} or {@code null} references.
  • + *
  • Automatically convert collections and maps between Java, .NET, and C++.
  • + *
  • + * Optionally avoid deserialization of objects on the server side + * (objects are stored in {@link PortableObject} format). + *
  • + *
  • Avoid need to have concrete class definitions on the server side.
  • + *
  • Dynamically change structure of the classes without having to restart the cluster.
  • + *
  • Index into portable objects for querying purposes.
  • + *
+ *

Working With Portables Directly

+ * Once an object is defined as portable, + * Ignite will always store it in memory in the portable (i.e. binary) format. + * User can choose to work either with the portable format or with the deserialized form + * (assuming that class definitions are present in the classpath). + *

+ * To work with the portable format directly, user should create a special cache projection - * using {@link IgniteCache#withKeepPortable()} method and then retrieve individual fields as needed: ++ * using IgniteCache.withKeepPortable() method and then retrieve individual fields as needed: + *

+  * IgniteCache<PortableObject, PortableObject> prj = cache.withKeepPortable();
+  *
+  * // Convert instance of MyKey to portable format.
+  * // We could also use PortableBuilder to create the key in portable format directly.
+  * PortableObject key = grid.portables().toPortable(new MyKey());
+  *
+  * PortableObject val = prj.get(key);
+  *
+  * String field = val.field("myFieldName");
+  * 
+ * Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized + * typed objects at all times. In this case we do incur the deserialization cost. However, if + * {@link PortableMarshaller#isKeepDeserialized()} is {@code true} then Ignite will only deserialize on the first access + * and will cache the deserialized object, so it does not have to be deserialized again: + *
+  * IgniteCache<MyKey.class, MyValue.class> cache = grid.cache(null);
+  *
+  * MyValue val = cache.get(new MyKey());
+  *
+  * // Normal java getter.
+  * String fieldVal = val.getMyFieldName();
+  * 
+ * If we used, for example, one of the automatically handled portable types for a key, like integer, + * and still wanted to work with binary portable format for values, then we would declare cache projection + * as follows: + *
+  * IgniteCache<Integer.class, PortableObject> prj = cache.withKeepPortable();
+  * 
+ *

Automatic Portable Types

+ * Note that only portable classes are converted to {@link PortableObject} format. Following + * classes are never converted (e.g., {@link #toPortable(Object)} method will return original + * object, and instances of these classes will be stored in cache without changes): + *
    + *
  • All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)
  • + *
  • Arrays of primitives (byte[], int[], ...)
  • + *
  • {@link String} and array of {@link String}s
  • + *
  • {@link UUID} and array of {@link UUID}s
  • + *
  • {@link Date} and array of {@link Date}s
  • + *
  • {@link Timestamp} and array of {@link Timestamp}s
  • + *
  • Enums and array of enums
  • + *
  • + * Maps, collections and array of objects (but objects inside + * them will still be converted if they are portable) + *
  • + *
+ *

Working With Maps and Collections

+ * All maps and collections in the portable objects are serialized automatically. When working + * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most + * adequate collection or map in either language. For example, {@link ArrayList} in Java will become + * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap} + * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary} + * in C#, etc. + *

Building Portable Objects

+ * Ignite comes with {@link PortableBuilder} which allows to build portable objects dynamically: + *
+  * PortableBuilder builder = Ignition.ignite().portables().builder();
+  *
+  * builder.typeId("MyObject");
+  *
+  * builder.stringField("fieldA", "A");
+  * build.intField("fieldB", "B");
+  *
+  * PortableObject portableObj = builder.build();
+  * 
+ * For the cases when class definition is present + * in the class path, it is also possible to populate a standard POJO and then + * convert it to portable format, like so: + *
+  * MyObject obj = new MyObject();
+  *
+  * obj.setFieldA("A");
+  * obj.setFieldB(123);
+  *
+  * PortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
+  * 
+ * NOTE: you don't need to convert typed objects to portable format before storing + * them in cache, Ignite will do that automatically. + *

Portable Metadata

+ * Even though Ignite portable protocol only works with hash codes for type and field names + * to achieve better performance, Ignite provides metadata for all portable types which + * can be queried ar runtime via any of the {@link IgnitePortables#metadata(Class)} + * methods. Having metadata also allows for proper formatting of {@code PortableObject#toString()} method, + * even when portable objects are kept in binary format only, which may be necessary for audit reasons. + *

Dynamic Structure Changes

+ * Since objects are always cached in the portable binary format, server does not need to + * be aware of the class definitions. Moreover, if class definitions are not present or not + * used on the server, then clients can continuously change the structure of the portable + * objects without having to restart the cluster. For example, if one client stores a + * certain class with fields A and B, and another client stores the same class with + * fields B and C, then the server-side portable object will have the fields A, B, and C. + * As the structure of a portable object changes, the new fields become available for SQL queries + * automatically. + *

Configuration

+ * By default all your objects are considered as portables and no specific configuration is needed. + * However, in some cases, like when an object is used by both Java and .Net, you may need to specify portable objects + * explicitly by calling {@link PortableMarshaller#setClassNames(Collection)}. + * The only requirement Ignite imposes is that your object has an empty + * constructor. Note, that since server side does not have to know the class definition, + * you only need to list portable objects in configuration on the client side. However, if you + * list them on the server side as well, then you get the ability to deserialize portable objects + * into concrete types on the server as well as on the client. + *

+ * Here is an example of portable configuration (note that star (*) notation is supported): + *

+  * ...
+  * <!-- Explicit portable objects configuration. -->
+  * <property name="marshaller">
+  *     <bean class="org.apache.ignite.marshaller.portable.PortableMarshaller">
+  *         <property name="classNames">
+  *             <list>
+  *                 <value>my.package.for.portable.objects.*</value>
+  *                 <value>org.apache.ignite.examples.client.portable.Employee</value>
+  *             </list>
+  *         </property>
+  *     </bean>
+  * </property>
+  * ...
+  * 
+ * or from code: + *
+  * IgniteConfiguration cfg = new IgniteConfiguration();
+  *
+  * PortableMarshaller marsh = new PortableMarshaller();
+  *
+  * marsh.setClassNames(Arrays.asList(
+  *     Employee.class.getName(),
+  *     Address.class.getName())
+  * );
+  *
+  * cfg.setMarshaller(marsh);
+  * 
+ * You can also specify class name for a portable object via {@link PortableTypeConfiguration}. + * Do it in case if you need to override other configuration properties on per-type level, like + * ID-mapper, or serializer. + *

Custom Affinity Keys

+ * Often you need to specify an alternate key (not the cache key) for affinity routing whenever + * storing objects in cache. For example, if you are caching {@code Employee} object with + * {@code Organization}, and want to colocate employees with organization they work for, + * so you can process them together, you need to specify an alternate affinity key. + * With portable objects you would have to do it as following: + *
+  * <property name="marshaller">
+  *     <bean class="org.gridgain.grid.marshaller.portable.PortableMarshaller">
+  *         ...
+  *         <property name="typeConfigurations">
+  *             <list>
+  *                 <bean class="org.apache.ignite.portable.PortableTypeConfiguration">
+  *                     <property name="className" value="org.apache.ignite.examples.client.portable.EmployeeKey"/>
+  *                     <property name="affinityKeyFieldName" value="organizationId"/>
+  *                 </bean>
+  *             </list>
+  *         </property>
+  *         ...
+  *     </bean>
+  * </property>
+  * 
+ *

Serialization

+ * Serialization and deserialization works out-of-the-box in Ignite. However, you can provide your own custom + * serialization logic by optionally implementing {@link PortableMarshalAware} interface, like so: + *
+  * public class Address implements PortableMarshalAware {
+  *     private String street;
+  *     private int zip;
+  *
+  *     // Empty constructor required for portable deserialization.
+  *     public Address() {}
+  *
+  *     @Override public void writePortable(PortableWriter writer) throws PortableException {
+  *         writer.writeString("street", street);
+  *         writer.writeInt("zip", zip);
+  *     }
+  *
+  *     @Override public void readPortable(PortableReader reader) throws PortableException {
+  *         street = reader.readString("street");
+  *         zip = reader.readInt("zip");
+  *     }
+  * }
+  * 
+ * Alternatively, if you cannot change class definitions, you can provide custom serialization + * logic in {@link PortableSerializer} either globally in {@link PortableMarshaller} or + * for a specific type via {@link PortableTypeConfiguration} instance. + *

+ * Similar to java serialization you can use {@code writeReplace()} and {@code readResolve()} methods. + *

    + *
  • + * {@code readResolve} is defined as follows: {@code ANY-ACCESS-MODIFIER Object readResolve()}. + * It may be used to replace the de-serialized object by another one of your choice. + *
  • + *
  • + * {@code writeReplace} is defined as follows: {@code ANY-ACCESS-MODIFIER Object writeReplace()}. This method + * allows the developer to provide a replacement object that will be serialized instead of the original one. + *
  • + *
+ * + *

Custom ID Mappers

+ * Ignite implementation uses name hash codes to generate IDs for class names or field names + * internally. However, in cases when you want to provide your own ID mapping schema, + * you can provide your own {@link PortableIdMapper} implementation. + *

+ * ID-mapper may be provided either globally in {@link PortableMarshaller}, + * or for a specific type via {@link PortableTypeConfiguration} instance. + *

Query Indexing

+ * Portable objects can be indexed for querying by specifying index fields in + * {@link org.apache.ignite.cache.CacheTypeMetadata} inside of specific + * {@link org.apache.ignite.configuration.CacheConfiguration} instance, + * like so: + *
+  * ...
+  * <bean class="org.apache.ignite.cache.CacheConfiguration">
+  *     ...
+  *     <property name="typeMetadata">
+  *         <list>
+  *             <bean class="CacheTypeMetadata">
+  *                 <property name="type" value="Employee"/>
+  *
+  *                 <!-- Fields to index in ascending order. -->
+  *                 <property name="ascendingFields">
+  *                     <map>
+  *                     <entry key="name" value="java.lang.String"/>
+  *
+  *                         <!-- Nested portable objects can also be indexed. -->
+  *                         <entry key="address.zip" value="java.lang.Integer"/>
+  *                     </map>
+  *                 </property>
+  *             </bean>
+  *         </list>
+  *     </property>
+  * </bean>
+  * 
+ */ + public interface IgnitePortables { + /** + * Gets type ID for given type name. + * + * @param typeName Type name. + * @return Type ID. + */ + public int typeId(String typeName); + + /** + * Converts provided object to instance of {@link PortableObject}. + * + * @param obj Object to convert. + * @return Converted object. + * @throws PortableException In case of error. + */ + public T toPortable(@Nullable Object obj) throws PortableException; + + /** + * Creates new portable builder. + * + * @param typeId ID of the type. + * @return Newly portable builder. + */ + public PortableBuilder builder(int typeId); + + /** + * Creates new portable builder. + * + * @param typeName Type name. + * @return Newly portable builder. + */ + public PortableBuilder builder(String typeName); + + /** + * Creates portable builder initialized by existing portable object. + * + * @param portableObj Portable object to initialize builder. + * @return Portable builder. + */ + public PortableBuilder builder(PortableObject portableObj); + + /** + * Gets metadata for provided class. + * + * @param cls Class. + * @return Metadata. + * @throws PortableException In case of error. + */ + @Nullable public PortableMetadata metadata(Class cls) throws PortableException; + + /** + * Gets metadata for provided class name. + * + * @param typeName Type name. + * @return Metadata. + * @throws PortableException In case of error. + */ + @Nullable public PortableMetadata metadata(String typeName) throws PortableException; + + /** + * Gets metadata for provided type ID. + * + * @param typeId Type ID. + * @return Metadata. + * @throws PortableException In case of error. + */ + @Nullable public PortableMetadata metadata(int typeId) throws PortableException; + + /** + * Gets metadata for all known types. + * + * @return Metadata. + * @throws PortableException In case of error. + */ + public Collection metadata() throws PortableException; + } http://git-wip-us.apache.org/repos/asf/ignite/blob/80c71a89/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java ---------------------------------------------------------------------- diff --cc modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java index 6ac2b64,9fb56bc..eafaf65 --- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java @@@ -17,25 -17,10 +17,17 @@@ package org.apache.ignite.configuration; +import java.io.Serializable; +import java.util.Collection; +import java.util.HashSet; +import javax.cache.Cache; +import javax.cache.configuration.CompleteConfiguration; +import javax.cache.configuration.Factory; +import javax.cache.configuration.MutableConfiguration; +import javax.cache.expiry.ExpiryPolicy; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; - import org.apache.ignite.cache.CacheAtomicWriteOrderMode; - import org.apache.ignite.cache.CacheAtomicityMode; - import org.apache.ignite.cache.CacheEntryProcessor; - import org.apache.ignite.cache.CacheInterceptor; - import org.apache.ignite.cache.CacheMemoryMode; - import org.apache.ignite.cache.CacheMode; - import org.apache.ignite.cache.CacheRebalanceMode; - import org.apache.ignite.cache.CacheTypeMetadata; - import org.apache.ignite.cache.CacheWriteSynchronizationMode; -import org.apache.ignite.IgniteException; + import org.apache.ignite.cache.*; import org.apache.ignite.cache.affinity.AffinityFunction; import org.apache.ignite.cache.affinity.AffinityKeyMapper; import org.apache.ignite.cache.eviction.EvictionFilter; http://git-wip-us.apache.org/repos/asf/ignite/blob/80c71a89/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/80c71a89/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/80c71a89/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/80c71a89/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/80c71a89/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/80c71a89/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java ---------------------------------------------------------------------- diff --cc modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java index 0000000,bfc34cd..e3905cd mode 000000,100644..100644 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java @@@ -1,0 -1,358 +1,358 @@@ + /* + * 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.marshaller.portable; + + import java.io.ByteArrayOutputStream; + import java.io.IOException; + import java.io.InputStream; + import java.io.OutputStream; + import java.sql.Timestamp; + import java.util.ArrayList; + import java.util.Collection; + import org.apache.ignite.IgniteCheckedException; + import org.apache.ignite.internal.portable.GridPortableMarshaller; + import org.apache.ignite.internal.portable.PortableContext; + import org.apache.ignite.marshaller.AbstractMarshaller; + import org.apache.ignite.marshaller.MarshallerContext; + import org.apache.ignite.portable.PortableException; + import org.apache.ignite.portable.PortableIdMapper; + import org.apache.ignite.portable.PortableObject; + import org.apache.ignite.portable.PortableProtocolVersion; + import org.apache.ignite.portable.PortableSerializer; + import org.apache.ignite.portable.PortableTypeConfiguration; + import org.jetbrains.annotations.Nullable; + + /** + * Implementation of {@link org.apache.ignite.marshaller.Marshaller} that lets to serialize and deserialize all objects + * in the portable format. + *

+ * {@code PortableMarshaller} is tested only on Java HotSpot VM on other VMs it could yield unexpected results. + *

+ *

Configuration

+ *

Mandatory

+ * This marshaller has no mandatory configuration parameters. + *

Java Example

+ *
+  * PortableMarshaller marshaller = new PortableMarshaller();
+  *
+  * IgniteConfiguration cfg = new IgniteConfiguration();
+  *
+  * // Override marshaller.
+  * cfg.setMarshaller(marshaller);
+  *
+  * // Starts grid.
+  * G.start(cfg);
+  * 
+ *

Spring Example

+ * PortableMarshaller can be configured from Spring XML configuration file: + *
+  * <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>
+  * 
+ *

+ * + *
+ * For information about Spring framework visit www.springframework.org + */ + public class PortableMarshaller extends AbstractMarshaller { + /** Default portable protocol version. */ + public static final PortableProtocolVersion DFLT_PORTABLE_PROTO_VER = PortableProtocolVersion.VER_1_4_0; + + /** Class names. */ + private Collection clsNames; + + /** ID mapper. */ + private PortableIdMapper idMapper; + + /** Serializer. */ + private PortableSerializer serializer; + + /** Types. */ + private Collection typeCfgs; + + /** Use timestamp flag. */ + private boolean useTs = true; + + /** Whether to convert string to bytes using UTF-8 encoding. */ + private boolean convertString = true; + + /** Meta data enabled flag. */ + private boolean metaDataEnabled = true; + + /** Keep deserialized flag. */ + private boolean keepDeserialized = true; + + /** Protocol version. */ + private PortableProtocolVersion protoVer = DFLT_PORTABLE_PROTO_VER; + + /** */ + private GridPortableMarshaller impl; + + /** + * Gets class names. + * + * @return Class names. + */ + public Collection getClassNames() { + return clsNames; + } + + /** + * Sets class names of portable objects explicitly. + * + * @param clsNames Class names. + */ + public void setClassNames(Collection clsNames) { + this.clsNames = new ArrayList<>(clsNames.size()); + + for (String clsName : clsNames) + this.clsNames.add(clsName.trim()); + } + + /** + * Gets ID mapper. + * + * @return ID mapper. + */ + public PortableIdMapper getIdMapper() { + return idMapper; + } + + /** + * Sets ID mapper. + * + * @param idMapper ID mapper. + */ + public void setIdMapper(PortableIdMapper idMapper) { + this.idMapper = idMapper; + } + + /** + * Gets serializer. + * + * @return Serializer. + */ + public PortableSerializer getSerializer() { + return serializer; + } + + /** + * Sets serializer. + * + * @param serializer Serializer. + */ + public void setSerializer(PortableSerializer serializer) { + this.serializer = serializer; + } + + /** + * Gets types configuration. + * + * @return Types configuration. + */ + public Collection getTypeConfigurations() { + return typeCfgs; + } + + /** + * Sets type configurations. + * + * @param typeCfgs Type configurations. + */ + public void setTypeConfigurations(Collection typeCfgs) { + this.typeCfgs = typeCfgs; + } + + /** + * If {@code true} then date values converted to {@link Timestamp} on deserialization. + *

+ * Default value is {@code true}. + * + * @return Flag indicating whether date values converted to {@link Timestamp} during unmarshalling. + */ + public boolean isUseTimestamp() { + return useTs; + } + + /** + * @param useTs Flag indicating whether date values converted to {@link Timestamp} during unmarshalling. + */ + public void setUseTimestamp(boolean useTs) { + this.useTs = useTs; + } + + /** + * Gets strings must be converted to or from bytes using UTF-8 encoding. + *

+ * Default value is {@code true}. + * + * @return Flag indicating whether string must be converted to byte array using UTF-8 encoding. + */ + public boolean isConvertStringToBytes() { + return convertString; + } + + /** + * Sets strings must be converted to or from bytes using UTF-8 encoding. + *

+ * Default value is {@code true}. + * + * @param convertString Flag indicating whether string must be converted to byte array using UTF-8 encoding. + */ + public void setConvertStringToBytes(boolean convertString) { + this.convertString = convertString; + } + + /** + * If {@code true}, meta data will be collected or all types. If you need to override this behaviour for + * some specific type, use {@link PortableTypeConfiguration#setMetaDataEnabled(Boolean)} method. + *

+ * Default value if {@code true}. + * + * @return Whether meta data is collected. + */ + public boolean isMetaDataEnabled() { + return metaDataEnabled; + } + + /** + * @param metaDataEnabled Whether meta data is collected. + */ + public void setMetaDataEnabled(boolean metaDataEnabled) { + this.metaDataEnabled = metaDataEnabled; + } + + /** + * If {@code true}, {@link PortableObject} will cache deserialized instance after + * {@link PortableObject#deserialize()} is called. All consequent calls of this + * method on the same instance of {@link PortableObject} will return that cached + * value without actually deserializing portable object. If you need to override this + * behaviour for some specific type, use {@link PortableTypeConfiguration#setKeepDeserialized(Boolean)} + * method. + *

+ * Default value if {@code true}. + * + * @return Whether deserialized value is kept. + */ + public boolean isKeepDeserialized() { + return keepDeserialized; + } + + /** + * @param keepDeserialized Whether deserialized value is kept. + */ + public void setKeepDeserialized(boolean keepDeserialized) { + this.keepDeserialized = keepDeserialized; + } + + /** + * Gets portable protocol version. + *

+ * Defaults to {@link #DFLT_PORTABLE_PROTO_VER}. + * + * @return Portable protocol version. + */ + public PortableProtocolVersion getProtocolVersion() { + return protoVer; + } + + /** + * Sets portable protocol version. + *

+ * Defaults to {@link #DFLT_PORTABLE_PROTO_VER}. + * + * @param protoVer Portable protocol version. + */ + public void setProtocolVersion(PortableProtocolVersion protoVer) { + if (protoVer == null) + throw new IllegalArgumentException("Wrong portable protocol version: " + protoVer); + + this.protoVer = protoVer; + } + + /** + * Returns currently set {@link MarshallerContext}. + * + * @return Marshaller context. + */ + public MarshallerContext getContext() { + return ctx; + } + + /** + * Sets {@link PortableContext}. + *

+ * @param ctx Portable context. + */ + private void setPortableContext(PortableContext ctx) { + ctx.configure(this); + + impl = new GridPortableMarshaller(ctx); + } + + /** {@inheritDoc} */ + @Override public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException { + return impl.marshal(obj, 0); + } + + /** {@inheritDoc} */ + @Override public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException { + byte[] arr = marshal(obj); + + try { + out.write(arr); + } + catch (IOException e) { + throw new PortableException("Failed to marshal the object: " + obj, e); + } + } + + /** {@inheritDoc} */ + @Override public T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws IgniteCheckedException { + return impl.deserialize(bytes, clsLdr); + } + + /** {@inheritDoc} */ + @Override public T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ++ ByteArrayOutputStream buf = new ByteArrayOutputStream(); + + byte[] arr = new byte[4096]; + int cnt; + + // we have to fully read the InputStream because GridPortableMarshaller requires support of a method that + // returns number of bytes remaining. + try { + while ((cnt = in.read(arr)) != -1) - buffer.write(arr, 0, cnt); ++ buf.write(arr, 0, cnt); + - buffer.flush(); ++ buf.flush(); + - return impl.deserialize(buffer.toByteArray(), clsLdr); ++ return impl.deserialize(buf.toByteArray(), clsLdr); + } + catch (IOException e) { + throw new PortableException("Failed to unmarshal the object from InputStream", e); + } + } + } http://git-wip-us.apache.org/repos/asf/ignite/blob/80c71a89/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java ---------------------------------------------------------------------- diff --cc modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java index d89e397,2b448f8..134ee33 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java @@@ -129,8 -153,12 +129,13 @@@ public class IgniteCacheProcessProxy p, @Nullable Object... args) + @Override public IgniteCache withKeepPortable() { + throw new UnsupportedOperationException("Method should be supported."); + } + + /** {@inheritDoc} */ - @Override public void loadCache(@Nullable IgniteBiPredicate p, @Nullable Object... args) throws CacheException { ++ @Override public void loadCache(@Nullable IgniteBiPredicate p, @Nullable Object... args) + throws CacheException { throw new UnsupportedOperationException("Method should be supported."); } http://git-wip-us.apache.org/repos/asf/ignite/blob/80c71a89/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java ----------------------------------------------------------------------