forked from hazelcast/hazelcast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds CPMap Client Support [HZ-3539] (hazelcast#25877)
Adds client support for the CPMap API, e.g. ```java HazelcastInstance client = HazelcastClient.newHazelcastClient(); CPMap<String, String> map = client.getCPSubsystem().getMap("mymap"); assert map.put("k", "v") == null; assert "v".equals(map.get("k")); ``` EE PR: https://github.com/hazelcast/hazelcast-enterprise/pull/6752 Client Protocol PR: hazelcast/hazelcast-client-protocol#484
- Loading branch information
1 parent
9301cde
commit 1fa9b9c
Showing
28 changed files
with
1,344 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...lcast/src/main/java/com/hazelcast/client/impl/protocol/codec/CPMapCompareAndSetCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed 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 com.hazelcast.client.impl.protocol.codec; | ||
|
||
import com.hazelcast.client.impl.protocol.ClientMessage; | ||
import com.hazelcast.client.impl.protocol.Generated; | ||
import com.hazelcast.client.impl.protocol.codec.builtin.*; | ||
import com.hazelcast.client.impl.protocol.codec.custom.*; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import static com.hazelcast.client.impl.protocol.ClientMessage.*; | ||
import static com.hazelcast.client.impl.protocol.codec.builtin.FixedSizeTypesCodec.*; | ||
|
||
/* | ||
* This file is auto-generated by the Hazelcast Client Protocol Code Generator. | ||
* To change this file, edit the templates or the protocol | ||
* definitions on the https://github.com/hazelcast/hazelcast-client-protocol | ||
* and regenerate it. | ||
*/ | ||
|
||
/** | ||
* Tests if the value associated with the key is expectedValue and if so associates key with | ||
* newValue. | ||
*/ | ||
@SuppressWarnings("unused") | ||
@Generated("f6639933f5e2c5fc315fa4e20d0ca863") | ||
public final class CPMapCompareAndSetCodec { | ||
//hex: 0x230600 | ||
public static final int REQUEST_MESSAGE_TYPE = 2295296; | ||
//hex: 0x230601 | ||
public static final int RESPONSE_MESSAGE_TYPE = 2295297; | ||
private static final int REQUEST_INITIAL_FRAME_SIZE = PARTITION_ID_FIELD_OFFSET + INT_SIZE_IN_BYTES; | ||
private static final int RESPONSE_RESPONSE_FIELD_OFFSET = RESPONSE_BACKUP_ACKS_FIELD_OFFSET + BYTE_SIZE_IN_BYTES; | ||
private static final int RESPONSE_INITIAL_FRAME_SIZE = RESPONSE_RESPONSE_FIELD_OFFSET + BOOLEAN_SIZE_IN_BYTES; | ||
|
||
private CPMapCompareAndSetCodec() { | ||
} | ||
|
||
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"}) | ||
public static class RequestParameters { | ||
|
||
/** | ||
* CP group ID of this CPMap instance. | ||
*/ | ||
public com.hazelcast.cp.internal.RaftGroupId groupId; | ||
|
||
/** | ||
* Name of this CPMap instance. | ||
*/ | ||
public java.lang.String name; | ||
|
||
/** | ||
* Key of the data that is subject of the compare and set. | ||
*/ | ||
public com.hazelcast.internal.serialization.Data key; | ||
|
||
/** | ||
* The expected value associated with key. | ||
*/ | ||
public com.hazelcast.internal.serialization.Data expectedValue; | ||
|
||
/** | ||
* The new value to associate with key. | ||
*/ | ||
public com.hazelcast.internal.serialization.Data newValue; | ||
} | ||
|
||
public static ClientMessage encodeRequest(com.hazelcast.cp.internal.RaftGroupId groupId, java.lang.String name, com.hazelcast.internal.serialization.Data key, com.hazelcast.internal.serialization.Data expectedValue, com.hazelcast.internal.serialization.Data newValue) { | ||
ClientMessage clientMessage = ClientMessage.createForEncode(); | ||
clientMessage.setContainsSerializedDataInRequest(true); | ||
clientMessage.setRetryable(false); | ||
clientMessage.setOperationName("CPMap.CompareAndSet"); | ||
ClientMessage.Frame initialFrame = new ClientMessage.Frame(new byte[REQUEST_INITIAL_FRAME_SIZE], UNFRAGMENTED_MESSAGE); | ||
encodeInt(initialFrame.content, TYPE_FIELD_OFFSET, REQUEST_MESSAGE_TYPE); | ||
encodeInt(initialFrame.content, PARTITION_ID_FIELD_OFFSET, -1); | ||
clientMessage.add(initialFrame); | ||
RaftGroupIdCodec.encode(clientMessage, groupId); | ||
StringCodec.encode(clientMessage, name); | ||
DataCodec.encode(clientMessage, key); | ||
DataCodec.encode(clientMessage, expectedValue); | ||
DataCodec.encode(clientMessage, newValue); | ||
return clientMessage; | ||
} | ||
|
||
public static CPMapCompareAndSetCodec.RequestParameters decodeRequest(ClientMessage clientMessage) { | ||
ClientMessage.ForwardFrameIterator iterator = clientMessage.frameIterator(); | ||
RequestParameters request = new RequestParameters(); | ||
//empty initial frame | ||
iterator.next(); | ||
request.groupId = RaftGroupIdCodec.decode(iterator); | ||
request.name = StringCodec.decode(iterator); | ||
request.key = DataCodec.decode(iterator); | ||
request.expectedValue = DataCodec.decode(iterator); | ||
request.newValue = DataCodec.decode(iterator); | ||
return request; | ||
} | ||
|
||
public static ClientMessage encodeResponse(boolean response) { | ||
ClientMessage clientMessage = ClientMessage.createForEncode(); | ||
ClientMessage.Frame initialFrame = new ClientMessage.Frame(new byte[RESPONSE_INITIAL_FRAME_SIZE], UNFRAGMENTED_MESSAGE); | ||
encodeInt(initialFrame.content, TYPE_FIELD_OFFSET, RESPONSE_MESSAGE_TYPE); | ||
encodeBoolean(initialFrame.content, RESPONSE_RESPONSE_FIELD_OFFSET, response); | ||
clientMessage.add(initialFrame); | ||
|
||
return clientMessage; | ||
} | ||
|
||
/** | ||
* True if key was associated with newValue, otherwise false. | ||
*/ | ||
public static boolean decodeResponse(ClientMessage clientMessage) { | ||
ClientMessage.ForwardFrameIterator iterator = clientMessage.frameIterator(); | ||
ClientMessage.Frame initialFrame = iterator.next(); | ||
return decodeBoolean(initialFrame.content, RESPONSE_RESPONSE_FIELD_OFFSET); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
hazelcast/src/main/java/com/hazelcast/client/impl/protocol/codec/CPMapDeleteCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed 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 com.hazelcast.client.impl.protocol.codec; | ||
|
||
import com.hazelcast.client.impl.protocol.ClientMessage; | ||
import com.hazelcast.client.impl.protocol.Generated; | ||
import com.hazelcast.client.impl.protocol.codec.builtin.*; | ||
import com.hazelcast.client.impl.protocol.codec.custom.*; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import static com.hazelcast.client.impl.protocol.ClientMessage.*; | ||
import static com.hazelcast.client.impl.protocol.codec.builtin.FixedSizeTypesCodec.*; | ||
|
||
/* | ||
* This file is auto-generated by the Hazelcast Client Protocol Code Generator. | ||
* To change this file, edit the templates or the protocol | ||
* definitions on the https://github.com/hazelcast/hazelcast-client-protocol | ||
* and regenerate it. | ||
*/ | ||
|
||
/** | ||
* Deletes the value associated with the key in the specified map. | ||
*/ | ||
@SuppressWarnings("unused") | ||
@Generated("41b2cb5de969f159cc1168a65aecbb2b") | ||
public final class CPMapDeleteCodec { | ||
//hex: 0x230500 | ||
public static final int REQUEST_MESSAGE_TYPE = 2295040; | ||
//hex: 0x230501 | ||
public static final int RESPONSE_MESSAGE_TYPE = 2295041; | ||
private static final int REQUEST_INITIAL_FRAME_SIZE = PARTITION_ID_FIELD_OFFSET + INT_SIZE_IN_BYTES; | ||
private static final int RESPONSE_INITIAL_FRAME_SIZE = RESPONSE_BACKUP_ACKS_FIELD_OFFSET + BYTE_SIZE_IN_BYTES; | ||
|
||
private CPMapDeleteCodec() { | ||
} | ||
|
||
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"}) | ||
public static class RequestParameters { | ||
|
||
/** | ||
* CP group ID of this CPMap instance. | ||
*/ | ||
public com.hazelcast.cp.internal.RaftGroupId groupId; | ||
|
||
/** | ||
* Name of this CPMap instance. | ||
*/ | ||
public java.lang.String name; | ||
|
||
/** | ||
* Key of the value to delete. | ||
*/ | ||
public com.hazelcast.internal.serialization.Data key; | ||
} | ||
|
||
public static ClientMessage encodeRequest(com.hazelcast.cp.internal.RaftGroupId groupId, java.lang.String name, com.hazelcast.internal.serialization.Data key) { | ||
ClientMessage clientMessage = ClientMessage.createForEncode(); | ||
clientMessage.setContainsSerializedDataInRequest(true); | ||
clientMessage.setRetryable(false); | ||
clientMessage.setOperationName("CPMap.Delete"); | ||
ClientMessage.Frame initialFrame = new ClientMessage.Frame(new byte[REQUEST_INITIAL_FRAME_SIZE], UNFRAGMENTED_MESSAGE); | ||
encodeInt(initialFrame.content, TYPE_FIELD_OFFSET, REQUEST_MESSAGE_TYPE); | ||
encodeInt(initialFrame.content, PARTITION_ID_FIELD_OFFSET, -1); | ||
clientMessage.add(initialFrame); | ||
RaftGroupIdCodec.encode(clientMessage, groupId); | ||
StringCodec.encode(clientMessage, name); | ||
DataCodec.encode(clientMessage, key); | ||
return clientMessage; | ||
} | ||
|
||
public static CPMapDeleteCodec.RequestParameters decodeRequest(ClientMessage clientMessage) { | ||
ClientMessage.ForwardFrameIterator iterator = clientMessage.frameIterator(); | ||
RequestParameters request = new RequestParameters(); | ||
//empty initial frame | ||
iterator.next(); | ||
request.groupId = RaftGroupIdCodec.decode(iterator); | ||
request.name = StringCodec.decode(iterator); | ||
request.key = DataCodec.decode(iterator); | ||
return request; | ||
} | ||
|
||
public static ClientMessage encodeResponse(@Nullable com.hazelcast.internal.serialization.Data response) { | ||
ClientMessage clientMessage = ClientMessage.createForEncode(); | ||
ClientMessage.Frame initialFrame = new ClientMessage.Frame(new byte[RESPONSE_INITIAL_FRAME_SIZE], UNFRAGMENTED_MESSAGE); | ||
encodeInt(initialFrame.content, TYPE_FIELD_OFFSET, RESPONSE_MESSAGE_TYPE); | ||
clientMessage.add(initialFrame); | ||
|
||
CodecUtil.encodeNullable(clientMessage, response, DataCodec::encode); | ||
return clientMessage; | ||
} | ||
|
||
/** | ||
* Always null, delete does not return any value. | ||
*/ | ||
public static com.hazelcast.internal.serialization.Data decodeResponse(ClientMessage clientMessage) { | ||
ClientMessage.ForwardFrameIterator iterator = clientMessage.frameIterator(); | ||
//empty initial frame | ||
iterator.next(); | ||
return CodecUtil.decodeNullable(iterator, DataCodec::decode); | ||
} | ||
} |
Oops, something went wrong.