use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class CacheObjectBinaryProcessorImpl method buildEnum.
/** {@inheritDoc} */
@Override
public BinaryObject buildEnum(String typeName, String name) throws BinaryObjectException {
A.notNullOrEmpty(typeName, "enum type name");
A.notNullOrEmpty(name, "enum name");
int typeId = binaryCtx.typeId(typeName);
BinaryMetadata metadata = metadata0(typeId);
if (metadata == null)
throw new BinaryObjectException("Failed to get metadata for type [typeId=" + typeId + ", typeName='" + typeName + "']");
Integer ordinal = metadata.getEnumOrdinalByName(name);
typeName = binaryCtx.userTypeName(typeName);
if (ordinal == null)
throw new BinaryObjectException("Failed to resolve enum ordinal by name [typeId=" + typeId + ", typeName='" + typeName + "', name='" + name + "']");
return new BinaryEnumObjectImpl(binaryCtx, typeId, null, ordinal);
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class CacheObjectBinaryProcessorImpl method metadata.
/** {@inheritDoc} */
@Override
public Map<Integer, BinaryType> metadata(Collection<Integer> typeIds) throws BinaryObjectException {
try {
Collection<BinaryMetadataKey> keys = new ArrayList<>(typeIds.size());
for (Integer typeId : typeIds) keys.add(new BinaryMetadataKey(typeId));
Map<Integer, BinaryType> res = U.newHashMap(metadataLocCache.size());
for (Map.Entry<Integer, BinaryMetadataHolder> e : metadataLocCache.entrySet()) res.put(e.getKey(), e.getValue().metadata().wrap(binaryCtx));
return res;
} catch (CacheException e) {
throw new BinaryObjectException(e);
}
}
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) {
if (S.INCLUDE_SENSITIVE && !F.isEmpty(typeName))
throw new BinaryObjectException("Failed to deserialize object [typeName=" + typeName + ']', e);
else
throw new BinaryObjectException("Failed to deserialize object [typeId=" + typeId + ']', e);
}
}
Aggregations