Skip to content

Commit

Permalink
Set runtime at attach
Browse files Browse the repository at this point in the history
  • Loading branch information
aashikam committed Aug 24, 2024
1 parent 66fc36c commit d4976aa
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,7 +44,6 @@
public class ListenerUtil {
private static final ArrayList<BObject> services = new ArrayList<>();
private static final Map<BObject, DispatcherService> serviceDispatcherMap = new HashMap<>();
private static Runtime runtime;
private static EmpConnector connector;
private static TopicSubscription subscription;

Expand All @@ -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")
Expand All @@ -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);
Expand All @@ -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<BObject> services = (ArrayList<BObject>) listener.getNativeData(CONSUMER_SERVICES);
@SuppressWarnings("unchecked")
Expand Down

0 comments on commit d4976aa

Please sign in to comment.