/** * Throw exception on class duplication. * * @param clsName Class name. * @param id Type id. */ private static BinaryObjectException duplicateTypeIdException(String clsName, int id) { return new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']'); }
/** {@inheritDoc} */ private BinaryObjectException unsupported() { return new BinaryObjectException("Binary marshaller is not configured."); } }
/** * Check protocol version. * * @param protoVer Protocol version. */ public static void checkProtocolVersion(byte protoVer) { if (GridBinaryMarshaller.PROTO_VER != protoVer) throw new BinaryObjectException("Unsupported protocol version: " + protoVer); }
/** {@inheritDoc} */ @Override public String enumName() throws BinaryObjectException { throw new BinaryObjectException("Object is not enum."); }
/** * @param cnt Remaining bytes. */ private void ensureHasData(int cnt) { if (buf.remaining() < cnt) throw new BinaryObjectException("Not enough data to read the value " + "[requiredBytes=" + cnt + ", remainingBytes=" + buf.remaining() + ']'); } }
/** {@inheritDoc} */ @Override public BinaryRawReader rawReader() { if (!raw) { streamPositionRandom(rawOff); raw = true; return this; } else throw new BinaryObjectException("Method \"rawReader\" can be called only once."); }
/** {@inheritDoc} */ @Override public int hashCode(BinaryObject obj) { if (obj == null) throw new BinaryObjectException("Cannot calculate hash code because binary object is null."); return hashCode0(obj); }
/** {@inheritDoc} */ @Override protected void marshal0(@Nullable Object obj, OutputStream out) throws IgniteCheckedException { byte[] arr = marshal(obj); try { out.write(arr); } catch (Exception e) { throw new BinaryObjectException("Failed to marshal the object: " + obj, e); } }
/** {@inheritDoc} */ @Override public void position(int pos) { if (remaining() + this.pos < pos) throw new BinaryObjectException("Position is out of bounds: " + pos); else this.pos = pos; }
/** * @return Instance. * @throws BinaryObjectException In case of error. */ private Object newInstance() throws BinaryObjectException { try { return ctor != null ? ctor.newInstance() : GridUnsafe.allocateInstance(cls); } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) { throw new BinaryObjectException("Failed to instantiate instance: " + cls, e); } }
/** {@inheritDoc} */ @Override public void read0(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); } }
/** {@inheritDoc} */ @Override public String enumName() throws BinaryObjectException { BinaryMetadata metadata = ctx.metadata0(typeId); if (metadata == null) throw new BinaryObjectException("Failed to get metadata for enum [typeId=" + typeId + ", typeName='" + clsName + "', ordinal=" + ord + "]"); String name = metadata.getEnumNameByOrdinal(ord); if (name == null) throw new BinaryObjectException("Unable to resolve enum constant name [typeId=" + typeId + ", typeName='" + metadata.typeName() + "', ordinal=" + ord + "]"); return name; }
/** * Having target class in place we simply read ordinal and create final representation. * * @param cls Enum class. * @return Value. */ public static Enum<?> doReadEnum(BinaryInputStream in, Class<?> cls) throws BinaryObjectException { assert cls != null; if (!cls.isEnum()) throw new BinaryObjectException("Class does not represent enum type: " + cls.getName()); int ord = in.readInt(); return BinaryEnumCache.get(cls, ord); }
/** * Create binary type which is used by users. * * @param ctx Context. * @param obj Binary object. * @return Binary type. */ public static BinaryType type(BinaryContext ctx, BinaryObjectEx obj) { if (ctx == null) throw new BinaryObjectException("BinaryContext is not set for the object."); return ctx.metadata(obj.typeId()); }
@Override public void onAfterMetadataRequest(int typeId, BinaryType type) { if (syncMeta) { try { initMetaReq.countDown(); initMetaReq.await(); } catch (Exception e) { throw new BinaryObjectException(e); } } }
/** * Ensure that there is enough data. * * @param cnt Length. */ protected void ensureEnoughData(int cnt) { if (remaining() < cnt) throw new BinaryObjectException("Not enough data to read the value [position=" + pos + ", requiredBytes=" + cnt + ", remainingBytes=" + remaining() + ']'); }
/** */ void onDisconnected() { cancelFutures(MetadataUpdateResult.createFailureResult(new BinaryObjectException("Failed to update or wait for metadata, client node disconnected"))); }
/** * @param in Input stream. * @return Class name. */ public static String doReadClassName(BinaryInputStream in) { byte flag = in.readByte(); if (flag != GridBinaryMarshaller.STRING) throw new BinaryObjectException("Failed to read class name [position=" + (in.position() - 1) + ']'); return doReadString(in); }
/** Deserialize string. */ private String readString(BinaryInputStream in) throws BinaryObjectException { try { try (BinaryReaderExImpl r = new BinaryReaderExImpl(marsh.context(), in, null, true)) { return r.readString(); } } catch (IOException e) { throw new BinaryObjectException(e); } }
/** {@inheritDoc} */ @Override public void readBinary(BinaryReaderExImpl reader, ClientListenerProtocolVersion ver) throws BinaryObjectException { super.readBinary(reader, ver); cursorId = reader.readLong(); String locFileName = reader.readString(); int batchSize = reader.readInt(); if (!BulkLoadAckClientParameters.isValidPacketSize(batchSize)) throw new BinaryObjectException(BulkLoadAckClientParameters.packetSizeErrorMesssage(batchSize)); params = new BulkLoadAckClientParameters(locFileName, batchSize); }