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());
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations