From 16cc45aff97d36dd6512301d680a124eca3f220c Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Fri, 22 Nov 2024 13:19:00 +0530 Subject: [PATCH 1/2] Improve callMethod logic --- .../stdlib/file/service/FSListener.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/file/service/FSListener.java b/native/src/main/java/io/ballerina/stdlib/file/service/FSListener.java index c7ecdfa..22d577f 100644 --- a/native/src/main/java/io/ballerina/stdlib/file/service/FSListener.java +++ b/native/src/main/java/io/ballerina/stdlib/file/service/FSListener.java @@ -19,6 +19,7 @@ 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.values.BObject; import org.wso2.transport.localfilesystem.server.connector.contract.LocalFileSystemEvent; @@ -41,14 +42,16 @@ public FSListener(Runtime runtime) { @Override public void onMessage(LocalFileSystemEvent fileEvent) { - for (Map.Entry> 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> 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, new StrandMetadata(true, null)); + } } - } + }); } public void addService(BObject service, Map attachedFunctions) { From f5374d02115ba2ebc0b0b848470ffa38f83463ab Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Mon, 25 Nov 2024 11:10:51 +0530 Subject: [PATCH 2/2] Add suggestions from code review --- .../java/io/ballerina/stdlib/file/service/FSListener.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/native/src/main/java/io/ballerina/stdlib/file/service/FSListener.java b/native/src/main/java/io/ballerina/stdlib/file/service/FSListener.java index 22d577f..f6903de 100644 --- a/native/src/main/java/io/ballerina/stdlib/file/service/FSListener.java +++ b/native/src/main/java/io/ballerina/stdlib/file/service/FSListener.java @@ -21,6 +21,8 @@ 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; @@ -48,7 +50,9 @@ public void onMessage(LocalFileSystemEvent fileEvent) { if (serviceFunction != null) { String functionName = serviceFunction.getName(); BObject service = serviceEntry.getKey(); - runtime.callMethod(service, functionName, new StrandMetadata(true, null)); + ObjectType type = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(service)); + boolean isConcurrentSafe = type.isIsolated() && type.isIsolated(functionName); + runtime.callMethod(service, functionName, new StrandMetadata(isConcurrentSafe, null)); } } });