org.apache.ignite.internal.processors.cache

## Class CacheObjectAdapter

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.CacheObjectAdapter

All Implemented Interfaces:
  Externalizable, Serializable, CacheObject, Message

Direct Known Subclasses:
  CacheObjectImpl, KeyCacheObjectImpl

    public abstract class CacheObjectAdapter
    extends Object
    implements CacheObject, Externalizable

See Also:
  Serialized Form

### Field Summary

Fields
`protected Object` `val`
`protected byte[]` `valBytes`

### 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 and Description
`CacheObjectAdapter()`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`byte` `cacheObjectType()`
`byte` `fieldsCount()` Gets fields count.
`protected boolean` `needCopy(CacheObjectValueContext ctx)`
`static int` `objectPutSize(int dataLen)`
`boolean` `putValue(ByteBuffer buf)`
`boolean` `putValue(ByteBuffer buf, int off, int len)`
`static boolean` `putValue(byte cacheObjType, ByteBuffer buf, int off, int len, byte[] valBytes, int start)`
`int` `putValue(long addr)`
`static int` `putValue(long addr, byte type, byte[] valBytes, int valOff)`
`void` `readExternal(ObjectInput in)`
`boolean` `readFrom(ByteBuffer buf, MessageReader reader)` Reads this message from provided byte buffer.
`String` `toString()`
`int` `valueBytesLength(CacheObjectContext ctx)`
`void` `writeExternal(ObjectOutput out)`
`boolean` `writeTo(ByteBuffer buf, MessageWriter writer)` Writes this message to provided byte buffer.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.apache.ignite.internal.processors.cache.CacheObject

`finishUnmarshal, isPlatformType, prepareForCache, prepareMarshal, value, valueBytes`

### Methods inherited from interface org.apache.ignite.plugin.extensions.communication.Message

`directType, onAckReceived`

### Field Detail

#### val

    @GridToStringInclude(sensitive=true)
    protected Object val

#### valBytes

    protected byte[] valBytes

### Constructor Detail

#### CacheObjectAdapter

    public CacheObjectAdapter()

### Method Detail

#### needCopy

    protected boolean needCopy(CacheObjectValueContext ctx)

Parameters:
  `ctx` - Context.
Returns:
  `True` need to copy value returned to user.

#### cacheObjectType

    public byte cacheObjectType()

Specified by:
  `cacheObjectType` in interface `CacheObject`
Returns:
  Object type.

#### writeExternal

    public void writeExternal(ObjectOutput out)
                       throws IOException

Specified by:
  `writeExternal` in interface `Externalizable`
Throws:
  `IOException`

#### readExternal

    public void readExternal(ObjectInput in)
                      throws IOException,
                             ClassNotFoundException

Specified by:
  `readExternal` in interface `Externalizable`
Throws:
  `IOException`
  `ClassNotFoundException`

#### putValue

    public boolean putValue(ByteBuffer buf)
                     throws IgniteCheckedException

Specified by:
  `putValue` in interface `CacheObject`
Parameters:
  `buf` - Buffer to write value to.
Returns:
  `True` if value was successfully written, `false` if there was not enough space in the buffer.
Throws:
  `IgniteCheckedException` - If failed.

#### putValue

    public int putValue(long addr)
                 throws IgniteCheckedException

Specified by:
  `putValue` in interface `CacheObject`
Parameters:
  `addr` - Address tp write value to.
Returns:
  Number of bytes written.
Throws:
  `IgniteCheckedException` - If failed.

#### putValue

    public static int putValue(long addr,
                               byte type,
                               byte[] valBytes,
                               int valOff)

Parameters:
  `addr` - Write address.
  `type` - Object type.
  `valBytes` - Value bytes array.
  `valOff` - Value bytes array offset.
Returns:
  Offset shift compared to initial address.

#### putValue

    public boolean putValue(ByteBuffer buf,
                            int off,
                            int len)
                     throws IgniteCheckedException

Specified by:
  `putValue` in interface `CacheObject`
Parameters:
  `buf` - Buffer to write value to.
  `off` - Offset in source binary data.
  `len` - Length of the data to write.
Returns:
  `True` if value was successfully written, `false` if there was not enough space in the buffer.
Throws:
  `IgniteCheckedException` - If failed.

#### valueBytesLength

    public int valueBytesLength(CacheObjectContext ctx)
                         throws IgniteCheckedException

Specified by:
  `valueBytesLength` in interface `CacheObject`
Parameters:
  `ctx` - Cache object context.
Returns:
  Size required to store this value object.
Throws:
  `IgniteCheckedException` - If failed.

#### readFrom

    public boolean readFrom(ByteBuffer buf,
                            MessageReader reader)

Reads this message from provided byte buffer.

Specified by:
  `readFrom` in interface `Message`
Parameters:
  `buf` - Byte buffer.
  `reader` - Reader.
Returns:
  Whether message was fully read.

#### writeTo

    public boolean writeTo(ByteBuffer buf,
                           MessageWriter writer)

Writes this message to provided byte buffer.

Specified by:
  `writeTo` in interface `Message`
Parameters:
  `buf` - Byte buffer.
  `writer` - Writer.
Returns:
  Whether message was fully written.

#### fieldsCount

    public byte fieldsCount()

Gets fields count.

Specified by:
  `fieldsCount` in interface `Message`
Returns:
  Fields count.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### objectPutSize

    public static int objectPutSize(int dataLen)

Parameters:
  `dataLen` - Serialized value length.
Returns:
  Full size required to store cache object.
See Also:
  `putValue(byte, ByteBuffer, int, int, byte[], int)`

#### putValue

    public static boolean putValue(byte cacheObjType,
                                   ByteBuffer buf,
                                   int off,
                                   int len,
                                   byte[] valBytes,
                                   int start)
                            throws IgniteCheckedException

Parameters:
  `cacheObjType` - Cache object type.
  `buf` - Buffer to write value to.
  `off` - Offset in source binary data.
  `len` - Length of the data to write.
  `valBytes` - Binary data.
  `start` - Start offset in binary data.
Returns:
  `True` if data were successfully written.
Throws:
  `IgniteCheckedException` - If failed.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.9.0
Release Date | : October 15 2020