Search in sources :

Example 46 with BinaryObjectException

use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.

the class BinaryArrayIdentityResolver method equals0.

/**
 * {@inheritDoc}
 */
@Override
protected boolean equals0(BinaryObject o1, BinaryObject o2) {
    if (o1 instanceof BinaryObjectEx && o2 instanceof BinaryObjectEx) {
        BinaryObjectEx ex1 = (BinaryObjectEx) o1;
        BinaryObjectEx ex2 = (BinaryObjectEx) o2;
        if (ex1.typeId() != ex2.typeId())
            return false;
        if (ex1 instanceof BinaryObjectExImpl) {
            // Handle regular object.
            assert ex2 instanceof BinaryObjectExImpl;
            BinaryObjectExImpl exx1 = (BinaryObjectExImpl) ex1;
            BinaryObjectExImpl exx2 = (BinaryObjectExImpl) ex2;
            if (exx1.hasArray())
                return exx2.hasArray() ? equalsHeap(exx1, exx2) : equalsHeapOffheap(exx1, exx2);
            else
                return exx2.hasArray() ? equalsHeapOffheap(exx2, exx1) : equalsOffheap(exx1, exx2);
        } else {
            // Handle enums.
            assert ex1 instanceof BinaryEnumObjectImpl;
            assert ex2 instanceof BinaryEnumObjectImpl;
            return ex1.enumOrdinal() == ex2.enumOrdinal();
        }
    }
    BinaryObject o = o1 instanceof BinaryObjectEx ? o2 : o1;
    throw new BinaryObjectException("Array identity resolver cannot be used with provided BinaryObject " + "implementation: " + o.getClass().getName());
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 47 with BinaryObjectException

use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.

the class BinaryClassDescriptor method constructor.

/**
 * @param cls Class.
 * @return Constructor.
 * @throws BinaryObjectException If constructor doesn't exist.
 */
@SuppressWarnings("ConstantConditions")
@Nullable
private static Constructor<?> constructor(Class<?> cls) throws BinaryObjectException {
    assert cls != null;
    try {
        Constructor<?> ctor = U.forceEmptyConstructor(cls);
        if (ctor == null)
            throw new BinaryObjectException("Failed to find empty constructor for class: " + cls.getName());
        ctor.setAccessible(true);
        return ctor;
    } catch (IgniteCheckedException e) {
        throw new BinaryObjectException("Failed to get constructor for class: " + cls.getName(), e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) Nullable(org.jetbrains.annotations.Nullable)

Example 48 with BinaryObjectException

use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.

the class BinaryClassDescriptor method read.

/**
 * @param reader Reader.
 * @return Object.
 * @throws BinaryObjectException If failed.
 */
Object read(BinaryReaderExImpl reader) throws BinaryObjectException {
    try {
        assert reader != null;
        assert mode != BinaryWriteMode.OPTIMIZED : "OptimizedMarshaller should not be used here: " + cls.getName();
        Object res;
        switch(mode) {
            case BINARY:
                res = newInstance();
                reader.setHandle(res);
                if (serializer != null)
                    serializer.readBinary(res, reader);
                else
                    ((Binarylizable) res).readBinary(reader);
                break;
            case OBJECT:
                res = newInstance();
                reader.setHandle(res);
                for (BinaryFieldAccessor info : fields) info.read(res, reader);
                break;
            default:
                assert false : "Invalid mode: " + mode;
                return null;
        }
        if (readResolveMtd != null) {
            try {
                res = readResolveMtd.invoke(res);
                reader.setHandle(res);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InvocationTargetException e) {
                if (e.getTargetException() instanceof BinaryObjectException)
                    throw (BinaryObjectException) e.getTargetException();
                throw new BinaryObjectException("Failed to execute readResolve() method on " + res, e);
            }
        }
        return res;
    } catch (Exception e) {
        String msg;
        if (S.INCLUDE_SENSITIVE && !F.isEmpty(typeName))
            msg = "Failed to deserialize object [typeName=" + typeName + ']';
        else
            msg = "Failed to deserialize object [typeId=" + typeId + ']';
        U.error(ctx.log(), msg, e);
        throw new BinaryObjectException(msg, e);
    }
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 49 with BinaryObjectException

use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.

the class BinaryContext method registerUserClassName.

/**
 * Register "type ID to class name" mapping on all nodes to allow for mapping requests resolution form client.
 * Other {@link BinaryContext}'s "register" methods and method
 * {@link BinaryContext#descriptorForClass(Class, boolean)} already call this functionality so use this method
 * only when registering class names whose {@link Class} is unknown.
 *
 * @param typeId Type ID.
 * @param clsName Class Name.
 * @return {@code True} if the mapping was registered successfully.
 */
public boolean registerUserClassName(int typeId, String clsName) {
    IgniteCheckedException e = null;
    boolean res = false;
    try {
        res = marshCtx.registerClassName(JAVA_ID, typeId, clsName);
    } catch (DuplicateTypeIdException dupEx) {
        // Ignore if trying to register mapped type name of the already registered class name and vise versa
        BinaryInternalMapper mapper = userTypeMapper(typeId);
        String oldName = dupEx.getRegisteredClassName();
        if (!(mapper.typeName(oldName).equals(clsName) || mapper.typeName(clsName).equals(oldName)))
            e = dupEx;
    } catch (IgniteCheckedException igniteEx) {
        e = igniteEx;
    }
    if (e != null)
        throw new BinaryObjectException("Failed to register class.", e);
    return res;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DuplicateTypeIdException(org.apache.ignite.internal.DuplicateTypeIdException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 50 with BinaryObjectException

use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.

the class BinaryMarshaller method unmarshal0.

/**
 * {@inheritDoc}
 */
@Override
protected <T> T unmarshal0(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    // 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);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Aggregations

BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)50 BinaryObject (org.apache.ignite.binary.BinaryObject)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)9 Date (java.util.Date)5 BinaryType (org.apache.ignite.binary.BinaryType)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 IOException (java.io.IOException)3 Time (java.sql.Time)3 Timestamp (java.sql.Timestamp)3 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 BigDecimal (java.math.BigDecimal)2 BigInteger (java.math.BigInteger)2 UUID (java.util.UUID)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 IgniteException (org.apache.ignite.IgniteException)2