This is an automated email from the ASF dual-hosted git repository.

sergeychugunov 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 ee2df95b537 IGNITE-28264 Extract enum from message class, use 
serializer to encode and decode the enum (#12916)
ee2df95b537 is described below

commit ee2df95b53789f4ceee482ae826a516a901022cc
Author: Sergey Chugunov <[email protected]>
AuthorDate: Tue Mar 31 10:41:08 2026 +0400

    IGNITE-28264 Extract enum from message class, use serializer to encode and 
decode the enum (#12916)
---
 .../communication/GridIoMessageFactory.java        |   4 +-
 .../cache/CacheEntryPredicateAdapter.java          | 104 ++---------------
 .../processors/cache/CacheEntryPredicateType.java  |  44 ++++++++
 .../processors/cache/GridCacheContext.java         |   6 +-
 .../internal/processors/cache/GridCacheUtils.java  |   4 +-
 .../CacheEntryPredicateAdapterMessageTest.java     | 123 ---------------------
 .../ignite/testsuites/IgniteBasicTestSuite.java    |   2 -
 7 files changed, 60 insertions(+), 227 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index edeef1147bd..e97b2ad3517 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -68,7 +68,7 @@ import 
org.apache.ignite.internal.processors.authentication.UserAuthenticateResp
 import 
org.apache.ignite.internal.processors.authentication.UserManagementOperationFinishedMessage;
 import 
org.apache.ignite.internal.processors.authentication.UserManagementOperationFinishedMessageSerializer;
 import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapter;
-import 
org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapterMarshallableSerializer;
+import 
org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapterSerializer;
 import org.apache.ignite.internal.processors.cache.CacheEvictionEntry;
 import 
org.apache.ignite.internal.processors.cache.CacheEvictionEntrySerializer;
 import org.apache.ignite.internal.processors.cache.CacheInvokeDirectResult;
@@ -477,7 +477,7 @@ public class GridIoMessageFactory implements 
MessageFactoryProvider {
         factory.register(95, DataStreamerEntry::new, new 
DataStreamerEntrySerializer());
         factory.register(96, CacheContinuousQueryEntry::new, new 
CacheContinuousQueryEntryMarshallableSerializer(marsh, clsLdr));
         factory.register(97, CacheEvictionEntry::new, new 
CacheEvictionEntrySerializer());
-        factory.register(98, CacheEntryPredicateAdapter::new, new 
CacheEntryPredicateAdapterMarshallableSerializer(marsh, clsLdr));
+        factory.register(98, CacheEntryPredicateAdapter::new, new 
CacheEntryPredicateAdapterSerializer());
         factory.register(100, IgniteTxEntry::new, new 
IgniteTxEntrySerializer());
         factory.register(101, TxEntryValueHolder::new, new 
TxEntryValueHolderSerializer());
         factory.register(102, CacheVersionedValue::new, new 
CacheVersionedValueSerializer());
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java
index 1cc84a98a4f..0c30dc615aa 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java
@@ -23,28 +23,20 @@ import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.internal.Order;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.internal.CU;
-import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.plugin.extensions.communication.MarshallableMessage;
 import org.jetbrains.annotations.Nullable;
 
 /** A unified container for common, typical cache entry predicates. */
-public class CacheEntryPredicateAdapter implements CacheEntryPredicate, 
MarshallableMessage {
+public class CacheEntryPredicateAdapter implements CacheEntryPredicate {
     /** */
     private static final long serialVersionUID = 4647110502545358709L;
 
-    /** */
-    public static final CacheEntryPredicateAdapter ALWAYS_FALSE = new 
CacheEntryPredicateAdapter(PredicateType.ALWAYS_FALSE);
-
     /** */
     protected transient boolean locked;
 
     /** */
     @GridToStringInclude
-    private PredicateType type;
-
-    /** Type value serialization holder. */
     @Order(0)
-    protected transient byte code;
+    CacheEntryPredicateType type;
 
     /** */
     @GridToStringInclude
@@ -53,11 +45,11 @@ public class CacheEntryPredicateAdapter implements 
CacheEntryPredicate, Marshall
 
     /** */
     public CacheEntryPredicateAdapter() {
-        type = PredicateType.OTHER;
+        type = CacheEntryPredicateType.OTHER;
     }
 
     /** */
-    public CacheEntryPredicateAdapter(PredicateType type) {
+    public CacheEntryPredicateAdapter(CacheEntryPredicateType type) {
         assert type != null;
 
         this.type = type;
@@ -65,8 +57,7 @@ public class CacheEntryPredicateAdapter implements 
CacheEntryPredicate, Marshall
 
     /** */
     public CacheEntryPredicateAdapter(@Nullable CacheObject val) {
-        type = PredicateType.VALUE;
-        code = 1;
+        type = CacheEntryPredicateType.VALUE;
 
         this.val = val;
     }
@@ -77,7 +68,7 @@ public class CacheEntryPredicateAdapter implements 
CacheEntryPredicate, Marshall
     }
 
     /** */
-    public PredicateType type() {
+    public CacheEntryPredicateType type() {
         return type;
     }
 
@@ -130,93 +121,14 @@ public class CacheEntryPredicateAdapter implements 
CacheEntryPredicate, Marshall
 
     /** {@inheritDoc} */
     @Override public void finishUnmarshal(GridCacheContext ctx, ClassLoader 
ldr) throws IgniteCheckedException {
-        if (type == PredicateType.VALUE)
+        if (type == CacheEntryPredicateType.VALUE)
             val.finishUnmarshal(ctx.cacheObjectContext(), ldr);
     }
 
     /** {@inheritDoc} */
     @Override public void prepareMarshal(GridCacheContext ctx) throws 
IgniteCheckedException {
-        if (type == PredicateType.VALUE)
+        if (type == CacheEntryPredicateType.VALUE)
             val.prepareMarshal(ctx.cacheObjectContext());
     }
 
-    /** */
-    public byte code() {
-        return code;
-    }
-
-    /** */
-    public void code(byte code) {
-        this.code = code;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void prepareMarshal(Marshaller marsh) throws 
IgniteCheckedException {
-        switch (type) {
-            case OTHER:
-                code = 0;
-                break;
-
-            case VALUE:
-                code = 1;
-                break;
-
-            case HAS_VALUE:
-                code = 2;
-                break;
-
-            case HAS_NO_VALUE:
-                code = 3;
-                break;
-
-            case ALWAYS_FALSE:
-                code = 4;
-                break;
-
-            default:
-                throw new IllegalArgumentException("Unknown cache entry 
predicate type: " + type);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void finishUnmarshal(Marshaller marsh, ClassLoader 
clsLdr) throws IgniteCheckedException {
-        switch (code) {
-            case 0:
-                type = PredicateType.OTHER;
-                break;
-
-            case 1:
-                type = PredicateType.VALUE;
-                break;
-
-            case 2:
-                type = PredicateType.HAS_VALUE;
-                break;
-
-            case 3:
-                type = PredicateType.HAS_NO_VALUE;
-                break;
-
-            case 4:
-                type = PredicateType.ALWAYS_FALSE;
-                break;
-
-            default:
-                throw new IllegalArgumentException("Unknown cache entry 
predicate type code: " + code);
-        }
-    }
-
-    /** Common predicate type. */
-    public enum PredicateType {
-        /** Other custom predicate. */
-        OTHER,
-        /** Entry has certain equal value. */
-        VALUE,
-        /** Entry has any value. */
-        HAS_VALUE,
-        /** Entry has no value. */
-        HAS_NO_VALUE,
-        /** Is always false. */
-        ALWAYS_FALSE
-    }
 }
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateType.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateType.java
new file mode 100644
index 00000000000..d35f81a2522
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateType.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+/**
+ * Type of {@link CacheEntryPredicateAdapter}.
+ */
+public enum CacheEntryPredicateType {
+    /**
+     * Predicate that entry has specified value.
+     */
+    VALUE,
+    /**
+     * Predicate that entry has any value.
+     */
+    HAS_VALUE,
+    /**
+     * Predicate that entry has no value.
+     */
+    HAS_NO_VALUE,
+    /**
+     * Predicate that is always {@code false}.
+     */
+    ALWAYS_FALSE,
+    /**
+     * Any other predicate.
+     */
+    OTHER
+}
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index a01f0153814..5444815620d 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -1201,7 +1201,7 @@ public class GridCacheContext<K, V> implements 
Externalizable {
 
         for (CacheEntryPredicate p0 : p) {
             if ((p0 instanceof CacheEntryPredicateAdapter) &&
-                ((CacheEntryPredicateAdapter)p0).type() == 
CacheEntryPredicateAdapter.PredicateType.HAS_NO_VALUE)
+                ((CacheEntryPredicateAdapter)p0).type() == 
CacheEntryPredicateType.HAS_NO_VALUE)
                 return true;
         }
 
@@ -1212,14 +1212,14 @@ public class GridCacheContext<K, V> implements 
Externalizable {
      * @return No value filter.
      */
     public CacheEntryPredicate noVal() {
-        return new 
CacheEntryPredicateAdapter(CacheEntryPredicateAdapter.PredicateType.HAS_NO_VALUE);
+        return new 
CacheEntryPredicateAdapter(CacheEntryPredicateType.HAS_NO_VALUE);
     }
 
     /**
      * @return Has value filter.
      */
     public CacheEntryPredicate hasVal() {
-        return new 
CacheEntryPredicateAdapter(CacheEntryPredicateAdapter.PredicateType.HAS_VALUE);
+        return new 
CacheEntryPredicateAdapter(CacheEntryPredicateType.HAS_VALUE);
     }
 
     /**
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index 00e0fd0f3ec..94377623724 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -245,7 +245,9 @@ public class GridCacheUtils {
     private static final CacheEntryPredicate[] EMPTY_FILTER0 = new 
CacheEntryPredicate[0];
 
     /** */
-    private static final CacheEntryPredicate[] ALWAYS_FALSE0_ARR = new 
CacheEntryPredicate[] {CacheEntryPredicateAdapter.ALWAYS_FALSE};
+    private static final CacheEntryPredicate[] ALWAYS_FALSE0_ARR = new 
CacheEntryPredicate[] {
+        new CacheEntryPredicateAdapter(CacheEntryPredicateType.ALWAYS_FALSE)
+    };
 
     /** Read filter. */
     public static final IgnitePredicate<IgniteTxEntry> READ_FILTER = new 
P1<IgniteTxEntry>() {
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/CacheEntryPredicateAdapterMessageTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/CacheEntryPredicateAdapterMessageTest.java
deleted file mode 100644
index f56dddb7dae..00000000000
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/CacheEntryPredicateAdapterMessageTest.java
+++ /dev/null
@@ -1,123 +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.managers.communication;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapter;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.junit.Test;
-
-import static org.apache.ignite.marshaller.Marshallers.jdk;
-import static 
org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-/** */
-public class CacheEntryPredicateAdapterMessageTest {
-    /** */
-    @Test
-    public void testCacheEntryPredicateAdapterCode() {
-        assertEquals(0, prepare(new CacheEntryPredicateAdapter()));
-        assertEquals(0, prepare(new 
CacheEntryPredicateAdapter(CacheEntryPredicateAdapter.PredicateType.OTHER)));
-        assertEquals(1, prepare(new 
CacheEntryPredicateAdapter(CacheEntryPredicateAdapter.PredicateType.VALUE)));
-        assertEquals(1, prepare(new 
CacheEntryPredicateAdapter((CacheObject)null)));
-        assertEquals(2, prepare(new 
CacheEntryPredicateAdapter(CacheEntryPredicateAdapter.PredicateType.HAS_VALUE)));
-        assertEquals(3, prepare(new 
CacheEntryPredicateAdapter(CacheEntryPredicateAdapter.PredicateType.HAS_NO_VALUE)));
-        assertEquals(4, prepare(new 
CacheEntryPredicateAdapter(CacheEntryPredicateAdapter.PredicateType.ALWAYS_FALSE)));
-
-        for (CacheEntryPredicateAdapter.PredicateType t : 
CacheEntryPredicateAdapter.PredicateType.values()) {
-            assertTrue(prepare(new CacheEntryPredicateAdapter(t)) >= 0);
-            assertTrue(prepare(new CacheEntryPredicateAdapter(t)) < 5);
-        }
-    }
-
-    /** */
-    byte prepare(CacheEntryPredicateAdapter msg) {
-        try {
-            msg.prepareMarshal(jdk());
-        }
-        catch (IgniteCheckedException e) {
-            throw new RuntimeException(e);
-        }
-
-        return msg.code();
-    }
-
-    /** */
-    @Test
-    public void testCacheEntryPredicateAdapterFromCode() throws 
IgniteCheckedException {
-        CacheEntryPredicateAdapter msg = new 
CacheEntryPredicateAdapter((CacheObject)null);
-        msg.finishUnmarshal(jdk(), U.gridClassLoader());
-        assertSame(CacheEntryPredicateAdapter.PredicateType.VALUE, msg.type());
-
-        msg.code((byte)0);
-        msg.finishUnmarshal(jdk(), U.gridClassLoader());
-        assertSame(CacheEntryPredicateAdapter.PredicateType.OTHER, msg.type());
-
-        msg.code((byte)1);
-        msg.finishUnmarshal(jdk(), U.gridClassLoader());
-        assertSame(CacheEntryPredicateAdapter.PredicateType.VALUE, msg.type());
-
-        msg.code((byte)2);
-        msg.finishUnmarshal(jdk(), U.gridClassLoader());
-        assertSame(CacheEntryPredicateAdapter.PredicateType.HAS_VALUE, 
msg.type());
-
-        msg.code((byte)3);
-        msg.finishUnmarshal(jdk(), U.gridClassLoader());
-        assertSame(CacheEntryPredicateAdapter.PredicateType.HAS_NO_VALUE, 
msg.type());
-
-        msg.code((byte)4);
-        msg.finishUnmarshal(jdk(), U.gridClassLoader());
-        assertSame(CacheEntryPredicateAdapter.PredicateType.ALWAYS_FALSE, 
msg.type());
-
-        Throwable t = assertThrowsWithCause(() -> {
-            msg.code((byte)5);
-
-            try {
-                msg.finishUnmarshal(jdk(), U.gridClassLoader());
-            }
-            catch (IgniteCheckedException e) {
-                throw new RuntimeException(e);
-            }
-        }, IllegalArgumentException.class);
-        assertEquals("Unknown cache entry predicate type code: 5", 
t.getMessage());
-    }
-
-    /** */
-    @Test
-    public void testConversionConsistency() throws IgniteCheckedException {
-        for (CacheEntryPredicateAdapter.PredicateType t : 
F.concat(CacheEntryPredicateAdapter.PredicateType.values())) {
-            CacheEntryPredicateAdapter msg = new CacheEntryPredicateAdapter(t);
-
-            assertEquals(t, msg.type());
-
-            CacheEntryPredicateAdapter newMsg = new 
CacheEntryPredicateAdapter();
-
-            msg.prepareMarshal(jdk());
-
-            newMsg.code(msg.code());
-
-            newMsg.finishUnmarshal(jdk(), U.gridClassLoader());
-
-            assertEquals(msg.type(), newMsg.type());
-        }
-    }
-}
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 44a47adc753..c3587ca0b3c 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -38,7 +38,6 @@ import 
org.apache.ignite.internal.IgniteSlowClientDetectionSelfTest;
 import org.apache.ignite.internal.TransactionsMXBeanImplTest;
 import 
org.apache.ignite.internal.codegen.IgniteDataTransferObjectProcessorTest;
 import org.apache.ignite.internal.codegen.MessageProcessorTest;
-import 
org.apache.ignite.internal.managers.communication.CacheEntryPredicateAdapterMessageTest;
 import org.apache.ignite.internal.managers.communication.CompressedMessageTest;
 import org.apache.ignite.internal.managers.communication.DefaultEnumMapperTest;
 import org.apache.ignite.internal.managers.communication.ErrorMessageSelfTest;
@@ -150,7 +149,6 @@ import org.junit.runners.Suite;
 
     MessageProcessorTest.class,
     ErrorMessageSelfTest.class,
-    CacheEntryPredicateAdapterMessageTest.class,
     DefaultEnumMapperTest.class,
     IgniteDataTransferObjectProcessorTest.class,
     CompressedMessageTest.class

Reply via email to