From d4976aa433465adf08a3cc64bd96711e5233898a Mon Sep 17 00:00:00 2001 From: aashikam Date: Sat, 24 Aug 2024 06:56:35 +0530 Subject: [PATCH] Set runtime at attach --- .../main/java/io/ballerinax/salesforce/ListenerUtil.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/native/src/main/java/io/ballerinax/salesforce/ListenerUtil.java b/native/src/main/java/io/ballerinax/salesforce/ListenerUtil.java index 6fe630ad..27186926 100644 --- a/native/src/main/java/io/ballerinax/salesforce/ListenerUtil.java +++ b/native/src/main/java/io/ballerinax/salesforce/ListenerUtil.java @@ -20,7 +20,6 @@ package io.ballerinax.salesforce; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Runtime; import io.ballerina.runtime.api.creators.ErrorCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BError; @@ -45,7 +44,6 @@ public class ListenerUtil { private static final ArrayList services = new ArrayList<>(); private static final Map serviceDispatcherMap = new HashMap<>(); - private static Runtime runtime; private static EmpConnector connector; private static TopicSubscription subscription; @@ -56,7 +54,7 @@ public static void initListener(BObject listener, int replayFrom, boolean isSand listener.addNativeData(IS_SAND_BOX, isSandBox); } - public static Object attachService(BObject listener, BObject service, Object channelName) { + public static Object attachService(Environment environment, BObject listener, BObject service, Object channelName) { listener.addNativeData(CHANNEL_NAME, ((BString) channelName).getValue()); @SuppressWarnings("unchecked") @@ -69,14 +67,14 @@ public static Object attachService(BObject listener, BObject service, Object cha return null; } - DispatcherService dispatcherService = new DispatcherService(service, runtime); + DispatcherService dispatcherService = new DispatcherService(service, environment.getRuntime()); services.add(service); serviceDispatcherMap.put(service, dispatcherService); return null; } - public static Object startListener(Environment environment, BString username, BString password, BObject listener) { + public static Object startListener(BString username, BString password, BObject listener) { BearerTokenProvider tokenProvider = new BearerTokenProvider(() -> { try { return LoginHelper.login(username.getValue(), password.getValue(), listener); @@ -96,7 +94,6 @@ public static Object startListener(Environment environment, BString username, BS } catch (Exception e) { return sfdcError(e.getMessage()); } - runtime = environment.getRuntime(); @SuppressWarnings("unchecked") ArrayList services = (ArrayList) listener.getNativeData(CONSUMER_SERVICES); @SuppressWarnings("unchecked")