Class BinaryObjectOffheapImpl
- java.lang.Object
-
- org.apache.ignite.internal.binary.BinaryObjectExImpl
-
- org.apache.ignite.internal.binary.BinaryObjectOffheapImpl
-
- All Implemented Interfaces:
Externalizable,Serializable,Cloneable,BinaryObject,BinaryObjectEx,CacheObject,Message
public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Externalizable, CacheObject
Binary object implementation over offheap memory- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.apache.ignite.internal.processors.cache.CacheObject
TYPE_BINARY, TYPE_BINARY_ENUM, TYPE_BYTE_ARR, TYPE_REGULAR
-
Fields inherited from interface org.apache.ignite.plugin.extensions.communication.Message
DIRECT_TYPE_SIZE
-
-
Constructor Summary
Constructors Constructor Description BinaryObjectOffheapImpl()ForExternalizable(not supported).BinaryObjectOffheapImpl(BinaryContext ctx, long ptr, int start, int size)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]array()bytecacheObjectType()BinaryObjectclone()Copies this binary object.BinaryContextcontext()Get binary context.BinarySerializedFieldComparatorcreateFieldComparator()Create field comparator.BinarySchemacreateSchema()Create schema for object.intdataStartOffset()Get offset of data begin.<T> Tdeserialize()Gets fully deserialized instance of binary object.<T> Tdeserialize(@Nullable ClassLoader ldr)Gets fully deserialized instance of binary object.shortdirectType()Gets message type.<F> Ffield(int fieldId)Gets field value.<F> Ffield(String fieldName)Gets field value.protected <F> Ffield(BinaryReaderHandles rCtx, String fieldName)<F> FfieldByOrder(int order)Get field by offset.bytefieldsCount()Gets fields count.voidfinishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr)intfooterStartOffset()Get offset of the footer begin.booleanhasArray()booleanhasField(String fieldName)Checks whether field exists in the object.inthashCode()booleanhasSchema()BinaryObjectheapCopy()booleanisFlagSet(short flag)Check if flag set.booleanisPlatformType()Gets flag indicating whether object value is a platform type.intlength()longoffheapAddress()voidonAckReceived()Method called when ack message received.CacheObjectprepareForCache(CacheObjectContext ctx)Prepares cache object for cache (e.g. copies user-provided object if needed).voidprepareMarshal(CacheObjectValueContext ctx)intputValue(long addr)booleanputValue(ByteBuffer buf)booleanputValue(ByteBuffer buf, int off, int len)@Nullable BinaryTyperawType()Get raw type.voidreadExternal(ObjectInput in)booleanreadFrom(ByteBuffer buf, MessageReader reader)Reads this message from provided byte buffer.intschemaId()Get schema ID.intsize()Get the size of the objectintstart()BinaryObjectBuildertoBuilder()Creates a newBinaryObjectBuilderbased on this binary object.@Nullable BinaryTypetype()Gets type information for this binary object.inttypeId()<T> Tvalue(CacheObjectValueContext ctx, boolean cpy)<T> Tvalue(CacheObjectValueContext ctx, boolean cpy, ClassLoader ldr)Deserializes a value from an internal representation.byte[]valueBytes(CacheObjectValueContext ctx)intvalueBytesLength(CacheObjectContext ctx)voidwriteExternal(ObjectOutput out)protected booleanwriteFieldByOrder(int fieldOffset, ByteBuffer buf)Writes field value defined by the given field offset to the given byte buffer.booleanwriteTo(ByteBuffer buf, MessageWriter writer)Writes this message to provided byte buffer.-
Methods inherited from class org.apache.ignite.internal.binary.BinaryObjectExImpl
enumName, enumOrdinal, equals, hasCircularReferences, toString
-
-
-
-
Constructor Detail
-
BinaryObjectOffheapImpl
public BinaryObjectOffheapImpl()
ForExternalizable(not supported).
-
BinaryObjectOffheapImpl
public BinaryObjectOffheapImpl(BinaryContext ctx, long ptr, int start, int size)
- Parameters:
ctx- Context.ptr- Memory address.start- Object start.size- Memory size.
-
-
Method Detail
-
heapCopy
public BinaryObject heapCopy()
- Returns:
- Heap-based copy.
-
typeId
public int typeId()
- Specified by:
typeIdin interfaceBinaryObjectEx- Returns:
- Type ID.
-
length
public int length()
- Specified by:
lengthin classBinaryObjectExImpl- Returns:
- Length.
-
hasSchema
public boolean hasSchema()
- Specified by:
hasSchemain classBinaryObjectExImpl- Returns:
Trueif object has schema.
-
schemaId
public int schemaId()
Get schema ID.- Specified by:
schemaIdin classBinaryObjectExImpl- Returns:
- Schema ID.
-
createSchema
public BinarySchema createSchema()
Create schema for object.- Specified by:
createSchemain classBinaryObjectExImpl- Returns:
- Schema.
-
context
public BinaryContext context()
Get binary context.- Specified by:
contextin classBinaryObjectExImpl- Returns:
- Binary context.
-
start
public int start()
- Specified by:
startin classBinaryObjectExImpl- Returns:
- Object start.
-
array
public byte[] array()
- Specified by:
arrayin classBinaryObjectExImpl- Returns:
- Object array if object is array based, otherwise
null.
-
putValue
public boolean putValue(ByteBuffer buf) throws IgniteCheckedException
- Specified by:
putValuein interfaceCacheObject- Parameters:
buf- Buffer to write value to.- Returns:
Trueif value was successfully written,falseif there was not enough space in the buffer.- Throws:
IgniteCheckedException- If failed.
-
putValue
public int putValue(long addr) throws IgniteCheckedException- Specified by:
putValuein interfaceCacheObject- Parameters:
addr- Address tp write value to.- Returns:
- Number of bytes written.
- Throws:
IgniteCheckedException- If failed.
-
putValue
public boolean putValue(ByteBuffer buf, int off, int len) throws IgniteCheckedException
- Specified by:
putValuein interfaceCacheObject- Parameters:
buf- Buffer to write value to.off- Offset in source binary data.len- Length of the data to write.- Returns:
Trueif value was successfully written,falseif there was not enough space in the buffer.- Throws:
IgniteCheckedException- If failed.
-
valueBytesLength
public int valueBytesLength(CacheObjectContext ctx) throws IgniteCheckedException
- Specified by:
valueBytesLengthin interfaceCacheObject- Parameters:
ctx- Cache object context.- Returns:
- Size required to store this value object.
- Throws:
IgniteCheckedException- If failed.
-
offheapAddress
public long offheapAddress()
- Specified by:
offheapAddressin classBinaryObjectExImpl- Returns:
- Object offheap address is object is offheap based, otherwise 0.
-
hasArray
public boolean hasArray()
- Specified by:
hasArrayin classBinaryObjectExImpl- Returns:
Trueif object is array based.
-
isFlagSet
public boolean isFlagSet(short flag)
Check if flag set.- Specified by:
isFlagSetin interfaceBinaryObjectEx- Parameters:
flag- flag to check.- Returns:
trueif flag is set,falseotherwise.
-
type
@Nullable public @Nullable BinaryType type() throws BinaryObjectException
Gets type information for this binary object.- Specified by:
typein interfaceBinaryObject- Returns:
- Binary object type information.
- Throws:
BinaryObjectException- In case of error.
-
rawType
@Nullable public @Nullable BinaryType rawType() throws BinaryObjectException
Get raw type.- Specified by:
rawTypein interfaceBinaryObjectEx- Returns:
- Raw type
- Throws:
BinaryObjectException- If failed.
-
field
@Nullable public <F> F field(String fieldName) throws BinaryObjectException
Gets field value.- Specified by:
fieldin interfaceBinaryObject- Type Parameters:
F- Type of the field value.- Parameters:
fieldName- Field name.- Returns:
- Field value.
- Throws:
BinaryObjectException- In case of any other error.
-
field
@Nullable public <F> F field(int fieldId) throws BinaryObjectExceptionGets field value.- Specified by:
fieldin classBinaryObjectExImpl- Parameters:
fieldId- Field ID.- Returns:
- Field value.
- Throws:
BinaryObjectException- In case of any other error.
-
createFieldComparator
public BinarySerializedFieldComparator createFieldComparator()
Create field comparator.- Specified by:
createFieldComparatorin classBinaryObjectExImpl- Returns:
- Comparator.
-
dataStartOffset
public int dataStartOffset()
Get offset of data begin.- Specified by:
dataStartOffsetin classBinaryObjectExImpl- Returns:
- Field value.
-
footerStartOffset
public int footerStartOffset()
Get offset of the footer begin.- Specified by:
footerStartOffsetin classBinaryObjectExImpl- Returns:
- Field value.
-
fieldByOrder
@Nullable public <F> F fieldByOrder(int order)
Get field by offset.- Specified by:
fieldByOrderin classBinaryObjectExImpl- Parameters:
order- Field offset.- Returns:
- Field value.
-
writeFieldByOrder
protected boolean writeFieldByOrder(int fieldOffset, ByteBuffer buf)Writes field value defined by the given field offset to the given byte buffer.- Specified by:
writeFieldByOrderin classBinaryObjectExImpl- Parameters:
fieldOffset- Field offset.- Returns:
- Boolean flag indicating whether the field was successfully written to the buffer,
falseif there is no enough space for the field in the buffer.
-
field
@Nullable protected <F> F field(BinaryReaderHandles rCtx, String fieldName)
- Specified by:
fieldin classBinaryObjectExImpl- Parameters:
rCtx- Reader context.fieldName- Field name.- Returns:
- Field value.
-
hasField
public boolean hasField(String fieldName)
Checks whether field exists in the object.- Specified by:
hasFieldin interfaceBinaryObject- Parameters:
fieldName- Field name.- Returns:
Trueif field exists.
-
deserialize
@Nullable public <T> T deserialize(@Nullable @Nullable ClassLoader ldr) throws BinaryObjectExceptionGets fully deserialized instance of binary object. Ifldrwas not specified, configured class loader will be usedIgniteConfiguration.getClassLoader().- Specified by:
deserializein interfaceBinaryObject- Type Parameters:
T- Type of the deserialized object.- Parameters:
ldr- Class loader.- Returns:
- Fully deserialized instance of binary object.
- Throws:
BinaryInvalidTypeException- If class doesn't exist.BinaryObjectException- In case of any other error.
-
deserialize
@Nullable public <T> T deserialize() throws BinaryObjectExceptionGets fully deserialized instance of binary object.- Specified by:
deserializein interfaceBinaryObject- Type Parameters:
T- Type of the deserialized object.- Returns:
- Fully deserialized instance of binary object.
- Throws:
BinaryInvalidTypeException- If class doesn't exist.BinaryObjectException- In case of any other error.
-
clone
public BinaryObject clone() throws CloneNotSupportedException
Copies this binary object.- Specified by:
clonein interfaceBinaryObject- Overrides:
clonein classBinaryObjectExImpl- Returns:
- Copy of this binary object.
- Throws:
CloneNotSupportedException
-
toBuilder
public BinaryObjectBuilder toBuilder() throws BinaryObjectException
Creates a newBinaryObjectBuilderbased on this binary object. The following codeBinaryObjectBuilder builder = binaryObject.toBuilder();
is equivalent toBinaryObjectBuilder builder = ignite.binary().builder(binaryObject);
- Specified by:
toBuilderin interfaceBinaryObject- Overrides:
toBuilderin classBinaryObjectExImpl- Returns:
- Binary object builder.
- Throws:
BinaryObjectException- If builder cannot be created.
-
cacheObjectType
public byte cacheObjectType()
- Specified by:
cacheObjectTypein interfaceCacheObject- Returns:
- Object type.
-
isPlatformType
public boolean isPlatformType()
Gets flag indicating whether object value is a platform type. Platform types will be automatically deserialized on public API cache operations regardless whetherIgniteCache.withKeepBinary()is used or not.- Specified by:
isPlatformTypein interfaceCacheObject- Returns:
- Platform type flag.
-
value
@Nullable public <T> T value(CacheObjectValueContext ctx, boolean cpy)
- Specified by:
valuein interfaceCacheObject- Parameters:
ctx- Context.cpy- Iftrueneed to copy value.- Returns:
- Value.
-
value
@Nullable public <T> T value(CacheObjectValueContext ctx, boolean cpy, ClassLoader ldr)
Deserializes a value from an internal representation.- Specified by:
valuein interfaceCacheObject- Parameters:
ctx- Context.cpy- Iftrueneed to copy value.ldr- Class loader, if it isnull, default class loader will be used.- Returns:
- Value.
-
valueBytes
public byte[] valueBytes(CacheObjectValueContext ctx) throws IgniteCheckedException
- Specified by:
valueBytesin interfaceCacheObject- Parameters:
ctx- Context.- Returns:
- Value bytes.
- Throws:
IgniteCheckedException- If failed.
-
prepareForCache
public CacheObject prepareForCache(CacheObjectContext ctx)
Prepares cache object for cache (e.g. copies user-provided object if needed).- Specified by:
prepareForCachein interfaceCacheObject- Parameters:
ctx- Cache context.- Returns:
- Instance to store in cache.
-
finishUnmarshal
public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws IgniteCheckedException
- Specified by:
finishUnmarshalin interfaceCacheObject- Parameters:
ctx- Context.ldr- Class loader.- Throws:
IgniteCheckedException- If failed.
-
prepareMarshal
public void prepareMarshal(CacheObjectValueContext ctx) throws IgniteCheckedException
- Specified by:
prepareMarshalin interfaceCacheObject- Parameters:
ctx- Context.- Throws:
IgniteCheckedException- If failed.
-
writeTo
public boolean writeTo(ByteBuffer buf, MessageWriter writer)
Writes this message to provided byte buffer.
-
readFrom
public boolean readFrom(ByteBuffer buf, MessageReader reader)
Reads this message from provided byte buffer.
-
directType
public short directType()
Gets message type.- Specified by:
directTypein interfaceMessage- Returns:
- Message type.
-
fieldsCount
public byte fieldsCount()
Gets fields count.- Specified by:
fieldsCountin interfaceMessage- Returns:
- Fields count.
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
onAckReceived
public void onAckReceived()
Method called when ack message received.- Specified by:
onAckReceivedin interfaceMessage
-
size
public int size()
Get the size of the object- Specified by:
sizein interfaceBinaryObject- Returns:
- Size of the object
-
-