This is an automated email from the ASF dual-hosted git repository.
nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 7366b7ce6ad IGNITE-26478 Remove CacheObjectValueContext#kernalContext
method (#12360)
7366b7ce6ad is described below
commit 7366b7ce6ada9c5ea7dd55a24861b302e62ab71c
Author: Nikolay <[email protected]>
AuthorDate: Fri Sep 19 20:59:15 2025 +0300
IGNITE-26478 Remove CacheObjectValueContext#kernalContext method (#12360)
---
.../ignite/internal/binary/BinaryObjectImpl.java | 5 +-
.../cache/AbstractCacheObjectContext.java | 126 ++++++++++++++-
.../processors/cache/CacheObjectAdapter.java | 4 +-
.../cache/CacheObjectTransformerUtils.java | 170 ---------------------
.../processors/cache/CacheObjectValueContext.java | 32 +++-
.../cacheobject/PlatformCacheObjectImpl.java | 3 +-
6 files changed, 155 insertions(+), 185 deletions(-)
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index 350b2c24160..0c9fa15f50e 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -36,7 +36,6 @@ import
org.apache.ignite.internal.binary.streams.BinaryOutputStream;
import org.apache.ignite.internal.binary.streams.BinaryStreams;
import org.apache.ignite.internal.processors.cache.CacheObject;
import org.apache.ignite.internal.processors.cache.CacheObjectAdapter;
-import org.apache.ignite.internal.processors.cache.CacheObjectTransformerUtils;
import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
import org.apache.ignite.internal.processors.cache.KeyCacheObject;
import org.apache.ignite.internal.util.GridUnsafe;
@@ -249,7 +248,7 @@ final class BinaryObjectImpl extends BinaryObjectExImpl
implements Externalizabl
* @return Array.
*/
private byte[] arrayFromValueBytes(CacheObjectValueContext ctx) {
- return CacheObjectTransformerUtils.restoreIfNecessary(valBytes, ctx);
+ return ctx.restoreIfNecessary(valBytes);
}
/**
@@ -258,7 +257,7 @@ final class BinaryObjectImpl extends BinaryObjectExImpl
implements Externalizabl
private byte[] valueBytesFromArray(CacheObjectValueContext ctx) {
assert part == -1; // Keys should never be transformed.
- return CacheObjectTransformerUtils.transformIfNecessary(arr, start,
length(), ctx);
+ return ctx.transformIfNecessary(arr, start, length());
}
/** {@inheritDoc} */
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/AbstractCacheObjectContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/AbstractCacheObjectContext.java
index 4d6b31884b2..49dee74e82e 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/AbstractCacheObjectContext.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/AbstractCacheObjectContext.java
@@ -17,12 +17,19 @@
package org.apache.ignite.internal.processors.cache;
+import java.nio.ByteBuffer;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.events.CacheObjectTransformedEvent;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.binary.BinaryContext;
+import
org.apache.ignite.internal.cache.transform.CacheObjectTransformerProcessor;
+import org.apache.ignite.internal.util.GridUnsafe;
import org.jetbrains.annotations.Nullable;
+import static org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_TRANSFORMED;
+import static
org.apache.ignite.internal.binary.GridBinaryMarshaller.TRANSFORMED;
+
/**
* Abstract implementation of {@link CacheObjectValueContext}.
*/
@@ -37,8 +44,10 @@ public abstract class AbstractCacheObjectContext implements
CacheObjectValueCont
this.ctx = ctx;
}
- /** {@inheritDoc} */
- @Override public GridKernalContext kernalContext() {
+ /**
+ * @return Kernal context.
+ */
+ public GridKernalContext kernalContext() {
return ctx;
}
@@ -82,4 +91,117 @@ public abstract class AbstractCacheObjectContext implements
CacheObjectValueCont
@Override public boolean isPeerClassLoadingEnabled() {
return ctx.config().isPeerClassLoadingEnabled();
}
+
+ /** {@inheritDoc} */
+ @Override public byte[] transformIfNecessary(byte[] bytes, int offset, int
length) {
+ assert bytes[offset] != TRANSFORMED;
+
+ CacheObjectTransformerProcessor transformer = ctx.transformer();
+
+ if (transformer == null)
+ return bytes;
+
+ ByteBuffer src = ByteBuffer.wrap(bytes, offset, length);
+ ByteBuffer transformed = transformer.transform(src);
+
+ if (transformed != null) {
+ assert transformed.remaining() > 0 : transformed.remaining();
+
+ byte[] res = toArray(transformed);
+
+ if (recordable(EVT_CACHE_OBJECT_TRANSFORMED)) {
+ ctx.event().record(
+ new
CacheObjectTransformedEvent(ctx.discovery().localNode(),
+ "Object transformed",
+ EVT_CACHE_OBJECT_TRANSFORMED,
+ detachIfNecessary(bytes, offset, length),
+ res,
+ false));
+ }
+
+ return res;
+ }
+ else {
+ byte[] res = detachIfNecessary(bytes, offset, length);
+
+ if (recordable(EVT_CACHE_OBJECT_TRANSFORMED)) {
+ ctx.event().record(
+ new
CacheObjectTransformedEvent(ctx.discovery().localNode(),
+ "Object transformation was cancelled.",
+ EVT_CACHE_OBJECT_TRANSFORMED,
+ res,
+ res,
+ false));
+ }
+
+ return res;
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte[] restoreIfNecessary(byte[] bytes) {
+ if (bytes[0] != TRANSFORMED)
+ return bytes;
+
+ CacheObjectTransformerProcessor transformer = ctx.transformer();
+
+ ByteBuffer src = ByteBuffer.wrap(bytes, 1, bytes.length - 1); //
Skipping TRANSFORMED.
+ ByteBuffer restored = transformer.restore(src);
+
+ byte[] res = toArray(restored);
+
+ if (recordable(EVT_CACHE_OBJECT_TRANSFORMED)) {
+ ctx.event().record(
+ new CacheObjectTransformedEvent(ctx.discovery().localNode(),
+ "Object restored",
+ EVT_CACHE_OBJECT_TRANSFORMED,
+ res,
+ bytes,
+ true));
+ }
+
+ return res;
+ }
+
+ /** */
+ private static byte[] detachIfNecessary(byte[] bytes, int offset, int
length) {
+ if (offset == 0 && length == bytes.length)
+ return bytes;
+
+ byte[] res = new byte[length];
+
+ GridUnsafe.arrayCopy(bytes, offset, res, 0, length);
+
+ return res;
+ }
+
+ /**
+ * @param buf Buffer.
+ */
+ private static byte[] toArray(ByteBuffer buf) {
+ if (buf.isDirect()) {
+ byte[] res = new byte[buf.remaining()];
+
+ buf.get(res);
+
+ return res;
+ }
+ else {
+ if (buf.remaining() != buf.capacity())
+ throw new IllegalStateException("Unexpected Heap Byte Buffer
state. " +
+ "Wrapped array must contain the data without any offsets
to avoid unnecessary copying. " +
+ "Position must be 0, limit must be equal to the capacity."
+
+ " [buf=" + buf + "]");
+
+ return buf.array();
+ }
+ }
+
+ /**
+ * @param type Type.
+ */
+ private boolean recordable(int type) {
+ return ctx.event() != null // Can be null at external usage (via
StandaloneGridKernalContext)
+ && ctx.event().isRecordable(type);
+ }
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
index 67195646ab6..357a0ea726a 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
@@ -60,14 +60,14 @@ public abstract class CacheObjectAdapter implements
CacheObject, Externalizable
protected byte[] valueBytesFromValue(CacheObjectValueContext ctx) throws
IgniteCheckedException {
byte[] bytes = ctx.marshal(val);
- return CacheObjectTransformerUtils.transformIfNecessary(bytes, ctx);
+ return ctx.transformIfNecessary(bytes);
}
/**
* @return Value from value bytes.
*/
protected Object valueFromValueBytes(CacheObjectValueContext ctx,
ClassLoader ldr) throws IgniteCheckedException {
- byte[] bytes =
CacheObjectTransformerUtils.restoreIfNecessary(valBytes, ctx);
+ byte[] bytes = ctx.restoreIfNecessary(valBytes);
return ctx.unmarshal(bytes, ldr);
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectTransformerUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectTransformerUtils.java
deleted file mode 100644
index 6af164686ae..00000000000
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectTransformerUtils.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.cache;
-
-import java.nio.ByteBuffer;
-import org.apache.ignite.events.CacheObjectTransformedEvent;
-import
org.apache.ignite.internal.cache.transform.CacheObjectTransformerProcessor;
-import org.apache.ignite.internal.util.GridUnsafe;
-
-import static org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_TRANSFORMED;
-import static
org.apache.ignite.internal.binary.GridBinaryMarshaller.TRANSFORMED;
-
-/** */
-public class CacheObjectTransformerUtils {
- /** */
- private static CacheObjectTransformerProcessor
transformer(CacheObjectValueContext ctx) {
- return ctx.kernalContext().transformer();
- }
-
- /**
- * Transforms bytes according to {@link CacheObjectTransformerProcessor}
when specified.
- * @param bytes Given bytes.
- * @param ctx Context.
- * @return Transformed bytes.
- */
- public static byte[] transformIfNecessary(byte[] bytes,
CacheObjectValueContext ctx) {
- return transformIfNecessary(bytes, 0, bytes.length, ctx);
- }
-
- /**
- * Transforms bytes according to {@link CacheObjectTransformerProcessor}
when specified.
- * @param bytes Given bytes.
- * @param ctx Context.
- * @return Transformed bytes.
- */
- public static byte[] transformIfNecessary(byte[] bytes, int offset, int
length, CacheObjectValueContext ctx) {
- assert bytes[offset] != TRANSFORMED;
-
- CacheObjectTransformerProcessor transformer = transformer(ctx);
-
- if (transformer == null)
- return bytes;
-
- ByteBuffer src = ByteBuffer.wrap(bytes, offset, length);
- ByteBuffer transformed = transformer.transform(src);
-
- if (transformed != null) {
- assert transformed.remaining() > 0 : transformed.remaining();
-
- byte[] res = toArray(transformed);
-
- if (recordable(ctx, EVT_CACHE_OBJECT_TRANSFORMED)) {
- ctx.kernalContext().event().record(
- new
CacheObjectTransformedEvent(ctx.kernalContext().discovery().localNode(),
- "Object transformed",
- EVT_CACHE_OBJECT_TRANSFORMED,
- detachIfNecessary(bytes, offset, length),
- res,
- false));
- }
-
- return res;
- }
- else {
- byte[] res = detachIfNecessary(bytes, offset, length);
-
- if (recordable(ctx, EVT_CACHE_OBJECT_TRANSFORMED)) {
- ctx.kernalContext().event().record(
- new
CacheObjectTransformedEvent(ctx.kernalContext().discovery().localNode(),
- "Object transformation was cancelled.",
- EVT_CACHE_OBJECT_TRANSFORMED,
- res,
- res,
- false));
- }
-
- return res;
- }
- }
-
- /**
- *
- */
- private static byte[] detachIfNecessary(byte[] bytes, int offset, int
length) {
- if (offset == 0 && length == bytes.length)
- return bytes;
-
- byte[] res = new byte[length];
-
- GridUnsafe.arrayCopy(bytes, offset, res, 0, length);
-
- return res;
- }
-
- /**
- * Restores transformed bytes if necessary.
- * @param bytes Given bytes.
- * @param ctx Context.
- * @return Restored bytes.
- */
- public static byte[] restoreIfNecessary(byte[] bytes,
CacheObjectValueContext ctx) {
- if (bytes[0] != TRANSFORMED)
- return bytes;
-
- CacheObjectTransformerProcessor transformer = transformer(ctx);
-
- ByteBuffer src = ByteBuffer.wrap(bytes, 1, bytes.length - 1); //
Skipping TRANSFORMED.
- ByteBuffer restored = transformer.restore(src);
-
- byte[] res = toArray(restored);
-
- if (recordable(ctx, EVT_CACHE_OBJECT_TRANSFORMED)) {
- ctx.kernalContext().event().record(
- new
CacheObjectTransformedEvent(ctx.kernalContext().discovery().localNode(),
- "Object restored",
- EVT_CACHE_OBJECT_TRANSFORMED,
- res,
- bytes,
- true));
- }
-
- return res;
- }
-
- /**
- * @param buf Buffer.
- */
- private static byte[] toArray(ByteBuffer buf) {
- if (buf.isDirect()) {
- byte[] res = new byte[buf.remaining()];
-
- buf.get(res);
-
- return res;
- }
- else {
- if (buf.remaining() != buf.capacity())
- throw new IllegalStateException("Unexpected Heap Byte Buffer
state. " +
- "Wrapped array must contain the data without any offsets
to avoid unnecessary copying. " +
- "Position must be 0, limit must be equal to the capacity."
+
- " [buf=" + buf + "]");
-
- return buf.array();
- }
- }
-
- /**
- * @param ctx Context.
- * @param type Type.
- */
- private static boolean recordable(CacheObjectValueContext ctx, int type) {
- return ctx.kernalContext().event() != null // Can be null at external
usage (via StandaloneGridKernalContext)
- && ctx.kernalContext().event().isRecordable(type);
- }
-}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectValueContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectValueContext.java
index 42294e96456..edefa2672ad 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectValueContext.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectValueContext.java
@@ -19,19 +19,14 @@ package org.apache.ignite.internal.processors.cache;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.binary.BinaryContext;
+import
org.apache.ignite.internal.cache.transform.CacheObjectTransformerProcessor;
import org.jetbrains.annotations.Nullable;
/**
* Context to get value of cache object.
*/
public interface CacheObjectValueContext {
- /**
- * @return Kernal context.
- */
- public GridKernalContext kernalContext();
-
/**
* @return Copy on get flag.
*/
@@ -102,4 +97,29 @@ public interface CacheObjectValueContext {
/** @return {@code true} if peer class loading is enabled, {@code false}
otherwise. */
public boolean isPeerClassLoadingEnabled();
+
+ /**
+ * Transforms bytes according to {@link CacheObjectTransformerProcessor}
when specified.
+ * @param bytes Given bytes.
+ * @return Transformed bytes.
+ */
+ public default byte[] transformIfNecessary(byte[] bytes) {
+ return transformIfNecessary(bytes, 0, bytes.length);
+ }
+
+ /**
+ * Transforms bytes according to {@link CacheObjectTransformerProcessor}
when specified.
+ * @param bytes Given bytes.
+ * @param offset Index to start from.
+ * @param length Data length.
+ * @return Transformed bytes.
+ */
+ public byte[] transformIfNecessary(byte[] bytes, int offset, int length);
+
+ /**
+ * Restores transformed bytes if necessary.
+ * @param bytes Given bytes.
+ * @return Restored bytes.
+ */
+ public byte[] restoreIfNecessary(byte[] bytes);
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/PlatformCacheObjectImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/PlatformCacheObjectImpl.java
index 17b9566d281..d068b78d3f7 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/PlatformCacheObjectImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/PlatformCacheObjectImpl.java
@@ -19,7 +19,6 @@ package org.apache.ignite.internal.processors.cacheobject;
import org.apache.ignite.internal.processors.cache.CacheObject;
import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
-import org.apache.ignite.internal.processors.cache.CacheObjectTransformerUtils;
import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
/**
@@ -55,7 +54,7 @@ public class PlatformCacheObjectImpl extends CacheObjectImpl {
private byte[] valueBytesFromArray(CacheObjectValueContext ctx) {
assert arr != null;
- return CacheObjectTransformerUtils.transformIfNecessary(arr, 0,
arr.length, ctx);
+ return ctx.transformIfNecessary(arr, 0, arr.length);
}
/** {@inheritDoc} */