Skip to content

Commit

Permalink
Improve callMethod Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
HindujaB committed Nov 22, 2024
1 parent 866d2fa commit 6a7954d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package io.ballerina.stdlib.graphql.runtime.engine;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.concurrent.StrandMetadata;
import io.ballerina.runtime.api.creators.TypeCreator;
import io.ballerina.runtime.api.creators.ValueCreator;
import io.ballerina.runtime.api.types.ArrayType;
Expand Down Expand Up @@ -547,8 +546,7 @@ private void addConstraintValidationErrors(Environment environment, BArray error
Object[] arguments = {errors, fieldNode};
try {
Object result = environment.getRuntime()
.callMethod(this.responseGenerator, ADD_CONSTRAINT_ERRORS_METHOD,
new StrandMetadata(true, null), arguments);
.callMethod(this.responseGenerator, ADD_CONSTRAINT_ERRORS_METHOD, null, arguments);
executionCallback.notifySuccess(result);
} catch (BError bError) {
executionCallback.notifyFailure(bError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.Runtime;
import io.ballerina.runtime.api.concurrent.StrandMetadata;
import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.types.IntersectionType;
import io.ballerina.runtime.api.types.MethodType;
import io.ballerina.runtime.api.types.ObjectType;
import io.ballerina.runtime.api.types.RemoteMethodType;
import io.ballerina.runtime.api.types.ResourceMethodType;
import io.ballerina.runtime.api.types.ServiceType;
Expand Down Expand Up @@ -137,12 +135,8 @@ private static Object getResultObject(Environment environment, BObject context,
CompletableFuture<Object> subscriptionFutureResult = new CompletableFuture<>();
ExecutionCallback executionCallback = new ExecutionCallback(subscriptionFutureResult);
Object[] args = argumentHandler.getArguments();
HashMap<String, Object> properties = null;
if (ObserveUtils.isObservabilityEnabled() && ObserveUtils.isTracingEnabled()) {
properties = getPropertiesToPropagate(environment, context);
}
try {
Object result = callResourceMethod(environment.getRuntime(), service, methodName, properties, args);
Object result = callResourceMethod(environment.getRuntime(), service, methodName, args);
executionCallback.notifySuccess(result);
} catch (BError bError) {
executionCallback.notifyFailure(bError);
Expand All @@ -151,12 +145,8 @@ private static Object getResultObject(Environment environment, BObject context,
});
}

private static Object callResourceMethod(Runtime runtime, BObject service, String methodName,
HashMap<String, Object> properties, Object[] args) {
ObjectType objectType = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(service));
boolean isIsolated = objectType.isIsolated() && objectType.isIsolated(methodName);
StrandMetadata strandMetadata = new StrandMetadata(isIsolated, properties);
return runtime.callMethod(service, methodName, strandMetadata, args);
private static Object callResourceMethod(Runtime runtime, BObject service, String methodName, Object[] args) {
return runtime.callMethod(service, methodName, null, args);
}

public static Object executeQueryResource(Environment environment, BObject context, BObject service,
Expand Down Expand Up @@ -195,13 +185,9 @@ public static Object executeInterceptor(Environment environment, BObject interce
CompletableFuture<Object> future = new CompletableFuture<>();
ExecutionCallback executionCallback = new ExecutionCallback(future);
Object[] arguments = getInterceptorArguments(context, field);
HashMap<String, Object> properties = null;
if (ObserveUtils.isObservabilityEnabled() && ObserveUtils.isTracingEnabled()) {
properties = getPropertiesToPropagate(environment, context);
}
try {
Object result = callResourceMethod(environment.getRuntime(), interceptor, remoteMethod.getName(),
properties, arguments);
arguments);
executionCallback.notifySuccess(result);
} catch (BError bError) {
executionCallback.notifyFailure(bError);
Expand Down Expand Up @@ -300,13 +286,9 @@ public static void executePrefetchMethod(Environment environment, BObject contex
ExecutionCallback executionCallback = new ExecutionCallback(future);
ArgumentHandler argumentHandler = new ArgumentHandler(resourceMethod, context, fieldObject, null, false);
Object[] arguments = argumentHandler.getArguments();
HashMap<String, Object> properties = null;
if (ObserveUtils.isObservabilityEnabled() && ObserveUtils.isTracingEnabled()) {
properties = getPropertiesToPropagate(environment, context);
}
try {
Object result = callResourceMethod(environment.getRuntime(), service, resourceMethod.getName(),
properties, arguments);
arguments);
executionCallback.notifySuccess(result);
} catch (BError bError) {
executionCallback.notifyFailure(bError);
Expand Down

0 comments on commit 6a7954d

Please sign in to comment.