THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Every customey may impelent this interface in proper way if necessary:
Code Block | ||||
---|---|---|---|---|
| ||||
IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = ... cfg.setCacheObjectTransformSpi(new XXXTransformerSpi()); return cfg; } |
But, most customers just want to thansform the data, so, they may extend the adapter with the simple API.
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); } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
class CompressionTransformerSpi extends CacheObjectTransformerSpiAdapter { private static final LZ4Factory lz4Factory = LZ4Factory.fastestInstance(); protected ByteBuffer transform(ByteBuffer original) throws IgniteCheckedException { int lim = original.remaining() - CacheObjectTransformerSpi.OVERHEAD; if (lim <= 0) throw new IgniteCheckedException("Compression is not profitable."); ByteBuffer compressed = byteBuffer(lim); Zstd.compress(compressed, original, 1); compressed.flip(); return compressed; } protected ByteBuffer restore(ByteBuffer transformed, int length) { ByteBuffer restored = byteBuffer(length); Zstd.decompress(restored, transformed); restored.flip(); return restored; } } |
...