Skip to content

Commit

Permalink
Remove unwanted completable futures
Browse files Browse the repository at this point in the history
  • Loading branch information
warunalakshitha committed Dec 10, 2024
1 parent 06fd31d commit b8ffe8a
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 145 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ stdlibTaskVersion=2.6.0-20241122-124800-cb84357
# Level 03
stdlibCacheVersion=3.9.0-20241122-182900-c956a97
stdlibFileVersion=1.11.0-20241122-180900-dff344c
stdlibMimeVersion=2.11.0-20241125-094600-bbddf94
stdlibMimeVersion=2.11.0-20241204-145000-6cef6a1
stdlibUuidVersion=1.9.0-20241125-110300-5eb185d

# Level 04
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.api.values.BTypedesc;

import java.util.concurrent.CompletableFuture;

import static io.ballerina.stdlib.graphql.runtime.utils.ModuleUtils.getResult;

/**
* This class is used to execute a GraphQL document using the Ballerina GraphQL client.
*/
Expand Down Expand Up @@ -67,15 +63,11 @@ private static Object invokeClientMethod(Environment env, BObject client, BStrin

private static Object invokeClientMethod(Environment env, BObject client, String methodName, Object[] paramFeed) {
return env.yieldAndRun(() -> {
CompletableFuture<Object> balFuture = new CompletableFuture<>();
QueryExecutorCallback executorCallback = new QueryExecutorCallback(balFuture);
try {
Object result = env.getRuntime().callMethod(client, methodName, null, paramFeed);
executorCallback.notifySuccess(result);
return env.getRuntime().callMethod(client, methodName, null, paramFeed);
} catch (BError bError) {
executorCallback.notifyFailure(bError);
return bError;
}
return getResult(balFuture);
});
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;

import static io.ballerina.runtime.api.types.TypeTags.INTERSECTION_TAG;
import static io.ballerina.stdlib.graphql.runtime.engine.EngineUtils.ARGUMENTS_FIELD;
Expand Down Expand Up @@ -540,16 +539,18 @@ private boolean isRepresentationArgument(Type type) {

private void addConstraintValidationErrors(Environment environment, BArray errors) {
environment.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
ExecutionCallback executionCallback = new ExecutionCallback(future);
BObject fieldNode = this.field.getObjectValue(INTERNAL_NODE);
Object[] arguments = {errors, fieldNode};
try {
Object result = environment.getRuntime()
.callMethod(this.responseGenerator, ADD_CONSTRAINT_ERRORS_METHOD, null, arguments);
executionCallback.notifySuccess(result);
environment.getRuntime().callMethod(this.responseGenerator, ADD_CONSTRAINT_ERRORS_METHOD, null,
arguments);
} catch (BError bError) {
executionCallback.notifyFailure(bError);
bError.printStackTrace();
// Service level `panic` is captured in this method.
// Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the
// application.
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
}
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BTypedesc;

import java.util.concurrent.CompletableFuture;

import static io.ballerina.stdlib.graphql.runtime.utils.ModuleUtils.getResult;

/**
* This class provides native implementations of the Ballerina DataLoader class.
*/
Expand All @@ -38,17 +34,18 @@ private DataLoader() {

public static Object get(Environment env, BObject dataLoader, Object key, BTypedesc typedesc) {
return env.yieldAndRun(() -> {
CompletableFuture<Object> balFuture = new CompletableFuture<>();
Object[] paramFeed = getProcessGetMethodParams(key, typedesc);
ExecutionCallback executionCallback = new ExecutionCallback(balFuture);
try {
Object result = env.getRuntime().callMethod(dataLoader, DATA_LOADER_PROCESSES_GET_METHOD_NAME, null,
paramFeed);
executionCallback.notifySuccess(result);
return env.getRuntime().callMethod(dataLoader, DATA_LOADER_PROCESSES_GET_METHOD_NAME, null, paramFeed);
} catch (BError bError) {
executionCallback.notifyFailure(bError);
bError.printStackTrace();
// Service level `panic` is captured in this method.
// Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the
// application.
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
}
return getResult(balFuture);
return null;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CompletableFuture;

import static io.ballerina.runtime.observability.ObservabilityConstants.KEY_OBSERVER_CONTEXT;
import static io.ballerina.stdlib.graphql.commons.utils.TypeUtils.removeEscapeCharacter;
Expand All @@ -64,7 +63,6 @@
import static io.ballerina.stdlib.graphql.runtime.engine.EngineUtils.SUBSCRIBE_ACCESSOR;
import static io.ballerina.stdlib.graphql.runtime.engine.EngineUtils.isPathsMatching;
import static io.ballerina.stdlib.graphql.runtime.utils.ModuleUtils.getModule;
import static io.ballerina.stdlib.graphql.runtime.utils.ModuleUtils.getResult;
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.ERROR_TYPE;
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.INTERNAL_NODE;
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.createError;
Expand Down Expand Up @@ -133,16 +131,18 @@ private static Object getResultObject(Environment environment, BObject context,
return null;
}
return environment.yieldAndRun(() -> {
CompletableFuture<Object> subscriptionFutureResult = new CompletableFuture<>();
ExecutionCallback executionCallback = new ExecutionCallback(subscriptionFutureResult);
Object[] args = argumentHandler.getArguments();
try {
Object result = callResourceMethod(environment.getRuntime(), service, methodName, args);
executionCallback.notifySuccess(result);
return callResourceMethod(environment.getRuntime(), service, methodName, args);
} catch (BError bError) {
executionCallback.notifyFailure(bError);
bError.printStackTrace();
// Service level `panic` is captured in this method.
// Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the
// application.
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
}
return getResult(subscriptionFutureResult);
return null;
});
}

Expand Down Expand Up @@ -183,17 +183,18 @@ public static Object executeInterceptor(Environment environment, BObject interce
return null;
}
return environment.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
ExecutionCallback executionCallback = new ExecutionCallback(future);
Object[] arguments = getInterceptorArguments(context, field);
try {
Object result = callResourceMethod(environment.getRuntime(), interceptor, remoteMethod.getName(),
arguments);
executionCallback.notifySuccess(result);
return callResourceMethod(environment.getRuntime(), interceptor, remoteMethod.getName(), arguments);
} catch (BError bError) {
executionCallback.notifyFailure(bError);
bError.printStackTrace();
// Service level `panic` is captured in this method.
// Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the
// application.
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
}
return getResult(future);
return null;
});
}

Expand Down Expand Up @@ -283,16 +284,17 @@ public static boolean hasPrefetchMethod(BObject serviceObject, BString prefetchM
public static void executePrefetchMethod(Environment environment, BObject context, BObject service,
MethodType resourceMethod, BObject fieldObject) {
environment.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
ExecutionCallback executionCallback = new ExecutionCallback(future);
ArgumentHandler argumentHandler = new ArgumentHandler(resourceMethod, context, fieldObject, null, false);
Object[] arguments = argumentHandler.getArguments();
try {
Object result = callResourceMethod(environment.getRuntime(), service, resourceMethod.getName(),
arguments);
executionCallback.notifySuccess(result);
return callResourceMethod(environment.getRuntime(), service, resourceMethod.getName(), arguments);
} catch (BError bError) {
executionCallback.notifyFailure(bError);
bError.printStackTrace();
// Service level `panic` is captured in this method.
// Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the
// application.
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
}
return null;
});
Expand Down

This file was deleted.

12 changes: 5 additions & 7 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
<Bug pattern="BC_UNCONFIRMED_CAST" />
</And>
</Match>
<Match>
<And>
<Class name="io.ballerina.stdlib.graphql.runtime.engine.ExecutionCallback" />
<Method name = "notifyFailure" />
<Bug pattern="DM_EXIT" />
</And>
</Match>
<Match>
<Bug pattern="EI_EXPOSE_REP, EI_EXPOSE_REP2" />
</Match>
Expand All @@ -53,4 +46,9 @@
<Method name = "getServiceResolver" />
<Bug pattern="DCN_NULLPOINTER_EXCEPTION" />
</Match>
<Match>
<And>
<Bug pattern="DM_EXIT" />
</And>
</Match>
</FindBugsFilter>

0 comments on commit b8ffe8a

Please sign in to comment.