You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2015/12/11 16:55:51 UTC
[23/59] [abbrv] ignite git commit: ignite-2065: rename "portable"
packages to "binary"
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryCachingMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryCachingMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryCachingMetadataHandler.java
deleted file mode 100644
index a3c846b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryCachingMetadataHandler.java
+++ /dev/null
@@ -1,70 +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.internal.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-
-import java.util.HashMap;
-
-/**
- * Simple caching metadata handler. Used mainly in tests.
- */
-public class BinaryCachingMetadataHandler implements BinaryMetadataHandler {
- /** Cached metadatas. */
- private final HashMap<Integer, BinaryType> metas = new HashMap<>();
-
- /**
- * Create new handler instance.
- *
- * @return New handler.
- */
- public static BinaryCachingMetadataHandler create() {
- return new BinaryCachingMetadataHandler();
- }
-
- /**
- * Private constructor.
- */
- private BinaryCachingMetadataHandler() {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public synchronized void addMeta(int typeId, BinaryType type) throws BinaryObjectException {
- synchronized (this) {
- BinaryType oldType = metas.put(typeId, type);
-
- if (oldType != null) {
- BinaryMetadata oldMeta = ((BinaryTypeImpl)oldType).metadata();
- BinaryMetadata newMeta = ((BinaryTypeImpl)type).metadata();
-
- BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta);
-
- BinaryType mergedType = mergedMeta.wrap(((BinaryTypeImpl)oldType).context());
-
- metas.put(typeId, mergedType);
- }
- }
- }
-
- /** {@inheritDoc} */
- @Override public synchronized BinaryType metadata(int typeId) throws BinaryObjectException {
- return metas.get(typeId);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumCache.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumCache.java
deleted file mode 100644
index fc042e5..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumCache.java
+++ /dev/null
@@ -1,69 +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.internal.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.jsr166.ConcurrentHashMap8;
-
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * Cache for enum constants.
- */
-public class BinaryEnumCache {
- /** Cache for enum constants. */
- private static final ConcurrentMap<Class<?>, Object[]> ENUM_CACHE = new ConcurrentHashMap8<>();
-
- /**
- * Get value for the given class and ordinal.
- *
- * @param cls Class.
- * @param ord Ordinal.
- * @return Value.
- * @throws BinaryObjectException In case of invalid ordinal.
- */
- @SuppressWarnings("unchecked")
- public static <T> T get(Class<?> cls, int ord) throws BinaryObjectException {
- assert cls != null;
-
- if (ord >= 0) {
- Object[] vals = ENUM_CACHE.get(cls);
-
- if (vals == null) {
- vals = cls.getEnumConstants();
-
- ENUM_CACHE.putIfAbsent(cls, vals);
- }
-
- if (ord < vals.length)
- return (T) vals[ord];
- else
- throw new BinaryObjectException("Failed to get enum value for ordinal (do you have correct class " +
- "version?) [cls=" + cls.getName() + ", ordinal=" + ord + ", totalValues=" + vals.length + ']');
- }
- else
- return null;
- }
-
- /**
- * Clears cache.
- */
- public static void clear() {
- ENUM_CACHE.clear();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
deleted file mode 100644
index 467d767..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
+++ /dev/null
@@ -1,311 +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.internal.portable;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.internal.GridDirectTransient;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
-import org.apache.ignite.internal.util.typedef.internal.SB;
-import org.apache.ignite.plugin.extensions.communication.MessageReader;
-import org.apache.ignite.plugin.extensions.communication.MessageWriter;
-import org.jetbrains.annotations.Nullable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.nio.ByteBuffer;
-
-/**
- * Binary enum object.
- */
-public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, CacheObject {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** Context. */
- @GridDirectTransient
- private PortableContext ctx;
-
- /** Type ID. */
- private int typeId;
-
- /** Raw data. */
- private String clsName;
-
- /** Ordinal. */
- private int ord;
-
- /**
- * {@link Externalizable} support.
- */
- public BinaryEnumObjectImpl() {
- // No-op.
- }
-
- /**
- * Constructor.
- *
- * @param ctx Context.
- * @param typeId Type ID.
- * @param clsName Class name.
- * @param ord Ordinal.
- */
- public BinaryEnumObjectImpl(PortableContext ctx, int typeId, @Nullable String clsName, int ord) {
- assert ctx != null;
-
- this.ctx = ctx;
- this.typeId = typeId;
- this.clsName = clsName;
- this.ord = ord;
- }
-
- /**
- * @return Class name.
- */
- @Nullable public String className() {
- return clsName;
- }
-
- /** {@inheritDoc} */
- @Override public int typeId() {
- return typeId;
- }
-
- /** {@inheritDoc} */
- @Override public BinaryType type() throws BinaryObjectException {
- return ctx.metadata(typeId());
- }
-
- /** {@inheritDoc} */
- @Override public <F> F field(String fieldName) throws BinaryObjectException {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public boolean hasField(String fieldName) {
- return false;
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override public <T> T deserialize() throws BinaryObjectException {
- Class cls = PortableUtils.resolveClass(ctx, typeId, clsName, null, true);
-
- return BinaryEnumCache.get(cls, ord);
- }
-
- /** {@inheritDoc} */
- @Override public BinaryObject clone() throws CloneNotSupportedException {
- return (BinaryObject)super.clone();
- }
-
- /** {@inheritDoc} */
- @Override public int enumOrdinal() throws BinaryObjectException {
- return ord;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return 31 * typeId + ord;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object obj) {
- if (obj != null && (obj instanceof BinaryEnumObjectImpl)) {
- BinaryEnumObjectImpl other = (BinaryEnumObjectImpl)obj;
-
- return typeId == other.typeId && ord == other.ord;
- }
-
- return false;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- // 1. Try deserializing the object.
- try {
- Object val = deserialize();
-
- return new SB().a(val).toString();
- }
- catch (Exception e) {
- // No-op.
- }
-
- // 2. Try getting meta.
- BinaryType type;
-
- try {
- type = type();
- }
- catch (Exception e) {
- type = null;
- }
-
- if (type != null) {
- return type.typeName() + "[ordinal=" + ord + ']';
- }
- else {
- if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID)
- return "BinaryEnum[clsName=" + clsName + ", ordinal=" + ord + ']';
- else
- return "BinaryEnum[typeId=" + typeId + ", ordinal=" + ord + ']';
- }
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(ctx);
-
- out.writeInt(typeId);
- out.writeObject(clsName);
- out.writeInt(ord);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- ctx = (PortableContext)in.readObject();
-
- typeId = in.readInt();
- clsName = (String)in.readObject();
- ord = in.readInt();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
- return deserialize();
- }
-
- /** {@inheritDoc} */
- @Override public byte[] valueBytes(CacheObjectContext cacheCtx) throws IgniteCheckedException {
- return ctx.marshaller().marshal(this);
- }
-
- /** {@inheritDoc} */
- @Override public byte cacheObjectType() {
- return TYPE_BINARY;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isPlatformType() {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
- return this;
- }
-
- /** {@inheritDoc} */
- @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
- this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.processor()).portableContext();
- }
-
- /** {@inheritDoc} */
- @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public byte directType() {
- return 119;
- }
-
- /** {@inheritDoc} */
- @Override public byte fieldsCount() {
- return 3;
- }
-
- /** {@inheritDoc} */
- @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
- writer.setBuffer(buf);
-
- if (!writer.isHeaderWritten()) {
- if (!writer.writeHeader(directType(), fieldsCount()))
- return false;
-
- writer.onHeaderWritten();
- }
-
- switch (writer.state()) {
- case 0:
- if (!writer.writeString("clsName", clsName))
- return false;
-
- writer.incrementState();
-
- case 1:
- if (!writer.writeInt("ord", ord))
- return false;
-
- writer.incrementState();
-
- case 2:
- if (!writer.writeInt("typeId", typeId))
- return false;
-
- writer.incrementState();
-
- }
-
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
- reader.setBuffer(buf);
-
- if (!reader.beforeMessageRead())
- return false;
-
- switch (reader.state()) {
- case 0:
- clsName = reader.readString("clsName");
-
- if (!reader.isLastRead())
- return false;
-
- reader.incrementState();
-
- case 1:
- ord = reader.readInt("ord");
-
- if (!reader.isLastRead())
- return false;
-
- reader.incrementState();
-
- case 2:
- typeId = reader.readInt("typeId");
-
- if (!reader.isLastRead())
- return false;
-
- reader.incrementState();
-
- }
-
- return reader.afterMessageRead(BinaryEnumObjectImpl.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java
deleted file mode 100644
index 7701fb5..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java
+++ /dev/null
@@ -1,856 +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.internal.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import sun.misc.Unsafe;
-
-import java.lang.reflect.Field;
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-
-/**
- * Field accessor to speedup access.
- */
-public abstract class BinaryFieldAccessor {
- /** Field ID. */
- protected final int id;
-
- /** Mode. */
- protected final BinaryWriteMode mode;
-
- /**
- * Create accessor for the field.
- *
- * @param field Field.
- * @param id FIeld ID.
- * @return Accessor.
- */
- public static BinaryFieldAccessor create(Field field, int id) {
- BinaryWriteMode mode = PortableUtils.mode(field.getType());
-
- switch (mode) {
- case P_BYTE:
- return new BytePrimitiveAccessor(field, id);
-
- case P_BOOLEAN:
- return new BooleanPrimitiveAccessor(field, id);
-
- case P_SHORT:
- return new ShortPrimitiveAccessor(field, id);
-
- case P_CHAR:
- return new CharPrimitiveAccessor(field, id);
-
- case P_INT:
- return new IntPrimitiveAccessor(field, id);
-
- case P_LONG:
- return new LongPrimitiveAccessor(field, id);
-
- case P_FLOAT:
- return new FloatPrimitiveAccessor(field, id);
-
- case P_DOUBLE:
- return new DoublePrimitiveAccessor(field, id);
-
- case BYTE:
- case BOOLEAN:
- case SHORT:
- case CHAR:
- case INT:
- case LONG:
- case FLOAT:
- case DOUBLE:
- case DECIMAL:
- case STRING:
- case UUID:
- case DATE:
- case TIMESTAMP:
- case BYTE_ARR:
- case SHORT_ARR:
- case INT_ARR:
- case LONG_ARR:
- case FLOAT_ARR:
- case DOUBLE_ARR:
- case CHAR_ARR:
- case BOOLEAN_ARR:
- case DECIMAL_ARR:
- case STRING_ARR:
- case UUID_ARR:
- case DATE_ARR:
- case TIMESTAMP_ARR:
- case ENUM_ARR:
- case OBJECT_ARR:
- case PORTABLE_OBJ:
- case PORTABLE:
- case EXTERNALIZABLE:
- return new DefaultFinalClassAccessor(field, id, mode, false);
-
- default:
- return new DefaultFinalClassAccessor(field, id, mode, !U.isFinal(field.getType()));
- }
- }
-
- /**
- * Protected constructor.
- *
- * @param id Field ID.
- * @param mode Mode;
- */
- protected BinaryFieldAccessor(int id, BinaryWriteMode mode) {
- assert id != 0;
- assert mode != null;
-
- this.id = id;
- this.mode = mode;
- }
-
- /**
- * Get mode.
- *
- * @return Mode.
- */
- public BinaryWriteMode mode() {
- return mode;
- }
-
- /**
- * Write field.
- *
- * @param obj Object.
- * @param writer Writer.
- * @throws BinaryObjectException If failed.
- */
- public abstract void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException;
-
- /**
- * Read field.
- *
- * @param obj Object.
- * @param reader Reader.
- * @throws BinaryObjectException If failed.
- */
- public abstract void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException;
-
- /**
- * Base primitive field accessor.
- */
- private static abstract class AbstractPrimitiveAccessor extends BinaryFieldAccessor {
- /** Unsafe instance. */
- protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
- /** Offset. */
- protected final long offset;
-
- /**
- * Constructor.
- *
- * @param field Field.
- * @param id Field ID.
- * @param mode Mode.
- */
- protected AbstractPrimitiveAccessor(Field field, int id, BinaryWriteMode mode) {
- super(id, mode);
-
- assert field != null;
-
- offset = UNSAFE.objectFieldOffset(field);
- }
- }
-
- /**
- * Byte field accessor.
- */
- private static class BytePrimitiveAccessor extends AbstractPrimitiveAccessor {
- /**
- * Constructor.
- *
- * @param field Field.
- */
- public BytePrimitiveAccessor(Field field, int id) {
- super(field, id, BinaryWriteMode.P_BYTE);
- }
-
- /** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
- writer.writeFieldIdNoSchemaUpdate(id);
-
- byte val = UNSAFE.getByte(obj, offset);
-
- writer.writeByteFieldPrimitive(val);
- }
-
- /** {@inheritDoc} */
- @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
- byte val = reader.readByte(id);
-
- UNSAFE.putByte(obj, offset, val);
- }
- }
-
- /**
- * Boolean field accessor.
- */
- private static class BooleanPrimitiveAccessor extends AbstractPrimitiveAccessor {
- /**
- * Constructor.
- *
- * @param field Field.
- */
- public BooleanPrimitiveAccessor(Field field, int id) {
- super(field, id, BinaryWriteMode.P_BOOLEAN);
- }
-
- /** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
- writer.writeFieldIdNoSchemaUpdate(id);
-
- boolean val = UNSAFE.getBoolean(obj, offset);
-
- writer.writeBooleanFieldPrimitive(val);
- }
-
- /** {@inheritDoc} */
- @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
- boolean val = reader.readBoolean(id);
-
- UNSAFE.putBoolean(obj, offset, val);
- }
- }
-
- /**
- * Short field accessor.
- */
- private static class ShortPrimitiveAccessor extends AbstractPrimitiveAccessor {
- /**
- * Constructor.
- *
- * @param field Field.
- */
- public ShortPrimitiveAccessor(Field field, int id) {
- super(field, id, BinaryWriteMode.P_SHORT);
- }
-
- /** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
- writer.writeFieldIdNoSchemaUpdate(id);
-
- short val = UNSAFE.getShort(obj, offset);
-
- writer.writeShortFieldPrimitive(val);
- }
-
- /** {@inheritDoc} */
- @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
- short val = reader.readShort(id);
-
- UNSAFE.putShort(obj, offset, val);
- }
- }
-
- /**
- * Char field accessor.
- */
- private static class CharPrimitiveAccessor extends AbstractPrimitiveAccessor {
- /**
- * Constructor.
- *
- * @param field Field.
- */
- public CharPrimitiveAccessor(Field field, int id) {
- super(field, id, BinaryWriteMode.P_CHAR);
- }
-
- /** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
- writer.writeFieldIdNoSchemaUpdate(id);
-
- char val = UNSAFE.getChar(obj, offset);
-
- writer.writeCharFieldPrimitive(val);
- }
-
- /** {@inheritDoc} */
- @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
- char val = reader.readChar(id);
-
- UNSAFE.putChar(obj, offset, val);
- }
- }
-
- /**
- * Int field accessor.
- */
- private static class IntPrimitiveAccessor extends AbstractPrimitiveAccessor {
- /**
- * Constructor.
- *
- * @param field Field.
- */
- public IntPrimitiveAccessor(Field field, int id) {
- super(field, id, BinaryWriteMode.P_INT);
- }
-
- /** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
- writer.writeFieldIdNoSchemaUpdate(id);
-
- int val = UNSAFE.getInt(obj, offset);
-
- writer.writeIntFieldPrimitive(val);
- }
-
- /** {@inheritDoc} */
- @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
- int val = reader.readInt(id);
-
- UNSAFE.putInt(obj, offset, val);
- }
- }
-
- /**
- * Long field accessor.
- */
- private static class LongPrimitiveAccessor extends AbstractPrimitiveAccessor {
- /**
- * Constructor.
- *
- * @param field Field.
- */
- public LongPrimitiveAccessor(Field field, int id) {
- super(field, id, BinaryWriteMode.P_LONG);
- }
-
- /** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
- writer.writeFieldIdNoSchemaUpdate(id);
-
- long val = UNSAFE.getLong(obj, offset);
-
- writer.writeLongFieldPrimitive(val);
- }
-
- /** {@inheritDoc} */
- @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
- long val = reader.readLong(id);
-
- UNSAFE.putLong(obj, offset, val);
- }
- }
-
- /**
- * Float field accessor.
- */
- private static class FloatPrimitiveAccessor extends AbstractPrimitiveAccessor {
- /**
- * Constructor.
- *
- * @param field Field.
- */
- public FloatPrimitiveAccessor(Field field, int id) {
- super(field, id, BinaryWriteMode.P_FLOAT);
- }
-
- /** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
- writer.writeFieldIdNoSchemaUpdate(id);
-
- float val = UNSAFE.getFloat(obj, offset);
-
- writer.writeFloatFieldPrimitive(val);
- }
-
- /** {@inheritDoc} */
- @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
- float val = reader.readFloat(id);
-
- UNSAFE.putFloat(obj, offset, val);
- }
- }
-
- /**
- * Double field accessor.
- */
- private static class DoublePrimitiveAccessor extends AbstractPrimitiveAccessor {
- /**
- * Constructor.
- *
- * @param field Field.
- */
- public DoublePrimitiveAccessor(Field field, int id) {
- super(field, id, BinaryWriteMode.P_DOUBLE);
- }
-
- /** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
- writer.writeFieldIdNoSchemaUpdate(id);
-
- double val = UNSAFE.getDouble(obj, offset);
-
- writer.writeDoubleFieldPrimitive(val);
- }
-
- /** {@inheritDoc} */
- @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
- double val = reader.readDouble(id);
-
- UNSAFE.putDouble(obj, offset, val);
- }
- }
-
- /**
- * Default accessor.
- */
- private static class DefaultFinalClassAccessor extends BinaryFieldAccessor {
- /** Target field. */
- private final Field field;
-
- /** Dynamic accessor flag. */
- private final boolean dynamic;
-
- /**
- * Constructor.
- *
- * @param field Field.
- * @param id Field ID.
- * @param mode Mode.
- */
- DefaultFinalClassAccessor(Field field, int id, BinaryWriteMode mode, boolean dynamic) {
- super(id, mode);
-
- assert field != null;
-
- this.field = field;
- this.dynamic = dynamic;
- }
-
- /** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
- assert obj != null;
- assert writer != null;
-
- writer.writeFieldIdNoSchemaUpdate(id);
-
- Object val;
-
- try {
- val = field.get(obj);
- }
- catch (IllegalAccessException e) {
- throw new BinaryObjectException("Failed to get value for field: " + field, e);
- }
-
- switch (mode(val)) {
- case BYTE:
- writer.writeByteField((Byte) val);
-
- break;
-
- case SHORT:
- writer.writeShortField((Short) val);
-
- break;
-
- case INT:
- writer.writeIntField((Integer) val);
-
- break;
-
- case LONG:
- writer.writeLongField((Long)val);
-
- break;
-
- case FLOAT:
- writer.writeFloatField((Float)val);
-
- break;
-
- case DOUBLE:
- writer.writeDoubleField((Double)val);
-
- break;
-
- case CHAR:
- writer.writeCharField((Character)val);
-
- break;
-
- case BOOLEAN:
- writer.writeBooleanField((Boolean)val);
-
- break;
-
- case DECIMAL:
- writer.writeDecimalField((BigDecimal)val);
-
- break;
-
- case STRING:
- writer.writeStringField((String)val);
-
- break;
-
- case UUID:
- writer.writeUuidField((UUID)val);
-
- break;
-
- case DATE:
- writer.writeDateField((Date)val);
-
- break;
-
- case TIMESTAMP:
- writer.writeTimestampField((Timestamp)val);
-
- break;
-
- case BYTE_ARR:
- writer.writeByteArrayField((byte[])val);
-
- break;
-
- case SHORT_ARR:
- writer.writeShortArrayField((short[])val);
-
- break;
-
- case INT_ARR:
- writer.writeIntArrayField((int[])val);
-
- break;
-
- case LONG_ARR:
- writer.writeLongArrayField((long[])val);
-
- break;
-
- case FLOAT_ARR:
- writer.writeFloatArrayField((float[])val);
-
- break;
-
- case DOUBLE_ARR:
- writer.writeDoubleArrayField((double[])val);
-
- break;
-
- case CHAR_ARR:
- writer.writeCharArrayField((char[])val);
-
- break;
-
- case BOOLEAN_ARR:
- writer.writeBooleanArrayField((boolean[])val);
-
- break;
-
- case DECIMAL_ARR:
- writer.writeDecimalArrayField((BigDecimal[])val);
-
- break;
-
- case STRING_ARR:
- writer.writeStringArrayField((String[])val);
-
- break;
-
- case UUID_ARR:
- writer.writeUuidArrayField((UUID[])val);
-
- break;
-
- case DATE_ARR:
- writer.writeDateArrayField((Date[])val);
-
- break;
-
- case TIMESTAMP_ARR:
- writer.writeTimestampArrayField((Timestamp[])val);
-
- break;
-
- case OBJECT_ARR:
- writer.writeObjectArrayField((Object[])val);
-
- break;
-
- case COL:
- writer.writeCollectionField((Collection<?>)val);
-
- break;
-
- case MAP:
- writer.writeMapField((Map<?, ?>)val);
-
- break;
-
- case PORTABLE_OBJ:
- writer.writePortableObjectField((BinaryObjectImpl)val);
-
- break;
-
- case ENUM:
- writer.writeEnumField((Enum<?>)val);
-
- break;
-
- case ENUM_ARR:
- writer.writeEnumArrayField((Object[])val);
-
- break;
-
- case PORTABLE:
- case EXTERNALIZABLE:
- case OBJECT:
- writer.writeObjectField(val);
-
- break;
-
- case CLASS:
- writer.writeClassField((Class)val);
-
- break;
-
- default:
- assert false : "Invalid mode: " + mode;
- }
- }
-
- /** {@inheritDoc} */
- @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
- Object val = dynamic ? reader.readField(id) : readFixedType(reader);
-
- try {
- if (val != null || !field.getType().isPrimitive())
- field.set(obj, val);
- }
- catch (IllegalAccessException e) {
- throw new BinaryObjectException("Failed to set value for field: " + field, e);
- }
- }
-
- /**
- * Reads fixed type from the given reader with flags validation.
- *
- * @param reader Reader to read from.
- * @return Read value.
- * @throws BinaryObjectException If failed to read value from the stream.
- */
- protected Object readFixedType(BinaryReaderExImpl reader) throws BinaryObjectException {
- Object val = null;
-
- switch (mode) {
- case BYTE:
- val = reader.readByteNullable(id);
-
- break;
-
- case SHORT:
- val = reader.readShortNullable(id);
-
- break;
-
- case INT:
- val = reader.readIntNullable(id);
-
- break;
-
- case LONG:
- val = reader.readLongNullable(id);
-
- break;
-
- case FLOAT:
- val = reader.readFloatNullable(id);
-
- break;
-
- case DOUBLE:
- val = reader.readDoubleNullable(id);
-
- break;
-
- case CHAR:
- val = reader.readCharNullable(id);
-
- break;
-
- case BOOLEAN:
- val = reader.readBooleanNullable(id);
-
- break;
-
- case DECIMAL:
- val = reader.readDecimal(id);
-
- break;
-
- case STRING:
- val = reader.readString(id);
-
- break;
-
- case UUID:
- val = reader.readUuid(id);
-
- break;
-
- case DATE:
- val = reader.readDate(id);
-
- break;
-
- case TIMESTAMP:
- val = reader.readTimestamp(id);
-
- break;
-
- case BYTE_ARR:
- val = reader.readByteArray(id);
-
- break;
-
- case SHORT_ARR:
- val = reader.readShortArray(id);
-
- break;
-
- case INT_ARR:
- val = reader.readIntArray(id);
-
- break;
-
- case LONG_ARR:
- val = reader.readLongArray(id);
-
- break;
-
- case FLOAT_ARR:
- val = reader.readFloatArray(id);
-
- break;
-
- case DOUBLE_ARR:
- val = reader.readDoubleArray(id);
-
- break;
-
- case CHAR_ARR:
- val = reader.readCharArray(id);
-
- break;
-
- case BOOLEAN_ARR:
- val = reader.readBooleanArray(id);
-
- break;
-
- case DECIMAL_ARR:
- val = reader.readDecimalArray(id);
-
- break;
-
- case STRING_ARR:
- val = reader.readStringArray(id);
-
- break;
-
- case UUID_ARR:
- val = reader.readUuidArray(id);
-
- break;
-
- case DATE_ARR:
- val = reader.readDateArray(id);
-
- break;
-
- case TIMESTAMP_ARR:
- val = reader.readTimestampArray(id);
-
- break;
-
- case OBJECT_ARR:
- val = reader.readObjectArray(id);
-
- break;
-
- case COL:
- val = reader.readCollection(id, null);
-
- break;
-
- case MAP:
- val = reader.readMap(id, null);
-
- break;
-
- case PORTABLE_OBJ:
- val = reader.readPortableObject(id);
-
- break;
-
- case ENUM:
- val = reader.readEnum(id, field.getType());
-
- break;
-
- case ENUM_ARR:
- val = reader.readEnumArray(id, field.getType().getComponentType());
-
- break;
-
- case PORTABLE:
- case EXTERNALIZABLE:
- case OBJECT:
- val = reader.readObject(id);
-
- break;
-
- case CLASS:
- val = reader.readClass(id);
-
- break;
-
- default:
- assert false : "Invalid mode: " + mode;
- }
-
- return val;
- }
-
- /**
- * @param val Val to get write mode for.
- * @return Write mode.
- */
- protected BinaryWriteMode mode(Object val) {
- return dynamic ?
- val == null ? BinaryWriteMode.OBJECT : PortableUtils.mode(val.getClass()) :
- mode;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java
deleted file mode 100644
index b471fbe..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java
+++ /dev/null
@@ -1,116 +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.internal.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryField;
-
-/**
- * Implementation of portable field descriptor.
- */
-public class BinaryFieldImpl implements BinaryField {
- /** Type ID. */
- private final int typeId;
-
- /** Well-known object schemas. */
- @GridToStringExclude
- private final PortableSchemaRegistry schemas;
-
- /** Field name. */
- private final String fieldName;
-
- /** Pre-calculated field ID. */
- private final int fieldId;
-
- /**
- * Constructor.
- *
- * @param schemas Schemas.
- * @param fieldName Field name.
- * @param fieldId Field ID.
- */
- public BinaryFieldImpl(int typeId, PortableSchemaRegistry schemas, String fieldName, int fieldId) {
- assert typeId != 0;
- assert schemas != null;
- assert fieldName != null;
- assert fieldId != 0;
-
- this.typeId = typeId;
- this.schemas = schemas;
- this.fieldName = fieldName;
- this.fieldId = fieldId;
- }
-
- /** {@inheritDoc} */
- @Override public String name() {
- return fieldName;
- }
-
- /** {@inheritDoc} */
- @Override public boolean exists(BinaryObject obj) {
- BinaryObjectExImpl obj0 = (BinaryObjectExImpl)obj;
-
- return fieldOrder(obj0) != PortableSchema.ORDER_NOT_FOUND;
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override public <T> T value(BinaryObject obj) {
- BinaryObjectExImpl obj0 = (BinaryObjectExImpl)obj;
-
- int order = fieldOrder(obj0);
-
- return order != PortableSchema.ORDER_NOT_FOUND ? (T)obj0.fieldByOrder(order) : null;
- }
-
- /**
- * Get relative field offset.
- *
- * @param obj Object.
- * @return Field offset.
- */
- private int fieldOrder(BinaryObjectExImpl obj) {
- if (typeId != obj.typeId()) {
- throw new BinaryObjectException("Failed to get field because type ID of passed object differs" +
- " from type ID this " + BinaryField.class.getSimpleName() + " belongs to [expected=" + typeId +
- ", actual=" + obj.typeId() + ']');
- }
-
- int schemaId = obj.schemaId();
-
- PortableSchema schema = schemas.schema(schemaId);
-
- if (schema == null) {
- schema = obj.createSchema();
-
- schemas.addSchema(schemaId, schema);
- }
-
- assert schema != null;
-
- return schema.order(fieldId);
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(BinaryFieldImpl.class, this);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java
deleted file mode 100644
index 2b5a53a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java
+++ /dev/null
@@ -1,161 +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.internal.portable;
-
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Internal ID mapper. Mimics ID mapper interface, but provides default implementation and offers slightly better
- * performance on micro-level in default case because it doesn't need virtual calls.
- */
-public class BinaryInternalIdMapper implements BinaryIdMapper {
- /** Maximum lower-case character. */
- private static final char MAX_LOWER_CASE_CHAR = 0x7e;
-
- /** Cached lower-case characters. */
- private static final char[] LOWER_CASE_CHARS;
-
- /** Default implementation. */
- private static final BinaryInternalIdMapper DFLT = new BinaryInternalIdMapper();
-
- /**
- * Static initializer.
- */
- static {
- LOWER_CASE_CHARS = new char[MAX_LOWER_CASE_CHAR + 1];
-
- for (char c = 0; c <= MAX_LOWER_CASE_CHAR; c++)
- LOWER_CASE_CHARS[c] = Character.toLowerCase(c);
- }
-
- /**
- * Get default instance.
- *
- * @return Default instance.
- */
- public static BinaryInternalIdMapper defaultInstance() {
- return DFLT;
- }
-
- /**
- * Create internal mapper.
- *
- * @param mapper Public mapper.
- * @return Internal mapper.
- */
- public static BinaryInternalIdMapper create(@Nullable BinaryIdMapper mapper) {
- return mapper == null ? DFLT : new Wrapper(mapper);
- }
-
- /**
- * Private constructor.
- */
- protected BinaryInternalIdMapper() {
- // No-op.
- }
-
- /**
- * Get type ID.
- *
- * @param typeName Type name.
- * @return Type ID.
- */
- public int typeId(String typeName) {
- assert typeName != null;
-
- return lowerCaseHashCode(typeName, true);
- }
-
- /**
- * Get field ID.
- *
- * @param typeId Type ID.
- * @param fieldName Field name.
- * @return Field ID.
- */
- public int fieldId(int typeId, String fieldName) {
- assert fieldName != null;
-
- return lowerCaseHashCode(fieldName, false);
- }
-
- /**
- * Routine to calculate string hash code an
- *
- * @param str String.
- * @param type {@code True} if this is type name, false otherwise.
- * @return Hash code for given string converted to lower case.
- */
- private static int lowerCaseHashCode(String str, boolean type) {
- int len = str.length();
-
- int h = 0;
-
- for (int i = 0; i < len; i++) {
- int c = str.charAt(i);
-
- c = c <= MAX_LOWER_CASE_CHAR ? LOWER_CASE_CHARS[c] : Character.toLowerCase(c);
-
- h = 31 * h + c;
- }
-
- if (h != 0)
- return h;
- else {
- String what = type ? "type" : "field";
-
- throw new BinaryObjectException("Default binary ID mapper resolved " + what + " ID to zero " +
- "(either change " + what + "'s name or use custom ID mapper) [name=" + str + ']');
- }
- }
-
- /**
- * Wrapping ID mapper.
- */
- private static class Wrapper extends BinaryInternalIdMapper {
- /** Delegate. */
- private final BinaryIdMapper mapper;
-
- /**
- * Constructor.
- *
- * @param mapper Delegate.
- */
- private Wrapper(BinaryIdMapper mapper) {
- assert mapper != null;
-
- this.mapper = mapper;
- }
-
- /** {@inheritDoc} */
- @Override public int typeId(String typeName) {
- int id = mapper.typeId(typeName);
-
- return id != 0 ? id : super.typeId(typeName);
- }
-
- /** {@inheritDoc} */
- @Override public int fieldId(int typeId, String fieldName) {
- int id = mapper.fieldId(typeId, fieldName);
-
- return id != 0 ? id : super.fieldId(typeId, fieldName);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java
deleted file mode 100644
index bfaae74..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java
+++ /dev/null
@@ -1,142 +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.internal.portable;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.marshaller.AbstractMarshaller;
-import org.apache.ignite.marshaller.MarshallerContext;
-import org.jetbrains.annotations.Nullable;
-import sun.misc.Unsafe;
-
-/**
- * Implementation of {@link org.apache.ignite.marshaller.Marshaller} that lets to serialize and deserialize all objects
- * in the binary format.
- */
-public class BinaryMarshaller extends AbstractMarshaller {
- /** */
- private GridPortableMarshaller impl;
-
- /**
- * Checks whether {@code BinaryMarshaller} is able to work on the current JVM.
- * <p>
- * As long as {@code BinaryMarshaller} 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 BinaryMarshaller} can work on the current JVM or
- * {@code false} if it can't.
- */
- @SuppressWarnings({"TypeParameterExtendsFinalClass", "ErrorNotRethrown"})
- public static boolean available() {
- try {
- Unsafe unsafe = GridUnsafe.unsafe();
-
- Class<? extends Unsafe> unsafeCls = unsafe.getClass();
-
- 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;
- }
- }
-
- /**
- * Returns currently set {@link MarshallerContext}.
- *
- * @return Marshaller context.
- */
- public MarshallerContext getContext() {
- return ctx;
- }
-
- /**
- * Sets {@link PortableContext}.
- * <p/>
- * @param ctx Portable context.
- */
- @SuppressWarnings("UnusedDeclaration")
- private void setPortableContext(PortableContext ctx, IgniteConfiguration cfg) {
- ctx.configure(this, cfg);
-
- impl = new GridPortableMarshaller(ctx);
- }
-
- /** {@inheritDoc} */
- @Override public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException {
- return impl.marshal(obj);
- }
-
- /** {@inheritDoc} */
- @Override public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException {
- byte[] arr = marshal(obj);
-
- try {
- out.write(arr);
- }
- catch (IOException e) {
- throw new BinaryObjectException("Failed to marshal the object: " + obj, e);
- }
- }
-
- /** {@inheritDoc} */
- @Override public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
- return impl.deserialize(bytes, clsLdr);
- }
-
- /** {@inheritDoc} */
- @Override public <T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
- ByteArrayOutputStream buf = new ByteArrayOutputStream();
-
- // we have to fully read the InputStream because GridPortableMarshaller requires support of a method that
- // returns number of bytes remaining.
- try {
- byte[] arr = new byte[4096];
-
- int cnt;
-
- while ((cnt = in.read(arr)) != -1)
- buf.write(arr, 0, cnt);
-
- buf.flush();
-
- return impl.deserialize(buf.toByteArray(), clsLdr);
- }
- catch (IOException e) {
- throw new BinaryObjectException("Failed to unmarshal the object from InputStream", e);
- }
- }
-
- /** {@inheritDoc} */
- @Override public void onUndeploy(ClassLoader ldr) {
- impl.context().onUndeploy(ldr);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadata.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadata.java
deleted file mode 100644
index 8ba2e23..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadata.java
+++ /dev/null
@@ -1,180 +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.internal.portable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import org.apache.ignite.internal.util.tostring.GridToStringInclude;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Portable metadata which is passed over a wire.
- */
-public class BinaryMetadata implements Externalizable {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** Type ID. */
- private int typeId;
-
- /** Type name. */
- private String typeName;
-
- /** Recorded object fields. */
- @GridToStringInclude
- private Map<String, Integer> fields;
-
- /** Affinity key field name. */
- private String affKeyFieldName;
-
- /** Schemas associated with type. */
- private Collection<PortableSchema> schemas;
-
- /** Whether this is enum type. */
- private boolean isEnum;
-
- /**
- * For {@link Externalizable}.
- */
- public BinaryMetadata() {
- // No-op.
- }
-
- /**
- * Constructor.
- *
- * @param typeId Type ID.
- * @param typeName Type name.
- * @param fields Fields map.
- * @param affKeyFieldName Affinity key field name.
- * @param schemas Schemas.
- * @param isEnum Enum flag.
- */
- public BinaryMetadata(int typeId, String typeName, @Nullable Map<String, Integer> fields,
- @Nullable String affKeyFieldName, @Nullable Collection<PortableSchema> schemas, boolean isEnum) {
- assert typeName != null;
-
- this.typeId = typeId;
- this.typeName = typeName;
- this.fields = fields;
- this.affKeyFieldName = affKeyFieldName;
- this.schemas = schemas;
- this.isEnum = isEnum;
- }
-
- /**
- * @return Type ID.
- */
- public int typeId() {
- return typeId;
- }
-
- /**
- * @return Type name.
- */
- public String typeName() {
- return typeName;
- }
-
- /**
- * @return Fields.
- */
- public Collection<String> fields() {
- return fields != null ? fields.keySet() : Collections.<String>emptyList();
- }
-
- /**
- * @return Fields.
- */
- public Map<String, Integer> fieldsMap() {
- return fields != null ? fields : Collections.<String, Integer>emptyMap();
- }
-
- /**
- * @param fieldName Field name.
- * @return Field type name.
- */
- @Nullable public String fieldTypeName(String fieldName) {
- Integer typeId = fields != null ? fields.get(fieldName) : null;
-
- return typeId != null ? PortableUtils.fieldTypeName(typeId) : null;
- }
-
- /**
- * @return Affinity key field name.
- */
- @Nullable public String affinityKeyFieldName() {
- return affKeyFieldName;
- }
-
- /**
- * @return Schemas.
- */
- public Collection<PortableSchema> schemas() {
- return schemas != null ? schemas : Collections.<PortableSchema>emptyList();
- }
-
- /**
- * @return {@code True} if this is enum type.
- */
- public boolean isEnum() {
- return isEnum;
- }
-
- /**
- * Wrap metadata into binary type.
- *
- * @param ctx Portable context.
- * @return Binary type.
- */
- public BinaryTypeImpl wrap(PortableContext ctx) {
- return new BinaryTypeImpl(ctx, this);
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(typeId);
- U.writeString(out, typeName);
- U.writeMap(out, fields);
- U.writeString(out, affKeyFieldName);
- U.writeCollection(out, schemas);
- out.writeBoolean(isEnum);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- typeId = in.readInt();
- typeName = U.readString(in);
- fields = U.readMap(in);
- affKeyFieldName = U.readString(in);
- schemas = U.readCollection(in);
- isEnum = in.readBoolean();
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(BinaryMetadata.class, this);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java
deleted file mode 100644
index 6ad0ad1..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java
+++ /dev/null
@@ -1,277 +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.internal.portable;
-
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryRawWriter;
-import org.apache.ignite.binary.BinaryWriter;
-import org.jetbrains.annotations.Nullable;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-/**
- * Writer for meta data collection.
- */
-class BinaryMetadataCollector implements BinaryWriter {
- /** Type ID. */
- private final int typeId;
-
- /** Type name. */
- private final String typeName;
-
- /** ID mapper. */
- private final BinaryIdMapper idMapper;
-
- /** Collected metadata. */
- private final Map<String, Integer> meta = new HashMap<>();
-
- /** Schema builder. */
- private PortableSchema.Builder schemaBuilder = PortableSchema.Builder.newBuilder();
-
- /**
- * Constructor.
- *
- * @param typeId Type ID.
- * @param typeName Type name.
- * @param idMapper ID mapper.
- */
- BinaryMetadataCollector(int typeId, String typeName, BinaryIdMapper idMapper) {
- this.typeId = typeId;
- this.typeName = typeName;
- this.idMapper = idMapper;
- }
-
- /**
- * @return Field meta data.
- */
- Map<String, Integer> meta() {
- return meta;
- }
-
- /**
- * @return Schemas.
- */
- PortableSchema schema() {
- return schemaBuilder.build();
- }
-
- /** {@inheritDoc} */
- @Override public void writeByte(String fieldName, byte val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.BYTE);
- }
-
- /** {@inheritDoc} */
- @Override public void writeShort(String fieldName, short val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.SHORT);
- }
-
- /** {@inheritDoc} */
- @Override public void writeInt(String fieldName, int val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.INT);
- }
-
- /** {@inheritDoc} */
- @Override public void writeLong(String fieldName, long val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.LONG);
- }
-
- /** {@inheritDoc} */
- @Override public void writeFloat(String fieldName, float val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.FLOAT);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDouble(String fieldName, double val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.DOUBLE);
- }
-
- /** {@inheritDoc} */
- @Override public void writeChar(String fieldName, char val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.CHAR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeBoolean(String fieldName, boolean val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.BOOLEAN);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.DECIMAL);
- }
-
- /** {@inheritDoc} */
- @Override public void writeString(String fieldName, @Nullable String val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.STRING);
- }
-
- /** {@inheritDoc} */
- @Override public void writeUuid(String fieldName, @Nullable UUID val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.UUID);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDate(String fieldName, @Nullable Date val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.DATE);
- }
-
- /** {@inheritDoc} */
- @Override public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.TIMESTAMP);
- }
-
- /** {@inheritDoc} */
- @Override public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.ENUM);
- }
-
- /** {@inheritDoc} */
- @Override public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.ENUM_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeObject(String fieldName, @Nullable Object obj) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.OBJECT);
- }
-
- /** {@inheritDoc} */
- @Override public void writeByteArray(String fieldName, @Nullable byte[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.BYTE_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeShortArray(String fieldName, @Nullable short[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.SHORT_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeIntArray(String fieldName, @Nullable int[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.INT_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeLongArray(String fieldName, @Nullable long[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.LONG_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeFloatArray(String fieldName, @Nullable float[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.FLOAT_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDoubleArray(String fieldName, @Nullable double[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.DOUBLE_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeCharArray(String fieldName, @Nullable char[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.CHAR_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeBooleanArray(String fieldName, @Nullable boolean[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.BOOLEAN_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.DECIMAL_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeStringArray(String fieldName, @Nullable String[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.STRING_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.UUID_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDateArray(String fieldName, @Nullable Date[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.DATE_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.TIMESTAMP_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public void writeObjectArray(String fieldName, @Nullable Object[] val) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.OBJECT_ARR);
- }
-
- /** {@inheritDoc} */
- @Override public <T> void writeCollection(String fieldName, @Nullable Collection<T> col)
- throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.COL);
- }
-
- /** {@inheritDoc} */
- @Override public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map) throws BinaryObjectException {
- add(fieldName, BinaryWriteMode.MAP);
- }
-
- /** {@inheritDoc} */
- @Override public BinaryRawWriter rawWriter() {
- return (BinaryRawWriter)Proxy.newProxyInstance(getClass().getClassLoader(),
- new Class<?>[] { BinaryRawWriterEx.class },
- new InvocationHandler() {
- @Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable {
- return null;
- }
- });
- }
-
- /**
- * @param name Field name.
- * @param mode Field mode.
- * @throws BinaryObjectException In case of error.
- */
- private void add(String name, BinaryWriteMode mode) throws BinaryObjectException {
- assert name != null;
-
- int fieldTypeId = mode.typeId();
-
- Integer oldFieldTypeId = meta.put(name, fieldTypeId);
-
- if (oldFieldTypeId != null && !oldFieldTypeId.equals(fieldTypeId)) {
- throw new BinaryObjectException(
- "Field is written twice with different types [" + "typeName=" + typeName + ", fieldName=" + name +
- ", fieldTypeName1=" + PortableUtils.fieldTypeName(oldFieldTypeId) +
- ", fieldTypeName2=" + PortableUtils.fieldTypeName(fieldTypeId) + ']'
- );
- }
-
- schemaBuilder.addField(idMapper.fieldId(typeId, name));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataHandler.java
deleted file mode 100644
index add8c2d..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataHandler.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.internal.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-
-/**
- * Portable meta data handler.
- */
-public interface BinaryMetadataHandler {
- /**
- * Adds meta data.
- *
- * @param typeId Type ID.
- * @param meta Meta data.
- * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
- */
- public void addMeta(int typeId, BinaryType meta) throws BinaryObjectException;
-
- /**
- * Gets meta data for provided type ID.
- *
- * @param typeId Type ID.
- * @return Meta data.
- * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
- */
- public BinaryType metadata(int typeId) throws BinaryObjectException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryNoopMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryNoopMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryNoopMetadataHandler.java
deleted file mode 100644
index c4fc5e3..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryNoopMetadataHandler.java
+++ /dev/null
@@ -1,53 +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.internal.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-
-/**
- * No-op metadata handler.
- */
-public class BinaryNoopMetadataHandler implements BinaryMetadataHandler {
- /** Cached singleton instance. */
- private static final BinaryNoopMetadataHandler INSTANCE = new BinaryNoopMetadataHandler();
-
- /**
- * @return Instance.
- */
- public static BinaryNoopMetadataHandler instance() {
- return INSTANCE;
- }
-
- /**
- * Private constructor.
- */
- private BinaryNoopMetadataHandler() {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void addMeta(int typeId, BinaryType meta) throws BinaryObjectException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.java
deleted file mode 100644
index acc8e4b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.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.internal.portable;
-
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- * Extended binary object interface.
- */
-public interface BinaryObjectEx extends BinaryObject {
- /**
- * @return Type ID.
- */
- public int typeId();
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectExImpl.java
deleted file mode 100644
index a32329a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectExImpl.java
+++ /dev/null
@@ -1,251 +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.internal.portable;
-
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.IdentityHashMap;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
-import org.apache.ignite.internal.util.typedef.internal.SB;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.binary.BinaryObject;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Internal portable object interface.
- */
-public abstract class BinaryObjectExImpl implements BinaryObjectEx {
- /**
- * @return Length.
- */
- public abstract int length();
-
- /**
- * @return Object start.
- */
- public abstract int start();
-
- /**
- * @return {@code True} if object is array based.
- */
- protected abstract boolean hasArray();
-
- /**
- * @return Object array if object is array based, otherwise {@code null}.
- */
- public abstract byte[] array();
-
- /**
- * @return Object offheap address is object is offheap based, otherwise 0.
- */
- public abstract long offheapAddress();
-
- /**
- * Gets field value.
- *
- * @param fieldId Field ID.
- * @return Field value.
- * @throws org.apache.ignite.binary.BinaryObjectException In case of any other error.
- */
- @Nullable public abstract <F> F field(int fieldId) throws BinaryObjectException;
-
- /** {@inheritDoc} */
- @Override public int enumOrdinal() throws BinaryObjectException {
- throw new BinaryObjectException("Object is not enum.");
- }
-
- /**
- * Get field by offset.
- *
- * @param fieldOffset Field offset.
- * @return Field value.
- */
- @Nullable protected abstract <F> F fieldByOrder(int fieldOffset);
-
- /**
- * @param ctx Reader context.
- * @param fieldName Field name.
- * @return Field value.
- */
- @Nullable protected abstract <F> F field(BinaryReaderHandles ctx, String fieldName);
-
- /**
- * Get schema ID.
- *
- * @return Schema ID.
- */
- protected abstract int schemaId();
-
- /**
- * Create schema for object.
- *
- * @return Schema.
- */
- protected abstract PortableSchema createSchema();
-
- /** {@inheritDoc} */
- @Override public BinaryObject clone() throws CloneNotSupportedException {
- return (BinaryObject)super.clone();
- }
-
- /** {@inheritDoc} */
- public boolean equals(Object other) {
- if (other == this)
- return true;
-
- if (other == null)
- return false;
-
- if (!(other instanceof BinaryObjectExImpl))
- return false;
-
- BinaryObjectExImpl otherPo = (BinaryObjectExImpl)other;
-
- if (length() != otherPo.length() || typeId() != otherPo.typeId())
- return false;
-
- if (hasArray()) {
- if (otherPo.hasArray()) {
- int len = length();
- int end = start() + len;
-
- byte[] arr = array();
- byte[] otherArr = otherPo.array();
-
- for (int i = start(), j = otherPo.start(); i < end; i++, j++) {
- if (arr[i] != otherArr[j])
- return false;
- }
-
- return true;
- }
- else {
- assert otherPo.offheapAddress() > 0;
-
- return GridUnsafeMemory.compare(otherPo.offheapAddress() + otherPo.start(), array());
- }
- }
- else {
- assert offheapAddress() > 0;
-
- if (otherPo.hasArray())
- return GridUnsafeMemory.compare(offheapAddress() + start(), otherPo.array());
- else {
- assert otherPo.offheapAddress() > 0;
-
- return GridUnsafeMemory.compare(offheapAddress() + start(),
- otherPo.offheapAddress() + otherPo.start(),
- length());
- }
- }
- }
-
- /**
- * @param ctx Reader context.
- * @param handles Handles for already traversed objects.
- * @return String representation.
- */
- private String toString(BinaryReaderHandles ctx, IdentityHashMap<BinaryObject, Integer> handles) {
- int idHash = System.identityHashCode(this);
- int hash = hashCode();
-
- BinaryType meta;
-
- try {
- meta = type();
- }
- catch (BinaryObjectException ignore) {
- meta = null;
- }
-
- if (meta == null)
- return BinaryObject.class.getSimpleName() + " [idHash=" + idHash + ", hash=" + hash + ", typeId=" + typeId() + ']';
-
- handles.put(this, idHash);
-
- SB buf = new SB(meta.typeName());
-
- if (meta.fieldNames() != null) {
- buf.a(" [idHash=").a(idHash).a(", hash=").a(hash);
-
- for (String name : meta.fieldNames()) {
- Object val = field(ctx, name);
-
- buf.a(", ").a(name).a('=');
-
- if (val instanceof byte[])
- buf.a(Arrays.toString((byte[]) val));
- else if (val instanceof short[])
- buf.a(Arrays.toString((short[])val));
- else if (val instanceof int[])
- buf.a(Arrays.toString((int[])val));
- else if (val instanceof long[])
- buf.a(Arrays.toString((long[])val));
- else if (val instanceof float[])
- buf.a(Arrays.toString((float[])val));
- else if (val instanceof double[])
- buf.a(Arrays.toString((double[])val));
- else if (val instanceof char[])
- buf.a(Arrays.toString((char[])val));
- else if (val instanceof boolean[])
- buf.a(Arrays.toString((boolean[]) val));
- else if (val instanceof BigDecimal[])
- buf.a(Arrays.toString((BigDecimal[])val));
- else {
- if (val instanceof BinaryObjectExImpl) {
- BinaryObjectExImpl po = (BinaryObjectExImpl)val;
-
- Integer idHash0 = handles.get(val);
-
- if (idHash0 != null) { // Circular reference.
- BinaryType meta0 = po.type();
-
- assert meta0 != null;
-
- buf.a(meta0.typeName()).a(" [hash=").a(idHash0).a(", ...]");
- }
- else
- buf.a(po.toString(ctx, handles));
- }
- else
- buf.a(val);
- }
- }
-
- buf.a(']');
- }
-
- return buf.toString();
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- try {
- BinaryReaderHandles ctx = new BinaryReaderHandles();
-
- ctx.put(start(), this);
-
- return toString(ctx, new IdentityHashMap<BinaryObject, Integer>());
- }
- catch (BinaryObjectException e) {
- throw new IgniteException("Failed to create string representation of portable object.", e);
- }
- }
-}
\ No newline at end of file