Skip to content

Commit

Permalink
Improve Utils class usage
Browse files Browse the repository at this point in the history
  • Loading branch information
HindujaB committed Nov 19, 2024
1 parent 5a57977 commit 5a6c58d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.ballerina.runtime.api.values.BString;
import io.ballerina.stdlib.mqtt.utils.MqttConstants;
import io.ballerina.stdlib.mqtt.utils.MqttUtils;
import io.ballerina.stdlib.mqtt.utils.Util;
import org.eclipse.paho.mqttv5.client.IMqttToken;
import org.eclipse.paho.mqttv5.client.MqttCallback;
import org.eclipse.paho.mqttv5.client.MqttClient;
Expand Down Expand Up @@ -111,16 +110,20 @@ private void invokeOnMessage(MqttMessage message, String topic) {
}
try {
Object result = runtime.callMethod(service, MqttConstants.ONMESSAGE, null, bMqttMessage, callerObject);
Util.notifySuccess(result);
if (result instanceof BError error) {
error.printStackTrace();
}
} catch (BError bError) {
Util.notifyFailure(bError);
bError.printStackTrace();
}
} else {
try {
Object result = runtime.callMethod(service, MqttConstants.ONMESSAGE, null, bMqttMessage);
Util.notifySuccess(result);
if (result instanceof BError error) {
error.printStackTrace();
}
} catch (BError bError) {
Util.notifyFailure(bError);
bError.printStackTrace();
}
}
}
Expand All @@ -132,9 +135,11 @@ private void invokeOnError(BError bError) {
}
try {
Object result = runtime.callMethod(service, MqttConstants.ONERROR, null, bError);
Util.notifySuccess(result);
if (result instanceof BError error) {
error.printStackTrace();
}
} catch (BError error) {
Util.notifyFailure(error);
bError.printStackTrace();
}
}

Expand All @@ -146,9 +151,11 @@ private void invokeOnComplete(IMqttToken token) {
bMqttToken = getMqttDeliveryToken(token);
try {
Object result = runtime.callMethod(service, MqttConstants.ONCOMPLETE, null, bMqttToken);
Util.notifySuccess(result);
if (result instanceof BError error) {
error.printStackTrace();
}
} catch (BError bError) {
Util.notifyFailure(bError);
bError.printStackTrace();
}
}

Expand Down
53 changes: 0 additions & 53 deletions native/src/main/java/io/ballerina/stdlib/mqtt/utils/Util.java

This file was deleted.

0 comments on commit 5a6c58d

Please sign in to comment.