Fixes for OSGi, remove automatic creation of executor for async requests (WIP) by gflores-jahia · Pull Request #569 · graphql-java-kickstart/graphql-java-servlet · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion graphql-java-kickstart/bnd.bnd
15 changes: 12 additions & 3 deletions graphql-java-servlet/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
Export-Package: graphql.kickstart.servlet.*
Import-Package: !lombok,*
Require-Capability: osgi.extender;
filter:="(&(osgi.extender=osgi.component)(version>=1.3)(!(version>=2.0)))"
Import-Package: !lombok,\
graphql;version="[20.2,22)",\
graphql.execution.instrumentation;version="[20.2,22)",\
graphql.execution.preparsed;version="[20.2,22)",\
graphql.execution.reactive;version="[20.2,22)",\
graphql.schema;version="[20.2,22)",\
javax.servlet;version="[3.1,5)",\
javax.servlet.http;version="[3.1,5)",\
javax.websocket;version="[1.1,2)",\
javax.websocket.server;version="[1.1,2)",\
*
Require-Capability: osgi.extender;filter:="(&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))"
6 changes: 3 additions & 3 deletions graphql-java-servlet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ dependencies {
api(project(':graphql-java-kickstart'))

// Servlet
compileOnly "jakarta.servlet:jakarta.servlet-api:6.0.0"
compileOnly "jakarta.websocket:jakarta.websocket-api:2.1.1"
compileOnly "jakarta.websocket:jakarta.websocket-client-api:2.1.1"
api "jakarta.servlet:jakarta.servlet-api:6.0.0"
api "jakarta.websocket:jakarta.websocket-api:2.1.1"
api "jakarta.websocket:jakarta.websocket-client-api:2.1.1"
implementation "org.slf4j:slf4j-api:$LIB_SLF4J_VER"

// OSGi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import lombok.Getter;

Expand Down Expand Up @@ -67,12 +64,12 @@ public static GraphQLConfiguration.Builder with(GraphQLSchema schema) {
}

public static GraphQLConfiguration.Builder with(GraphQLSchemaServletProvider schemaProvider) {
return new Builder(GraphQLInvocationInputFactory.newBuilder(schemaProvider));
return new Builder().with(GraphQLInvocationInputFactory.newBuilder(schemaProvider));
}

public static GraphQLConfiguration.Builder with(
GraphQLInvocationInputFactory invocationInputFactory) {
return new Builder(invocationInputFactory);
return new Builder().with(invocationInputFactory);
}

public GraphQLInvocationInputFactory getInvocationInputFactory() {
Expand Down Expand Up @@ -144,19 +141,9 @@ public static class Builder {
private Supplier<BatchInputPreProcessor> batchInputPreProcessorSupplier =
NoOpBatchInputPreProcessor::new;
private GraphQLResponseCacheManager responseCacheManager;
private int asyncCorePoolSize = 10;
private int asyncMaxPoolSize = 200;
private Executor asyncExecutor;
private AsyncTaskDecorator asyncTaskDecorator;

private Builder(GraphQLInvocationInputFactory.Builder invocationInputFactoryBuilder) {
this.invocationInputFactoryBuilder = invocationInputFactoryBuilder;
}

private Builder(GraphQLInvocationInputFactory invocationInputFactory) {
this.invocationInputFactory = invocationInputFactory;
}

public Builder with(GraphQLInvoker graphQLInvoker) {
this.graphQLInvoker = graphQLInvoker;
return this;
Expand All @@ -183,17 +170,39 @@ public Builder with(List<GraphQLServletListener> listeners) {
return this;
}

public Builder with(GraphQLInvocationInputFactory.Builder invocationInputFactoryBuilder) {
if (this.invocationInputFactoryBuilder != null) {
throw new IllegalArgumentException("Cannot set invocationInputFactoryBuilder if invocationInputFactory is used");
}
this.invocationInputFactoryBuilder = invocationInputFactoryBuilder;
return this;
}

public Builder with(GraphQLInvocationInputFactory invocationInputFactory) {
if (this.invocationInputFactoryBuilder != null) {
throw new IllegalArgumentException("Cannot set invocationInputFactory if invocationInputFactoryBuilder is used");
}
this.invocationInputFactory = invocationInputFactory;
return this;
}

public Builder with(GraphQLServletContextBuilder contextBuilder) {
if (this.invocationInputFactoryBuilder == null) {
throw new IllegalArgumentException("Cannot use a contextBuilder without setting invocationInputFactoryBuilder first");
}
this.invocationInputFactoryBuilder.withGraphQLContextBuilder(contextBuilder);
return this;
}

public Builder with(GraphQLServletRootObjectBuilder rootObjectBuilder) {
if (this.invocationInputFactoryBuilder == null) {
throw new IllegalArgumentException("Cannot use a rootObjectBuilder without setting invocationInputFactoryBuilder first");
}
this.invocationInputFactoryBuilder.withGraphQLRootObjectBuilder(rootObjectBuilder);
return this;
}

public Builder with(long subscriptionTimeout) {
public Builder subscriptionTimeout(long subscriptionTimeout) {
this.subscriptionTimeout = subscriptionTimeout;
return this;
}
Expand All @@ -208,16 +217,6 @@ public Builder with(Executor asyncExecutor) {
return this;
}

public Builder asyncCorePoolSize(int asyncCorePoolSize) {
this.asyncCorePoolSize = asyncCorePoolSize;
return this;
}

public Builder asyncMaxPoolSize(int asyncMaxPoolSize) {
this.asyncMaxPoolSize = asyncMaxPoolSize;
return this;
}

public Builder with(ContextSetting contextSetting) {
if (contextSetting != null) {
this.contextSetting = contextSetting;
Expand Down Expand Up @@ -249,20 +248,12 @@ public Builder with(AsyncTaskDecorator asyncTaskDecorator) {
return this;
}

private Executor getAsyncExecutor() {
private Executor getAsyncTaskExecutor() {
if (asyncExecutor != null) {
return asyncExecutor;
return new AsyncTaskExecutor(asyncExecutor, asyncTaskDecorator);
}
return new ThreadPoolExecutor(
asyncCorePoolSize,
asyncMaxPoolSize,
60,
TimeUnit.SECONDS,
new LinkedBlockingQueue<>(Integer.MAX_VALUE));
}

private Executor getAsyncTaskExecutor() {
return new AsyncTaskExecutor(getAsyncExecutor(), asyncTaskDecorator);
return null;
}

public GraphQLConfiguration build() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graphql.kickstart.servlet;

import graphql.schema.GraphQLSchema;
import java.util.concurrent.ThreadPoolExecutor;

/** @author Michiel Oliemans */
public abstract class GraphQLHttpServlet extends AbstractGraphQLHttpServlet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public boolean isShutDown() {
return isShutDown.get();
}

private SubscriptionProtocolFactory getSubscriptionProtocolFactory(List<String> accept) {
public SubscriptionProtocolFactory getSubscriptionProtocolFactory(List<String> accept) {
for (String protocol : accept) {
for (SubscriptionProtocolFactory subscriptionProtocolFactory :
subscriptionProtocolFactories) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void execute(
HttpServletRequest request,
HttpServletResponse response,
ListenerHandler listenerHandler) {
if (request.isAsyncSupported()) {
if (request.isAsyncSupported() && configuration.getAsyncExecutor() != null) {
invokeAndHandleAsync(invocationInput, request, response, listenerHandler);
} else {
handle(invocationInput, request, response, listenerHandler);
Expand Down
Loading