Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace worker runtime API #852

Merged
merged 5 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,20 @@
package io.ballerina.stdlib.email.server;

import io.ballerina.runtime.api.Runtime;
import io.ballerina.runtime.api.async.StrandMetadata;
import io.ballerina.runtime.api.types.ObjectType;
import io.ballerina.runtime.api.utils.TypeUtils;
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.stdlib.email.util.EmailConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import static io.ballerina.stdlib.email.util.EmailConstants.ON_CLOSE_METADATA;
import static io.ballerina.stdlib.email.util.EmailConstants.ON_ERROR_METADATA;
import static io.ballerina.stdlib.email.util.EmailConstants.ON_CLOSE;
import static io.ballerina.stdlib.email.util.EmailConstants.ON_ERROR;
import static io.ballerina.stdlib.email.util.EmailConstants.ON_MESSAGE;
import static io.ballerina.stdlib.email.util.EmailConstants.ON_MESSAGE_METADATA;

/**
* Email connector listener for Ballerina.
Expand Down Expand Up @@ -68,7 +65,7 @@ public boolean onMessage(EmailEvent emailEvent) {
if (runtime != null) {
Set<Map.Entry<String, BObject>> services = registeredServices.entrySet();
for (Map.Entry<String, BObject> service : services) {
invokeAsyncCall(service.getValue(), ON_MESSAGE, ON_MESSAGE_METADATA, email);
runtime.call(service.getValue(), ON_MESSAGE, email);
}
} else {
log.error("Runtime should not be null.");
Expand All @@ -85,7 +82,7 @@ public void onError(Object error) {
if (runtime != null) {
Set<Map.Entry<String, BObject>> services = registeredServices.entrySet();
for (Map.Entry<String, BObject> service : services) {
invokeAsyncCall(service.getValue(), EmailConstants.ON_ERROR, ON_ERROR_METADATA, error);
runtime.call(service.getValue(), ON_ERROR, error);
}
} else {
log.error("Runtime should not be null.");
Expand All @@ -103,7 +100,7 @@ public void onClose(Object error) {
if (runtime != null) {
Set<Map.Entry<String, BObject>> services = registeredServices.entrySet();
for (Map.Entry<String, BObject> service : services) {
invokeAsyncCall(service.getValue(), EmailConstants.ON_CLOSE, ON_CLOSE_METADATA, error);
runtime.call(service.getValue(), ON_CLOSE, error);
}
} else {
log.error("Runtime should not be null.");
Expand All @@ -119,13 +116,4 @@ protected void addService(BObject service) {
}
}

private void invokeAsyncCall(BObject service, String methodName, StrandMetadata metadata, Object arg) {
ObjectType serviceType = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(service));
if (serviceType.isIsolated() && serviceType.isIsolated(methodName)) {
runtime.call(service, methodName, null, metadata, null, arg);
} else {
runtime.startNonIsolatedWorker(service, methodName, null, metadata, null, arg);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package io.ballerina.stdlib.email.util;

import io.ballerina.runtime.api.Module;
import io.ballerina.runtime.api.async.StrandMetadata;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.values.BString;

Expand Down Expand Up @@ -152,14 +151,4 @@ private EmailConstants() {}
public static final String EMAIL_MESSAGE = "Message";
public static final String ERROR = "Error";

// Strand meta data
public static final StrandMetadata ON_MESSAGE_METADATA = new StrandMetadata(BALLERINA_BUILTIN_PKG_PREFIX,
MODULE_NAME, EmailUtils.getEmailPackage().getVersion(), ON_MESSAGE);

public static final StrandMetadata ON_ERROR_METADATA = new StrandMetadata(BALLERINA_BUILTIN_PKG_PREFIX,
MODULE_NAME, EmailUtils.getEmailPackage().getVersion(), ON_ERROR);

public static final StrandMetadata ON_CLOSE_METADATA = new StrandMetadata(BALLERINA_BUILTIN_PKG_PREFIX,
MODULE_NAME, EmailUtils.getEmailPackage().getVersion(), ON_CLOSE);

}
Loading