Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinperera00 committed Nov 25, 2024
1 parent e3f6b20 commit 251aac9
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean onMessage(EmailEvent emailEvent) {
if (runtime != null) {
Set<Map.Entry<String, BObject>> services = registeredServices.entrySet();
for (Map.Entry<String, BObject> service : services) {
runtime.callMethod(service.getValue(), ON_MESSAGE, new StrandMetadata(true, null), email);
callMethod(service.getValue(), ON_MESSAGE, email);
}
} else {
log.error("Runtime should not be null.");
Expand All @@ -86,7 +86,7 @@ public void onError(Object error) {
if (runtime != null) {
Set<Map.Entry<String, BObject>> services = registeredServices.entrySet();
for (Map.Entry<String, BObject> service : services) {
runtime.callMethod(service.getValue(), ON_ERROR, new StrandMetadata(true, null), error);
callMethod(service.getValue(), ON_ERROR, error);
}
} else {
log.error("Runtime should not be null.");
Expand All @@ -106,7 +106,7 @@ public void onClose(Object error) {
if (runtime != null) {
Set<Map.Entry<String, BObject>> services = registeredServices.entrySet();
for (Map.Entry<String, BObject> service : services) {
runtime.callMethod(service.getValue(), ON_CLOSE, new StrandMetadata(true, null), error);
callMethod(service.getValue(), ON_CLOSE, error);
}
} else {
log.error("Runtime should not be null.");
Expand All @@ -123,4 +123,10 @@ protected void addService(BObject service) {
}
}

private void callMethod(BObject service, String methodName, Object args) {
ObjectType serviceType = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(service));
boolean isConcurrentSafe = serviceType.isIsolated() && serviceType.isIsolated(methodName);
runtime.callMethod(service, methodName, new StrandMetadata(isConcurrentSafe, null), args);
}

}

0 comments on commit 251aac9

Please sign in to comment.