Skip to content

Commit ee2df95

Browse files
IGNITE-28264 Extract enum from message class, use serializer to encode and decode the enum (#12916)
1 parent 8a26b18 commit ee2df95

7 files changed

Lines changed: 60 additions & 227 deletions

File tree

modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
import org.apache.ignite.internal.processors.authentication.UserManagementOperationFinishedMessage;
6969
import org.apache.ignite.internal.processors.authentication.UserManagementOperationFinishedMessageSerializer;
7070
import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapter;
71-
import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapterMarshallableSerializer;
71+
import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapterSerializer;
7272
import org.apache.ignite.internal.processors.cache.CacheEvictionEntry;
7373
import org.apache.ignite.internal.processors.cache.CacheEvictionEntrySerializer;
7474
import org.apache.ignite.internal.processors.cache.CacheInvokeDirectResult;
@@ -477,7 +477,7 @@ public GridIoMessageFactory(Marshaller marsh, ClassLoader clsLdr) {
477477
factory.register(95, DataStreamerEntry::new, new DataStreamerEntrySerializer());
478478
factory.register(96, CacheContinuousQueryEntry::new, new CacheContinuousQueryEntryMarshallableSerializer(marsh, clsLdr));
479479
factory.register(97, CacheEvictionEntry::new, new CacheEvictionEntrySerializer());
480-
factory.register(98, CacheEntryPredicateAdapter::new, new CacheEntryPredicateAdapterMarshallableSerializer(marsh, clsLdr));
480+
factory.register(98, CacheEntryPredicateAdapter::new, new CacheEntryPredicateAdapterSerializer());
481481
factory.register(100, IgniteTxEntry::new, new IgniteTxEntrySerializer());
482482
factory.register(101, TxEntryValueHolder::new, new TxEntryValueHolderSerializer());
483483
factory.register(102, CacheVersionedValue::new, new CacheVersionedValueSerializer());

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java

Lines changed: 8 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,20 @@
2323
import org.apache.ignite.internal.Order;
2424
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
2525
import org.apache.ignite.internal.util.typedef.internal.CU;
26-
import org.apache.ignite.marshaller.Marshaller;
27-
import org.apache.ignite.plugin.extensions.communication.MarshallableMessage;
2826
import org.jetbrains.annotations.Nullable;
2927

3028
/** A unified container for common, typical cache entry predicates. */
31-
public class CacheEntryPredicateAdapter implements CacheEntryPredicate, MarshallableMessage {
29+
public class CacheEntryPredicateAdapter implements CacheEntryPredicate {
3230
/** */
3331
private static final long serialVersionUID = 4647110502545358709L;
3432

35-
/** */
36-
public static final CacheEntryPredicateAdapter ALWAYS_FALSE = new CacheEntryPredicateAdapter(PredicateType.ALWAYS_FALSE);
37-
3833
/** */
3934
protected transient boolean locked;
4035

4136
/** */
4237
@GridToStringInclude
43-
private PredicateType type;
44-
45-
/** Type value serialization holder. */
4638
@Order(0)
47-
protected transient byte code;
39+
CacheEntryPredicateType type;
4840

4941
/** */
5042
@GridToStringInclude
@@ -53,20 +45,19 @@ public class CacheEntryPredicateAdapter implements CacheEntryPredicate, Marshall
5345

5446
/** */
5547
public CacheEntryPredicateAdapter() {
56-
type = PredicateType.OTHER;
48+
type = CacheEntryPredicateType.OTHER;
5749
}
5850

5951
/** */
60-
public CacheEntryPredicateAdapter(PredicateType type) {
52+
public CacheEntryPredicateAdapter(CacheEntryPredicateType type) {
6153
assert type != null;
6254

6355
this.type = type;
6456
}
6557

6658
/** */
6759
public CacheEntryPredicateAdapter(@Nullable CacheObject val) {
68-
type = PredicateType.VALUE;
69-
code = 1;
60+
type = CacheEntryPredicateType.VALUE;
7061

7162
this.val = val;
7263
}
@@ -77,7 +68,7 @@ public CacheEntryPredicateAdapter(@Nullable CacheObject val) {
7768
}
7869

7970
/** */
80-
public PredicateType type() {
71+
public CacheEntryPredicateType type() {
8172
return type;
8273
}
8374

@@ -130,93 +121,14 @@ public PredicateType type() {
130121

131122
/** {@inheritDoc} */
132123
@Override public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException {
133-
if (type == PredicateType.VALUE)
124+
if (type == CacheEntryPredicateType.VALUE)
134125
val.finishUnmarshal(ctx.cacheObjectContext(), ldr);
135126
}
136127

137128
/** {@inheritDoc} */
138129
@Override public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException {
139-
if (type == PredicateType.VALUE)
130+
if (type == CacheEntryPredicateType.VALUE)
140131
val.prepareMarshal(ctx.cacheObjectContext());
141132
}
142133

143-
/** */
144-
public byte code() {
145-
return code;
146-
}
147-
148-
/** */
149-
public void code(byte code) {
150-
this.code = code;
151-
}
152-
153-
/** {@inheritDoc} */
154-
@Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException {
155-
switch (type) {
156-
case OTHER:
157-
code = 0;
158-
break;
159-
160-
case VALUE:
161-
code = 1;
162-
break;
163-
164-
case HAS_VALUE:
165-
code = 2;
166-
break;
167-
168-
case HAS_NO_VALUE:
169-
code = 3;
170-
break;
171-
172-
case ALWAYS_FALSE:
173-
code = 4;
174-
break;
175-
176-
default:
177-
throw new IllegalArgumentException("Unknown cache entry predicate type: " + type);
178-
}
179-
}
180-
181-
/** {@inheritDoc} */
182-
@Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException {
183-
switch (code) {
184-
case 0:
185-
type = PredicateType.OTHER;
186-
break;
187-
188-
case 1:
189-
type = PredicateType.VALUE;
190-
break;
191-
192-
case 2:
193-
type = PredicateType.HAS_VALUE;
194-
break;
195-
196-
case 3:
197-
type = PredicateType.HAS_NO_VALUE;
198-
break;
199-
200-
case 4:
201-
type = PredicateType.ALWAYS_FALSE;
202-
break;
203-
204-
default:
205-
throw new IllegalArgumentException("Unknown cache entry predicate type code: " + code);
206-
}
207-
}
208-
209-
/** Common predicate type. */
210-
public enum PredicateType {
211-
/** Other custom predicate. */
212-
OTHER,
213-
/** Entry has certain equal value. */
214-
VALUE,
215-
/** Entry has any value. */
216-
HAS_VALUE,
217-
/** Entry has no value. */
218-
HAS_NO_VALUE,
219-
/** Is always false. */
220-
ALWAYS_FALSE
221-
}
222134
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.processors.cache;
19+
20+
/**
21+
* Type of {@link CacheEntryPredicateAdapter}.
22+
*/
23+
public enum CacheEntryPredicateType {
24+
/**
25+
* Predicate that entry has specified value.
26+
*/
27+
VALUE,
28+
/**
29+
* Predicate that entry has any value.
30+
*/
31+
HAS_VALUE,
32+
/**
33+
* Predicate that entry has no value.
34+
*/
35+
HAS_NO_VALUE,
36+
/**
37+
* Predicate that is always {@code false}.
38+
*/
39+
ALWAYS_FALSE,
40+
/**
41+
* Any other predicate.
42+
*/
43+
OTHER
44+
}

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ public boolean putIfAbsentFilter(@Nullable CacheEntryPredicate[] p) {
12011201

12021202
for (CacheEntryPredicate p0 : p) {
12031203
if ((p0 instanceof CacheEntryPredicateAdapter) &&
1204-
((CacheEntryPredicateAdapter)p0).type() == CacheEntryPredicateAdapter.PredicateType.HAS_NO_VALUE)
1204+
((CacheEntryPredicateAdapter)p0).type() == CacheEntryPredicateType.HAS_NO_VALUE)
12051205
return true;
12061206
}
12071207

@@ -1212,14 +1212,14 @@ public boolean putIfAbsentFilter(@Nullable CacheEntryPredicate[] p) {
12121212
* @return No value filter.
12131213
*/
12141214
public CacheEntryPredicate noVal() {
1215-
return new CacheEntryPredicateAdapter(CacheEntryPredicateAdapter.PredicateType.HAS_NO_VALUE);
1215+
return new CacheEntryPredicateAdapter(CacheEntryPredicateType.HAS_NO_VALUE);
12161216
}
12171217

12181218
/**
12191219
* @return Has value filter.
12201220
*/
12211221
public CacheEntryPredicate hasVal() {
1222-
return new CacheEntryPredicateAdapter(CacheEntryPredicateAdapter.PredicateType.HAS_VALUE);
1222+
return new CacheEntryPredicateAdapter(CacheEntryPredicateType.HAS_VALUE);
12231223
}
12241224

12251225
/**

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ public static boolean cheatCache(int id) {
245245
private static final CacheEntryPredicate[] EMPTY_FILTER0 = new CacheEntryPredicate[0];
246246

247247
/** */
248-
private static final CacheEntryPredicate[] ALWAYS_FALSE0_ARR = new CacheEntryPredicate[] {CacheEntryPredicateAdapter.ALWAYS_FALSE};
248+
private static final CacheEntryPredicate[] ALWAYS_FALSE0_ARR = new CacheEntryPredicate[] {
249+
new CacheEntryPredicateAdapter(CacheEntryPredicateType.ALWAYS_FALSE)
250+
};
249251

250252
/** Read filter. */
251253
public static final IgnitePredicate<IgniteTxEntry> READ_FILTER = new P1<IgniteTxEntry>() {

modules/core/src/test/java/org/apache/ignite/internal/managers/communication/CacheEntryPredicateAdapterMessageTest.java

Lines changed: 0 additions & 123 deletions
This file was deleted.

modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.apache.ignite.internal.TransactionsMXBeanImplTest;
3939
import org.apache.ignite.internal.codegen.IgniteDataTransferObjectProcessorTest;
4040
import org.apache.ignite.internal.codegen.MessageProcessorTest;
41-
import org.apache.ignite.internal.managers.communication.CacheEntryPredicateAdapterMessageTest;
4241
import org.apache.ignite.internal.managers.communication.CompressedMessageTest;
4342
import org.apache.ignite.internal.managers.communication.DefaultEnumMapperTest;
4443
import org.apache.ignite.internal.managers.communication.ErrorMessageSelfTest;
@@ -150,7 +149,6 @@
150149

151150
MessageProcessorTest.class,
152151
ErrorMessageSelfTest.class,
153-
CacheEntryPredicateAdapterMessageTest.class,
154152
DefaultEnumMapperTest.class,
155153
IgniteDataTransferObjectProcessorTest.class,
156154
CompressedMessageTest.class

0 commit comments

Comments
 (0)