Skip to content

Commit

Permalink
Merge pull request #852 from HindujaB/java21
Browse files Browse the repository at this point in the history
Replace worker runtime API
  • Loading branch information
warunalakshitha authored Oct 12, 2024
2 parents 0d5bd3e + 4f1120e commit 7e1c511
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
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);

}

0 comments on commit 7e1c511

Please sign in to comment.