THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block | ||||
---|---|---|---|---|
| ||||
private byte[] arrayFromValueBytes(CacheObjectValueContext ctx) { return CacheObjectsTransformer.restoreIfNecessary(valBytes, ctx); } private byte[] valueBytesFromArray(CacheObjectValueContext ctx) { return CacheObjectsTransformer.transformIfNecessary(arr, start, arr.length, ctx); } ... public void finishUnmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws IgniteCheckedException { if (arr == null) arr = arrayFromValueBytes(ctx); } ... public void prepareMarshal(CacheObjectValueContext ctx) { if (valBytes == null) valBytes = valueBytesFromArray(ctx); } |
Some customets may want to encrypt the data, some to compress, while some just keep it as is.
So, we must provide the simple way to append any transformation.
Simplest way is to use Service Provider Interface (IgniteSpi):
Code Block | ||||
---|---|---|---|---|
| ||||
public interface CacheObjectTransformerSpi extends IgniteSpi {
/** Additional space required to store the transformed data. */
public int OVERHEAD = 6;
/**
* Transforms the data.
*
* @param bytes Byte array contains the data.
* @param offset Data offset.
* @param length Data length.
* @return Byte array contains the transformed data started with non-filled area with {@link #OVERHEAD} size.
* @throws IgniteCheckedException when transformation is not possible/suitable.
*/
public byte[] transform(byte[] bytes, int offset, int length) throws IgniteCheckedException;
/**
* Restores the data.
*
* @param bytes Byte array ending with the transformed data.
* @param offset Transformed data offset.
* @param length Original data length.
* @return Byte array contains the restored data.
*/
public byte[] restore(byte[] bytes, int offset, int length);
} |
Code Block | ||||
---|---|---|---|---|
| ||||
public abstract class CacheObjectTransformerSpiAdapter extends IgniteSpiAdapter implements CacheObjectTransformerSpi {
...
/**
* Transforms the data.
*
* @param original Original data.
* @return Transformed data.
* @throws IgniteCheckedException when transformation is not possible/suitable.
*/
protected abstract ByteBuffer transform(ByteBuffer original) throws IgniteCheckedException;
/**
* Restores the data.
*
* @param transformed Transformed data.
* @param length Original data length.
* @return Restored data.
*/
protected abstract ByteBuffer restore(ByteBuffer transformed, int length);
} |
Transformation requires additional memory allocation and subsequent GC work.
...