You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2017/04/14 11:22:41 UTC
[01/10] ignite git commit: IGNITE-4938: Moved OptimizedMarshaller to
private package. This closes #1793.
Repository: ignite
Updated Branches:
refs/heads/master a025268da -> 1676ff656
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/spring/src/test/java/org/apache/ignite/internal/GridSpringBeanSerializationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/GridSpringBeanSerializationSelfTest.java b/modules/spring/src/test/java/org/apache/ignite/internal/GridSpringBeanSerializationSelfTest.java
index 390a528..4c0613f 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/GridSpringBeanSerializationSelfTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/GridSpringBeanSerializationSelfTest.java
@@ -22,7 +22,7 @@ import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/web-console/frontend/app/modules/configuration/generator/ConfigurationGenerator.js
----------------------------------------------------------------------
diff --git a/modules/web-console/frontend/app/modules/configuration/generator/ConfigurationGenerator.js b/modules/web-console/frontend/app/modules/configuration/generator/ConfigurationGenerator.js
index 670b828..dfb0669 100644
--- a/modules/web-console/frontend/app/modules/configuration/generator/ConfigurationGenerator.js
+++ b/modules/web-console/frontend/app/modules/configuration/generator/ConfigurationGenerator.js
@@ -1179,7 +1179,7 @@ export default class IgniteConfigurationGenerator {
switch (kind) {
case 'OptimizedMarshaller':
- bean = new Bean('org.apache.ignite.marshaller.optimized.OptimizedMarshaller', 'marshaller', settings)
+ bean = new Bean('org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller', 'marshaller', settings)
.intProperty('poolSize')
.intProperty('requireSerializable');
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/web/src/test/webapp2/META-INF/ignite-webapp-config.xml
----------------------------------------------------------------------
diff --git a/modules/web/src/test/webapp2/META-INF/ignite-webapp-config.xml b/modules/web/src/test/webapp2/META-INF/ignite-webapp-config.xml
index 53848fe..e504fe7 100644
--- a/modules/web/src/test/webapp2/META-INF/ignite-webapp-config.xml
+++ b/modules/web/src/test/webapp2/META-INF/ignite-webapp-config.xml
@@ -42,7 +42,7 @@
Configure optimized marshaller.
-->
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
<!--
For better performance set this property to true in case
all marshalled classes implement java.io.Serializable.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/yardstick/config/ignite-int-max-values-onheap-config.xml
----------------------------------------------------------------------
diff --git a/modules/yardstick/config/ignite-int-max-values-onheap-config.xml b/modules/yardstick/config/ignite-int-max-values-onheap-config.xml
index c0d777d..242ae7d 100644
--- a/modules/yardstick/config/ignite-int-max-values-onheap-config.xml
+++ b/modules/yardstick/config/ignite-int-max-values-onheap-config.xml
@@ -29,7 +29,7 @@
<property name="peerClassLoadingEnabled" value="true"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
<property name="requireSerializable" value="false"/>
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/yardstick/config/ignite-jdbc-config.xml
----------------------------------------------------------------------
diff --git a/modules/yardstick/config/ignite-jdbc-config.xml b/modules/yardstick/config/ignite-jdbc-config.xml
index 9428858..b944a6b 100644
--- a/modules/yardstick/config/ignite-jdbc-config.xml
+++ b/modules/yardstick/config/ignite-jdbc-config.xml
@@ -33,7 +33,7 @@
<property name="localHost" value="127.0.0.1"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
<property name="requireSerializable" value="false"/>
</bean>
</property>
[10/10] ignite git commit: Merge remote-tracking branch
'origin/master'
Posted by vo...@apache.org.
Merge remote-tracking branch 'origin/master'
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1676ff65
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1676ff65
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1676ff65
Branch: refs/heads/master
Commit: 1676ff656b3ea3efbc32864f333c43e3edde3318
Parents: a1b5b8c a025268
Author: devozerov <vo...@gridgain.com>
Authored: Fri Apr 14 14:22:26 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Fri Apr 14 14:22:26 2017 +0300
----------------------------------------------------------------------
.../rest/client/message/GridClientNodeBean.java | 2 +-
.../top/GridTopologyCommandHandler.java | 4 +
.../visor/service/VisorServiceDescriptor.java | 9 +-
...ryConfigurationCustomSerializerSelfTest.java | 147 +++++++++++++++++++
.../IgniteBinaryObjectsTestSuite.java | 2 +
.../platforms/cpp/core-test/src/cache_test.cpp | 38 ++---
.../frontend/app/helpers/jade/mixins.pug | 12 +-
.../frontend/app/modules/sql/sql.controller.js | 6 -
.../frontend/app/primitives/btn-group/index.pug | 35 +++++
.../views/configuration/domains-import.tpl.pug | 2 +-
.../views/configuration/domains.tpl.pug | 1 -
.../web-console/frontend/views/sql/sql.tpl.pug | 12 +-
12 files changed, 228 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
[06/10] ignite git commit: IGNITE-4938: Moved OptimizedMarshaller to
private package. This closes #1793.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
deleted file mode 100644
index 95a301b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
+++ /dev/null
@@ -1,1231 +0,0 @@
-/*
- * 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.optimized;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.NotActiveException;
-import java.io.ObjectInputStream;
-import java.io.ObjectInputValidation;
-import java.io.ObjectStreamClass;
-import java.lang.reflect.Array;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Properties;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentMap;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.io.GridDataInput;
-import org.apache.ignite.internal.util.typedef.internal.SB;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.MarshallerContext;
-
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.ARRAY_LIST;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.BOOLEAN;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.BOOLEAN_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.BYTE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.BYTE_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.CHAR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.CHAR_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.CLS;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.DATE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.DOUBLE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.DOUBLE_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.ENUM;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.EXTERNALIZABLE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.FLOAT;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.FLOAT_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.HANDLE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.HASH_MAP;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.HASH_SET;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.HASH_SET_MAP_OFF;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.INT;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.INT_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.JDK;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.JDK_MARSH;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LINKED_HASH_MAP;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LINKED_HASH_SET;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LINKED_LIST;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LONG;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LONG_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.NULL;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.OBJ_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.PROPS;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.PROXY;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SERIALIZABLE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SHORT;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SHORT_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.STR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.UUID;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.classDescriptor;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.setBoolean;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.setByte;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.setChar;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.setDouble;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.setFloat;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.setInt;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.setLong;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.setObject;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.setShort;
-
-/**
- * Optimized object input stream.
- */
-class OptimizedObjectInputStream extends ObjectInputStream {
- /** Dummy object for HashSet. */
- private static final Object DUMMY = new Object();
-
- /** */
- private final HandleTable handles = new HandleTable(10);
-
- /** */
- private MarshallerContext ctx;
-
- /** */
- private OptimizedMarshallerIdMapper mapper;
-
- /** */
- private ClassLoader clsLdr;
-
- /** */
- private GridDataInput in;
-
- /** */
- private Object curObj;
-
- /** */
- private OptimizedClassDescriptor.ClassFields curFields;
-
- /** */
- private Class<?> curCls;
-
- /** */
- private ConcurrentMap<Class, OptimizedClassDescriptor> clsMap;
-
- /**
- * @param in Input.
- * @throws IOException In case of error.
- */
- OptimizedObjectInputStream(GridDataInput in) throws IOException {
- this.in = in;
- }
-
- /**
- * @param clsMap Class descriptors by class map.
- * @param ctx Context.
- * @param mapper ID mapper.
- * @param clsLdr Class loader.
- */
- void context(
- ConcurrentMap<Class, OptimizedClassDescriptor> clsMap,
- MarshallerContext ctx,
- OptimizedMarshallerIdMapper mapper,
- ClassLoader clsLdr)
- {
- this.clsMap = clsMap;
- this.ctx = ctx;
- this.mapper = mapper;
- this.clsLdr = clsLdr;
- }
-
- /**
- * @return Input.
- */
- public GridDataInput in() {
- return in;
- }
-
- /**
- * @param in Input.
- */
- public void in(GridDataInput in) {
- this.in = in;
- }
-
- /** {@inheritDoc} */
- @Override public void close() throws IOException {
- reset();
-
- ctx = null;
- clsLdr = null;
- clsMap = null;
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod")
- @Override public void reset() throws IOException {
- in.reset();
- handles.clear();
-
- curObj = null;
- curFields = null;
- }
-
- /** {@inheritDoc} */
- @Override public Object readObjectOverride() throws ClassNotFoundException, IOException {
- curObj = null;
- curFields = null;
-
- byte ref = in.readByte();
-
- switch (ref) {
- case NULL:
- return null;
-
- case HANDLE:
- return handles.lookup(readInt());
-
- case JDK:
- try {
- return JDK_MARSH.unmarshal(this, clsLdr);
- }
- catch (IgniteCheckedException e) {
- IOException ioEx = e.getCause(IOException.class);
-
- if (ioEx != null)
- throw ioEx;
- else
- throw new IOException("Failed to deserialize object with JDK marshaller.", e);
- }
-
- case BYTE:
- return readByte();
-
- case SHORT:
- return readShort();
-
- case INT:
- return readInt();
-
- case LONG:
- return readLong();
-
- case FLOAT:
- return readFloat();
-
- case DOUBLE:
- return readDouble();
-
- case CHAR:
- return readChar();
-
- case BOOLEAN:
- return readBoolean();
-
- case BYTE_ARR:
- return readByteArray();
-
- case SHORT_ARR:
- return readShortArray();
-
- case INT_ARR:
- return readIntArray();
-
- case LONG_ARR:
- return readLongArray();
-
- case FLOAT_ARR:
- return readFloatArray();
-
- case DOUBLE_ARR:
- return readDoubleArray();
-
- case CHAR_ARR:
- return readCharArray();
-
- case BOOLEAN_ARR:
- return readBooleanArray();
-
- case OBJ_ARR:
- return readArray(readClass());
-
- case STR:
- return readString();
-
- case UUID:
- return readUuid();
-
- case PROPS:
- return readProperties();
-
- case ARRAY_LIST:
- return readArrayList();
-
- case HASH_MAP:
- return readHashMap(false);
-
- case HASH_SET:
- return readHashSet(HASH_SET_MAP_OFF);
-
- case LINKED_LIST:
- return readLinkedList();
-
- case LINKED_HASH_MAP:
- return readLinkedHashMap(false);
-
- case LINKED_HASH_SET:
- return readLinkedHashSet(HASH_SET_MAP_OFF);
-
- case DATE:
- return readDate();
-
- case CLS:
- return readClass();
-
- case PROXY:
- Class<?>[] intfs = new Class<?>[readInt()];
-
- for (int i = 0; i < intfs.length; i++)
- intfs[i] = readClass();
-
- InvocationHandler ih = (InvocationHandler)readObject();
-
- return Proxy.newProxyInstance(clsLdr != null ? clsLdr : U.gridClassLoader(), intfs, ih);
-
- case ENUM:
- case EXTERNALIZABLE:
- case SERIALIZABLE:
- int typeId = readInt();
-
- OptimizedClassDescriptor desc = typeId == 0 ?
- classDescriptor(clsMap, U.forName(readUTF(), clsLdr), ctx, mapper):
- classDescriptor(clsMap, typeId, clsLdr, ctx, mapper);
-
- curCls = desc.describedClass();
-
- return desc.read(this);
-
- default:
- SB msg = new SB("Unexpected error occurred during unmarshalling");
-
- if (curCls != null)
- msg.a(" of an instance of the class: ").a(curCls.getName());
-
- msg.a(". Check that all nodes are running the same version of Ignite and that all nodes have " +
- "GridOptimizedMarshaller configured with identical optimized classes lists, if any " +
- "(see setClassNames and setClassNamesPath methods). If your serialized classes implement " +
- "java.io.Externalizable interface, verify that serialization logic is correct.");
-
- throw new IOException(msg.toString());
- }
- }
-
- /**
- * @return Class.
- * @throws ClassNotFoundException If class was not found.
- * @throws IOException In case of other error.
- */
- private Class<?> readClass() throws ClassNotFoundException, IOException {
- int compTypeId = readInt();
-
- return compTypeId == 0 ? U.forName(readUTF(), clsLdr) :
- classDescriptor(clsMap, compTypeId, clsLdr, ctx, mapper).describedClass();
- }
-
- /**
- * Reads array from this stream.
- *
- * @param compType Array component type.
- * @return Array.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("unchecked")
- <T> T[] readArray(Class<T> compType) throws ClassNotFoundException, IOException {
- int len = in.readInt();
-
- T[] arr = (T[])Array.newInstance(compType, len);
-
- handles.assign(arr);
-
- for (int i = 0; i < len; i++)
- arr[i] = (T)readObject();
-
- return arr;
- }
-
- /**
- * Reads {@link UUID} from this stream.
- *
- * @return UUID.
- * @throws IOException In case of error.
- */
- UUID readUuid() throws IOException {
- UUID uuid = new UUID(readLong(), readLong());
-
- handles.assign(uuid);
-
- return uuid;
- }
-
- /**
- * Reads {@link Properties} from this stream.
- *
- * @return Properties.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- Properties readProperties() throws ClassNotFoundException, IOException {
- Properties dflts = readBoolean() ? null : (Properties)readObject();
-
- Properties props = new Properties(dflts);
-
- int size = in.readInt();
-
- for (int i = 0; i < size; i++)
- props.setProperty(readUTF(), readUTF());
-
- handles.assign(props);
-
- return props;
- }
-
- /**
- * Reads and sets all non-static and non-transient field values from this stream.
- *
- * @param obj Object.
- * @param fieldOffs Field offsets.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- void readFields(Object obj, OptimizedClassDescriptor.ClassFields fieldOffs) throws ClassNotFoundException,
- IOException {
- for (int i = 0; i < fieldOffs.size(); i++) {
- OptimizedClassDescriptor.FieldInfo t = fieldOffs.get(i);
-
- switch ((t.type())) {
- case BYTE:
- byte resByte = readByte();
-
- if (t.field() != null)
- setByte(obj, t.offset(), resByte);
-
- break;
-
- case SHORT:
- short resShort = readShort();
-
- if (t.field() != null)
- setShort(obj, t.offset(), resShort);
-
- break;
-
- case INT:
- int resInt = readInt();
-
- if (t.field() != null)
- setInt(obj, t.offset(), resInt);
-
- break;
-
- case LONG:
- long resLong = readLong();
-
- if (t.field() != null)
- setLong(obj, t.offset(), resLong);
-
- break;
-
- case FLOAT:
- float resFloat = readFloat();
-
- if (t.field() != null)
- setFloat(obj, t.offset(), resFloat);
-
- break;
-
- case DOUBLE:
- double resDouble = readDouble();
-
- if (t.field() != null)
- setDouble(obj, t.offset(), resDouble);
-
- break;
-
- case CHAR:
- char resChar = readChar();
-
- if (t.field() != null)
- setChar(obj, t.offset(), resChar);
-
- break;
-
- case BOOLEAN:
- boolean resBoolean = readBoolean();
-
- if (t.field() != null)
- setBoolean(obj, t.offset(), resBoolean);
-
- break;
-
- case OTHER:
- Object resObject = readObject();
-
- if (t.field() != null)
- setObject(obj, t.offset(), resObject);
- }
- }
- }
-
- /**
- * Reads {@link Externalizable} object.
- *
- * @param constructor Constructor.
- * @param readResolveMtd {@code readResolve} method.
- * @return Object.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- Object readExternalizable(Constructor<?> constructor, Method readResolveMtd)
- throws ClassNotFoundException, IOException {
- Object obj;
-
- try {
- obj = constructor.newInstance();
- }
- catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
- throw new IOException(e);
- }
-
- int handle = handles.assign(obj);
-
- Externalizable extObj = ((Externalizable)obj);
-
- extObj.readExternal(this);
-
- if (readResolveMtd != null) {
- try {
- obj = readResolveMtd.invoke(obj);
-
- handles.set(handle, obj);
- }
- catch (IllegalAccessException | InvocationTargetException e) {
- throw new IOException(e);
- }
- }
-
- return obj;
- }
-
- /**
- * Reads serializable object.
- *
- * @param cls Class.
- * @param mtds {@code readObject} methods.
- * @param readResolveMtd {@code readResolve} method.
- * @param fields class fields details.
- * @return Object.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- Object readSerializable(Class<?> cls, List<Method> mtds, Method readResolveMtd,
- OptimizedClassDescriptor.Fields fields) throws ClassNotFoundException, IOException {
- Object obj;
-
- try {
- obj = GridUnsafe.allocateInstance(cls);
- }
- catch (InstantiationException e) {
- throw new IOException(e);
- }
-
- int handle = handles.assign(obj);
-
- for (int i = 0; i < mtds.size(); i++) {
- Method mtd = mtds.get(i);
-
- if (mtd != null) {
- curObj = obj;
- curFields = fields.fields(i);
-
- try {
- mtd.invoke(obj, this);
- }
- catch (IllegalAccessException | InvocationTargetException e) {
- throw new IOException(e);
- }
- }
- else
- readFields(obj, fields.fields(i));
- }
-
- if (readResolveMtd != null) {
- try {
- obj = readResolveMtd.invoke(obj);
-
- handles.set(handle, obj);
- }
- catch (IllegalAccessException | InvocationTargetException e) {
- throw new IOException(e);
- }
- }
-
- return obj;
- }
-
- /**
- * Reads {@link ArrayList}.
- *
- * @return List.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- ArrayList<?> readArrayList() throws ClassNotFoundException, IOException {
- int size = readInt();
-
- ArrayList<Object> list = new ArrayList<>(size);
-
- handles.assign(list);
-
- for (int i = 0; i < size; i++)
- list.add(readObject());
-
- return list;
- }
-
- /**
- * Reads {@link HashMap}.
- *
- * @param set Whether reading underlying map from {@link HashSet}.
- * @return Map.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- HashMap<?, ?> readHashMap(boolean set) throws ClassNotFoundException, IOException {
- int size = readInt();
- float loadFactor = readFloat();
-
- HashMap<Object, Object> map = new HashMap<>(size, loadFactor);
-
- if (!set)
- handles.assign(map);
-
- for (int i = 0; i < size; i++) {
- Object key = readObject();
- Object val = !set ? readObject() : DUMMY;
-
- map.put(key, val);
- }
-
- return map;
- }
-
- /**
- * Reads {@link HashSet}.
- *
- * @param mapFieldOff Map field offset.
- * @return Set.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("unchecked")
- HashSet<?> readHashSet(long mapFieldOff) throws ClassNotFoundException, IOException {
- try {
- HashSet<Object> set = (HashSet<Object>)GridUnsafe.allocateInstance(HashSet.class);
-
- handles.assign(set);
-
- setObject(set, mapFieldOff, readHashMap(true));
-
- return set;
- }
- catch (InstantiationException e) {
- throw new IOException(e);
- }
- }
-
- /**
- * Reads {@link LinkedList}.
- *
- * @return List.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- LinkedList<?> readLinkedList() throws ClassNotFoundException, IOException {
- int size = readInt();
-
- LinkedList<Object> list = new LinkedList<>();
-
- handles.assign(list);
-
- for (int i = 0; i < size; i++)
- list.add(readObject());
-
- return list;
- }
-
- /**
- * Reads {@link LinkedHashMap}.
- *
- * @param set Whether reading underlying map from {@link LinkedHashSet}.
- * @return Map.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- LinkedHashMap<?, ?> readLinkedHashMap(boolean set) throws ClassNotFoundException, IOException {
- int size = readInt();
- float loadFactor = readFloat();
- boolean accessOrder = readBoolean();
-
- LinkedHashMap<Object, Object> map = new LinkedHashMap<>(size, loadFactor, accessOrder);
-
- if (!set)
- handles.assign(map);
-
- for (int i = 0; i < size; i++) {
- Object key = readObject();
- Object val = !set ? readObject() : DUMMY;
-
- map.put(key, val);
- }
-
- return map;
- }
-
- /**
- * Reads {@link LinkedHashSet}.
- *
- * @param mapFieldOff Map field offset.
- * @return Set.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("unchecked")
- LinkedHashSet<?> readLinkedHashSet(long mapFieldOff) throws ClassNotFoundException, IOException {
- try {
- LinkedHashSet<Object> set = (LinkedHashSet<Object>)GridUnsafe.allocateInstance(LinkedHashSet.class);
-
- handles.assign(set);
-
- setObject(set, mapFieldOff, readLinkedHashMap(true));
-
- return set;
- }
- catch (InstantiationException e) {
- throw new IOException(e);
- }
- }
-
- /**
- * Reads {@link Date}.
- *
- * @return Date.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- Date readDate() throws ClassNotFoundException, IOException {
- Date date = new Date(readLong());
-
- handles.assign(date);
-
- return date;
- }
-
- /**
- * Reads array of {@code byte}s.
- *
- * @return Array.
- * @throws IOException In case of error.
- */
- byte[] readByteArray() throws IOException {
- byte[] arr = in.readByteArray();
-
- handles.assign(arr);
-
- return arr;
- }
-
- /**
- * Reads array of {@code short}s.
- *
- * @return Array.
- * @throws IOException In case of error.
- */
- short[] readShortArray() throws IOException {
- short[] arr = in.readShortArray();
-
- handles.assign(arr);
-
- return arr;
- }
-
- /**
- * Reads array of {@code int}s.
- *
- * @return Array.
- * @throws IOException In case of error.
- */
- int[] readIntArray() throws IOException {
- int[] arr = in.readIntArray();
-
- handles.assign(arr);
-
- return arr;
- }
-
- /**
- * Reads array of {@code long}s.
- *
- * @return Array.
- * @throws IOException In case of error.
- */
- long[] readLongArray() throws IOException {
- long[] arr = in.readLongArray();
-
- handles.assign(arr);
-
- return arr;
- }
-
- /**
- * Reads array of {@code float}s.
- *
- * @return Array.
- * @throws IOException In case of error.
- */
- float[] readFloatArray() throws IOException {
- float[] arr = in.readFloatArray();
-
- handles.assign(arr);
-
- return arr;
- }
-
- /**
- * Reads array of {@code double}s.
- *
- * @return Array.
- * @throws IOException In case of error.
- */
- double[] readDoubleArray() throws IOException {
- double[] arr = in.readDoubleArray();
-
- handles.assign(arr);
-
- return arr;
- }
-
- /**
- * Reads array of {@code char}s.
- *
- * @return Array.
- * @throws IOException In case of error.
- */
- char[] readCharArray() throws IOException {
- char[] arr = in.readCharArray();
-
- handles.assign(arr);
-
- return arr;
- }
-
- /**
- * Reads array of {@code boolean}s.
- *
- * @return Array.
- * @throws IOException In case of error.
- */
- boolean[] readBooleanArray() throws IOException {
- boolean[] arr = in.readBooleanArray();
-
- handles.assign(arr);
-
- return arr;
- }
-
- /**
- * Reads {@link String}.
- *
- * @return String.
- * @throws IOException In case of error.
- */
- public String readString() throws IOException {
- String str = in.readUTF();
-
- handles.assign(str);
-
- return str;
- }
-
- /** {@inheritDoc} */
- @Override public void readFully(byte[] b) throws IOException {
- in.readFully(b);
- }
-
- /** {@inheritDoc} */
- @Override public void readFully(byte[] b, int off, int len) throws IOException {
- in.readFully(b, off, len);
- }
-
- /** {@inheritDoc} */
- @Override public int skipBytes(int n) throws IOException {
- return in.skipBytes(n);
- }
-
- /** {@inheritDoc} */
- @Override public boolean readBoolean() throws IOException {
- return in.readBoolean();
- }
-
- /** {@inheritDoc} */
- @Override public byte readByte() throws IOException {
- return in.readByte();
- }
-
- /** {@inheritDoc} */
- @Override public int readUnsignedByte() throws IOException {
- return in.readUnsignedByte();
- }
-
- /** {@inheritDoc} */
- @Override public short readShort() throws IOException {
- return in.readShort();
- }
-
- /** {@inheritDoc} */
- @Override public int readUnsignedShort() throws IOException {
- return in.readUnsignedShort();
- }
-
- /** {@inheritDoc} */
- @Override public char readChar() throws IOException {
- return in.readChar();
- }
-
- /** {@inheritDoc} */
- @Override public int readInt() throws IOException {
- return in.readInt();
- }
-
- /** {@inheritDoc} */
- @Override public long readLong() throws IOException {
- return in.readLong();
- }
-
- /** {@inheritDoc} */
- @Override public float readFloat() throws IOException {
- return in.readFloat();
- }
-
- /** {@inheritDoc} */
- @Override public double readDouble() throws IOException {
- return in.readDouble();
- }
-
- /** {@inheritDoc} */
- @Override public int read() throws IOException {
- return in.read();
- }
-
- /** {@inheritDoc} */
- @Override public int read(byte[] b) throws IOException {
- return in.read(b);
- }
-
- /** {@inheritDoc} */
- @Override public int read(byte[] b, int off, int len) throws IOException {
- return in.read(b, off, len);
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("deprecation")
- @Override public String readLine() throws IOException {
- return in.readLine();
- }
-
- /** {@inheritDoc} */
- @Override public String readUTF() throws IOException {
- return in.readUTF();
- }
-
- /** {@inheritDoc} */
- @Override public Object readUnshared() throws IOException, ClassNotFoundException {
- return readObject();
- }
-
- /** {@inheritDoc} */
- @Override public void defaultReadObject() throws IOException, ClassNotFoundException {
- if (curObj == null)
- throw new NotActiveException("Not in readObject() call.");
-
- readFields(curObj, curFields);
- }
-
- /** {@inheritDoc} */
- @Override public ObjectInputStream.GetField readFields() throws IOException, ClassNotFoundException {
- if (curObj == null)
- throw new NotActiveException("Not in readObject() call.");
-
- return new GetFieldImpl(this);
- }
-
- /** {@inheritDoc} */
- @Override public void registerValidation(ObjectInputValidation obj, int pri) {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public int available() throws IOException {
- return -1;
- }
-
- /**
- * Returns objects that were added to handles table.
- * Used ONLY for test purposes.
- *
- * @return Handled objects.
- */
- Object[] handledObjects() {
- return handles.entries;
- }
-
- /**
- * Lightweight identity hash table which maps objects to integer handles,
- * assigned in ascending order.
- */
- private static class HandleTable {
- /** Array mapping handle -> object/exception (depending on status). */
- private Object[] entries;
-
- /** Number of handles in table. */
- private int size;
-
- /**
- * Creates handle table with the given initial capacity.
- *
- * @param initCap Initial capacity.
- */
- HandleTable(int initCap) {
- entries = new Object[initCap];
- }
-
- /**
- * Assigns next available handle to given object, and returns assigned
- * handle.
- *
- * @param obj Object.
- * @return Handle.
- */
- int assign(Object obj) {
- if (size >= entries.length)
- grow();
-
- entries[size] = obj;
-
- return size++;
- }
-
- /**
- * Assigns new object to existing handle. Old object is forgotten.
- *
- * @param handle Handle.
- * @param obj Object.
- */
- void set(int handle, Object obj) {
- entries[handle] = obj;
- }
-
- /**
- * Looks up and returns object associated with the given handle.
- *
- * @param handle Handle.
- * @return Object.
- */
- Object lookup(int handle) {
- return entries[handle];
- }
-
- /**
- * Resets table to its initial state.
- */
- void clear() {
- Arrays.fill(entries, 0, size, null);
-
- size = 0;
- }
-
- /**
- * Expands capacity of internal arrays.
- */
- private void grow() {
- int newCap = (entries.length << 1) + 1;
-
- Object[] newEntries = new Object[newCap];
-
- System.arraycopy(entries, 0, newEntries, 0, size);
-
- entries = newEntries;
- }
- }
-
- /**
- * {@link GetField} implementation.
- */
- private static class GetFieldImpl extends GetField {
- /** Field info. */
- private final OptimizedClassDescriptor.ClassFields fieldInfo;
-
- /** Values. */
- private final Object[] objs;
-
- /**
- * @param in Stream.
- * @throws IOException In case of error.
- * @throws ClassNotFoundException If class not found.
- */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- private GetFieldImpl(OptimizedObjectInputStream in) throws IOException, ClassNotFoundException {
- fieldInfo = in.curFields;
-
- objs = new Object[fieldInfo.size()];
-
- for (int i = 0; i < fieldInfo.size(); i++) {
- OptimizedClassDescriptor.FieldInfo t = fieldInfo.get(i);
-
- Object obj = null;
-
- switch (t.type()) {
- case BYTE:
- obj = in.readByte();
-
- break;
-
- case SHORT:
- obj = in.readShort();
-
- break;
-
- case INT:
- obj = in.readInt();
-
- break;
-
- case LONG:
- obj = in.readLong();
-
- break;
-
- case FLOAT:
- obj = in.readFloat();
-
- break;
-
- case DOUBLE:
- obj = in.readDouble();
-
- break;
-
- case CHAR:
- obj = in.readChar();
-
- break;
-
- case BOOLEAN:
- obj = in.readBoolean();
-
- break;
-
- case OTHER:
- obj = in.readObject();
- }
-
- objs[i] = obj;
- }
- }
-
- /** {@inheritDoc} */
- @Override public ObjectStreamClass getObjectStreamClass() {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @Override public boolean defaulted(String name) throws IOException {
- return objs[fieldInfo.getIndex(name)] == null;
- }
-
- /** {@inheritDoc} */
- @Override public boolean get(String name, boolean dflt) throws IOException {
- return value(name, dflt);
- }
-
- /** {@inheritDoc} */
- @Override public byte get(String name, byte dflt) throws IOException {
- return value(name, dflt);
- }
-
- /** {@inheritDoc} */
- @Override public char get(String name, char dflt) throws IOException {
- return value(name, dflt);
- }
-
- /** {@inheritDoc} */
- @Override public short get(String name, short dflt) throws IOException {
- return value(name, dflt);
- }
-
- /** {@inheritDoc} */
- @Override public int get(String name, int dflt) throws IOException {
- return value(name, dflt);
- }
-
- /** {@inheritDoc} */
- @Override public long get(String name, long dflt) throws IOException {
- return value(name, dflt);
- }
-
- /** {@inheritDoc} */
- @Override public float get(String name, float dflt) throws IOException {
- return value(name, dflt);
- }
-
- /** {@inheritDoc} */
- @Override public double get(String name, double dflt) throws IOException {
- return value(name, dflt);
- }
-
- /** {@inheritDoc} */
- @Override public Object get(String name, Object dflt) throws IOException {
- return value(name, dflt);
- }
-
- /**
- * @param name Field name.
- * @param dflt Default value.
- * @return Value.
- */
- @SuppressWarnings("unchecked")
- private <T> T value(String name, T dflt) {
- return objs[fieldInfo.getIndex(name)] != null ? (T)objs[fieldInfo.getIndex(name)] : dflt;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
deleted file mode 100644
index 98d85a0..0000000
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
+++ /dev/null
@@ -1,875 +0,0 @@
-/*
- * 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.optimized;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.NotActiveException;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentMap;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.util.GridHandleTable;
-import org.apache.ignite.internal.util.io.GridDataOutput;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.marshaller.MarshallerContext;
-
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.HANDLE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.JDK;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.JDK_MARSH;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.NULL;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.classDescriptor;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.getBoolean;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.getByte;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.getChar;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.getDouble;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.getFloat;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.getInt;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.getLong;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.getObject;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.getShort;
-
-/**
- * Optimized object output stream.
- */
-class OptimizedObjectOutputStream extends ObjectOutputStream {
- /** */
- private final GridHandleTable handles = new GridHandleTable(10, 3.00f);
-
- /** */
- private final GridDataOutput out;
-
- /** */
- private MarshallerContext ctx;
-
- /** */
- private OptimizedMarshallerIdMapper mapper;
-
- /** */
- private boolean requireSer;
-
- /** */
- private Object curObj;
-
- /** */
- private OptimizedClassDescriptor.ClassFields curFields;
-
- /** */
- private PutFieldImpl curPut;
-
- /** */
- private ConcurrentMap<Class, OptimizedClassDescriptor> clsMap;
-
- /**
- * @param out Output.
- * @throws IOException In case of error.
- */
- OptimizedObjectOutputStream(GridDataOutput out) throws IOException {
- this.out = out;
- }
-
- /**
- * @param clsMap Class descriptors by class map.
- * @param ctx Context.
- * @param mapper ID mapper.
- * @param requireSer Require {@link Serializable} flag.
- */
- void context(ConcurrentMap<Class, OptimizedClassDescriptor> clsMap,
- MarshallerContext ctx,
- OptimizedMarshallerIdMapper mapper,
- boolean requireSer) {
- this.clsMap = clsMap;
- this.ctx = ctx;
- this.mapper = mapper;
- this.requireSer = requireSer;
- }
-
- /**
- * @return Require {@link Serializable} flag.
- */
- boolean requireSerializable() {
- return requireSer;
- }
-
- /**
- * @return Output.
- */
- public GridDataOutput out() {
- return out;
- }
-
- /** {@inheritDoc} */
- @Override public void close() throws IOException {
- reset();
-
- ctx = null;
- clsMap = null;
- }
-
- /** {@inheritDoc} */
- @Override public void write(byte[] b) throws IOException {
- out.write(b);
- }
-
- /** {@inheritDoc} */
- @Override public void write(byte[] b, int off, int len) throws IOException {
- out.write(b, off, len);
- }
-
- /** {@inheritDoc} */
- @Override protected void writeObjectOverride(Object obj) throws IOException {
- writeObject0(obj);
- }
-
- /**
- * Writes object to stream.
- *
- * @param obj Object.
- * @throws IOException In case of error.
- */
- private void writeObject0(Object obj) throws IOException {
- curObj = null;
- curFields = null;
- curPut = null;
-
- if (obj == null)
- writeByte(NULL);
- else {
- if (obj instanceof Throwable && !(obj instanceof Externalizable)) {
- writeByte(JDK);
-
- try {
- JDK_MARSH.marshal(obj, this);
- }
- catch (IgniteCheckedException e) {
- IOException ioEx = e.getCause(IOException.class);
-
- if (ioEx != null)
- throw ioEx;
- else
- throw new IOException("Failed to serialize object with JDK marshaller: " + obj, e);
- }
- }
- else {
- OptimizedClassDescriptor desc = classDescriptor(
- clsMap,
- obj instanceof Object[] ? Object[].class : obj.getClass(),
- ctx,
- mapper);
-
- if (desc.excluded()) {
- writeByte(NULL);
-
- return;
- }
-
- Object obj0 = desc.replace(obj);
-
- if (obj0 == null) {
- writeByte(NULL);
-
- return;
- }
-
- int handle = -1;
-
- if (!desc.isPrimitive() && !desc.isEnum() && !desc.isClass() && !desc.isProxy())
- handle = handles.lookup(obj);
-
- if (obj0 != obj) {
- obj = obj0;
-
- desc = classDescriptor(clsMap,
- obj instanceof Object[] ? Object[].class : obj.getClass(),
- ctx,
- mapper);
- }
-
- if (handle >= 0) {
- writeByte(HANDLE);
- writeInt(handle);
- }
- else
- desc.write(this, obj);
- }
- }
- }
-
- /**
- * Writes array to this stream.
- *
- * @param arr Array.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- void writeArray(Object[] arr) throws IOException {
- int len = arr.length;
-
- writeInt(len);
-
- for (int i = 0; i < len; i++) {
- Object obj = arr[i];
-
- writeObject0(obj);
- }
- }
-
- /**
- * Writes {@link UUID} to this stream.
- *
- * @param uuid UUID.
- * @throws IOException In case of error.
- */
- void writeUuid(UUID uuid) throws IOException {
- writeLong(uuid.getMostSignificantBits());
- writeLong(uuid.getLeastSignificantBits());
- }
-
- /**
- * Writes {@link Properties} to this stream.
- *
- * @param props Properties.
- * @param dfltsFieldOff Defaults field offset.
- * @throws IOException In case of error.
- */
- void writeProperties(Properties props, long dfltsFieldOff) throws IOException {
- Properties dflts = (Properties)getObject(props, dfltsFieldOff);
-
- if (dflts == null)
- writeBoolean(true);
- else {
- writeBoolean(false);
-
- writeObject0(dflts);
- }
-
- Set<String> names = props.stringPropertyNames();
-
- writeInt(names.size());
-
- for (String name : names) {
- writeUTF(name);
- writeUTF(props.getProperty(name));
- }
- }
-
- /**
- * Writes externalizable object.
- *
- * @param obj Object.
- * @throws IOException In case of error.
- */
- void writeExternalizable(Object obj) throws IOException {
- Externalizable extObj = (Externalizable)obj;
-
- extObj.writeExternal(this);
- }
-
- /**
- * Writes serializable object.
- *
- * @param obj Object.
- * @param mtds {@code writeObject} methods.
- * @param fields class fields details.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- void writeSerializable(Object obj, List<Method> mtds, OptimizedClassDescriptor.Fields fields)
- throws IOException {
- for (int i = 0; i < mtds.size(); i++) {
- Method mtd = mtds.get(i);
-
- if (mtd != null) {
- curObj = obj;
- curFields = fields.fields(i);
-
- try {
- mtd.invoke(obj, this);
- }
- catch (IllegalAccessException e) {
- throw new IOException(e);
- }
- catch (InvocationTargetException e) {
- throw new IOException(e.getCause());
- }
- }
- else
- writeFields(obj, fields.fields(i));
- }
- }
-
- /**
- * Writes {@link ArrayList}.
- *
- * @param list List.
- * @throws IOException In case of error.
- */
- @SuppressWarnings({"ForLoopReplaceableByForEach", "TypeMayBeWeakened"})
- void writeArrayList(ArrayList<?> list) throws IOException {
- int size = list.size();
-
- writeInt(size);
-
- for (int i = 0; i < size; i++)
- writeObject0(list.get(i));
- }
-
- /**
- * Writes {@link HashMap}.
- *
- * @param map Map.
- * @param loadFactorFieldOff Load factor field offset.
- * @param set Whether writing underlying map from {@link HashSet}.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("TypeMayBeWeakened")
- void writeHashMap(HashMap<?, ?> map, long loadFactorFieldOff, boolean set) throws IOException {
- int size = map.size();
-
- writeInt(size);
- writeFloat(getFloat(map, loadFactorFieldOff));
-
- for (Map.Entry<?, ?> e : map.entrySet()) {
- writeObject0(e.getKey());
-
- if (!set)
- writeObject0(e.getValue());
- }
- }
-
- /**
- * Writes {@link HashSet}.
- *
- * @param set Set.
- * @param mapFieldOff Map field offset.
- * @param loadFactorFieldOff Load factor field offset.
- * @throws IOException In case of error.
- */
- void writeHashSet(HashSet<?> set, long mapFieldOff, long loadFactorFieldOff) throws IOException {
- writeHashMap((HashMap<?, ?>)getObject(set, mapFieldOff), loadFactorFieldOff, true);
- }
-
- /**
- * Writes {@link LinkedList}.
- *
- * @param list List.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("TypeMayBeWeakened")
- void writeLinkedList(LinkedList<?> list) throws IOException {
- int size = list.size();
-
- writeInt(size);
-
- for (Object obj : list)
- writeObject0(obj);
- }
-
- /**
- * Writes {@link LinkedHashMap}.
- *
- * @param map Map.
- * @param loadFactorFieldOff Load factor field offset.
- * @param accessOrderFieldOff access order field offset.
- * @param set Whether writing underlying map from {@link LinkedHashSet}.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("TypeMayBeWeakened")
- void writeLinkedHashMap(LinkedHashMap<?, ?> map, long loadFactorFieldOff, long accessOrderFieldOff, boolean set)
- throws IOException {
- int size = map.size();
-
- writeInt(size);
- writeFloat(getFloat(map, loadFactorFieldOff));
-
- if (accessOrderFieldOff >= 0)
- writeBoolean(getBoolean(map, accessOrderFieldOff));
- else
- writeBoolean(false);
-
- for (Map.Entry<?, ?> e : map.entrySet()) {
- writeObject0(e.getKey());
-
- if (!set)
- writeObject0(e.getValue());
- }
- }
-
- /**
- * Writes {@link LinkedHashSet}.
- *
- * @param set Set.
- * @param mapFieldOff Map field offset.
- * @param loadFactorFieldOff Load factor field offset.
- * @throws IOException In case of error.
- */
- void writeLinkedHashSet(LinkedHashSet<?> set, long mapFieldOff, long loadFactorFieldOff) throws IOException {
- LinkedHashMap<?, ?> map = (LinkedHashMap<?, ?>)getObject(set, mapFieldOff);
-
- writeLinkedHashMap(map, loadFactorFieldOff, -1, true);
- }
-
- /**
- * Writes {@link Date}.
- *
- * @param date Date.
- * @throws IOException In case of error.
- */
- void writeDate(Date date) throws IOException {
- writeLong(date.getTime());
- }
-
- /**
- * Writes all non-static and non-transient field values to this stream.
- *
- * @param obj Object.
- * @param fields Fields.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- private void writeFields(Object obj, OptimizedClassDescriptor.ClassFields fields) throws IOException {
- for (int i = 0; i < fields.size(); i++) {
- OptimizedClassDescriptor.FieldInfo t = fields.get(i);
-
- switch (t.type()) {
- case BYTE:
- if (t.field() != null)
- writeByte(getByte(obj, t.offset()));
-
- break;
-
- case SHORT:
- if (t.field() != null)
- writeShort(getShort(obj, t.offset()));
-
- break;
-
- case INT:
- if (t.field() != null)
- writeInt(getInt(obj, t.offset()));
-
- break;
-
- case LONG:
- if (t.field() != null)
- writeLong(getLong(obj, t.offset()));
-
- break;
-
- case FLOAT:
- if (t.field() != null)
- writeFloat(getFloat(obj, t.offset()));
-
- break;
-
- case DOUBLE:
- if (t.field() != null)
- writeDouble(getDouble(obj, t.offset()));
-
- break;
-
- case CHAR:
- if (t.field() != null)
- writeChar(getChar(obj, t.offset()));
-
- break;
-
- case BOOLEAN:
- if (t.field() != null)
- writeBoolean(getBoolean(obj, t.offset()));
-
- break;
-
- case OTHER:
- if (t.field() != null)
- writeObject0(getObject(obj, t.offset()));
- }
- }
- }
-
- /**
- * Writes array of {@code byte}s.
- *
- * @param arr Array.
- * @throws IOException In case of error.
- */
- void writeByteArray(byte[] arr) throws IOException {
- out.writeByteArray(arr);
- }
-
- /**
- * Writes array of {@code short}s.
- *
- * @param arr Array.
- * @throws IOException In case of error.
- */
- void writeShortArray(short[] arr) throws IOException {
- out.writeShortArray(arr);
- }
-
- /**
- * Writes array of {@code int}s.
- *
- * @param arr Array.
- * @throws IOException In case of error.
- */
- void writeIntArray(int[] arr) throws IOException {
- out.writeIntArray(arr);
- }
-
- /**
- * Writes array of {@code long}s.
- *
- * @param arr Array.
- * @throws IOException In case of error.
- */
- void writeLongArray(long[] arr) throws IOException {
- out.writeLongArray(arr);
- }
-
- /**
- * Writes array of {@code float}s.
- *
- * @param arr Array.
- * @throws IOException In case of error.
- */
- void writeFloatArray(float[] arr) throws IOException {
- out.writeFloatArray(arr);
- }
-
- /**
- * Writes array of {@code double}s.
- *
- * @param arr Array.
- * @throws IOException In case of error.
- */
- void writeDoubleArray(double[] arr) throws IOException {
- out.writeDoubleArray(arr);
- }
-
- /**
- * Writes array of {@code char}s.
- *
- * @param arr Array.
- * @throws IOException In case of error.
- */
- void writeCharArray(char[] arr) throws IOException {
- out.writeCharArray(arr);
- }
-
- /**
- * Writes array of {@code boolean}s.
- *
- * @param arr Array.
- * @throws IOException In case of error.
- */
- void writeBooleanArray(boolean[] arr) throws IOException {
- out.writeBooleanArray(arr);
- }
-
- /**
- * Writes {@link String}.
- *
- * @param str String.
- * @throws IOException In case of error.
- */
- void writeString(String str) throws IOException {
- out.writeUTF(str);
- }
-
- /** {@inheritDoc} */
- @Override public void writeBoolean(boolean v) throws IOException {
- out.writeBoolean(v);
- }
-
- /** {@inheritDoc} */
- @Override public void writeByte(int v) throws IOException {
- out.writeByte(v);
- }
-
- /** {@inheritDoc} */
- @Override public void writeShort(int v) throws IOException {
- out.writeShort(v);
- }
-
- /** {@inheritDoc} */
- @Override public void writeChar(int v) throws IOException {
- out.writeChar(v);
- }
-
- /** {@inheritDoc} */
- @Override public void writeInt(int v) throws IOException {
- out.writeInt(v);
- }
-
- /** {@inheritDoc} */
- @Override public void writeLong(long v) throws IOException {
- out.writeLong(v);
- }
-
- /** {@inheritDoc} */
- @Override public void writeFloat(float v) throws IOException {
- out.writeFloat(v);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDouble(double v) throws IOException {
- out.writeDouble(v);
- }
-
- /** {@inheritDoc} */
- @Override public void write(int b) throws IOException {
- writeByte(b);
- }
-
- /** {@inheritDoc} */
- @Override public void writeBytes(String s) throws IOException {
- out.writeBytes(s);
- }
-
- /** {@inheritDoc} */
- @Override public void writeChars(String s) throws IOException {
- out.writeChars(s);
- }
-
- /** {@inheritDoc} */
- @Override public void writeUTF(String s) throws IOException {
- out.writeUTF(s);
- }
-
- /** {@inheritDoc} */
- @Override public void useProtocolVersion(int ver) throws IOException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void writeUnshared(Object obj) throws IOException {
- writeObject0(obj);
- }
-
- /** {@inheritDoc} */
- @Override public void defaultWriteObject() throws IOException {
- if (curObj == null)
- throw new NotActiveException("Not in writeObject() call.");
-
- writeFields(curObj, curFields);
- }
-
- /** {@inheritDoc} */
- @Override public ObjectOutputStream.PutField putFields() throws IOException {
- if (curObj == null)
- throw new NotActiveException("Not in writeObject() call or fields already written.");
-
- if (curPut == null)
- curPut = new PutFieldImpl(this);
-
- return curPut;
- }
-
- /** {@inheritDoc} */
- @Override public void writeFields() throws IOException {
- if (curObj == null)
- throw new NotActiveException("Not in writeObject() call.");
-
- if (curPut == null)
- throw new NotActiveException("putFields() was not called.");
-
- for (IgniteBiTuple<OptimizedFieldType, Object> t : curPut.objs) {
- switch (t.get1()) {
- case BYTE:
- writeByte((Byte)t.get2());
-
- break;
-
- case SHORT:
- writeShort((Short)t.get2());
-
- break;
-
- case INT:
- writeInt((Integer)t.get2());
-
- break;
-
- case LONG:
- writeLong((Long)t.get2());
-
- break;
-
- case FLOAT:
- writeFloat((Float)t.get2());
-
- break;
-
- case DOUBLE:
- writeDouble((Double)t.get2());
-
- break;
-
- case CHAR:
- writeChar((Character)t.get2());
-
- break;
-
- case BOOLEAN:
- writeBoolean((Boolean)t.get2());
-
- break;
-
- case OTHER:
- writeObject0(t.get2());
- }
- }
- }
-
- /** {@inheritDoc} */
- @Override public void reset() throws IOException {
- out.reset();
- handles.clear();
-
- curObj = null;
- curFields = null;
- curPut = null;
- }
-
- /** {@inheritDoc} */
- @Override public void flush() throws IOException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void drain() throws IOException {
- // No-op.
- }
-
- /**
- * Returns objects that were added to handles table.
- * Used ONLY for test purposes.
- *
- * @return Handled objects.
- */
- Object[] handledObjects() {
- return handles.objects();
- }
-
- /**
- * {@link PutField} implementation.
- */
- private static class PutFieldImpl extends PutField {
- /** Stream. */
- private final OptimizedObjectOutputStream out;
-
- /** Fields info. */
- private final OptimizedClassDescriptor.ClassFields curFields;
- /** Values. */
- private final IgniteBiTuple<OptimizedFieldType, Object>[] objs;
-
- /**
- * @param out Output stream.
- */
- @SuppressWarnings("unchecked")
- private PutFieldImpl(OptimizedObjectOutputStream out) {
- this.out = out;
-
- curFields = out.curFields;
-
- objs = new IgniteBiTuple[curFields.size()];
- }
-
- /** {@inheritDoc} */
- @Override public void put(String name, boolean val) {
- value(name, val);
- }
-
- /** {@inheritDoc} */
- @Override public void put(String name, byte val) {
- value(name, val);
- }
-
- /** {@inheritDoc} */
- @Override public void put(String name, char val) {
- value(name, val);
- }
-
- /** {@inheritDoc} */
- @Override public void put(String name, short val) {
- value(name, val);
- }
-
- /** {@inheritDoc} */
- @Override public void put(String name, int val) {
- value(name, val);
- }
-
- /** {@inheritDoc} */
- @Override public void put(String name, long val) {
- value(name, val);
- }
-
- /** {@inheritDoc} */
- @Override public void put(String name, float val) {
- value(name, val);
- }
-
- /** {@inheritDoc} */
- @Override public void put(String name, double val) {
- value(name, val);
- }
-
- /** {@inheritDoc} */
- @Override public void put(String name, Object val) {
- value(name, val);
- }
-
- /** {@inheritDoc} */
- @Override public void write(ObjectOutput out) throws IOException {
- if (out != this.out)
- throw new IllegalArgumentException("Wrong stream.");
-
- this.out.writeFields();
- }
-
- /**
- * @param name Field name.
- * @param val Value.
- */
- private void value(String name, Object val) {
- int i = curFields.getIndex(name);
-
- OptimizedClassDescriptor.FieldInfo info = curFields.get(i);
-
- objs[i] = F.t(info.type(), val);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamRegistry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamRegistry.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamRegistry.java
deleted file mode 100644
index fd1b917..0000000
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamRegistry.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * 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.optimized;
-
-import java.io.IOException;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.IgniteInterruptedCheckedException;
-import org.apache.ignite.internal.util.io.GridUnsafeDataInput;
-import org.apache.ignite.internal.util.io.GridUnsafeDataOutput;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-/**
- * Storage for object streams.
- */
-class OptimizedObjectStreamRegistry {
- /** Holders. */
- private static final ThreadLocal<StreamHolder> holders = new ThreadLocal<>();
-
- /** Output streams pool. */
- private static BlockingQueue<OptimizedObjectOutputStream> outPool;
-
- /** Input streams pool. */
- private static BlockingQueue<OptimizedObjectInputStream> inPool;
-
- /**
- * Ensures singleton.
- */
- private OptimizedObjectStreamRegistry() {
- // No-op.
- }
-
- /**
- * Sets streams pool size.
- *
- * @param size Streams pool size.
- */
- static void poolSize(int size) {
- if (size > 0) {
- outPool = new LinkedBlockingQueue<>(size);
- inPool = new LinkedBlockingQueue<>(size);
-
- for (int i = 0; i < size; i++) {
- outPool.offer(createOut());
- inPool.offer(createIn());
- }
- }
- else {
- outPool = null;
- inPool = null;
- }
- }
-
- /**
- * Gets output stream.
- *
- * @return Object output stream.
- * @throws org.apache.ignite.internal.IgniteInterruptedCheckedException If thread is interrupted while trying to take holder from pool.
- */
- static OptimizedObjectOutputStream out() throws IgniteInterruptedCheckedException {
- if (outPool != null) {
- try {
- return outPool.take();
- }
- catch (InterruptedException e) {
- throw new IgniteInterruptedCheckedException(
- "Failed to take output object stream from pool (thread interrupted).", e);
- }
- }
- else
- return holder().acquireOut();
- }
-
- /**
- * Gets input stream.
- *
- * @return Object input stream.
- * @throws org.apache.ignite.internal.IgniteInterruptedCheckedException If thread is interrupted while trying to take holder from pool.
- */
- static OptimizedObjectInputStream in() throws IgniteInterruptedCheckedException {
- if (inPool != null) {
- try {
- return inPool.take();
- }
- catch (InterruptedException e) {
- throw new IgniteInterruptedCheckedException(
- "Failed to take input object stream from pool (thread interrupted).", e);
- }
- }
- else
- return holder().acquireIn();
- }
-
- /**
- * Closes and releases output stream.
- *
- * @param out Object output stream.
- */
- static void closeOut(OptimizedObjectOutputStream out) {
- U.close(out, null);
-
- if (outPool != null) {
- boolean b = outPool.offer(out);
-
- assert b;
- }
- else {
- StreamHolder holder = holders.get();
-
- if (holder != null)
- holder.releaseOut();
- }
- }
-
- /**
- * Closes and releases input stream.
- *
- * @param in Object input stream.
- */
- @SuppressWarnings("TypeMayBeWeakened")
- static void closeIn(OptimizedObjectInputStream in) {
- U.close(in, null);
-
- if (inPool != null) {
- boolean b = inPool.offer(in);
-
- assert b;
- }
- else {
- StreamHolder holder = holders.get();
-
- if (holder != null)
- holder.releaseIn();
- }
- }
-
- /**
- * Gets holder from pool or thread local.
- *
- * @return Stream holder.
- * @throws org.apache.ignite.internal.IgniteInterruptedCheckedException If thread is interrupted while trying to take holder from pool.
- */
- private static StreamHolder holder() throws IgniteInterruptedCheckedException {
- StreamHolder holder = holders.get();
-
- if (holder == null)
- holders.set(holder = new StreamHolder());
-
- return holder;
- }
-
- /**
- * Creates output stream.
- *
- * @return Object output stream.
- */
- private static OptimizedObjectOutputStream createOut() {
- try {
- return new OptimizedObjectOutputStream(new GridUnsafeDataOutput(4 * 1024));
- }
- catch (IOException e) {
- throw new IgniteException("Failed to create object output stream.", e);
- }
- }
-
- /**
- * Creates input stream.
- *
- * @return Object input stream.
- */
- private static OptimizedObjectInputStream createIn() {
- try {
- return new OptimizedObjectInputStream(new GridUnsafeDataInput());
- }
- catch (IOException e) {
- throw new IgniteException("Failed to create object input stream.", e);
- }
- }
-
- /**
- * Streams holder.
- */
- private static class StreamHolder {
- /** Output stream. */
- private final OptimizedObjectOutputStream out = createOut();
-
- /** Input stream. */
- private final OptimizedObjectInputStream in = createIn();
-
- /** Output streams counter. */
- private int outAcquireCnt;
-
- /** Input streams counter. */
- private int inAcquireCnt;
-
- /**
- * Gets output stream.
- *
- * @return Object output stream.
- */
- OptimizedObjectOutputStream acquireOut() {
- return outAcquireCnt++ > 0 ? createOut() : out;
- }
-
- /**
- * Gets input stream.
- *
- * @return Object input stream.
- */
- OptimizedObjectInputStream acquireIn() {
- return inAcquireCnt++ > 0 ? createIn() : in;
- }
-
- /**
- * Releases output stream.
- */
- void releaseOut() {
- outAcquireCnt--;
- }
-
- /**
- * Releases input stream.
- */
- void releaseIn() {
- inAcquireCnt--;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/package-info.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/package-info.java
deleted file mode 100644
index bb61add..0000000
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Contains Optimized marshaller.
- */
-package org.apache.ignite.marshaller.optimized;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/resources/META-INF/classnames.properties
----------------------------------------------------------------------
diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties
index 335a33f..7d00841 100644
--- a/modules/core/src/main/resources/META-INF/classnames.properties
+++ b/modules/core/src/main/resources/META-INF/classnames.properties
@@ -1895,7 +1895,7 @@ org.apache.ignite.lang.IgniteRunnable
org.apache.ignite.lang.IgniteUuid
org.apache.ignite.lifecycle.LifecycleEventType
org.apache.ignite.marshaller.jdk.JdkMarshallerDummySerializable
-org.apache.ignite.marshaller.optimized.OptimizedFieldType
+org.apache.ignite.internal.marshaller.optimized.OptimizedFieldType
org.apache.ignite.messaging.MessagingListenActor
org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction
org.apache.ignite.platform.dotnet.PlatformDotNetCacheStoreFactory
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/config/example-cache.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/example-cache.xml b/modules/core/src/test/config/example-cache.xml
index d9556af..95be5b3 100644
--- a/modules/core/src/test/config/example-cache.xml
+++ b/modules/core/src/test/config/example-cache.xml
@@ -44,7 +44,7 @@
<property name="peerClassLoadingEnabled" value="true"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
<!-- Set to false to allow non-serializable objects in examples, default is true. -->
<property name="requireSerializable" value="false"/>
</bean>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/config/igfs-loopback.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/igfs-loopback.xml b/modules/core/src/test/config/igfs-loopback.xml
index 5bfbdae..7ec5f10 100644
--- a/modules/core/src/test/config/igfs-loopback.xml
+++ b/modules/core/src/test/config/igfs-loopback.xml
@@ -57,7 +57,7 @@
Configure optimized marshaller.
-->
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
<!--
For better performance set this property to true in case
all marshalled classes implement java.io.Serializable.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/config/igfs-shmem.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/igfs-shmem.xml b/modules/core/src/test/config/igfs-shmem.xml
index 5876b41..f6b1790 100644
--- a/modules/core/src/test/config/igfs-shmem.xml
+++ b/modules/core/src/test/config/igfs-shmem.xml
@@ -57,7 +57,7 @@
Configure optimized marshaller.
-->
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
<!--
For better performance set this property to true in case
all marshalled classes implement java.io.Serializable.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/config/spring-start-nodes-attr.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/spring-start-nodes-attr.xml b/modules/core/src/test/config/spring-start-nodes-attr.xml
index 8db8598..b329973 100644
--- a/modules/core/src/test/config/spring-start-nodes-attr.xml
+++ b/modules/core/src/test/config/spring-start-nodes-attr.xml
@@ -37,7 +37,7 @@
<property name="connectorConfiguration"><null/></property>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
<property name="requireSerializable" value="false"/>
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/config/spring-start-nodes.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/spring-start-nodes.xml b/modules/core/src/test/config/spring-start-nodes.xml
index 8ab68fb..9b2ee94 100644
--- a/modules/core/src/test/config/spring-start-nodes.xml
+++ b/modules/core/src/test/config/spring-start-nodes.xml
@@ -31,7 +31,7 @@
<property name="connectorConfiguration"><null/></property>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
<property name="requireSerializable" value="false"/>
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/config/websession/example-cache-base.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/websession/example-cache-base.xml b/modules/core/src/test/config/websession/example-cache-base.xml
index d3d5b46..20f103e 100644
--- a/modules/core/src/test/config/websession/example-cache-base.xml
+++ b/modules/core/src/test/config/websession/example-cache-base.xml
@@ -30,7 +30,7 @@
<property name="peerClassLoadingEnabled" value="true"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
<!-- Set to false to allow non-serializable objects in examples, default is true. -->
<property name="requireSerializable" value="false"/>
</bean>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/IgniteExternalizableAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/IgniteExternalizableAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/IgniteExternalizableAbstractTest.java
index 63436ab..de8dfbe 100644
--- a/modules/core/src/test/java/org/apache/ignite/IgniteExternalizableAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/IgniteExternalizableAbstractTest.java
@@ -23,7 +23,7 @@ import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.marshaller.MarshallerContext;
import org.apache.ignite.marshaller.MarshallerContextTestImpl;
import org.apache.ignite.marshaller.jdk.JdkMarshaller;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreOptimizedMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreOptimizedMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreOptimizedMarshallerSelfTest.java
index 3f6c9b4..f69a593 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreOptimizedMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreOptimizedMarshallerSelfTest.java
@@ -18,7 +18,7 @@
package org.apache.ignite.cache.store.jdbc;
import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
/**
* Test for {@link CacheJdbcPojoStore} with optimized marshaller.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/igfs/IgfsPathSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/igfs/IgfsPathSelfTest.java b/modules/core/src/test/java/org/apache/ignite/igfs/IgfsPathSelfTest.java
index 3092374..e16385e 100644
--- a/modules/core/src/test/java/org/apache/ignite/igfs/IgfsPathSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/igfs/IgfsPathSelfTest.java
@@ -25,7 +25,7 @@ import java.util.Arrays;
import java.util.concurrent.Callable;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.jetbrains.annotations.Nullable;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/GridLifecycleAwareSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridLifecycleAwareSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridLifecycleAwareSelfTest.java
index 17ef65a..61d6069 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridLifecycleAwareSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridLifecycleAwareSelfTest.java
@@ -28,7 +28,7 @@ import org.apache.ignite.lifecycle.LifecycleAware;
import org.apache.ignite.lifecycle.LifecycleBean;
import org.apache.ignite.lifecycle.LifecycleEventType;
import org.apache.ignite.logger.java.JavaLogger;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.plugin.segmentation.SegmentationResolver;
import org.apache.ignite.testframework.junits.common.GridAbstractLifecycleAwareSelfTest;
import org.jetbrains.annotations.Nullable;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/managers/GridManagerStopSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/GridManagerStopSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/GridManagerStopSelfTest.java
index 50691b6..f9845c8 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/managers/GridManagerStopSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/GridManagerStopSelfTest.java
@@ -28,7 +28,7 @@ import org.apache.ignite.internal.managers.failover.GridFailoverManager;
import org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerManager;
import org.apache.ignite.internal.processors.pool.PoolProcessor;
import org.apache.ignite.internal.processors.resource.GridResourceProcessor;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.resources.LoggerResource;
import org.apache.ignite.spi.IgniteSpi;
import org.apache.ignite.spi.checkpoint.sharedfs.SharedFsCheckpointSpi;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAttributesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAttributesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAttributesSelfTest.java
index 6591776..10a7a30 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAttributesSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAttributesSelfTest.java
@@ -22,7 +22,7 @@ import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.configuration.DeploymentMode;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
[02/10] ignite git commit: IGNITE-4938: Moved OptimizedMarshaller to
private package. This closes #1793.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamSelfTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamSelfTest.java
deleted file mode 100644
index 655a19a..0000000
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedObjectStreamSelfTest.java
+++ /dev/null
@@ -1,2157 +0,0 @@
-/*
- * 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.optimized;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.NotActiveException;
-import java.io.NotSerializableException;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamException;
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.net.Inet4Address;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.text.SimpleDateFormat;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.IdentityHashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.PriorityQueue;
-import java.util.Properties;
-import java.util.Queue;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.UUID;
-import java.util.Vector;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentMap;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.util.io.GridUnsafeDataInput;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.MarshallerContext;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.marshaller.MarshallerExclusions;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-
-import static org.junit.Assert.assertArrayEquals;
-
-/**
- * Test for optimized object streams.
- */
-public class OptimizedObjectStreamSelfTest extends GridCommonAbstractTest {
- /** */
- private static final MarshallerContext CTX = new MarshallerContextTestImpl();
-
- /** */
- private ConcurrentMap<Class, OptimizedClassDescriptor> clsMap = new ConcurrentHashMap8<>();
-
- /**
- * @throws Exception If failed.
- */
- public void testNull() throws Exception {
- assertNull(marshalUnmarshal(null));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testByte() throws Exception {
- byte val = 10;
-
- assertEquals(new Byte(val), marshalUnmarshal(val));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testShort() throws Exception {
- short val = 100;
-
- assertEquals(new Short(val), marshalUnmarshal(val));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testInteger() throws Exception {
- int val = 100;
-
- assertEquals(new Integer(val), marshalUnmarshal(val));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testLong() throws Exception {
- long val = 1000L;
-
- assertEquals(new Long(val), marshalUnmarshal(val));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testFloat() throws Exception {
- float val = 10.0f;
-
- assertEquals(val, marshalUnmarshal(val));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testDouble() throws Exception {
- double val = 100.0d;
-
- assertEquals(val, marshalUnmarshal(val));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testBoolean() throws Exception {
- boolean val = true;
-
- assertEquals(new Boolean(val), marshalUnmarshal(val));
-
- val = false;
-
- assertEquals(new Boolean(val), marshalUnmarshal(val));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testChar() throws Exception {
- char val = 10;
-
- assertEquals(new Character(val), marshalUnmarshal(val));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testByteArray() throws Exception {
- byte[] arr = marshalUnmarshal(new byte[] {1, 2});
-
- assertArrayEquals(new byte[] {1, 2}, arr);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testShortArray() throws Exception {
- short[] arr = marshalUnmarshal(new short[] {1, 2});
-
- assertArrayEquals(new short[] {1, 2}, arr);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testIntArray() throws Exception {
- int[] arr = marshalUnmarshal(new int[] {1, 2});
-
- assertArrayEquals(new int[] {1, 2}, arr);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testLongArray() throws Exception {
- long[] arr = marshalUnmarshal(new long[] {1L, 2L});
-
- assertArrayEquals(new long[] {1, 2}, arr);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testFloatArray() throws Exception {
- float[] arr = marshalUnmarshal(new float[] {1.0f, 2.0f});
-
- assertArrayEquals(new float[] {1.0f, 2.0f}, arr, 0.1f);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testDoubleArray() throws Exception {
- double[] arr = marshalUnmarshal(new double[] {1.0d, 2.0d});
-
- assertArrayEquals(new double[] {1.0d, 2.0d}, arr, 0.1d);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testBooleanArray() throws Exception {
- boolean[] arr = marshalUnmarshal(new boolean[] {true, false, false});
-
- assertEquals(3, arr.length);
- assertEquals(true, arr[0]);
- assertEquals(false, arr[1]);
- assertEquals(false, arr[2]);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testCharArray() throws Exception {
- char[] arr = marshalUnmarshal(new char[] {1, 2});
-
- assertArrayEquals(new char[] {1, 2}, arr);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testObject() throws Exception {
- TestObject obj = new TestObject();
-
- obj.longVal = 100L;
- obj.doubleVal = 100.0d;
- obj.longArr = new Long[] {200L, 300L};
- obj.doubleArr = new Double[] {200.0d, 300.0d};
-
- assertEquals(obj, marshalUnmarshal(obj));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testRequireSerializable() throws Exception {
- try {
- OptimizedMarshaller marsh = new OptimizedMarshaller(true);
-
- marsh.setContext(CTX);
-
- marsh.marshal(new Object());
-
- assert false : "Exception not thrown.";
- }
- catch (IgniteCheckedException e) {
- NotSerializableException serEx = e.getCause(NotSerializableException.class);
-
- if (serEx == null)
- throw e;
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testPool() throws Exception {
- final TestObject obj = new TestObject();
-
- obj.longVal = 100L;
- obj.doubleVal = 100.0d;
- obj.longArr = new Long[100 * 1024];
- obj.doubleArr = new Double[100 * 1024];
-
- Arrays.fill(obj.longArr, 100L);
- Arrays.fill(obj.doubleArr, 100.0d);
-
- final OptimizedMarshaller marsh = new OptimizedMarshaller();
-
- marsh.setContext(CTX);
-
- marsh.setPoolSize(5);
-
- try {
- multithreaded(new Callable<Object>() {
- @Override public Object call() throws Exception {
- for (int i = 0; i < 50; i++)
- assertEquals(obj, marsh.unmarshal(marsh.marshal(obj), null));
-
- return null;
- }
- }, 20);
- }
- finally {
- marsh.setPoolSize(0);
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testObjectWithNulls() throws Exception {
- TestObject obj = new TestObject();
-
- obj.longVal = 100L;
- obj.longArr = new Long[] {200L, 300L};
-
- assertEquals(obj, marshalUnmarshal(obj));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testObjectArray() throws Exception {
- TestObject obj1 = new TestObject();
-
- obj1.longVal = 100L;
- obj1.doubleVal = 100.0d;
- obj1.longArr = new Long[] {200L, 300L};
- obj1.doubleArr = new Double[] {200.0d, 300.0d};
-
- TestObject obj2 = new TestObject();
-
- obj2.longVal = 400L;
- obj2.doubleVal = 400.0d;
- obj2.longArr = new Long[] {500L, 600L};
- obj2.doubleArr = new Double[] {500.0d, 600.0d};
-
- TestObject[] arr = {obj1, obj2};
-
- assertArrayEquals(arr, (Object[])marshalUnmarshal(arr));
-
- String[] strArr = {"str1", "str2"};
-
- assertArrayEquals(strArr, (String[])marshalUnmarshal(strArr));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testExternalizable() throws Exception {
- ExternalizableTestObject1 obj = new ExternalizableTestObject1();
-
- obj.longVal = 100L;
- obj.doubleVal = 100.0d;
- obj.longArr = new Long[] {200L, 300L};
- obj.doubleArr = new Double[] {200.0d, 300.0d};
-
- assertEquals(obj, marshalUnmarshal(obj));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testExternalizableWithNulls() throws Exception {
- ExternalizableTestObject2 obj = new ExternalizableTestObject2();
-
- obj.longVal = 100L;
- obj.doubleVal = 100.0d;
- obj.longArr = new Long[] {200L, 300L};
- obj.doubleArr = new Double[] {200.0d, 300.0d};
-
- obj = marshalUnmarshal(obj);
-
- assertEquals(100L, obj.longVal.longValue());
- assertNull(obj.doubleVal);
- assertArrayEquals(new Long[] {200L, 300L}, obj.longArr);
- assertNull(obj.doubleArr);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testLink() throws Exception {
- for (int i = 0; i < 20; i++) {
- LinkTestObject1 obj1 = new LinkTestObject1();
- LinkTestObject2 obj2 = new LinkTestObject2();
- LinkTestObject2 obj3 = new LinkTestObject2();
-
- obj1.val = 100;
- obj2.ref = obj1;
- obj3.ref = obj1;
-
- LinkTestObject2[] arr = new LinkTestObject2[] {obj2, obj3};
-
- assertArrayEquals(arr, (Object[])marshalUnmarshal(arr));
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testCycleLink() throws Exception {
- for (int i = 0; i < 20; i++) {
- CycleLinkTestObject obj = new CycleLinkTestObject();
-
- obj.val = 100;
- obj.ref = obj;
-
- assertEquals(obj, marshalUnmarshal(obj));
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testNoDefaultConstructor() throws Exception {
- NoDefaultConstructorTestObject obj = new NoDefaultConstructorTestObject(100);
-
- assertEquals(obj, marshalUnmarshal(obj));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testEnum() throws Exception {
- assertEquals(TestEnum.B, marshalUnmarshal(TestEnum.B));
-
- TestEnum[] arr = new TestEnum[] {TestEnum.C, TestEnum.A, TestEnum.B, TestEnum.A};
-
- assertArrayEquals(arr, (Object[])marshalUnmarshal(arr));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testCollection() throws Exception {
- TestObject obj1 = new TestObject();
-
- obj1.longVal = 100L;
- obj1.doubleVal = 100.0d;
- obj1.longArr = new Long[] {200L, 300L};
- obj1.doubleArr = new Double[] {200.0d, 300.0d};
-
- TestObject obj2 = new TestObject();
-
- obj2.longVal = 400L;
- obj2.doubleVal = 400.0d;
- obj2.longArr = new Long[] {500L, 600L};
- obj2.doubleArr = new Double[] {500.0d, 600.0d};
-
- Collection<TestObject> col = F.asList(obj1, obj2);
-
- assertEquals(col, marshalUnmarshal(col));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testMap() throws Exception {
- TestObject obj1 = new TestObject();
-
- obj1.longVal = 100L;
- obj1.doubleVal = 100.0d;
- obj1.longArr = new Long[] {200L, 300L};
- obj1.doubleArr = new Double[] {200.0d, 300.0d};
-
- TestObject obj2 = new TestObject();
-
- obj2.longVal = 400L;
- obj2.doubleVal = 400.0d;
- obj2.longArr = new Long[] {500L, 600L};
- obj2.doubleArr = new Double[] {500.0d, 600.0d};
-
- Map<Integer, TestObject> map = F.asMap(1, obj1, 2, obj2);
-
- assertEquals(map, marshalUnmarshal(map));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testUuid() throws Exception {
- UUID uuid = UUID.randomUUID();
-
- assertEquals(uuid, marshalUnmarshal(uuid));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testDate() throws Exception {
- Date date = new Date();
-
- assertEquals(date, marshalUnmarshal(date));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testTransient() throws Exception {
- TransientTestObject obj = marshalUnmarshal(new TransientTestObject(100, 200, "str1", "str2"));
-
- assertEquals(100, obj.val1);
- assertEquals(0, obj.val2);
- assertEquals("str1", obj.str1);
- assertNull(obj.str2);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testWriteReadObject() throws Exception {
- WriteReadTestObject obj = marshalUnmarshal(new WriteReadTestObject(100, "str"));
-
- assertEquals(100, obj.val);
- assertEquals("Optional data", obj.str);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testWriteReplace() throws Exception {
- ReplaceTestObject obj = marshalUnmarshal(new ReplaceTestObject(100));
-
- assertEquals(200, obj.value());
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testWriteReplaceNull() throws Exception {
- ReplaceNullTestObject obj = marshalUnmarshal(new ReplaceNullTestObject());
-
- assertNull(obj);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testReadResolve() throws Exception {
- ResolveTestObject obj = marshalUnmarshal(new ResolveTestObject(100));
-
- assertEquals(200, obj.value());
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testArrayDeque() throws Exception {
- Queue<Integer> queue = new ArrayDeque<>();
-
- for (int i = 0; i < 100; i++)
- queue.add(i);
-
- Queue<Integer> newQueue = marshalUnmarshal(queue);
-
- assertEquals(queue.size(), newQueue.size());
-
- Integer i;
-
- while ((i = newQueue.poll()) != null)
- assertEquals(queue.poll(), i);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testArrayList() throws Exception {
- Collection<Integer> list = new ArrayList<>();
-
- for (int i = 0; i < 100; i++)
- list.add(i);
-
- assertEquals(list, marshalUnmarshal(list));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testHashMap() throws Exception {
- Map<Integer, Integer> map = new HashMap<>();
-
- for (int i = 0; i < 100; i++)
- map.put(i, i);
-
- assertEquals(map, marshalUnmarshal(map));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testHashSet() throws Exception {
- Collection<Integer> set = new HashSet<>();
-
- for (int i = 0; i < 100; i++)
- set.add(i);
-
- assertEquals(set, marshalUnmarshal(set));
- }
-
- /**
- * @throws Exception If failed.
- */
- @SuppressWarnings("UseOfObsoleteCollectionType")
- public void testHashtable() throws Exception {
- Map<Integer, Integer> map = new Hashtable<>();
-
- for (int i = 0; i < 100; i++)
- map.put(i, i);
-
- assertEquals(map, marshalUnmarshal(map));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testIdentityHashMap() throws Exception {
- Map<Integer, Integer> map = new IdentityHashMap<>();
-
- for (int i = 0; i < 100; i++)
- map.put(i, i);
-
- assertEquals(map, marshalUnmarshal(map));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testLinkedHashMap() throws Exception {
- Map<Integer, Integer> map = new LinkedHashMap<>();
-
- for (int i = 0; i < 100; i++)
- map.put(i, i);
-
- assertEquals(map, marshalUnmarshal(map));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testLinkedHashSet() throws Exception {
- Collection<Integer> set = new LinkedHashSet<>();
-
- for (int i = 0; i < 100; i++)
- set.add(i);
-
- assertEquals(set, marshalUnmarshal(set));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testLinkedList() throws Exception {
- Collection<Integer> list = new LinkedList<>();
-
- for (int i = 0; i < 100; i++)
- list.add(i);
-
- assertEquals(list, marshalUnmarshal(list));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testPriorityQueue() throws Exception {
- Queue<Integer> queue = new PriorityQueue<>();
-
- for (int i = 0; i < 100; i++)
- queue.add(i);
-
- Queue<Integer> newQueue = marshalUnmarshal(queue);
-
- assertEquals(queue.size(), newQueue.size());
-
- Integer i;
-
- while ((i = newQueue.poll()) != null)
- assertEquals(queue.poll(), i);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testProperties() throws Exception {
- Properties dflts = new Properties();
-
- dflts.setProperty("key1", "val1");
- dflts.setProperty("key2", "wrong");
-
- Properties props = new Properties(dflts);
-
- props.setProperty("key2", "val2");
-
- Properties newProps = marshalUnmarshal(props);
-
- assertEquals("val1", newProps.getProperty("key1"));
- assertEquals("val2", newProps.getProperty("key2"));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testTreeMap() throws Exception {
- Map<Integer, Integer> map = new TreeMap<>();
-
- for (int i = 0; i < 100; i++)
- map.put(i, i);
-
- assertEquals(map, marshalUnmarshal(map));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testTreeSet() throws Exception {
- Collection<Integer> set = new TreeSet<>();
-
- for (int i = 0; i < 100; i++)
- set.add(i);
-
- assertEquals(set, marshalUnmarshal(set));
- }
-
- /**
- * @throws Exception If failed.
- */
- @SuppressWarnings("UseOfObsoleteCollectionType")
- public void testVector() throws Exception {
- Collection<Integer> vector = new Vector<>();
-
- for (int i = 0; i < 100; i++)
- vector.add(i);
-
- assertEquals(vector, marshalUnmarshal(vector));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testString() throws Exception {
- assertEquals("Latin", marshalUnmarshal("Latin"));
- assertEquals("\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430", marshalUnmarshal("\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430"));
- assertEquals("\u4e2d\u56fd\u7684", marshalUnmarshal("\u4e2d\u56fd\u7684"));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testReadLine() throws Exception {
- OptimizedObjectInputStream in = new OptimizedObjectInputStream(new GridUnsafeDataInput());
-
- byte[] bytes = "line1\nline2\r\nli\rne3\nline4".getBytes();
-
- in.in().bytes(bytes, bytes.length);
-
- assertEquals("line1", in.readLine());
- assertEquals("line2", in.readLine());
- assertEquals("line3", in.readLine());
- assertEquals("line4", in.readLine());
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testHierarchy() throws Exception {
- C c = new C(100, "str", 200, "str", 300, "str");
-
- C newC = marshalUnmarshal(c);
-
- assertEquals(100, newC.valueA());
- assertEquals("Optional data", newC.stringA());
- assertEquals(200, newC.valueB());
- assertNull(newC.stringB());
- assertEquals(0, newC.valueC());
- assertEquals("Optional data", newC.stringC());
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testInet4Address() throws Exception {
- Inet4Address addr = (Inet4Address)InetAddress.getByName("localhost");
-
- assertEquals(addr, marshalUnmarshal(addr));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testClass() throws Exception {
- assertEquals(int.class, marshalUnmarshal(int.class));
- assertEquals(Long.class, marshalUnmarshal(Long.class));
- assertEquals(TestObject.class, marshalUnmarshal(TestObject.class));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testWriteReadFields() throws Exception {
- WriteReadFieldsTestObject obj = marshalUnmarshal(new WriteReadFieldsTestObject(100, "str"));
-
- assertEquals(100, obj.val);
- assertEquals("Optional data", obj.str);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testWriteFields() throws Exception {
- WriteFieldsTestObject obj = marshalUnmarshal(new WriteFieldsTestObject(100, "str"));
-
- assertEquals(100, obj.val);
- assertEquals("Optional data", obj.str);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testBigInteger() throws Exception {
- BigInteger b = new BigInteger("54654865468745468465321414646834562346475457488");
-
- assertEquals(b, marshalUnmarshal(b));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testBigDecimal() throws Exception {
- BigDecimal b = new BigDecimal("849572389457208934572093574.123512938654126458542145");
-
- assertEquals(b, marshalUnmarshal(b));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testSimpleDateFormat() throws Exception {
- SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyyy");
-
- assertEquals(f, marshalUnmarshal(f));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testComplexObject() throws Exception {
- ComplexTestObject obj = new ComplexTestObject();
-
- assertEquals(obj, marshalUnmarshal(obj));
-
- ExternalizableTestObject1 extObj1 = new ExternalizableTestObject1();
-
- extObj1.longVal = 1000L;
- extObj1.doubleVal = 1000.0d;
- extObj1.longArr = new Long[] {1000L, 2000L, 3000L};
- extObj1.doubleArr = new Double[] {1000.0d, 2000.0d, 3000.0d};
-
- ExternalizableTestObject1 extObj2 = new ExternalizableTestObject1();
-
- extObj2.longVal = 2000L;
- extObj2.doubleVal = 2000.0d;
- extObj2.longArr = new Long[] {4000L, 5000L, 6000L};
- extObj2.doubleArr = new Double[] {4000.0d, 5000.0d, 6000.0d};
-
- Properties props = new Properties();
-
- props.setProperty("name", "value");
-
- Collection<Integer> col = F.asList(10, 20, 30);
-
- Map<Integer, String> map = F.asMap(10, "str1", 20, "str2", 30, "str3");
-
- obj = new ComplexTestObject(
- (byte)1,
- (short)10,
- 100,
- 1000L,
- 100.0f,
- 1000.0d,
- 'a',
- false,
- (byte)2,
- (short)20,
- 200,
- 2000L,
- 200.0f,
- 2000.0d,
- 'b',
- true,
- new byte[] {1, 2, 3},
- new short[] {10, 20, 30},
- new int[] {100, 200, 300},
- new long[] {1000, 2000, 3000},
- new float[] {100.0f, 200.0f, 300.0f},
- new double[] {1000.0d, 2000.0d, 3000.0d},
- new char[] {'a', 'b', 'c'},
- new boolean[] {false, true},
- new ExternalizableTestObject1[] {extObj1, extObj2},
- "String",
- TestEnum.A,
- UUID.randomUUID(),
- props,
- new ArrayList<>(col),
- new HashMap<>(map),
- new HashSet<>(col),
- new LinkedList<>(col),
- new LinkedHashMap<>(map),
- new LinkedHashSet<>(col),
- new Date(),
- ExternalizableTestObject2.class
- );
-
- assertEquals(obj, marshalUnmarshal(obj));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testReadToArray() throws Exception {
- OptimizedObjectInputStream in = OptimizedObjectStreamRegistry.in();
-
- try {
- byte[] arr = new byte[50];
-
- for (int i = 0; i < arr.length; i++)
- arr[i] = (byte)i;
-
- in.in().bytes(arr, arr.length);
-
- byte[] buf = new byte[10];
-
- assertEquals(10, in.read(buf));
-
- for (int i = 0; i < buf.length; i++)
- assertEquals(i, buf[i]);
-
- buf = new byte[30];
-
- assertEquals(20, in.read(buf, 0, 20));
-
- for (int i = 0; i < buf.length; i++)
- assertEquals(i < 20 ? 10 + i : 0, buf[i]);
-
- buf = new byte[30];
-
- assertEquals(10, in.read(buf, 10, 10));
-
- for (int i = 0; i < buf.length; i++)
- assertEquals(i >= 10 && i < 20 ? 30 + (i - 10) : 0, buf[i]);
-
- buf = new byte[20];
-
- assertEquals(10, in.read(buf));
-
- for (int i = 0; i < buf.length; i++)
- assertEquals(i < 10 ? 40 + i : 0, buf[i]);
- }
- finally {
- OptimizedObjectStreamRegistry.closeIn(in);
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testHandleTableGrow() throws Exception {
- List<String> c = new ArrayList<>();
-
- for (int i = 0; i < 29; i++)
- c.add("str");
-
- String str = c.get(28);
-
- c.add("str");
- c.add(str);
-
- List<Object> c0 = marshalUnmarshal(c);
-
- assertTrue(c0.get(28) == c0.get(30));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testIncorrectExternalizable() throws Exception {
- GridTestUtils.assertThrows(
- log,
- new Callable<Object>() {
- @Override public Object call() throws Exception {
- return marshalUnmarshal(new IncorrectExternalizable());
- }
- },
- IOException.class,
- null);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testExcludedClass() throws Exception {
- Class<?>[] exclClasses = U.staticField(MarshallerExclusions.class, "EXCL_CLASSES");
-
- assertFalse(F.isEmpty(exclClasses));
-
- for (Class<?> cls : exclClasses)
- assertEquals(cls, marshalUnmarshal(cls));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testInet6Address() throws Exception {
- final InetAddress address = Inet6Address.getByAddress(new byte[16]);
-
- assertEquals(address, marshalUnmarshal(address));
- }
-
- /**
- * @throws Exception If failed.
- */
- @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
- public void testPutFieldsWithDefaultWriteObject() throws Exception {
- try {
- marshalUnmarshal(new CustomWriteObjectMethodObject("test"));
- }
- catch (IOException e) {
- assert e.getCause() instanceof NotActiveException;
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- @SuppressWarnings("ThrowableInstanceNeverThrown")
- public void testThrowable() throws Exception {
- Throwable t = new Throwable("Throwable");
-
- assertEquals(t.getMessage(), ((Throwable)marshalUnmarshal(t)).getMessage());
- }
-
- /**
- * Marshals and unmarshals object.
- *
- * @param obj Original object.
- * @return Object after marshalling and unmarshalling.
- * @throws Exception In case of error.
- */
- private <T> T marshalUnmarshal(@Nullable Object obj) throws Exception {
- OptimizedObjectOutputStream out = null;
- OptimizedObjectInputStream in = null;
-
- try {
- out = OptimizedObjectStreamRegistry.out();
-
- out.context(clsMap, CTX, null, true);
-
- out.writeObject(obj);
-
- byte[] arr = out.out().array();
-
- in = OptimizedObjectStreamRegistry.in();
-
- in.context(clsMap, CTX, null, getClass().getClassLoader());
-
- in.in().bytes(arr, arr.length);
-
- Object obj0 = in.readObject();
-
- checkHandles(out, in);
-
- return (T)obj0;
- }
- finally {
- OptimizedObjectStreamRegistry.closeOut(out);
- OptimizedObjectStreamRegistry.closeIn(in);
- }
- }
-
- /**
- * Checks that handles are equal in output and input streams.
- *
- * @param out Output stream.
- * @param in Input stream.
- * @throws Exception If failed.
- */
- private void checkHandles(OptimizedObjectOutputStream out, OptimizedObjectInputStream in)
- throws Exception {
- Object[] outHandles = out.handledObjects();
- Object[] inHandles = in.handledObjects();
-
- assertEquals(outHandles.length, inHandles.length);
-
- for (int i = 0; i < outHandles.length; i++) {
- if (outHandles[i] == null)
- assertTrue(inHandles[i] == null);
- else {
- assertFalse(inHandles[i] == null);
-
- assertTrue(outHandles[i].getClass() == inHandles[i].getClass());
- }
- }
- }
-
- /** */
- private static class IncorrectExternalizable implements Externalizable {
- /**
- * Required by {@link Externalizable}.
- */
- public IncorrectExternalizable() {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(0);
- out.writeInt(200);
- out.writeObject("str");
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- in.readInt();
- in.readObject();
- }
- }
-
- /**
- * Test object.
- */
- private static class TestObject implements Serializable {
- /** */
- private Long longVal;
-
- /** */
- private Double doubleVal;
-
- /** */
- private Long[] longArr;
-
- /** */
- private Double[] doubleArr;
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- TestObject obj = (TestObject)o;
-
- return longVal != null ? longVal.equals(obj.longVal) : obj.longVal == null &&
- doubleVal != null ? doubleVal.equals(obj.doubleVal) : obj.doubleVal == null &&
- Arrays.equals(longArr, obj.longArr) &&
- Arrays.equals(doubleArr, obj.doubleArr);
- }
- }
-
- /**
- * Externalizable test object.
- */
- private static class ExternalizableTestObject1 implements Externalizable {
- /** */
- private Long longVal;
-
- /** */
- private Double doubleVal;
-
- /** */
- private Long[] longArr;
-
- /** */
- private Double[] doubleArr;
-
- /**
- * Required by {@link Externalizable}.
- */
- public ExternalizableTestObject1() {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- ExternalizableTestObject1 obj = (ExternalizableTestObject1)o;
-
- return longVal != null ? longVal.equals(obj.longVal) : obj.longVal == null &&
- doubleVal != null ? doubleVal.equals(obj.doubleVal) : obj.doubleVal == null &&
- Arrays.equals(longArr, obj.longArr) &&
- Arrays.equals(doubleArr, obj.doubleArr);
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- out.writeLong(longVal);
- out.writeDouble(doubleVal);
- U.writeArray(out, longArr);
- U.writeArray(out, doubleArr);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- longVal = in.readLong();
- doubleVal = in.readDouble();
-
- Object[] arr = U.readArray(in);
-
- longArr = Arrays.copyOf(arr, arr.length, Long[].class);
-
- arr = U.readArray(in);
-
- doubleArr = Arrays.copyOf(arr, arr.length, Double[].class);
- }
- }
-
- /**
- * Externalizable test object.
- */
- private static class ExternalizableTestObject2 implements Externalizable {
- /** */
- private Long longVal;
-
- /** */
- private Double doubleVal;
-
- /** */
- private Long[] longArr;
-
- /** */
- private Double[] doubleArr;
-
- /**
- * Required by {@link Externalizable}.
- */
- public ExternalizableTestObject2() {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- ExternalizableTestObject2 obj = (ExternalizableTestObject2)o;
-
- return longVal != null ? longVal.equals(obj.longVal) : obj.longVal == null &&
- doubleVal != null ? doubleVal.equals(obj.doubleVal) : obj.doubleVal == null &&
- Arrays.equals(longArr, obj.longArr) &&
- Arrays.equals(doubleArr, obj.doubleArr);
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- out.writeLong(longVal);
- U.writeArray(out, longArr);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- longVal = in.readLong();
-
- Object[] arr = U.readArray(in);
-
- longArr = Arrays.copyOf(arr, arr.length, Long[].class);
- }
- }
-
- /**
- * Test object.
- */
- private static class LinkTestObject1 implements Serializable {
- /** */
- private int val;
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- LinkTestObject1 obj = (LinkTestObject1)o;
-
- return val == obj.val;
- }
- }
-
- /**
- * Test object.
- */
- private static class LinkTestObject2 implements Serializable {
- /** */
- private LinkTestObject1 ref;
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- LinkTestObject2 obj = (LinkTestObject2)o;
-
- return ref != null ? ref.equals(obj.ref) : obj.ref == null;
- }
- }
-
- /**
- * Cycle link test object.
- */
- private static class CycleLinkTestObject implements Serializable {
- /** */
- private int val;
-
- /** */
- private CycleLinkTestObject ref;
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- CycleLinkTestObject obj = (CycleLinkTestObject)o;
-
- return val == obj.val && ref != null ? ref.val == val : obj.ref == null;
- }
- }
-
- /**
- * Test object without default constructor.
- */
- private static class NoDefaultConstructorTestObject implements Serializable {
- /** */
- private int val;
-
- /**
- * @param val Value.
- */
- private NoDefaultConstructorTestObject(int val) {
- this.val = val;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- NoDefaultConstructorTestObject obj = (NoDefaultConstructorTestObject)o;
-
- return val == obj.val;
- }
- }
-
- /**
- * Test object with transient fields.
- */
- @SuppressWarnings("TransientFieldNotInitialized")
- private static class TransientTestObject implements Serializable {
- /** */
- private int val1;
-
- /** */
- private transient int val2;
-
- /** */
- private String str1;
-
- /** */
- private transient String str2;
-
- /**
- * @param val1 Value 1.
- * @param val2 Value 2.
- * @param str1 String 1.
- * @param str2 String 2.
- */
- private TransientTestObject(int val1, int val2, String str1, String str2) {
- this.val1 = val1;
- this.val2 = val2;
- this.str1 = str1;
- this.str2 = str2;
- }
- }
-
- /**
- * Test object with {@code writeObject} and {@code readObject} methods.
- */
- @SuppressWarnings("TransientFieldNotInitialized")
- private static class WriteReadTestObject implements Serializable {
- /** */
- private int val;
-
- /** */
- private transient String str;
-
- /**
- * @param val Value.
- * @param str String.
- */
- private WriteReadTestObject(int val, String str) {
- this.val = val;
- this.str = str;
- }
-
- /**
- * @param out Output stream.
- * @throws IOException In case of error.
- */
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
-
- out.writeUTF("Optional data");
- }
-
- /**
- * @param in Input stream.
- * @throws IOException In case of error.
- * @throws ClassNotFoundException If class not found.
- */
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
-
- str = in.readUTF();
- }
- }
-
- /**
- * Test object that uses {@code writeFields} and {@code readFields} methods.
- */
- private static class WriteReadFieldsTestObject implements Serializable {
- /** */
- private int val;
-
- /** */
- private String str;
-
- /**
- * @param val Value.
- * @param str String.
- */
- private WriteReadFieldsTestObject(int val, String str) {
- this.val = val;
- this.str = str;
- }
-
- /**
- * @param out Output stream.
- * @throws IOException In case of error.
- */
- private void writeObject(ObjectOutputStream out) throws IOException {
- ObjectOutputStream.PutField fields = out.putFields();
-
- fields.put("val", val);
- fields.put("str", "Optional data");
-
- out.writeFields();
- }
-
- /**
- * @param in Input stream.
- * @throws IOException In case of error.
- * @throws ClassNotFoundException If class not found.
- */
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- ObjectInputStream.GetField fields = in.readFields();
-
- val = fields.get("val", 0);
- str = (String)fields.get("str", null);
- }
- }
-
- /**
- * Test object that uses {@code writeFields} and {@code readFields} methods.
- */
- private static class WriteFieldsTestObject implements Serializable {
- /** */
- private int val;
-
- /** */
- @SuppressWarnings("UnusedDeclaration")
- private String str;
-
- /**
- * @param val Value.
- * @param str String.
- */
- private WriteFieldsTestObject(int val, String str) {
- this.val = val;
- this.str = str;
- }
-
- /**
- * @param out Output stream.
- * @throws IOException In case of error.
- */
- private void writeObject(ObjectOutputStream out) throws IOException {
- ObjectOutputStream.PutField fields = out.putFields();
-
- fields.put("val", val);
- fields.put("str", "Optional data");
-
- out.writeFields();
- }
- }
-
- /**
- * Base object with {@code writeReplace} method.
- */
- private abstract static class ReplaceTestBaseObject implements Serializable {
- /** */
- private int val;
-
- /**
- * @param val Value.
- */
- private ReplaceTestBaseObject(int val) {
- this.val = val;
- }
-
- /**
- * @return Value.
- */
- public int value() {
- return val;
- }
-
- /**
- * @return Replaced object.
- * @throws ObjectStreamException In case of error.
- */
- protected Object writeReplace() throws ObjectStreamException {
- return new ReplaceTestObject(val * 2);
- }
- }
-
- /**
- * Test object for {@code writeReplace} method.
- */
- private static class ReplaceTestObject extends ReplaceTestBaseObject {
- /**
- * @param val Value.
- */
- private ReplaceTestObject(int val) {
- super(val);
- }
- }
-
- /**
- * Test object with {@code writeReplace} method.
- */
- private static class ReplaceNullTestObject implements Serializable {
- /**
- * @return Replaced object.
- * @throws ObjectStreamException In case of error.
- */
- protected Object writeReplace() throws ObjectStreamException {
- return null;
- }
- }
-
- /**
- * Base object with {@code readResolve} method.
- */
- private abstract static class ResolveTestBaseObject implements Serializable {
- /** */
- private int val;
-
- /**
- * @param val Value.
- */
- private ResolveTestBaseObject(int val) {
- this.val = val;
- }
-
- /**
- * @return Value.
- */
- public int value() {
- return val;
- }
-
- /**
- * @return Replaced object.
- * @throws ObjectStreamException In case of error.
- */
- protected Object readResolve() throws ObjectStreamException {
- return new ResolveTestObject(val * 2);
- }
- }
-
- /**
- * Test object for {@code readResolve} method.
- */
- private static class ResolveTestObject extends ResolveTestBaseObject {
- /**
- * @param val Value.
- */
- private ResolveTestObject(int val) {
- super(val);
- }
- }
-
- /**
- * Class A.
- */
- private static class A implements Serializable {
- /** */
- private int valA;
-
- /** */
- private transient String strA;
-
- /**
- * @param valA Value A.
- * @param strA String A.
- */
- A(int valA, String strA) {
- this.valA = valA;
- this.strA = strA;
- }
-
- /**
- * @return Value.
- */
- int valueA() {
- return valA;
- }
-
- /**
- * @return String.
- */
- String stringA() {
- return strA;
- }
-
- /**
- * @param out Output stream.
- * @throws IOException In case of error.
- */
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.defaultWriteObject();
-
- out.writeUTF("Optional data");
- }
-
- /**
- * @param in Input stream.
- * @throws IOException In case of error.
- * @throws ClassNotFoundException If class not found.
- */
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- in.defaultReadObject();
-
- strA = in.readUTF();
- }
- }
-
- /**
- * Class B.
- */
- private static class B extends A {
- /** */
- private int valB;
-
- /** */
- @SuppressWarnings("TransientFieldNotInitialized")
- private transient String strB;
-
- /**
- * @param valA Value A.
- * @param strA String A.
- * @param valB Value B.
- * @param strB String B.
- */
- B(int valA, String strA, int valB, String strB) {
- super(valA, strA);
-
- this.valB = valB;
- this.strB = strB;
- }
-
- /**
- * @return Value.
- */
- int valueB() {
- return valB;
- }
-
- /**
- * @return String.
- */
- String stringB() {
- return strB;
- }
- }
-
- /**
- * Class C.
- */
- @SuppressWarnings("MethodOverridesPrivateMethodOfSuperclass")
- private static class C extends B {
- /** */
- @SuppressWarnings("InstanceVariableMayNotBeInitializedByReadObject")
- private int valC;
-
- /** */
- private transient String strC;
-
- /**
- * @param valA Value A.
- * @param strA String A.
- * @param valB Value B.
- * @param strB String B.
- * @param valC Value C.
- * @param strC String C.
- */
- C(int valA, String strA, int valB, String strB, int valC, String strC) {
- super(valA, strA, valB, strB);
-
- this.valC = valC;
- this.strC = strC;
- }
-
- /**
- * @return Value.
- */
- int valueC() {
- return valC;
- }
-
- /**
- * @return String.
- */
- String stringC() {
- return strC;
- }
-
- /**
- * @param out Output stream.
- * @throws IOException In case of error.
- */
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.writeUTF("Optional data");
- }
-
- /**
- * @param in Input stream.
- * @throws IOException In case of error.
- * @throws ClassNotFoundException If class not found.
- */
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- strC = in.readUTF();
- }
- }
-
- /**
- * Complex test object.
- */
- private static class ComplexTestObject implements Serializable {
- /** */
- private byte byteVal1;
-
- /** */
- private short shortVal1;
-
- /** */
- private int intVal1;
-
- /** */
- private long longVal1;
-
- /** */
- private float floatVal1;
-
- /** */
- private double doubleVal1;
-
- /** */
- private char cVal1;
-
- /** */
- private boolean boolVal1;
-
- /** */
- private Byte byteVal2;
-
- /** */
- private Short shortVal2;
-
- /** */
- private Integer intVal2;
-
- /** */
- private Long longVal2;
-
- /** */
- private Float floatVal2;
-
- /** */
- private Double doubleVal2;
-
- /** */
- private Character cVal2;
-
- /** */
- private Boolean boolVal2;
-
- /** */
- private byte[] byteArr;
-
- /** */
- private short[] shortArr;
-
- /** */
- private int[] intArr;
-
- /** */
- private long[] longArr;
-
- /** */
- private float[] floatArr;
-
- /** */
- private double[] doubleArr;
-
- /** */
- private char[] cArr;
-
- /** */
- private boolean[] boolArr;
-
- /** */
- private ExternalizableTestObject1[] objArr;
-
- /** */
- private String str;
-
- /** */
- private TestEnum enumVal;
-
- /** */
- private UUID uuid;
-
- /** */
- private Properties props;
-
- /** */
- private ArrayList<Integer> arrList;
-
- /** */
- private HashMap<Integer, String> hashMap;
-
- /** */
- private HashSet<Integer> hashSet;
-
- /** */
- private LinkedList<Integer> linkedList;
-
- /** */
- private LinkedHashMap<Integer, String> linkedHashMap;
-
- /** */
- private LinkedHashSet<Integer> linkedHashSet;
-
- /** */
- private Date date;
-
- /** */
- private Class<?> cls;
-
- /** */
- private ComplexTestObject self;
-
- /** */
- private ComplexTestObject() {
- self = this;
- }
-
- /**
- * @param byteVal1 Byte value.
- * @param shortVal1 Short value.
- * @param intVal1 Integer value.
- * @param longVal1 Long value.
- * @param floatVal1 Float value.
- * @param doubleVal1 Double value.
- * @param cVal1 Char value.
- * @param boolVal1 Boolean value.
- * @param byteVal2 Byte value.
- * @param shortVal2 Short value.
- * @param intVal2 Integer value.
- * @param longVal2 Long value.
- * @param floatVal2 Float value.
- * @param doubleVal2 Double value.
- * @param cVal2 Char value.
- * @param boolVal2 Boolean value.
- * @param byteArr Bytes array.
- * @param shortArr Shorts array.
- * @param intArr Integers array.
- * @param longArr Longs array.
- * @param floatArr Floats array.
- * @param doubleArr Doubles array.
- * @param cArr Chars array.
- * @param boolArr Booleans array.
- * @param objArr Objects array.
- * @param str String.
- * @param enumVal Enum.
- * @param uuid UUID.
- * @param props Properties.
- * @param arrList ArrayList.
- * @param hashMap HashMap.
- * @param hashSet HashSet.
- * @param linkedList LinkedList.
- * @param linkedHashMap LinkedHashMap.
- * @param linkedHashSet LinkedHashSet.
- * @param date Date.
- * @param cls Class.
- */
- private ComplexTestObject(byte byteVal1, short shortVal1, int intVal1, long longVal1, float floatVal1,
- double doubleVal1, char cVal1, boolean boolVal1, Byte byteVal2, Short shortVal2, Integer intVal2,
- Long longVal2, Float floatVal2, Double doubleVal2, Character cVal2, Boolean boolVal2, byte[] byteArr,
- short[] shortArr, int[] intArr, long[] longArr, float[] floatArr, double[] doubleArr, char[] cArr,
- boolean[] boolArr, ExternalizableTestObject1[] objArr, String str, TestEnum enumVal, UUID uuid,
- Properties props, ArrayList<Integer> arrList, HashMap<Integer, String> hashMap, HashSet<Integer> hashSet,
- LinkedList<Integer> linkedList, LinkedHashMap<Integer, String> linkedHashMap,
- LinkedHashSet<Integer> linkedHashSet, Date date, Class<?> cls) {
- this.byteVal1 = byteVal1;
- this.shortVal1 = shortVal1;
- this.intVal1 = intVal1;
- this.longVal1 = longVal1;
- this.floatVal1 = floatVal1;
- this.doubleVal1 = doubleVal1;
- this.cVal1 = cVal1;
- this.boolVal1 = boolVal1;
- this.byteVal2 = byteVal2;
- this.shortVal2 = shortVal2;
- this.intVal2 = intVal2;
- this.longVal2 = longVal2;
- this.floatVal2 = floatVal2;
- this.doubleVal2 = doubleVal2;
- this.cVal2 = cVal2;
- this.boolVal2 = boolVal2;
- this.byteArr = byteArr;
- this.shortArr = shortArr;
- this.intArr = intArr;
- this.longArr = longArr;
- this.floatArr = floatArr;
- this.doubleArr = doubleArr;
- this.cArr = cArr;
- this.boolArr = boolArr;
- this.objArr = objArr;
- this.str = str;
- this.enumVal = enumVal;
- this.uuid = uuid;
- this.props = props;
- this.arrList = arrList;
- this.hashMap = hashMap;
- this.hashSet = hashSet;
- this.linkedList = linkedList;
- this.linkedHashMap = linkedHashMap;
- this.linkedHashSet = linkedHashSet;
- this.date = date;
- this.cls = cls;
-
- self = this;
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("RedundantIfStatement")
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- ComplexTestObject obj = (ComplexTestObject)o;
-
- if (boolVal1 != obj.boolVal1)
- return false;
-
- if (byteVal1 != obj.byteVal1)
- return false;
-
- if (cVal1 != obj.cVal1)
- return false;
-
- if (Double.compare(obj.doubleVal1, doubleVal1) != 0)
- return false;
-
- if (Float.compare(obj.floatVal1, floatVal1) != 0)
- return false;
-
- if (intVal1 != obj.intVal1)
- return false;
-
- if (longVal1 != obj.longVal1)
- return false;
-
- if (shortVal1 != obj.shortVal1)
- return false;
-
- if (arrList != null ? !arrList.equals(obj.arrList) : obj.arrList != null)
- return false;
-
- if (!Arrays.equals(boolArr, obj.boolArr))
- return false;
-
- if (boolVal2 != null ? !boolVal2.equals(obj.boolVal2) : obj.boolVal2 != null)
- return false;
-
- if (!Arrays.equals(byteArr, obj.byteArr))
- return false;
-
- if (byteVal2 != null ? !byteVal2.equals(obj.byteVal2) : obj.byteVal2 != null)
- return false;
-
- if (!Arrays.equals(cArr, obj.cArr))
- return false;
-
- if (cVal2 != null ? !cVal2.equals(obj.cVal2) : obj.cVal2 != null)
- return false;
-
- if (cls != null ? !cls.equals(obj.cls) : obj.cls != null)
- return false;
-
- if (date != null ? !date.equals(obj.date) : obj.date != null)
- return false;
-
- if (!Arrays.equals(doubleArr, obj.doubleArr))
- return false;
-
- if (doubleVal2 != null ? !doubleVal2.equals(obj.doubleVal2) : obj.doubleVal2 != null)
- return false;
-
- if (enumVal != obj.enumVal)
- return false;
-
- if (!Arrays.equals(floatArr, obj.floatArr))
- return false;
-
- if (floatVal2 != null ? !floatVal2.equals(obj.floatVal2) : obj.floatVal2 != null)
- return false;
-
- if (hashMap != null ? !hashMap.equals(obj.hashMap) : obj.hashMap != null)
- return false;
-
- if (hashSet != null ? !hashSet.equals(obj.hashSet) : obj.hashSet != null)
- return false;
-
- if (!Arrays.equals(intArr, obj.intArr))
- return false;
-
- if (intVal2 != null ? !intVal2.equals(obj.intVal2) : obj.intVal2 != null)
- return false;
-
- if (linkedHashMap != null ? !linkedHashMap.equals(obj.linkedHashMap) : obj.linkedHashMap != null)
- return false;
-
- if (linkedHashSet != null ? !linkedHashSet.equals(obj.linkedHashSet) : obj.linkedHashSet != null)
- return false;
-
- if (linkedList != null ? !linkedList.equals(obj.linkedList) : obj.linkedList != null)
- return false;
-
- if (!Arrays.equals(longArr, obj.longArr))
- return false;
-
- if (longVal2 != null ? !longVal2.equals(obj.longVal2) : obj.longVal2 != null)
- return false;
-
- if (!Arrays.equals(objArr, obj.objArr))
- return false;
-
- if (props != null ? !props.equals(obj.props) : obj.props != null)
- return false;
-
- if (!Arrays.equals(shortArr, obj.shortArr))
- return false;
-
- if (shortVal2 != null ? !shortVal2.equals(obj.shortVal2) : obj.shortVal2 != null)
- return false;
-
- if (str != null ? !str.equals(obj.str) : obj.str != null)
- return false;
-
- if (uuid != null ? !uuid.equals(obj.uuid) : obj.uuid != null)
- return false;
-
- if (self != this)
- return false;
-
- return true;
- }
- }
-
- /**
- * Test enum.
- */
- @SuppressWarnings("JavaDoc")
- private enum TestEnum {
- /** */
- A,
-
- /** */
- B,
-
- /** */
- C
- }
-
- /**
- * Class with custom serialization method which at the beginning invokes
- * {@link ObjectOutputStream#defaultWriteObject()} and {@link ObjectOutputStream#putFields()} then.
- */
- public static class CustomWriteObjectMethodObject implements Serializable {
- /** */
- private final String name;
-
- /**
- * Creates new instance.
- * @param name Object name.
- */
- public CustomWriteObjectMethodObject(String name) {
- this.name = name;
- }
-
- /** {@inheritDoc} */
- private void writeObject(ObjectOutputStream stream) throws IOException {
- stream.defaultWriteObject();
-
- ObjectOutputStream.PutField fields = stream.putFields();
- fields.put("name", "test");
-
- stream.writeFields();
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/TestTcpDiscoveryIpFinderAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/TestTcpDiscoveryIpFinderAdapter.java b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/TestTcpDiscoveryIpFinderAdapter.java
deleted file mode 100644
index f72e77a..0000000
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/TestTcpDiscoveryIpFinderAdapter.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.optimized;
-
-import java.net.InetSocketAddress;
-import java.util.Collection;
-import org.apache.ignite.spi.IgniteSpiException;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter;
-
-/**
- * Test TCP discovery IP finder adapter.
- */
-public class TestTcpDiscoveryIpFinderAdapter extends TcpDiscoveryIpFinderAdapter {
- /** {@inheritDoc} */
- @Override public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void unregisterAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
- // No-op.
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/package-info.java b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/package-info.java
deleted file mode 100644
index 2b5a692..0000000
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Optimized marchalling test package.
- */
-package org.apache.ignite.marshaller.optimized;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/messaging/IgniteMessagingWithClientTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/messaging/IgniteMessagingWithClientTest.java b/modules/core/src/test/java/org/apache/ignite/messaging/IgniteMessagingWithClientTest.java
index b731b4b..0df7933 100644
--- a/modules/core/src/test/java/org/apache/ignite/messaging/IgniteMessagingWithClientTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/messaging/IgniteMessagingWithClientTest.java
@@ -29,7 +29,7 @@ import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiPredicate;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoveryMarshallerCheckSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoveryMarshallerCheckSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoveryMarshallerCheckSelfTest.java
index d3ffb96..eb011b4 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoveryMarshallerCheckSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoveryMarshallerCheckSelfTest.java
@@ -20,7 +20,7 @@ package org.apache.ignite.spi.discovery.tcp;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.marshaller.jdk.JdkMarshaller;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.IgniteSpiException;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryMarshallerCheckSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryMarshallerCheckSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryMarshallerCheckSelfTest.java
index df2ea22..dd43cbc 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryMarshallerCheckSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryMarshallerCheckSelfTest.java
@@ -20,7 +20,7 @@ package org.apache.ignite.spi.discovery.tcp;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.marshaller.jdk.JdkMarshaller;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.IgniteSpiException;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java
index 26e7a90..1d08c48 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java
@@ -43,7 +43,7 @@ import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.configuration.TopologyValidator;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.processors.cache.MapCacheStoreStrategy;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import static org.apache.ignite.internal.util.lang.GridFunc.asArray;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
index 4d861d0..f8494da 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
@@ -36,7 +36,7 @@ import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.logger.NullLogger;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.apache.ignite.resources.LoggerResource;
import org.apache.ignite.testframework.config.GridTestProperties;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java
index 438132c..8badd86 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryBasicTestSuite.java
@@ -39,13 +39,13 @@ import org.apache.ignite.internal.util.nio.GridNioSelfTest;
import org.apache.ignite.internal.util.nio.GridNioSslSelfTest;
import org.apache.ignite.marshaller.DynamicProxySerializationMultiJvmSelfTest;
import org.apache.ignite.marshaller.jdk.GridJdkMarshallerSelfTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerEnumSelfTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerNodeFailoverTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerPooledSelfTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerSelfTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerSerialPersistentFieldsSelfTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerTest;
-import org.apache.ignite.marshaller.optimized.OptimizedObjectStreamSelfTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerEnumSelfTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerNodeFailoverTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerPooledSelfTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerSelfTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerSerialPersistentFieldsSelfTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedObjectStreamSelfTest;
import org.apache.ignite.messaging.GridMessagingNoPeerClassLoadingSelfTest;
import org.apache.ignite.messaging.GridMessagingSelfTest;
import org.apache.ignite.testframework.config.GridTestProperties;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java
index 22d3add..4c5cb98 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java
@@ -24,13 +24,13 @@ import org.apache.ignite.internal.util.GridHandleTableSelfTest;
import org.apache.ignite.internal.util.io.GridUnsafeDataInputOutputByteOrderSelfTest;
import org.apache.ignite.internal.util.io.GridUnsafeDataOutputArraySizingSelfTest;
import org.apache.ignite.marshaller.jdk.GridJdkMarshallerSelfTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerEnumSelfTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerNodeFailoverTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerPooledSelfTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerSelfTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerSerialPersistentFieldsSelfTest;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshallerTest;
-import org.apache.ignite.marshaller.optimized.OptimizedObjectStreamSelfTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerEnumSelfTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerNodeFailoverTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerPooledSelfTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerSelfTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerSerialPersistentFieldsSelfTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerTest;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedObjectStreamSelfTest;
import org.apache.ignite.testframework.GridTestUtils;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/webapp/META-INF/ignite-webapp-config.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/webapp/META-INF/ignite-webapp-config.xml b/modules/core/src/test/webapp/META-INF/ignite-webapp-config.xml
index 7fdd559..cb781e0 100644
--- a/modules/core/src/test/webapp/META-INF/ignite-webapp-config.xml
+++ b/modules/core/src/test/webapp/META-INF/ignite-webapp-config.xml
@@ -51,7 +51,7 @@
Configure optimized marshaller.
-->
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
<!--
For better performance set this property to true in case
all marshalled classes implement java.io.Serializable.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-0.xml
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-0.xml b/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-0.xml
index dd3da7c..03cf945 100644
--- a/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-0.xml
+++ b/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-0.xml
@@ -54,7 +54,7 @@
<property name="gridName" value="IGFS-cli-0"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-1.xml
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-1.xml b/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-1.xml
index c577d28..a6022fa 100644
--- a/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-1.xml
+++ b/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-1.xml
@@ -54,7 +54,7 @@
<property name="gridName" value="IGFS-cli-1"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-2.xml
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-2.xml b/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-2.xml
index 1f7eaa3..6cfcf57 100644
--- a/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-2.xml
+++ b/modules/hadoop/src/test/config/hadoop-fs-open-test/grid-2.xml
@@ -54,7 +54,7 @@
<property name="gridName" value="IGFS-cli-2"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/hadoop/src/test/config/igfs-cli-config-dual-async.xml
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/config/igfs-cli-config-dual-async.xml b/modules/hadoop/src/test/config/igfs-cli-config-dual-async.xml
index bd2ae87..488d8d9 100644
--- a/modules/hadoop/src/test/config/igfs-cli-config-dual-async.xml
+++ b/modules/hadoop/src/test/config/igfs-cli-config-dual-async.xml
@@ -55,7 +55,7 @@
<property name="gridName" value="test-IGFS-cli"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/hadoop/src/test/config/igfs-cli-config-dual-sync.xml
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/config/igfs-cli-config-dual-sync.xml b/modules/hadoop/src/test/config/igfs-cli-config-dual-sync.xml
index 9b76344..f6d5bab 100644
--- a/modules/hadoop/src/test/config/igfs-cli-config-dual-sync.xml
+++ b/modules/hadoop/src/test/config/igfs-cli-config-dual-sync.xml
@@ -53,7 +53,7 @@
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="clientMode" value="true"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/hadoop/src/test/config/igfs-cli-config-primary.xml
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/config/igfs-cli-config-primary.xml b/modules/hadoop/src/test/config/igfs-cli-config-primary.xml
index 0268cff..c1c41b4 100644
--- a/modules/hadoop/src/test/config/igfs-cli-config-primary.xml
+++ b/modules/hadoop/src/test/config/igfs-cli-config-primary.xml
@@ -55,7 +55,7 @@
<property name="gridName" value="test-IGFS-cli"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/hadoop/src/test/config/igfs-cli-config-proxy.xml
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/config/igfs-cli-config-proxy.xml b/modules/hadoop/src/test/config/igfs-cli-config-proxy.xml
index f4f794f..bd4b215 100644
--- a/modules/hadoop/src/test/config/igfs-cli-config-proxy.xml
+++ b/modules/hadoop/src/test/config/igfs-cli-config-proxy.xml
@@ -53,7 +53,7 @@
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="clientMode" value="true"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/IgniteHadoopFileSystemAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/IgniteHadoopFileSystemAbstractSelfTest.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/IgniteHadoopFileSystemAbstractSelfTest.java
index ff4ccea..f70838a 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/IgniteHadoopFileSystemAbstractSelfTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/IgniteHadoopFileSystemAbstractSelfTest.java
@@ -77,7 +77,7 @@ import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoClassQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoClassQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoClassQuerySelfTest.java
index 48d624d..4fa73b5 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoClassQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheNoClassQuerySelfTest.java
@@ -27,7 +27,7 @@ import org.apache.ignite.cache.QueryIndex;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
index e46c953..ec83687 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
@@ -38,7 +38,7 @@ import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/indexing/src/test/java/org/apache/ignite/loadtests/h2indexing/FetchingQueryCursorStressTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/loadtests/h2indexing/FetchingQueryCursorStressTest.java b/modules/indexing/src/test/java/org/apache/ignite/loadtests/h2indexing/FetchingQueryCursorStressTest.java
index 91d0c0b..bbc9762 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/loadtests/h2indexing/FetchingQueryCursorStressTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/loadtests/h2indexing/FetchingQueryCursorStressTest.java
@@ -34,7 +34,7 @@ import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.query.annotations.QuerySqlField;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
/**
* SQL query stress test.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/marshaller-invalid.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/marshaller-invalid.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/marshaller-invalid.xml
index c680314..6b93909 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/marshaller-invalid.xml
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/marshaller-invalid.xml
@@ -25,7 +25,7 @@
<property name="connectorConfiguration"><null/></property>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller" />
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller" />
</property>
<property name="discoverySpi">
[04/10] ignite git commit: IGNITE-4938: Moved OptimizedMarshaller to
private package. This closes #1793.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamSelfTest.java
new file mode 100644
index 0000000..5f72c29
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamSelfTest.java
@@ -0,0 +1,2162 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.NotActiveException;
+import java.io.NotSerializableException;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.text.SimpleDateFormat;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.IdentityHashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Properties;
+import java.util.Queue;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.UUID;
+import java.util.Vector;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentMap;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedClassDescriptor;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedObjectInputStream;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedObjectOutputStream;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedObjectStreamRegistry;
+import org.apache.ignite.internal.util.io.GridUnsafeDataInput;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContext;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.marshaller.MarshallerExclusions;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+
+import static org.junit.Assert.assertArrayEquals;
+
+/**
+ * Test for optimized object streams.
+ */
+public class OptimizedObjectStreamSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final MarshallerContext CTX = new MarshallerContextTestImpl();
+
+ /** */
+ private ConcurrentMap<Class, OptimizedClassDescriptor> clsMap = new ConcurrentHashMap8<>();
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testNull() throws Exception {
+ assertNull(marshalUnmarshal(null));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testByte() throws Exception {
+ byte val = 10;
+
+ assertEquals(new Byte(val), marshalUnmarshal(val));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testShort() throws Exception {
+ short val = 100;
+
+ assertEquals(new Short(val), marshalUnmarshal(val));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testInteger() throws Exception {
+ int val = 100;
+
+ assertEquals(new Integer(val), marshalUnmarshal(val));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLong() throws Exception {
+ long val = 1000L;
+
+ assertEquals(new Long(val), marshalUnmarshal(val));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFloat() throws Exception {
+ float val = 10.0f;
+
+ assertEquals(val, marshalUnmarshal(val));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDouble() throws Exception {
+ double val = 100.0d;
+
+ assertEquals(val, marshalUnmarshal(val));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBoolean() throws Exception {
+ boolean val = true;
+
+ assertEquals(new Boolean(val), marshalUnmarshal(val));
+
+ val = false;
+
+ assertEquals(new Boolean(val), marshalUnmarshal(val));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testChar() throws Exception {
+ char val = 10;
+
+ assertEquals(new Character(val), marshalUnmarshal(val));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testByteArray() throws Exception {
+ byte[] arr = marshalUnmarshal(new byte[] {1, 2});
+
+ assertArrayEquals(new byte[] {1, 2}, arr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testShortArray() throws Exception {
+ short[] arr = marshalUnmarshal(new short[] {1, 2});
+
+ assertArrayEquals(new short[] {1, 2}, arr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testIntArray() throws Exception {
+ int[] arr = marshalUnmarshal(new int[] {1, 2});
+
+ assertArrayEquals(new int[] {1, 2}, arr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLongArray() throws Exception {
+ long[] arr = marshalUnmarshal(new long[] {1L, 2L});
+
+ assertArrayEquals(new long[] {1, 2}, arr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFloatArray() throws Exception {
+ float[] arr = marshalUnmarshal(new float[] {1.0f, 2.0f});
+
+ assertArrayEquals(new float[] {1.0f, 2.0f}, arr, 0.1f);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDoubleArray() throws Exception {
+ double[] arr = marshalUnmarshal(new double[] {1.0d, 2.0d});
+
+ assertArrayEquals(new double[] {1.0d, 2.0d}, arr, 0.1d);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBooleanArray() throws Exception {
+ boolean[] arr = marshalUnmarshal(new boolean[] {true, false, false});
+
+ assertEquals(3, arr.length);
+ assertEquals(true, arr[0]);
+ assertEquals(false, arr[1]);
+ assertEquals(false, arr[2]);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCharArray() throws Exception {
+ char[] arr = marshalUnmarshal(new char[] {1, 2});
+
+ assertArrayEquals(new char[] {1, 2}, arr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testObject() throws Exception {
+ TestObject obj = new TestObject();
+
+ obj.longVal = 100L;
+ obj.doubleVal = 100.0d;
+ obj.longArr = new Long[] {200L, 300L};
+ obj.doubleArr = new Double[] {200.0d, 300.0d};
+
+ assertEquals(obj, marshalUnmarshal(obj));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testRequireSerializable() throws Exception {
+ try {
+ OptimizedMarshaller marsh = new OptimizedMarshaller(true);
+
+ marsh.setContext(CTX);
+
+ marsh.marshal(new Object());
+
+ assert false : "Exception not thrown.";
+ }
+ catch (IgniteCheckedException e) {
+ NotSerializableException serEx = e.getCause(NotSerializableException.class);
+
+ if (serEx == null)
+ throw e;
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPool() throws Exception {
+ final TestObject obj = new TestObject();
+
+ obj.longVal = 100L;
+ obj.doubleVal = 100.0d;
+ obj.longArr = new Long[100 * 1024];
+ obj.doubleArr = new Double[100 * 1024];
+
+ Arrays.fill(obj.longArr, 100L);
+ Arrays.fill(obj.doubleArr, 100.0d);
+
+ final OptimizedMarshaller marsh = new OptimizedMarshaller();
+
+ marsh.setContext(CTX);
+
+ marsh.setPoolSize(5);
+
+ try {
+ multithreaded(new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ for (int i = 0; i < 50; i++)
+ assertEquals(obj, marsh.unmarshal(marsh.marshal(obj), null));
+
+ return null;
+ }
+ }, 20);
+ }
+ finally {
+ marsh.setPoolSize(0);
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testObjectWithNulls() throws Exception {
+ TestObject obj = new TestObject();
+
+ obj.longVal = 100L;
+ obj.longArr = new Long[] {200L, 300L};
+
+ assertEquals(obj, marshalUnmarshal(obj));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testObjectArray() throws Exception {
+ TestObject obj1 = new TestObject();
+
+ obj1.longVal = 100L;
+ obj1.doubleVal = 100.0d;
+ obj1.longArr = new Long[] {200L, 300L};
+ obj1.doubleArr = new Double[] {200.0d, 300.0d};
+
+ TestObject obj2 = new TestObject();
+
+ obj2.longVal = 400L;
+ obj2.doubleVal = 400.0d;
+ obj2.longArr = new Long[] {500L, 600L};
+ obj2.doubleArr = new Double[] {500.0d, 600.0d};
+
+ TestObject[] arr = {obj1, obj2};
+
+ assertArrayEquals(arr, (Object[])marshalUnmarshal(arr));
+
+ String[] strArr = {"str1", "str2"};
+
+ assertArrayEquals(strArr, (String[])marshalUnmarshal(strArr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testExternalizable() throws Exception {
+ ExternalizableTestObject1 obj = new ExternalizableTestObject1();
+
+ obj.longVal = 100L;
+ obj.doubleVal = 100.0d;
+ obj.longArr = new Long[] {200L, 300L};
+ obj.doubleArr = new Double[] {200.0d, 300.0d};
+
+ assertEquals(obj, marshalUnmarshal(obj));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testExternalizableWithNulls() throws Exception {
+ ExternalizableTestObject2 obj = new ExternalizableTestObject2();
+
+ obj.longVal = 100L;
+ obj.doubleVal = 100.0d;
+ obj.longArr = new Long[] {200L, 300L};
+ obj.doubleArr = new Double[] {200.0d, 300.0d};
+
+ obj = marshalUnmarshal(obj);
+
+ assertEquals(100L, obj.longVal.longValue());
+ assertNull(obj.doubleVal);
+ assertArrayEquals(new Long[] {200L, 300L}, obj.longArr);
+ assertNull(obj.doubleArr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLink() throws Exception {
+ for (int i = 0; i < 20; i++) {
+ LinkTestObject1 obj1 = new LinkTestObject1();
+ LinkTestObject2 obj2 = new LinkTestObject2();
+ LinkTestObject2 obj3 = new LinkTestObject2();
+
+ obj1.val = 100;
+ obj2.ref = obj1;
+ obj3.ref = obj1;
+
+ LinkTestObject2[] arr = new LinkTestObject2[] {obj2, obj3};
+
+ assertArrayEquals(arr, (Object[])marshalUnmarshal(arr));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCycleLink() throws Exception {
+ for (int i = 0; i < 20; i++) {
+ CycleLinkTestObject obj = new CycleLinkTestObject();
+
+ obj.val = 100;
+ obj.ref = obj;
+
+ assertEquals(obj, marshalUnmarshal(obj));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testNoDefaultConstructor() throws Exception {
+ NoDefaultConstructorTestObject obj = new NoDefaultConstructorTestObject(100);
+
+ assertEquals(obj, marshalUnmarshal(obj));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testEnum() throws Exception {
+ assertEquals(TestEnum.B, marshalUnmarshal(TestEnum.B));
+
+ TestEnum[] arr = new TestEnum[] {TestEnum.C, TestEnum.A, TestEnum.B, TestEnum.A};
+
+ assertArrayEquals(arr, (Object[])marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCollection() throws Exception {
+ TestObject obj1 = new TestObject();
+
+ obj1.longVal = 100L;
+ obj1.doubleVal = 100.0d;
+ obj1.longArr = new Long[] {200L, 300L};
+ obj1.doubleArr = new Double[] {200.0d, 300.0d};
+
+ TestObject obj2 = new TestObject();
+
+ obj2.longVal = 400L;
+ obj2.doubleVal = 400.0d;
+ obj2.longArr = new Long[] {500L, 600L};
+ obj2.doubleArr = new Double[] {500.0d, 600.0d};
+
+ Collection<TestObject> col = F.asList(obj1, obj2);
+
+ assertEquals(col, marshalUnmarshal(col));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMap() throws Exception {
+ TestObject obj1 = new TestObject();
+
+ obj1.longVal = 100L;
+ obj1.doubleVal = 100.0d;
+ obj1.longArr = new Long[] {200L, 300L};
+ obj1.doubleArr = new Double[] {200.0d, 300.0d};
+
+ TestObject obj2 = new TestObject();
+
+ obj2.longVal = 400L;
+ obj2.doubleVal = 400.0d;
+ obj2.longArr = new Long[] {500L, 600L};
+ obj2.doubleArr = new Double[] {500.0d, 600.0d};
+
+ Map<Integer, TestObject> map = F.asMap(1, obj1, 2, obj2);
+
+ assertEquals(map, marshalUnmarshal(map));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testUuid() throws Exception {
+ UUID uuid = UUID.randomUUID();
+
+ assertEquals(uuid, marshalUnmarshal(uuid));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDate() throws Exception {
+ Date date = new Date();
+
+ assertEquals(date, marshalUnmarshal(date));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTransient() throws Exception {
+ TransientTestObject obj = marshalUnmarshal(new TransientTestObject(100, 200, "str1", "str2"));
+
+ assertEquals(100, obj.val1);
+ assertEquals(0, obj.val2);
+ assertEquals("str1", obj.str1);
+ assertNull(obj.str2);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testWriteReadObject() throws Exception {
+ WriteReadTestObject obj = marshalUnmarshal(new WriteReadTestObject(100, "str"));
+
+ assertEquals(100, obj.val);
+ assertEquals("Optional data", obj.str);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testWriteReplace() throws Exception {
+ ReplaceTestObject obj = marshalUnmarshal(new ReplaceTestObject(100));
+
+ assertEquals(200, obj.value());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testWriteReplaceNull() throws Exception {
+ ReplaceNullTestObject obj = marshalUnmarshal(new ReplaceNullTestObject());
+
+ assertNull(obj);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testReadResolve() throws Exception {
+ ResolveTestObject obj = marshalUnmarshal(new ResolveTestObject(100));
+
+ assertEquals(200, obj.value());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testArrayDeque() throws Exception {
+ Queue<Integer> queue = new ArrayDeque<>();
+
+ for (int i = 0; i < 100; i++)
+ queue.add(i);
+
+ Queue<Integer> newQueue = marshalUnmarshal(queue);
+
+ assertEquals(queue.size(), newQueue.size());
+
+ Integer i;
+
+ while ((i = newQueue.poll()) != null)
+ assertEquals(queue.poll(), i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testArrayList() throws Exception {
+ Collection<Integer> list = new ArrayList<>();
+
+ for (int i = 0; i < 100; i++)
+ list.add(i);
+
+ assertEquals(list, marshalUnmarshal(list));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testHashMap() throws Exception {
+ Map<Integer, Integer> map = new HashMap<>();
+
+ for (int i = 0; i < 100; i++)
+ map.put(i, i);
+
+ assertEquals(map, marshalUnmarshal(map));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testHashSet() throws Exception {
+ Collection<Integer> set = new HashSet<>();
+
+ for (int i = 0; i < 100; i++)
+ set.add(i);
+
+ assertEquals(set, marshalUnmarshal(set));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("UseOfObsoleteCollectionType")
+ public void testHashtable() throws Exception {
+ Map<Integer, Integer> map = new Hashtable<>();
+
+ for (int i = 0; i < 100; i++)
+ map.put(i, i);
+
+ assertEquals(map, marshalUnmarshal(map));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testIdentityHashMap() throws Exception {
+ Map<Integer, Integer> map = new IdentityHashMap<>();
+
+ for (int i = 0; i < 100; i++)
+ map.put(i, i);
+
+ assertEquals(map, marshalUnmarshal(map));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLinkedHashMap() throws Exception {
+ Map<Integer, Integer> map = new LinkedHashMap<>();
+
+ for (int i = 0; i < 100; i++)
+ map.put(i, i);
+
+ assertEquals(map, marshalUnmarshal(map));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLinkedHashSet() throws Exception {
+ Collection<Integer> set = new LinkedHashSet<>();
+
+ for (int i = 0; i < 100; i++)
+ set.add(i);
+
+ assertEquals(set, marshalUnmarshal(set));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLinkedList() throws Exception {
+ Collection<Integer> list = new LinkedList<>();
+
+ for (int i = 0; i < 100; i++)
+ list.add(i);
+
+ assertEquals(list, marshalUnmarshal(list));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPriorityQueue() throws Exception {
+ Queue<Integer> queue = new PriorityQueue<>();
+
+ for (int i = 0; i < 100; i++)
+ queue.add(i);
+
+ Queue<Integer> newQueue = marshalUnmarshal(queue);
+
+ assertEquals(queue.size(), newQueue.size());
+
+ Integer i;
+
+ while ((i = newQueue.poll()) != null)
+ assertEquals(queue.poll(), i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testProperties() throws Exception {
+ Properties dflts = new Properties();
+
+ dflts.setProperty("key1", "val1");
+ dflts.setProperty("key2", "wrong");
+
+ Properties props = new Properties(dflts);
+
+ props.setProperty("key2", "val2");
+
+ Properties newProps = marshalUnmarshal(props);
+
+ assertEquals("val1", newProps.getProperty("key1"));
+ assertEquals("val2", newProps.getProperty("key2"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTreeMap() throws Exception {
+ Map<Integer, Integer> map = new TreeMap<>();
+
+ for (int i = 0; i < 100; i++)
+ map.put(i, i);
+
+ assertEquals(map, marshalUnmarshal(map));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTreeSet() throws Exception {
+ Collection<Integer> set = new TreeSet<>();
+
+ for (int i = 0; i < 100; i++)
+ set.add(i);
+
+ assertEquals(set, marshalUnmarshal(set));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("UseOfObsoleteCollectionType")
+ public void testVector() throws Exception {
+ Collection<Integer> vector = new Vector<>();
+
+ for (int i = 0; i < 100; i++)
+ vector.add(i);
+
+ assertEquals(vector, marshalUnmarshal(vector));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testString() throws Exception {
+ assertEquals("Latin", marshalUnmarshal("Latin"));
+ assertEquals("\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430", marshalUnmarshal("\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430"));
+ assertEquals("\u4e2d\u56fd\u7684", marshalUnmarshal("\u4e2d\u56fd\u7684"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testReadLine() throws Exception {
+ OptimizedObjectInputStream in = new OptimizedObjectInputStream(new GridUnsafeDataInput());
+
+ byte[] bytes = "line1\nline2\r\nli\rne3\nline4".getBytes();
+
+ in.in().bytes(bytes, bytes.length);
+
+ assertEquals("line1", in.readLine());
+ assertEquals("line2", in.readLine());
+ assertEquals("line3", in.readLine());
+ assertEquals("line4", in.readLine());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testHierarchy() throws Exception {
+ C c = new C(100, "str", 200, "str", 300, "str");
+
+ C newC = marshalUnmarshal(c);
+
+ assertEquals(100, newC.valueA());
+ assertEquals("Optional data", newC.stringA());
+ assertEquals(200, newC.valueB());
+ assertNull(newC.stringB());
+ assertEquals(0, newC.valueC());
+ assertEquals("Optional data", newC.stringC());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testInet4Address() throws Exception {
+ Inet4Address addr = (Inet4Address)InetAddress.getByName("localhost");
+
+ assertEquals(addr, marshalUnmarshal(addr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClass() throws Exception {
+ assertEquals(int.class, marshalUnmarshal(int.class));
+ assertEquals(Long.class, marshalUnmarshal(Long.class));
+ assertEquals(TestObject.class, marshalUnmarshal(TestObject.class));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testWriteReadFields() throws Exception {
+ WriteReadFieldsTestObject obj = marshalUnmarshal(new WriteReadFieldsTestObject(100, "str"));
+
+ assertEquals(100, obj.val);
+ assertEquals("Optional data", obj.str);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testWriteFields() throws Exception {
+ WriteFieldsTestObject obj = marshalUnmarshal(new WriteFieldsTestObject(100, "str"));
+
+ assertEquals(100, obj.val);
+ assertEquals("Optional data", obj.str);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBigInteger() throws Exception {
+ BigInteger b = new BigInteger("54654865468745468465321414646834562346475457488");
+
+ assertEquals(b, marshalUnmarshal(b));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBigDecimal() throws Exception {
+ BigDecimal b = new BigDecimal("849572389457208934572093574.123512938654126458542145");
+
+ assertEquals(b, marshalUnmarshal(b));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testSimpleDateFormat() throws Exception {
+ SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyyy");
+
+ assertEquals(f, marshalUnmarshal(f));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testComplexObject() throws Exception {
+ ComplexTestObject obj = new ComplexTestObject();
+
+ assertEquals(obj, marshalUnmarshal(obj));
+
+ ExternalizableTestObject1 extObj1 = new ExternalizableTestObject1();
+
+ extObj1.longVal = 1000L;
+ extObj1.doubleVal = 1000.0d;
+ extObj1.longArr = new Long[] {1000L, 2000L, 3000L};
+ extObj1.doubleArr = new Double[] {1000.0d, 2000.0d, 3000.0d};
+
+ ExternalizableTestObject1 extObj2 = new ExternalizableTestObject1();
+
+ extObj2.longVal = 2000L;
+ extObj2.doubleVal = 2000.0d;
+ extObj2.longArr = new Long[] {4000L, 5000L, 6000L};
+ extObj2.doubleArr = new Double[] {4000.0d, 5000.0d, 6000.0d};
+
+ Properties props = new Properties();
+
+ props.setProperty("name", "value");
+
+ Collection<Integer> col = F.asList(10, 20, 30);
+
+ Map<Integer, String> map = F.asMap(10, "str1", 20, "str2", 30, "str3");
+
+ obj = new ComplexTestObject(
+ (byte)1,
+ (short)10,
+ 100,
+ 1000L,
+ 100.0f,
+ 1000.0d,
+ 'a',
+ false,
+ (byte)2,
+ (short)20,
+ 200,
+ 2000L,
+ 200.0f,
+ 2000.0d,
+ 'b',
+ true,
+ new byte[] {1, 2, 3},
+ new short[] {10, 20, 30},
+ new int[] {100, 200, 300},
+ new long[] {1000, 2000, 3000},
+ new float[] {100.0f, 200.0f, 300.0f},
+ new double[] {1000.0d, 2000.0d, 3000.0d},
+ new char[] {'a', 'b', 'c'},
+ new boolean[] {false, true},
+ new ExternalizableTestObject1[] {extObj1, extObj2},
+ "String",
+ TestEnum.A,
+ UUID.randomUUID(),
+ props,
+ new ArrayList<>(col),
+ new HashMap<>(map),
+ new HashSet<>(col),
+ new LinkedList<>(col),
+ new LinkedHashMap<>(map),
+ new LinkedHashSet<>(col),
+ new Date(),
+ ExternalizableTestObject2.class
+ );
+
+ assertEquals(obj, marshalUnmarshal(obj));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testReadToArray() throws Exception {
+ OptimizedObjectInputStream in = OptimizedObjectStreamRegistry.in();
+
+ try {
+ byte[] arr = new byte[50];
+
+ for (int i = 0; i < arr.length; i++)
+ arr[i] = (byte)i;
+
+ in.in().bytes(arr, arr.length);
+
+ byte[] buf = new byte[10];
+
+ assertEquals(10, in.read(buf));
+
+ for (int i = 0; i < buf.length; i++)
+ assertEquals(i, buf[i]);
+
+ buf = new byte[30];
+
+ assertEquals(20, in.read(buf, 0, 20));
+
+ for (int i = 0; i < buf.length; i++)
+ assertEquals(i < 20 ? 10 + i : 0, buf[i]);
+
+ buf = new byte[30];
+
+ assertEquals(10, in.read(buf, 10, 10));
+
+ for (int i = 0; i < buf.length; i++)
+ assertEquals(i >= 10 && i < 20 ? 30 + (i - 10) : 0, buf[i]);
+
+ buf = new byte[20];
+
+ assertEquals(10, in.read(buf));
+
+ for (int i = 0; i < buf.length; i++)
+ assertEquals(i < 10 ? 40 + i : 0, buf[i]);
+ }
+ finally {
+ OptimizedObjectStreamRegistry.closeIn(in);
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testHandleTableGrow() throws Exception {
+ List<String> c = new ArrayList<>();
+
+ for (int i = 0; i < 29; i++)
+ c.add("str");
+
+ String str = c.get(28);
+
+ c.add("str");
+ c.add(str);
+
+ List<Object> c0 = marshalUnmarshal(c);
+
+ assertTrue(c0.get(28) == c0.get(30));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testIncorrectExternalizable() throws Exception {
+ GridTestUtils.assertThrows(
+ log,
+ new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ return marshalUnmarshal(new IncorrectExternalizable());
+ }
+ },
+ IOException.class,
+ null);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testExcludedClass() throws Exception {
+ Class<?>[] exclClasses = U.staticField(MarshallerExclusions.class, "EXCL_CLASSES");
+
+ assertFalse(F.isEmpty(exclClasses));
+
+ for (Class<?> cls : exclClasses)
+ assertEquals(cls, marshalUnmarshal(cls));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testInet6Address() throws Exception {
+ final InetAddress address = Inet6Address.getByAddress(new byte[16]);
+
+ assertEquals(address, marshalUnmarshal(address));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+ public void testPutFieldsWithDefaultWriteObject() throws Exception {
+ try {
+ marshalUnmarshal(new CustomWriteObjectMethodObject("test"));
+ }
+ catch (IOException e) {
+ assert e.getCause() instanceof NotActiveException;
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("ThrowableInstanceNeverThrown")
+ public void testThrowable() throws Exception {
+ Throwable t = new Throwable("Throwable");
+
+ assertEquals(t.getMessage(), ((Throwable)marshalUnmarshal(t)).getMessage());
+ }
+
+ /**
+ * Marshals and unmarshals object.
+ *
+ * @param obj Original object.
+ * @return Object after marshalling and unmarshalling.
+ * @throws Exception In case of error.
+ */
+ private <T> T marshalUnmarshal(@Nullable Object obj) throws Exception {
+ OptimizedObjectOutputStream out = null;
+ OptimizedObjectInputStream in = null;
+
+ try {
+ out = OptimizedObjectStreamRegistry.out();
+
+ out.context(clsMap, CTX, null, true);
+
+ out.writeObject(obj);
+
+ byte[] arr = out.out().array();
+
+ in = OptimizedObjectStreamRegistry.in();
+
+ in.context(clsMap, CTX, null, getClass().getClassLoader());
+
+ in.in().bytes(arr, arr.length);
+
+ Object obj0 = in.readObject();
+
+ checkHandles(out, in);
+
+ return (T)obj0;
+ }
+ finally {
+ OptimizedObjectStreamRegistry.closeOut(out);
+ OptimizedObjectStreamRegistry.closeIn(in);
+ }
+ }
+
+ /**
+ * Checks that handles are equal in output and input streams.
+ *
+ * @param out Output stream.
+ * @param in Input stream.
+ * @throws Exception If failed.
+ */
+ private void checkHandles(OptimizedObjectOutputStream out, OptimizedObjectInputStream in)
+ throws Exception {
+ Object[] outHandles = out.handledObjects();
+ Object[] inHandles = in.handledObjects();
+
+ assertEquals(outHandles.length, inHandles.length);
+
+ for (int i = 0; i < outHandles.length; i++) {
+ if (outHandles[i] == null)
+ assertTrue(inHandles[i] == null);
+ else {
+ assertFalse(inHandles[i] == null);
+
+ assertTrue(outHandles[i].getClass() == inHandles[i].getClass());
+ }
+ }
+ }
+
+ /** */
+ private static class IncorrectExternalizable implements Externalizable {
+ /**
+ * Required by {@link Externalizable}.
+ */
+ public IncorrectExternalizable() {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeInt(0);
+ out.writeInt(200);
+ out.writeObject("str");
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ in.readInt();
+ in.readObject();
+ }
+ }
+
+ /**
+ * Test object.
+ */
+ private static class TestObject implements Serializable {
+ /** */
+ private Long longVal;
+
+ /** */
+ private Double doubleVal;
+
+ /** */
+ private Long[] longArr;
+
+ /** */
+ private Double[] doubleArr;
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestObject obj = (TestObject)o;
+
+ return longVal != null ? longVal.equals(obj.longVal) : obj.longVal == null &&
+ doubleVal != null ? doubleVal.equals(obj.doubleVal) : obj.doubleVal == null &&
+ Arrays.equals(longArr, obj.longArr) &&
+ Arrays.equals(doubleArr, obj.doubleArr);
+ }
+ }
+
+ /**
+ * Externalizable test object.
+ */
+ private static class ExternalizableTestObject1 implements Externalizable {
+ /** */
+ private Long longVal;
+
+ /** */
+ private Double doubleVal;
+
+ /** */
+ private Long[] longArr;
+
+ /** */
+ private Double[] doubleArr;
+
+ /**
+ * Required by {@link Externalizable}.
+ */
+ public ExternalizableTestObject1() {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ ExternalizableTestObject1 obj = (ExternalizableTestObject1)o;
+
+ return longVal != null ? longVal.equals(obj.longVal) : obj.longVal == null &&
+ doubleVal != null ? doubleVal.equals(obj.doubleVal) : obj.doubleVal == null &&
+ Arrays.equals(longArr, obj.longArr) &&
+ Arrays.equals(doubleArr, obj.doubleArr);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeLong(longVal);
+ out.writeDouble(doubleVal);
+ U.writeArray(out, longArr);
+ U.writeArray(out, doubleArr);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ longVal = in.readLong();
+ doubleVal = in.readDouble();
+
+ Object[] arr = U.readArray(in);
+
+ longArr = Arrays.copyOf(arr, arr.length, Long[].class);
+
+ arr = U.readArray(in);
+
+ doubleArr = Arrays.copyOf(arr, arr.length, Double[].class);
+ }
+ }
+
+ /**
+ * Externalizable test object.
+ */
+ private static class ExternalizableTestObject2 implements Externalizable {
+ /** */
+ private Long longVal;
+
+ /** */
+ private Double doubleVal;
+
+ /** */
+ private Long[] longArr;
+
+ /** */
+ private Double[] doubleArr;
+
+ /**
+ * Required by {@link Externalizable}.
+ */
+ public ExternalizableTestObject2() {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ ExternalizableTestObject2 obj = (ExternalizableTestObject2)o;
+
+ return longVal != null ? longVal.equals(obj.longVal) : obj.longVal == null &&
+ doubleVal != null ? doubleVal.equals(obj.doubleVal) : obj.doubleVal == null &&
+ Arrays.equals(longArr, obj.longArr) &&
+ Arrays.equals(doubleArr, obj.doubleArr);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeLong(longVal);
+ U.writeArray(out, longArr);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ longVal = in.readLong();
+
+ Object[] arr = U.readArray(in);
+
+ longArr = Arrays.copyOf(arr, arr.length, Long[].class);
+ }
+ }
+
+ /**
+ * Test object.
+ */
+ private static class LinkTestObject1 implements Serializable {
+ /** */
+ private int val;
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ LinkTestObject1 obj = (LinkTestObject1)o;
+
+ return val == obj.val;
+ }
+ }
+
+ /**
+ * Test object.
+ */
+ private static class LinkTestObject2 implements Serializable {
+ /** */
+ private LinkTestObject1 ref;
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ LinkTestObject2 obj = (LinkTestObject2)o;
+
+ return ref != null ? ref.equals(obj.ref) : obj.ref == null;
+ }
+ }
+
+ /**
+ * Cycle link test object.
+ */
+ private static class CycleLinkTestObject implements Serializable {
+ /** */
+ private int val;
+
+ /** */
+ private CycleLinkTestObject ref;
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ CycleLinkTestObject obj = (CycleLinkTestObject)o;
+
+ return val == obj.val && ref != null ? ref.val == val : obj.ref == null;
+ }
+ }
+
+ /**
+ * Test object without default constructor.
+ */
+ private static class NoDefaultConstructorTestObject implements Serializable {
+ /** */
+ private int val;
+
+ /**
+ * @param val Value.
+ */
+ private NoDefaultConstructorTestObject(int val) {
+ this.val = val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ NoDefaultConstructorTestObject obj = (NoDefaultConstructorTestObject)o;
+
+ return val == obj.val;
+ }
+ }
+
+ /**
+ * Test object with transient fields.
+ */
+ @SuppressWarnings("TransientFieldNotInitialized")
+ private static class TransientTestObject implements Serializable {
+ /** */
+ private int val1;
+
+ /** */
+ private transient int val2;
+
+ /** */
+ private String str1;
+
+ /** */
+ private transient String str2;
+
+ /**
+ * @param val1 Value 1.
+ * @param val2 Value 2.
+ * @param str1 String 1.
+ * @param str2 String 2.
+ */
+ private TransientTestObject(int val1, int val2, String str1, String str2) {
+ this.val1 = val1;
+ this.val2 = val2;
+ this.str1 = str1;
+ this.str2 = str2;
+ }
+ }
+
+ /**
+ * Test object with {@code writeObject} and {@code readObject} methods.
+ */
+ @SuppressWarnings("TransientFieldNotInitialized")
+ private static class WriteReadTestObject implements Serializable {
+ /** */
+ private int val;
+
+ /** */
+ private transient String str;
+
+ /**
+ * @param val Value.
+ * @param str String.
+ */
+ private WriteReadTestObject(int val, String str) {
+ this.val = val;
+ this.str = str;
+ }
+
+ /**
+ * @param out Output stream.
+ * @throws IOException In case of error.
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ out.defaultWriteObject();
+
+ out.writeUTF("Optional data");
+ }
+
+ /**
+ * @param in Input stream.
+ * @throws IOException In case of error.
+ * @throws ClassNotFoundException If class not found.
+ */
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+
+ str = in.readUTF();
+ }
+ }
+
+ /**
+ * Test object that uses {@code writeFields} and {@code readFields} methods.
+ */
+ private static class WriteReadFieldsTestObject implements Serializable {
+ /** */
+ private int val;
+
+ /** */
+ private String str;
+
+ /**
+ * @param val Value.
+ * @param str String.
+ */
+ private WriteReadFieldsTestObject(int val, String str) {
+ this.val = val;
+ this.str = str;
+ }
+
+ /**
+ * @param out Output stream.
+ * @throws IOException In case of error.
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ ObjectOutputStream.PutField fields = out.putFields();
+
+ fields.put("val", val);
+ fields.put("str", "Optional data");
+
+ out.writeFields();
+ }
+
+ /**
+ * @param in Input stream.
+ * @throws IOException In case of error.
+ * @throws ClassNotFoundException If class not found.
+ */
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ ObjectInputStream.GetField fields = in.readFields();
+
+ val = fields.get("val", 0);
+ str = (String)fields.get("str", null);
+ }
+ }
+
+ /**
+ * Test object that uses {@code writeFields} and {@code readFields} methods.
+ */
+ private static class WriteFieldsTestObject implements Serializable {
+ /** */
+ private int val;
+
+ /** */
+ @SuppressWarnings("UnusedDeclaration")
+ private String str;
+
+ /**
+ * @param val Value.
+ * @param str String.
+ */
+ private WriteFieldsTestObject(int val, String str) {
+ this.val = val;
+ this.str = str;
+ }
+
+ /**
+ * @param out Output stream.
+ * @throws IOException In case of error.
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ ObjectOutputStream.PutField fields = out.putFields();
+
+ fields.put("val", val);
+ fields.put("str", "Optional data");
+
+ out.writeFields();
+ }
+ }
+
+ /**
+ * Base object with {@code writeReplace} method.
+ */
+ private abstract static class ReplaceTestBaseObject implements Serializable {
+ /** */
+ private int val;
+
+ /**
+ * @param val Value.
+ */
+ private ReplaceTestBaseObject(int val) {
+ this.val = val;
+ }
+
+ /**
+ * @return Value.
+ */
+ public int value() {
+ return val;
+ }
+
+ /**
+ * @return Replaced object.
+ * @throws ObjectStreamException In case of error.
+ */
+ protected Object writeReplace() throws ObjectStreamException {
+ return new ReplaceTestObject(val * 2);
+ }
+ }
+
+ /**
+ * Test object for {@code writeReplace} method.
+ */
+ private static class ReplaceTestObject extends ReplaceTestBaseObject {
+ /**
+ * @param val Value.
+ */
+ private ReplaceTestObject(int val) {
+ super(val);
+ }
+ }
+
+ /**
+ * Test object with {@code writeReplace} method.
+ */
+ private static class ReplaceNullTestObject implements Serializable {
+ /**
+ * @return Replaced object.
+ * @throws ObjectStreamException In case of error.
+ */
+ protected Object writeReplace() throws ObjectStreamException {
+ return null;
+ }
+ }
+
+ /**
+ * Base object with {@code readResolve} method.
+ */
+ private abstract static class ResolveTestBaseObject implements Serializable {
+ /** */
+ private int val;
+
+ /**
+ * @param val Value.
+ */
+ private ResolveTestBaseObject(int val) {
+ this.val = val;
+ }
+
+ /**
+ * @return Value.
+ */
+ public int value() {
+ return val;
+ }
+
+ /**
+ * @return Replaced object.
+ * @throws ObjectStreamException In case of error.
+ */
+ protected Object readResolve() throws ObjectStreamException {
+ return new ResolveTestObject(val * 2);
+ }
+ }
+
+ /**
+ * Test object for {@code readResolve} method.
+ */
+ private static class ResolveTestObject extends ResolveTestBaseObject {
+ /**
+ * @param val Value.
+ */
+ private ResolveTestObject(int val) {
+ super(val);
+ }
+ }
+
+ /**
+ * Class A.
+ */
+ private static class A implements Serializable {
+ /** */
+ private int valA;
+
+ /** */
+ private transient String strA;
+
+ /**
+ * @param valA Value A.
+ * @param strA String A.
+ */
+ A(int valA, String strA) {
+ this.valA = valA;
+ this.strA = strA;
+ }
+
+ /**
+ * @return Value.
+ */
+ int valueA() {
+ return valA;
+ }
+
+ /**
+ * @return String.
+ */
+ String stringA() {
+ return strA;
+ }
+
+ /**
+ * @param out Output stream.
+ * @throws IOException In case of error.
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ out.defaultWriteObject();
+
+ out.writeUTF("Optional data");
+ }
+
+ /**
+ * @param in Input stream.
+ * @throws IOException In case of error.
+ * @throws ClassNotFoundException If class not found.
+ */
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+
+ strA = in.readUTF();
+ }
+ }
+
+ /**
+ * Class B.
+ */
+ private static class B extends A {
+ /** */
+ private int valB;
+
+ /** */
+ @SuppressWarnings("TransientFieldNotInitialized")
+ private transient String strB;
+
+ /**
+ * @param valA Value A.
+ * @param strA String A.
+ * @param valB Value B.
+ * @param strB String B.
+ */
+ B(int valA, String strA, int valB, String strB) {
+ super(valA, strA);
+
+ this.valB = valB;
+ this.strB = strB;
+ }
+
+ /**
+ * @return Value.
+ */
+ int valueB() {
+ return valB;
+ }
+
+ /**
+ * @return String.
+ */
+ String stringB() {
+ return strB;
+ }
+ }
+
+ /**
+ * Class C.
+ */
+ @SuppressWarnings("MethodOverridesPrivateMethodOfSuperclass")
+ private static class C extends B {
+ /** */
+ @SuppressWarnings("InstanceVariableMayNotBeInitializedByReadObject")
+ private int valC;
+
+ /** */
+ private transient String strC;
+
+ /**
+ * @param valA Value A.
+ * @param strA String A.
+ * @param valB Value B.
+ * @param strB String B.
+ * @param valC Value C.
+ * @param strC String C.
+ */
+ C(int valA, String strA, int valB, String strB, int valC, String strC) {
+ super(valA, strA, valB, strB);
+
+ this.valC = valC;
+ this.strC = strC;
+ }
+
+ /**
+ * @return Value.
+ */
+ int valueC() {
+ return valC;
+ }
+
+ /**
+ * @return String.
+ */
+ String stringC() {
+ return strC;
+ }
+
+ /**
+ * @param out Output stream.
+ * @throws IOException In case of error.
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ out.writeUTF("Optional data");
+ }
+
+ /**
+ * @param in Input stream.
+ * @throws IOException In case of error.
+ * @throws ClassNotFoundException If class not found.
+ */
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ strC = in.readUTF();
+ }
+ }
+
+ /**
+ * Complex test object.
+ */
+ private static class ComplexTestObject implements Serializable {
+ /** */
+ private byte byteVal1;
+
+ /** */
+ private short shortVal1;
+
+ /** */
+ private int intVal1;
+
+ /** */
+ private long longVal1;
+
+ /** */
+ private float floatVal1;
+
+ /** */
+ private double doubleVal1;
+
+ /** */
+ private char cVal1;
+
+ /** */
+ private boolean boolVal1;
+
+ /** */
+ private Byte byteVal2;
+
+ /** */
+ private Short shortVal2;
+
+ /** */
+ private Integer intVal2;
+
+ /** */
+ private Long longVal2;
+
+ /** */
+ private Float floatVal2;
+
+ /** */
+ private Double doubleVal2;
+
+ /** */
+ private Character cVal2;
+
+ /** */
+ private Boolean boolVal2;
+
+ /** */
+ private byte[] byteArr;
+
+ /** */
+ private short[] shortArr;
+
+ /** */
+ private int[] intArr;
+
+ /** */
+ private long[] longArr;
+
+ /** */
+ private float[] floatArr;
+
+ /** */
+ private double[] doubleArr;
+
+ /** */
+ private char[] cArr;
+
+ /** */
+ private boolean[] boolArr;
+
+ /** */
+ private ExternalizableTestObject1[] objArr;
+
+ /** */
+ private String str;
+
+ /** */
+ private TestEnum enumVal;
+
+ /** */
+ private UUID uuid;
+
+ /** */
+ private Properties props;
+
+ /** */
+ private ArrayList<Integer> arrList;
+
+ /** */
+ private HashMap<Integer, String> hashMap;
+
+ /** */
+ private HashSet<Integer> hashSet;
+
+ /** */
+ private LinkedList<Integer> linkedList;
+
+ /** */
+ private LinkedHashMap<Integer, String> linkedHashMap;
+
+ /** */
+ private LinkedHashSet<Integer> linkedHashSet;
+
+ /** */
+ private Date date;
+
+ /** */
+ private Class<?> cls;
+
+ /** */
+ private ComplexTestObject self;
+
+ /** */
+ private ComplexTestObject() {
+ self = this;
+ }
+
+ /**
+ * @param byteVal1 Byte value.
+ * @param shortVal1 Short value.
+ * @param intVal1 Integer value.
+ * @param longVal1 Long value.
+ * @param floatVal1 Float value.
+ * @param doubleVal1 Double value.
+ * @param cVal1 Char value.
+ * @param boolVal1 Boolean value.
+ * @param byteVal2 Byte value.
+ * @param shortVal2 Short value.
+ * @param intVal2 Integer value.
+ * @param longVal2 Long value.
+ * @param floatVal2 Float value.
+ * @param doubleVal2 Double value.
+ * @param cVal2 Char value.
+ * @param boolVal2 Boolean value.
+ * @param byteArr Bytes array.
+ * @param shortArr Shorts array.
+ * @param intArr Integers array.
+ * @param longArr Longs array.
+ * @param floatArr Floats array.
+ * @param doubleArr Doubles array.
+ * @param cArr Chars array.
+ * @param boolArr Booleans array.
+ * @param objArr Objects array.
+ * @param str String.
+ * @param enumVal Enum.
+ * @param uuid UUID.
+ * @param props Properties.
+ * @param arrList ArrayList.
+ * @param hashMap HashMap.
+ * @param hashSet HashSet.
+ * @param linkedList LinkedList.
+ * @param linkedHashMap LinkedHashMap.
+ * @param linkedHashSet LinkedHashSet.
+ * @param date Date.
+ * @param cls Class.
+ */
+ private ComplexTestObject(byte byteVal1, short shortVal1, int intVal1, long longVal1, float floatVal1,
+ double doubleVal1, char cVal1, boolean boolVal1, Byte byteVal2, Short shortVal2, Integer intVal2,
+ Long longVal2, Float floatVal2, Double doubleVal2, Character cVal2, Boolean boolVal2, byte[] byteArr,
+ short[] shortArr, int[] intArr, long[] longArr, float[] floatArr, double[] doubleArr, char[] cArr,
+ boolean[] boolArr, ExternalizableTestObject1[] objArr, String str, TestEnum enumVal, UUID uuid,
+ Properties props, ArrayList<Integer> arrList, HashMap<Integer, String> hashMap, HashSet<Integer> hashSet,
+ LinkedList<Integer> linkedList, LinkedHashMap<Integer, String> linkedHashMap,
+ LinkedHashSet<Integer> linkedHashSet, Date date, Class<?> cls) {
+ this.byteVal1 = byteVal1;
+ this.shortVal1 = shortVal1;
+ this.intVal1 = intVal1;
+ this.longVal1 = longVal1;
+ this.floatVal1 = floatVal1;
+ this.doubleVal1 = doubleVal1;
+ this.cVal1 = cVal1;
+ this.boolVal1 = boolVal1;
+ this.byteVal2 = byteVal2;
+ this.shortVal2 = shortVal2;
+ this.intVal2 = intVal2;
+ this.longVal2 = longVal2;
+ this.floatVal2 = floatVal2;
+ this.doubleVal2 = doubleVal2;
+ this.cVal2 = cVal2;
+ this.boolVal2 = boolVal2;
+ this.byteArr = byteArr;
+ this.shortArr = shortArr;
+ this.intArr = intArr;
+ this.longArr = longArr;
+ this.floatArr = floatArr;
+ this.doubleArr = doubleArr;
+ this.cArr = cArr;
+ this.boolArr = boolArr;
+ this.objArr = objArr;
+ this.str = str;
+ this.enumVal = enumVal;
+ this.uuid = uuid;
+ this.props = props;
+ this.arrList = arrList;
+ this.hashMap = hashMap;
+ this.hashSet = hashSet;
+ this.linkedList = linkedList;
+ this.linkedHashMap = linkedHashMap;
+ this.linkedHashSet = linkedHashSet;
+ this.date = date;
+ this.cls = cls;
+
+ self = this;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("RedundantIfStatement")
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ ComplexTestObject obj = (ComplexTestObject)o;
+
+ if (boolVal1 != obj.boolVal1)
+ return false;
+
+ if (byteVal1 != obj.byteVal1)
+ return false;
+
+ if (cVal1 != obj.cVal1)
+ return false;
+
+ if (Double.compare(obj.doubleVal1, doubleVal1) != 0)
+ return false;
+
+ if (Float.compare(obj.floatVal1, floatVal1) != 0)
+ return false;
+
+ if (intVal1 != obj.intVal1)
+ return false;
+
+ if (longVal1 != obj.longVal1)
+ return false;
+
+ if (shortVal1 != obj.shortVal1)
+ return false;
+
+ if (arrList != null ? !arrList.equals(obj.arrList) : obj.arrList != null)
+ return false;
+
+ if (!Arrays.equals(boolArr, obj.boolArr))
+ return false;
+
+ if (boolVal2 != null ? !boolVal2.equals(obj.boolVal2) : obj.boolVal2 != null)
+ return false;
+
+ if (!Arrays.equals(byteArr, obj.byteArr))
+ return false;
+
+ if (byteVal2 != null ? !byteVal2.equals(obj.byteVal2) : obj.byteVal2 != null)
+ return false;
+
+ if (!Arrays.equals(cArr, obj.cArr))
+ return false;
+
+ if (cVal2 != null ? !cVal2.equals(obj.cVal2) : obj.cVal2 != null)
+ return false;
+
+ if (cls != null ? !cls.equals(obj.cls) : obj.cls != null)
+ return false;
+
+ if (date != null ? !date.equals(obj.date) : obj.date != null)
+ return false;
+
+ if (!Arrays.equals(doubleArr, obj.doubleArr))
+ return false;
+
+ if (doubleVal2 != null ? !doubleVal2.equals(obj.doubleVal2) : obj.doubleVal2 != null)
+ return false;
+
+ if (enumVal != obj.enumVal)
+ return false;
+
+ if (!Arrays.equals(floatArr, obj.floatArr))
+ return false;
+
+ if (floatVal2 != null ? !floatVal2.equals(obj.floatVal2) : obj.floatVal2 != null)
+ return false;
+
+ if (hashMap != null ? !hashMap.equals(obj.hashMap) : obj.hashMap != null)
+ return false;
+
+ if (hashSet != null ? !hashSet.equals(obj.hashSet) : obj.hashSet != null)
+ return false;
+
+ if (!Arrays.equals(intArr, obj.intArr))
+ return false;
+
+ if (intVal2 != null ? !intVal2.equals(obj.intVal2) : obj.intVal2 != null)
+ return false;
+
+ if (linkedHashMap != null ? !linkedHashMap.equals(obj.linkedHashMap) : obj.linkedHashMap != null)
+ return false;
+
+ if (linkedHashSet != null ? !linkedHashSet.equals(obj.linkedHashSet) : obj.linkedHashSet != null)
+ return false;
+
+ if (linkedList != null ? !linkedList.equals(obj.linkedList) : obj.linkedList != null)
+ return false;
+
+ if (!Arrays.equals(longArr, obj.longArr))
+ return false;
+
+ if (longVal2 != null ? !longVal2.equals(obj.longVal2) : obj.longVal2 != null)
+ return false;
+
+ if (!Arrays.equals(objArr, obj.objArr))
+ return false;
+
+ if (props != null ? !props.equals(obj.props) : obj.props != null)
+ return false;
+
+ if (!Arrays.equals(shortArr, obj.shortArr))
+ return false;
+
+ if (shortVal2 != null ? !shortVal2.equals(obj.shortVal2) : obj.shortVal2 != null)
+ return false;
+
+ if (str != null ? !str.equals(obj.str) : obj.str != null)
+ return false;
+
+ if (uuid != null ? !uuid.equals(obj.uuid) : obj.uuid != null)
+ return false;
+
+ if (self != this)
+ return false;
+
+ return true;
+ }
+ }
+
+ /**
+ * Test enum.
+ */
+ @SuppressWarnings("JavaDoc")
+ private enum TestEnum {
+ /** */
+ A,
+
+ /** */
+ B,
+
+ /** */
+ C
+ }
+
+ /**
+ * Class with custom serialization method which at the beginning invokes
+ * {@link ObjectOutputStream#defaultWriteObject()} and {@link ObjectOutputStream#putFields()} then.
+ */
+ public static class CustomWriteObjectMethodObject implements Serializable {
+ /** */
+ private final String name;
+
+ /**
+ * Creates new instance.
+ * @param name Object name.
+ */
+ public CustomWriteObjectMethodObject(String name) {
+ this.name = name;
+ }
+
+ /** {@inheritDoc} */
+ private void writeObject(ObjectOutputStream stream) throws IOException {
+ stream.defaultWriteObject();
+
+ ObjectOutputStream.PutField fields = stream.putFields();
+ fields.put("name", "test");
+
+ stream.writeFields();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/TestTcpDiscoveryIpFinderAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/TestTcpDiscoveryIpFinderAdapter.java b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/TestTcpDiscoveryIpFinderAdapter.java
new file mode 100644
index 0000000..fcf1750
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/TestTcpDiscoveryIpFinderAdapter.java
@@ -0,0 +1,43 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.net.InetSocketAddress;
+import java.util.Collection;
+import org.apache.ignite.spi.IgniteSpiException;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter;
+
+/**
+ * Test TCP discovery IP finder adapter.
+ */
+public class TestTcpDiscoveryIpFinderAdapter extends TcpDiscoveryIpFinderAdapter {
+ /** {@inheritDoc} */
+ @Override public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void unregisterAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
+ // No-op.
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStartupInDeploymentModesTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStartupInDeploymentModesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStartupInDeploymentModesTest.java
index 6f65545..d065890 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStartupInDeploymentModesTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStartupInDeploymentModesTest.java
@@ -24,7 +24,7 @@ import org.apache.ignite.configuration.DeploymentMode;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
index 7c05b36..3ff302d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
@@ -33,7 +33,7 @@ import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCach
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.marshaller.MarshallerContext;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
index 38f9d97..ee1c9e5 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
@@ -38,7 +38,7 @@ import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.processors.cache.extras.GridCacheObsoleteEntryExtras;
import org.apache.ignite.internal.processors.cache.store.CacheLocalStore;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheVersionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheVersionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheVersionSelfTest.java
index 8179dc5..9bf1c43 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheVersionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheVersionSelfTest.java
@@ -21,7 +21,7 @@ import java.util.concurrent.Callable;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx;
import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheAffinityEarlyTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheAffinityEarlyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheAffinityEarlyTest.java
index d4e4269..051ca00 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheAffinityEarlyTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheAffinityEarlyTest.java
@@ -29,7 +29,7 @@ import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGetFutureHangsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGetFutureHangsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGetFutureHangsSelfTest.java
index 78cb817..9ee8d69 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGetFutureHangsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheGetFutureHangsSelfTest.java
@@ -32,7 +32,7 @@ import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.T2;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutMultiNodeSelfTest.java
index 0ba2228..3b7fa4f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutMultiNodeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutMultiNodeSelfTest.java
@@ -29,7 +29,7 @@ import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutTest.java
index 97bd202..40440e0 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutTest.java
@@ -27,7 +27,7 @@ import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearTxForceKeyTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearTxForceKeyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearTxForceKeyTest.java
index f5b7635..be8f1bc 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearTxForceKeyTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearTxForceKeyTest.java
@@ -22,7 +22,6 @@ import org.apache.ignite.IgniteCache;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheEntryProcessorNonSerializableTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheEntryProcessorNonSerializableTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheEntryProcessorNonSerializableTest.java
index b462417..b29f2bb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheEntryProcessorNonSerializableTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheEntryProcessorNonSerializableTest.java
@@ -30,7 +30,7 @@ import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.internal.IgniteEx;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractBaseSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractBaseSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractBaseSelfTest.java
index 724bacb..47a768e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractBaseSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractBaseSelfTest.java
@@ -53,7 +53,7 @@ import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.internal.util.typedef.X;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteUuid;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfoSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfoSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfoSelfTest.java
index b2b87dc..47af49b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfoSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfoSelfTest.java
@@ -21,7 +21,7 @@ import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.jetbrains.annotations.Nullable;
import java.io.Externalizable;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java
index 3119f2d..68f68b1 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java
@@ -30,7 +30,7 @@ import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.util.lang.GridAbsPredicate;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgniteCallable;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.apache.ignite.resources.LoggerResource;
import org.apache.ignite.services.Service;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceDeployment2ClassLoadersOptimizedMarshallerTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceDeployment2ClassLoadersOptimizedMarshallerTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceDeployment2ClassLoadersOptimizedMarshallerTest.java
index f2988cc..23a36d1 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceDeployment2ClassLoadersOptimizedMarshallerTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceDeployment2ClassLoadersOptimizedMarshallerTest.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.processors.service;
import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
/**
* Tests that not all nodes in cluster need user's service definition (only nodes according to filter).
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceDeploymentClassLoadingOptimizedMarshallerTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceDeploymentClassLoadingOptimizedMarshallerTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceDeploymentClassLoadingOptimizedMarshallerTest.java
index cb0c911..930c6ed 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceDeploymentClassLoadingOptimizedMarshallerTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceDeploymentClassLoadingOptimizedMarshallerTest.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.processors.service;
import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
/**
* Tests that not all nodes in cluster need user's service definition (only nodes according to filter).
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/marshaller/DynamicProxySerializationMultiJvmSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/DynamicProxySerializationMultiJvmSelfTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/DynamicProxySerializationMultiJvmSelfTest.java
index f75af03..3e1e6f7 100644
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/DynamicProxySerializationMultiJvmSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/marshaller/DynamicProxySerializationMultiJvmSelfTest.java
@@ -26,7 +26,7 @@ import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.lang.IgniteCallable;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/marshaller/GridMarshallerPerformanceTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/GridMarshallerPerformanceTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/GridMarshallerPerformanceTest.java
index a9d0f66..3b45977 100644
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/GridMarshallerPerformanceTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/marshaller/GridMarshallerPerformanceTest.java
@@ -43,7 +43,7 @@ import org.apache.ignite.internal.util.typedef.COX;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteInClosure;
import org.apache.ignite.lang.IgniteOutClosure;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerEnumSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerEnumSelfTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerEnumSelfTest.java
deleted file mode 100644
index c072170..0000000
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerEnumSelfTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.optimized;
-
-import junit.framework.TestCase;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.testframework.junits.GridTestKernalContext;
-import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger;
-
-/**
- *
- */
-public class OptimizedMarshallerEnumSelfTest extends TestCase {
-
- private String igniteHome = System.getProperty("user.dir");
-
- private final IgniteLogger rootLog = new GridTestLog4jLogger(false);
- /**
- * @throws Exception If failed.
- */
- public void testEnumSerialisation() throws Exception {
- OptimizedMarshaller marsh = new OptimizedMarshaller();
-
- MarshallerContextTestImpl context = new MarshallerContextTestImpl();
-
- context.onMarshallerProcessorStarted(newContext(), null);
-
- marsh.setContext(context);
-
- byte[] bytes = marsh.marshal(TestEnum.Bond);
-
- TestEnum unmarshalled = marsh.unmarshal(bytes, Thread.currentThread().getContextClassLoader());
-
- assertEquals(TestEnum.Bond, unmarshalled);
- assertEquals(TestEnum.Bond.desc, unmarshalled.desc);
- }
-
- private GridKernalContext newContext() throws IgniteCheckedException {
- IgniteConfiguration cfg = new IgniteConfiguration();
-
- cfg.setIgniteHome(igniteHome);
- cfg.setClientMode(false);
-
- return new GridTestKernalContext(rootLog.getLogger(OptimizedMarshallerEnumSelfTest.class), cfg);
- }
-
- private enum TestEnum {
- Equity("Equity") {
- @Override public String getTestString() {
- return "eee";
- }
- },
-
- Bond("Bond") {
- @Override public String getTestString() {
- return "qqq";
- }
- };
-
- public final String desc;
-
- TestEnum(String desc) {
- this.desc = desc;
- }
-
- public abstract String getTestString();
- }
-}
\ No newline at end of file
[05/10] ignite git commit: IGNITE-4938: Moved OptimizedMarshaller to
private package. This closes #1793.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerEnumSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerEnumSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerEnumSelfTest.java
new file mode 100644
index 0000000..c7a58f7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerEnumSelfTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.marshaller.optimized;
+
+import junit.framework.TestCase;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.testframework.junits.GridTestKernalContext;
+import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger;
+
+/**
+ *
+ */
+public class OptimizedMarshallerEnumSelfTest extends TestCase {
+
+ private String igniteHome = System.getProperty("user.dir");
+
+ private final IgniteLogger rootLog = new GridTestLog4jLogger(false);
+ /**
+ * @throws Exception If failed.
+ */
+ public void testEnumSerialisation() throws Exception {
+ OptimizedMarshaller marsh = new OptimizedMarshaller();
+
+ MarshallerContextTestImpl context = new MarshallerContextTestImpl();
+
+ context.onMarshallerProcessorStarted(newContext(), null);
+
+ marsh.setContext(context);
+
+ byte[] bytes = marsh.marshal(TestEnum.Bond);
+
+ TestEnum unmarshalled = marsh.unmarshal(bytes, Thread.currentThread().getContextClassLoader());
+
+ assertEquals(TestEnum.Bond, unmarshalled);
+ assertEquals(TestEnum.Bond.desc, unmarshalled.desc);
+ }
+
+ private GridKernalContext newContext() throws IgniteCheckedException {
+ IgniteConfiguration cfg = new IgniteConfiguration();
+
+ cfg.setIgniteHome(igniteHome);
+ cfg.setClientMode(false);
+
+ return new GridTestKernalContext(rootLog.getLogger(OptimizedMarshallerEnumSelfTest.class), cfg);
+ }
+
+ private enum TestEnum {
+ Equity("Equity") {
+ @Override public String getTestString() {
+ return "eee";
+ }
+ },
+
+ Bond("Bond") {
+ @Override public String getTestString() {
+ return "qqq";
+ }
+ };
+
+ public final String desc;
+
+ TestEnum(String desc) {
+ this.desc = desc;
+ }
+
+ public abstract String getTestString();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerNodeFailoverTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerNodeFailoverTest.java b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerNodeFailoverTest.java
new file mode 100644
index 0000000..f842b5f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerNodeFailoverTest.java
@@ -0,0 +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.internal.marshaller.optimized;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class OptimizedMarshallerNodeFailoverTest extends GridCommonAbstractTest {
+ /** */
+ private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private boolean cache;
+
+ /** */
+ private String workDir;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+ disco.setIpFinder(ipFinder);
+
+ cfg.setDiscoverySpi(disco);
+
+ cfg.setMarshaller(new OptimizedMarshaller());
+
+ cfg.setWorkDirectory(workDir);
+
+ if (cache) {
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setCacheMode(PARTITIONED);
+ ccfg.setBackups(1);
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+ cfg.setCacheConfiguration(ccfg);
+ }
+ else
+ cfg.setClientMode(true);
+
+ return cfg;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClassCacheUpdateFailover1() throws Exception {
+ classCacheUpdateFailover(false);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClassCacheUpdateFailover2() throws Exception {
+ classCacheUpdateFailover(true);
+ }
+
+ /**
+ * @param stopSrv If {@code true} restarts server node, otherwise client node.
+ * @throws Exception If failed.
+ */
+ private void classCacheUpdateFailover(boolean stopSrv) throws Exception {
+ cache = true;
+
+ startGridsMultiThreaded(2);
+
+ cache = stopSrv;
+
+ IgniteCache<Integer, Object> cache0 = ignite(0).cache(null);
+
+ for (int i = 0; i < 20; i++) {
+ log.info("Iteration: " + i);
+
+ Map<Integer, Object> map = new HashMap<>();
+
+ for (int j = 0; j < 10_000; j++)
+ map.put(j, create(i + 1));
+
+ final Ignite ignite = startGrid(2);
+
+ IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable() {
+ @Override public Object call() throws Exception {
+ ignite.close();
+
+ return null;
+ }
+ });
+
+ cache0.putAll(map);
+
+ fut.get();
+ }
+
+ cache = true;
+
+ Ignite ignite = startGrid(2); // Check can start one more cache node.
+
+ assertNotNull(ignite.cache(null));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testRestartAllNodes() throws Exception {
+ cache = true;
+
+ String home = U.getIgniteHome();
+
+ String[] workDirs = new String[3];
+
+ for (int i = 0; i < 3; i++) {
+ workDirs[i] = home + "/work/marshallerTestNode_" + i;
+
+ File file = new File(workDirs[i]);
+
+ if (file.exists())
+ assert U.delete(file);
+ }
+
+ try {
+ for (int i = 0; i < workDirs.length; i++) {
+ workDir = workDirs[i];
+
+ startGrid(i);
+ }
+
+ Marshaller marsh = ignite(0).configuration().getMarshaller();
+
+ TestClass1 obj = new TestClass1();
+
+ obj.val = 111;
+
+ byte[] bytes = marsh.marshal(obj);
+
+ stopAllGrids();
+
+ for (int i = 0; i < workDirs.length; i++) {
+ workDir = workDirs[i];
+
+ startGrid(i);
+ }
+
+ for (int i = 0; i < 3; i++) {
+ marsh = ignite(i).configuration().getMarshaller();
+
+ TestClass1 obj0 = marsh.unmarshal(bytes, null);
+
+ assertEquals(111, obj0.val);
+ }
+ }
+ finally {
+ for (String dir : workDirs)
+ assert U.delete(new File(dir));
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+ }
+
+ /**
+ * @param id Class ID.
+ * @return Test class instance.
+ */
+ private static Object create(int id) {
+ switch (id) {
+ case 1: return new TestClass1();
+
+ case 2: return new TestClass2();
+
+ case 3: return new TestClass3();
+
+ case 4: return new TestClass4();
+
+ case 5: return new TestClass5();
+
+ case 6: return new TestClass6();
+
+ case 7: return new TestClass7();
+
+ case 8: return new TestClass8();
+
+ case 9: return new TestClass9();
+
+ case 10: return new TestClass10();
+
+ case 11: return new TestClass11();
+
+ case 12: return new TestClass12();
+
+ case 13: return new TestClass13();
+
+ case 14: return new TestClass14();
+
+ case 15: return new TestClass15();
+
+ case 16: return new TestClass16();
+
+ case 17: return new TestClass17();
+
+ case 18: return new TestClass18();
+
+ case 19: return new TestClass19();
+
+ case 20: return new TestClass20();
+ }
+
+ fail();
+
+ return null;
+ }
+
+ /**
+ *
+ */
+ static class TestClass1 implements Serializable {
+ /** */
+ int val;
+ }
+
+ /**
+ *
+ */
+ static class TestClass2 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass3 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass4 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass5 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass6 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass7 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass8 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass9 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass10 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass11 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass12 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass13 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass14 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass15 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass16 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass17 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass18 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass19 implements Serializable {}
+
+ /**
+ *
+ */
+ static class TestClass20 implements Serializable {}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerPooledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerPooledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerPooledSelfTest.java
new file mode 100644
index 0000000..02954f9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerPooledSelfTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.marshaller.optimized;
+
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerSelfTest;
+import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+
+/**
+ * Optimized marshaller self test.
+ */
+@GridCommonTest(group = "Marshaller")
+public class OptimizedMarshallerPooledSelfTest extends OptimizedMarshallerSelfTest {
+ /** {@inheritDoc} */
+ @Override protected Marshaller marshaller() {
+ OptimizedMarshaller m = new OptimizedMarshaller(false);
+
+ m.setPoolSize(8);
+
+ return m;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ super.afterTestsStopped();
+
+ // Reset static registry.
+ new OptimizedMarshaller().setPoolSize(0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerSelfTest.java
new file mode 100644
index 0000000..fa95abc
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerSelfTest.java
@@ -0,0 +1,284 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.concurrent.Callable;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.marshaller.GridMarshallerAbstractTest;
+import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+
+/**
+ * Optimized marshaller self test.
+ */
+@GridCommonTest(group = "Marshaller")
+public class OptimizedMarshallerSelfTest extends GridMarshallerAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected Marshaller marshaller() {
+ return new OptimizedMarshaller(false);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTestMarshalling() throws Exception {
+ final String msg = "PASSED";
+
+ byte[] buf = marshal(new IgniteRunnable() {
+ @Override public void run() {
+ c1.apply(msg);
+ c2.apply(msg);
+
+ c3.apply();
+ c4.reduce();
+
+ System.out.println("Test message: " + msg);
+ }
+ });
+
+ Runnable r = unmarshal(buf);
+
+ assertNotNull(r);
+
+ r.run();
+ }
+
+ /**
+ * Tests marshal self-linked object.
+ *
+ * @throws IgniteCheckedException If marshalling failed.
+ */
+ public void testMarshallingSelfLink() throws IgniteCheckedException {
+ SelfLink sl = new SelfLink("a string 1");
+
+ sl.link(sl);
+
+ SelfLink sl1 = unmarshal(marshal(sl));
+
+ assert sl1.link() == sl1;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testInvalid() throws Exception {
+ GridTestUtils.assertThrows(
+ log,
+ new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ byte[] arr = new byte[10];
+
+ arr[0] = (byte)200;
+
+ unmarshal(arr);
+
+ return null;
+ }
+ },
+ IgniteCheckedException.class,
+ null
+ );
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testNested() throws Exception {
+ NestedTestObject obj = new NestedTestObject("String", 100);
+
+ NestedTestObject newObj = unmarshal(marshal(obj));
+
+ assertEquals("String", newObj.str);
+ assertEquals(100, newObj.val);
+ }
+
+ /**
+ * Class for nested execution test.
+ */
+ private static class NestedTestObject implements Serializable {
+ /** */
+ private String str;
+
+ /** */
+ private int val;
+
+ /**
+ * @param str String.
+ * @param val Value.
+ */
+ private NestedTestObject(String str, int val) {
+ this.str = str;
+ this.val = val;
+ }
+
+ /** {@inheritDoc} */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ try {
+ byte[] arr = marshal(str);
+
+ out.writeInt(arr.length);
+ out.write(arr);
+
+ out.writeInt(val);
+ }
+ catch (IgniteCheckedException e) {
+ throw new IOException(e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("UnusedParameters")
+ private void readObject(ObjectInputStream in) throws IOException {
+ try {
+ byte[] arr = new byte[in.readInt()];
+
+ in.read(arr);
+
+ str = unmarshal(arr);
+
+ val = in.readInt();
+ }
+ catch (IgniteCheckedException e) {
+ throw new IOException(e);
+ }
+ }
+ }
+
+ /** */
+ private static class TestObject2 {
+ /** */
+ private final int i;
+
+ /**
+ * Constructor for TestObject2 instances.
+ *
+ * @param i Integer value to hold.
+ */
+ private TestObject2(int i) {
+ this.i = i;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ return i == ((TestObject2)o).i;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return i;
+ }
+ }
+
+ /**
+ * Static nested class.
+ */
+ private static class TestObject {
+ /** */
+ private final TestObject2 o2;
+
+ /** The only meaningful field in the class, used for {@link #equals(Object o)} and {@link #hashCode()}. */
+ private final String str;
+
+ /**
+ * @param str String to hold.
+ * @param i Integer.
+ */
+ TestObject(String str, int i) {
+ this.str = str;
+
+ o2 = new TestObject2(i);
+ }
+
+ /**
+ * Method for accessing value of the hold string after the object is created.
+ *
+ * @return Wrapped string.
+ */
+ public String string() {
+ return str;
+ }
+
+ /**
+ * @return Object held in this wrapped.
+ */
+ public TestObject2 obj() {
+ return o2;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return 31 * o2.hashCode() + str.hashCode();
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("RedundantIfStatement")
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestObject obj = (TestObject)o;
+
+ if (o2 != null ? !o2.equals(obj.o2) : obj.o2 != null)
+ return false;
+
+ if (str != null ? !str.equals(obj.str) : obj.str != null)
+ return false;
+
+ return true;
+ }
+ }
+
+ /**
+ * Static nested class.
+ */
+ private static class SelfLink extends TestObject {
+ /** */
+ private SelfLink link;
+
+ /**
+ * @param str String to hold.
+ */
+ SelfLink(String str) {
+ super(str, 1);
+ }
+
+ /**
+ * @return The object this link points to,.
+ */
+ public SelfLink link() {
+ return link;
+ }
+
+ /**
+ * @param link The object this link should points to,
+ */
+ public void link(SelfLink link) {
+ this.link = link;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerSerialPersistentFieldsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerSerialPersistentFieldsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerSerialPersistentFieldsSelfTest.java
new file mode 100644
index 0000000..5a9d10c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerSerialPersistentFieldsSelfTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
+
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.marshaller.GridMarshallerAbstractTest;
+import org.apache.ignite.marshaller.Marshaller;
+
+/**
+ * Test that Optimized Marshaller works with classes with serialPersistentFields.
+ */
+public class OptimizedMarshallerSerialPersistentFieldsSelfTest extends GridMarshallerAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected Marshaller marshaller() {
+ return new OptimizedMarshaller(false);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testOptimizedMarshaller() throws Exception {
+ unmarshal(marshal(new TestClass()));
+
+ TestClass2 val = unmarshal(marshal(new TestClass2()));
+
+ assertNull(val.field3);
+ }
+
+ /**
+ * Test class with serialPersistentFields fields.
+ */
+ private static class TestClass implements Serializable {
+ private static final long serialVersionUID = 0L;
+
+ /** For serialization compatibility. */
+ private static final ObjectStreamField[] serialPersistentFields = {
+ new ObjectStreamField("field1", Integer.TYPE),
+ new ObjectStreamField("field2", Integer.TYPE)
+ };
+
+ /**
+ * @param s Object output stream.
+ */
+ private void writeObject(ObjectOutputStream s) throws IOException {
+ s.putFields().put("field1", 1);
+ s.putFields().put("field2", 2);
+ s.writeFields();
+
+ s.writeObject(null);
+ }
+
+ /**
+ * @param s Object input stream.
+ */
+ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
+ s.defaultReadObject();
+
+ s.readObject();
+ }
+ }
+
+ /**
+ * Test class with serialPersistentFields fields.
+ */
+ private static class TestClass2 implements Serializable {
+ private static final long serialVersionUID = 0L;
+
+ private Integer field3 = 1;
+
+ /** For serialization compatibility. */
+ private static final ObjectStreamField[] serialPersistentFields = {
+ new ObjectStreamField("field1", Integer.TYPE),
+ new ObjectStreamField("field2", Integer.TYPE)
+ };
+
+ /**
+ * @param s Object output stream.
+ */
+ private void writeObject(ObjectOutputStream s) throws IOException {
+ s.putFields().put("field1", 1);
+ s.putFields().put("field2", 2);
+ s.writeFields();
+
+ s.writeObject(null);
+ }
+
+ /**
+ * @param s Object input stream.
+ */
+ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
+ s.defaultReadObject();
+
+ s.readObject();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerTest.java b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerTest.java
new file mode 100644
index 0000000..2698042
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerTest.java
@@ -0,0 +1,790 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.concurrent.ConcurrentMap;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.GridMarshallerTestInheritedBean;
+import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ *
+ */
+public class OptimizedMarshallerTest extends GridCommonAbstractTest {
+ /**
+ * @return Marshaller.
+ */
+ private OptimizedMarshaller marshaller() {
+ U.clearClassCache();
+
+ OptimizedMarshaller marsh = new OptimizedMarshaller();
+
+ marsh.setContext(new MarshallerContextTestImpl());
+
+ return marsh;
+ }
+
+ /**
+ * Tests ability to marshal non-serializable objects.
+ *
+ * @throws IgniteCheckedException If marshalling failed.
+ */
+ public void testNonSerializable() throws IgniteCheckedException {
+ OptimizedMarshaller marsh = marshaller();
+
+ marsh.setRequireSerializable(false);
+
+ NonSerializable outObj = marsh.unmarshal(marsh.marshal(new NonSerializable(null)), null);
+
+ outObj.checkAfterUnmarshalled();
+ }
+
+ /**
+ * Tests ability to marshal non-serializable objects.
+ *
+ * @throws IgniteCheckedException If marshalling failed.
+ */
+ public void testNonSerializable1() throws IgniteCheckedException {
+ OptimizedMarshaller marsh = marshaller();
+
+ marsh.setRequireSerializable(false);
+
+ byte[] bytes = marsh.marshal(new TcpDiscoveryVmIpFinder());
+
+ TcpDiscoveryIpFinder ipFinder = marsh.unmarshal(bytes, null);
+
+ assertFalse(ipFinder.isShared());
+
+ ipFinder = marsh.unmarshal(marsh.marshal(new TcpDiscoveryVmIpFinder(true)), null);
+
+ assertTrue(ipFinder.isShared());
+ }
+
+ /**
+ * Tests ability to marshal non-serializable objects.
+ *
+ * @throws IgniteCheckedException If marshalling failed.
+ */
+ public void testNonSerializable2() throws IgniteCheckedException {
+ OptimizedMarshaller marsh = marshaller();
+
+ marsh.setRequireSerializable(false);
+
+ TcpDiscoveryIpFinderAdapter ipFinder = new TcpDiscoveryIpFinderAdapter() {
+ @Override public Collection<InetSocketAddress> getRegisteredAddresses() {
+ return null;
+ }
+
+ @Override public void registerAddresses(Collection<InetSocketAddress> addrs) {
+ //No-op.
+ }
+
+ @Override public void unregisterAddresses(Collection<InetSocketAddress> addrs) {
+ //No-op.
+ }
+ };
+
+ ipFinder.setShared(false);
+
+ byte[] bytes = marsh.marshal(ipFinder);
+
+ ipFinder = marsh.unmarshal(bytes, null);
+
+ assertFalse(ipFinder.isShared());
+ }
+
+ /**
+ * Tests ability to marshal non-serializable objects.
+ *
+ * @throws IgniteCheckedException If marshalling failed.
+ */
+ public void testNonSerializable3() throws IgniteCheckedException {
+ OptimizedMarshaller marsh = marshaller();
+
+ marsh.setRequireSerializable(false);
+
+ byte[] bytes = marsh.marshal(new TestTcpDiscoveryIpFinderAdapter());
+
+ TcpDiscoveryIpFinder ipFinder = marsh.unmarshal(bytes, null);
+
+ assertFalse(ipFinder.isShared());
+ }
+
+ /**
+ * Tests ability to marshal non-serializable objects.
+ *
+ * @throws IgniteCheckedException If marshalling failed.
+ */
+ public void testNonSerializable4() throws IgniteCheckedException {
+ OptimizedMarshaller marsh = marshaller();
+
+ marsh.setRequireSerializable(false);
+
+ byte[] bytes = marsh.marshal(new GridMarshallerTestInheritedBean());
+
+ info(Arrays.toString(bytes));
+
+ GridMarshallerTestInheritedBean bean = marsh.unmarshal(bytes, null);
+
+ assertTrue(bean.isFlag());
+ }
+
+ /**
+ * Tests ability to marshal non-serializable objects.
+ *
+ * @throws IgniteCheckedException If marshalling failed.
+ */
+ public void testNonSerializable5() throws IgniteCheckedException {
+ Marshaller marsh = marshaller();
+
+ byte[] bytes = marsh.marshal(true);
+
+ Boolean val = marsh.unmarshal(bytes, null);
+
+ assertTrue(val);
+ }
+
+ /**
+ * Tests ability to marshal serializable objects.
+ *
+ * @throws IgniteCheckedException If marshalling failed.
+ */
+ public void testSerializable() throws IgniteCheckedException {
+ Marshaller marsh = marshaller();
+
+ SomeSerializable outObj = marsh.unmarshal(marsh.marshal(new SomeSerializable(null)), null);
+
+ outObj.checkAfterUnmarshalled();
+ }
+
+ /**
+ * @throws IgniteCheckedException If failed.
+ */
+ public void testSerializableAfterChangingValue() throws IgniteCheckedException {
+ Marshaller marsh = marshaller();
+
+ SomeSimpleSerializable newObj = new SomeSimpleSerializable();
+
+ assert(newObj.flag);
+
+ newObj.setFlagValue(false);
+
+ assert(! newObj.flag);
+
+ SomeSimpleSerializable outObj = marsh.unmarshal(marsh.marshal(newObj), null);
+
+ assert (! outObj.flag);
+ }
+
+ /**
+ * Tests ability to marshal externalizable objects.
+ *
+ * @throws IgniteCheckedException If marshalling failed.
+ */
+ public void testExternalizable() throws IgniteCheckedException {
+ Marshaller marsh = marshaller();
+
+ ExternalizableA outObj = marsh.unmarshal(marsh.marshal(new ExternalizableA(null, true)), null);
+ ExternalizableA outObj1 = marsh.unmarshal(marsh.marshal(new ExternalizableA(null, false)), null);
+
+ assertNotNull(outObj);
+ assertNotNull(outObj1);
+ }
+
+ /**
+ * Tests {@link OptimizedMarshaller#setRequireSerializable(boolean)}.
+ */
+ public void testRequireSerializable() {
+ OptimizedMarshaller marsh = marshaller();
+
+ marsh.setRequireSerializable(true);
+
+ try {
+ marsh.marshal(new NonSerializable(null));
+
+ fail();
+ }
+ catch (IgniteCheckedException ignore) {
+ // No-op.
+ }
+ }
+
+ /**
+ * Tests {@link Proxy}.
+ *
+ * @throws IgniteCheckedException If marshalling failed.
+ */
+ public void testProxy() throws IgniteCheckedException {
+ OptimizedMarshaller marsh = marshaller();
+
+ marsh.setRequireSerializable(false);
+
+ SomeItf inItf = (SomeItf)Proxy.newProxyInstance(
+ OptimizedMarshallerTest.class.getClassLoader(), new Class[] {SomeItf.class},
+ new InvocationHandler() {
+ private NonSerializable obj = new NonSerializable(null);
+
+ @Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable {
+ obj.checkAfterUnmarshalled();
+
+ return 17;
+ }
+ }
+ );
+
+ SomeItf outItf = marsh.unmarshal(marsh.marshal(inItf), null);
+
+ assertEquals(outItf.checkAfterUnmarshalled(), 17);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDescriptorCache() throws Exception {
+ try {
+ Ignite ignite = startGridsMultiThreaded(2);
+
+ String taskClsName = "org.apache.ignite.tests.p2p.SingleSplitTestTask";
+ String jobClsName = "org.apache.ignite.tests.p2p.SingleSplitTestTask$SingleSplitTestJob";
+
+ ClassLoader ldr = getExternalClassLoader();
+
+ Class<? extends ComputeTask<?, ?>> taskCls = (Class<? extends ComputeTask<?, ?>>)ldr.loadClass(taskClsName);
+ Class<? extends ComputeTask<?, ?>> jobCls = (Class<? extends ComputeTask<?, ?>>)ldr.loadClass(jobClsName);
+
+ ignite.compute().localDeployTask(taskCls, ldr);
+
+ ignite.compute().execute(taskClsName, 2);
+
+ ConcurrentMap<Class<?>, OptimizedClassDescriptor> cache =
+ U.field(ignite.configuration().getMarshaller(), "clsMap");
+
+ assertTrue(cache.containsKey(jobCls));
+
+ ignite.compute().undeployTask(taskClsName);
+
+ // Wait for undeploy.
+ Thread.sleep(1000);
+
+ assertFalse(cache.containsKey(jobCls));
+ }
+ finally {
+ stopAllGrids();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPerformance() throws Exception {
+ System.gc();
+
+ checkPerformance(10000, 4);
+ }
+
+ /**
+ * @param cnt Number of marshalling attempts.
+ * @param tries Number of retries.
+ * @throws Exception If failed.
+ */
+ private void checkPerformance(int cnt, int tries) throws Exception {
+ Marshaller marsh = marshaller();
+
+ for (int j = 0; j < tries; j++) {
+ System.gc();
+
+ long start = System.currentTimeMillis();
+
+ for (int i = 0; i < cnt; i++) {
+ TestCacheKey key = new TestCacheKey("key", "id");
+
+ TestCacheKey outKey = marsh.unmarshal(marsh.marshal(key), null);
+
+ assert key.equals(outKey);
+ assert key.hashCode() == outKey.hashCode();
+ }
+
+ info("Time non-serializable: " + (System.currentTimeMillis() - start));
+
+ System.gc();
+
+ start = System.currentTimeMillis();
+
+ for (int i = 0; i < cnt; i++) {
+ TestCacheKeySerializable key1 = new TestCacheKeySerializable("key", "id");
+
+ TestCacheKeySerializable outKey = marsh.unmarshal(marsh.marshal(key1), null);
+
+ assert key1.equals(outKey);
+ assert key1.hashCode() == outKey.hashCode();
+ }
+
+ info("Time serializable: " + (System.currentTimeMillis() - start));
+
+ System.gc();
+
+ start = System.currentTimeMillis();
+
+ for (int i = 0; i < cnt; i++) {
+ TestCacheKeyExternalizable key2 = new TestCacheKeyExternalizable("key", "id");
+
+ TestCacheKeyExternalizable outKey = marsh.unmarshal(marsh.marshal(key2), null);
+
+ assert key2.equals(outKey);
+ assert key2.hashCode() == outKey.hashCode();
+ }
+
+ info("Time externalizable: " + (System.currentTimeMillis() - start));
+
+ info(">>>");
+ }
+
+ info(">>> Finished performance check <<<");
+ }
+
+ /**
+ * Some non-serializable class.
+ */
+ @SuppressWarnings( {"PublicField","TransientFieldInNonSerializableClass","FieldMayBeStatic"})
+ private static class NonSerializableA {
+ /** */
+ private final long longVal = 0x33445566778899AAL;
+
+ /** */
+ protected Short shortVal = (short)0xAABB;
+
+ /** */
+ public String[] strArr = {"AA","BB"};
+
+ /** */
+ public boolean flag1 = true;
+
+ /** */
+ public boolean flag2;
+
+ /** */
+ public Boolean flag3;
+
+ /** */
+ public Boolean flag4 = true;
+
+ /** */
+ public Boolean flag5 = false;
+
+ /** */
+ private transient int intVal = 0xAABBCCDD;
+
+ /**
+ * @param strArr Array.
+ * @param shortVal Short value.
+ */
+ @SuppressWarnings( {"UnusedDeclaration"})
+ private NonSerializableA(@Nullable String[] strArr, @Nullable Short shortVal) {
+ // No-op.
+ }
+
+ /**
+ * Checks correctness of the state after unmarshalling.
+ */
+ void checkAfterUnmarshalled() {
+ assertEquals(longVal, 0x33445566778899AAL);
+
+ assertEquals(shortVal.shortValue(), (short)0xAABB);
+
+ assertTrue(Arrays.equals(strArr, new String[] {"AA","BB"}));
+
+ assertEquals(intVal, 0);
+
+ assertTrue(flag1);
+ assertFalse(flag2);
+ assertNull(flag3);
+ assertTrue(flag4);
+ assertFalse(flag5);
+ }
+ }
+
+ /**
+ * Some non-serializable class.
+ */
+ @SuppressWarnings( {"PublicField","TransientFieldInNonSerializableClass","PackageVisibleInnerClass"})
+ static class NonSerializableB extends NonSerializableA {
+ /** */
+ public Short shortVal = 0x1122;
+
+ /** */
+ public long longVal = 0x8877665544332211L;
+
+ /** */
+ private transient NonSerializableA[] aArr = {
+ new NonSerializableA(null, null),
+ new NonSerializableA(null, null),
+ new NonSerializableA(null, null)
+ };
+
+ /** */
+ protected Double doubleVal = 123.456;
+
+ /**
+ * Just to eliminate the default constructor.
+ */
+ private NonSerializableB() {
+ super(null, null);
+ }
+
+ /**
+ * Checks correctness of the state after unmarshalling.
+ */
+ @Override void checkAfterUnmarshalled() {
+ super.checkAfterUnmarshalled();
+
+ assertEquals(shortVal.shortValue(), 0x1122);
+
+ assertEquals(longVal, 0x8877665544332211L);
+
+ assertNull(aArr);
+
+ assertEquals(doubleVal, 123.456);
+ }
+ }
+
+ /**
+ * Some non-serializable class.
+ */
+ @SuppressWarnings( {"TransientFieldInNonSerializableClass","PublicField"})
+ private static class NonSerializable extends NonSerializableB {
+ /** */
+ private int idVal = -17;
+
+ /** */
+ private final NonSerializableA aVal = new NonSerializableB();
+
+ /** */
+ private transient NonSerializableB bVal = new NonSerializableB();
+
+ /** */
+ private NonSerializableA[] bArr = new NonSerializableA[] {
+ new NonSerializableB(),
+ new NonSerializableA(null, null)
+ };
+
+ /** */
+ public float floatVal = 567.89F;
+
+ /**
+ * Just to eliminate the default constructor.
+ *
+ * @param aVal Unused.
+ */
+ @SuppressWarnings( {"UnusedDeclaration"})
+ private NonSerializable(NonSerializableA aVal) {
+ }
+
+ /**
+ * Checks correctness of the state after unmarshalling.
+ */
+ @Override void checkAfterUnmarshalled() {
+ super.checkAfterUnmarshalled();
+
+ assertEquals(idVal, -17);
+
+ aVal.checkAfterUnmarshalled();
+
+ assertNull(bVal);
+
+ for (NonSerializableA a : bArr) {
+ a.checkAfterUnmarshalled();
+ }
+
+ assertEquals(floatVal, 567.89F);
+ }
+ }
+
+ /**
+ * Some serializable class.
+ */
+ @SuppressWarnings( {"PublicField","TransientFieldInNonSerializableClass","PackageVisibleInnerClass"})
+ static class ForSerializableB {
+ /** */
+ public Short shortVal = 0x1122;
+
+ /** */
+ public long longVal = 0x8877665544332211L;
+
+ /** */
+ private transient NonSerializableA[] aArr;
+
+ /** */
+ private transient String strVal = "abc";
+
+ /** */
+ protected Double doubleVal = 123.456;
+
+ /**
+ */
+ protected void init() {
+ shortVal = 0x1122;
+
+ longVal = 0x8877665544332211L;
+
+ aArr = new NonSerializableA[] {
+ new NonSerializableA(null, null),
+ new NonSerializableA(null, null),
+ new NonSerializableA(null, null)
+ };
+ }
+
+ /**
+ * Checks correctness of the state after unmarshalling.
+ */
+ void checkAfterUnmarshalled() {
+ assertEquals(shortVal.shortValue(), 0x1122);
+
+ assertEquals(longVal, 0x8877665544332211L);
+
+ assertNull(aArr);
+
+ assertNull(strVal);
+
+ assertEquals(doubleVal, 123.456);
+ }
+ }
+
+ /**
+ * Some serializable class.
+ */
+ private static class SomeSimpleSerializable extends ComputeJobAdapter {
+ /** */
+ private boolean flag = true;
+
+ /**
+ * @param newFlagVal - The new value of flag field.
+ */
+ public void setFlagValue(boolean newFlagVal) {
+ flag = newFlagVal;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object execute() {
+ assert false;
+
+ return null;
+ }
+ }
+ /**
+ * Some serializable class.
+ */
+ private static class SomeSerializable extends ForSerializableB implements Serializable {
+ /**
+ * Just to eliminate the default constructor.
+ *
+ * @param id Unused.
+ */
+ @SuppressWarnings( {"UnusedDeclaration"})
+ private SomeSerializable(Long id) {
+ init();
+ }
+ }
+
+ /**
+ */
+ private static interface SomeItf {
+ /**
+ * @return Check result.
+ */
+ int checkAfterUnmarshalled();
+ }
+
+ /**
+ * Some externalizable class.
+ */
+ @SuppressWarnings( {"UnusedDeclaration", "PublicField"})
+ private static class ExternalizableA implements Externalizable {
+ /** */
+ private boolean boolVal;
+
+ /** */
+ public String[] strArr;
+
+ /** No-arg constructor is required by externalization. */
+ public ExternalizableA() {
+ // No-op.
+ }
+
+ /**
+ *
+ * @param strArr String array.
+ * @param boolVal Boolean value.
+ */
+ private ExternalizableA(String[] strArr, boolean boolVal) {
+ this.strArr = strArr;
+ this.boolVal = boolVal;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeBoolean(false);
+ out.writeBoolean(false);
+ out.writeBoolean(false);
+ out.writeBoolean(false);
+ out.writeBoolean(false);
+ out.writeBoolean(false);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ boolVal = in.readBoolean();
+ in.readBoolean();
+ in.readBoolean();
+ in.readBoolean();
+ in.readBoolean();
+ in.readBoolean();
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestCacheKey implements Serializable {
+ /** */
+ private String key;
+
+ /** */
+ @SuppressWarnings({"UnusedDeclaration"})
+ private String terminalId;
+
+ /**
+ * @param key Key.
+ * @param terminalId Some ID.
+ */
+ TestCacheKey(String key, String terminalId) {
+ this.key = key;
+ this.terminalId = terminalId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return key.hashCode();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return obj instanceof TestCacheKey && key.equals(((TestCacheKey)obj).key);
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestCacheKeySerializable implements Serializable {
+ /** */
+ private String key;
+
+ /** */
+ @SuppressWarnings({"UnusedDeclaration"})
+ private String terminalId;
+
+ /**
+ * @param key Key.
+ * @param terminalId Some ID.
+ */
+ TestCacheKeySerializable(String key, String terminalId) {
+ this.key = key;
+ this.terminalId = terminalId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return key.hashCode();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return obj instanceof TestCacheKeySerializable && key.equals(((TestCacheKeySerializable)obj).key);
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestCacheKeyExternalizable implements Externalizable {
+ /** */
+ private String key;
+
+ /** */
+ private String terminalId;
+
+ /**
+ *
+ */
+ public TestCacheKeyExternalizable() {
+ // No-op.
+ }
+
+ /**
+ * @param key Key.
+ * @param terminalId Some ID.
+ */
+ TestCacheKeyExternalizable(String key, String terminalId) {
+ this.key = key;
+ this.terminalId = terminalId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return key.hashCode();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return obj instanceof TestCacheKeyExternalizable && key.equals(((TestCacheKeyExternalizable)obj).key);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ U.writeString(out, key);
+ U.writeString(out, terminalId);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ key = U.readString(in);
+ terminalId = U.readString(in);
+ }
+ }
+}
\ No newline at end of file
[07/10] ignite git commit: IGNITE-4938: Moved OptimizedMarshaller to
private package. This closes #1793.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
deleted file mode 100644
index fd885f2..0000000
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
+++ /dev/null
@@ -1,1141 +0,0 @@
-/*
- * 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.optimized;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.NotSerializableException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamField;
-import java.io.Serializable;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentMap;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteProductVersion;
-import org.apache.ignite.marshaller.MarshallerContext;
-import org.apache.ignite.marshaller.MarshallerExclusions;
-import org.apache.ignite.internal.util.SerializableTransient;
-import org.apache.ignite.marshaller.MarshallerUtils;
-
-import static java.lang.reflect.Modifier.isFinal;
-import static java.lang.reflect.Modifier.isPrivate;
-import static java.lang.reflect.Modifier.isStatic;
-import static java.lang.reflect.Modifier.isTransient;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.ARRAY_LIST;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.BOOLEAN;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.BOOLEAN_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.BYTE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.BYTE_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.CHAR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.CHAR_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.CLS;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.DATE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.DOUBLE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.DOUBLE_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.ENUM;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.EXTERNALIZABLE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.FLOAT;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.FLOAT_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.HASH_MAP;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.HASH_SET;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.HASH_SET_MAP_OFF;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.INT;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.INT_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LINKED_HASH_MAP;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LINKED_HASH_SET;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LINKED_LIST;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LONG;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LONG_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.OBJ_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.PROPS;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.PROXY;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SERIALIZABLE;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SHORT;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SHORT_ARR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.STR;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.UUID;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.classDescriptor;
-import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.computeSerialVersionUid;
-
-/**
- * Class descriptor.
- */
-class OptimizedClassDescriptor {
- /** Class. */
- private final Class<?> cls;
-
- /** Context. */
- private final MarshallerContext ctx;
-
- /** */
- private ConcurrentMap<Class, OptimizedClassDescriptor> clsMap;
-
- /** ID mapper. */
- private final OptimizedMarshallerIdMapper mapper;
-
- /** Class name. */
- private final String name;
-
- /** Type ID. */
- private final int typeId;
-
- /** Short ID. */
- private final short checksum;
-
- /** Class type. */
- private int type;
-
- /** Primitive flag. */
- private boolean isPrimitive;
-
- /** Enum flag. */
- private boolean isEnum;
-
- /** Serializable flag. */
- private boolean isSerial;
-
- /** Excluded flag. */
- private boolean excluded;
-
- /** {@code True} if descriptor is for {@link Class}. */
- private boolean isCls;
-
- /** Enumeration values. */
- private Object[] enumVals;
-
- /** Constructor. */
- private Constructor<?> constructor;
-
- /** Fields. */
- private Fields fields;
-
- /** {@code writeObject} methods. */
- private List<Method> writeObjMtds;
-
- /** {@code writeReplace} method. */
- private Method writeReplaceMtd;
-
- /** {@code readObject} methods. */
- private List<Method> readObjMtds;
-
- /** {@code readResolve} method. */
- private Method readResolveMtd;
-
- /** Defaults field offset. */
- private long dfltsFieldOff;
-
- /** Load factor field offset. */
- private long loadFactorFieldOff;
-
- /** Access order field offset. */
- private long accessOrderFieldOff;
-
- /** Proxy interfaces. */
- private Class<?>[] proxyIntfs;
-
- /** Method returns serializable transient fields. */
- private Method serTransMtd;
-
- /**
- * Creates descriptor for class.
- *
- * @param typeId Type ID.
- * @param clsMap Class descriptors by class map.
- * @param cls Class.
- * @param ctx Context.
- * @param mapper ID mapper.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- OptimizedClassDescriptor(Class<?> cls,
- int typeId,
- ConcurrentMap<Class, OptimizedClassDescriptor> clsMap,
- MarshallerContext ctx,
- OptimizedMarshallerIdMapper mapper)
- throws IOException {
- this.cls = cls;
- this.typeId = typeId;
- this.clsMap = clsMap;
- this.ctx = ctx;
- this.mapper = mapper;
-
- name = cls.getName();
-
- excluded = MarshallerExclusions.isExcluded(cls);
-
- if (!excluded) {
- Class<?> parent;
-
- if (cls == byte.class || cls == Byte.class) {
- type = BYTE;
-
- isPrimitive = true;
- }
- else if (cls == short.class || cls == Short.class) {
- type = SHORT;
-
- isPrimitive = true;
- }
- else if (cls == int.class || cls == Integer.class) {
- type = INT;
-
- isPrimitive = true;
- }
- else if (cls == long.class || cls == Long.class) {
- type = LONG;
-
- isPrimitive = true;
- }
- else if (cls == float.class || cls == Float.class) {
- type = FLOAT;
-
- isPrimitive = true;
- }
- else if (cls == double.class || cls == Double.class) {
- type = DOUBLE;
-
- isPrimitive = true;
- }
- else if (cls == char.class || cls == Character.class) {
- type = CHAR;
-
- isPrimitive = true;
- }
- else if (cls == boolean.class || cls == Boolean.class) {
- type = BOOLEAN;
-
- isPrimitive = true;
- }
- else if (cls == byte[].class)
- type = BYTE_ARR;
- else if (cls == short[].class)
- type = SHORT_ARR;
- else if (cls == int[].class)
- type = INT_ARR;
- else if (cls == long[].class)
- type = LONG_ARR;
- else if (cls == float[].class)
- type = FLOAT_ARR;
- else if (cls == double[].class)
- type = DOUBLE_ARR;
- else if (cls == char[].class)
- type = CHAR_ARR;
- else if (cls == boolean[].class)
- type = BOOLEAN_ARR;
- else if (cls.isArray())
- type = OBJ_ARR;
- else if (cls == String.class)
- type = STR;
- else if (cls.isEnum()) {
- type = ENUM;
-
- isEnum = true;
- enumVals = cls.getEnumConstants();
- }
- // Support for enum constants, based on anonymous children classes.
- else if ((parent = cls.getSuperclass()) != null && parent.isEnum()) {
- type = ENUM;
-
- isEnum = true;
- enumVals = parent.getEnumConstants();
- }
- else if (cls == UUID.class)
- type = UUID;
- else if (cls == Properties.class) {
- type = PROPS;
-
- try {
- dfltsFieldOff = GridUnsafe.objectFieldOffset(Properties.class.getDeclaredField("defaults"));
- }
- catch (NoSuchFieldException e) {
- throw new IOException(e);
- }
- }
- else if (cls == ArrayList.class)
- type = ARRAY_LIST;
- else if (cls == HashMap.class) {
- type = HASH_MAP;
-
- try {
- loadFactorFieldOff = GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
- }
- catch (NoSuchFieldException e) {
- throw new IOException(e);
- }
- }
- else if (cls == HashSet.class) {
- type = HASH_SET;
-
- try {
- loadFactorFieldOff = GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
- }
- catch (NoSuchFieldException e) {
- throw new IOException(e);
- }
- }
- else if (cls == LinkedList.class)
- type = LINKED_LIST;
- else if (cls == LinkedHashMap.class) {
- type = LINKED_HASH_MAP;
-
- try {
- loadFactorFieldOff =
- GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
- accessOrderFieldOff =
- GridUnsafe.objectFieldOffset(LinkedHashMap.class.getDeclaredField("accessOrder"));
- }
- catch (NoSuchFieldException e) {
- throw new IOException(e);
- }
- }
- else if (cls == LinkedHashSet.class) {
- type = LINKED_HASH_SET;
-
- try {
- loadFactorFieldOff = GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
- }
- catch (NoSuchFieldException e) {
- throw new IOException(e);
- }
- }
- else if (cls == Date.class)
- type = DATE;
- else if (cls == Class.class) {
- type = CLS;
-
- isCls = true;
- }
- else if (Proxy.class.isAssignableFrom(cls)) {
- type = PROXY;
-
- proxyIntfs = cls.getInterfaces();
- }
- else {
- Class<?> c = cls;
-
- while ((writeReplaceMtd == null || readResolveMtd == null) && c != null && !c.equals(Object.class)) {
- if (writeReplaceMtd == null) {
- try {
- writeReplaceMtd = c.getDeclaredMethod("writeReplace");
-
- if (!isStatic(writeReplaceMtd.getModifiers()) &&
- !(isPrivate(writeReplaceMtd.getModifiers()) && c != cls) &&
- writeReplaceMtd.getReturnType().equals(Object.class))
- writeReplaceMtd.setAccessible(true);
- else
- // Set method back to null if it has incorrect signature.
- writeReplaceMtd = null;
- }
- catch (NoSuchMethodException ignored) {
- // No-op.
- }
- }
-
- if (readResolveMtd == null) {
- try {
- readResolveMtd = c.getDeclaredMethod("readResolve");
-
- if (!isStatic(readResolveMtd.getModifiers()) &&
- !(isPrivate(readResolveMtd.getModifiers()) && c != cls) &&
- readResolveMtd.getReturnType().equals(Object.class))
- readResolveMtd.setAccessible(true);
- else
- // Set method back to null if it has incorrect signature.
- readResolveMtd = null;
- }
- catch (NoSuchMethodException ignored) {
- // No-op.
- }
- }
-
- c = c.getSuperclass();
- }
-
- if (Externalizable.class.isAssignableFrom(cls)) {
- type = EXTERNALIZABLE;
-
- try {
- constructor = !Modifier.isStatic(cls.getModifiers()) && cls.getDeclaringClass() != null ?
- cls.getDeclaredConstructor(cls.getDeclaringClass()) :
- cls.getDeclaredConstructor();
-
- constructor.setAccessible(true);
- }
- catch (NoSuchMethodException e) {
- throw new IOException("Externalizable class doesn't have default constructor: " + cls, e);
- }
- }
- else {
- type = SERIALIZABLE;
-
- isSerial = Serializable.class.isAssignableFrom(cls);
-
- writeObjMtds = new ArrayList<>();
- readObjMtds = new ArrayList<>();
- List<ClassFields> fields = new ArrayList<>();
-
- for (c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
- Method mtd;
-
- try {
- mtd = c.getDeclaredMethod("writeObject", ObjectOutputStream.class);
-
- int mod = mtd.getModifiers();
-
- if (!isStatic(mod) && isPrivate(mod) && mtd.getReturnType() == Void.TYPE)
- mtd.setAccessible(true);
- else
- // Set method back to null if it has incorrect signature.
- mtd = null;
- }
- catch (NoSuchMethodException ignored) {
- mtd = null;
- }
-
- writeObjMtds.add(mtd);
-
- try {
- mtd = c.getDeclaredMethod("readObject", ObjectInputStream.class);
-
- int mod = mtd.getModifiers();
-
- if (!isStatic(mod) && isPrivate(mod) && mtd.getReturnType() == Void.TYPE)
- mtd.setAccessible(true);
- else
- // Set method back to null if it has incorrect signature.
- mtd = null;
- }
- catch (NoSuchMethodException ignored) {
- mtd = null;
- }
-
- readObjMtds.add(mtd);
-
- final SerializableTransient serTransAn = c.getAnnotation(SerializableTransient.class);
-
- // Custom serialization policy for transient fields.
- if (serTransAn != null) {
- try {
- serTransMtd = c.getDeclaredMethod(serTransAn.methodName(), cls, IgniteProductVersion.class);
-
- int mod = serTransMtd.getModifiers();
-
- if (isStatic(mod) && isPrivate(mod)
- && serTransMtd.getReturnType() == String[].class)
- serTransMtd.setAccessible(true);
- else
- // Set method back to null if it has incorrect signature.
- serTransMtd = null;
- }
- catch (NoSuchMethodException ignored) {
- serTransMtd = null;
- }
- }
-
- Field[] clsFields0 = c.getDeclaredFields();
-
- Map<String, Field> fieldNames = new HashMap<>();
-
- for (Field f : clsFields0)
- fieldNames.put(f.getName(), f);
-
- List<FieldInfo> clsFields = new ArrayList<>(clsFields0.length);
-
- boolean hasSerialPersistentFields = false;
-
- try {
- Field serFieldsDesc = c.getDeclaredField("serialPersistentFields");
-
- int mod = serFieldsDesc.getModifiers();
-
- if (serFieldsDesc.getType() == ObjectStreamField[].class &&
- isPrivate(mod) && isStatic(mod) && isFinal(mod)) {
- hasSerialPersistentFields = true;
-
- serFieldsDesc.setAccessible(true);
-
- ObjectStreamField[] serFields = (ObjectStreamField[]) serFieldsDesc.get(null);
-
- for (int i = 0; i < serFields.length; i++) {
- ObjectStreamField serField = serFields[i];
-
- FieldInfo fieldInfo;
-
- if (!fieldNames.containsKey(serField.getName())) {
- fieldInfo = new FieldInfo(null,
- serField.getName(),
- -1,
- fieldType(serField.getType()));
- }
- else {
- Field f = fieldNames.get(serField.getName());
-
- fieldInfo = new FieldInfo(f,
- serField.getName(),
- GridUnsafe.objectFieldOffset(f),
- fieldType(serField.getType()));
- }
-
- clsFields.add(fieldInfo);
- }
- }
- }
- catch (NoSuchFieldException ignored) {
- // No-op.
- }
- catch (IllegalAccessException e) {
- throw new IOException("Failed to get value of 'serialPersistentFields' field in class: " +
- cls.getName(), e);
- }
-
- if (!hasSerialPersistentFields) {
- for (int i = 0; i < clsFields0.length; i++) {
- Field f = clsFields0[i];
-
- int mod = f.getModifiers();
-
- if (!isStatic(mod) && !isTransient(mod)) {
- FieldInfo fieldInfo = new FieldInfo(f, f.getName(),
- GridUnsafe.objectFieldOffset(f), fieldType(f.getType()));
-
- clsFields.add(fieldInfo);
- }
- }
- }
-
- Collections.sort(clsFields, new Comparator<FieldInfo>() {
- @Override public int compare(FieldInfo t1, FieldInfo t2) {
- return t1.name().compareTo(t2.name());
- }
- });
-
- fields.add(new ClassFields(clsFields));
- }
-
- Collections.reverse(writeObjMtds);
- Collections.reverse(readObjMtds);
- Collections.reverse(fields);
-
- this.fields = new Fields(fields);
- }
- }
- }
-
- checksum = computeSerialVersionUid(cls, fields != null ? fields.ownFields() : null);
- }
-
- /**
- * @return Excluded flag.
- */
- boolean excluded() {
- return excluded;
- }
-
- /**
- * @return Class.
- */
- Class<?> describedClass() {
- return cls;
- }
-
- /**
- * @return Primitive flag.
- */
- boolean isPrimitive() {
- return isPrimitive;
- }
-
- /**
- * @return Enum flag.
- */
- boolean isEnum() {
- return isEnum;
- }
-
- /**
- * @return {@code True} if descriptor is for {@link Class}.
- */
- boolean isClass() {
- return isCls;
- }
-
- /**
- * @return {@code True} if descriptor is for {@link Proxy}.
- */
- boolean isProxy() {
- return type == PROXY;
- }
-
- /**
- * Replaces object.
- *
- * @param obj Object.
- * @return Replaced object or {@code null} if there is no {@code writeReplace} method.
- * @throws IOException In case of error.
- */
- Object replace(Object obj) throws IOException {
- if (writeReplaceMtd != null) {
- try {
- return writeReplaceMtd.invoke(obj);
- }
- catch (IllegalAccessException | InvocationTargetException e) {
- throw new IOException(e);
- }
- }
-
- return obj;
- }
-
- /**
- * Writes object to stream.
- *
- * @param out Output stream.
- * @param obj Object.
- * @throws IOException In case of error.
- */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- void write(OptimizedObjectOutputStream out, Object obj) throws IOException {
- out.write(type);
-
- switch (type) {
- case BYTE:
- out.writeByte((Byte)obj);
-
- break;
-
- case SHORT:
- out.writeShort((Short)obj);
-
- break;
-
- case INT:
- out.writeInt((Integer)obj);
-
- break;
-
- case LONG:
- out.writeLong((Long)obj);
-
- break;
-
- case FLOAT:
- out.writeFloat((Float)obj);
-
- break;
-
- case DOUBLE:
- out.writeDouble((Double)obj);
-
- break;
-
- case CHAR:
- out.writeChar((Character)obj);
-
- break;
-
- case BOOLEAN:
- out.writeBoolean((Boolean)obj);
-
- break;
-
- case BYTE_ARR:
- out.writeByteArray((byte[])obj);
-
- break;
-
- case SHORT_ARR:
- out.writeShortArray((short[])obj);
-
- break;
-
- case INT_ARR:
- out.writeIntArray((int[])obj);
-
- break;
-
- case LONG_ARR:
- out.writeLongArray((long[])obj);
-
- break;
-
- case FLOAT_ARR:
- out.writeFloatArray((float[])obj);
-
- break;
-
- case DOUBLE_ARR:
- out.writeDoubleArray((double[])obj);
-
- break;
-
- case CHAR_ARR:
- out.writeCharArray((char[])obj);
-
- break;
-
- case BOOLEAN_ARR:
- out.writeBooleanArray((boolean[])obj);
-
- break;
-
- case OBJ_ARR:
- OptimizedClassDescriptor compDesc = classDescriptor(clsMap,
- obj.getClass().getComponentType(),
- ctx,
- mapper);
-
- compDesc.writeTypeData(out);
-
- out.writeArray((Object[])obj);
-
- break;
-
- case STR:
- out.writeString((String)obj);
-
- break;
-
- case UUID:
- out.writeUuid((UUID)obj);
-
- break;
-
- case PROPS:
- out.writeProperties((Properties)obj, dfltsFieldOff);
-
- break;
-
- case ARRAY_LIST:
- out.writeArrayList((ArrayList<?>)obj);
-
- break;
-
- case HASH_MAP:
- out.writeHashMap((HashMap<?, ?>)obj, loadFactorFieldOff, false);
-
- break;
-
- case HASH_SET:
- out.writeHashSet((HashSet<?>)obj, HASH_SET_MAP_OFF, loadFactorFieldOff);
-
- break;
-
- case LINKED_LIST:
- out.writeLinkedList((LinkedList<?>)obj);
-
- break;
-
- case LINKED_HASH_MAP:
- out.writeLinkedHashMap((LinkedHashMap<?, ?>)obj, loadFactorFieldOff, accessOrderFieldOff, false);
-
- break;
-
- case LINKED_HASH_SET:
- out.writeLinkedHashSet((LinkedHashSet<?>)obj, HASH_SET_MAP_OFF, loadFactorFieldOff);
-
- break;
-
- case DATE:
- out.writeDate((Date)obj);
-
- break;
-
- case CLS:
- OptimizedClassDescriptor clsDesc = classDescriptor(clsMap, (Class<?>)obj, ctx, mapper);
-
- clsDesc.writeTypeData(out);
-
- break;
-
- case PROXY:
- out.writeInt(proxyIntfs.length);
-
- for (Class<?> intf : proxyIntfs) {
- OptimizedClassDescriptor intfDesc = classDescriptor(clsMap, intf, ctx, mapper);
-
- intfDesc.writeTypeData(out);
- }
-
- InvocationHandler ih = Proxy.getInvocationHandler(obj);
-
- assert ih != null;
-
- out.writeObject(ih);
-
- break;
-
- case ENUM:
- writeTypeData(out);
-
- out.writeInt(((Enum)obj).ordinal());
-
- break;
-
- case EXTERNALIZABLE:
- writeTypeData(out);
-
- out.writeShort(checksum);
- out.writeExternalizable(obj);
-
- break;
-
- case SERIALIZABLE:
- if (out.requireSerializable() && !isSerial)
- throw new NotSerializableException("Must implement java.io.Serializable or " +
- "set OptimizedMarshaller.setRequireSerializable() to false " +
- "(note that performance may degrade if object is not Serializable): " + name);
-
- writeTypeData(out);
-
- out.writeShort(checksum);
- out.writeSerializable(obj, writeObjMtds, serializableFields(obj.getClass(), obj, null));
-
- break;
-
- default:
- throw new IllegalStateException("Invalid class type: " + type);
- }
- }
-
- /**
- * Gets list of serializable fields. If {@link #serTransMtd} method
- * returns list of transient fields, they will be added to other fields.
- * Transient fields that are not included in that list will be normally
- * ignored.
- *
- * @param cls Class.
- * @param obj Object.
- * @param ver Job sender version.
- * @return Serializable fields.
- */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- private Fields serializableFields(Class<?> cls, Object obj, IgniteProductVersion ver) {
- if (serTransMtd == null)
- return fields;
-
- try {
- final String[] transFields = (String[])serTransMtd.invoke(cls, obj, ver);
-
- if (transFields == null || transFields.length == 0)
- return fields;
-
- List<FieldInfo> clsFields = new ArrayList<>();
-
- clsFields.addAll(fields.fields.get(0).fields);
-
- for (int i = 0; i < transFields.length; i++) {
- final String fieldName = transFields[i];
-
- final Field f = cls.getDeclaredField(fieldName);
-
- FieldInfo fieldInfo = new FieldInfo(f, f.getName(),
- GridUnsafe.objectFieldOffset(f), fieldType(f.getType()));
-
- clsFields.add(fieldInfo);
- }
-
- Collections.sort(clsFields, new Comparator<FieldInfo>() {
- @Override public int compare(FieldInfo t1, FieldInfo t2) {
- return t1.name().compareTo(t2.name());
- }
- });
-
- List<ClassFields> fields = new ArrayList<>();
-
- fields.add(new ClassFields(clsFields));
-
- return new Fields(fields);
- }
- catch (Exception ignored) {
- return fields;
- }
- }
-
- /**
- * @param out Output stream.
- * @throws IOException In case of error.
- */
- void writeTypeData(OptimizedObjectOutputStream out) throws IOException {
- out.writeInt(typeId);
-
- if (typeId == 0)
- out.writeUTF(name);
- }
-
- /**
- * Reads object from stream.
- *
- * @param in Input stream.
- * @return Object.
- * @throws ClassNotFoundException If class not found.
- * @throws IOException In case of error.
- */
- Object read(OptimizedObjectInputStream in) throws ClassNotFoundException, IOException {
- switch (type) {
- case ENUM:
- return enumVals[in.readInt()];
-
- case EXTERNALIZABLE:
- verifyChecksum(in.readShort());
-
- return in.readExternalizable(constructor, readResolveMtd);
-
- case SERIALIZABLE:
- verifyChecksum(in.readShort());
-
- // If no serialize method, then unmarshal as usual.
- if (serTransMtd != null)
- return in.readSerializable(cls, readObjMtds, readResolveMtd,
- serializableFields(cls, null, MarshallerUtils.jobSenderVersion()));
- else
- return in.readSerializable(cls, readObjMtds, readResolveMtd, fields);
-
- default:
- assert false : "Unexpected type: " + type;
-
- return null;
- }
- }
-
- /**
- * @param checksum Checksum.
- * @throws ClassNotFoundException If checksum is wrong.
- * @throws IOException In case of error.
- */
- private void verifyChecksum(short checksum) throws ClassNotFoundException, IOException {
- if (checksum != this.checksum)
- throw new ClassNotFoundException("Optimized stream class checksum mismatch " +
- "(is same version of marshalled class present on all nodes?) " +
- "[expected=" + this.checksum + ", actual=" + checksum + ", cls=" + cls + ']');
- }
-
- /**
- * @param cls Class.
- * @return Type.
- */
- @SuppressWarnings("IfMayBeConditional")
- private OptimizedFieldType fieldType(Class<?> cls) {
- OptimizedFieldType type;
-
- if (cls == byte.class)
- type = OptimizedFieldType.BYTE;
- else if (cls == short.class)
- type = OptimizedFieldType.SHORT;
- else if (cls == int.class)
- type = OptimizedFieldType.INT;
- else if (cls == long.class)
- type = OptimizedFieldType.LONG;
- else if (cls == float.class)
- type = OptimizedFieldType.FLOAT;
- else if (cls == double.class)
- type = OptimizedFieldType.DOUBLE;
- else if (cls == char.class)
- type = OptimizedFieldType.CHAR;
- else if (cls == boolean.class)
- type = OptimizedFieldType.BOOLEAN;
- else
- type = OptimizedFieldType.OTHER;
-
- return type;
- }
-
- /**
- * Information about one field.
- */
- @SuppressWarnings("PackageVisibleInnerClass")
- static class FieldInfo {
- /** Field. */
- private final Field field;
-
- /** Field offset. */
- private final long fieldOffs;
-
- /** Field type. */
- private final OptimizedFieldType fieldType;
-
- /** Field name. */
- private final String fieldName;
-
- /**
- * @param field Field.
- * @param name Field name.
- * @param offset Field offset.
- * @param type Grid optimized field type.
- */
- FieldInfo(Field field, String name, long offset, OptimizedFieldType type) {
- this.field = field;
- fieldOffs = offset;
- fieldType = type;
- fieldName = name;
- }
-
- /**
- * @return Returns field.
- */
- Field field() {
- return field;
- }
-
- /**
- * @return Offset.
- */
- long offset() {
- return fieldOffs;
- }
-
- /**
- * @return Type.
- */
- OptimizedFieldType type() {
- return fieldType;
- }
-
- /**
- * @return Name.
- */
- String name() {
- return fieldName;
- }
- }
-
- /**
- * Information about one class.
- */
- static class ClassFields {
- /** Fields. */
- private final List<FieldInfo> fields;
-
- private final Map<String, Integer> nameToIndex;
-
- /**
- * @param fields Field infos.
- */
- ClassFields(List<FieldInfo> fields) {
- this.fields = fields;
-
- nameToIndex = U.newHashMap(fields.size());
-
- for (int i = 0; i < fields.size(); ++i)
- nameToIndex.put(fields.get(i).name(), i);
- }
-
- /**
- * @return Class fields.
- */
- List<FieldInfo> fields() {
- return fields;
- }
-
- /**
- * @return Fields count.
- */
- int size() {
- return fields.size();
- }
-
- /**
- * @param i Field's index.
- * @return FieldInfo.
- */
- FieldInfo get(int i) {
- return fields.get(i);
- }
-
- /**
- * @param name Field's name.
- * @return Field's index.
- */
- int getIndex(String name) {
- assert nameToIndex.containsKey(name);
-
- return nameToIndex.get(name);
- }
- }
-
- /**
- * Encapsulates data about class fields.
- */
- @SuppressWarnings("PackageVisibleInnerClass")
- static class Fields {
- /** Fields. */
- private final List<ClassFields> fields;
-
- /** Own fields (excluding inherited). */
- private final List<Field> ownFields;
-
- /**
- * Creates new instance.
- *
- * @param fields Fields.
- */
- Fields(List<ClassFields> fields) {
- this.fields = fields;
-
- if (fields.isEmpty())
- ownFields = null;
- else {
- ownFields = new ArrayList<>(fields.size());
-
- for (FieldInfo f : fields.get(fields.size() - 1).fields()) {
- if (f.field() != null)
- ownFields.add(f.field);
- }
- }
- }
-
- /**
- * Returns class's own fields (excluding inherited).
- *
- * @return List of fields or {@code null} if fields list is empty.
- */
- List<Field> ownFields() {
- return ownFields;
- }
-
- /**
- * Returns field types and their offsets.
- *
- * @param i hierarchy level where 0 corresponds to top level.
- * @return list of pairs where first value is field type and second value is its offset.
- */
- ClassFields fields(int i) {
- return fields.get(i);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedFieldType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedFieldType.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedFieldType.java
deleted file mode 100644
index aca7ce4..0000000
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedFieldType.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.optimized;
-
-/**
- * Field type used to calculate {@code Unsafe} offsets into objects.
- */
-enum OptimizedFieldType {
- /** */
- BYTE,
-
- /** */
- SHORT,
-
- /** */
- INT,
-
- /** */
- LONG,
-
- /** */
- FLOAT,
-
- /** */
- DOUBLE,
-
- /** */
- CHAR,
-
- /** */
- BOOLEAN,
-
- /** */
- OTHER
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshaller.java
deleted file mode 100644
index e61e8dc..0000000
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshaller.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * 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.optimized;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.util.concurrent.ConcurrentMap;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteSystemProperties;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-import sun.misc.Unsafe;
-
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID;
-
-/**
- * Optimized implementation of {@link org.apache.ignite.marshaller.Marshaller}.
- * Unlike {@link org.apache.ignite.marshaller.jdk.JdkMarshaller},
- * which is based on standard {@link ObjectOutputStream}, this marshaller does not
- * enforce that all serialized objects implement {@link Serializable} interface. It is also
- * about 20 times faster as it removes lots of serialization overhead that exists in
- * default JDK implementation.
- * <p>
- * {@code OptimizedMarshaller} is tested only on Java HotSpot VM on other VMs
- * it could yield unexpected results. It is the default marshaller on Java HotSpot VMs
- * and will be used if no other marshaller was explicitly configured.
- * <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">
- * OptimizedMarshaller marshaller = new OptimizedMarshaller();
- *
- * // Enforce Serializable interface.
- * marshaller.setRequireSerializable(true);
- *
- * IgniteConfiguration cfg = new IgniteConfiguration();
- *
- * // Override marshaller.
- * cfg.setMarshaller(marshaller);
- *
- * // Starts grid.
- * G.start(cfg);
- * </pre>
- * <h2 class="header">Spring Example</h2>
- * GridOptimizedMarshaller 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.optimized.OptimizedMarshaller">
- * <property name="requireSerializable">true</property>
- * </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 OptimizedMarshaller extends AbstractNodeNameAwareMarshaller {
- /** Use default {@code serialVersionUID} for {@link Serializable} classes. */
- public static final boolean USE_DFLT_SUID =
- IgniteSystemProperties.getBoolean(IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID, false);
-
- /** Default class loader. */
- private final ClassLoader dfltClsLdr = getClass().getClassLoader();
-
- /** Whether or not to require an object to be serializable in order to be marshalled. */
- private boolean requireSer = true;
-
- /** ID mapper. */
- private OptimizedMarshallerIdMapper mapper;
-
- /** Class descriptors by class. */
- private final ConcurrentMap<Class, OptimizedClassDescriptor> clsMap = new ConcurrentHashMap8<>();
-
- /**
- * Creates new marshaller will all defaults.
- *
- * @throws IgniteException If this marshaller is not supported on the current JVM.
- */
- public OptimizedMarshaller() {
- if (!available())
- throw new IgniteException("Using OptimizedMarshaller on unsupported JVM version (some of " +
- "JVM-private APIs required for the marshaller to work are missing).");
- }
-
- /**
- * Creates new marshaller providing whether it should
- * require {@link Serializable} interface or not.
- *
- * @param requireSer Whether to require {@link Serializable}.
- */
- public OptimizedMarshaller(boolean requireSer) {
- this.requireSer = requireSer;
- }
-
- /**
- * Sets whether marshaller should require {@link Serializable} interface or not.
- *
- * @param requireSer Whether to require {@link Serializable}.
- * @return {@code this} for chaining.
- */
- public OptimizedMarshaller setRequireSerializable(boolean requireSer) {
- this.requireSer = requireSer;
-
- return this;
- }
-
- /**
- * Sets ID mapper.
- *
- * @param mapper ID mapper.
- * @return {@code this} for chaining.
- */
- public OptimizedMarshaller setIdMapper(OptimizedMarshallerIdMapper mapper) {
- this.mapper = mapper;
-
- return this;
- }
-
- /**
- * Specifies size of cached object streams used by marshaller. Object streams are cached for
- * performance reason to avoid costly recreation for every serialization routine. If {@code 0} (default),
- * pool is not used and each thread has its own cached object stream which it keeps reusing.
- * <p>
- * Since each stream has an internal buffer, creating a stream for each thread can lead to
- * high memory consumption if many large messages are marshalled or unmarshalled concurrently.
- * Consider using pool in this case. This will limit number of streams that can be created and,
- * therefore, decrease memory consumption.
- * <p>
- * NOTE: Using streams pool can decrease performance since streams will be shared between
- * different threads which will lead to more frequent context switching.
- *
- * @param poolSize Streams pool size. If {@code 0}, pool is not used.
- * @return {@code this} for chaining.
- */
- public OptimizedMarshaller setPoolSize(int poolSize) {
- OptimizedObjectStreamRegistry.poolSize(poolSize);
-
- return this;
- }
-
- /** {@inheritDoc} */
- @Override protected void marshal0(@Nullable Object obj, OutputStream out) throws IgniteCheckedException {
- assert out != null;
-
- OptimizedObjectOutputStream objOut = null;
-
- try {
- objOut = OptimizedObjectStreamRegistry.out();
-
- objOut.context(clsMap, ctx, mapper, requireSer);
-
- objOut.out().outputStream(out);
-
- objOut.writeObject(obj);
- }
- catch (IOException e) {
- throw new IgniteCheckedException("Failed to serialize object: " + obj, e);
- }
- finally {
- OptimizedObjectStreamRegistry.closeOut(objOut);
- }
- }
-
- /** {@inheritDoc} */
- @Override protected byte[] marshal0(@Nullable Object obj) throws IgniteCheckedException {
- OptimizedObjectOutputStream objOut = null;
-
- try {
- objOut = OptimizedObjectStreamRegistry.out();
-
- objOut.context(clsMap, ctx, mapper, requireSer);
-
- objOut.writeObject(obj);
-
- return objOut.out().array();
- }
- catch (Exception e) {
- throw new IgniteCheckedException("Failed to serialize object: " + obj, e);
- }
- finally {
- OptimizedObjectStreamRegistry.closeOut(objOut);
- }
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override protected <T> T unmarshal0(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
- assert in != null;
-
- OptimizedObjectInputStream objIn = null;
-
- try {
- objIn = OptimizedObjectStreamRegistry.in();
-
- objIn.context(clsMap, ctx, mapper, clsLdr != null ? clsLdr : dfltClsLdr);
-
- objIn.in().inputStream(in);
-
- return (T)objIn.readObject();
- }
- catch (ClassNotFoundException e) {
- throw new IgniteCheckedException("Failed to find class with given class loader for unmarshalling " +
- "(make sure same versions of all classes are available on all nodes or enable peer-class-loading) " +
- "[clsLdr=" + clsLdr + ", cls=" + e.getMessage() + "]", e);
- }
- catch (Exception e) {
- throw new IgniteCheckedException("Failed to deserialize object with given class loader: " + clsLdr, e);
- }
- finally {
- OptimizedObjectStreamRegistry.closeIn(objIn);
- }
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override protected <T> T unmarshal0(byte[] arr, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
- assert arr != null;
-
- OptimizedObjectInputStream objIn = null;
-
- try {
- objIn = OptimizedObjectStreamRegistry.in();
-
- objIn.context(clsMap, ctx, mapper, clsLdr != null ? clsLdr : dfltClsLdr);
-
- objIn.in().bytes(arr, arr.length);
-
- return (T)objIn.readObject();
- }
- catch (ClassNotFoundException e) {
- throw new IgniteCheckedException("Failed to find class with given class loader for unmarshalling " +
- "(make sure same version of all classes are available on all nodes or enable peer-class-loading)" +
- " [clsLdr=" + clsLdr + ", cls=" + e.getMessage() + "]", e);
- }
- catch (Exception e) {
- throw new IgniteCheckedException("Failed to deserialize object with given class loader: " + clsLdr, e);
- }
- finally {
- OptimizedObjectStreamRegistry.closeIn(objIn);
- }
- }
-
- /**
- * Checks whether {@code GridOptimizedMarshaller} is able to work on the current JVM.
- * <p>
- * As long as {@code GridOptimizedMarshaller} 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 GridOptimizedMarshaller} can work on the current JVM or
- * {@code false} if it can't.
- */
- @SuppressWarnings({"TypeParameterExtendsFinalClass", "ErrorNotRethrown"})
- public static boolean available() {
- try {
- Class<? extends Unsafe> unsafeCls = Unsafe.class;
-
- 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;
- }
- }
-
- /**
- * Undeployment callback invoked when class loader is being undeployed.
- *
- * @param ldr Class loader being undeployed.
- */
- @Override public void onUndeploy(ClassLoader ldr) {
- for (Class<?> cls : clsMap.keySet()) {
- if (ldr.equals(cls.getClassLoader()))
- clsMap.remove(cls);
- }
-
- U.clearClassCache(ldr);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerIdMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerIdMapper.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerIdMapper.java
deleted file mode 100644
index 91d07df..0000000
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerIdMapper.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.optimized;
-
-/**
- * ID mapper.
- */
-public interface OptimizedMarshallerIdMapper {
- /**
- * Gets type ID for provided class name.
- * <p>
- * If {@code 0} is returned, hash code of class name will be used.
- *
- * @param clsName Class name.
- * @return Type ID.
- */
- public int typeId(String clsName);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
deleted file mode 100644
index 60a627a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
+++ /dev/null
@@ -1,551 +0,0 @@
-/*
- * 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.optimized;
-
-import java.io.IOException;
-import java.io.ObjectStreamClass;
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.nio.charset.Charset;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.HashSet;
-import java.util.List;
-import java.util.concurrent.ConcurrentMap;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.marshaller.MarshallerContext;
-import org.apache.ignite.marshaller.jdk.JdkMarshaller;
-
-import static org.apache.ignite.internal.MarshallerPlatformIds.JAVA_ID;
-
-/**
- * Miscellaneous utility methods to facilitate {@link OptimizedMarshaller}.
- */
-class OptimizedMarshallerUtils {
- /** */
- static final long HASH_SET_MAP_OFF;
-
- /** */
- static final byte JDK = -2;
-
- /** */
- static final byte HANDLE = -1;
-
- /** */
- static final byte NULL = 0;
-
- /** */
- static final byte BYTE = 1;
-
- /** */
- static final byte SHORT = 2;
-
- /** */
- static final byte INT = 3;
-
- /** */
- static final byte LONG = 4;
-
- /** */
- static final byte FLOAT = 5;
-
- /** */
- static final byte DOUBLE = 6;
-
- /** */
- static final byte CHAR = 7;
-
- /** */
- static final byte BOOLEAN = 8;
-
- /** */
- static final byte BYTE_ARR = 9;
-
- /** */
- static final byte SHORT_ARR = 10;
-
- /** */
- static final byte INT_ARR = 11;
-
- /** */
- static final byte LONG_ARR = 12;
-
- /** */
- static final byte FLOAT_ARR = 13;
-
- /** */
- static final byte DOUBLE_ARR = 14;
-
- /** */
- static final byte CHAR_ARR = 15;
-
- /** */
- static final byte BOOLEAN_ARR = 16;
-
- /** */
- static final byte OBJ_ARR = 17;
-
- /** */
- static final byte STR = 18;
-
- /** */
- static final byte UUID = 19;
-
- /** */
- static final byte PROPS = 20;
-
- /** */
- static final byte ARRAY_LIST = 21;
-
- /** */
- static final byte HASH_MAP = 22;
-
- /** */
- static final byte HASH_SET = 23;
-
- /** */
- static final byte LINKED_LIST = 24;
-
- /** */
- static final byte LINKED_HASH_MAP = 25;
-
- /** */
- static final byte LINKED_HASH_SET = 26;
-
- /** */
- static final byte DATE = 27;
-
- /** */
- static final byte CLS = 28;
-
- /** */
- static final byte PROXY = 29;
-
- /** */
- static final byte ENUM = 100;
-
- /** */
- static final byte EXTERNALIZABLE = 101;
-
- /** */
- static final byte SERIALIZABLE = 102;
-
- /** UTF-8 character name. */
- static final Charset UTF_8 = Charset.forName("UTF-8");
-
- /** JDK marshaller. */
- static final JdkMarshaller JDK_MARSH = new JdkMarshaller();
-
- static {
- long mapOff;
-
- try {
- mapOff = GridUnsafe.objectFieldOffset(HashSet.class.getDeclaredField("map"));
- }
- catch (NoSuchFieldException ignored) {
- try {
- // Workaround for legacy IBM JRE.
- mapOff = GridUnsafe.objectFieldOffset(HashSet.class.getDeclaredField("backingMap"));
- }
- catch (NoSuchFieldException e2) {
- throw new IgniteException("Initialization failure.", e2);
- }
- }
-
- HASH_SET_MAP_OFF = mapOff;
- }
-
- /**
- */
- private OptimizedMarshallerUtils() {
- // No-op.
- }
-
- /**
- * Gets descriptor for provided class.
- *
- * @param clsMap Class descriptors by class map.
- * @param cls Class.
- * @param ctx Context.
- * @param mapper ID mapper.
- * @return Descriptor.
- * @throws IOException In case of error.
- */
- static OptimizedClassDescriptor classDescriptor(
- ConcurrentMap<Class, OptimizedClassDescriptor> clsMap,
- Class cls,
- MarshallerContext ctx,
- OptimizedMarshallerIdMapper mapper)
- throws IOException
- {
- OptimizedClassDescriptor desc = clsMap.get(cls);
-
- if (desc == null) {
- int typeId = resolveTypeId(cls.getName(), mapper);
-
- boolean registered;
-
- try {
- registered = ctx.registerClassName(JAVA_ID, typeId, cls.getName());
- }
- catch (IgniteCheckedException e) {
- throw new IOException("Failed to register class: " + cls.getName(), e);
- }
-
- desc = new OptimizedClassDescriptor(cls, registered ? typeId : 0, clsMap, ctx, mapper);
-
- if (registered) {
- OptimizedClassDescriptor old = clsMap.putIfAbsent(cls, desc);
-
- if (old != null)
- desc = old;
- }
- }
-
- return desc;
- }
-
- /**
- * @param clsName Class name.
- * @param mapper Mapper.
- * @return Type ID.
- */
- private static int resolveTypeId(String clsName, OptimizedMarshallerIdMapper mapper) {
- int typeId;
-
- if (mapper != null) {
- typeId = mapper.typeId(clsName);
-
- if (typeId == 0)
- typeId = clsName.hashCode();
- }
- else
- typeId = clsName.hashCode();
-
- return typeId;
- }
-
- /**
- * Gets descriptor for provided ID.
- *
- * @param clsMap Class descriptors by class map.
- * @param typeId ID.
- * @param ldr Class loader.
- * @param ctx Context.
- * @param mapper ID mapper.
- * @return Descriptor.
- * @throws IOException In case of error.
- * @throws ClassNotFoundException If class was not found.
- */
- static OptimizedClassDescriptor classDescriptor(
- ConcurrentMap<Class, OptimizedClassDescriptor> clsMap,
- int typeId,
- ClassLoader ldr,
- MarshallerContext ctx,
- OptimizedMarshallerIdMapper mapper) throws IOException, ClassNotFoundException {
- Class cls;
-
- try {
- cls = ctx.getClass(typeId, ldr);
- }
- catch (IgniteCheckedException e) {
- throw new IOException("Failed to resolve class for ID: " + typeId, e);
- }
-
- OptimizedClassDescriptor desc = clsMap.get(cls);
-
- if (desc == null) {
- OptimizedClassDescriptor old = clsMap.putIfAbsent(cls, desc =
- new OptimizedClassDescriptor(cls, resolveTypeId(cls.getName(), mapper), clsMap, ctx, mapper));
-
- if (old != null)
- desc = old;
- }
-
- return desc;
- }
-
- /**
- * Computes the serial version UID value for the given class. The code is taken from {@link
- * ObjectStreamClass#computeDefaultSUID(Class)}.
- *
- * @param cls A class.
- * @param fields Fields.
- * @return A serial version UID.
- * @throws IOException If failed.
- */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- static short computeSerialVersionUid(Class cls, List<Field> fields) throws IOException {
- if (Serializable.class.isAssignableFrom(cls) && !Enum.class.isAssignableFrom(cls)) {
- try {
- Field field = cls.getDeclaredField("serialVersionUID");
-
- if (field.getType() == long.class) {
- int mod = field.getModifiers();
-
- if (Modifier.isStatic(mod) && Modifier.isFinal(mod)) {
- field.setAccessible(true);
-
- return (short)field.getLong(null);
- }
- }
- }
- catch (NoSuchFieldException ignored) {
- // No-op.
- }
- catch (IllegalAccessException e) {
- throw new IOException(e);
- }
-
- if (OptimizedMarshaller.USE_DFLT_SUID)
- return (short)ObjectStreamClass.lookup(cls).getSerialVersionUID();
- }
-
- MessageDigest md;
-
- try {
- md = MessageDigest.getInstance("SHA");
- }
- catch (NoSuchAlgorithmException e) {
- throw new IOException("Failed to get digest for SHA.", e);
- }
-
- md.update(cls.getName().getBytes(UTF_8));
-
- if (!F.isEmpty(fields)) {
- for (int i = 0; i < fields.size(); i++) {
- Field f = fields.get(i);
-
- md.update(f.getName().getBytes(UTF_8));
- md.update(f.getType().getName().getBytes(UTF_8));
- }
- }
-
- byte[] hashBytes = md.digest();
-
- long hash = 0;
-
- // Composes a single-long hash from the byte[] hash.
- for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--)
- hash = (hash << 8) | (hashBytes[i] & 0xFF);
-
- return (short)hash;
- }
-
- /**
- * Gets byte field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @return Byte value.
- */
- static byte getByte(Object obj, long off) {
- return GridUnsafe.getByteField(obj, off);
- }
-
- /**
- * Sets byte field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @param val Value.
- */
- static void setByte(Object obj, long off, byte val) {
- GridUnsafe.putByteField(obj, off, val);
- }
-
- /**
- * Gets short field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @return Short value.
- */
- static short getShort(Object obj, long off) {
- return GridUnsafe.getShortField(obj, off);
- }
-
- /**
- * Sets short field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @param val Value.
- */
- static void setShort(Object obj, long off, short val) {
- GridUnsafe.putShortField(obj, off, val);
- }
-
- /**
- * Gets integer field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @return Integer value.
- */
- static int getInt(Object obj, long off) {
- return GridUnsafe.getIntField(obj, off);
- }
-
- /**
- * Sets integer field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @param val Value.
- */
- static void setInt(Object obj, long off, int val) {
- GridUnsafe.putIntField(obj, off, val);
- }
-
- /**
- * Gets long field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @return Long value.
- */
- static long getLong(Object obj, long off) {
- return GridUnsafe.getLongField(obj, off);
- }
-
- /**
- * Sets long field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @param val Value.
- */
- static void setLong(Object obj, long off, long val) {
- GridUnsafe.putLongField(obj, off, val);
- }
-
- /**
- * Gets float field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @return Float value.
- */
- static float getFloat(Object obj, long off) {
- return GridUnsafe.getFloatField(obj, off);
- }
-
- /**
- * Sets float field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @param val Value.
- */
- static void setFloat(Object obj, long off, float val) {
- GridUnsafe.putFloatField(obj, off, val);
- }
-
- /**
- * Gets double field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @return Double value.
- */
- static double getDouble(Object obj, long off) {
- return GridUnsafe.getDoubleField(obj, off);
- }
-
- /**
- * Sets double field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @param val Value.
- */
- static void setDouble(Object obj, long off, double val) {
- GridUnsafe.putDoubleField(obj, off, val);
- }
-
- /**
- * Gets char field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @return Char value.
- */
- static char getChar(Object obj, long off) {
- return GridUnsafe.getCharField(obj, off);
- }
-
- /**
- * Sets char field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @param val Value.
- */
- static void setChar(Object obj, long off, char val) {
- GridUnsafe.putCharField(obj, off, val);
- }
-
- /**
- * Gets boolean field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @return Boolean value.
- */
- static boolean getBoolean(Object obj, long off) {
- return GridUnsafe.getBooleanField(obj, off);
- }
-
- /**
- * Sets boolean field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @param val Value.
- */
- static void setBoolean(Object obj, long off, boolean val) {
- GridUnsafe.putBooleanField(obj, off, val);
- }
-
- /**
- * Gets field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @return Value.
- */
- static Object getObject(Object obj, long off) {
- return GridUnsafe.getObjectField(obj, off);
- }
-
- /**
- * Sets field value.
- *
- * @param obj Object.
- * @param off Field offset.
- * @param val Value.
- */
- static void setObject(Object obj, long off, Object val) {
- GridUnsafe.putObjectField(obj, off, val);
- }
-}
[08/10] ignite git commit: IGNITE-4938: Moved OptimizedMarshaller to
private package. This closes #1793.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerUtils.java
new file mode 100644
index 0000000..f9a6df9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerUtils.java
@@ -0,0 +1,551 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.io.IOException;
+import java.io.ObjectStreamClass;
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.nio.charset.Charset;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.concurrent.ConcurrentMap;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.marshaller.MarshallerContext;
+import org.apache.ignite.marshaller.jdk.JdkMarshaller;
+
+import static org.apache.ignite.internal.MarshallerPlatformIds.JAVA_ID;
+
+/**
+ * Miscellaneous utility methods to facilitate {@link OptimizedMarshaller}.
+ */
+class OptimizedMarshallerUtils {
+ /** */
+ static final long HASH_SET_MAP_OFF;
+
+ /** */
+ static final byte JDK = -2;
+
+ /** */
+ static final byte HANDLE = -1;
+
+ /** */
+ static final byte NULL = 0;
+
+ /** */
+ static final byte BYTE = 1;
+
+ /** */
+ static final byte SHORT = 2;
+
+ /** */
+ static final byte INT = 3;
+
+ /** */
+ static final byte LONG = 4;
+
+ /** */
+ static final byte FLOAT = 5;
+
+ /** */
+ static final byte DOUBLE = 6;
+
+ /** */
+ static final byte CHAR = 7;
+
+ /** */
+ static final byte BOOLEAN = 8;
+
+ /** */
+ static final byte BYTE_ARR = 9;
+
+ /** */
+ static final byte SHORT_ARR = 10;
+
+ /** */
+ static final byte INT_ARR = 11;
+
+ /** */
+ static final byte LONG_ARR = 12;
+
+ /** */
+ static final byte FLOAT_ARR = 13;
+
+ /** */
+ static final byte DOUBLE_ARR = 14;
+
+ /** */
+ static final byte CHAR_ARR = 15;
+
+ /** */
+ static final byte BOOLEAN_ARR = 16;
+
+ /** */
+ static final byte OBJ_ARR = 17;
+
+ /** */
+ static final byte STR = 18;
+
+ /** */
+ static final byte UUID = 19;
+
+ /** */
+ static final byte PROPS = 20;
+
+ /** */
+ static final byte ARRAY_LIST = 21;
+
+ /** */
+ static final byte HASH_MAP = 22;
+
+ /** */
+ static final byte HASH_SET = 23;
+
+ /** */
+ static final byte LINKED_LIST = 24;
+
+ /** */
+ static final byte LINKED_HASH_MAP = 25;
+
+ /** */
+ static final byte LINKED_HASH_SET = 26;
+
+ /** */
+ static final byte DATE = 27;
+
+ /** */
+ static final byte CLS = 28;
+
+ /** */
+ static final byte PROXY = 29;
+
+ /** */
+ static final byte ENUM = 100;
+
+ /** */
+ static final byte EXTERNALIZABLE = 101;
+
+ /** */
+ static final byte SERIALIZABLE = 102;
+
+ /** UTF-8 character name. */
+ static final Charset UTF_8 = Charset.forName("UTF-8");
+
+ /** JDK marshaller. */
+ static final JdkMarshaller JDK_MARSH = new JdkMarshaller();
+
+ static {
+ long mapOff;
+
+ try {
+ mapOff = GridUnsafe.objectFieldOffset(HashSet.class.getDeclaredField("map"));
+ }
+ catch (NoSuchFieldException ignored) {
+ try {
+ // Workaround for legacy IBM JRE.
+ mapOff = GridUnsafe.objectFieldOffset(HashSet.class.getDeclaredField("backingMap"));
+ }
+ catch (NoSuchFieldException e2) {
+ throw new IgniteException("Initialization failure.", e2);
+ }
+ }
+
+ HASH_SET_MAP_OFF = mapOff;
+ }
+
+ /**
+ */
+ private OptimizedMarshallerUtils() {
+ // No-op.
+ }
+
+ /**
+ * Gets descriptor for provided class.
+ *
+ * @param clsMap Class descriptors by class map.
+ * @param cls Class.
+ * @param ctx Context.
+ * @param mapper ID mapper.
+ * @return Descriptor.
+ * @throws IOException In case of error.
+ */
+ static OptimizedClassDescriptor classDescriptor(
+ ConcurrentMap<Class, OptimizedClassDescriptor> clsMap,
+ Class cls,
+ MarshallerContext ctx,
+ OptimizedMarshallerIdMapper mapper)
+ throws IOException
+ {
+ OptimizedClassDescriptor desc = clsMap.get(cls);
+
+ if (desc == null) {
+ int typeId = resolveTypeId(cls.getName(), mapper);
+
+ boolean registered;
+
+ try {
+ registered = ctx.registerClassName(JAVA_ID, typeId, cls.getName());
+ }
+ catch (IgniteCheckedException e) {
+ throw new IOException("Failed to register class: " + cls.getName(), e);
+ }
+
+ desc = new OptimizedClassDescriptor(cls, registered ? typeId : 0, clsMap, ctx, mapper);
+
+ if (registered) {
+ OptimizedClassDescriptor old = clsMap.putIfAbsent(cls, desc);
+
+ if (old != null)
+ desc = old;
+ }
+ }
+
+ return desc;
+ }
+
+ /**
+ * @param clsName Class name.
+ * @param mapper Mapper.
+ * @return Type ID.
+ */
+ private static int resolveTypeId(String clsName, OptimizedMarshallerIdMapper mapper) {
+ int typeId;
+
+ if (mapper != null) {
+ typeId = mapper.typeId(clsName);
+
+ if (typeId == 0)
+ typeId = clsName.hashCode();
+ }
+ else
+ typeId = clsName.hashCode();
+
+ return typeId;
+ }
+
+ /**
+ * Gets descriptor for provided ID.
+ *
+ * @param clsMap Class descriptors by class map.
+ * @param typeId ID.
+ * @param ldr Class loader.
+ * @param ctx Context.
+ * @param mapper ID mapper.
+ * @return Descriptor.
+ * @throws IOException In case of error.
+ * @throws ClassNotFoundException If class was not found.
+ */
+ static OptimizedClassDescriptor classDescriptor(
+ ConcurrentMap<Class, OptimizedClassDescriptor> clsMap,
+ int typeId,
+ ClassLoader ldr,
+ MarshallerContext ctx,
+ OptimizedMarshallerIdMapper mapper) throws IOException, ClassNotFoundException {
+ Class cls;
+
+ try {
+ cls = ctx.getClass(typeId, ldr);
+ }
+ catch (IgniteCheckedException e) {
+ throw new IOException("Failed to resolve class for ID: " + typeId, e);
+ }
+
+ OptimizedClassDescriptor desc = clsMap.get(cls);
+
+ if (desc == null) {
+ OptimizedClassDescriptor old = clsMap.putIfAbsent(cls, desc =
+ new OptimizedClassDescriptor(cls, resolveTypeId(cls.getName(), mapper), clsMap, ctx, mapper));
+
+ if (old != null)
+ desc = old;
+ }
+
+ return desc;
+ }
+
+ /**
+ * Computes the serial version UID value for the given class. The code is taken from {@link
+ * ObjectStreamClass#computeDefaultSUID(Class)}.
+ *
+ * @param cls A class.
+ * @param fields Fields.
+ * @return A serial version UID.
+ * @throws IOException If failed.
+ */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ static short computeSerialVersionUid(Class cls, List<Field> fields) throws IOException {
+ if (Serializable.class.isAssignableFrom(cls) && !Enum.class.isAssignableFrom(cls)) {
+ try {
+ Field field = cls.getDeclaredField("serialVersionUID");
+
+ if (field.getType() == long.class) {
+ int mod = field.getModifiers();
+
+ if (Modifier.isStatic(mod) && Modifier.isFinal(mod)) {
+ field.setAccessible(true);
+
+ return (short)field.getLong(null);
+ }
+ }
+ }
+ catch (NoSuchFieldException ignored) {
+ // No-op.
+ }
+ catch (IllegalAccessException e) {
+ throw new IOException(e);
+ }
+
+ if (OptimizedMarshaller.USE_DFLT_SUID)
+ return (short)ObjectStreamClass.lookup(cls).getSerialVersionUID();
+ }
+
+ MessageDigest md;
+
+ try {
+ md = MessageDigest.getInstance("SHA");
+ }
+ catch (NoSuchAlgorithmException e) {
+ throw new IOException("Failed to get digest for SHA.", e);
+ }
+
+ md.update(cls.getName().getBytes(UTF_8));
+
+ if (!F.isEmpty(fields)) {
+ for (int i = 0; i < fields.size(); i++) {
+ Field f = fields.get(i);
+
+ md.update(f.getName().getBytes(UTF_8));
+ md.update(f.getType().getName().getBytes(UTF_8));
+ }
+ }
+
+ byte[] hashBytes = md.digest();
+
+ long hash = 0;
+
+ // Composes a single-long hash from the byte[] hash.
+ for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--)
+ hash = (hash << 8) | (hashBytes[i] & 0xFF);
+
+ return (short)hash;
+ }
+
+ /**
+ * Gets byte field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @return Byte value.
+ */
+ static byte getByte(Object obj, long off) {
+ return GridUnsafe.getByteField(obj, off);
+ }
+
+ /**
+ * Sets byte field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @param val Value.
+ */
+ static void setByte(Object obj, long off, byte val) {
+ GridUnsafe.putByteField(obj, off, val);
+ }
+
+ /**
+ * Gets short field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @return Short value.
+ */
+ static short getShort(Object obj, long off) {
+ return GridUnsafe.getShortField(obj, off);
+ }
+
+ /**
+ * Sets short field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @param val Value.
+ */
+ static void setShort(Object obj, long off, short val) {
+ GridUnsafe.putShortField(obj, off, val);
+ }
+
+ /**
+ * Gets integer field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @return Integer value.
+ */
+ static int getInt(Object obj, long off) {
+ return GridUnsafe.getIntField(obj, off);
+ }
+
+ /**
+ * Sets integer field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @param val Value.
+ */
+ static void setInt(Object obj, long off, int val) {
+ GridUnsafe.putIntField(obj, off, val);
+ }
+
+ /**
+ * Gets long field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @return Long value.
+ */
+ static long getLong(Object obj, long off) {
+ return GridUnsafe.getLongField(obj, off);
+ }
+
+ /**
+ * Sets long field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @param val Value.
+ */
+ static void setLong(Object obj, long off, long val) {
+ GridUnsafe.putLongField(obj, off, val);
+ }
+
+ /**
+ * Gets float field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @return Float value.
+ */
+ static float getFloat(Object obj, long off) {
+ return GridUnsafe.getFloatField(obj, off);
+ }
+
+ /**
+ * Sets float field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @param val Value.
+ */
+ static void setFloat(Object obj, long off, float val) {
+ GridUnsafe.putFloatField(obj, off, val);
+ }
+
+ /**
+ * Gets double field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @return Double value.
+ */
+ static double getDouble(Object obj, long off) {
+ return GridUnsafe.getDoubleField(obj, off);
+ }
+
+ /**
+ * Sets double field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @param val Value.
+ */
+ static void setDouble(Object obj, long off, double val) {
+ GridUnsafe.putDoubleField(obj, off, val);
+ }
+
+ /**
+ * Gets char field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @return Char value.
+ */
+ static char getChar(Object obj, long off) {
+ return GridUnsafe.getCharField(obj, off);
+ }
+
+ /**
+ * Sets char field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @param val Value.
+ */
+ static void setChar(Object obj, long off, char val) {
+ GridUnsafe.putCharField(obj, off, val);
+ }
+
+ /**
+ * Gets boolean field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @return Boolean value.
+ */
+ static boolean getBoolean(Object obj, long off) {
+ return GridUnsafe.getBooleanField(obj, off);
+ }
+
+ /**
+ * Sets boolean field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @param val Value.
+ */
+ static void setBoolean(Object obj, long off, boolean val) {
+ GridUnsafe.putBooleanField(obj, off, val);
+ }
+
+ /**
+ * Gets field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @return Value.
+ */
+ static Object getObject(Object obj, long off) {
+ return GridUnsafe.getObjectField(obj, off);
+ }
+
+ /**
+ * Sets field value.
+ *
+ * @param obj Object.
+ * @param off Field offset.
+ * @param val Value.
+ */
+ static void setObject(Object obj, long off, Object val) {
+ GridUnsafe.putObjectField(obj, off, val);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectInputStream.java
new file mode 100644
index 0000000..be0e115
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectInputStream.java
@@ -0,0 +1,1231 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.NotActiveException;
+import java.io.ObjectInputStream;
+import java.io.ObjectInputValidation;
+import java.io.ObjectStreamClass;
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentMap;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.io.GridDataInput;
+import org.apache.ignite.internal.util.typedef.internal.SB;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContext;
+
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.ARRAY_LIST;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.BOOLEAN;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.BOOLEAN_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.BYTE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.BYTE_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.CHAR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.CHAR_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.CLS;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.DATE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.DOUBLE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.DOUBLE_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.ENUM;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.EXTERNALIZABLE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.FLOAT;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.FLOAT_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.HANDLE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.HASH_MAP;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.HASH_SET;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.HASH_SET_MAP_OFF;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.INT;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.INT_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.JDK;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.JDK_MARSH;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.LINKED_HASH_MAP;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.LINKED_HASH_SET;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.LINKED_LIST;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.LONG;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.LONG_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.NULL;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.OBJ_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.PROPS;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.PROXY;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.SERIALIZABLE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.SHORT;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.SHORT_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.STR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.UUID;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.classDescriptor;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setBoolean;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setByte;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setChar;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setDouble;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setFloat;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setInt;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setLong;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setObject;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setShort;
+
+/**
+ * Optimized object input stream.
+ */
+class OptimizedObjectInputStream extends ObjectInputStream {
+ /** Dummy object for HashSet. */
+ private static final Object DUMMY = new Object();
+
+ /** */
+ private final HandleTable handles = new HandleTable(10);
+
+ /** */
+ private MarshallerContext ctx;
+
+ /** */
+ private OptimizedMarshallerIdMapper mapper;
+
+ /** */
+ private ClassLoader clsLdr;
+
+ /** */
+ private GridDataInput in;
+
+ /** */
+ private Object curObj;
+
+ /** */
+ private OptimizedClassDescriptor.ClassFields curFields;
+
+ /** */
+ private Class<?> curCls;
+
+ /** */
+ private ConcurrentMap<Class, OptimizedClassDescriptor> clsMap;
+
+ /**
+ * @param in Input.
+ * @throws IOException In case of error.
+ */
+ OptimizedObjectInputStream(GridDataInput in) throws IOException {
+ this.in = in;
+ }
+
+ /**
+ * @param clsMap Class descriptors by class map.
+ * @param ctx Context.
+ * @param mapper ID mapper.
+ * @param clsLdr Class loader.
+ */
+ void context(
+ ConcurrentMap<Class, OptimizedClassDescriptor> clsMap,
+ MarshallerContext ctx,
+ OptimizedMarshallerIdMapper mapper,
+ ClassLoader clsLdr)
+ {
+ this.clsMap = clsMap;
+ this.ctx = ctx;
+ this.mapper = mapper;
+ this.clsLdr = clsLdr;
+ }
+
+ /**
+ * @return Input.
+ */
+ public GridDataInput in() {
+ return in;
+ }
+
+ /**
+ * @param in Input.
+ */
+ public void in(GridDataInput in) {
+ this.in = in;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void close() throws IOException {
+ reset();
+
+ ctx = null;
+ clsLdr = null;
+ clsMap = null;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod")
+ @Override public void reset() throws IOException {
+ in.reset();
+ handles.clear();
+
+ curObj = null;
+ curFields = null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object readObjectOverride() throws ClassNotFoundException, IOException {
+ curObj = null;
+ curFields = null;
+
+ byte ref = in.readByte();
+
+ switch (ref) {
+ case NULL:
+ return null;
+
+ case HANDLE:
+ return handles.lookup(readInt());
+
+ case JDK:
+ try {
+ return JDK_MARSH.unmarshal(this, clsLdr);
+ }
+ catch (IgniteCheckedException e) {
+ IOException ioEx = e.getCause(IOException.class);
+
+ if (ioEx != null)
+ throw ioEx;
+ else
+ throw new IOException("Failed to deserialize object with JDK marshaller.", e);
+ }
+
+ case BYTE:
+ return readByte();
+
+ case SHORT:
+ return readShort();
+
+ case INT:
+ return readInt();
+
+ case LONG:
+ return readLong();
+
+ case FLOAT:
+ return readFloat();
+
+ case DOUBLE:
+ return readDouble();
+
+ case CHAR:
+ return readChar();
+
+ case BOOLEAN:
+ return readBoolean();
+
+ case BYTE_ARR:
+ return readByteArray();
+
+ case SHORT_ARR:
+ return readShortArray();
+
+ case INT_ARR:
+ return readIntArray();
+
+ case LONG_ARR:
+ return readLongArray();
+
+ case FLOAT_ARR:
+ return readFloatArray();
+
+ case DOUBLE_ARR:
+ return readDoubleArray();
+
+ case CHAR_ARR:
+ return readCharArray();
+
+ case BOOLEAN_ARR:
+ return readBooleanArray();
+
+ case OBJ_ARR:
+ return readArray(readClass());
+
+ case STR:
+ return readString();
+
+ case UUID:
+ return readUuid();
+
+ case PROPS:
+ return readProperties();
+
+ case ARRAY_LIST:
+ return readArrayList();
+
+ case HASH_MAP:
+ return readHashMap(false);
+
+ case HASH_SET:
+ return readHashSet(HASH_SET_MAP_OFF);
+
+ case LINKED_LIST:
+ return readLinkedList();
+
+ case LINKED_HASH_MAP:
+ return readLinkedHashMap(false);
+
+ case LINKED_HASH_SET:
+ return readLinkedHashSet(HASH_SET_MAP_OFF);
+
+ case DATE:
+ return readDate();
+
+ case CLS:
+ return readClass();
+
+ case PROXY:
+ Class<?>[] intfs = new Class<?>[readInt()];
+
+ for (int i = 0; i < intfs.length; i++)
+ intfs[i] = readClass();
+
+ InvocationHandler ih = (InvocationHandler)readObject();
+
+ return Proxy.newProxyInstance(clsLdr != null ? clsLdr : U.gridClassLoader(), intfs, ih);
+
+ case ENUM:
+ case EXTERNALIZABLE:
+ case SERIALIZABLE:
+ int typeId = readInt();
+
+ OptimizedClassDescriptor desc = typeId == 0 ?
+ classDescriptor(clsMap, U.forName(readUTF(), clsLdr), ctx, mapper):
+ classDescriptor(clsMap, typeId, clsLdr, ctx, mapper);
+
+ curCls = desc.describedClass();
+
+ return desc.read(this);
+
+ default:
+ SB msg = new SB("Unexpected error occurred during unmarshalling");
+
+ if (curCls != null)
+ msg.a(" of an instance of the class: ").a(curCls.getName());
+
+ msg.a(". Check that all nodes are running the same version of Ignite and that all nodes have " +
+ "GridOptimizedMarshaller configured with identical optimized classes lists, if any " +
+ "(see setClassNames and setClassNamesPath methods). If your serialized classes implement " +
+ "java.io.Externalizable interface, verify that serialization logic is correct.");
+
+ throw new IOException(msg.toString());
+ }
+ }
+
+ /**
+ * @return Class.
+ * @throws ClassNotFoundException If class was not found.
+ * @throws IOException In case of other error.
+ */
+ private Class<?> readClass() throws ClassNotFoundException, IOException {
+ int compTypeId = readInt();
+
+ return compTypeId == 0 ? U.forName(readUTF(), clsLdr) :
+ classDescriptor(clsMap, compTypeId, clsLdr, ctx, mapper).describedClass();
+ }
+
+ /**
+ * Reads array from this stream.
+ *
+ * @param compType Array component type.
+ * @return Array.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("unchecked")
+ <T> T[] readArray(Class<T> compType) throws ClassNotFoundException, IOException {
+ int len = in.readInt();
+
+ T[] arr = (T[])Array.newInstance(compType, len);
+
+ handles.assign(arr);
+
+ for (int i = 0; i < len; i++)
+ arr[i] = (T)readObject();
+
+ return arr;
+ }
+
+ /**
+ * Reads {@link UUID} from this stream.
+ *
+ * @return UUID.
+ * @throws IOException In case of error.
+ */
+ UUID readUuid() throws IOException {
+ UUID uuid = new UUID(readLong(), readLong());
+
+ handles.assign(uuid);
+
+ return uuid;
+ }
+
+ /**
+ * Reads {@link Properties} from this stream.
+ *
+ * @return Properties.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ Properties readProperties() throws ClassNotFoundException, IOException {
+ Properties dflts = readBoolean() ? null : (Properties)readObject();
+
+ Properties props = new Properties(dflts);
+
+ int size = in.readInt();
+
+ for (int i = 0; i < size; i++)
+ props.setProperty(readUTF(), readUTF());
+
+ handles.assign(props);
+
+ return props;
+ }
+
+ /**
+ * Reads and sets all non-static and non-transient field values from this stream.
+ *
+ * @param obj Object.
+ * @param fieldOffs Field offsets.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ void readFields(Object obj, OptimizedClassDescriptor.ClassFields fieldOffs) throws ClassNotFoundException,
+ IOException {
+ for (int i = 0; i < fieldOffs.size(); i++) {
+ OptimizedClassDescriptor.FieldInfo t = fieldOffs.get(i);
+
+ switch ((t.type())) {
+ case BYTE:
+ byte resByte = readByte();
+
+ if (t.field() != null)
+ setByte(obj, t.offset(), resByte);
+
+ break;
+
+ case SHORT:
+ short resShort = readShort();
+
+ if (t.field() != null)
+ setShort(obj, t.offset(), resShort);
+
+ break;
+
+ case INT:
+ int resInt = readInt();
+
+ if (t.field() != null)
+ setInt(obj, t.offset(), resInt);
+
+ break;
+
+ case LONG:
+ long resLong = readLong();
+
+ if (t.field() != null)
+ setLong(obj, t.offset(), resLong);
+
+ break;
+
+ case FLOAT:
+ float resFloat = readFloat();
+
+ if (t.field() != null)
+ setFloat(obj, t.offset(), resFloat);
+
+ break;
+
+ case DOUBLE:
+ double resDouble = readDouble();
+
+ if (t.field() != null)
+ setDouble(obj, t.offset(), resDouble);
+
+ break;
+
+ case CHAR:
+ char resChar = readChar();
+
+ if (t.field() != null)
+ setChar(obj, t.offset(), resChar);
+
+ break;
+
+ case BOOLEAN:
+ boolean resBoolean = readBoolean();
+
+ if (t.field() != null)
+ setBoolean(obj, t.offset(), resBoolean);
+
+ break;
+
+ case OTHER:
+ Object resObject = readObject();
+
+ if (t.field() != null)
+ setObject(obj, t.offset(), resObject);
+ }
+ }
+ }
+
+ /**
+ * Reads {@link Externalizable} object.
+ *
+ * @param constructor Constructor.
+ * @param readResolveMtd {@code readResolve} method.
+ * @return Object.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ Object readExternalizable(Constructor<?> constructor, Method readResolveMtd)
+ throws ClassNotFoundException, IOException {
+ Object obj;
+
+ try {
+ obj = constructor.newInstance();
+ }
+ catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
+ throw new IOException(e);
+ }
+
+ int handle = handles.assign(obj);
+
+ Externalizable extObj = ((Externalizable)obj);
+
+ extObj.readExternal(this);
+
+ if (readResolveMtd != null) {
+ try {
+ obj = readResolveMtd.invoke(obj);
+
+ handles.set(handle, obj);
+ }
+ catch (IllegalAccessException | InvocationTargetException e) {
+ throw new IOException(e);
+ }
+ }
+
+ return obj;
+ }
+
+ /**
+ * Reads serializable object.
+ *
+ * @param cls Class.
+ * @param mtds {@code readObject} methods.
+ * @param readResolveMtd {@code readResolve} method.
+ * @param fields class fields details.
+ * @return Object.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ Object readSerializable(Class<?> cls, List<Method> mtds, Method readResolveMtd,
+ OptimizedClassDescriptor.Fields fields) throws ClassNotFoundException, IOException {
+ Object obj;
+
+ try {
+ obj = GridUnsafe.allocateInstance(cls);
+ }
+ catch (InstantiationException e) {
+ throw new IOException(e);
+ }
+
+ int handle = handles.assign(obj);
+
+ for (int i = 0; i < mtds.size(); i++) {
+ Method mtd = mtds.get(i);
+
+ if (mtd != null) {
+ curObj = obj;
+ curFields = fields.fields(i);
+
+ try {
+ mtd.invoke(obj, this);
+ }
+ catch (IllegalAccessException | InvocationTargetException e) {
+ throw new IOException(e);
+ }
+ }
+ else
+ readFields(obj, fields.fields(i));
+ }
+
+ if (readResolveMtd != null) {
+ try {
+ obj = readResolveMtd.invoke(obj);
+
+ handles.set(handle, obj);
+ }
+ catch (IllegalAccessException | InvocationTargetException e) {
+ throw new IOException(e);
+ }
+ }
+
+ return obj;
+ }
+
+ /**
+ * Reads {@link ArrayList}.
+ *
+ * @return List.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ ArrayList<?> readArrayList() throws ClassNotFoundException, IOException {
+ int size = readInt();
+
+ ArrayList<Object> list = new ArrayList<>(size);
+
+ handles.assign(list);
+
+ for (int i = 0; i < size; i++)
+ list.add(readObject());
+
+ return list;
+ }
+
+ /**
+ * Reads {@link HashMap}.
+ *
+ * @param set Whether reading underlying map from {@link HashSet}.
+ * @return Map.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ HashMap<?, ?> readHashMap(boolean set) throws ClassNotFoundException, IOException {
+ int size = readInt();
+ float loadFactor = readFloat();
+
+ HashMap<Object, Object> map = new HashMap<>(size, loadFactor);
+
+ if (!set)
+ handles.assign(map);
+
+ for (int i = 0; i < size; i++) {
+ Object key = readObject();
+ Object val = !set ? readObject() : DUMMY;
+
+ map.put(key, val);
+ }
+
+ return map;
+ }
+
+ /**
+ * Reads {@link HashSet}.
+ *
+ * @param mapFieldOff Map field offset.
+ * @return Set.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("unchecked")
+ HashSet<?> readHashSet(long mapFieldOff) throws ClassNotFoundException, IOException {
+ try {
+ HashSet<Object> set = (HashSet<Object>)GridUnsafe.allocateInstance(HashSet.class);
+
+ handles.assign(set);
+
+ setObject(set, mapFieldOff, readHashMap(true));
+
+ return set;
+ }
+ catch (InstantiationException e) {
+ throw new IOException(e);
+ }
+ }
+
+ /**
+ * Reads {@link LinkedList}.
+ *
+ * @return List.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ LinkedList<?> readLinkedList() throws ClassNotFoundException, IOException {
+ int size = readInt();
+
+ LinkedList<Object> list = new LinkedList<>();
+
+ handles.assign(list);
+
+ for (int i = 0; i < size; i++)
+ list.add(readObject());
+
+ return list;
+ }
+
+ /**
+ * Reads {@link LinkedHashMap}.
+ *
+ * @param set Whether reading underlying map from {@link LinkedHashSet}.
+ * @return Map.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ LinkedHashMap<?, ?> readLinkedHashMap(boolean set) throws ClassNotFoundException, IOException {
+ int size = readInt();
+ float loadFactor = readFloat();
+ boolean accessOrder = readBoolean();
+
+ LinkedHashMap<Object, Object> map = new LinkedHashMap<>(size, loadFactor, accessOrder);
+
+ if (!set)
+ handles.assign(map);
+
+ for (int i = 0; i < size; i++) {
+ Object key = readObject();
+ Object val = !set ? readObject() : DUMMY;
+
+ map.put(key, val);
+ }
+
+ return map;
+ }
+
+ /**
+ * Reads {@link LinkedHashSet}.
+ *
+ * @param mapFieldOff Map field offset.
+ * @return Set.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("unchecked")
+ LinkedHashSet<?> readLinkedHashSet(long mapFieldOff) throws ClassNotFoundException, IOException {
+ try {
+ LinkedHashSet<Object> set = (LinkedHashSet<Object>)GridUnsafe.allocateInstance(LinkedHashSet.class);
+
+ handles.assign(set);
+
+ setObject(set, mapFieldOff, readLinkedHashMap(true));
+
+ return set;
+ }
+ catch (InstantiationException e) {
+ throw new IOException(e);
+ }
+ }
+
+ /**
+ * Reads {@link Date}.
+ *
+ * @return Date.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ Date readDate() throws ClassNotFoundException, IOException {
+ Date date = new Date(readLong());
+
+ handles.assign(date);
+
+ return date;
+ }
+
+ /**
+ * Reads array of {@code byte}s.
+ *
+ * @return Array.
+ * @throws IOException In case of error.
+ */
+ byte[] readByteArray() throws IOException {
+ byte[] arr = in.readByteArray();
+
+ handles.assign(arr);
+
+ return arr;
+ }
+
+ /**
+ * Reads array of {@code short}s.
+ *
+ * @return Array.
+ * @throws IOException In case of error.
+ */
+ short[] readShortArray() throws IOException {
+ short[] arr = in.readShortArray();
+
+ handles.assign(arr);
+
+ return arr;
+ }
+
+ /**
+ * Reads array of {@code int}s.
+ *
+ * @return Array.
+ * @throws IOException In case of error.
+ */
+ int[] readIntArray() throws IOException {
+ int[] arr = in.readIntArray();
+
+ handles.assign(arr);
+
+ return arr;
+ }
+
+ /**
+ * Reads array of {@code long}s.
+ *
+ * @return Array.
+ * @throws IOException In case of error.
+ */
+ long[] readLongArray() throws IOException {
+ long[] arr = in.readLongArray();
+
+ handles.assign(arr);
+
+ return arr;
+ }
+
+ /**
+ * Reads array of {@code float}s.
+ *
+ * @return Array.
+ * @throws IOException In case of error.
+ */
+ float[] readFloatArray() throws IOException {
+ float[] arr = in.readFloatArray();
+
+ handles.assign(arr);
+
+ return arr;
+ }
+
+ /**
+ * Reads array of {@code double}s.
+ *
+ * @return Array.
+ * @throws IOException In case of error.
+ */
+ double[] readDoubleArray() throws IOException {
+ double[] arr = in.readDoubleArray();
+
+ handles.assign(arr);
+
+ return arr;
+ }
+
+ /**
+ * Reads array of {@code char}s.
+ *
+ * @return Array.
+ * @throws IOException In case of error.
+ */
+ char[] readCharArray() throws IOException {
+ char[] arr = in.readCharArray();
+
+ handles.assign(arr);
+
+ return arr;
+ }
+
+ /**
+ * Reads array of {@code boolean}s.
+ *
+ * @return Array.
+ * @throws IOException In case of error.
+ */
+ boolean[] readBooleanArray() throws IOException {
+ boolean[] arr = in.readBooleanArray();
+
+ handles.assign(arr);
+
+ return arr;
+ }
+
+ /**
+ * Reads {@link String}.
+ *
+ * @return String.
+ * @throws IOException In case of error.
+ */
+ public String readString() throws IOException {
+ String str = in.readUTF();
+
+ handles.assign(str);
+
+ return str;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readFully(byte[] b) throws IOException {
+ in.readFully(b);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readFully(byte[] b, int off, int len) throws IOException {
+ in.readFully(b, off, len);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int skipBytes(int n) throws IOException {
+ return in.skipBytes(n);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean readBoolean() throws IOException {
+ return in.readBoolean();
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte readByte() throws IOException {
+ return in.readByte();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int readUnsignedByte() throws IOException {
+ return in.readUnsignedByte();
+ }
+
+ /** {@inheritDoc} */
+ @Override public short readShort() throws IOException {
+ return in.readShort();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int readUnsignedShort() throws IOException {
+ return in.readUnsignedShort();
+ }
+
+ /** {@inheritDoc} */
+ @Override public char readChar() throws IOException {
+ return in.readChar();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int readInt() throws IOException {
+ return in.readInt();
+ }
+
+ /** {@inheritDoc} */
+ @Override public long readLong() throws IOException {
+ return in.readLong();
+ }
+
+ /** {@inheritDoc} */
+ @Override public float readFloat() throws IOException {
+ return in.readFloat();
+ }
+
+ /** {@inheritDoc} */
+ @Override public double readDouble() throws IOException {
+ return in.readDouble();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int read() throws IOException {
+ return in.read();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int read(byte[] b) throws IOException {
+ return in.read(b);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int read(byte[] b, int off, int len) throws IOException {
+ return in.read(b, off, len);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("deprecation")
+ @Override public String readLine() throws IOException {
+ return in.readLine();
+ }
+
+ /** {@inheritDoc} */
+ @Override public String readUTF() throws IOException {
+ return in.readUTF();
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object readUnshared() throws IOException, ClassNotFoundException {
+ return readObject();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void defaultReadObject() throws IOException, ClassNotFoundException {
+ if (curObj == null)
+ throw new NotActiveException("Not in readObject() call.");
+
+ readFields(curObj, curFields);
+ }
+
+ /** {@inheritDoc} */
+ @Override public ObjectInputStream.GetField readFields() throws IOException, ClassNotFoundException {
+ if (curObj == null)
+ throw new NotActiveException("Not in readObject() call.");
+
+ return new GetFieldImpl(this);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void registerValidation(ObjectInputValidation obj, int pri) {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public int available() throws IOException {
+ return -1;
+ }
+
+ /**
+ * Returns objects that were added to handles table.
+ * Used ONLY for test purposes.
+ *
+ * @return Handled objects.
+ */
+ Object[] handledObjects() {
+ return handles.entries;
+ }
+
+ /**
+ * Lightweight identity hash table which maps objects to integer handles,
+ * assigned in ascending order.
+ */
+ private static class HandleTable {
+ /** Array mapping handle -> object/exception (depending on status). */
+ private Object[] entries;
+
+ /** Number of handles in table. */
+ private int size;
+
+ /**
+ * Creates handle table with the given initial capacity.
+ *
+ * @param initCap Initial capacity.
+ */
+ HandleTable(int initCap) {
+ entries = new Object[initCap];
+ }
+
+ /**
+ * Assigns next available handle to given object, and returns assigned
+ * handle.
+ *
+ * @param obj Object.
+ * @return Handle.
+ */
+ int assign(Object obj) {
+ if (size >= entries.length)
+ grow();
+
+ entries[size] = obj;
+
+ return size++;
+ }
+
+ /**
+ * Assigns new object to existing handle. Old object is forgotten.
+ *
+ * @param handle Handle.
+ * @param obj Object.
+ */
+ void set(int handle, Object obj) {
+ entries[handle] = obj;
+ }
+
+ /**
+ * Looks up and returns object associated with the given handle.
+ *
+ * @param handle Handle.
+ * @return Object.
+ */
+ Object lookup(int handle) {
+ return entries[handle];
+ }
+
+ /**
+ * Resets table to its initial state.
+ */
+ void clear() {
+ Arrays.fill(entries, 0, size, null);
+
+ size = 0;
+ }
+
+ /**
+ * Expands capacity of internal arrays.
+ */
+ private void grow() {
+ int newCap = (entries.length << 1) + 1;
+
+ Object[] newEntries = new Object[newCap];
+
+ System.arraycopy(entries, 0, newEntries, 0, size);
+
+ entries = newEntries;
+ }
+ }
+
+ /**
+ * {@link GetField} implementation.
+ */
+ private static class GetFieldImpl extends GetField {
+ /** Field info. */
+ private final OptimizedClassDescriptor.ClassFields fieldInfo;
+
+ /** Values. */
+ private final Object[] objs;
+
+ /**
+ * @param in Stream.
+ * @throws IOException In case of error.
+ * @throws ClassNotFoundException If class not found.
+ */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ private GetFieldImpl(OptimizedObjectInputStream in) throws IOException, ClassNotFoundException {
+ fieldInfo = in.curFields;
+
+ objs = new Object[fieldInfo.size()];
+
+ for (int i = 0; i < fieldInfo.size(); i++) {
+ OptimizedClassDescriptor.FieldInfo t = fieldInfo.get(i);
+
+ Object obj = null;
+
+ switch (t.type()) {
+ case BYTE:
+ obj = in.readByte();
+
+ break;
+
+ case SHORT:
+ obj = in.readShort();
+
+ break;
+
+ case INT:
+ obj = in.readInt();
+
+ break;
+
+ case LONG:
+ obj = in.readLong();
+
+ break;
+
+ case FLOAT:
+ obj = in.readFloat();
+
+ break;
+
+ case DOUBLE:
+ obj = in.readDouble();
+
+ break;
+
+ case CHAR:
+ obj = in.readChar();
+
+ break;
+
+ case BOOLEAN:
+ obj = in.readBoolean();
+
+ break;
+
+ case OTHER:
+ obj = in.readObject();
+ }
+
+ objs[i] = obj;
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public ObjectStreamClass getObjectStreamClass() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean defaulted(String name) throws IOException {
+ return objs[fieldInfo.getIndex(name)] == null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean get(String name, boolean dflt) throws IOException {
+ return value(name, dflt);
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte get(String name, byte dflt) throws IOException {
+ return value(name, dflt);
+ }
+
+ /** {@inheritDoc} */
+ @Override public char get(String name, char dflt) throws IOException {
+ return value(name, dflt);
+ }
+
+ /** {@inheritDoc} */
+ @Override public short get(String name, short dflt) throws IOException {
+ return value(name, dflt);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int get(String name, int dflt) throws IOException {
+ return value(name, dflt);
+ }
+
+ /** {@inheritDoc} */
+ @Override public long get(String name, long dflt) throws IOException {
+ return value(name, dflt);
+ }
+
+ /** {@inheritDoc} */
+ @Override public float get(String name, float dflt) throws IOException {
+ return value(name, dflt);
+ }
+
+ /** {@inheritDoc} */
+ @Override public double get(String name, double dflt) throws IOException {
+ return value(name, dflt);
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object get(String name, Object dflt) throws IOException {
+ return value(name, dflt);
+ }
+
+ /**
+ * @param name Field name.
+ * @param dflt Default value.
+ * @return Value.
+ */
+ @SuppressWarnings("unchecked")
+ private <T> T value(String name, T dflt) {
+ return objs[fieldInfo.getIndex(name)] != null ? (T)objs[fieldInfo.getIndex(name)] : dflt;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java
new file mode 100644
index 0000000..bdb1b2f
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java
@@ -0,0 +1,875 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.NotActiveException;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentMap;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.util.GridHandleTable;
+import org.apache.ignite.internal.util.io.GridDataOutput;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.marshaller.MarshallerContext;
+
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.HANDLE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.JDK;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.JDK_MARSH;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.NULL;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.classDescriptor;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getBoolean;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getByte;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getChar;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getDouble;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getFloat;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getInt;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getLong;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getObject;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getShort;
+
+/**
+ * Optimized object output stream.
+ */
+class OptimizedObjectOutputStream extends ObjectOutputStream {
+ /** */
+ private final GridHandleTable handles = new GridHandleTable(10, 3.00f);
+
+ /** */
+ private final GridDataOutput out;
+
+ /** */
+ private MarshallerContext ctx;
+
+ /** */
+ private OptimizedMarshallerIdMapper mapper;
+
+ /** */
+ private boolean requireSer;
+
+ /** */
+ private Object curObj;
+
+ /** */
+ private OptimizedClassDescriptor.ClassFields curFields;
+
+ /** */
+ private PutFieldImpl curPut;
+
+ /** */
+ private ConcurrentMap<Class, OptimizedClassDescriptor> clsMap;
+
+ /**
+ * @param out Output.
+ * @throws IOException In case of error.
+ */
+ OptimizedObjectOutputStream(GridDataOutput out) throws IOException {
+ this.out = out;
+ }
+
+ /**
+ * @param clsMap Class descriptors by class map.
+ * @param ctx Context.
+ * @param mapper ID mapper.
+ * @param requireSer Require {@link Serializable} flag.
+ */
+ void context(ConcurrentMap<Class, OptimizedClassDescriptor> clsMap,
+ MarshallerContext ctx,
+ OptimizedMarshallerIdMapper mapper,
+ boolean requireSer) {
+ this.clsMap = clsMap;
+ this.ctx = ctx;
+ this.mapper = mapper;
+ this.requireSer = requireSer;
+ }
+
+ /**
+ * @return Require {@link Serializable} flag.
+ */
+ boolean requireSerializable() {
+ return requireSer;
+ }
+
+ /**
+ * @return Output.
+ */
+ public GridDataOutput out() {
+ return out;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void close() throws IOException {
+ reset();
+
+ ctx = null;
+ clsMap = null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(byte[] b) throws IOException {
+ out.write(b);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(byte[] b, int off, int len) throws IOException {
+ out.write(b, off, len);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void writeObjectOverride(Object obj) throws IOException {
+ writeObject0(obj);
+ }
+
+ /**
+ * Writes object to stream.
+ *
+ * @param obj Object.
+ * @throws IOException In case of error.
+ */
+ private void writeObject0(Object obj) throws IOException {
+ curObj = null;
+ curFields = null;
+ curPut = null;
+
+ if (obj == null)
+ writeByte(NULL);
+ else {
+ if (obj instanceof Throwable && !(obj instanceof Externalizable)) {
+ writeByte(JDK);
+
+ try {
+ JDK_MARSH.marshal(obj, this);
+ }
+ catch (IgniteCheckedException e) {
+ IOException ioEx = e.getCause(IOException.class);
+
+ if (ioEx != null)
+ throw ioEx;
+ else
+ throw new IOException("Failed to serialize object with JDK marshaller: " + obj, e);
+ }
+ }
+ else {
+ OptimizedClassDescriptor desc = classDescriptor(
+ clsMap,
+ obj instanceof Object[] ? Object[].class : obj.getClass(),
+ ctx,
+ mapper);
+
+ if (desc.excluded()) {
+ writeByte(NULL);
+
+ return;
+ }
+
+ Object obj0 = desc.replace(obj);
+
+ if (obj0 == null) {
+ writeByte(NULL);
+
+ return;
+ }
+
+ int handle = -1;
+
+ if (!desc.isPrimitive() && !desc.isEnum() && !desc.isClass() && !desc.isProxy())
+ handle = handles.lookup(obj);
+
+ if (obj0 != obj) {
+ obj = obj0;
+
+ desc = classDescriptor(clsMap,
+ obj instanceof Object[] ? Object[].class : obj.getClass(),
+ ctx,
+ mapper);
+ }
+
+ if (handle >= 0) {
+ writeByte(HANDLE);
+ writeInt(handle);
+ }
+ else
+ desc.write(this, obj);
+ }
+ }
+ }
+
+ /**
+ * Writes array to this stream.
+ *
+ * @param arr Array.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ void writeArray(Object[] arr) throws IOException {
+ int len = arr.length;
+
+ writeInt(len);
+
+ for (int i = 0; i < len; i++) {
+ Object obj = arr[i];
+
+ writeObject0(obj);
+ }
+ }
+
+ /**
+ * Writes {@link UUID} to this stream.
+ *
+ * @param uuid UUID.
+ * @throws IOException In case of error.
+ */
+ void writeUuid(UUID uuid) throws IOException {
+ writeLong(uuid.getMostSignificantBits());
+ writeLong(uuid.getLeastSignificantBits());
+ }
+
+ /**
+ * Writes {@link Properties} to this stream.
+ *
+ * @param props Properties.
+ * @param dfltsFieldOff Defaults field offset.
+ * @throws IOException In case of error.
+ */
+ void writeProperties(Properties props, long dfltsFieldOff) throws IOException {
+ Properties dflts = (Properties)getObject(props, dfltsFieldOff);
+
+ if (dflts == null)
+ writeBoolean(true);
+ else {
+ writeBoolean(false);
+
+ writeObject0(dflts);
+ }
+
+ Set<String> names = props.stringPropertyNames();
+
+ writeInt(names.size());
+
+ for (String name : names) {
+ writeUTF(name);
+ writeUTF(props.getProperty(name));
+ }
+ }
+
+ /**
+ * Writes externalizable object.
+ *
+ * @param obj Object.
+ * @throws IOException In case of error.
+ */
+ void writeExternalizable(Object obj) throws IOException {
+ Externalizable extObj = (Externalizable)obj;
+
+ extObj.writeExternal(this);
+ }
+
+ /**
+ * Writes serializable object.
+ *
+ * @param obj Object.
+ * @param mtds {@code writeObject} methods.
+ * @param fields class fields details.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ void writeSerializable(Object obj, List<Method> mtds, OptimizedClassDescriptor.Fields fields)
+ throws IOException {
+ for (int i = 0; i < mtds.size(); i++) {
+ Method mtd = mtds.get(i);
+
+ if (mtd != null) {
+ curObj = obj;
+ curFields = fields.fields(i);
+
+ try {
+ mtd.invoke(obj, this);
+ }
+ catch (IllegalAccessException e) {
+ throw new IOException(e);
+ }
+ catch (InvocationTargetException e) {
+ throw new IOException(e.getCause());
+ }
+ }
+ else
+ writeFields(obj, fields.fields(i));
+ }
+ }
+
+ /**
+ * Writes {@link ArrayList}.
+ *
+ * @param list List.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings({"ForLoopReplaceableByForEach", "TypeMayBeWeakened"})
+ void writeArrayList(ArrayList<?> list) throws IOException {
+ int size = list.size();
+
+ writeInt(size);
+
+ for (int i = 0; i < size; i++)
+ writeObject0(list.get(i));
+ }
+
+ /**
+ * Writes {@link HashMap}.
+ *
+ * @param map Map.
+ * @param loadFactorFieldOff Load factor field offset.
+ * @param set Whether writing underlying map from {@link HashSet}.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("TypeMayBeWeakened")
+ void writeHashMap(HashMap<?, ?> map, long loadFactorFieldOff, boolean set) throws IOException {
+ int size = map.size();
+
+ writeInt(size);
+ writeFloat(getFloat(map, loadFactorFieldOff));
+
+ for (Map.Entry<?, ?> e : map.entrySet()) {
+ writeObject0(e.getKey());
+
+ if (!set)
+ writeObject0(e.getValue());
+ }
+ }
+
+ /**
+ * Writes {@link HashSet}.
+ *
+ * @param set Set.
+ * @param mapFieldOff Map field offset.
+ * @param loadFactorFieldOff Load factor field offset.
+ * @throws IOException In case of error.
+ */
+ void writeHashSet(HashSet<?> set, long mapFieldOff, long loadFactorFieldOff) throws IOException {
+ writeHashMap((HashMap<?, ?>)getObject(set, mapFieldOff), loadFactorFieldOff, true);
+ }
+
+ /**
+ * Writes {@link LinkedList}.
+ *
+ * @param list List.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("TypeMayBeWeakened")
+ void writeLinkedList(LinkedList<?> list) throws IOException {
+ int size = list.size();
+
+ writeInt(size);
+
+ for (Object obj : list)
+ writeObject0(obj);
+ }
+
+ /**
+ * Writes {@link LinkedHashMap}.
+ *
+ * @param map Map.
+ * @param loadFactorFieldOff Load factor field offset.
+ * @param accessOrderFieldOff access order field offset.
+ * @param set Whether writing underlying map from {@link LinkedHashSet}.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("TypeMayBeWeakened")
+ void writeLinkedHashMap(LinkedHashMap<?, ?> map, long loadFactorFieldOff, long accessOrderFieldOff, boolean set)
+ throws IOException {
+ int size = map.size();
+
+ writeInt(size);
+ writeFloat(getFloat(map, loadFactorFieldOff));
+
+ if (accessOrderFieldOff >= 0)
+ writeBoolean(getBoolean(map, accessOrderFieldOff));
+ else
+ writeBoolean(false);
+
+ for (Map.Entry<?, ?> e : map.entrySet()) {
+ writeObject0(e.getKey());
+
+ if (!set)
+ writeObject0(e.getValue());
+ }
+ }
+
+ /**
+ * Writes {@link LinkedHashSet}.
+ *
+ * @param set Set.
+ * @param mapFieldOff Map field offset.
+ * @param loadFactorFieldOff Load factor field offset.
+ * @throws IOException In case of error.
+ */
+ void writeLinkedHashSet(LinkedHashSet<?> set, long mapFieldOff, long loadFactorFieldOff) throws IOException {
+ LinkedHashMap<?, ?> map = (LinkedHashMap<?, ?>)getObject(set, mapFieldOff);
+
+ writeLinkedHashMap(map, loadFactorFieldOff, -1, true);
+ }
+
+ /**
+ * Writes {@link Date}.
+ *
+ * @param date Date.
+ * @throws IOException In case of error.
+ */
+ void writeDate(Date date) throws IOException {
+ writeLong(date.getTime());
+ }
+
+ /**
+ * Writes all non-static and non-transient field values to this stream.
+ *
+ * @param obj Object.
+ * @param fields Fields.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ private void writeFields(Object obj, OptimizedClassDescriptor.ClassFields fields) throws IOException {
+ for (int i = 0; i < fields.size(); i++) {
+ OptimizedClassDescriptor.FieldInfo t = fields.get(i);
+
+ switch (t.type()) {
+ case BYTE:
+ if (t.field() != null)
+ writeByte(getByte(obj, t.offset()));
+
+ break;
+
+ case SHORT:
+ if (t.field() != null)
+ writeShort(getShort(obj, t.offset()));
+
+ break;
+
+ case INT:
+ if (t.field() != null)
+ writeInt(getInt(obj, t.offset()));
+
+ break;
+
+ case LONG:
+ if (t.field() != null)
+ writeLong(getLong(obj, t.offset()));
+
+ break;
+
+ case FLOAT:
+ if (t.field() != null)
+ writeFloat(getFloat(obj, t.offset()));
+
+ break;
+
+ case DOUBLE:
+ if (t.field() != null)
+ writeDouble(getDouble(obj, t.offset()));
+
+ break;
+
+ case CHAR:
+ if (t.field() != null)
+ writeChar(getChar(obj, t.offset()));
+
+ break;
+
+ case BOOLEAN:
+ if (t.field() != null)
+ writeBoolean(getBoolean(obj, t.offset()));
+
+ break;
+
+ case OTHER:
+ if (t.field() != null)
+ writeObject0(getObject(obj, t.offset()));
+ }
+ }
+ }
+
+ /**
+ * Writes array of {@code byte}s.
+ *
+ * @param arr Array.
+ * @throws IOException In case of error.
+ */
+ void writeByteArray(byte[] arr) throws IOException {
+ out.writeByteArray(arr);
+ }
+
+ /**
+ * Writes array of {@code short}s.
+ *
+ * @param arr Array.
+ * @throws IOException In case of error.
+ */
+ void writeShortArray(short[] arr) throws IOException {
+ out.writeShortArray(arr);
+ }
+
+ /**
+ * Writes array of {@code int}s.
+ *
+ * @param arr Array.
+ * @throws IOException In case of error.
+ */
+ void writeIntArray(int[] arr) throws IOException {
+ out.writeIntArray(arr);
+ }
+
+ /**
+ * Writes array of {@code long}s.
+ *
+ * @param arr Array.
+ * @throws IOException In case of error.
+ */
+ void writeLongArray(long[] arr) throws IOException {
+ out.writeLongArray(arr);
+ }
+
+ /**
+ * Writes array of {@code float}s.
+ *
+ * @param arr Array.
+ * @throws IOException In case of error.
+ */
+ void writeFloatArray(float[] arr) throws IOException {
+ out.writeFloatArray(arr);
+ }
+
+ /**
+ * Writes array of {@code double}s.
+ *
+ * @param arr Array.
+ * @throws IOException In case of error.
+ */
+ void writeDoubleArray(double[] arr) throws IOException {
+ out.writeDoubleArray(arr);
+ }
+
+ /**
+ * Writes array of {@code char}s.
+ *
+ * @param arr Array.
+ * @throws IOException In case of error.
+ */
+ void writeCharArray(char[] arr) throws IOException {
+ out.writeCharArray(arr);
+ }
+
+ /**
+ * Writes array of {@code boolean}s.
+ *
+ * @param arr Array.
+ * @throws IOException In case of error.
+ */
+ void writeBooleanArray(boolean[] arr) throws IOException {
+ out.writeBooleanArray(arr);
+ }
+
+ /**
+ * Writes {@link String}.
+ *
+ * @param str String.
+ * @throws IOException In case of error.
+ */
+ void writeString(String str) throws IOException {
+ out.writeUTF(str);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBoolean(boolean v) throws IOException {
+ out.writeBoolean(v);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeByte(int v) throws IOException {
+ out.writeByte(v);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeShort(int v) throws IOException {
+ out.writeShort(v);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeChar(int v) throws IOException {
+ out.writeChar(v);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeInt(int v) throws IOException {
+ out.writeInt(v);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeLong(long v) throws IOException {
+ out.writeLong(v);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeFloat(float v) throws IOException {
+ out.writeFloat(v);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDouble(double v) throws IOException {
+ out.writeDouble(v);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(int b) throws IOException {
+ writeByte(b);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBytes(String s) throws IOException {
+ out.writeBytes(s);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeChars(String s) throws IOException {
+ out.writeChars(s);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeUTF(String s) throws IOException {
+ out.writeUTF(s);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void useProtocolVersion(int ver) throws IOException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeUnshared(Object obj) throws IOException {
+ writeObject0(obj);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void defaultWriteObject() throws IOException {
+ if (curObj == null)
+ throw new NotActiveException("Not in writeObject() call.");
+
+ writeFields(curObj, curFields);
+ }
+
+ /** {@inheritDoc} */
+ @Override public ObjectOutputStream.PutField putFields() throws IOException {
+ if (curObj == null)
+ throw new NotActiveException("Not in writeObject() call or fields already written.");
+
+ if (curPut == null)
+ curPut = new PutFieldImpl(this);
+
+ return curPut;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeFields() throws IOException {
+ if (curObj == null)
+ throw new NotActiveException("Not in writeObject() call.");
+
+ if (curPut == null)
+ throw new NotActiveException("putFields() was not called.");
+
+ for (IgniteBiTuple<OptimizedFieldType, Object> t : curPut.objs) {
+ switch (t.get1()) {
+ case BYTE:
+ writeByte((Byte)t.get2());
+
+ break;
+
+ case SHORT:
+ writeShort((Short)t.get2());
+
+ break;
+
+ case INT:
+ writeInt((Integer)t.get2());
+
+ break;
+
+ case LONG:
+ writeLong((Long)t.get2());
+
+ break;
+
+ case FLOAT:
+ writeFloat((Float)t.get2());
+
+ break;
+
+ case DOUBLE:
+ writeDouble((Double)t.get2());
+
+ break;
+
+ case CHAR:
+ writeChar((Character)t.get2());
+
+ break;
+
+ case BOOLEAN:
+ writeBoolean((Boolean)t.get2());
+
+ break;
+
+ case OTHER:
+ writeObject0(t.get2());
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void reset() throws IOException {
+ out.reset();
+ handles.clear();
+
+ curObj = null;
+ curFields = null;
+ curPut = null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void flush() throws IOException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void drain() throws IOException {
+ // No-op.
+ }
+
+ /**
+ * Returns objects that were added to handles table.
+ * Used ONLY for test purposes.
+ *
+ * @return Handled objects.
+ */
+ Object[] handledObjects() {
+ return handles.objects();
+ }
+
+ /**
+ * {@link PutField} implementation.
+ */
+ private static class PutFieldImpl extends PutField {
+ /** Stream. */
+ private final OptimizedObjectOutputStream out;
+
+ /** Fields info. */
+ private final OptimizedClassDescriptor.ClassFields curFields;
+ /** Values. */
+ private final IgniteBiTuple<OptimizedFieldType, Object>[] objs;
+
+ /**
+ * @param out Output stream.
+ */
+ @SuppressWarnings("unchecked")
+ private PutFieldImpl(OptimizedObjectOutputStream out) {
+ this.out = out;
+
+ curFields = out.curFields;
+
+ objs = new IgniteBiTuple[curFields.size()];
+ }
+
+ /** {@inheritDoc} */
+ @Override public void put(String name, boolean val) {
+ value(name, val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void put(String name, byte val) {
+ value(name, val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void put(String name, char val) {
+ value(name, val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void put(String name, short val) {
+ value(name, val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void put(String name, int val) {
+ value(name, val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void put(String name, long val) {
+ value(name, val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void put(String name, float val) {
+ value(name, val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void put(String name, double val) {
+ value(name, val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void put(String name, Object val) {
+ value(name, val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(ObjectOutput out) throws IOException {
+ if (out != this.out)
+ throw new IllegalArgumentException("Wrong stream.");
+
+ this.out.writeFields();
+ }
+
+ /**
+ * @param name Field name.
+ * @param val Value.
+ */
+ private void value(String name, Object val) {
+ int i = curFields.getIndex(name);
+
+ OptimizedClassDescriptor.FieldInfo info = curFields.get(i);
+
+ objs[i] = F.t(info.type(), val);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamRegistry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamRegistry.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamRegistry.java
new file mode 100644
index 0000000..cc31a9f
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamRegistry.java
@@ -0,0 +1,244 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.io.IOException;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.util.io.GridUnsafeDataInput;
+import org.apache.ignite.internal.util.io.GridUnsafeDataOutput;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+/**
+ * Storage for object streams.
+ */
+class OptimizedObjectStreamRegistry {
+ /** Holders. */
+ private static final ThreadLocal<StreamHolder> holders = new ThreadLocal<>();
+
+ /** Output streams pool. */
+ private static BlockingQueue<OptimizedObjectOutputStream> outPool;
+
+ /** Input streams pool. */
+ private static BlockingQueue<OptimizedObjectInputStream> inPool;
+
+ /**
+ * Ensures singleton.
+ */
+ private OptimizedObjectStreamRegistry() {
+ // No-op.
+ }
+
+ /**
+ * Sets streams pool size.
+ *
+ * @param size Streams pool size.
+ */
+ static void poolSize(int size) {
+ if (size > 0) {
+ outPool = new LinkedBlockingQueue<>(size);
+ inPool = new LinkedBlockingQueue<>(size);
+
+ for (int i = 0; i < size; i++) {
+ outPool.offer(createOut());
+ inPool.offer(createIn());
+ }
+ }
+ else {
+ outPool = null;
+ inPool = null;
+ }
+ }
+
+ /**
+ * Gets output stream.
+ *
+ * @return Object output stream.
+ * @throws org.apache.ignite.internal.IgniteInterruptedCheckedException If thread is interrupted while trying to take holder from pool.
+ */
+ static OptimizedObjectOutputStream out() throws IgniteInterruptedCheckedException {
+ if (outPool != null) {
+ try {
+ return outPool.take();
+ }
+ catch (InterruptedException e) {
+ throw new IgniteInterruptedCheckedException(
+ "Failed to take output object stream from pool (thread interrupted).", e);
+ }
+ }
+ else
+ return holder().acquireOut();
+ }
+
+ /**
+ * Gets input stream.
+ *
+ * @return Object input stream.
+ * @throws org.apache.ignite.internal.IgniteInterruptedCheckedException If thread is interrupted while trying to take holder from pool.
+ */
+ static OptimizedObjectInputStream in() throws IgniteInterruptedCheckedException {
+ if (inPool != null) {
+ try {
+ return inPool.take();
+ }
+ catch (InterruptedException e) {
+ throw new IgniteInterruptedCheckedException(
+ "Failed to take input object stream from pool (thread interrupted).", e);
+ }
+ }
+ else
+ return holder().acquireIn();
+ }
+
+ /**
+ * Closes and releases output stream.
+ *
+ * @param out Object output stream.
+ */
+ static void closeOut(OptimizedObjectOutputStream out) {
+ U.close(out, null);
+
+ if (outPool != null) {
+ boolean b = outPool.offer(out);
+
+ assert b;
+ }
+ else {
+ StreamHolder holder = holders.get();
+
+ if (holder != null)
+ holder.releaseOut();
+ }
+ }
+
+ /**
+ * Closes and releases input stream.
+ *
+ * @param in Object input stream.
+ */
+ @SuppressWarnings("TypeMayBeWeakened")
+ static void closeIn(OptimizedObjectInputStream in) {
+ U.close(in, null);
+
+ if (inPool != null) {
+ boolean b = inPool.offer(in);
+
+ assert b;
+ }
+ else {
+ StreamHolder holder = holders.get();
+
+ if (holder != null)
+ holder.releaseIn();
+ }
+ }
+
+ /**
+ * Gets holder from pool or thread local.
+ *
+ * @return Stream holder.
+ * @throws org.apache.ignite.internal.IgniteInterruptedCheckedException If thread is interrupted while trying to take holder from pool.
+ */
+ private static StreamHolder holder() throws IgniteInterruptedCheckedException {
+ StreamHolder holder = holders.get();
+
+ if (holder == null)
+ holders.set(holder = new StreamHolder());
+
+ return holder;
+ }
+
+ /**
+ * Creates output stream.
+ *
+ * @return Object output stream.
+ */
+ private static OptimizedObjectOutputStream createOut() {
+ try {
+ return new OptimizedObjectOutputStream(new GridUnsafeDataOutput(4 * 1024));
+ }
+ catch (IOException e) {
+ throw new IgniteException("Failed to create object output stream.", e);
+ }
+ }
+
+ /**
+ * Creates input stream.
+ *
+ * @return Object input stream.
+ */
+ private static OptimizedObjectInputStream createIn() {
+ try {
+ return new OptimizedObjectInputStream(new GridUnsafeDataInput());
+ }
+ catch (IOException e) {
+ throw new IgniteException("Failed to create object input stream.", e);
+ }
+ }
+
+ /**
+ * Streams holder.
+ */
+ private static class StreamHolder {
+ /** Output stream. */
+ private final OptimizedObjectOutputStream out = createOut();
+
+ /** Input stream. */
+ private final OptimizedObjectInputStream in = createIn();
+
+ /** Output streams counter. */
+ private int outAcquireCnt;
+
+ /** Input streams counter. */
+ private int inAcquireCnt;
+
+ /**
+ * Gets output stream.
+ *
+ * @return Object output stream.
+ */
+ OptimizedObjectOutputStream acquireOut() {
+ return outAcquireCnt++ > 0 ? createOut() : out;
+ }
+
+ /**
+ * Gets input stream.
+ *
+ * @return Object input stream.
+ */
+ OptimizedObjectInputStream acquireIn() {
+ return inAcquireCnt++ > 0 ? createIn() : in;
+ }
+
+ /**
+ * Releases output stream.
+ */
+ void releaseOut() {
+ outAcquireCnt--;
+ }
+
+ /**
+ * Releases input stream.
+ */
+ void releaseIn() {
+ inAcquireCnt--;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/marshaller/Marshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/Marshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/Marshaller.java
index e99ca35..8ffeacd 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/Marshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/Marshaller.java
@@ -22,6 +22,7 @@ import java.io.OutputStream;
import org.apache.ignite.IgniteBinary;
import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.jetbrains.annotations.Nullable;
/**
@@ -33,7 +34,7 @@ import org.jetbrains.annotations.Nullable;
* <ul>
* <li>Default binary marshaller. Will be used when no other marshaller is explicitly set to the
* configuration. For more information, see {@link IgniteBinary}.</li>
- * <li>{@link org.apache.ignite.marshaller.optimized.OptimizedMarshaller}</li>
+ * <li>{@link OptimizedMarshaller}</li>
* <li>{@link org.apache.ignite.marshaller.jdk.JdkMarshaller}</li>
* </ul>
* <p>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshaller.java
index 2ecdc8e..8c27841 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshaller.java
@@ -22,6 +22,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.internal.util.io.GridByteArrayInputStream;
import org.apache.ignite.internal.util.io.GridByteArrayOutputStream;
import org.apache.ignite.internal.util.typedef.internal.S;
@@ -36,7 +37,7 @@ import org.jetbrains.annotations.Nullable;
* <h2 class="header">Mandatory</h2>
* This marshaller has no mandatory configuration parameters.
* <h2 class="header">Java Example</h2>
- * {@code JdkMarshaller} needs to be explicitly configured to override default {@link org.apache.ignite.marshaller.optimized.OptimizedMarshaller}.
+ * {@code JdkMarshaller} needs to be explicitly configured to override default {@link OptimizedMarshaller}.
* <pre name="code" class="java">
* JdkMarshaller marshaller = new JdkMarshaller();
*
[09/10] ignite git commit: IGNITE-4938: Moved OptimizedMarshaller to
private package. This closes #1793.
Posted by vo...@apache.org.
IGNITE-4938: Moved OptimizedMarshaller to private package. This closes #1793.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a1b5b8c3
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a1b5b8c3
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a1b5b8c3
Branch: refs/heads/master
Commit: a1b5b8c39c847b308c3180bc5308b0a09adf75ec
Parents: b3b5395
Author: Alexander Paschenko <al...@gmail.com>
Authored: Fri Apr 14 14:21:57 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Fri Apr 14 14:21:58 2017 +0300
----------------------------------------------------------------------
examples/config/filesystem/example-igfs.xml | 7 -
.../MemcacheRestExampleNodeStartup.java | 7 -
.../optimized/OptimizedMarshallerAopTest.java | 105 +
.../optimized/OptimizedMarshallerAopTest.java | 104 -
modules/clients/src/test/config/jdbc-config.xml | 2 +-
.../apache/ignite/IgniteSystemProperties.java | 2 +-
.../apache/ignite/internal/IgniteKernal.java | 2 +-
.../internal/binary/BinaryClassDescriptor.java | 2 +-
.../ignite/internal/binary/BinaryContext.java | 2 +-
.../GridClientOptimizedMarshaller.java | 2 +-
.../GridClientZipOptimizedMarshaller.java | 2 +-
.../optimized/OptimizedClassDescriptor.java | 1141 +++++++++
.../optimized/OptimizedFieldType.java | 50 +
.../optimized/OptimizedMarshaller.java | 313 +++
.../optimized/OptimizedMarshallerIdMapper.java | 33 +
.../optimized/OptimizedMarshallerUtils.java | 551 +++++
.../optimized/OptimizedObjectInputStream.java | 1231 ++++++++++
.../optimized/OptimizedObjectOutputStream.java | 875 +++++++
.../OptimizedObjectStreamRegistry.java | 244 ++
.../apache/ignite/marshaller/Marshaller.java | 3 +-
.../ignite/marshaller/jdk/JdkMarshaller.java | 3 +-
.../optimized/OptimizedClassDescriptor.java | 1141 ---------
.../optimized/OptimizedFieldType.java | 50 -
.../optimized/OptimizedMarshaller.java | 313 ---
.../optimized/OptimizedMarshallerIdMapper.java | 33 -
.../optimized/OptimizedMarshallerUtils.java | 551 -----
.../optimized/OptimizedObjectInputStream.java | 1231 ----------
.../optimized/OptimizedObjectOutputStream.java | 875 -------
.../OptimizedObjectStreamRegistry.java | 244 --
.../marshaller/optimized/package-info.java | 22 -
.../resources/META-INF/classnames.properties | 2 +-
modules/core/src/test/config/example-cache.xml | 2 +-
modules/core/src/test/config/igfs-loopback.xml | 2 +-
modules/core/src/test/config/igfs-shmem.xml | 2 +-
.../src/test/config/spring-start-nodes-attr.xml | 2 +-
.../core/src/test/config/spring-start-nodes.xml | 2 +-
.../config/websession/example-cache-base.xml | 2 +-
.../IgniteExternalizableAbstractTest.java | 2 +-
...dbcPojoStoreOptimizedMarshallerSelfTest.java | 2 +-
.../apache/ignite/igfs/IgfsPathSelfTest.java | 2 +-
.../internal/GridLifecycleAwareSelfTest.java | 2 +-
.../managers/GridManagerStopSelfTest.java | 2 +-
.../GridDiscoveryManagerAttributesSelfTest.java | 2 +-
.../OptimizedMarshallerEnumSelfTest.java | 87 +
.../OptimizedMarshallerNodeFailoverTest.java | 358 +++
.../OptimizedMarshallerPooledSelfTest.java | 46 +
.../optimized/OptimizedMarshallerSelfTest.java | 284 +++
...arshallerSerialPersistentFieldsSelfTest.java | 116 +
.../optimized/OptimizedMarshallerTest.java | 790 +++++++
.../OptimizedObjectStreamSelfTest.java | 2162 ++++++++++++++++++
.../TestTcpDiscoveryIpFinderAdapter.java | 43 +
.../CacheStartupInDeploymentModesTest.java | 2 +-
.../cache/GridCacheEntryMemorySizeSelfTest.java | 2 +-
...ridCacheStoreManagerDeserializationTest.java | 2 +-
.../cache/GridCacheVersionSelfTest.java | 2 +-
.../distributed/CacheAffinityEarlyTest.java | 2 +-
.../CacheGetFutureHangsSelfTest.java | 2 +-
.../IgniteCacheCreatePutMultiNodeSelfTest.java | 2 +-
.../distributed/IgniteCacheCreatePutTest.java | 2 +-
.../near/GridCacheNearTxForceKeyTest.java | 1 -
.../CacheEntryProcessorNonSerializableTest.java | 2 +-
.../igfs/IgfsAbstractBaseSelfTest.java | 2 +-
.../processors/igfs/IgfsFileInfoSelfTest.java | 2 +-
.../service/ClosureServiceClientsNodesTest.java | 2 +-
...ent2ClassLoadersOptimizedMarshallerTest.java | 2 +-
...mentClassLoadingOptimizedMarshallerTest.java | 2 +-
...namicProxySerializationMultiJvmSelfTest.java | 2 +-
.../GridMarshallerPerformanceTest.java | 2 +-
.../OptimizedMarshallerEnumSelfTest.java | 87 -
.../OptimizedMarshallerNodeFailoverTest.java | 357 ---
.../OptimizedMarshallerPooledSelfTest.java | 44 -
.../optimized/OptimizedMarshallerSelfTest.java | 283 ---
...arshallerSerialPersistentFieldsSelfTest.java | 114 -
.../optimized/OptimizedMarshallerTest.java | 790 -------
.../OptimizedObjectStreamSelfTest.java | 2157 -----------------
.../TestTcpDiscoveryIpFinderAdapter.java | 43 -
.../marshaller/optimized/package-info.java | 22 -
.../IgniteMessagingWithClientTest.java | 2 +-
...pClientDiscoveryMarshallerCheckSelfTest.java | 2 +-
.../TcpDiscoveryMarshallerCheckSelfTest.java | 2 +-
.../configvariations/ConfigVariations.java | 2 +-
.../junits/IgniteTestResources.java | 2 +-
.../testsuites/IgniteBinaryBasicTestSuite.java | 14 +-
.../IgniteMarshallerSelfTestSuite.java | 14 +-
.../webapp/META-INF/ignite-webapp-config.xml | 2 +-
.../test/config/hadoop-fs-open-test/grid-0.xml | 2 +-
.../test/config/hadoop-fs-open-test/grid-1.xml | 2 +-
.../test/config/hadoop-fs-open-test/grid-2.xml | 2 +-
.../test/config/igfs-cli-config-dual-async.xml | 2 +-
.../test/config/igfs-cli-config-dual-sync.xml | 2 +-
.../src/test/config/igfs-cli-config-primary.xml | 2 +-
.../src/test/config/igfs-cli-config-proxy.xml | 2 +-
.../IgniteHadoopFileSystemAbstractSelfTest.java | 2 +-
.../cache/IgniteCacheNoClassQuerySelfTest.java | 2 +-
.../h2/sql/AbstractH2CompareQueryTest.java | 2 +-
.../FetchingQueryCursorStressTest.java | 2 +-
.../Config/marshaller-invalid.xml | 2 +-
.../GridSpringBeanSerializationSelfTest.java | 2 +-
.../generator/ConfigurationGenerator.js | 2 +-
.../webapp2/META-INF/ignite-webapp-config.xml | 2 +-
.../ignite-int-max-values-onheap-config.xml | 2 +-
modules/yardstick/config/ignite-jdbc-config.xml | 2 +-
102 files changed, 8506 insertions(+), 8551 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/examples/config/filesystem/example-igfs.xml
----------------------------------------------------------------------
diff --git a/examples/config/filesystem/example-igfs.xml b/examples/config/filesystem/example-igfs.xml
index 2236821..454dc9f 100644
--- a/examples/config/filesystem/example-igfs.xml
+++ b/examples/config/filesystem/example-igfs.xml
@@ -50,13 +50,6 @@
Configuration below demonstrates how to setup a IgniteFs node with file data.
-->
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
- <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>
-
<property name="fileSystemConfiguration">
<list>
<bean class="org.apache.ignite.configuration.FileSystemConfiguration">
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java b/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java
index 3c835be..439e042 100644
--- a/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java
+++ b/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java
@@ -23,7 +23,6 @@ import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.ConnectorConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
@@ -64,12 +63,6 @@ public class MemcacheRestExampleNodeStartup {
cfg.setConnectorConfiguration(new ConnectorConfiguration());
- OptimizedMarshaller marsh = new OptimizedMarshaller();
-
- marsh.setRequireSerializable(false);
-
- cfg.setMarshaller(marsh);
-
CacheConfiguration cacheCfg = new CacheConfiguration();
cacheCfg.setAtomicityMode(TRANSACTIONAL);
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/aop/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerAopTest.java
----------------------------------------------------------------------
diff --git a/modules/aop/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerAopTest.java b/modules/aop/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerAopTest.java
new file mode 100644
index 0000000..a1c52ab
--- /dev/null
+++ b/modules/aop/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerAopTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.compute.gridify.Gridify;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.events.Event;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.events.EventType.EVT_TASK_FINISHED;
+
+/**
+ * Test use GridOptimizedMarshaller and AspectJ AOP.
+ *
+ * The following configuration needs to be applied to enable AspectJ byte code
+ * weaving.
+ * <ul>
+ * <li>
+ * JVM configuration should include:
+ * <tt>-javaagent:[IGNITE_HOME]/libs/aspectjweaver-1.7.2.jar</tt>
+ * </li>
+ * <li>
+ * Classpath should contain the <tt>[IGNITE_HOME]/modules/tests/config/aop/aspectj</tt> folder.
+ * </li>
+ * </ul>
+ */
+public class OptimizedMarshallerAopTest extends GridCommonAbstractTest {
+ /** */
+ private static final AtomicInteger cntr = new AtomicInteger();
+
+ /**
+ * Constructs a test.
+ */
+ public OptimizedMarshallerAopTest() {
+ super(false /* start grid. */);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ IgniteConfiguration cfg = new IgniteConfiguration();
+
+ cfg.setMarshaller(new OptimizedMarshaller());
+
+ G.start(cfg);
+
+ assert G.allGrids().size() == 1;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ assert G.allGrids().isEmpty();
+ }
+
+ /**
+ * JUnit.
+ *
+ * @throws Exception If failed.
+ */
+ public void testUp() throws Exception {
+ G.ignite().events().localListen(new IgnitePredicate<Event>() {
+ @Override public boolean apply(Event evt) {
+ cntr.incrementAndGet();
+
+ return true;
+ }
+ }, EVT_TASK_FINISHED);
+
+ gridify1();
+
+ assertEquals("Method gridify() wasn't executed on grid.", 1, cntr.get());
+ }
+
+ /**
+ * Method grid-enabled with {@link org.apache.ignite.compute.gridify.Gridify} annotation.
+ * <p>
+ * Note that default {@code Gridify} configuration is used, so this method
+ * will be executed on remote node with the same argument.
+ */
+ @Gridify
+ private void gridify1() {
+ X.println("Executes on grid");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/aop/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerAopTest.java
----------------------------------------------------------------------
diff --git a/modules/aop/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerAopTest.java b/modules/aop/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerAopTest.java
deleted file mode 100644
index 7985fb2..0000000
--- a/modules/aop/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerAopTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.optimized;
-
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.ignite.compute.gridify.Gridify;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.events.Event;
-import org.apache.ignite.internal.util.typedef.G;
-import org.apache.ignite.internal.util.typedef.X;
-import org.apache.ignite.lang.IgnitePredicate;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import static org.apache.ignite.events.EventType.EVT_TASK_FINISHED;
-
-/**
- * Test use GridOptimizedMarshaller and AspectJ AOP.
- *
- * The following configuration needs to be applied to enable AspectJ byte code
- * weaving.
- * <ul>
- * <li>
- * JVM configuration should include:
- * <tt>-javaagent:[IGNITE_HOME]/libs/aspectjweaver-1.7.2.jar</tt>
- * </li>
- * <li>
- * Classpath should contain the <tt>[IGNITE_HOME]/modules/tests/config/aop/aspectj</tt> folder.
- * </li>
- * </ul>
- */
-public class OptimizedMarshallerAopTest extends GridCommonAbstractTest {
- /** */
- private static final AtomicInteger cntr = new AtomicInteger();
-
- /**
- * Constructs a test.
- */
- public OptimizedMarshallerAopTest() {
- super(false /* start grid. */);
- }
-
- /** {@inheritDoc} */
- @Override protected void beforeTestsStarted() throws Exception {
- IgniteConfiguration cfg = new IgniteConfiguration();
-
- cfg.setMarshaller(new OptimizedMarshaller());
-
- G.start(cfg);
-
- assert G.allGrids().size() == 1;
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTestsStopped() throws Exception {
- stopAllGrids();
-
- assert G.allGrids().isEmpty();
- }
-
- /**
- * JUnit.
- *
- * @throws Exception If failed.
- */
- public void testUp() throws Exception {
- G.ignite().events().localListen(new IgnitePredicate<Event>() {
- @Override public boolean apply(Event evt) {
- cntr.incrementAndGet();
-
- return true;
- }
- }, EVT_TASK_FINISHED);
-
- gridify1();
-
- assertEquals("Method gridify() wasn't executed on grid.", 1, cntr.get());
- }
-
- /**
- * Method grid-enabled with {@link org.apache.ignite.compute.gridify.Gridify} annotation.
- * <p>
- * Note that default {@code Gridify} configuration is used, so this method
- * will be executed on remote node with the same argument.
- */
- @Gridify
- private void gridify1() {
- X.println("Executes on grid");
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/clients/src/test/config/jdbc-config.xml
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/config/jdbc-config.xml b/modules/clients/src/test/config/jdbc-config.xml
index 27d2617..7bba410 100644
--- a/modules/clients/src/test/config/jdbc-config.xml
+++ b/modules/clients/src/test/config/jdbc-config.xml
@@ -32,7 +32,7 @@
<property name="localHost" value="127.0.0.1"/>
<property name="marshaller">
- <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
+ <bean class="org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller">
<property name="requireSerializable" value="false"/>
</bean>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
index 0b4644f..1216db8 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
@@ -24,7 +24,7 @@ import java.util.Map;
import java.util.Properties;
import javax.net.ssl.HostnameVerifier;
import org.apache.ignite.lang.IgnitePredicate;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.jetbrains.annotations.Nullable;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 286ced0..c991319 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -170,7 +170,7 @@ import org.apache.ignite.lifecycle.LifecycleAware;
import org.apache.ignite.lifecycle.LifecycleBean;
import org.apache.ignite.lifecycle.LifecycleEventType;
import org.apache.ignite.marshaller.MarshallerExclusions;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.mxbean.ClusterLocalNodeMetricsMXBean;
import org.apache.ignite.mxbean.IgniteMXBean;
import org.apache.ignite.mxbean.StripedExecutorMXBean;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
index 92e4874..f6e637f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
@@ -48,7 +48,7 @@ import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.MarshallerExclusions;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.jetbrains.annotations.Nullable;
import static org.apache.ignite.internal.processors.query.QueryUtils.isGeometryClass;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
index 1ce2d65..f339253 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
@@ -87,7 +87,7 @@ import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.marshaller.MarshallerContext;
import org.apache.ignite.marshaller.MarshallerUtils;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.jetbrains.annotations.Nullable;
import org.jsr166.ConcurrentHashMap8;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientOptimizedMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientOptimizedMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientOptimizedMarshaller.java
index 6a4b5e8..75f1807 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientOptimizedMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientOptimizedMarshaller.java
@@ -26,7 +26,7 @@ import org.apache.ignite.internal.MarshallerContextImpl;
import org.apache.ignite.internal.client.marshaller.GridClientMarshaller;
import org.apache.ignite.internal.processors.rest.client.message.GridClientMessage;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.plugin.PluginProvider;
import org.jetbrains.annotations.Nullable;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientZipOptimizedMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientZipOptimizedMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientZipOptimizedMarshaller.java
index b709634..bc8220f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientZipOptimizedMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientZipOptimizedMarshaller.java
@@ -31,7 +31,7 @@ import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.client.marshaller.GridClientMarshaller;
import org.apache.ignite.internal.processors.rest.client.message.GridClientMessage;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.plugin.PluginProvider;
import org.jetbrains.annotations.Nullable;
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedClassDescriptor.java
new file mode 100644
index 0000000..4c0ce17
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedClassDescriptor.java
@@ -0,0 +1,1141 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteProductVersion;
+import org.apache.ignite.marshaller.MarshallerContext;
+import org.apache.ignite.marshaller.MarshallerExclusions;
+import org.apache.ignite.internal.util.SerializableTransient;
+import org.apache.ignite.marshaller.MarshallerUtils;
+
+import static java.lang.reflect.Modifier.isFinal;
+import static java.lang.reflect.Modifier.isPrivate;
+import static java.lang.reflect.Modifier.isStatic;
+import static java.lang.reflect.Modifier.isTransient;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.ARRAY_LIST;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.BOOLEAN;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.BOOLEAN_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.BYTE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.BYTE_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.CHAR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.CHAR_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.CLS;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.DATE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.DOUBLE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.DOUBLE_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.ENUM;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.EXTERNALIZABLE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.FLOAT;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.FLOAT_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.HASH_MAP;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.HASH_SET;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.HASH_SET_MAP_OFF;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.INT;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.INT_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.LINKED_HASH_MAP;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.LINKED_HASH_SET;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.LINKED_LIST;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.LONG;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.LONG_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.OBJ_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.PROPS;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.PROXY;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.SERIALIZABLE;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.SHORT;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.SHORT_ARR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.STR;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.UUID;
+import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.computeSerialVersionUid;
+
+/**
+ * Class descriptor.
+ */
+class OptimizedClassDescriptor {
+ /** Class. */
+ private final Class<?> cls;
+
+ /** Context. */
+ private final MarshallerContext ctx;
+
+ /** */
+ private ConcurrentMap<Class, OptimizedClassDescriptor> clsMap;
+
+ /** ID mapper. */
+ private final OptimizedMarshallerIdMapper mapper;
+
+ /** Class name. */
+ private final String name;
+
+ /** Type ID. */
+ private final int typeId;
+
+ /** Short ID. */
+ private final short checksum;
+
+ /** Class type. */
+ private int type;
+
+ /** Primitive flag. */
+ private boolean isPrimitive;
+
+ /** Enum flag. */
+ private boolean isEnum;
+
+ /** Serializable flag. */
+ private boolean isSerial;
+
+ /** Excluded flag. */
+ private boolean excluded;
+
+ /** {@code True} if descriptor is for {@link Class}. */
+ private boolean isCls;
+
+ /** Enumeration values. */
+ private Object[] enumVals;
+
+ /** Constructor. */
+ private Constructor<?> constructor;
+
+ /** Fields. */
+ private Fields fields;
+
+ /** {@code writeObject} methods. */
+ private List<Method> writeObjMtds;
+
+ /** {@code writeReplace} method. */
+ private Method writeReplaceMtd;
+
+ /** {@code readObject} methods. */
+ private List<Method> readObjMtds;
+
+ /** {@code readResolve} method. */
+ private Method readResolveMtd;
+
+ /** Defaults field offset. */
+ private long dfltsFieldOff;
+
+ /** Load factor field offset. */
+ private long loadFactorFieldOff;
+
+ /** Access order field offset. */
+ private long accessOrderFieldOff;
+
+ /** Proxy interfaces. */
+ private Class<?>[] proxyIntfs;
+
+ /** Method returns serializable transient fields. */
+ private Method serTransMtd;
+
+ /**
+ * Creates descriptor for class.
+ *
+ * @param typeId Type ID.
+ * @param clsMap Class descriptors by class map.
+ * @param cls Class.
+ * @param ctx Context.
+ * @param mapper ID mapper.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ OptimizedClassDescriptor(Class<?> cls,
+ int typeId,
+ ConcurrentMap<Class, OptimizedClassDescriptor> clsMap,
+ MarshallerContext ctx,
+ OptimizedMarshallerIdMapper mapper)
+ throws IOException {
+ this.cls = cls;
+ this.typeId = typeId;
+ this.clsMap = clsMap;
+ this.ctx = ctx;
+ this.mapper = mapper;
+
+ name = cls.getName();
+
+ excluded = MarshallerExclusions.isExcluded(cls);
+
+ if (!excluded) {
+ Class<?> parent;
+
+ if (cls == byte.class || cls == Byte.class) {
+ type = BYTE;
+
+ isPrimitive = true;
+ }
+ else if (cls == short.class || cls == Short.class) {
+ type = SHORT;
+
+ isPrimitive = true;
+ }
+ else if (cls == int.class || cls == Integer.class) {
+ type = INT;
+
+ isPrimitive = true;
+ }
+ else if (cls == long.class || cls == Long.class) {
+ type = LONG;
+
+ isPrimitive = true;
+ }
+ else if (cls == float.class || cls == Float.class) {
+ type = FLOAT;
+
+ isPrimitive = true;
+ }
+ else if (cls == double.class || cls == Double.class) {
+ type = DOUBLE;
+
+ isPrimitive = true;
+ }
+ else if (cls == char.class || cls == Character.class) {
+ type = CHAR;
+
+ isPrimitive = true;
+ }
+ else if (cls == boolean.class || cls == Boolean.class) {
+ type = BOOLEAN;
+
+ isPrimitive = true;
+ }
+ else if (cls == byte[].class)
+ type = BYTE_ARR;
+ else if (cls == short[].class)
+ type = SHORT_ARR;
+ else if (cls == int[].class)
+ type = INT_ARR;
+ else if (cls == long[].class)
+ type = LONG_ARR;
+ else if (cls == float[].class)
+ type = FLOAT_ARR;
+ else if (cls == double[].class)
+ type = DOUBLE_ARR;
+ else if (cls == char[].class)
+ type = CHAR_ARR;
+ else if (cls == boolean[].class)
+ type = BOOLEAN_ARR;
+ else if (cls.isArray())
+ type = OBJ_ARR;
+ else if (cls == String.class)
+ type = STR;
+ else if (cls.isEnum()) {
+ type = ENUM;
+
+ isEnum = true;
+ enumVals = cls.getEnumConstants();
+ }
+ // Support for enum constants, based on anonymous children classes.
+ else if ((parent = cls.getSuperclass()) != null && parent.isEnum()) {
+ type = ENUM;
+
+ isEnum = true;
+ enumVals = parent.getEnumConstants();
+ }
+ else if (cls == UUID.class)
+ type = UUID;
+ else if (cls == Properties.class) {
+ type = PROPS;
+
+ try {
+ dfltsFieldOff = GridUnsafe.objectFieldOffset(Properties.class.getDeclaredField("defaults"));
+ }
+ catch (NoSuchFieldException e) {
+ throw new IOException(e);
+ }
+ }
+ else if (cls == ArrayList.class)
+ type = ARRAY_LIST;
+ else if (cls == HashMap.class) {
+ type = HASH_MAP;
+
+ try {
+ loadFactorFieldOff = GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
+ }
+ catch (NoSuchFieldException e) {
+ throw new IOException(e);
+ }
+ }
+ else if (cls == HashSet.class) {
+ type = HASH_SET;
+
+ try {
+ loadFactorFieldOff = GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
+ }
+ catch (NoSuchFieldException e) {
+ throw new IOException(e);
+ }
+ }
+ else if (cls == LinkedList.class)
+ type = LINKED_LIST;
+ else if (cls == LinkedHashMap.class) {
+ type = LINKED_HASH_MAP;
+
+ try {
+ loadFactorFieldOff =
+ GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
+ accessOrderFieldOff =
+ GridUnsafe.objectFieldOffset(LinkedHashMap.class.getDeclaredField("accessOrder"));
+ }
+ catch (NoSuchFieldException e) {
+ throw new IOException(e);
+ }
+ }
+ else if (cls == LinkedHashSet.class) {
+ type = LINKED_HASH_SET;
+
+ try {
+ loadFactorFieldOff = GridUnsafe.objectFieldOffset(HashMap.class.getDeclaredField("loadFactor"));
+ }
+ catch (NoSuchFieldException e) {
+ throw new IOException(e);
+ }
+ }
+ else if (cls == Date.class)
+ type = DATE;
+ else if (cls == Class.class) {
+ type = CLS;
+
+ isCls = true;
+ }
+ else if (Proxy.class.isAssignableFrom(cls)) {
+ type = PROXY;
+
+ proxyIntfs = cls.getInterfaces();
+ }
+ else {
+ Class<?> c = cls;
+
+ while ((writeReplaceMtd == null || readResolveMtd == null) && c != null && !c.equals(Object.class)) {
+ if (writeReplaceMtd == null) {
+ try {
+ writeReplaceMtd = c.getDeclaredMethod("writeReplace");
+
+ if (!isStatic(writeReplaceMtd.getModifiers()) &&
+ !(isPrivate(writeReplaceMtd.getModifiers()) && c != cls) &&
+ writeReplaceMtd.getReturnType().equals(Object.class))
+ writeReplaceMtd.setAccessible(true);
+ else
+ // Set method back to null if it has incorrect signature.
+ writeReplaceMtd = null;
+ }
+ catch (NoSuchMethodException ignored) {
+ // No-op.
+ }
+ }
+
+ if (readResolveMtd == null) {
+ try {
+ readResolveMtd = c.getDeclaredMethod("readResolve");
+
+ if (!isStatic(readResolveMtd.getModifiers()) &&
+ !(isPrivate(readResolveMtd.getModifiers()) && c != cls) &&
+ readResolveMtd.getReturnType().equals(Object.class))
+ readResolveMtd.setAccessible(true);
+ else
+ // Set method back to null if it has incorrect signature.
+ readResolveMtd = null;
+ }
+ catch (NoSuchMethodException ignored) {
+ // No-op.
+ }
+ }
+
+ c = c.getSuperclass();
+ }
+
+ if (Externalizable.class.isAssignableFrom(cls)) {
+ type = EXTERNALIZABLE;
+
+ try {
+ constructor = !Modifier.isStatic(cls.getModifiers()) && cls.getDeclaringClass() != null ?
+ cls.getDeclaredConstructor(cls.getDeclaringClass()) :
+ cls.getDeclaredConstructor();
+
+ constructor.setAccessible(true);
+ }
+ catch (NoSuchMethodException e) {
+ throw new IOException("Externalizable class doesn't have default constructor: " + cls, e);
+ }
+ }
+ else {
+ type = SERIALIZABLE;
+
+ isSerial = Serializable.class.isAssignableFrom(cls);
+
+ writeObjMtds = new ArrayList<>();
+ readObjMtds = new ArrayList<>();
+ List<ClassFields> fields = new ArrayList<>();
+
+ for (c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
+ Method mtd;
+
+ try {
+ mtd = c.getDeclaredMethod("writeObject", ObjectOutputStream.class);
+
+ int mod = mtd.getModifiers();
+
+ if (!isStatic(mod) && isPrivate(mod) && mtd.getReturnType() == Void.TYPE)
+ mtd.setAccessible(true);
+ else
+ // Set method back to null if it has incorrect signature.
+ mtd = null;
+ }
+ catch (NoSuchMethodException ignored) {
+ mtd = null;
+ }
+
+ writeObjMtds.add(mtd);
+
+ try {
+ mtd = c.getDeclaredMethod("readObject", ObjectInputStream.class);
+
+ int mod = mtd.getModifiers();
+
+ if (!isStatic(mod) && isPrivate(mod) && mtd.getReturnType() == Void.TYPE)
+ mtd.setAccessible(true);
+ else
+ // Set method back to null if it has incorrect signature.
+ mtd = null;
+ }
+ catch (NoSuchMethodException ignored) {
+ mtd = null;
+ }
+
+ readObjMtds.add(mtd);
+
+ final SerializableTransient serTransAn = c.getAnnotation(SerializableTransient.class);
+
+ // Custom serialization policy for transient fields.
+ if (serTransAn != null) {
+ try {
+ serTransMtd = c.getDeclaredMethod(serTransAn.methodName(), cls, IgniteProductVersion.class);
+
+ int mod = serTransMtd.getModifiers();
+
+ if (isStatic(mod) && isPrivate(mod)
+ && serTransMtd.getReturnType() == String[].class)
+ serTransMtd.setAccessible(true);
+ else
+ // Set method back to null if it has incorrect signature.
+ serTransMtd = null;
+ }
+ catch (NoSuchMethodException ignored) {
+ serTransMtd = null;
+ }
+ }
+
+ Field[] clsFields0 = c.getDeclaredFields();
+
+ Map<String, Field> fieldNames = new HashMap<>();
+
+ for (Field f : clsFields0)
+ fieldNames.put(f.getName(), f);
+
+ List<FieldInfo> clsFields = new ArrayList<>(clsFields0.length);
+
+ boolean hasSerialPersistentFields = false;
+
+ try {
+ Field serFieldsDesc = c.getDeclaredField("serialPersistentFields");
+
+ int mod = serFieldsDesc.getModifiers();
+
+ if (serFieldsDesc.getType() == ObjectStreamField[].class &&
+ isPrivate(mod) && isStatic(mod) && isFinal(mod)) {
+ hasSerialPersistentFields = true;
+
+ serFieldsDesc.setAccessible(true);
+
+ ObjectStreamField[] serFields = (ObjectStreamField[]) serFieldsDesc.get(null);
+
+ for (int i = 0; i < serFields.length; i++) {
+ ObjectStreamField serField = serFields[i];
+
+ FieldInfo fieldInfo;
+
+ if (!fieldNames.containsKey(serField.getName())) {
+ fieldInfo = new FieldInfo(null,
+ serField.getName(),
+ -1,
+ fieldType(serField.getType()));
+ }
+ else {
+ Field f = fieldNames.get(serField.getName());
+
+ fieldInfo = new FieldInfo(f,
+ serField.getName(),
+ GridUnsafe.objectFieldOffset(f),
+ fieldType(serField.getType()));
+ }
+
+ clsFields.add(fieldInfo);
+ }
+ }
+ }
+ catch (NoSuchFieldException ignored) {
+ // No-op.
+ }
+ catch (IllegalAccessException e) {
+ throw new IOException("Failed to get value of 'serialPersistentFields' field in class: " +
+ cls.getName(), e);
+ }
+
+ if (!hasSerialPersistentFields) {
+ for (int i = 0; i < clsFields0.length; i++) {
+ Field f = clsFields0[i];
+
+ int mod = f.getModifiers();
+
+ if (!isStatic(mod) && !isTransient(mod)) {
+ FieldInfo fieldInfo = new FieldInfo(f, f.getName(),
+ GridUnsafe.objectFieldOffset(f), fieldType(f.getType()));
+
+ clsFields.add(fieldInfo);
+ }
+ }
+ }
+
+ Collections.sort(clsFields, new Comparator<FieldInfo>() {
+ @Override public int compare(FieldInfo t1, FieldInfo t2) {
+ return t1.name().compareTo(t2.name());
+ }
+ });
+
+ fields.add(new ClassFields(clsFields));
+ }
+
+ Collections.reverse(writeObjMtds);
+ Collections.reverse(readObjMtds);
+ Collections.reverse(fields);
+
+ this.fields = new Fields(fields);
+ }
+ }
+ }
+
+ checksum = computeSerialVersionUid(cls, fields != null ? fields.ownFields() : null);
+ }
+
+ /**
+ * @return Excluded flag.
+ */
+ boolean excluded() {
+ return excluded;
+ }
+
+ /**
+ * @return Class.
+ */
+ Class<?> describedClass() {
+ return cls;
+ }
+
+ /**
+ * @return Primitive flag.
+ */
+ boolean isPrimitive() {
+ return isPrimitive;
+ }
+
+ /**
+ * @return Enum flag.
+ */
+ boolean isEnum() {
+ return isEnum;
+ }
+
+ /**
+ * @return {@code True} if descriptor is for {@link Class}.
+ */
+ boolean isClass() {
+ return isCls;
+ }
+
+ /**
+ * @return {@code True} if descriptor is for {@link Proxy}.
+ */
+ boolean isProxy() {
+ return type == PROXY;
+ }
+
+ /**
+ * Replaces object.
+ *
+ * @param obj Object.
+ * @return Replaced object or {@code null} if there is no {@code writeReplace} method.
+ * @throws IOException In case of error.
+ */
+ Object replace(Object obj) throws IOException {
+ if (writeReplaceMtd != null) {
+ try {
+ return writeReplaceMtd.invoke(obj);
+ }
+ catch (IllegalAccessException | InvocationTargetException e) {
+ throw new IOException(e);
+ }
+ }
+
+ return obj;
+ }
+
+ /**
+ * Writes object to stream.
+ *
+ * @param out Output stream.
+ * @param obj Object.
+ * @throws IOException In case of error.
+ */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ void write(OptimizedObjectOutputStream out, Object obj) throws IOException {
+ out.write(type);
+
+ switch (type) {
+ case BYTE:
+ out.writeByte((Byte)obj);
+
+ break;
+
+ case SHORT:
+ out.writeShort((Short)obj);
+
+ break;
+
+ case INT:
+ out.writeInt((Integer)obj);
+
+ break;
+
+ case LONG:
+ out.writeLong((Long)obj);
+
+ break;
+
+ case FLOAT:
+ out.writeFloat((Float)obj);
+
+ break;
+
+ case DOUBLE:
+ out.writeDouble((Double)obj);
+
+ break;
+
+ case CHAR:
+ out.writeChar((Character)obj);
+
+ break;
+
+ case BOOLEAN:
+ out.writeBoolean((Boolean)obj);
+
+ break;
+
+ case BYTE_ARR:
+ out.writeByteArray((byte[])obj);
+
+ break;
+
+ case SHORT_ARR:
+ out.writeShortArray((short[])obj);
+
+ break;
+
+ case INT_ARR:
+ out.writeIntArray((int[])obj);
+
+ break;
+
+ case LONG_ARR:
+ out.writeLongArray((long[])obj);
+
+ break;
+
+ case FLOAT_ARR:
+ out.writeFloatArray((float[])obj);
+
+ break;
+
+ case DOUBLE_ARR:
+ out.writeDoubleArray((double[])obj);
+
+ break;
+
+ case CHAR_ARR:
+ out.writeCharArray((char[])obj);
+
+ break;
+
+ case BOOLEAN_ARR:
+ out.writeBooleanArray((boolean[])obj);
+
+ break;
+
+ case OBJ_ARR:
+ OptimizedClassDescriptor compDesc = OptimizedMarshallerUtils.classDescriptor(clsMap,
+ obj.getClass().getComponentType(),
+ ctx,
+ mapper);
+
+ compDesc.writeTypeData(out);
+
+ out.writeArray((Object[])obj);
+
+ break;
+
+ case STR:
+ out.writeString((String)obj);
+
+ break;
+
+ case UUID:
+ out.writeUuid((UUID)obj);
+
+ break;
+
+ case PROPS:
+ out.writeProperties((Properties)obj, dfltsFieldOff);
+
+ break;
+
+ case ARRAY_LIST:
+ out.writeArrayList((ArrayList<?>)obj);
+
+ break;
+
+ case HASH_MAP:
+ out.writeHashMap((HashMap<?, ?>)obj, loadFactorFieldOff, false);
+
+ break;
+
+ case HASH_SET:
+ out.writeHashSet((HashSet<?>)obj, HASH_SET_MAP_OFF, loadFactorFieldOff);
+
+ break;
+
+ case LINKED_LIST:
+ out.writeLinkedList((LinkedList<?>)obj);
+
+ break;
+
+ case LINKED_HASH_MAP:
+ out.writeLinkedHashMap((LinkedHashMap<?, ?>)obj, loadFactorFieldOff, accessOrderFieldOff, false);
+
+ break;
+
+ case LINKED_HASH_SET:
+ out.writeLinkedHashSet((LinkedHashSet<?>)obj, HASH_SET_MAP_OFF, loadFactorFieldOff);
+
+ break;
+
+ case DATE:
+ out.writeDate((Date)obj);
+
+ break;
+
+ case CLS:
+ OptimizedClassDescriptor clsDesc = OptimizedMarshallerUtils.classDescriptor(clsMap, (Class<?>)obj, ctx, mapper);
+
+ clsDesc.writeTypeData(out);
+
+ break;
+
+ case PROXY:
+ out.writeInt(proxyIntfs.length);
+
+ for (Class<?> intf : proxyIntfs) {
+ OptimizedClassDescriptor intfDesc = OptimizedMarshallerUtils.classDescriptor(clsMap, intf, ctx, mapper);
+
+ intfDesc.writeTypeData(out);
+ }
+
+ InvocationHandler ih = Proxy.getInvocationHandler(obj);
+
+ assert ih != null;
+
+ out.writeObject(ih);
+
+ break;
+
+ case ENUM:
+ writeTypeData(out);
+
+ out.writeInt(((Enum)obj).ordinal());
+
+ break;
+
+ case EXTERNALIZABLE:
+ writeTypeData(out);
+
+ out.writeShort(checksum);
+ out.writeExternalizable(obj);
+
+ break;
+
+ case SERIALIZABLE:
+ if (out.requireSerializable() && !isSerial)
+ throw new NotSerializableException("Must implement java.io.Serializable or " +
+ "set OptimizedMarshaller.setRequireSerializable() to false " +
+ "(note that performance may degrade if object is not Serializable): " + name);
+
+ writeTypeData(out);
+
+ out.writeShort(checksum);
+ out.writeSerializable(obj, writeObjMtds, serializableFields(obj.getClass(), obj, null));
+
+ break;
+
+ default:
+ throw new IllegalStateException("Invalid class type: " + type);
+ }
+ }
+
+ /**
+ * Gets list of serializable fields. If {@link #serTransMtd} method
+ * returns list of transient fields, they will be added to other fields.
+ * Transient fields that are not included in that list will be normally
+ * ignored.
+ *
+ * @param cls Class.
+ * @param obj Object.
+ * @param ver Job sender version.
+ * @return Serializable fields.
+ */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ private Fields serializableFields(Class<?> cls, Object obj, IgniteProductVersion ver) {
+ if (serTransMtd == null)
+ return fields;
+
+ try {
+ final String[] transFields = (String[])serTransMtd.invoke(cls, obj, ver);
+
+ if (transFields == null || transFields.length == 0)
+ return fields;
+
+ List<FieldInfo> clsFields = new ArrayList<>();
+
+ clsFields.addAll(fields.fields.get(0).fields);
+
+ for (int i = 0; i < transFields.length; i++) {
+ final String fieldName = transFields[i];
+
+ final Field f = cls.getDeclaredField(fieldName);
+
+ FieldInfo fieldInfo = new FieldInfo(f, f.getName(),
+ GridUnsafe.objectFieldOffset(f), fieldType(f.getType()));
+
+ clsFields.add(fieldInfo);
+ }
+
+ Collections.sort(clsFields, new Comparator<FieldInfo>() {
+ @Override public int compare(FieldInfo t1, FieldInfo t2) {
+ return t1.name().compareTo(t2.name());
+ }
+ });
+
+ List<ClassFields> fields = new ArrayList<>();
+
+ fields.add(new ClassFields(clsFields));
+
+ return new Fields(fields);
+ }
+ catch (Exception ignored) {
+ return fields;
+ }
+ }
+
+ /**
+ * @param out Output stream.
+ * @throws IOException In case of error.
+ */
+ void writeTypeData(OptimizedObjectOutputStream out) throws IOException {
+ out.writeInt(typeId);
+
+ if (typeId == 0)
+ out.writeUTF(name);
+ }
+
+ /**
+ * Reads object from stream.
+ *
+ * @param in Input stream.
+ * @return Object.
+ * @throws ClassNotFoundException If class not found.
+ * @throws IOException In case of error.
+ */
+ Object read(OptimizedObjectInputStream in) throws ClassNotFoundException, IOException {
+ switch (type) {
+ case ENUM:
+ return enumVals[in.readInt()];
+
+ case EXTERNALIZABLE:
+ verifyChecksum(in.readShort());
+
+ return in.readExternalizable(constructor, readResolveMtd);
+
+ case SERIALIZABLE:
+ verifyChecksum(in.readShort());
+
+ // If no serialize method, then unmarshal as usual.
+ if (serTransMtd != null)
+ return in.readSerializable(cls, readObjMtds, readResolveMtd,
+ serializableFields(cls, null, MarshallerUtils.jobSenderVersion()));
+ else
+ return in.readSerializable(cls, readObjMtds, readResolveMtd, fields);
+
+ default:
+ assert false : "Unexpected type: " + type;
+
+ return null;
+ }
+ }
+
+ /**
+ * @param checksum Checksum.
+ * @throws ClassNotFoundException If checksum is wrong.
+ * @throws IOException In case of error.
+ */
+ private void verifyChecksum(short checksum) throws ClassNotFoundException, IOException {
+ if (checksum != this.checksum)
+ throw new ClassNotFoundException("Optimized stream class checksum mismatch " +
+ "(is same version of marshalled class present on all nodes?) " +
+ "[expected=" + this.checksum + ", actual=" + checksum + ", cls=" + cls + ']');
+ }
+
+ /**
+ * @param cls Class.
+ * @return Type.
+ */
+ @SuppressWarnings("IfMayBeConditional")
+ private OptimizedFieldType fieldType(Class<?> cls) {
+ OptimizedFieldType type;
+
+ if (cls == byte.class)
+ type = OptimizedFieldType.BYTE;
+ else if (cls == short.class)
+ type = OptimizedFieldType.SHORT;
+ else if (cls == int.class)
+ type = OptimizedFieldType.INT;
+ else if (cls == long.class)
+ type = OptimizedFieldType.LONG;
+ else if (cls == float.class)
+ type = OptimizedFieldType.FLOAT;
+ else if (cls == double.class)
+ type = OptimizedFieldType.DOUBLE;
+ else if (cls == char.class)
+ type = OptimizedFieldType.CHAR;
+ else if (cls == boolean.class)
+ type = OptimizedFieldType.BOOLEAN;
+ else
+ type = OptimizedFieldType.OTHER;
+
+ return type;
+ }
+
+ /**
+ * Information about one field.
+ */
+ @SuppressWarnings("PackageVisibleInnerClass")
+ static class FieldInfo {
+ /** Field. */
+ private final Field field;
+
+ /** Field offset. */
+ private final long fieldOffs;
+
+ /** Field type. */
+ private final OptimizedFieldType fieldType;
+
+ /** Field name. */
+ private final String fieldName;
+
+ /**
+ * @param field Field.
+ * @param name Field name.
+ * @param offset Field offset.
+ * @param type Grid optimized field type.
+ */
+ FieldInfo(Field field, String name, long offset, OptimizedFieldType type) {
+ this.field = field;
+ fieldOffs = offset;
+ fieldType = type;
+ fieldName = name;
+ }
+
+ /**
+ * @return Returns field.
+ */
+ Field field() {
+ return field;
+ }
+
+ /**
+ * @return Offset.
+ */
+ long offset() {
+ return fieldOffs;
+ }
+
+ /**
+ * @return Type.
+ */
+ OptimizedFieldType type() {
+ return fieldType;
+ }
+
+ /**
+ * @return Name.
+ */
+ String name() {
+ return fieldName;
+ }
+ }
+
+ /**
+ * Information about one class.
+ */
+ static class ClassFields {
+ /** Fields. */
+ private final List<FieldInfo> fields;
+
+ private final Map<String, Integer> nameToIndex;
+
+ /**
+ * @param fields Field infos.
+ */
+ ClassFields(List<FieldInfo> fields) {
+ this.fields = fields;
+
+ nameToIndex = U.newHashMap(fields.size());
+
+ for (int i = 0; i < fields.size(); ++i)
+ nameToIndex.put(fields.get(i).name(), i);
+ }
+
+ /**
+ * @return Class fields.
+ */
+ List<FieldInfo> fields() {
+ return fields;
+ }
+
+ /**
+ * @return Fields count.
+ */
+ int size() {
+ return fields.size();
+ }
+
+ /**
+ * @param i Field's index.
+ * @return FieldInfo.
+ */
+ FieldInfo get(int i) {
+ return fields.get(i);
+ }
+
+ /**
+ * @param name Field's name.
+ * @return Field's index.
+ */
+ int getIndex(String name) {
+ assert nameToIndex.containsKey(name);
+
+ return nameToIndex.get(name);
+ }
+ }
+
+ /**
+ * Encapsulates data about class fields.
+ */
+ @SuppressWarnings("PackageVisibleInnerClass")
+ static class Fields {
+ /** Fields. */
+ private final List<ClassFields> fields;
+
+ /** Own fields (excluding inherited). */
+ private final List<Field> ownFields;
+
+ /**
+ * Creates new instance.
+ *
+ * @param fields Fields.
+ */
+ Fields(List<ClassFields> fields) {
+ this.fields = fields;
+
+ if (fields.isEmpty())
+ ownFields = null;
+ else {
+ ownFields = new ArrayList<>(fields.size());
+
+ for (FieldInfo f : fields.get(fields.size() - 1).fields()) {
+ if (f.field() != null)
+ ownFields.add(f.field);
+ }
+ }
+ }
+
+ /**
+ * Returns class's own fields (excluding inherited).
+ *
+ * @return List of fields or {@code null} if fields list is empty.
+ */
+ List<Field> ownFields() {
+ return ownFields;
+ }
+
+ /**
+ * Returns field types and their offsets.
+ *
+ * @param i hierarchy level where 0 corresponds to top level.
+ * @return list of pairs where first value is field type and second value is its offset.
+ */
+ ClassFields fields(int i) {
+ return fields.get(i);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedFieldType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedFieldType.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedFieldType.java
new file mode 100644
index 0000000..39cad13
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedFieldType.java
@@ -0,0 +1,50 @@
+/*
+ * 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.marshaller.optimized;
+
+/**
+ * Field type used to calculate {@code Unsafe} offsets into objects.
+ */
+enum OptimizedFieldType {
+ /** */
+ BYTE,
+
+ /** */
+ SHORT,
+
+ /** */
+ INT,
+
+ /** */
+ LONG,
+
+ /** */
+ FLOAT,
+
+ /** */
+ DOUBLE,
+
+ /** */
+ CHAR,
+
+ /** */
+ BOOLEAN,
+
+ /** */
+ OTHER
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java
new file mode 100644
index 0000000..3f40d63
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshaller.java
@@ -0,0 +1,313 @@
+/*
+ * 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.marshaller.optimized;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.concurrent.ConcurrentMap;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+import sun.misc.Unsafe;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID;
+
+/**
+ * Optimized implementation of {@link org.apache.ignite.marshaller.Marshaller}.
+ * Unlike {@link org.apache.ignite.marshaller.jdk.JdkMarshaller},
+ * which is based on standard {@link ObjectOutputStream}, this marshaller does not
+ * enforce that all serialized objects implement {@link Serializable} interface. It is also
+ * about 20 times faster as it removes lots of serialization overhead that exists in
+ * default JDK implementation.
+ * <p>
+ * {@code OptimizedMarshaller} is tested only on Java HotSpot VM on other VMs
+ * it could yield unexpected results. It is the default marshaller on Java HotSpot VMs
+ * and will be used if no other marshaller was explicitly configured.
+ * <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">
+ * OptimizedMarshaller marshaller = new OptimizedMarshaller();
+ *
+ * // Enforce Serializable interface.
+ * marshaller.setRequireSerializable(true);
+ *
+ * IgniteConfiguration cfg = new IgniteConfiguration();
+ *
+ * // Override marshaller.
+ * cfg.setMarshaller(marshaller);
+ *
+ * // Starts grid.
+ * G.start(cfg);
+ * </pre>
+ * <h2 class="header">Spring Example</h2>
+ * GridOptimizedMarshaller 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.internal.marshaller.optimized.OptimizedMarshaller">
+ * <property name="requireSerializable">true</property>
+ * </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 OptimizedMarshaller extends AbstractNodeNameAwareMarshaller {
+ /** Use default {@code serialVersionUID} for {@link Serializable} classes. */
+ public static final boolean USE_DFLT_SUID =
+ IgniteSystemProperties.getBoolean(IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID, false);
+
+ /** Default class loader. */
+ private final ClassLoader dfltClsLdr = getClass().getClassLoader();
+
+ /** Whether or not to require an object to be serializable in order to be marshalled. */
+ private boolean requireSer = true;
+
+ /** ID mapper. */
+ private OptimizedMarshallerIdMapper mapper;
+
+ /** Class descriptors by class. */
+ private final ConcurrentMap<Class, OptimizedClassDescriptor> clsMap = new ConcurrentHashMap8<>();
+
+ /**
+ * Creates new marshaller will all defaults.
+ *
+ * @throws IgniteException If this marshaller is not supported on the current JVM.
+ */
+ public OptimizedMarshaller() {
+ if (!available())
+ throw new IgniteException("Using OptimizedMarshaller on unsupported JVM version (some of " +
+ "JVM-private APIs required for the marshaller to work are missing).");
+ }
+
+ /**
+ * Creates new marshaller providing whether it should
+ * require {@link Serializable} interface or not.
+ *
+ * @param requireSer Whether to require {@link Serializable}.
+ */
+ public OptimizedMarshaller(boolean requireSer) {
+ this.requireSer = requireSer;
+ }
+
+ /**
+ * Sets whether marshaller should require {@link Serializable} interface or not.
+ *
+ * @param requireSer Whether to require {@link Serializable}.
+ * @return {@code this} for chaining.
+ */
+ public OptimizedMarshaller setRequireSerializable(boolean requireSer) {
+ this.requireSer = requireSer;
+
+ return this;
+ }
+
+ /**
+ * Sets ID mapper.
+ *
+ * @param mapper ID mapper.
+ * @return {@code this} for chaining.
+ */
+ public OptimizedMarshaller setIdMapper(OptimizedMarshallerIdMapper mapper) {
+ this.mapper = mapper;
+
+ return this;
+ }
+
+ /**
+ * Specifies size of cached object streams used by marshaller. Object streams are cached for
+ * performance reason to avoid costly recreation for every serialization routine. If {@code 0} (default),
+ * pool is not used and each thread has its own cached object stream which it keeps reusing.
+ * <p>
+ * Since each stream has an internal buffer, creating a stream for each thread can lead to
+ * high memory consumption if many large messages are marshalled or unmarshalled concurrently.
+ * Consider using pool in this case. This will limit number of streams that can be created and,
+ * therefore, decrease memory consumption.
+ * <p>
+ * NOTE: Using streams pool can decrease performance since streams will be shared between
+ * different threads which will lead to more frequent context switching.
+ *
+ * @param poolSize Streams pool size. If {@code 0}, pool is not used.
+ * @return {@code this} for chaining.
+ */
+ public OptimizedMarshaller setPoolSize(int poolSize) {
+ OptimizedObjectStreamRegistry.poolSize(poolSize);
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void marshal0(@Nullable Object obj, OutputStream out) throws IgniteCheckedException {
+ assert out != null;
+
+ OptimizedObjectOutputStream objOut = null;
+
+ try {
+ objOut = OptimizedObjectStreamRegistry.out();
+
+ objOut.context(clsMap, ctx, mapper, requireSer);
+
+ objOut.out().outputStream(out);
+
+ objOut.writeObject(obj);
+ }
+ catch (IOException e) {
+ throw new IgniteCheckedException("Failed to serialize object: " + obj, e);
+ }
+ finally {
+ OptimizedObjectStreamRegistry.closeOut(objOut);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override protected byte[] marshal0(@Nullable Object obj) throws IgniteCheckedException {
+ OptimizedObjectOutputStream objOut = null;
+
+ try {
+ objOut = OptimizedObjectStreamRegistry.out();
+
+ objOut.context(clsMap, ctx, mapper, requireSer);
+
+ objOut.writeObject(obj);
+
+ return objOut.out().array();
+ }
+ catch (Exception e) {
+ throw new IgniteCheckedException("Failed to serialize object: " + obj, e);
+ }
+ finally {
+ OptimizedObjectStreamRegistry.closeOut(objOut);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override protected <T> T unmarshal0(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
+ assert in != null;
+
+ OptimizedObjectInputStream objIn = null;
+
+ try {
+ objIn = OptimizedObjectStreamRegistry.in();
+
+ objIn.context(clsMap, ctx, mapper, clsLdr != null ? clsLdr : dfltClsLdr);
+
+ objIn.in().inputStream(in);
+
+ return (T)objIn.readObject();
+ }
+ catch (ClassNotFoundException e) {
+ throw new IgniteCheckedException("Failed to find class with given class loader for unmarshalling " +
+ "(make sure same versions of all classes are available on all nodes or enable peer-class-loading) " +
+ "[clsLdr=" + clsLdr + ", cls=" + e.getMessage() + "]", e);
+ }
+ catch (Exception e) {
+ throw new IgniteCheckedException("Failed to deserialize object with given class loader: " + clsLdr, e);
+ }
+ finally {
+ OptimizedObjectStreamRegistry.closeIn(objIn);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override protected <T> T unmarshal0(byte[] arr, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
+ assert arr != null;
+
+ OptimizedObjectInputStream objIn = null;
+
+ try {
+ objIn = OptimizedObjectStreamRegistry.in();
+
+ objIn.context(clsMap, ctx, mapper, clsLdr != null ? clsLdr : dfltClsLdr);
+
+ objIn.in().bytes(arr, arr.length);
+
+ return (T)objIn.readObject();
+ }
+ catch (ClassNotFoundException e) {
+ throw new IgniteCheckedException("Failed to find class with given class loader for unmarshalling " +
+ "(make sure same version of all classes are available on all nodes or enable peer-class-loading)" +
+ " [clsLdr=" + clsLdr + ", cls=" + e.getMessage() + "]", e);
+ }
+ catch (Exception e) {
+ throw new IgniteCheckedException("Failed to deserialize object with given class loader: " + clsLdr, e);
+ }
+ finally {
+ OptimizedObjectStreamRegistry.closeIn(objIn);
+ }
+ }
+
+ /**
+ * Checks whether {@code GridOptimizedMarshaller} is able to work on the current JVM.
+ * <p>
+ * As long as {@code GridOptimizedMarshaller} 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 GridOptimizedMarshaller} can work on the current JVM or
+ * {@code false} if it can't.
+ */
+ @SuppressWarnings({"TypeParameterExtendsFinalClass", "ErrorNotRethrown"})
+ public static boolean available() {
+ try {
+ Class<? extends Unsafe> unsafeCls = Unsafe.class;
+
+ 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;
+ }
+ }
+
+ /**
+ * Undeployment callback invoked when class loader is being undeployed.
+ *
+ * @param ldr Class loader being undeployed.
+ */
+ @Override public void onUndeploy(ClassLoader ldr) {
+ for (Class<?> cls : clsMap.keySet()) {
+ if (ldr.equals(cls.getClassLoader()))
+ clsMap.remove(cls);
+ }
+
+ U.clearClassCache(ldr);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerIdMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerIdMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerIdMapper.java
new file mode 100644
index 0000000..381e5d0
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedMarshallerIdMapper.java
@@ -0,0 +1,33 @@
+/*
+ * 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.marshaller.optimized;
+
+/**
+ * ID mapper.
+ */
+public interface OptimizedMarshallerIdMapper {
+ /**
+ * Gets type ID for provided class name.
+ * <p>
+ * If {@code 0} is returned, hash code of class name will be used.
+ *
+ * @param clsName Class name.
+ * @return Type ID.
+ */
+ public int typeId(String clsName);
+}
\ No newline at end of file
[03/10] ignite git commit: IGNITE-4938: Moved OptimizedMarshaller to
private package. This closes #1793.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerNodeFailoverTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerNodeFailoverTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerNodeFailoverTest.java
deleted file mode 100644
index d6bbdb4..0000000
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerNodeFailoverTest.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * 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.optimized;
-
-import java.io.File;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.Callable;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-
-/**
- *
- */
-public class OptimizedMarshallerNodeFailoverTest extends GridCommonAbstractTest {
- /** */
- private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
-
- /** */
- private boolean cache;
-
- /** */
- private String workDir;
-
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
- TcpDiscoverySpi disco = new TcpDiscoverySpi();
-
- disco.setIpFinder(ipFinder);
-
- cfg.setDiscoverySpi(disco);
-
- cfg.setMarshaller(new OptimizedMarshaller());
-
- cfg.setWorkDirectory(workDir);
-
- if (cache) {
- CacheConfiguration ccfg = new CacheConfiguration();
-
- ccfg.setCacheMode(PARTITIONED);
- ccfg.setBackups(1);
- ccfg.setWriteSynchronizationMode(FULL_SYNC);
-
- cfg.setCacheConfiguration(ccfg);
- }
- else
- cfg.setClientMode(true);
-
- return cfg;
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testClassCacheUpdateFailover1() throws Exception {
- classCacheUpdateFailover(false);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testClassCacheUpdateFailover2() throws Exception {
- classCacheUpdateFailover(true);
- }
-
- /**
- * @param stopSrv If {@code true} restarts server node, otherwise client node.
- * @throws Exception If failed.
- */
- private void classCacheUpdateFailover(boolean stopSrv) throws Exception {
- cache = true;
-
- startGridsMultiThreaded(2);
-
- cache = stopSrv;
-
- IgniteCache<Integer, Object> cache0 = ignite(0).cache(null);
-
- for (int i = 0; i < 20; i++) {
- log.info("Iteration: " + i);
-
- Map<Integer, Object> map = new HashMap<>();
-
- for (int j = 0; j < 10_000; j++)
- map.put(j, create(i + 1));
-
- final Ignite ignite = startGrid(2);
-
- IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable() {
- @Override public Object call() throws Exception {
- ignite.close();
-
- return null;
- }
- });
-
- cache0.putAll(map);
-
- fut.get();
- }
-
- cache = true;
-
- Ignite ignite = startGrid(2); // Check can start one more cache node.
-
- assertNotNull(ignite.cache(null));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testRestartAllNodes() throws Exception {
- cache = true;
-
- String home = U.getIgniteHome();
-
- String[] workDirs = new String[3];
-
- for (int i = 0; i < 3; i++) {
- workDirs[i] = home + "/work/marshallerTestNode_" + i;
-
- File file = new File(workDirs[i]);
-
- if (file.exists())
- assert U.delete(file);
- }
-
- try {
- for (int i = 0; i < workDirs.length; i++) {
- workDir = workDirs[i];
-
- startGrid(i);
- }
-
- Marshaller marsh = ignite(0).configuration().getMarshaller();
-
- TestClass1 obj = new TestClass1();
-
- obj.val = 111;
-
- byte[] bytes = marsh.marshal(obj);
-
- stopAllGrids();
-
- for (int i = 0; i < workDirs.length; i++) {
- workDir = workDirs[i];
-
- startGrid(i);
- }
-
- for (int i = 0; i < 3; i++) {
- marsh = ignite(i).configuration().getMarshaller();
-
- TestClass1 obj0 = marsh.unmarshal(bytes, null);
-
- assertEquals(111, obj0.val);
- }
- }
- finally {
- for (String dir : workDirs)
- assert U.delete(new File(dir));
- }
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTest() throws Exception {
- super.afterTest();
-
- stopAllGrids();
- }
-
- /**
- * @param id Class ID.
- * @return Test class instance.
- */
- private static Object create(int id) {
- switch (id) {
- case 1: return new TestClass1();
-
- case 2: return new TestClass2();
-
- case 3: return new TestClass3();
-
- case 4: return new TestClass4();
-
- case 5: return new TestClass5();
-
- case 6: return new TestClass6();
-
- case 7: return new TestClass7();
-
- case 8: return new TestClass8();
-
- case 9: return new TestClass9();
-
- case 10: return new TestClass10();
-
- case 11: return new TestClass11();
-
- case 12: return new TestClass12();
-
- case 13: return new TestClass13();
-
- case 14: return new TestClass14();
-
- case 15: return new TestClass15();
-
- case 16: return new TestClass16();
-
- case 17: return new TestClass17();
-
- case 18: return new TestClass18();
-
- case 19: return new TestClass19();
-
- case 20: return new TestClass20();
- }
-
- fail();
-
- return null;
- }
-
- /**
- *
- */
- static class TestClass1 implements Serializable {
- /** */
- int val;
- }
-
- /**
- *
- */
- static class TestClass2 implements Serializable {}
-
- /**
- *
- */
- static class TestClass3 implements Serializable {}
-
- /**
- *
- */
- static class TestClass4 implements Serializable {}
-
- /**
- *
- */
- static class TestClass5 implements Serializable {}
-
- /**
- *
- */
- static class TestClass6 implements Serializable {}
-
- /**
- *
- */
- static class TestClass7 implements Serializable {}
-
- /**
- *
- */
- static class TestClass8 implements Serializable {}
-
- /**
- *
- */
- static class TestClass9 implements Serializable {}
-
- /**
- *
- */
- static class TestClass10 implements Serializable {}
-
- /**
- *
- */
- static class TestClass11 implements Serializable {}
-
- /**
- *
- */
- static class TestClass12 implements Serializable {}
-
- /**
- *
- */
- static class TestClass13 implements Serializable {}
-
- /**
- *
- */
- static class TestClass14 implements Serializable {}
-
- /**
- *
- */
- static class TestClass15 implements Serializable {}
-
- /**
- *
- */
- static class TestClass16 implements Serializable {}
-
- /**
- *
- */
- static class TestClass17 implements Serializable {}
-
- /**
- *
- */
- static class TestClass18 implements Serializable {}
-
- /**
- *
- */
- static class TestClass19 implements Serializable {}
-
- /**
- *
- */
- static class TestClass20 implements Serializable {}
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerPooledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerPooledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerPooledSelfTest.java
deleted file mode 100644
index a883270..0000000
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerPooledSelfTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.optimized;
-
-import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-
-/**
- * Optimized marshaller self test.
- */
-@GridCommonTest(group = "Marshaller")
-public class OptimizedMarshallerPooledSelfTest extends OptimizedMarshallerSelfTest {
- /** {@inheritDoc} */
- @Override protected Marshaller marshaller() {
- OptimizedMarshaller m = new OptimizedMarshaller(false);
-
- m.setPoolSize(8);
-
- return m;
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTestsStopped() throws Exception {
- super.afterTestsStopped();
-
- // Reset static registry.
- new OptimizedMarshaller().setPoolSize(0);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSelfTest.java
deleted file mode 100644
index a034b3a..0000000
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSelfTest.java
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * 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.optimized;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.concurrent.Callable;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.lang.IgniteRunnable;
-import org.apache.ignite.marshaller.GridMarshallerAbstractTest;
-import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-
-/**
- * Optimized marshaller self test.
- */
-@GridCommonTest(group = "Marshaller")
-public class OptimizedMarshallerSelfTest extends GridMarshallerAbstractTest {
- /** {@inheritDoc} */
- @Override protected Marshaller marshaller() {
- return new OptimizedMarshaller(false);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testTestMarshalling() throws Exception {
- final String msg = "PASSED";
-
- byte[] buf = marshal(new IgniteRunnable() {
- @Override public void run() {
- c1.apply(msg);
- c2.apply(msg);
-
- c3.apply();
- c4.reduce();
-
- System.out.println("Test message: " + msg);
- }
- });
-
- Runnable r = unmarshal(buf);
-
- assertNotNull(r);
-
- r.run();
- }
-
- /**
- * Tests marshal self-linked object.
- *
- * @throws IgniteCheckedException If marshalling failed.
- */
- public void testMarshallingSelfLink() throws IgniteCheckedException {
- SelfLink sl = new SelfLink("a string 1");
-
- sl.link(sl);
-
- SelfLink sl1 = unmarshal(marshal(sl));
-
- assert sl1.link() == sl1;
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testInvalid() throws Exception {
- GridTestUtils.assertThrows(
- log,
- new Callable<Object>() {
- @Override public Object call() throws Exception {
- byte[] arr = new byte[10];
-
- arr[0] = (byte)200;
-
- unmarshal(arr);
-
- return null;
- }
- },
- IgniteCheckedException.class,
- null
- );
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testNested() throws Exception {
- NestedTestObject obj = new NestedTestObject("String", 100);
-
- NestedTestObject newObj = unmarshal(marshal(obj));
-
- assertEquals("String", newObj.str);
- assertEquals(100, newObj.val);
- }
-
- /**
- * Class for nested execution test.
- */
- private static class NestedTestObject implements Serializable {
- /** */
- private String str;
-
- /** */
- private int val;
-
- /**
- * @param str String.
- * @param val Value.
- */
- private NestedTestObject(String str, int val) {
- this.str = str;
- this.val = val;
- }
-
- /** {@inheritDoc} */
- private void writeObject(ObjectOutputStream out) throws IOException {
- try {
- byte[] arr = marshal(str);
-
- out.writeInt(arr.length);
- out.write(arr);
-
- out.writeInt(val);
- }
- catch (IgniteCheckedException e) {
- throw new IOException(e);
- }
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("UnusedParameters")
- private void readObject(ObjectInputStream in) throws IOException {
- try {
- byte[] arr = new byte[in.readInt()];
-
- in.read(arr);
-
- str = unmarshal(arr);
-
- val = in.readInt();
- }
- catch (IgniteCheckedException e) {
- throw new IOException(e);
- }
- }
- }
-
- /** */
- private static class TestObject2 {
- /** */
- private final int i;
-
- /**
- * Constructor for TestObject2 instances.
- *
- * @param i Integer value to hold.
- */
- private TestObject2(int i) {
- this.i = i;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- return i == ((TestObject2)o).i;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return i;
- }
- }
-
- /**
- * Static nested class.
- */
- private static class TestObject {
- /** */
- private final TestObject2 o2;
-
- /** The only meaningful field in the class, used for {@link #equals(Object o)} and {@link #hashCode()}. */
- private final String str;
-
- /**
- * @param str String to hold.
- * @param i Integer.
- */
- TestObject(String str, int i) {
- this.str = str;
-
- o2 = new TestObject2(i);
- }
-
- /**
- * Method for accessing value of the hold string after the object is created.
- *
- * @return Wrapped string.
- */
- public String string() {
- return str;
- }
-
- /**
- * @return Object held in this wrapped.
- */
- public TestObject2 obj() {
- return o2;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return 31 * o2.hashCode() + str.hashCode();
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("RedundantIfStatement")
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- TestObject obj = (TestObject)o;
-
- if (o2 != null ? !o2.equals(obj.o2) : obj.o2 != null)
- return false;
-
- if (str != null ? !str.equals(obj.str) : obj.str != null)
- return false;
-
- return true;
- }
- }
-
- /**
- * Static nested class.
- */
- private static class SelfLink extends TestObject {
- /** */
- private SelfLink link;
-
- /**
- * @param str String to hold.
- */
- SelfLink(String str) {
- super(str, 1);
- }
-
- /**
- * @return The object this link points to,.
- */
- public SelfLink link() {
- return link;
- }
-
- /**
- * @param link The object this link should points to,
- */
- public void link(SelfLink link) {
- this.link = link;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSerialPersistentFieldsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSerialPersistentFieldsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSerialPersistentFieldsSelfTest.java
deleted file mode 100644
index ef05009..0000000
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerSerialPersistentFieldsSelfTest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.optimized;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamField;
-import java.io.Serializable;
-import org.apache.ignite.marshaller.GridMarshallerAbstractTest;
-import org.apache.ignite.marshaller.Marshaller;
-
-/**
- * Test that Optimized Marshaller works with classes with serialPersistentFields.
- */
-public class OptimizedMarshallerSerialPersistentFieldsSelfTest extends GridMarshallerAbstractTest {
- /** {@inheritDoc} */
- @Override protected Marshaller marshaller() {
- return new OptimizedMarshaller(false);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testOptimizedMarshaller() throws Exception {
- unmarshal(marshal(new TestClass()));
-
- TestClass2 val = unmarshal(marshal(new TestClass2()));
-
- assertNull(val.field3);
- }
-
- /**
- * Test class with serialPersistentFields fields.
- */
- private static class TestClass implements Serializable {
- private static final long serialVersionUID = 0L;
-
- /** For serialization compatibility. */
- private static final ObjectStreamField[] serialPersistentFields = {
- new ObjectStreamField("field1", Integer.TYPE),
- new ObjectStreamField("field2", Integer.TYPE)
- };
-
- /**
- * @param s Object output stream.
- */
- private void writeObject(ObjectOutputStream s) throws IOException {
- s.putFields().put("field1", 1);
- s.putFields().put("field2", 2);
- s.writeFields();
-
- s.writeObject(null);
- }
-
- /**
- * @param s Object input stream.
- */
- private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
- s.defaultReadObject();
-
- s.readObject();
- }
- }
-
- /**
- * Test class with serialPersistentFields fields.
- */
- private static class TestClass2 implements Serializable {
- private static final long serialVersionUID = 0L;
-
- private Integer field3 = 1;
-
- /** For serialization compatibility. */
- private static final ObjectStreamField[] serialPersistentFields = {
- new ObjectStreamField("field1", Integer.TYPE),
- new ObjectStreamField("field2", Integer.TYPE)
- };
-
- /**
- * @param s Object output stream.
- */
- private void writeObject(ObjectOutputStream s) throws IOException {
- s.putFields().put("field1", 1);
- s.putFields().put("field2", 2);
- s.writeFields();
-
- s.writeObject(null);
- }
-
- /**
- * @param s Object input stream.
- */
- private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
- s.defaultReadObject();
-
- s.readObject();
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a1b5b8c3/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerTest.java
deleted file mode 100644
index 2658a29..0000000
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerTest.java
+++ /dev/null
@@ -1,790 +0,0 @@
-/*
- * 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.optimized;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.Serializable;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.net.InetSocketAddress;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.concurrent.ConcurrentMap;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.compute.ComputeJobAdapter;
-import org.apache.ignite.compute.ComputeTask;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.GridMarshallerTestInheritedBean;
-import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.jetbrains.annotations.Nullable;
-
-/**
- *
- */
-public class OptimizedMarshallerTest extends GridCommonAbstractTest {
- /**
- * @return Marshaller.
- */
- private OptimizedMarshaller marshaller() {
- U.clearClassCache();
-
- OptimizedMarshaller marsh = new OptimizedMarshaller();
-
- marsh.setContext(new MarshallerContextTestImpl());
-
- return marsh;
- }
-
- /**
- * Tests ability to marshal non-serializable objects.
- *
- * @throws IgniteCheckedException If marshalling failed.
- */
- public void testNonSerializable() throws IgniteCheckedException {
- OptimizedMarshaller marsh = marshaller();
-
- marsh.setRequireSerializable(false);
-
- NonSerializable outObj = marsh.unmarshal(marsh.marshal(new NonSerializable(null)), null);
-
- outObj.checkAfterUnmarshalled();
- }
-
- /**
- * Tests ability to marshal non-serializable objects.
- *
- * @throws IgniteCheckedException If marshalling failed.
- */
- public void testNonSerializable1() throws IgniteCheckedException {
- OptimizedMarshaller marsh = marshaller();
-
- marsh.setRequireSerializable(false);
-
- byte[] bytes = marsh.marshal(new TcpDiscoveryVmIpFinder());
-
- TcpDiscoveryIpFinder ipFinder = marsh.unmarshal(bytes, null);
-
- assertFalse(ipFinder.isShared());
-
- ipFinder = marsh.unmarshal(marsh.marshal(new TcpDiscoveryVmIpFinder(true)), null);
-
- assertTrue(ipFinder.isShared());
- }
-
- /**
- * Tests ability to marshal non-serializable objects.
- *
- * @throws IgniteCheckedException If marshalling failed.
- */
- public void testNonSerializable2() throws IgniteCheckedException {
- OptimizedMarshaller marsh = marshaller();
-
- marsh.setRequireSerializable(false);
-
- TcpDiscoveryIpFinderAdapter ipFinder = new TcpDiscoveryIpFinderAdapter() {
- @Override public Collection<InetSocketAddress> getRegisteredAddresses() {
- return null;
- }
-
- @Override public void registerAddresses(Collection<InetSocketAddress> addrs) {
- //No-op.
- }
-
- @Override public void unregisterAddresses(Collection<InetSocketAddress> addrs) {
- //No-op.
- }
- };
-
- ipFinder.setShared(false);
-
- byte[] bytes = marsh.marshal(ipFinder);
-
- ipFinder = marsh.unmarshal(bytes, null);
-
- assertFalse(ipFinder.isShared());
- }
-
- /**
- * Tests ability to marshal non-serializable objects.
- *
- * @throws IgniteCheckedException If marshalling failed.
- */
- public void testNonSerializable3() throws IgniteCheckedException {
- OptimizedMarshaller marsh = marshaller();
-
- marsh.setRequireSerializable(false);
-
- byte[] bytes = marsh.marshal(new TestTcpDiscoveryIpFinderAdapter());
-
- TcpDiscoveryIpFinder ipFinder = marsh.unmarshal(bytes, null);
-
- assertFalse(ipFinder.isShared());
- }
-
- /**
- * Tests ability to marshal non-serializable objects.
- *
- * @throws IgniteCheckedException If marshalling failed.
- */
- public void testNonSerializable4() throws IgniteCheckedException {
- OptimizedMarshaller marsh = marshaller();
-
- marsh.setRequireSerializable(false);
-
- byte[] bytes = marsh.marshal(new GridMarshallerTestInheritedBean());
-
- info(Arrays.toString(bytes));
-
- GridMarshallerTestInheritedBean bean = marsh.unmarshal(bytes, null);
-
- assertTrue(bean.isFlag());
- }
-
- /**
- * Tests ability to marshal non-serializable objects.
- *
- * @throws IgniteCheckedException If marshalling failed.
- */
- public void testNonSerializable5() throws IgniteCheckedException {
- Marshaller marsh = marshaller();
-
- byte[] bytes = marsh.marshal(true);
-
- Boolean val = marsh.unmarshal(bytes, null);
-
- assertTrue(val);
- }
-
- /**
- * Tests ability to marshal serializable objects.
- *
- * @throws IgniteCheckedException If marshalling failed.
- */
- public void testSerializable() throws IgniteCheckedException {
- Marshaller marsh = marshaller();
-
- SomeSerializable outObj = marsh.unmarshal(marsh.marshal(new SomeSerializable(null)), null);
-
- outObj.checkAfterUnmarshalled();
- }
-
- /**
- * @throws IgniteCheckedException If failed.
- */
- public void testSerializableAfterChangingValue() throws IgniteCheckedException {
- Marshaller marsh = marshaller();
-
- SomeSimpleSerializable newObj = new SomeSimpleSerializable();
-
- assert(newObj.flag);
-
- newObj.setFlagValue(false);
-
- assert(! newObj.flag);
-
- SomeSimpleSerializable outObj = marsh.unmarshal(marsh.marshal(newObj), null);
-
- assert (! outObj.flag);
- }
-
- /**
- * Tests ability to marshal externalizable objects.
- *
- * @throws IgniteCheckedException If marshalling failed.
- */
- public void testExternalizable() throws IgniteCheckedException {
- Marshaller marsh = marshaller();
-
- ExternalizableA outObj = marsh.unmarshal(marsh.marshal(new ExternalizableA(null, true)), null);
- ExternalizableA outObj1 = marsh.unmarshal(marsh.marshal(new ExternalizableA(null, false)), null);
-
- assertNotNull(outObj);
- assertNotNull(outObj1);
- }
-
- /**
- * Tests {@link OptimizedMarshaller#setRequireSerializable(boolean)}.
- */
- public void testRequireSerializable() {
- OptimizedMarshaller marsh = marshaller();
-
- marsh.setRequireSerializable(true);
-
- try {
- marsh.marshal(new NonSerializable(null));
-
- fail();
- }
- catch (IgniteCheckedException ignore) {
- // No-op.
- }
- }
-
- /**
- * Tests {@link Proxy}.
- *
- * @throws IgniteCheckedException If marshalling failed.
- */
- public void testProxy() throws IgniteCheckedException {
- OptimizedMarshaller marsh = marshaller();
-
- marsh.setRequireSerializable(false);
-
- SomeItf inItf = (SomeItf)Proxy.newProxyInstance(
- OptimizedMarshallerTest.class.getClassLoader(), new Class[] {SomeItf.class},
- new InvocationHandler() {
- private NonSerializable obj = new NonSerializable(null);
-
- @Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable {
- obj.checkAfterUnmarshalled();
-
- return 17;
- }
- }
- );
-
- SomeItf outItf = marsh.unmarshal(marsh.marshal(inItf), null);
-
- assertEquals(outItf.checkAfterUnmarshalled(), 17);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testDescriptorCache() throws Exception {
- try {
- Ignite ignite = startGridsMultiThreaded(2);
-
- String taskClsName = "org.apache.ignite.tests.p2p.SingleSplitTestTask";
- String jobClsName = "org.apache.ignite.tests.p2p.SingleSplitTestTask$SingleSplitTestJob";
-
- ClassLoader ldr = getExternalClassLoader();
-
- Class<? extends ComputeTask<?, ?>> taskCls = (Class<? extends ComputeTask<?, ?>>)ldr.loadClass(taskClsName);
- Class<? extends ComputeTask<?, ?>> jobCls = (Class<? extends ComputeTask<?, ?>>)ldr.loadClass(jobClsName);
-
- ignite.compute().localDeployTask(taskCls, ldr);
-
- ignite.compute().execute(taskClsName, 2);
-
- ConcurrentMap<Class<?>, OptimizedClassDescriptor> cache =
- U.field(ignite.configuration().getMarshaller(), "clsMap");
-
- assertTrue(cache.containsKey(jobCls));
-
- ignite.compute().undeployTask(taskClsName);
-
- // Wait for undeploy.
- Thread.sleep(1000);
-
- assertFalse(cache.containsKey(jobCls));
- }
- finally {
- stopAllGrids();
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testPerformance() throws Exception {
- System.gc();
-
- checkPerformance(10000, 4);
- }
-
- /**
- * @param cnt Number of marshalling attempts.
- * @param tries Number of retries.
- * @throws Exception If failed.
- */
- private void checkPerformance(int cnt, int tries) throws Exception {
- Marshaller marsh = marshaller();
-
- for (int j = 0; j < tries; j++) {
- System.gc();
-
- long start = System.currentTimeMillis();
-
- for (int i = 0; i < cnt; i++) {
- TestCacheKey key = new TestCacheKey("key", "id");
-
- TestCacheKey outKey = marsh.unmarshal(marsh.marshal(key), null);
-
- assert key.equals(outKey);
- assert key.hashCode() == outKey.hashCode();
- }
-
- info("Time non-serializable: " + (System.currentTimeMillis() - start));
-
- System.gc();
-
- start = System.currentTimeMillis();
-
- for (int i = 0; i < cnt; i++) {
- TestCacheKeySerializable key1 = new TestCacheKeySerializable("key", "id");
-
- TestCacheKeySerializable outKey = marsh.unmarshal(marsh.marshal(key1), null);
-
- assert key1.equals(outKey);
- assert key1.hashCode() == outKey.hashCode();
- }
-
- info("Time serializable: " + (System.currentTimeMillis() - start));
-
- System.gc();
-
- start = System.currentTimeMillis();
-
- for (int i = 0; i < cnt; i++) {
- TestCacheKeyExternalizable key2 = new TestCacheKeyExternalizable("key", "id");
-
- TestCacheKeyExternalizable outKey = marsh.unmarshal(marsh.marshal(key2), null);
-
- assert key2.equals(outKey);
- assert key2.hashCode() == outKey.hashCode();
- }
-
- info("Time externalizable: " + (System.currentTimeMillis() - start));
-
- info(">>>");
- }
-
- info(">>> Finished performance check <<<");
- }
-
- /**
- * Some non-serializable class.
- */
- @SuppressWarnings( {"PublicField","TransientFieldInNonSerializableClass","FieldMayBeStatic"})
- private static class NonSerializableA {
- /** */
- private final long longVal = 0x33445566778899AAL;
-
- /** */
- protected Short shortVal = (short)0xAABB;
-
- /** */
- public String[] strArr = {"AA","BB"};
-
- /** */
- public boolean flag1 = true;
-
- /** */
- public boolean flag2;
-
- /** */
- public Boolean flag3;
-
- /** */
- public Boolean flag4 = true;
-
- /** */
- public Boolean flag5 = false;
-
- /** */
- private transient int intVal = 0xAABBCCDD;
-
- /**
- * @param strArr Array.
- * @param shortVal Short value.
- */
- @SuppressWarnings( {"UnusedDeclaration"})
- private NonSerializableA(@Nullable String[] strArr, @Nullable Short shortVal) {
- // No-op.
- }
-
- /**
- * Checks correctness of the state after unmarshalling.
- */
- void checkAfterUnmarshalled() {
- assertEquals(longVal, 0x33445566778899AAL);
-
- assertEquals(shortVal.shortValue(), (short)0xAABB);
-
- assertTrue(Arrays.equals(strArr, new String[] {"AA","BB"}));
-
- assertEquals(intVal, 0);
-
- assertTrue(flag1);
- assertFalse(flag2);
- assertNull(flag3);
- assertTrue(flag4);
- assertFalse(flag5);
- }
- }
-
- /**
- * Some non-serializable class.
- */
- @SuppressWarnings( {"PublicField","TransientFieldInNonSerializableClass","PackageVisibleInnerClass"})
- static class NonSerializableB extends NonSerializableA {
- /** */
- public Short shortVal = 0x1122;
-
- /** */
- public long longVal = 0x8877665544332211L;
-
- /** */
- private transient NonSerializableA[] aArr = {
- new NonSerializableA(null, null),
- new NonSerializableA(null, null),
- new NonSerializableA(null, null)
- };
-
- /** */
- protected Double doubleVal = 123.456;
-
- /**
- * Just to eliminate the default constructor.
- */
- private NonSerializableB() {
- super(null, null);
- }
-
- /**
- * Checks correctness of the state after unmarshalling.
- */
- @Override void checkAfterUnmarshalled() {
- super.checkAfterUnmarshalled();
-
- assertEquals(shortVal.shortValue(), 0x1122);
-
- assertEquals(longVal, 0x8877665544332211L);
-
- assertNull(aArr);
-
- assertEquals(doubleVal, 123.456);
- }
- }
-
- /**
- * Some non-serializable class.
- */
- @SuppressWarnings( {"TransientFieldInNonSerializableClass","PublicField"})
- private static class NonSerializable extends NonSerializableB {
- /** */
- private int idVal = -17;
-
- /** */
- private final NonSerializableA aVal = new NonSerializableB();
-
- /** */
- private transient NonSerializableB bVal = new NonSerializableB();
-
- /** */
- private NonSerializableA[] bArr = new NonSerializableA[] {
- new NonSerializableB(),
- new NonSerializableA(null, null)
- };
-
- /** */
- public float floatVal = 567.89F;
-
- /**
- * Just to eliminate the default constructor.
- *
- * @param aVal Unused.
- */
- @SuppressWarnings( {"UnusedDeclaration"})
- private NonSerializable(NonSerializableA aVal) {
- }
-
- /**
- * Checks correctness of the state after unmarshalling.
- */
- @Override void checkAfterUnmarshalled() {
- super.checkAfterUnmarshalled();
-
- assertEquals(idVal, -17);
-
- aVal.checkAfterUnmarshalled();
-
- assertNull(bVal);
-
- for (NonSerializableA a : bArr) {
- a.checkAfterUnmarshalled();
- }
-
- assertEquals(floatVal, 567.89F);
- }
- }
-
- /**
- * Some serializable class.
- */
- @SuppressWarnings( {"PublicField","TransientFieldInNonSerializableClass","PackageVisibleInnerClass"})
- static class ForSerializableB {
- /** */
- public Short shortVal = 0x1122;
-
- /** */
- public long longVal = 0x8877665544332211L;
-
- /** */
- private transient NonSerializableA[] aArr;
-
- /** */
- private transient String strVal = "abc";
-
- /** */
- protected Double doubleVal = 123.456;
-
- /**
- */
- protected void init() {
- shortVal = 0x1122;
-
- longVal = 0x8877665544332211L;
-
- aArr = new NonSerializableA[] {
- new NonSerializableA(null, null),
- new NonSerializableA(null, null),
- new NonSerializableA(null, null)
- };
- }
-
- /**
- * Checks correctness of the state after unmarshalling.
- */
- void checkAfterUnmarshalled() {
- assertEquals(shortVal.shortValue(), 0x1122);
-
- assertEquals(longVal, 0x8877665544332211L);
-
- assertNull(aArr);
-
- assertNull(strVal);
-
- assertEquals(doubleVal, 123.456);
- }
- }
-
- /**
- * Some serializable class.
- */
- private static class SomeSimpleSerializable extends ComputeJobAdapter {
- /** */
- private boolean flag = true;
-
- /**
- * @param newFlagVal - The new value of flag field.
- */
- public void setFlagValue(boolean newFlagVal) {
- flag = newFlagVal;
- }
-
- /** {@inheritDoc} */
- @Override public Object execute() {
- assert false;
-
- return null;
- }
- }
- /**
- * Some serializable class.
- */
- private static class SomeSerializable extends ForSerializableB implements Serializable {
- /**
- * Just to eliminate the default constructor.
- *
- * @param id Unused.
- */
- @SuppressWarnings( {"UnusedDeclaration"})
- private SomeSerializable(Long id) {
- init();
- }
- }
-
- /**
- */
- private static interface SomeItf {
- /**
- * @return Check result.
- */
- int checkAfterUnmarshalled();
- }
-
- /**
- * Some externalizable class.
- */
- @SuppressWarnings( {"UnusedDeclaration", "PublicField"})
- private static class ExternalizableA implements Externalizable {
- /** */
- private boolean boolVal;
-
- /** */
- public String[] strArr;
-
- /** No-arg constructor is required by externalization. */
- public ExternalizableA() {
- // No-op.
- }
-
- /**
- *
- * @param strArr String array.
- * @param boolVal Boolean value.
- */
- private ExternalizableA(String[] strArr, boolean boolVal) {
- this.strArr = strArr;
- this.boolVal = boolVal;
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- out.writeBoolean(false);
- out.writeBoolean(false);
- out.writeBoolean(false);
- out.writeBoolean(false);
- out.writeBoolean(false);
- out.writeBoolean(false);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- boolVal = in.readBoolean();
- in.readBoolean();
- in.readBoolean();
- in.readBoolean();
- in.readBoolean();
- in.readBoolean();
- }
- }
-
- /**
- *
- */
- private static class TestCacheKey implements Serializable {
- /** */
- private String key;
-
- /** */
- @SuppressWarnings({"UnusedDeclaration"})
- private String terminalId;
-
- /**
- * @param key Key.
- * @param terminalId Some ID.
- */
- TestCacheKey(String key, String terminalId) {
- this.key = key;
- this.terminalId = terminalId;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return key.hashCode();
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object obj) {
- return obj instanceof TestCacheKey && key.equals(((TestCacheKey)obj).key);
- }
- }
-
- /**
- *
- */
- private static class TestCacheKeySerializable implements Serializable {
- /** */
- private String key;
-
- /** */
- @SuppressWarnings({"UnusedDeclaration"})
- private String terminalId;
-
- /**
- * @param key Key.
- * @param terminalId Some ID.
- */
- TestCacheKeySerializable(String key, String terminalId) {
- this.key = key;
- this.terminalId = terminalId;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return key.hashCode();
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object obj) {
- return obj instanceof TestCacheKeySerializable && key.equals(((TestCacheKeySerializable)obj).key);
- }
- }
-
- /**
- *
- */
- private static class TestCacheKeyExternalizable implements Externalizable {
- /** */
- private String key;
-
- /** */
- private String terminalId;
-
- /**
- *
- */
- public TestCacheKeyExternalizable() {
- // No-op.
- }
-
- /**
- * @param key Key.
- * @param terminalId Some ID.
- */
- TestCacheKeyExternalizable(String key, String terminalId) {
- this.key = key;
- this.terminalId = terminalId;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return key.hashCode();
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object obj) {
- return obj instanceof TestCacheKeyExternalizable && key.equals(((TestCacheKeyExternalizable)obj).key);
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- U.writeString(out, key);
- U.writeString(out, terminalId);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- key = U.readString(in);
- terminalId = U.readString(in);
- }
- }
-}
\ No newline at end of file