Skip to content

Commit 6ccb40d

Browse files
committed
IGNITE-26728 Add EnumMessage
1 parent 2d31cd3 commit 6ccb40d

File tree

9 files changed

+60
-112
lines changed

9 files changed

+60
-112
lines changed

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

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,37 @@
1818
package org.apache.ignite.internal.managers.communication;
1919

2020
import org.apache.ignite.cache.CacheWriteSynchronizationMode;
21-
import org.apache.ignite.internal.Order;
22-
import org.apache.ignite.plugin.extensions.communication.Message;
2321
import org.jetbrains.annotations.Nullable;
2422

2523
/** */
26-
public class CacheWriteSynchronizationModeMessage implements Message {
24+
public class CacheWriteSynchronizationModeMessage extends EnumMessage<CacheWriteSynchronizationMode> {
2725
/** Type code. */
2826
public static final short TYPE_CODE = 503;
2927

30-
/** Cache write synchronization mode value. */
31-
@Nullable private CacheWriteSynchronizationMode cacheWriteSyncMode;
32-
33-
/** Code of cache write synchronization mode. */
34-
@Order(0)
35-
private byte code = -1;
36-
3728
/** Constructor. */
3829
public CacheWriteSynchronizationModeMessage() {
3930
// No-op.
4031
}
4132

4233
/** Constructor. */
43-
public CacheWriteSynchronizationModeMessage(@Nullable CacheWriteSynchronizationMode mode) {
44-
cacheWriteSyncMode = mode;
45-
code = encode(mode);
34+
public CacheWriteSynchronizationModeMessage(@Nullable CacheWriteSynchronizationMode val) {
35+
super(val);
4636
}
4737

48-
/** @param mode Cache write synchronization mode to encode. */
49-
private static byte encode(@Nullable CacheWriteSynchronizationMode mode) {
50-
if (mode == null)
51-
return -1;
52-
53-
switch (mode) {
38+
/** {@inheritDoc} */
39+
@Override protected byte code0(CacheWriteSynchronizationMode val) {
40+
switch (val) {
5441
case FULL_SYNC: return 0;
5542
case FULL_ASYNC: return 1;
5643
case PRIMARY_SYNC: return 2;
5744
}
5845

59-
throw new IllegalArgumentException("Unknown cache write synchronization mode: " + mode);
46+
throw new IllegalArgumentException("Unknown cache write synchronization mode: " + val);
6047
}
6148

62-
/** @param code Code of cache write synchronization mode to decode. */
63-
@Nullable private static CacheWriteSynchronizationMode decode(short code) {
49+
/** {@inheritDoc} */
50+
@Override protected CacheWriteSynchronizationMode value0(byte code) {
6451
switch (code) {
65-
case -1: return null;
6652
case 0: return CacheWriteSynchronizationMode.FULL_SYNC;
6753
case 1: return CacheWriteSynchronizationMode.FULL_ASYNC;
6854
case 2: return CacheWriteSynchronizationMode.PRIMARY_SYNC;
@@ -71,22 +57,6 @@ private static byte encode(@Nullable CacheWriteSynchronizationMode mode) {
7157
throw new IllegalArgumentException("Unknown cache write synchronization mode code: " + code);
7258
}
7359

74-
/** @param code Code of cache write synchronization mode. */
75-
public void code(byte code) {
76-
this.code = code;
77-
cacheWriteSyncMode = decode(code);
78-
}
79-
80-
/** @return Code of cache write synchronization mode. */
81-
public byte code() {
82-
return code;
83-
}
84-
85-
/** @return Cache write synchronization mode value. */
86-
public CacheWriteSynchronizationMode value() {
87-
return cacheWriteSyncMode;
88-
}
89-
9060
/** {@inheritDoc} */
9161
@Override public short directType() {
9262
return TYPE_CODE;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public void code(byte code) {
6767
return val;
6868
}
6969

70+
// /**
71+
// * Safely gets underlying value of message.
72+
// */
73+
// public static @Nullable <V extends Enum<V>> Enum<V> value(@Nullable EnumMessage<V> msg) {
74+
// return msg == null ? null : msg.value();
75+
// }
76+
7077
/**
7178
* Determines, whether wrapped enum has specified value.
7279
*

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

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,27 @@
1616
*/
1717
package org.apache.ignite.internal.managers.communication;
1818

19-
import org.apache.ignite.internal.Order;
2019
import org.apache.ignite.internal.processors.cache.GridCacheOperation;
21-
import org.apache.ignite.plugin.extensions.communication.Message;
2220
import org.jetbrains.annotations.Nullable;
2321

2422
/** */
25-
public class GridCacheOperationMessage implements Message {
23+
public class GridCacheOperationMessage extends EnumMessage<GridCacheOperation> {
2624
/** Type code. */
2725
public static final short TYPE_CODE = 504;
2826

29-
/** Cache oparation. */
30-
@Nullable private GridCacheOperation cacheOperation;
31-
32-
/** Cache oparation code. */
33-
@Order(0)
34-
private byte code = -1;
35-
3627
/** Constructor. */
3728
public GridCacheOperationMessage() {
3829
// No-op.
3930
}
4031

4132
/** Constructor. */
42-
public GridCacheOperationMessage(@Nullable GridCacheOperation cacheOperation) {
43-
this.cacheOperation = cacheOperation;
44-
code = encode(cacheOperation);
33+
public GridCacheOperationMessage(@Nullable GridCacheOperation val) {
34+
super(val);
4535
}
4636

47-
/** @param operation Cache operation to encode. */
48-
private static byte encode(@Nullable GridCacheOperation operation) {
49-
if (operation == null)
50-
return -1;
51-
52-
switch (operation) {
37+
/** {@inheritDoc} */
38+
@Override protected byte code0(GridCacheOperation val) {
39+
switch (val) {
5340
case READ: return 0;
5441
case CREATE: return 1;
5542
case UPDATE: return 2;
@@ -59,13 +46,12 @@ private static byte encode(@Nullable GridCacheOperation operation) {
5946
case NOOP: return 6;
6047
}
6148

62-
throw new IllegalArgumentException("Unknown cache operation: " + operation);
49+
throw new IllegalArgumentException("Unknown cache operation: " + val);
6350
}
6451

65-
/** @param code Cache operation code to dencode to a cache operation value. */
66-
@Nullable private static GridCacheOperation decode(byte code) {
52+
/** {@inheritDoc} */
53+
@Override protected GridCacheOperation value0(byte code) {
6754
switch (code) {
68-
case -1: return null;
6955
case 0: return GridCacheOperation.READ;
7056
case 1: return GridCacheOperation.CREATE;
7157
case 2: return GridCacheOperation.UPDATE;
@@ -78,22 +64,6 @@ private static byte encode(@Nullable GridCacheOperation operation) {
7864
throw new IllegalArgumentException("Unknown cache operation code: " + code);
7965
}
8066

81-
/** @code Cache operation code. */
82-
public void code(byte code) {
83-
this.code = code;
84-
cacheOperation = decode(code);
85-
}
86-
87-
/** @return Cache operation code. */
88-
public byte code() {
89-
return code;
90-
}
91-
92-
/** @return Cache operation value. */
93-
@Nullable public GridCacheOperation value() {
94-
return cacheOperation;
95-
}
96-
9767
/** {@inheritDoc} */
9868
@Override public short directType() {
9969
return TYPE_CODE;

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,29 @@ public TransactionIsolationMessage(TransactionIsolation val) {
3838
}
3939

4040
/** {@inheritDoc} */
41-
@Override public short directType() {
42-
return TYPE_CODE;
43-
}
44-
45-
/**
46-
* @param val Transaction isolation.
47-
* @return Code.
48-
*/
4941
@Override protected byte code0(@Nullable TransactionIsolation val) {
5042
switch (val) {
5143
case READ_COMMITTED: return 0;
5244
case REPEATABLE_READ: return 1;
5345
case SERIALIZABLE: return 2;
54-
default:
55-
throw new IllegalArgumentException("Unknown transaction isolation value: " + val);
5646
}
47+
48+
throw new IllegalArgumentException("Unknown transaction isolation value: " + val);
5749
}
5850

59-
/**
60-
* @param code Code.
61-
* @return Transaction isolation or null.
62-
*/
51+
/** {@inheritDoc} */
6352
@Override protected TransactionIsolation value0(byte code) {
6453
switch (code) {
6554
case 0: return TransactionIsolation.READ_COMMITTED;
6655
case 1: return TransactionIsolation.REPEATABLE_READ;
6756
case 2: return TransactionIsolation.SERIALIZABLE;
68-
default:
69-
throw new IllegalArgumentException("Unknown transaction isolation code: " + code);
7057
}
58+
59+
throw new IllegalArgumentException("Unknown transaction isolation code: " + code);
60+
}
61+
62+
/** {@inheritDoc} */
63+
@Override public short directType() {
64+
return TYPE_CODE;
7165
}
7266
}

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
8383
private boolean isRead;
8484

8585
/** Transaction isolation message. */
86-
@Order(15)
87-
private TransactionIsolationMessage isolation;
86+
@Order(value = 15, method = "isolationMessage")
87+
private TransactionIsolationMessage isolationMsg;
8888

8989
/** Key bytes for keys to lock. */
9090
@Order(16)
@@ -122,7 +122,7 @@ public GridDistributedLockRequest() {
122122
* @param lockVer Cache version.
123123
* @param isInTx {@code True} if implicit transaction lock.
124124
* @param isRead Indicates whether implicit lock is for read or write operation.
125-
* @param isolation Transaction isolation.
125+
* @param isolationMsg Transaction isolation.
126126
* @param isInvalidate Invalidation flag.
127127
* @param timeout Lock timeout.
128128
* @param keyCnt Number of keys.
@@ -139,7 +139,7 @@ public GridDistributedLockRequest(
139139
GridCacheVersion lockVer,
140140
boolean isInTx,
141141
boolean isRead,
142-
TransactionIsolation isolation,
142+
TransactionIsolation isolationMsg,
143143
boolean isInvalidate,
144144
long timeout,
145145
int keyCnt,
@@ -153,7 +153,7 @@ public GridDistributedLockRequest(
153153

154154
assert keyCnt > 0;
155155
assert futId != null;
156-
assert !isInTx || isolation != null;
156+
assert !isInTx || isolationMsg != null;
157157

158158
this.cacheId = cacheId;
159159
this.nodeId = nodeId;
@@ -162,7 +162,7 @@ public GridDistributedLockRequest(
162162
this.futId = futId;
163163
this.isInTx = isInTx;
164164
this.isRead = isRead;
165-
this.isolation = new TransactionIsolationMessage(isolation);
165+
this.isolationMsg = new TransactionIsolationMessage(isolationMsg);
166166
this.isInvalidate = isInvalidate;
167167
this.timeout = timeout;
168168
this.txSize = txSize;
@@ -357,18 +357,25 @@ public void storeUsed(boolean storeUsed) {
357357
flags &= ~STORE_USED_FLAG_MASK;
358358
}
359359

360+
/**
361+
* @return Transaction isolation.
362+
*/
363+
public TransactionIsolation isolation() {
364+
return isolationMsg.value();
365+
}
366+
360367
/**
361368
* @return Transaction isolation message.
362369
*/
363-
public TransactionIsolationMessage isolation() {
364-
return isolation;
370+
public TransactionIsolationMessage isolationMessage() {
371+
return isolationMsg;
365372
}
366373

367374
/**
368-
* @param isolation Transaction isolation message.
375+
* @param isolationMsg Transaction isolation message.
369376
*/
370-
public void isolation(TransactionIsolationMessage isolation) {
371-
this.isolation = isolation;
377+
public void isolationMessage(TransactionIsolationMessage isolationMsg) {
378+
this.isolationMsg = isolationMsg;
372379
}
373380

374381
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public void flags(byte flags) {
348348
public boolean replyRequired() {
349349
assert syncModeMsg != null && syncModeMsg.value() != null;
350350

351-
return syncModeMsg.value() == FULL_SYNC;
351+
return syncModeMsg.is(FULL_SYNC);
352352
}
353353

354354
/** {@inheritDoc} */

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ protected GridDhtTransactionalCacheAdapter(GridCacheContext<K, V> ctx, GridCache
235235
ctx.systemTx(),
236236
ctx.ioPolicy(),
237237
PESSIMISTIC,
238-
req.isolation().value(),
238+
req.isolation(),
239239
req.isInvalidate(),
240240
req.timeout(),
241241
req.txSize(),
@@ -919,7 +919,7 @@ public IgniteInternalFuture<GridNearLockResponse> lockAllAsync(
919919
false,
920920
ctx.ioPolicy(),
921921
PESSIMISTIC,
922-
req.isolation().value(),
922+
req.isolation(),
923923
req.timeout(),
924924
req.isInvalidate(),
925925
!req.skipStore(),

modules/core/src/test/java/org/apache/ignite/internal/managers/communication/CacheWriteSynchroizationModeMessageTest.java renamed to modules/core/src/test/java/org/apache/ignite/internal/managers/communication/CacheWriteSynchronizationModeMessageTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
import static org.junit.Assert.assertTrue;
2929

3030
/** */
31-
public class CacheWriteSynchroizationModeMessageTest {
31+
public class CacheWriteSynchronizationModeMessageTest {
3232
/** */
3333
@Test
34-
public void testCacheWriteSynchroizationCode() {
34+
public void testCacheWriteSynchronizationCode() {
3535
assertEquals(-1, new CacheWriteSynchronizationModeMessage(null).code());
3636
assertEquals(0, new CacheWriteSynchronizationModeMessage(CacheWriteSynchronizationMode.FULL_SYNC).code());
3737
assertEquals(1, new CacheWriteSynchronizationModeMessage(CacheWriteSynchronizationMode.FULL_ASYNC).code());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import org.apache.ignite.internal.TransactionsMXBeanImplTest;
3939
import org.apache.ignite.internal.codegen.MessageProcessorTest;
4040
import org.apache.ignite.internal.managers.communication.CacheEntryPredicateAdapterMessageTest;
41-
import org.apache.ignite.internal.managers.communication.CacheWriteSynchroizationModeMessageTest;
41+
import org.apache.ignite.internal.managers.communication.CacheWriteSynchronizationModeMessageTest;
4242
import org.apache.ignite.internal.managers.communication.ErrorMessageSelfTest;
4343
import org.apache.ignite.internal.managers.communication.GridCacheOperationModeMessageTest;
4444
import org.apache.ignite.internal.managers.communication.TransactionIsolationMessageTest;
@@ -152,7 +152,7 @@
152152
ErrorMessageSelfTest.class,
153153
TransactionIsolationMessageTest.class,
154154
GridCacheOperationModeMessageTest.class,
155-
CacheWriteSynchroizationModeMessageTest.class,
155+
CacheWriteSynchronizationModeMessageTest.class,
156156
CacheEntryPredicateAdapterMessageTest.class
157157
})
158158
public class IgniteBasicTestSuite {

0 commit comments

Comments
 (0)