Skip to content

Commit

Permalink
Merge pull request #545 from ravinperera00/java21_sync
Browse files Browse the repository at this point in the history
Improve callMethod logic
  • Loading branch information
warunalakshitha authored Nov 26, 2024
2 parents 946f4ef + 86443ef commit 00d62a7
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
package io.ballerina.stdlib.file.service;

import io.ballerina.runtime.api.Runtime;
import io.ballerina.runtime.api.concurrent.StrandMetadata;
import io.ballerina.runtime.api.types.MethodType;
import io.ballerina.runtime.api.types.ObjectType;
import io.ballerina.runtime.api.utils.TypeUtils;
import io.ballerina.runtime.api.values.BObject;
import org.wso2.transport.localfilesystem.server.connector.contract.LocalFileSystemEvent;
import org.wso2.transport.localfilesystem.server.connector.contract.LocalFileSystemListener;
Expand All @@ -41,14 +44,18 @@ public FSListener(Runtime runtime) {

@Override
public void onMessage(LocalFileSystemEvent fileEvent) {
for (Map.Entry<BObject, Map<String, MethodType>> serviceEntry: serviceRegistry.entrySet()) {
MethodType serviceFunction = serviceEntry.getValue().get(fileEvent.getEvent());
if (serviceFunction != null) {
String functionName = serviceFunction.getName();
BObject service = serviceEntry.getKey();
runtime.callMethod(service, functionName, null);
Thread.startVirtualThread(() -> {
for (Map.Entry<BObject, Map<String, MethodType>> serviceEntry: serviceRegistry.entrySet()) {
MethodType serviceFunction = serviceEntry.getValue().get(fileEvent.getEvent());
if (serviceFunction != null) {
String functionName = serviceFunction.getName();
BObject service = serviceEntry.getKey();
ObjectType type = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(service));
boolean isConcurrentSafe = type.isIsolated() && type.isIsolated(functionName);
runtime.callMethod(service, functionName, new StrandMetadata(isConcurrentSafe, null));
}
}
}
});
}

public void addService(BObject service, Map<String, MethodType> attachedFunctions) {
Expand Down

0 comments on commit 00d62a7

Please sign in to comment.