Skip to content

Commit

Permalink
Fix suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
dilanSachi committed Oct 27, 2023
1 parent 3de7cef commit 30067cb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion ballerina/queue_manager.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 18 additions & 21 deletions native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -101,10 +98,10 @@ private static BMap<BString, Object> getBProperties(MQMessage mqMessage) throws
BMap<BString, Object> 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);
}
Expand Down Expand Up @@ -134,20 +131,20 @@ private static void handlePropertyValue(BMap<BString, Object> 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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ public Thread newThread(Runnable runnable) {
ibmMqClientThread.setName(threadGroupName);
return ibmMqClientThread;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -67,14 +67,14 @@ public static Object init(BObject queueManager, BMap<BString, Object> 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,
Expand Down
4 changes: 2 additions & 2 deletions native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(() -> {
Expand All @@ -54,7 +54,7 @@ public static Object put(Environment environment, BObject topicObject, BMap mess
}

public static Object get(Environment environment, BObject topicObject, BMap<BString, Object> 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(() -> {
Expand Down

0 comments on commit 30067cb

Please sign in to comment.