From 2cfc9e664fc7fccf505234910ffed1ea02866f86 Mon Sep 17 00:00:00 2001 From: dilanSachi Date: Fri, 27 Oct 2023 16:25:46 +0530 Subject: [PATCH 01/11] Add basic pub sub support --- ballerina/constants.bal | 44 +++++++++++ ballerina/destination.bal | 24 +++++- ballerina/errors.bal | 13 ++- ballerina/queue_manager.bal | 9 ++- ballerina/types.bal | 12 ++- .../ballerina/lib/ibm.ibmmq/CommonUtils.java | 47 ++++++++++- .../lib/ibm.ibmmq/MQThreadFactory.java | 29 +++++++ .../ballerina/lib/ibm.ibmmq/QueueManager.java | 18 +++++ .../io/ballerina/lib/ibm.ibmmq/Topic.java | 79 +++++++++++++++++++ 9 files changed, 268 insertions(+), 7 deletions(-) create mode 100644 ballerina/constants.bal create mode 100644 native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java create mode 100644 native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java diff --git a/ballerina/constants.bal b/ballerina/constants.bal new file mode 100644 index 0000000..c0df91e --- /dev/null +++ b/ballerina/constants.bal @@ -0,0 +1,44 @@ +// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. 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. + +// Option to indicate whether the topic is being opened for either publication or subscription. +public const OPEN_AS_SUBSCRIPTION = 1; +public const OPEN_AS_PUBLICATION = 2; + +// Options that control the opening of the topic for either publication or subscription. +public const MQOO_ALTERNATE_USER_AUTHORITY = 4096; +public const MQOO_BIND_AS_Q_DEF = 0; +public const MQOO_FAIL_IF_QUIESCING = 8192; +public const MQOO_OUTPUT = 16; +public const MQOO_PASS_ALL_CONTEXT = 512; +public const MQOO_PASS_IDENTITY_CONTEXT = 256; +public const MQOO_SET_ALL_CONTEXT = 2048; +public const MQOO_SET_IDENTITY_CONTEXT = 1024; + +// Options related to the the get message in a topic. +public const MQGMO_WAIT = 1; +public const MQGMO_NO_WAIT = 0; +public const MQGMO_SYNCPOINT = 2; +public const MQGMO_NO_SYNCPOINT = 4; +public const MQGMO_BROWSE_FIRST = 16; +public const MQGMO_BROWSE_NEXT = 32; +public const MQGMO_BROWSE_MSG_UNDER_CURSOR = 2048; +public const MQGMO_MSG_UNDER_CURSOR = 256; +public const MQGMO_LOCK = 512; +public const MQGMO_UNLOCK = 1024; +public const MQGMO_ACCEPT_TRUNCATED_MSG = 64; +public const MQGMO_FAIL_IF_QUIESCING = 8192; +public const MQGMO_CONVERT = 16384; \ No newline at end of file diff --git a/ballerina/destination.bal b/ballerina/destination.bal index b214c94..b87ec53 100644 --- a/ballerina/destination.bal +++ b/ballerina/destination.bal @@ -13,17 +13,37 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. +import ballerina/jballerina.java; public type Destination distinct client object { remote function put(Message message) returns Error?; - remote function get() returns Message|Error?; + remote function get(GetMessageOptions options = {}) returns Message|Error?; }; public type Queue distinct client object { *Destination; }; -public type Topic distinct client object { +public client class Topic { *Destination; + + remote function put(Message message) returns Error? { + return self.externPut(message); + }; + + remote function get(GetMessageOptions options = {}) returns Message|Error { + return self.externGet(options); + }; + + private isolated function externPut(Message message) returns Error? = + @java:Method { + 'class: "io.ballerina.lib.ibm.ibmmq.Topic" + } external; + + private isolated function externGet(GetMessageOptions options) returns Message|Error = + @java:Method { + 'class: "io.ballerina.lib.ibm.ibmmq.Topic" + } external; }; + diff --git a/ballerina/errors.bal b/ballerina/errors.bal index 70643ec..2438af3 100644 --- a/ballerina/errors.bal +++ b/ballerina/errors.bal @@ -14,4 +14,15 @@ // specific language governing permissions and limitations // under the License. -public type Error distinct error; +public type Error distinct error; + +# The error details type for the module. +# +# + reasonCode - The reason code for the error +# + errorCode - The error code for the error +# + completionCode - The completion code for the error +public type ErrorDetails record {| + int reasonCode?; + string errorCode?; + int completionCode?; +|}; diff --git a/ballerina/queue_manager.bal b/ballerina/queue_manager.bal index 2d63fca..64ffecb 100644 --- a/ballerina/queue_manager.bal +++ b/ballerina/queue_manager.bal @@ -31,7 +31,12 @@ public isolated class QueueManager { return error Error("Not implemented"); } - public isolated function accessTopic(string topicName, string topicString, ConnectionOpenOptions options) returns Topic|Error { - return error Error("Not implemented"); + public isolated function accessTopic(string topicName, string topicString, OPEN_AS_OPTION openAs, AccessTopicOptions options) returns Topic|Error { + return self.externAccessTopic(topicName, topicString, openAs, options); } + + private isolated function externAccessTopic(string topicName, string topicString, OPEN_AS_OPTION openAs, AccessTopicOptions options) returns Topic|Error = + @java:Method { + 'class: "io.ballerina.lib.ibm.ibmmq.QueueManager" + } external; } diff --git a/ballerina/types.bal b/ballerina/types.bal index 47e7f4d..4aed9d7 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -14,6 +14,9 @@ // specific language governing permissions and limitations // under the License. +public type GM_OPTIONS MQGMO_WAIT|MQGMO_NO_WAIT|MQGMO_SYNCPOINT|MQGMO_NO_SYNCPOINT|MQGMO_BROWSE_FIRST|MQGMO_BROWSE_MSG_UNDER_CURSOR|MQGMO_MSG_UNDER_CURSOR|MQGMO_LOCK|MQGMO_UNLOCK|MQGMO_ACCEPT_TRUNCATED_MSG|MQGMO_BROWSE_NEXT|MQGMO_ACCEPT_TRUNCATED_MSG|MQGMO_FAIL_IF_QUIESCING|MQGMO_CONVERT; +public type OPEN_AS_OPTION OPEN_AS_SUBSCRIPTION|OPEN_AS_PUBLICATION; + public type QueueManagerConfiguration record {| string name; string host; @@ -24,12 +27,19 @@ public type QueueManagerConfiguration record {| |}; public enum ConnectionOpenOptions { - MQOO_OUTPUT = "MQOO_OUTPUT", + // MQOO_OUTPUT = "MQOO_OUTPUT", MQOO_INPUT_AS_Q_DEF = "MQOO_INPUT_AS_Q_DEF", MQOO_INPUT_EXCLUSIVE = "MQOO_INPUT_EXCLUSIVE", MQOO_INPUT_SHARED = "MQOO_INPUT_SHARED" } +public type AccessTopicOptions MQOO_ALTERNATE_USER_AUTHORITY|MQOO_BIND_AS_Q_DEF|MQOO_FAIL_IF_QUIESCING|MQOO_OUTPUT|MQOO_PASS_ALL_CONTEXT|MQOO_PASS_IDENTITY_CONTEXT|MQOO_SET_ALL_CONTEXT|MQOO_SET_IDENTITY_CONTEXT; + +public type GetMessageOptions record {| + GM_OPTIONS options = MQGMO_NO_SYNCPOINT; + int waitInterval = 0; +|}; + public type Property record {| map descriptor; boolean|byte|byte[]|decimal|float|int|string property; diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java index 6d354df..00564b3 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java @@ -18,23 +18,68 @@ package io.ballerina.lib.ibm.ibmmq; +import com.ibm.mq.MQException; +import com.ibm.mq.MQMessage; import io.ballerina.runtime.api.creators.ErrorCreator; +import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; +import java.io.IOException; import java.util.Optional; +import static io.ballerina.lib.ibm.ibmmq.Constants.IBMMQ_ERROR; +import static io.ballerina.lib.ibm.ibmmq.ModuleUtils.getModule; + /** * {@code CommonUtils} contains the common utility functions for the Ballerina IBM MQ connector. */ public class CommonUtils { + public static final String BTOPIC = "TOPIC"; + public static final String TOPIC_OBJECT = "TOPIC_OBJECT"; + + private static final String ERROR_DETAILS = "ErrorDetails"; + private static final BString ERROR_REASON_CODE = StringUtils.fromString("ErrorDetails"); + private static final BString ERROR_ERROR_CODE = StringUtils.fromString("ErrorDetails"); + private static final BString ERROR_COMPLETION_CODE = StringUtils.fromString("ErrorDetails"); + private static final BString MESSAGE_PAYLOAD = StringUtils.fromString("payload"); + private static final BString MESSAGE_PROPERTIES = StringUtils.fromString("properties"); + + public static MQMessage getMqMessage(BMap bMessage) { + byte[] payload = bMessage.getArrayValue(MESSAGE_PAYLOAD).getBytes(); + BMap properties = (BMap) bMessage.getMapValue(MESSAGE_PROPERTIES); + + MQMessage mqMessage = new MQMessage(); + try { + mqMessage.write(payload); + } catch (IOException e) { + throw createError(IBMMQ_ERROR, + String.format("Error occurred while populating payload: %s", e.getMessage()), e); + } + for (BString key : properties.getKeys()) { + try { + mqMessage.setObjectProperty(key.getValue(), properties.get(key)); + } catch (MQException e) { + throw createError(IBMMQ_ERROR, + String.format("Error occurred while setting message properties: %s", e.getMessage()), e); + } + } + return new MQMessage(); + } + public static BError createError(String errorType, String message, Throwable throwable) { BError cause = ErrorCreator.createError(throwable); + BMap errorDetails = ValueCreator.createRecordValue(getModule(), ERROR_DETAILS); + if (throwable instanceof MQException) { + errorDetails.put(ERROR_REASON_CODE, ((MQException) throwable).getReason()); + errorDetails.put(ERROR_ERROR_CODE, ((MQException) throwable).getErrorCode()); + errorDetails.put(ERROR_COMPLETION_CODE, ((MQException) throwable).getCompCode()); + } return ErrorCreator.createError( - ModuleUtils.getModule(), errorType, StringUtils.fromString(message), cause, null); + ModuleUtils.getModule(), errorType, StringUtils.fromString(message), cause, errorDetails); } public static Optional getOptionalStringProperty(BMap config, BString fieldName) { diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java new file mode 100644 index 0000000..0f2789e --- /dev/null +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 LLC. 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 io.ballerina.lib.ibm.ibmmq; + +public class MQThreadFactory implements java.util.concurrent.ThreadFactory { + @Override + public Thread newThread(Runnable runnable) { + Thread ibmMqClientThread = new Thread(runnable); + ibmMqClientThread.setName("balx-ibm-mq-client-network-thread"); + return ibmMqClientThread; + } + +} diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java index c067909..ce8be07 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java @@ -20,7 +20,10 @@ import com.ibm.mq.MQException; import com.ibm.mq.MQQueueManager; +import com.ibm.mq.MQTopic; import com.ibm.mq.constants.MQConstants; +import io.ballerina.runtime.api.Environment; +import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; @@ -64,6 +67,21 @@ public static Object init(BObject queueManager, BMap configurat return null; } + public static Object externAccessTopic(Environment env, BObject queueManagerObject, BString topicName, + BString topicString, Long openAs, Long options) { + MQQueueManager queueManager = (MQQueueManager) queueManagerObject.getNativeData(NATIVE_QUEUE_MANAGER); + try { + MQTopic mqTopic = queueManager.accessTopic(topicName.getValue(), topicString.getValue(), + openAs.intValue(), options.intValue()); + BObject bTopic = ValueCreator.createObjectValue(ModuleUtils.getModule(), CommonUtils.BTOPIC); + bTopic.addNativeData(CommonUtils.TOPIC_OBJECT, mqTopic); + return bTopic; + } catch (MQException e) { + return createError(IBMMQ_ERROR, + String.format("Error occurred while accessing topic: %s", e.getMessage()), e); + } + } + private static Hashtable getConnectionProperties(BMap configurations) { Hashtable properties = new Hashtable<>(); String host = configurations.getStringValue(HOST).getValue(); diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java new file mode 100644 index 0000000..a1380c2 --- /dev/null +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 LLC. 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 io.ballerina.lib.ibm.ibmmq; + +import com.ibm.mq.MQGetMessageOptions; +import com.ibm.mq.MQMessage; +import com.ibm.mq.MQTopic; +import io.ballerina.runtime.api.Environment; +import io.ballerina.runtime.api.Future; +import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BObject; +import io.ballerina.runtime.api.values.BString; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class Topic { + private static final ExecutorService topicExecutorService = Executors.newCachedThreadPool(new MQThreadFactory()); + + private static final BString WAIT_INTERVAL = StringUtils.fromString("waitInterval"); + private static final BString OPTIONS = StringUtils.fromString("options"); + + public static Object externPut(Environment environment, BObject topicObject, BMap message) { + MQTopic topic = (MQTopic) topicObject.getNativeData(CommonUtils.TOPIC_OBJECT); + MQMessage mqMessage = CommonUtils.getMqMessage(message); + Future future = environment.markAsync(); + topicExecutorService.execute(() -> { + try { + topic.put(mqMessage); + future.complete(null); + } catch (Exception e) { + future.complete(e); + } + }); + return null; + } + + public static Object externGet(Environment environment, BObject topicObject, BMap options) { + MQTopic topic = (MQTopic) topicObject.getNativeData(CommonUtils.TOPIC_OBJECT); + MQGetMessageOptions getMessageOptions = getGetMessageOptions(options); + Future future = environment.markAsync(); + topicExecutorService.execute(() -> { + try { + MQMessage message = new MQMessage(); + topic.get(message, getMessageOptions); + future.complete(message); + } catch (Exception e) { + future.complete(e); + } + }); + return null; + } + + private static MQGetMessageOptions getGetMessageOptions(BMap bOptions) { + int waitInterval = bOptions.getIntValue(WAIT_INTERVAL).intValue(); + int options = bOptions.getIntValue(OPTIONS).intValue(); + MQGetMessageOptions getMessageOptions = new MQGetMessageOptions(); + getMessageOptions.waitInterval = waitInterval; + getMessageOptions.options = options; + return getMessageOptions; + } +} From f52cdd31144b7a76f8cdb7c9f317b73879a9842a Mon Sep 17 00:00:00 2001 From: dilanSachi Date: Fri, 27 Oct 2023 16:26:31 +0530 Subject: [PATCH 02/11] Add newline --- ballerina/constants.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/constants.bal b/ballerina/constants.bal index c0df91e..eeb706f 100644 --- a/ballerina/constants.bal +++ b/ballerina/constants.bal @@ -41,4 +41,4 @@ public const MQGMO_LOCK = 512; public const MQGMO_UNLOCK = 1024; public const MQGMO_ACCEPT_TRUNCATED_MSG = 64; public const MQGMO_FAIL_IF_QUIESCING = 8192; -public const MQGMO_CONVERT = 16384; \ No newline at end of file +public const MQGMO_CONVERT = 16384; From fd4999fbbc1f20ee5eb34772a812489c20ee3a32 Mon Sep 17 00:00:00 2001 From: dilanSachi Date: Fri, 27 Oct 2023 16:39:17 +0530 Subject: [PATCH 03/11] Add bmessage creator util --- .../ballerina/lib/ibm.ibmmq/CommonUtils.java | 26 +++++++++++++++++-- .../io/ballerina/lib/ibm.ibmmq/Topic.java | 4 +-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java index 00564b3..acb23e2 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java @@ -28,6 +28,8 @@ import io.ballerina.runtime.api.values.BString; import java.io.IOException; +import java.util.Collections; +import java.util.Enumeration; import java.util.Optional; import static io.ballerina.lib.ibm.ibmmq.Constants.IBMMQ_ERROR; @@ -47,8 +49,9 @@ public class CommonUtils { private static final BString ERROR_COMPLETION_CODE = StringUtils.fromString("ErrorDetails"); private static final BString MESSAGE_PAYLOAD = StringUtils.fromString("payload"); private static final BString MESSAGE_PROPERTIES = StringUtils.fromString("properties"); + private static final String BMESSAGE_NAME = "Message"; - public static MQMessage getMqMessage(BMap bMessage) { + public static MQMessage getMqMessageFromMessage(BMap bMessage) { byte[] payload = bMessage.getArrayValue(MESSAGE_PAYLOAD).getBytes(); BMap properties = (BMap) bMessage.getMapValue(MESSAGE_PROPERTIES); @@ -67,7 +70,26 @@ public static MQMessage getMqMessage(BMap bMessage) { String.format("Error occurred while setting message properties: %s", e.getMessage()), e); } } - return new MQMessage(); + return mqMessage; + } + + public static BMap getBMessageFromMQMessage(MQMessage mqMessage) { + BMap bMessage = ValueCreator.createRecordValue(getModule(), BMESSAGE_NAME); + try { + byte[] payload = new byte[mqMessage.getDataLength()]; + mqMessage.readFully(payload); + bMessage.put(MESSAGE_PAYLOAD, payload); + BMap properties = ValueCreator.createRecordValue(getModule(), MESSAGE_PROPERTIES.getValue()); + Enumeration propertyNames = mqMessage.getPropertyNames("%"); + for (String propertyName : Collections.list(propertyNames)) { + properties.put(StringUtils.fromString(propertyName), mqMessage.getObjectProperty(propertyName)); + } + bMessage.put(MESSAGE_PROPERTIES, properties); + return bMessage; + } catch (MQException | IOException e) { + throw createError(IBMMQ_ERROR, + String.format("Error occurred while reading the message: %s", e.getMessage()), e); + } } public static BError createError(String errorType, String message, Throwable throwable) { diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java index a1380c2..5fcfcff 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java @@ -39,7 +39,7 @@ public class Topic { public static Object externPut(Environment environment, BObject topicObject, BMap message) { MQTopic topic = (MQTopic) topicObject.getNativeData(CommonUtils.TOPIC_OBJECT); - MQMessage mqMessage = CommonUtils.getMqMessage(message); + MQMessage mqMessage = CommonUtils.getMqMessageFromMessage(message); Future future = environment.markAsync(); topicExecutorService.execute(() -> { try { @@ -60,7 +60,7 @@ public static Object externGet(Environment environment, BObject topicObject, BMa try { MQMessage message = new MQMessage(); topic.get(message, getMessageOptions); - future.complete(message); + future.complete(CommonUtils.getBMessageFromMQMessage(message)); } catch (Exception e) { future.complete(e); } From 970f23591546d20236444487ebbc6138e7320a21 Mon Sep 17 00:00:00 2001 From: dilanSachi Date: Fri, 27 Oct 2023 16:44:58 +0530 Subject: [PATCH 04/11] Fix review comments --- ballerina/destination.bal | 14 ++++---------- ballerina/types.bal | 1 + .../io/ballerina/lib/ibm.ibmmq/CommonUtils.java | 3 ++- .../ballerina/lib/ibm.ibmmq/MQThreadFactory.java | 13 +++++++++++-- .../java/io/ballerina/lib/ibm.ibmmq/Topic.java | 3 ++- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ballerina/destination.bal b/ballerina/destination.bal index b87ec53..72710f9 100644 --- a/ballerina/destination.bal +++ b/ballerina/destination.bal @@ -28,21 +28,15 @@ public type Queue distinct client object { public client class Topic { *Destination; - remote function put(Message message) returns Error? { - return self.externPut(message); - }; - - remote function get(GetMessageOptions options = {}) returns Message|Error { - return self.externGet(options); - }; - - private isolated function externPut(Message message) returns Error? = + remote function put(Message message) returns Error? = @java:Method { + name: "externPut", 'class: "io.ballerina.lib.ibm.ibmmq.Topic" } external; - private isolated function externGet(GetMessageOptions options) returns Message|Error = + remote function get(GetMessageOptions options = {}) returns Message|Error = @java:Method { + name: "externGet", 'class: "io.ballerina.lib.ibm.ibmmq.Topic" } external; }; diff --git a/ballerina/types.bal b/ballerina/types.bal index 4aed9d7..226d647 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -15,6 +15,7 @@ // under the License. public type GM_OPTIONS MQGMO_WAIT|MQGMO_NO_WAIT|MQGMO_SYNCPOINT|MQGMO_NO_SYNCPOINT|MQGMO_BROWSE_FIRST|MQGMO_BROWSE_MSG_UNDER_CURSOR|MQGMO_MSG_UNDER_CURSOR|MQGMO_LOCK|MQGMO_UNLOCK|MQGMO_ACCEPT_TRUNCATED_MSG|MQGMO_BROWSE_NEXT|MQGMO_ACCEPT_TRUNCATED_MSG|MQGMO_FAIL_IF_QUIESCING|MQGMO_CONVERT; + public type OPEN_AS_OPTION OPEN_AS_SUBSCRIPTION|OPEN_AS_PUBLICATION; public type QueueManagerConfiguration record {| diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java index acb23e2..42b78bb 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java @@ -79,7 +79,8 @@ public static BMap getBMessageFromMQMessage(MQMessage mqMessage byte[] payload = new byte[mqMessage.getDataLength()]; mqMessage.readFully(payload); bMessage.put(MESSAGE_PAYLOAD, payload); - BMap properties = ValueCreator.createRecordValue(getModule(), MESSAGE_PROPERTIES.getValue()); + BMap properties = ValueCreator.createRecordValue(getModule(), + MESSAGE_PROPERTIES.getValue()); Enumeration propertyNames = mqMessage.getPropertyNames("%"); for (String propertyName : Collections.list(propertyNames)) { properties.put(StringUtils.fromString(propertyName), mqMessage.getObjectProperty(propertyName)); diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java index 0f2789e..ab95b27 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java @@ -18,11 +18,20 @@ package io.ballerina.lib.ibm.ibmmq; -public class MQThreadFactory implements java.util.concurrent.ThreadFactory { +import java.util.concurrent.ThreadFactory; + +public class MQThreadFactory implements ThreadFactory { + + private final String threadGroupName; + + public MQThreadFactory(String threadGroupName) { + this.threadGroupName = threadGroupName; + } + @Override public Thread newThread(Runnable runnable) { Thread ibmMqClientThread = new Thread(runnable); - ibmMqClientThread.setName("balx-ibm-mq-client-network-thread"); + ibmMqClientThread.setName(threadGroupName); return ibmMqClientThread; } diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java index 5fcfcff..daa417b 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java @@ -32,7 +32,8 @@ import java.util.concurrent.Executors; public class Topic { - private static final ExecutorService topicExecutorService = Executors.newCachedThreadPool(new MQThreadFactory()); + private static final ExecutorService topicExecutorService = + Executors.newCachedThreadPool(new MQThreadFactory("balx-ibm-mq-client-network-thread")); private static final BString WAIT_INTERVAL = StringUtils.fromString("waitInterval"); private static final BString OPTIONS = StringUtils.fromString("options"); From b3238a39bd30e0d05af754a304d8c49d80eafb17 Mon Sep 17 00:00:00 2001 From: dilanSachi Date: Fri, 27 Oct 2023 18:20:18 +0530 Subject: [PATCH 05/11] Add message property handling logic --- ballerina/types.bal | 4 +- .../ballerina/lib/ibm.ibmmq/CommonUtils.java | 130 +++++++++++++++--- .../io/ballerina/lib/ibm.ibmmq/Topic.java | 2 +- 3 files changed, 112 insertions(+), 24 deletions(-) diff --git a/ballerina/types.bal b/ballerina/types.bal index 226d647..8bbc6f1 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -42,8 +42,8 @@ public type GetMessageOptions record {| |}; public type Property record {| - map descriptor; - boolean|byte|byte[]|decimal|float|int|string property; + map descriptor?; + boolean|byte|byte[]|decimal|float|int|string value; |}; public type Message record {| diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java index 42b78bb..096fd7a 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java @@ -20,7 +20,9 @@ import com.ibm.mq.MQException; import com.ibm.mq.MQMessage; +import com.ibm.mq.MQPropertyDescriptor; import io.ballerina.runtime.api.creators.ErrorCreator; +import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BError; @@ -44,17 +46,27 @@ public class CommonUtils { public static final String TOPIC_OBJECT = "TOPIC_OBJECT"; private static final String ERROR_DETAILS = "ErrorDetails"; - private static final BString ERROR_REASON_CODE = StringUtils.fromString("ErrorDetails"); - private static final BString ERROR_ERROR_CODE = StringUtils.fromString("ErrorDetails"); - private static final BString ERROR_COMPLETION_CODE = StringUtils.fromString("ErrorDetails"); + private static final BString ERROR_REASON_CODE = StringUtils.fromString("reasonCode"); + private static final BString ERROR_ERROR_CODE = StringUtils.fromString("errorCode"); + private static final BString ERROR_COMPLETION_CODE = StringUtils.fromString("completionCode"); private static final BString MESSAGE_PAYLOAD = StringUtils.fromString("payload"); private static final BString MESSAGE_PROPERTIES = StringUtils.fromString("properties"); + private static final BString MESSAGE_PROPERTY = StringUtils.fromString("property"); + private static final String BPROPERTY = "Property"; private static final String BMESSAGE_NAME = "Message"; + private static final BString PD_VERSION = StringUtils.fromString("version"); + private static final BString PD_COPY_OPTIONS = StringUtils.fromString("copyOptions"); + private static final BString PD_OPTIONS = StringUtils.fromString("options"); + private static final BString PD_SUPPORT = StringUtils.fromString("support"); + private static final BString PD_CONTEXT = StringUtils.fromString("context"); + private static final BString PROPERTY_VALUE = StringUtils.fromString("value"); + private static final BString PROPERTY_DESCRIPTOR = StringUtils.fromString("descriptor"); - public static MQMessage getMqMessageFromMessage(BMap bMessage) { - byte[] payload = bMessage.getArrayValue(MESSAGE_PAYLOAD).getBytes(); - BMap properties = (BMap) bMessage.getMapValue(MESSAGE_PROPERTIES); + private static final MQPropertyDescriptor defaultPropertyDescriptor = new MQPropertyDescriptor(); + + public static MQMessage getMqMessageFromBMessage(BMap bMessage) { + byte[] payload = bMessage.getArrayValue(MESSAGE_PAYLOAD).getBytes(); MQMessage mqMessage = new MQMessage(); try { mqMessage.write(payload); @@ -62,14 +74,8 @@ public static MQMessage getMqMessageFromMessage(BMap bMessage) throw createError(IBMMQ_ERROR, String.format("Error occurred while populating payload: %s", e.getMessage()), e); } - for (BString key : properties.getKeys()) { - try { - mqMessage.setObjectProperty(key.getValue(), properties.get(key)); - } catch (MQException e) { - throw createError(IBMMQ_ERROR, - String.format("Error occurred while setting message properties: %s", e.getMessage()), e); - } - } + BMap properties = (BMap) bMessage.getMapValue(MESSAGE_PROPERTIES); + populateMQProperties(properties, mqMessage); return mqMessage; } @@ -79,13 +85,7 @@ public static BMap getBMessageFromMQMessage(MQMessage mqMessage byte[] payload = new byte[mqMessage.getDataLength()]; mqMessage.readFully(payload); bMessage.put(MESSAGE_PAYLOAD, payload); - BMap properties = ValueCreator.createRecordValue(getModule(), - MESSAGE_PROPERTIES.getValue()); - Enumeration propertyNames = mqMessage.getPropertyNames("%"); - for (String propertyName : Collections.list(propertyNames)) { - properties.put(StringUtils.fromString(propertyName), mqMessage.getObjectProperty(propertyName)); - } - bMessage.put(MESSAGE_PROPERTIES, properties); + bMessage.put(MESSAGE_PROPERTY, getBProperties(mqMessage)); return bMessage; } catch (MQException | IOException e) { throw createError(IBMMQ_ERROR, @@ -93,6 +93,94 @@ public static BMap getBMessageFromMQMessage(MQMessage mqMessage } } + private static BMap getBProperties(MQMessage mqMessage) throws MQException { + BMap properties = ValueCreator.createMapValue(TypeCreator + .createMapType(TypeCreator.createRecordType(BPROPERTY, getModule(), 0, false, 0))); + Enumeration propertyNames = mqMessage.getPropertyNames("%"); + for (String propertyName : Collections.list(propertyNames)) { + BMap property = ValueCreator.createRecordValue(getModule(), BPROPERTY); + MQPropertyDescriptor propertyDescriptor = new MQPropertyDescriptor(); + Object propertyObject = mqMessage.getObjectProperty(propertyName, propertyDescriptor); + if (propertyObject instanceof Integer) { + property.put(PROPERTY_VALUE, ((Integer) propertyObject).longValue()); + } else if (propertyObject instanceof String) { + property.put(PROPERTY_VALUE, StringUtils.fromString((String) propertyObject)); + } else { + property.put(PROPERTY_VALUE, propertyObject); + } + property.put(PROPERTY_DESCRIPTOR, + populateDescriptorFromMQPropertyDescriptor(propertyDescriptor)); + properties.put(StringUtils.fromString(propertyName), property); + } + return properties; + } + + private static void populateMQProperties(BMap properties, MQMessage mqMessage) { + for (BString key : properties.getKeys()) { + try { + handlePropertyValue(properties, mqMessage, key); + } catch (MQException e) { + throw createError(IBMMQ_ERROR, + String.format("Error occurred while setting message properties: %s", e.getMessage()), e); + } + } + } + + private static void handlePropertyValue(BMap properties, MQMessage mqMessage, BString key) + throws MQException { + BMap property = (BMap) properties.getMapValue(key); + MQPropertyDescriptor propertyDescriptor = defaultPropertyDescriptor; + if (property.containsKey(PROPERTY_DESCRIPTOR)) { + propertyDescriptor = getMQPropertyDescriptor(properties.getMapValue(PROPERTY_DESCRIPTOR)); + } + Object value = property.get(PROPERTY_VALUE); + if (value instanceof Long) { + mqMessage.setIntProperty(key.getValue(), propertyDescriptor, ((Long) properties.get(key)).intValue()); + } else if (value instanceof Boolean) { + mqMessage.setBooleanProperty(key.getValue(), propertyDescriptor, ((Boolean) properties.get(key))); + } else if (value instanceof Byte) { + mqMessage.setByteProperty(key.getValue(), propertyDescriptor, (Byte) properties.get(key)); + } else if (value instanceof byte[]) { + mqMessage.setBytesProperty(key.getValue(), propertyDescriptor, ((byte[]) properties.get(key))); + } else if (value instanceof Float) { + mqMessage.setFloatProperty(key.getValue(), propertyDescriptor, (Float) properties.get(key)); + } else if (value instanceof Double) { + mqMessage.setDoubleProperty(key.getValue(), propertyDescriptor, (Double) properties.get(key)); + } else if (value instanceof BString) { + mqMessage.setStringProperty(key.getValue(), propertyDescriptor, ((BString) properties.get(key)).getValue()); + } + } + + private static MQPropertyDescriptor getMQPropertyDescriptor(BMap descriptor) { + MQPropertyDescriptor propertyDescriptor = new MQPropertyDescriptor(); + if (descriptor.containsKey(PD_VERSION)) { + propertyDescriptor.version = ((Long) descriptor.get(PD_VERSION)).intValue(); + } + if (descriptor.containsKey(PD_COPY_OPTIONS)) { + propertyDescriptor.copyOptions = ((Long) descriptor.get(PD_COPY_OPTIONS)).intValue(); + } + if (descriptor.containsKey(PD_OPTIONS)) { + propertyDescriptor.options = ((Long) descriptor.get(PD_OPTIONS)).intValue(); + } + if (descriptor.containsKey(PD_SUPPORT)) { + propertyDescriptor.support = ((Long) descriptor.get(PD_SUPPORT)).intValue(); + } + if (descriptor.containsKey(PD_CONTEXT)) { + propertyDescriptor. context = ((Long) descriptor.get(PD_CONTEXT)).intValue(); + } + return propertyDescriptor; + } + + private static BMap populateDescriptorFromMQPropertyDescriptor(MQPropertyDescriptor propertyDescriptor) { + BMap descriptor = ValueCreator.createMapValue(); + descriptor.put(PD_VERSION, propertyDescriptor.version); + descriptor.put(PD_COPY_OPTIONS, propertyDescriptor.copyOptions); + descriptor.put(PD_OPTIONS, propertyDescriptor.options); + descriptor.put(PD_SUPPORT, propertyDescriptor.support); + descriptor.put(PD_CONTEXT, propertyDescriptor.context); + return descriptor; + } + public static BError createError(String errorType, String message, Throwable throwable) { BError cause = ErrorCreator.createError(throwable); BMap errorDetails = ValueCreator.createRecordValue(getModule(), ERROR_DETAILS); diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java index daa417b..fe7fa48 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java @@ -40,7 +40,7 @@ public class Topic { public static Object externPut(Environment environment, BObject topicObject, BMap message) { MQTopic topic = (MQTopic) topicObject.getNativeData(CommonUtils.TOPIC_OBJECT); - MQMessage mqMessage = CommonUtils.getMqMessageFromMessage(message); + MQMessage mqMessage = CommonUtils.getMqMessageFromBMessage(message); Future future = environment.markAsync(); topicExecutorService.execute(() -> { try { From 213acaecfb740d8ded9a642d6714be0e537e98c8 Mon Sep 17 00:00:00 2001 From: dilanSachi Date: Fri, 27 Oct 2023 18:28:09 +0530 Subject: [PATCH 06/11] Restructure project --- ballerina/init.bal | 2 +- .../main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java | 6 ++++-- native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java | 3 ++- .../io/ballerina/lib/ibm.ibmmq/{ => utils}/CommonUtils.java | 6 +++--- .../io/ballerina/lib/ibm.ibmmq/{ => utils}/ModuleUtils.java | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) rename native/src/main/java/io/ballerina/lib/ibm.ibmmq/{ => utils}/CommonUtils.java (98%) rename native/src/main/java/io/ballerina/lib/ibm.ibmmq/{ => utils}/ModuleUtils.java (96%) diff --git a/ballerina/init.bal b/ballerina/init.bal index 4741e40..c3f43f8 100644 --- a/ballerina/init.bal +++ b/ballerina/init.bal @@ -21,5 +21,5 @@ isolated function init() { } isolated function setModule() = @java:Method { - 'class: "io.ballerina.lib.ibm.ibmmq.ModuleUtils" + 'class: "io.ballerina.lib.ibm.ibmmq.utils.ModuleUtils" } external; diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java index ce8be07..5f9bb43 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java @@ -22,6 +22,8 @@ import com.ibm.mq.MQQueueManager; import com.ibm.mq.MQTopic; import com.ibm.mq.constants.MQConstants; +import io.ballerina.lib.ibm.ibmmq.utils.CommonUtils; +import io.ballerina.lib.ibm.ibmmq.utils.ModuleUtils; import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; @@ -31,8 +33,8 @@ import java.util.Hashtable; -import static io.ballerina.lib.ibm.ibmmq.CommonUtils.createError; -import static io.ballerina.lib.ibm.ibmmq.CommonUtils.getOptionalStringProperty; +import static io.ballerina.lib.ibm.ibmmq.utils.CommonUtils.createError; +import static io.ballerina.lib.ibm.ibmmq.utils.CommonUtils.getOptionalStringProperty; import static io.ballerina.lib.ibm.ibmmq.Constants.IBMMQ_ERROR; import static io.ballerina.lib.ibm.ibmmq.Constants.NATIVE_QUEUE_MANAGER; diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java index fe7fa48..6c860c6 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java @@ -21,6 +21,7 @@ import com.ibm.mq.MQGetMessageOptions; import com.ibm.mq.MQMessage; import com.ibm.mq.MQTopic; +import io.ballerina.lib.ibm.ibmmq.utils.CommonUtils; import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.utils.StringUtils; @@ -33,7 +34,7 @@ public class Topic { private static final ExecutorService topicExecutorService = - Executors.newCachedThreadPool(new MQThreadFactory("balx-ibm-mq-client-network-thread")); + Executors.newCachedThreadPool(new MQThreadFactory("balx-ibmmq-topic-client-network-thread")); private static final BString WAIT_INTERVAL = StringUtils.fromString("waitInterval"); private static final BString OPTIONS = StringUtils.fromString("options"); diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/CommonUtils.java similarity index 98% rename from native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java rename to native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/CommonUtils.java index 096fd7a..3eb98eb 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/CommonUtils.java @@ -16,7 +16,7 @@ * under the License. */ -package io.ballerina.lib.ibm.ibmmq; +package io.ballerina.lib.ibm.ibmmq.utils; import com.ibm.mq.MQException; import com.ibm.mq.MQMessage; @@ -35,7 +35,7 @@ import java.util.Optional; import static io.ballerina.lib.ibm.ibmmq.Constants.IBMMQ_ERROR; -import static io.ballerina.lib.ibm.ibmmq.ModuleUtils.getModule; +import static io.ballerina.lib.ibm.ibmmq.utils.ModuleUtils.getModule; /** * {@code CommonUtils} contains the common utility functions for the Ballerina IBM MQ connector. @@ -166,7 +166,7 @@ private static MQPropertyDescriptor getMQPropertyDescriptor(BMap descriptor) { propertyDescriptor.support = ((Long) descriptor.get(PD_SUPPORT)).intValue(); } if (descriptor.containsKey(PD_CONTEXT)) { - propertyDescriptor. context = ((Long) descriptor.get(PD_CONTEXT)).intValue(); + propertyDescriptor.context = ((Long) descriptor.get(PD_CONTEXT)).intValue(); } return propertyDescriptor; } diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/ModuleUtils.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/ModuleUtils.java similarity index 96% rename from native/src/main/java/io/ballerina/lib/ibm.ibmmq/ModuleUtils.java rename to native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/ModuleUtils.java index 80462df..c1507f1 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/ModuleUtils.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/ModuleUtils.java @@ -16,7 +16,7 @@ * under the License. */ -package io.ballerina.lib.ibm.ibmmq; +package io.ballerina.lib.ibm.ibmmq.utils; import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Module; From 6b2e6dcab681de782861e6259b97841f54cb7f46 Mon Sep 17 00:00:00 2001 From: dilanSachi Date: Fri, 27 Oct 2023 19:54:01 +0530 Subject: [PATCH 07/11] Apply suggestions from review --- ballerina/destination.bal | 2 -- ballerina/init.bal | 2 +- ballerina/queue_manager.bal | 6 +----- .../lib/ibm.ibmmq/{utils => }/CommonUtils.java | 12 ++++++------ .../lib/ibm.ibmmq/{utils => }/ModuleUtils.java | 2 +- .../io/ballerina/lib/ibm.ibmmq/QueueManager.java | 6 ++---- .../main/java/io/ballerina/lib/ibm.ibmmq/Topic.java | 5 ++--- 7 files changed, 13 insertions(+), 22 deletions(-) rename native/src/main/java/io/ballerina/lib/ibm.ibmmq/{utils => }/CommonUtils.java (95%) rename native/src/main/java/io/ballerina/lib/ibm.ibmmq/{utils => }/ModuleUtils.java (96%) diff --git a/ballerina/destination.bal b/ballerina/destination.bal index 72710f9..df202ce 100644 --- a/ballerina/destination.bal +++ b/ballerina/destination.bal @@ -30,13 +30,11 @@ public client class Topic { remote function put(Message message) returns Error? = @java:Method { - name: "externPut", 'class: "io.ballerina.lib.ibm.ibmmq.Topic" } external; remote function get(GetMessageOptions options = {}) returns Message|Error = @java:Method { - name: "externGet", 'class: "io.ballerina.lib.ibm.ibmmq.Topic" } external; }; diff --git a/ballerina/init.bal b/ballerina/init.bal index c3f43f8..4741e40 100644 --- a/ballerina/init.bal +++ b/ballerina/init.bal @@ -21,5 +21,5 @@ isolated function init() { } isolated function setModule() = @java:Method { - 'class: "io.ballerina.lib.ibm.ibmmq.utils.ModuleUtils" + 'class: "io.ballerina.lib.ibm.ibmmq.ModuleUtils" } external; diff --git a/ballerina/queue_manager.bal b/ballerina/queue_manager.bal index 64ffecb..adab5e2 100644 --- a/ballerina/queue_manager.bal +++ b/ballerina/queue_manager.bal @@ -31,11 +31,7 @@ public isolated class QueueManager { return error Error("Not implemented"); } - public isolated function accessTopic(string topicName, string topicString, OPEN_AS_OPTION openAs, AccessTopicOptions options) returns Topic|Error { - return self.externAccessTopic(topicName, topicString, openAs, options); - } - - private isolated function externAccessTopic(string topicName, string topicString, OPEN_AS_OPTION openAs, AccessTopicOptions options) returns Topic|Error = + public isolated function accessTopic(string topicName, string topicString, OPEN_AS_OPTION openAs, AccessTopicOptions options) returns Topic|Error = @java:Method { 'class: "io.ballerina.lib.ibm.ibmmq.QueueManager" } external; diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/CommonUtils.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java similarity index 95% rename from native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/CommonUtils.java rename to native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java index 3eb98eb..679aee8 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/CommonUtils.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java @@ -16,7 +16,7 @@ * under the License. */ -package io.ballerina.lib.ibm.ibmmq.utils; +package io.ballerina.lib.ibm.ibmmq; import com.ibm.mq.MQException; import com.ibm.mq.MQMessage; @@ -35,7 +35,7 @@ import java.util.Optional; import static io.ballerina.lib.ibm.ibmmq.Constants.IBMMQ_ERROR; -import static io.ballerina.lib.ibm.ibmmq.utils.ModuleUtils.getModule; +import static io.ballerina.lib.ibm.ibmmq.ModuleUtils.getModule; /** * {@code CommonUtils} contains the common utility functions for the Ballerina IBM MQ connector. @@ -184,10 +184,10 @@ private static BMap populateDescriptorFromMQPropertyDescriptor(MQPropertyDescrip public static BError createError(String errorType, String message, Throwable throwable) { BError cause = ErrorCreator.createError(throwable); BMap errorDetails = ValueCreator.createRecordValue(getModule(), ERROR_DETAILS); - if (throwable instanceof MQException) { - errorDetails.put(ERROR_REASON_CODE, ((MQException) throwable).getReason()); - errorDetails.put(ERROR_ERROR_CODE, ((MQException) throwable).getErrorCode()); - errorDetails.put(ERROR_COMPLETION_CODE, ((MQException) throwable).getCompCode()); + if (throwable instanceof MQException exception) { + errorDetails.put(ERROR_REASON_CODE, exception.getReason()); + errorDetails.put(ERROR_ERROR_CODE, exception.getErrorCode()); + errorDetails.put(ERROR_COMPLETION_CODE, exception.getCompCode()); } return ErrorCreator.createError( ModuleUtils.getModule(), errorType, StringUtils.fromString(message), cause, errorDetails); diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/ModuleUtils.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/ModuleUtils.java similarity index 96% rename from native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/ModuleUtils.java rename to native/src/main/java/io/ballerina/lib/ibm.ibmmq/ModuleUtils.java index c1507f1..80462df 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/utils/ModuleUtils.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/ModuleUtils.java @@ -16,7 +16,7 @@ * under the License. */ -package io.ballerina.lib.ibm.ibmmq.utils; +package io.ballerina.lib.ibm.ibmmq; import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Module; diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java index 5f9bb43..ce8be07 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java @@ -22,8 +22,6 @@ import com.ibm.mq.MQQueueManager; import com.ibm.mq.MQTopic; import com.ibm.mq.constants.MQConstants; -import io.ballerina.lib.ibm.ibmmq.utils.CommonUtils; -import io.ballerina.lib.ibm.ibmmq.utils.ModuleUtils; import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; @@ -33,8 +31,8 @@ import java.util.Hashtable; -import static io.ballerina.lib.ibm.ibmmq.utils.CommonUtils.createError; -import static io.ballerina.lib.ibm.ibmmq.utils.CommonUtils.getOptionalStringProperty; +import static io.ballerina.lib.ibm.ibmmq.CommonUtils.createError; +import static io.ballerina.lib.ibm.ibmmq.CommonUtils.getOptionalStringProperty; import static io.ballerina.lib.ibm.ibmmq.Constants.IBMMQ_ERROR; import static io.ballerina.lib.ibm.ibmmq.Constants.NATIVE_QUEUE_MANAGER; diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java index 6c860c6..decba79 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java @@ -21,7 +21,6 @@ import com.ibm.mq.MQGetMessageOptions; import com.ibm.mq.MQMessage; import com.ibm.mq.MQTopic; -import io.ballerina.lib.ibm.ibmmq.utils.CommonUtils; import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.utils.StringUtils; @@ -39,7 +38,7 @@ public class Topic { private static final BString WAIT_INTERVAL = StringUtils.fromString("waitInterval"); private static final BString OPTIONS = StringUtils.fromString("options"); - public static Object externPut(Environment environment, BObject topicObject, BMap message) { + public static Object put(Environment environment, BObject topicObject, BMap message) { MQTopic topic = (MQTopic) topicObject.getNativeData(CommonUtils.TOPIC_OBJECT); MQMessage mqMessage = CommonUtils.getMqMessageFromBMessage(message); Future future = environment.markAsync(); @@ -54,7 +53,7 @@ public static Object externPut(Environment environment, BObject topicObject, BMa return null; } - public static Object externGet(Environment environment, BObject topicObject, BMap options) { + public static Object get(Environment environment, BObject topicObject, BMap options) { MQTopic topic = (MQTopic) topicObject.getNativeData(CommonUtils.TOPIC_OBJECT); MQGetMessageOptions getMessageOptions = getGetMessageOptions(options); Future future = environment.markAsync(); From c2e5002fdf81683fa73e2542bd09e7034e39c934 Mon Sep 17 00:00:00 2001 From: dilanSachi Date: Fri, 27 Oct 2023 20:06:20 +0530 Subject: [PATCH 08/11] Update method name --- .../src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java index ce8be07..b468651 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java @@ -67,7 +67,7 @@ public static Object init(BObject queueManager, BMap configurat return null; } - public static Object externAccessTopic(Environment env, BObject queueManagerObject, BString topicName, + public static Object accessTopic(Environment env, BObject queueManagerObject, BString topicName, BString topicString, Long openAs, Long options) { MQQueueManager queueManager = (MQQueueManager) queueManagerObject.getNativeData(NATIVE_QUEUE_MANAGER); try { From 11b8d83fc814489b1bf22704596a4eae9ce7a6c6 Mon Sep 17 00:00:00 2001 From: Dilan Sachintha Nayanajith Date: Fri, 27 Oct 2023 20:16:06 +0530 Subject: [PATCH 09/11] Update ballerina/destination.bal Co-authored-by: Ayesh Almeida <77491511+ayeshLK@users.noreply.github.com> --- ballerina/destination.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/destination.bal b/ballerina/destination.bal index df202ce..7c77369 100644 --- a/ballerina/destination.bal +++ b/ballerina/destination.bal @@ -18,7 +18,7 @@ import ballerina/jballerina.java; public type Destination distinct client object { remote function put(Message message) returns Error?; - remote function get(GetMessageOptions options = {}) returns Message|Error?; + remote function get(*GetMessageOptions options) returns Message|Error?; }; public type Queue distinct client object { From 3de7cef096894fb9021fa8f29b597a07718699b9 Mon Sep 17 00:00:00 2001 From: dilanSachi Date: Fri, 27 Oct 2023 20:25:43 +0530 Subject: [PATCH 10/11] Update property map type --- ballerina/destination.bal | 2 +- ballerina/types.bal | 4 ++-- .../main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ballerina/destination.bal b/ballerina/destination.bal index 7c77369..25ca342 100644 --- a/ballerina/destination.bal +++ b/ballerina/destination.bal @@ -33,7 +33,7 @@ public client class Topic { 'class: "io.ballerina.lib.ibm.ibmmq.Topic" } external; - remote function get(GetMessageOptions options = {}) returns Message|Error = + remote function get(*GetMessageOptions options) returns Message|Error = @java:Method { 'class: "io.ballerina.lib.ibm.ibmmq.Topic" } external; diff --git a/ballerina/types.bal b/ballerina/types.bal index 8bbc6f1..b9a8dba 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -37,12 +37,12 @@ public enum ConnectionOpenOptions { public type AccessTopicOptions MQOO_ALTERNATE_USER_AUTHORITY|MQOO_BIND_AS_Q_DEF|MQOO_FAIL_IF_QUIESCING|MQOO_OUTPUT|MQOO_PASS_ALL_CONTEXT|MQOO_PASS_IDENTITY_CONTEXT|MQOO_SET_ALL_CONTEXT|MQOO_SET_IDENTITY_CONTEXT; public type GetMessageOptions record {| - GM_OPTIONS options = MQGMO_NO_SYNCPOINT; + GM_OPTIONS gmOptions = MQGMO_NO_SYNCPOINT; int waitInterval = 0; |}; public type Property record {| - map descriptor?; + map descriptor?; boolean|byte|byte[]|decimal|float|int|string value; |}; diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java index 679aee8..1b4a567 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java @@ -21,6 +21,7 @@ import com.ibm.mq.MQException; import com.ibm.mq.MQMessage; import com.ibm.mq.MQPropertyDescriptor; +import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.creators.ErrorCreator; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; @@ -62,7 +63,6 @@ public class CommonUtils { private static final BString PROPERTY_VALUE = StringUtils.fromString("value"); private static final BString PROPERTY_DESCRIPTOR = StringUtils.fromString("descriptor"); - private static final MQPropertyDescriptor defaultPropertyDescriptor = new MQPropertyDescriptor(); public static MQMessage getMqMessageFromBMessage(BMap bMessage) { @@ -172,7 +172,8 @@ private static MQPropertyDescriptor getMQPropertyDescriptor(BMap descriptor) { } private static BMap populateDescriptorFromMQPropertyDescriptor(MQPropertyDescriptor propertyDescriptor) { - BMap descriptor = ValueCreator.createMapValue(); + BMap descriptor = ValueCreator.createMapValue(TypeCreator + .createMapType(PredefinedTypes.TYPE_INT)); descriptor.put(PD_VERSION, propertyDescriptor.version); descriptor.put(PD_COPY_OPTIONS, propertyDescriptor.copyOptions); descriptor.put(PD_OPTIONS, propertyDescriptor.options); From 30067cb953234144643407265618d5681edf1a48 Mon Sep 17 00:00:00 2001 From: dilanSachi Date: Fri, 27 Oct 2023 21:08:01 +0530 Subject: [PATCH 11/11] Fix suggestions --- ballerina/queue_manager.bal | 2 +- ballerina/types.bal | 2 +- .../ballerina/lib/ibm.ibmmq/CommonUtils.java | 39 +++++++++---------- .../io/ballerina/lib/ibm.ibmmq/Constants.java | 2 + .../lib/ibm.ibmmq/MQThreadFactory.java | 1 - .../ballerina/lib/ibm.ibmmq/QueueManager.java | 12 +++--- .../io/ballerina/lib/ibm.ibmmq/Topic.java | 4 +- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/ballerina/queue_manager.bal b/ballerina/queue_manager.bal index adab5e2..65a03d8 100644 --- a/ballerina/queue_manager.bal +++ b/ballerina/queue_manager.bal @@ -31,7 +31,7 @@ public isolated class QueueManager { return error Error("Not implemented"); } - public isolated function accessTopic(string topicName, string topicString, OPEN_AS_OPTION openAs, AccessTopicOptions options) returns Topic|Error = + public isolated function accessTopic(string topicName, string topicString, OPEN_TOPIC_OPTION openTopicOption, AccessTopicOptions options) returns Topic|Error = @java:Method { 'class: "io.ballerina.lib.ibm.ibmmq.QueueManager" } external; diff --git a/ballerina/types.bal b/ballerina/types.bal index b9a8dba..669ccd9 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -16,7 +16,7 @@ public type GM_OPTIONS MQGMO_WAIT|MQGMO_NO_WAIT|MQGMO_SYNCPOINT|MQGMO_NO_SYNCPOINT|MQGMO_BROWSE_FIRST|MQGMO_BROWSE_MSG_UNDER_CURSOR|MQGMO_MSG_UNDER_CURSOR|MQGMO_LOCK|MQGMO_UNLOCK|MQGMO_ACCEPT_TRUNCATED_MSG|MQGMO_BROWSE_NEXT|MQGMO_ACCEPT_TRUNCATED_MSG|MQGMO_FAIL_IF_QUIESCING|MQGMO_CONVERT; -public type OPEN_AS_OPTION OPEN_AS_SUBSCRIPTION|OPEN_AS_PUBLICATION; +public type OPEN_TOPIC_OPTION OPEN_AS_SUBSCRIPTION|OPEN_AS_PUBLICATION; public type QueueManagerConfiguration record {| string name; diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java index 1b4a567..8401733 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java @@ -43,9 +43,6 @@ */ public class CommonUtils { - public static final String BTOPIC = "TOPIC"; - public static final String TOPIC_OBJECT = "TOPIC_OBJECT"; - private static final String ERROR_DETAILS = "ErrorDetails"; private static final BString ERROR_REASON_CODE = StringUtils.fromString("reasonCode"); private static final BString ERROR_ERROR_CODE = StringUtils.fromString("errorCode"); @@ -101,10 +98,10 @@ private static BMap getBProperties(MQMessage mqMessage) throws BMap property = ValueCreator.createRecordValue(getModule(), BPROPERTY); MQPropertyDescriptor propertyDescriptor = new MQPropertyDescriptor(); Object propertyObject = mqMessage.getObjectProperty(propertyName, propertyDescriptor); - if (propertyObject instanceof Integer) { - property.put(PROPERTY_VALUE, ((Integer) propertyObject).longValue()); - } else if (propertyObject instanceof String) { - property.put(PROPERTY_VALUE, StringUtils.fromString((String) propertyObject)); + if (propertyObject instanceof Integer intProperty) { + property.put(PROPERTY_VALUE, intProperty.longValue()); + } else if (propertyObject instanceof String stringProperty) { + property.put(PROPERTY_VALUE, StringUtils.fromString(stringProperty)); } else { property.put(PROPERTY_VALUE, propertyObject); } @@ -134,20 +131,20 @@ private static void handlePropertyValue(BMap properties, MQMess propertyDescriptor = getMQPropertyDescriptor(properties.getMapValue(PROPERTY_DESCRIPTOR)); } Object value = property.get(PROPERTY_VALUE); - if (value instanceof Long) { - mqMessage.setIntProperty(key.getValue(), propertyDescriptor, ((Long) properties.get(key)).intValue()); - } else if (value instanceof Boolean) { - mqMessage.setBooleanProperty(key.getValue(), propertyDescriptor, ((Boolean) properties.get(key))); - } else if (value instanceof Byte) { - mqMessage.setByteProperty(key.getValue(), propertyDescriptor, (Byte) properties.get(key)); - } else if (value instanceof byte[]) { - mqMessage.setBytesProperty(key.getValue(), propertyDescriptor, ((byte[]) properties.get(key))); - } else if (value instanceof Float) { - mqMessage.setFloatProperty(key.getValue(), propertyDescriptor, (Float) properties.get(key)); - } else if (value instanceof Double) { - mqMessage.setDoubleProperty(key.getValue(), propertyDescriptor, (Double) properties.get(key)); - } else if (value instanceof BString) { - mqMessage.setStringProperty(key.getValue(), propertyDescriptor, ((BString) properties.get(key)).getValue()); + if (value instanceof Long longValue) { + mqMessage.setIntProperty(key.getValue(), propertyDescriptor, longValue.intValue()); + } else if (value instanceof Boolean booleanValue) { + mqMessage.setBooleanProperty(key.getValue(), propertyDescriptor, booleanValue); + } else if (value instanceof Byte byteValue) { + mqMessage.setByteProperty(key.getValue(), propertyDescriptor, byteValue); + } else if (value instanceof byte[] bytesValue) { + mqMessage.setBytesProperty(key.getValue(), propertyDescriptor, bytesValue); + } else if (value instanceof Float floatValue) { + mqMessage.setFloatProperty(key.getValue(), propertyDescriptor, floatValue); + } else if (value instanceof Double doubleValue) { + mqMessage.setDoubleProperty(key.getValue(), propertyDescriptor, doubleValue); + } else if (value instanceof BString stringValue) { + mqMessage.setStringProperty(key.getValue(), propertyDescriptor, stringValue.getValue()); } } diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Constants.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Constants.java index d9ad77b..2145199 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Constants.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Constants.java @@ -24,4 +24,6 @@ public interface Constants { // Native properties in respective ballerina objects public static final String NATIVE_QUEUE_MANAGER = "queueManager"; + + public static final String NATIVE_TOPIC = "topic"; } diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java index ab95b27..1f7ab82 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java @@ -34,5 +34,4 @@ public Thread newThread(Runnable runnable) { ibmMqClientThread.setName(threadGroupName); return ibmMqClientThread; } - } diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java index b468651..d51f9c8 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java @@ -22,7 +22,6 @@ import com.ibm.mq.MQQueueManager; import com.ibm.mq.MQTopic; import com.ibm.mq.constants.MQConstants; -import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BMap; @@ -46,6 +45,7 @@ public class QueueManager { private static final BString CHANNEL = StringUtils.fromString("channel"); private static final BString USER_ID = StringUtils.fromString("userID"); private static final BString PASSWORD = StringUtils.fromString("password"); + private static final String BTOPIC = "Topic"; /** * Creates a JMS connection with the provided configurations. @@ -67,14 +67,14 @@ public static Object init(BObject queueManager, BMap configurat return null; } - public static Object accessTopic(Environment env, BObject queueManagerObject, BString topicName, - BString topicString, Long openAs, Long options) { + public static Object accessTopic(BObject queueManagerObject, BString topicName, + BString topicString, Long openTopicOption, Long options) { MQQueueManager queueManager = (MQQueueManager) queueManagerObject.getNativeData(NATIVE_QUEUE_MANAGER); try { MQTopic mqTopic = queueManager.accessTopic(topicName.getValue(), topicString.getValue(), - openAs.intValue(), options.intValue()); - BObject bTopic = ValueCreator.createObjectValue(ModuleUtils.getModule(), CommonUtils.BTOPIC); - bTopic.addNativeData(CommonUtils.TOPIC_OBJECT, mqTopic); + openTopicOption.intValue(), options.intValue()); + BObject bTopic = ValueCreator.createObjectValue(ModuleUtils.getModule(), BTOPIC); + bTopic.addNativeData(Constants.NATIVE_TOPIC, mqTopic); return bTopic; } catch (MQException e) { return createError(IBMMQ_ERROR, diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java index decba79..f960775 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java @@ -39,7 +39,7 @@ public class Topic { private static final BString OPTIONS = StringUtils.fromString("options"); public static Object put(Environment environment, BObject topicObject, BMap message) { - MQTopic topic = (MQTopic) topicObject.getNativeData(CommonUtils.TOPIC_OBJECT); + MQTopic topic = (MQTopic) topicObject.getNativeData(Constants.NATIVE_TOPIC); MQMessage mqMessage = CommonUtils.getMqMessageFromBMessage(message); Future future = environment.markAsync(); topicExecutorService.execute(() -> { @@ -54,7 +54,7 @@ public static Object put(Environment environment, BObject topicObject, BMap mess } public static Object get(Environment environment, BObject topicObject, BMap options) { - MQTopic topic = (MQTopic) topicObject.getNativeData(CommonUtils.TOPIC_OBJECT); + MQTopic topic = (MQTopic) topicObject.getNativeData(Constants.NATIVE_TOPIC); MQGetMessageOptions getMessageOptions = getGetMessageOptions(options); Future future = environment.markAsync(); topicExecutorService.execute(() -> {