http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java index a45bbc2..4ca41b9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java @@ -58,7 +58,7 @@ public class GridTaskProcessor extends GridProcessorAdapter { new EnumMap<>(GridTaskThreadContextKey.class); /** */ - private final IgniteMarshaller marsh; + private final Marshaller marsh; /** */ private final ConcurrentMap<IgniteUuid, GridTaskWorker<?, ?>> tasks = GridConcurrentFactory.newMap();
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java index b9881fd..ce0d760 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java @@ -84,7 +84,7 @@ class GridTaskWorker<T, R> extends GridWorker implements GridTimeoutObject { private final IgniteLogger log; /** */ - private final IgniteMarshaller marsh; + private final Marshaller marsh; /** */ private final GridTaskSessionImpl ses; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java index 49be994..cb622d9 100644 --- a/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java +++ b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java @@ -32,7 +32,7 @@ import java.util.concurrent.atomic.*; * internal UUID. */ public final class IgniteUuid implements Comparable<IgniteUuid>, Iterable<IgniteUuid>, Cloneable, Externalizable, - IgniteOptimizedMarshallable { + OptimizedMarshallable { /** */ private static final long serialVersionUID = 0L; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/AbstractMarshaller.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/AbstractMarshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/AbstractMarshaller.java new file mode 100644 index 0000000..4ac4005 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/AbstractMarshaller.java @@ -0,0 +1,65 @@ +/* + * 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; + +import org.apache.ignite.*; +import org.apache.ignite.internal.util.*; +import org.apache.ignite.internal.util.io.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.jetbrains.annotations.*; + +/** + * Base class for marshallers. Provides default implementations of methods + * that work with byte array or {@link GridByteArrayList}. These implementations + * use {@link GridByteArrayInputStream} or {@link GridByteArrayOutputStream} + * to marshal and unmarshal objects. + */ +public abstract class AbstractMarshaller implements Marshaller { + /** Default initial buffer size for the {@link GridByteArrayOutputStream}. */ + public static final int DFLT_BUFFER_SIZE = 512; + + /** {@inheritDoc} */ + @Override public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException { + GridByteArrayOutputStream out = null; + + try { + out = new GridByteArrayOutputStream(DFLT_BUFFER_SIZE); + + marshal(obj, out); + + return out.toByteArray(); + } + finally { + U.close(out, null); + } + } + + /** {@inheritDoc} */ + @Override public <T> T unmarshal(byte[] arr, @Nullable ClassLoader clsLdr) throws IgniteCheckedException { + GridByteArrayInputStream in = null; + + try { + in = new GridByteArrayInputStream(arr, 0, arr.length); + + return unmarshal(in, clsLdr); + } + finally { + U.close(in, null); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteAbstractMarshaller.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteAbstractMarshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteAbstractMarshaller.java deleted file mode 100644 index ca3fe02..0000000 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteAbstractMarshaller.java +++ /dev/null @@ -1,65 +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; - -import org.apache.ignite.*; -import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.io.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -/** - * Base class for marshallers. Provides default implementations of methods - * that work with byte array or {@link GridByteArrayList}. These implementations - * use {@link GridByteArrayInputStream} or {@link GridByteArrayOutputStream} - * to marshal and unmarshal objects. - */ -public abstract class IgniteAbstractMarshaller implements IgniteMarshaller { - /** Default initial buffer size for the {@link GridByteArrayOutputStream}. */ - public static final int DFLT_BUFFER_SIZE = 512; - - /** {@inheritDoc} */ - @Override public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException { - GridByteArrayOutputStream out = null; - - try { - out = new GridByteArrayOutputStream(DFLT_BUFFER_SIZE); - - marshal(obj, out); - - return out.toByteArray(); - } - finally { - U.close(out, null); - } - } - - /** {@inheritDoc} */ - @Override public <T> T unmarshal(byte[] arr, @Nullable ClassLoader clsLdr) throws IgniteCheckedException { - GridByteArrayInputStream in = null; - - try { - in = new GridByteArrayInputStream(arr, 0, arr.length); - - return unmarshal(in, clsLdr); - } - finally { - U.close(in, null); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteMarshaller.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteMarshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteMarshaller.java deleted file mode 100644 index 561704d..0000000 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteMarshaller.java +++ /dev/null @@ -1,109 +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; - -import org.apache.ignite.*; -import org.jetbrains.annotations.*; - -import java.io.*; - -/** - * {@code GridMarshaller} allows to marshal or unmarshal objects in grid. It provides - * serialization/deserialization mechanism for all instances that are sent across networks - * or are otherwise serialized. - * <p> - * Gridgain provides the following {@code GridMarshaller} implementations: - * <ul> - * <li>{@link org.apache.ignite.marshaller.optimized.IgniteOptimizedMarshaller} - default</li> - * <li>{@link org.apache.ignite.marshaller.jdk.IgniteJdkMarshaller}</li> - * </ul> - * <p> - * Below are examples of marshaller configuration, usage, and injection into tasks, jobs, - * and SPI's. - * <h2 class="header">Java Example</h2> - * {@code GridMarshaller} can be explicitely configured in code. - * <pre name="code" class="java"> - * GridJdkMarshaller marshaller = new GridJdkMarshaller(); - * - * GridConfiguration cfg = new GridConfiguration(); - * - * // Override marshaller. - * cfg.setMarshaller(marshaller); - * - * // Starts grid. - * G.start(cfg); - * </pre> - * <h2 class="header">Spring Example</h2> - * GridMarshaller can be configured from Spring XML configuration file: - * <pre name="code" class="xml"> - * <bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfiguration" singleton="true"> - * ... - * <property name="marshaller"> - * <bean class="org.apache.ignite.marshaller.jdk.GridJdkMarshaller"/> - * </property> - * ... - * </bean> - * </pre> - * <p> - * <img src="http://www.gridgain.com/images/spring-small.png"> - * <br> - * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a> - */ -public interface IgniteMarshaller { - /** - * Marshals object to the output stream. This method should not close - * given output stream. - * - * @param obj Object to marshal. - * @param out Output stream to marshal into. - * @throws IgniteCheckedException If marshalling failed. - */ - public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException; - - /** - * Marshals object to byte array. - * - * @param obj Object to marshal. - * @return Byte array. - * @throws IgniteCheckedException If marshalling failed. - */ - public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException; - - /** - * Unmarshals object from the output stream using given class loader. - * This method should not close given input stream. - * - * @param <T> Type of unmarshalled object. - * @param in Input stream. - * @param clsLdr Class loader to use. - * @return Unmarshalled object. - * @throws IgniteCheckedException If unmarshalling failed. - */ - public <T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException; - - /** - * Unmarshals object from byte array using given class loader. - * - * @param <T> Type of unmarshalled object. - * @param arr Byte array. - * @param clsLdr Class loader to use. - * @return Unmarshalled object. - * @throws IgniteCheckedException If unmarshalling failed. - */ - public <T> T unmarshal(byte[] arr, @Nullable ClassLoader clsLdr) throws IgniteCheckedException; -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteMarshallerExclusions.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteMarshallerExclusions.java b/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteMarshallerExclusions.java deleted file mode 100644 index 34d99da..0000000 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/IgniteMarshallerExclusions.java +++ /dev/null @@ -1,153 +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; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.internal.executor.*; -import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import javax.management.*; -import java.util.*; -import java.util.concurrent.*; - -/** - * Controls what classes should be excluded from marshalling by default. - */ -public final class IgniteMarshallerExclusions { - /** - * Classes that must be included in serialization. All marshallers must - * included these classes. - * <p> - * Note that this list supercedes {@link #EXCL_CLASSES}. - */ - private static final Class<?>[] INCL_CLASSES = new Class[] { - // GridGain classes. - GridLoggerProxy.class, - GridExecutorService.class - }; - - /** */ - private static final Map<Class<?>, Boolean> cache = new GridBoundedConcurrentLinkedHashMap<>( - 512, 512, 0.75f, 16); - - /** - * Excluded grid classes from serialization. All marshallers must omit - * these classes. Fields of these types should be serialized as {@code null}. - * <p> - * Note that {@link #INCL_CLASSES} supercedes this list. - */ - private static final Class<?>[] EXCL_CLASSES; - - /** - * - */ - static { - Class springCtxCls = null; - - try { - springCtxCls = Class.forName("org.springframework.context.ApplicationContext"); - } - catch (Exception ignored) { - // No-op. - } - - List<Class<?>> excl = new ArrayList<>(); - - // Non-GridGain classes. - excl.add(MBeanServer.class); - excl.add(ExecutorService.class); - excl.add(ClassLoader.class); - excl.add(Thread.class); - - if (springCtxCls != null) - excl.add(springCtxCls); - - // GridGain classes. - excl.add(IgniteLogger.class); - excl.add(ComputeTaskSession.class); - excl.add(ComputeLoadBalancer.class); - excl.add(ComputeJobContext.class); - excl.add(IgniteMarshaller.class); - excl.add(GridComponent.class); - excl.add(ComputeTaskContinuousMapper.class); - - EXCL_CLASSES = U.toArray(excl, new Class[excl.size()]); - } - - /** - * Ensures singleton. - */ - private IgniteMarshallerExclusions() { - // No-op. - } - - /** - * Checks given class against predefined set of excluded types. - * - * @param cls Class to check. - * @return {@code true} if class should be excluded, {@code false} otherwise. - */ - @SuppressWarnings("ForLoopReplaceableByForEach") - private static boolean isExcluded0(Class<?> cls) { - assert cls != null; - - final Class<?>[] inc = INCL_CLASSES; - - // NOTE: don't use foreach for performance reasons. - for (int i = 0; i < inc.length; i++) - if (inc[i].isAssignableFrom(cls)) - return false; - - final Class<?>[] exc = EXCL_CLASSES; - - // NOTE: don't use foreach for performance reasons. - for (int i = 0; i < exc.length; i++) - if (exc[i].isAssignableFrom(cls)) - return true; - - return false; - } - - /** - * Checks whether or not given class should be excluded from marshalling. - * - * @param cls Class to check. - * @return {@code true} if class should be excluded, {@code false} otherwise. - */ - public static boolean isExcluded(Class<?> cls) { - Boolean res = cache.get(cls); - - if (res == null) { - res = isExcluded0(cls); - - cache.put(cls, res); - } - - return res; - } - - /** - * Intended for test purposes only. - */ - public static void clearCache() { - cache.clear(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/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 new file mode 100644 index 0000000..14dd433 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/Marshaller.java @@ -0,0 +1,109 @@ +/* + * 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; + +import org.apache.ignite.*; +import org.jetbrains.annotations.*; + +import java.io.*; + +/** + * {@code GridMarshaller} allows to marshal or unmarshal objects in grid. It provides + * serialization/deserialization mechanism for all instances that are sent across networks + * or are otherwise serialized. + * <p> + * Gridgain provides the following {@code GridMarshaller} implementations: + * <ul> + * <li>{@link org.apache.ignite.marshaller.optimized.OptimizedMarshaller} - default</li> + * <li>{@link org.apache.ignite.marshaller.jdk.JdkMarshaller}</li> + * </ul> + * <p> + * Below are examples of marshaller configuration, usage, and injection into tasks, jobs, + * and SPI's. + * <h2 class="header">Java Example</h2> + * {@code GridMarshaller} can be explicitely configured in code. + * <pre name="code" class="java"> + * GridJdkMarshaller marshaller = new GridJdkMarshaller(); + * + * GridConfiguration cfg = new GridConfiguration(); + * + * // Override marshaller. + * cfg.setMarshaller(marshaller); + * + * // Starts grid. + * G.start(cfg); + * </pre> + * <h2 class="header">Spring Example</h2> + * GridMarshaller can be configured from Spring XML configuration file: + * <pre name="code" class="xml"> + * <bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfiguration" singleton="true"> + * ... + * <property name="marshaller"> + * <bean class="org.apache.ignite.marshaller.jdk.GridJdkMarshaller"/> + * </property> + * ... + * </bean> + * </pre> + * <p> + * <img src="http://www.gridgain.com/images/spring-small.png"> + * <br> + * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a> + */ +public interface Marshaller { + /** + * Marshals object to the output stream. This method should not close + * given output stream. + * + * @param obj Object to marshal. + * @param out Output stream to marshal into. + * @throws IgniteCheckedException If marshalling failed. + */ + public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException; + + /** + * Marshals object to byte array. + * + * @param obj Object to marshal. + * @return Byte array. + * @throws IgniteCheckedException If marshalling failed. + */ + public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException; + + /** + * Unmarshals object from the output stream using given class loader. + * This method should not close given input stream. + * + * @param <T> Type of unmarshalled object. + * @param in Input stream. + * @param clsLdr Class loader to use. + * @return Unmarshalled object. + * @throws IgniteCheckedException If unmarshalling failed. + */ + public <T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException; + + /** + * Unmarshals object from byte array using given class loader. + * + * @param <T> Type of unmarshalled object. + * @param arr Byte array. + * @param clsLdr Class loader to use. + * @return Unmarshalled object. + * @throws IgniteCheckedException If unmarshalling failed. + */ + public <T> T unmarshal(byte[] arr, @Nullable ClassLoader clsLdr) throws IgniteCheckedException; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerExclusions.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerExclusions.java b/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerExclusions.java new file mode 100644 index 0000000..25d2ccd --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerExclusions.java @@ -0,0 +1,153 @@ +/* + * 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; + +import org.apache.ignite.*; +import org.apache.ignite.compute.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.internal.executor.*; +import org.apache.ignite.internal.util.*; +import org.apache.ignite.internal.util.typedef.internal.*; + +import javax.management.*; +import java.util.*; +import java.util.concurrent.*; + +/** + * Controls what classes should be excluded from marshalling by default. + */ +public final class MarshallerExclusions { + /** + * Classes that must be included in serialization. All marshallers must + * included these classes. + * <p> + * Note that this list supercedes {@link #EXCL_CLASSES}. + */ + private static final Class<?>[] INCL_CLASSES = new Class[] { + // GridGain classes. + GridLoggerProxy.class, + GridExecutorService.class + }; + + /** */ + private static final Map<Class<?>, Boolean> cache = new GridBoundedConcurrentLinkedHashMap<>( + 512, 512, 0.75f, 16); + + /** + * Excluded grid classes from serialization. All marshallers must omit + * these classes. Fields of these types should be serialized as {@code null}. + * <p> + * Note that {@link #INCL_CLASSES} supercedes this list. + */ + private static final Class<?>[] EXCL_CLASSES; + + /** + * + */ + static { + Class springCtxCls = null; + + try { + springCtxCls = Class.forName("org.springframework.context.ApplicationContext"); + } + catch (Exception ignored) { + // No-op. + } + + List<Class<?>> excl = new ArrayList<>(); + + // Non-GridGain classes. + excl.add(MBeanServer.class); + excl.add(ExecutorService.class); + excl.add(ClassLoader.class); + excl.add(Thread.class); + + if (springCtxCls != null) + excl.add(springCtxCls); + + // GridGain classes. + excl.add(IgniteLogger.class); + excl.add(ComputeTaskSession.class); + excl.add(ComputeLoadBalancer.class); + excl.add(ComputeJobContext.class); + excl.add(Marshaller.class); + excl.add(GridComponent.class); + excl.add(ComputeTaskContinuousMapper.class); + + EXCL_CLASSES = U.toArray(excl, new Class[excl.size()]); + } + + /** + * Ensures singleton. + */ + private MarshallerExclusions() { + // No-op. + } + + /** + * Checks given class against predefined set of excluded types. + * + * @param cls Class to check. + * @return {@code true} if class should be excluded, {@code false} otherwise. + */ + @SuppressWarnings("ForLoopReplaceableByForEach") + private static boolean isExcluded0(Class<?> cls) { + assert cls != null; + + final Class<?>[] inc = INCL_CLASSES; + + // NOTE: don't use foreach for performance reasons. + for (int i = 0; i < inc.length; i++) + if (inc[i].isAssignableFrom(cls)) + return false; + + final Class<?>[] exc = EXCL_CLASSES; + + // NOTE: don't use foreach for performance reasons. + for (int i = 0; i < exc.length; i++) + if (exc[i].isAssignableFrom(cls)) + return true; + + return false; + } + + /** + * Checks whether or not given class should be excluded from marshalling. + * + * @param cls Class to check. + * @return {@code true} if class should be excluded, {@code false} otherwise. + */ + public static boolean isExcluded(Class<?> cls) { + Boolean res = cache.get(cls); + + if (res == null) { + res = isExcluded0(cls); + + cache.put(cls, res); + } + + return res; + } + + /** + * Intended for test purposes only. + */ + public static void clearCache() { + cache.clear(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshaller.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshaller.java deleted file mode 100644 index 92c5a61..0000000 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshaller.java +++ /dev/null @@ -1,117 +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.jdk; - -import org.apache.ignite.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.marshaller.*; -import org.jetbrains.annotations.*; - -import java.io.*; - -/** - * Implementation of {@link org.apache.ignite.marshaller.IgniteMarshaller} based on JDK serialization mechanism. - * <p> - * <h1 class="header">Configuration</h1> - * <h2 class="header">Mandatory</h2> - * This marshaller has no mandatory configuration parameters. - * <h2 class="header">Java Example</h2> - * {@code GridJdkMarshaller} needs to be explicitly configured to override default {@link org.apache.ignite.marshaller.optimized.IgniteOptimizedMarshaller}. - * <pre name="code" class="java"> - * GridJdkMarshaller marshaller = new GridJdkMarshaller(); - * - * GridConfiguration cfg = new GridConfiguration(); - * - * // Override default marshaller. - * cfg.setMarshaller(marshaller); - * - * // Starts grid. - * G.start(cfg); - * </pre> - * <h2 class="header">Spring Example</h2> - * GridJdkMarshaller can be configured from Spring XML configuration file: - * <pre name="code" class="xml"> - * <bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfiguration" singleton="true"> - * ... - * <property name="marshaller"> - * <bean class="org.apache.ignite.marshaller.jdk.GridJdkMarshaller"/> - * </property> - * ... - * </bean> - * </pre> - * <p> - * <img src="http://www.gridgain.com/images/spring-small.png"> - * <br> - * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a> - */ -public class IgniteJdkMarshaller extends IgniteAbstractMarshaller { - /** {@inheritDoc} */ - @Override public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException { - assert out != null; - - ObjectOutputStream objOut = null; - - try { - objOut = new IgniteJdkMarshallerObjectOutputStream(new IgniteJdkMarshallerOutputStreamWrapper(out)); - - // Make sure that we serialize only task, without class loader. - objOut.writeObject(obj); - - objOut.flush(); - } - catch (IOException e) { - throw new IgniteCheckedException("Failed to serialize object: " + obj, e); - } - finally{ - U.closeQuiet(objOut); - } - } - - /** {@inheritDoc} */ - @SuppressWarnings({"unchecked"}) - @Override public <T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException { - assert in != null; - - if (clsLdr == null) - clsLdr = getClass().getClassLoader(); - - ObjectInputStream objIn = null; - - try { - objIn = new IgniteJdkMarshallerObjectInputStream(new IgniteJdkMarshallerInputStreamWrapper(in), clsLdr); - - return (T)objIn.readObject(); - } - catch (IOException e) { - throw new IgniteCheckedException("Failed to deserialize object with given class loader: " + clsLdr, e); - } - 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, e); - } - finally{ - U.closeQuiet(objIn); - } - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(IgniteJdkMarshaller.class, this); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerDummySerializable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerDummySerializable.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerDummySerializable.java deleted file mode 100644 index 063f9d3..0000000 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerDummySerializable.java +++ /dev/null @@ -1,30 +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.jdk; - -import java.io.*; - -/** - * Serializable object used for {@link Object} replacement. - */ -class IgniteJdkMarshallerDummySerializable implements Serializable { - /** */ - private static final long serialVersionUID = 0L; - - // No-op. -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerInputStreamWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerInputStreamWrapper.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerInputStreamWrapper.java deleted file mode 100644 index 88aefa8..0000000 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerInputStreamWrapper.java +++ /dev/null @@ -1,81 +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.jdk; - -import java.io.*; - -/** - * Wrapper for {@link InputStream}. - */ -class IgniteJdkMarshallerInputStreamWrapper extends InputStream { - /** */ - private InputStream in; - - /** - * Creates wrapper. - * - * @param in Wrapped input stream - */ - IgniteJdkMarshallerInputStreamWrapper(InputStream in) { - assert in != null; - - this.in = in; - } - - /** {@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} */ - @Override public long skip(long n) throws IOException { - return in.skip(n); - } - - /** {@inheritDoc} */ - @Override public int available() throws IOException { - return in.available(); - } - - /** {@inheritDoc} */ - @SuppressWarnings({"NonSynchronizedMethodOverridesSynchronizedMethod"}) - @Override public void mark(int readLimit) { - in.mark(readLimit); - } - - /** {@inheritDoc} */ - @SuppressWarnings({"NonSynchronizedMethodOverridesSynchronizedMethod"}) - @Override public void reset() throws IOException { - in.reset(); - } - - /** {@inheritDoc} */ - @Override public boolean markSupported() { - return in.markSupported(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerObjectInputStream.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerObjectInputStream.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerObjectInputStream.java deleted file mode 100644 index e3cc6b5..0000000 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerObjectInputStream.java +++ /dev/null @@ -1,61 +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.jdk; - -import java.io.*; - -/** - * This class defines custom JDK object input stream. - */ -class IgniteJdkMarshallerObjectInputStream extends ObjectInputStream { - /** */ - private final ClassLoader clsLdr; - - /** - * @param in Parent input stream. - * @param clsLdr Custom class loader. - * @throws IOException If initialization failed. - */ - IgniteJdkMarshallerObjectInputStream(InputStream in, ClassLoader clsLdr) throws IOException { - super(in); - - assert clsLdr != null; - - this.clsLdr = clsLdr; - - enableResolveObject(true); - } - - /** {@inheritDoc} */ - @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { - // NOTE: DO NOT CHANGE TO 'clsLoader.loadClass()' - // Must have 'Class.forName()' instead of clsLoader.loadClass() - // due to weird ClassNotFoundExceptions for arrays of classes - // in certain cases. - return Class.forName(desc.getName(), true, clsLdr); - } - - /** {@inheritDoc} */ - @Override protected Object resolveObject(Object o) throws IOException { - if (o != null && o.getClass().equals(IgniteJdkMarshallerDummySerializable.class)) - return new Object(); - - return super.resolveObject(o); - } -} - http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerObjectOutputStream.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerObjectOutputStream.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerObjectOutputStream.java deleted file mode 100644 index 13d53ce..0000000 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerObjectOutputStream.java +++ /dev/null @@ -1,45 +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.jdk; - -import org.apache.ignite.marshaller.*; -import org.jetbrains.annotations.*; - -import java.io.*; - -/** - * This class defines own object output stream. - */ -class IgniteJdkMarshallerObjectOutputStream extends ObjectOutputStream { - /** - * @param out Output stream. - * @throws IOException Thrown in case of any I/O errors. - */ - IgniteJdkMarshallerObjectOutputStream(OutputStream out) throws IOException { - super(out); - - enableReplaceObject(true); - } - - /** {@inheritDoc} */ - @Nullable @Override protected Object replaceObject(Object o) throws IOException { - return o == null || IgniteMarshallerExclusions.isExcluded(o.getClass()) ? null : - o.getClass().equals(Object.class) ? new IgniteJdkMarshallerDummySerializable() : super.replaceObject(o); - } -} - http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerOutputStreamWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerOutputStreamWrapper.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerOutputStreamWrapper.java deleted file mode 100644 index 33f3d7c..0000000 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/IgniteJdkMarshallerOutputStreamWrapper.java +++ /dev/null @@ -1,59 +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.jdk; - -import java.io.*; - -/** - * Wrapper for {@link OutputStream}. - */ -class IgniteJdkMarshallerOutputStreamWrapper extends OutputStream { - /** */ - private OutputStream out; - - /** - * Creates wrapper. - * - * @param out Wrapped output stream - */ - IgniteJdkMarshallerOutputStreamWrapper(OutputStream out) { - assert out != null; - - this.out = out; - } - - /** {@inheritDoc} */ - @Override public void write(int b) throws IOException { - out.write(b); - } - - /** {@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 public void flush() throws IOException { - out.flush(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/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 new file mode 100644 index 0000000..868abaf --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshaller.java @@ -0,0 +1,117 @@ +/* + * 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.jdk; + +import org.apache.ignite.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.marshaller.*; +import org.jetbrains.annotations.*; + +import java.io.*; + +/** + * Implementation of {@link org.apache.ignite.marshaller.Marshaller} based on JDK serialization mechanism. + * <p> + * <h1 class="header">Configuration</h1> + * <h2 class="header">Mandatory</h2> + * This marshaller has no mandatory configuration parameters. + * <h2 class="header">Java Example</h2> + * {@code GridJdkMarshaller} needs to be explicitly configured to override default {@link org.apache.ignite.marshaller.optimized.OptimizedMarshaller}. + * <pre name="code" class="java"> + * GridJdkMarshaller marshaller = new GridJdkMarshaller(); + * + * GridConfiguration cfg = new GridConfiguration(); + * + * // Override default marshaller. + * cfg.setMarshaller(marshaller); + * + * // Starts grid. + * G.start(cfg); + * </pre> + * <h2 class="header">Spring Example</h2> + * GridJdkMarshaller can be configured from Spring XML configuration file: + * <pre name="code" class="xml"> + * <bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfiguration" singleton="true"> + * ... + * <property name="marshaller"> + * <bean class="org.apache.ignite.marshaller.jdk.GridJdkMarshaller"/> + * </property> + * ... + * </bean> + * </pre> + * <p> + * <img src="http://www.gridgain.com/images/spring-small.png"> + * <br> + * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a> + */ +public class JdkMarshaller extends AbstractMarshaller { + /** {@inheritDoc} */ + @Override public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException { + assert out != null; + + ObjectOutputStream objOut = null; + + try { + objOut = new JdkMarshallerObjectOutputStream(new JdkMarshallerOutputStreamWrapper(out)); + + // Make sure that we serialize only task, without class loader. + objOut.writeObject(obj); + + objOut.flush(); + } + catch (IOException e) { + throw new IgniteCheckedException("Failed to serialize object: " + obj, e); + } + finally{ + U.closeQuiet(objOut); + } + } + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked"}) + @Override public <T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException { + assert in != null; + + if (clsLdr == null) + clsLdr = getClass().getClassLoader(); + + ObjectInputStream objIn = null; + + try { + objIn = new JdkMarshallerObjectInputStream(new JdkMarshallerInputStreamWrapper(in), clsLdr); + + return (T)objIn.readObject(); + } + catch (IOException e) { + throw new IgniteCheckedException("Failed to deserialize object with given class loader: " + clsLdr, e); + } + 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, e); + } + finally{ + U.closeQuiet(objIn); + } + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(JdkMarshaller.class, this); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerDummySerializable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerDummySerializable.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerDummySerializable.java new file mode 100644 index 0000000..7d5f70c --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerDummySerializable.java @@ -0,0 +1,30 @@ +/* + * 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.jdk; + +import java.io.*; + +/** + * Serializable object used for {@link Object} replacement. + */ +class JdkMarshallerDummySerializable implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + // No-op. +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerInputStreamWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerInputStreamWrapper.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerInputStreamWrapper.java new file mode 100644 index 0000000..fb10b86 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerInputStreamWrapper.java @@ -0,0 +1,81 @@ +/* + * 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.jdk; + +import java.io.*; + +/** + * Wrapper for {@link InputStream}. + */ +class JdkMarshallerInputStreamWrapper extends InputStream { + /** */ + private InputStream in; + + /** + * Creates wrapper. + * + * @param in Wrapped input stream + */ + JdkMarshallerInputStreamWrapper(InputStream in) { + assert in != null; + + this.in = in; + } + + /** {@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} */ + @Override public long skip(long n) throws IOException { + return in.skip(n); + } + + /** {@inheritDoc} */ + @Override public int available() throws IOException { + return in.available(); + } + + /** {@inheritDoc} */ + @SuppressWarnings({"NonSynchronizedMethodOverridesSynchronizedMethod"}) + @Override public void mark(int readLimit) { + in.mark(readLimit); + } + + /** {@inheritDoc} */ + @SuppressWarnings({"NonSynchronizedMethodOverridesSynchronizedMethod"}) + @Override public void reset() throws IOException { + in.reset(); + } + + /** {@inheritDoc} */ + @Override public boolean markSupported() { + return in.markSupported(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerObjectInputStream.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerObjectInputStream.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerObjectInputStream.java new file mode 100644 index 0000000..119f5f5 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerObjectInputStream.java @@ -0,0 +1,61 @@ +/* + * 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.jdk; + +import java.io.*; + +/** + * This class defines custom JDK object input stream. + */ +class JdkMarshallerObjectInputStream extends ObjectInputStream { + /** */ + private final ClassLoader clsLdr; + + /** + * @param in Parent input stream. + * @param clsLdr Custom class loader. + * @throws IOException If initialization failed. + */ + JdkMarshallerObjectInputStream(InputStream in, ClassLoader clsLdr) throws IOException { + super(in); + + assert clsLdr != null; + + this.clsLdr = clsLdr; + + enableResolveObject(true); + } + + /** {@inheritDoc} */ + @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { + // NOTE: DO NOT CHANGE TO 'clsLoader.loadClass()' + // Must have 'Class.forName()' instead of clsLoader.loadClass() + // due to weird ClassNotFoundExceptions for arrays of classes + // in certain cases. + return Class.forName(desc.getName(), true, clsLdr); + } + + /** {@inheritDoc} */ + @Override protected Object resolveObject(Object o) throws IOException { + if (o != null && o.getClass().equals(JdkMarshallerDummySerializable.class)) + return new Object(); + + return super.resolveObject(o); + } +} + http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerObjectOutputStream.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerObjectOutputStream.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerObjectOutputStream.java new file mode 100644 index 0000000..13f603e --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerObjectOutputStream.java @@ -0,0 +1,45 @@ +/* + * 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.jdk; + +import org.apache.ignite.marshaller.*; +import org.jetbrains.annotations.*; + +import java.io.*; + +/** + * This class defines own object output stream. + */ +class JdkMarshallerObjectOutputStream extends ObjectOutputStream { + /** + * @param out Output stream. + * @throws IOException Thrown in case of any I/O errors. + */ + JdkMarshallerObjectOutputStream(OutputStream out) throws IOException { + super(out); + + enableReplaceObject(true); + } + + /** {@inheritDoc} */ + @Nullable @Override protected Object replaceObject(Object o) throws IOException { + return o == null || MarshallerExclusions.isExcluded(o.getClass()) ? null : + o.getClass().equals(Object.class) ? new JdkMarshallerDummySerializable() : super.replaceObject(o); + } +} + http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5674cdde/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerOutputStreamWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerOutputStreamWrapper.java b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerOutputStreamWrapper.java new file mode 100644 index 0000000..5e17639 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/jdk/JdkMarshallerOutputStreamWrapper.java @@ -0,0 +1,59 @@ +/* + * 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.jdk; + +import java.io.*; + +/** + * Wrapper for {@link OutputStream}. + */ +class JdkMarshallerOutputStreamWrapper extends OutputStream { + /** */ + private OutputStream out; + + /** + * Creates wrapper. + * + * @param out Wrapped output stream + */ + JdkMarshallerOutputStreamWrapper(OutputStream out) { + assert out != null; + + this.out = out; + } + + /** {@inheritDoc} */ + @Override public void write(int b) throws IOException { + out.write(b); + } + + /** {@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 public void flush() throws IOException { + out.flush(); + } +}
