Skip to content
Merged
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
6 changes: 6 additions & 0 deletions avaje-jex/src/main/java/io/avaje/jex/DJex.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.avaje.jex;

import io.avaje.inject.BeanScope;
import io.avaje.jex.core.CoreServiceLoader;
import io.avaje.jex.core.CoreServiceManager;
import io.avaje.jex.core.HealthPlugin;
import io.avaje.jex.jdk.JdkServerStart;
Expand Down Expand Up @@ -111,6 +112,11 @@ public Server start() {
if (config.health()) {
plugin(new HealthPlugin());
}

if (!config.useSpiPlugins()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this around the wrong way? Should be if (config.useSpiPlugins()) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

CoreServiceLoader.plugins().forEach(p -> p.apply(this));
}

final SpiRoutes routes =
new RoutesBuilder(
this.routing, this.config.ignoreTrailingSlashes())
Expand Down
26 changes: 12 additions & 14 deletions avaje-jex/src/main/java/io/avaje/jex/DJexConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ final class DJexConfig implements JexConfig {
private boolean health = true;
private boolean ignoreTrailingSlashes = true;
private Executor executor;

private boolean preCompressStaticFiles;
private JsonService jsonService;
private final Map<String, TemplateRender> renderers = new HashMap<>();
private SSLContext sslContext;
private final CompressionConfig compression= new CompressionConfig();
private boolean useJexSpi = true;
private final CompressionConfig compression = new CompressionConfig();

@Override
public JexConfig port(int port) {
Expand Down Expand Up @@ -59,12 +58,6 @@ public JexConfig ignoreTrailingSlashes(boolean ignoreTrailingSlashes) {
return this;
}

@Override
public JexConfig preCompressStaticFiles(boolean preCompressStaticFiles) {
this.preCompressStaticFiles = preCompressStaticFiles;
return this;
}

@Override
public JexConfig jsonService(JsonService jsonService) {
this.jsonService = jsonService;
Expand Down Expand Up @@ -118,11 +111,6 @@ public boolean ignoreTrailingSlashes() {
return ignoreTrailingSlashes;
}

@Override
public boolean preCompressStaticFiles() {
return preCompressStaticFiles;
}

@Override
public JsonService jsonService() {
return jsonService;
Expand Down Expand Up @@ -154,4 +142,14 @@ public JexConfig compression(Consumer<CompressionConfig> consumer) {
public CompressionConfig compression() {
return compression;
}

@Override
public DJexConfig disableSpiPlugins() {
useJexSpi = false;
return this;
}

boolean useSpiPlugins() {
return useJexSpi;
}
}
80 changes: 22 additions & 58 deletions avaje-jex/src/main/java/io/avaje/jex/JexConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.function.Consumer;

import javax.net.ssl.SSLContext;
Expand All @@ -12,97 +11,60 @@
import io.avaje.jex.spi.JsonService;
import io.avaje.jex.spi.TemplateRender;

/**
* Jex configuration.
*/
/** Jex configuration. */
public sealed interface JexConfig permits DJexConfig {

/**
* Set the port to use. Defaults to 7001.
*/
/** Set the port to use. Defaults to 7001. */
JexConfig port(int port);

/**
* Set the host to bind to.
*/
/** Set the host to bind to. */
JexConfig host(String host);

/**
* Set the contextPath.
*/
/** Set the contextPath. */
JexConfig contextPath(String contextPath);

/**
* Set to true to include the health endpoint. Defaults to true.
*/
/** Set to true to include the health endpoint. Defaults to true. */
JexConfig health(boolean health);

/**
* Set to true to ignore trailing slashes. Defaults to true.
*/
/** Set to true to ignore trailing slashes. Defaults to true. */
JexConfig ignoreTrailingSlashes(boolean ignoreTrailingSlashes);

/**
* Set to true to pre compress static files. Defaults to false.
*/
JexConfig preCompressStaticFiles(boolean preCompressStaticFiles);

/**
* Set the JsonService to use.
*/
/** Set the JsonService to use. */
JexConfig jsonService(JsonService jsonService);

/**
* Register a template renderer explicitly.
*
* @param extension The extension the renderer applies to.
* @param renderer The template render to use for the given extension.
* @param renderer The template render to use for the given extension.
*/
JexConfig renderer(String extension, TemplateRender renderer);

/**
* Set executor for serving requests.
*/
/** Set executor for serving requests. */
JexConfig executor(Executor executor);

/**
* Executor for serving requests. Defaults to a {@link Executors#newVirtualThreadPerTaskExecutor()}
* Executor for serving requests. Defaults to a {@link
* Executors#newVirtualThreadPerTaskExecutor()}
*/
Executor executor();

/**
* Return the port to use.
*/
/** Return the port to use. */
int port();

/**
* Return the host to bind to.
*/
/** Return the host to bind to. */
String host();

/**
* Return the contextPath to use.
*/
/** Return the contextPath to use. */
String contextPath();

/**
* Return true to include the health endpoint.
*/
/** Return true to include the health endpoint. */
boolean health();

/**
* Return true to ignore trailing slashes.
*/
/** Return true to ignore trailing slashes. */
boolean ignoreTrailingSlashes();

/**
* Return true if static files should be pre compressed.
*/
boolean preCompressStaticFiles();

/**
* Return the JsonService.
*/
/** Return the JsonService. */
JsonService jsonService();

/** Return the ssl context if https is enabled. */
Expand All @@ -111,13 +73,15 @@ public sealed interface JexConfig permits DJexConfig {
/** Enable https with the provided SSLContext. */
JexConfig sslContext(SSLContext ssl);

/**
* Return the template renderers registered by extension.
*/
/** Return the template renderers registered by extension. */
Map<String, TemplateRender> renderers();

/** configure compression via consumer */
JexConfig compression(Consumer<CompressionConfig> consumer);

/** get compression configuration */
CompressionConfig compression();

/** whether to disable JexPlugins loaded from ServiceLoader */
JexConfig disableSpiPlugins();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.ServiceLoader;

import io.avaje.jex.spi.JexExtension;
import io.avaje.jex.spi.JexPlugin;
import io.avaje.jex.spi.JsonService;
import io.avaje.jex.spi.TemplateRender;

Expand All @@ -16,13 +17,15 @@ public final class CoreServiceLoader {

private final JsonService jsonService;
private final List<TemplateRender> renders = new ArrayList<>();
private final List<JexPlugin> plugins = new ArrayList<>();

CoreServiceLoader() {
JsonService spiJsonService = null;
for (var spi : ServiceLoader.load(JexExtension.class)) {
switch (spi) {
case JsonService s -> spiJsonService = s;
case TemplateRender r -> renders.add(r);
case JexPlugin p -> plugins.add(p);
}
}
jsonService = spiJsonService;
Expand All @@ -35,4 +38,8 @@ public static Optional<JsonService> jsonService() {
public static List<TemplateRender> getRenders() {
return INSTANCE.renders;
}

public static List<JexPlugin> plugins() {
return INSTANCE.plugins;
}
}
2 changes: 1 addition & 1 deletion avaje-jex/src/main/java/io/avaje/jex/spi/JexExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
* META-INF/services/io.avaje.jex.spi.JexExtension } for it to be loaded by Jex
*/
@Service
public sealed interface JexExtension permits JsonService, TemplateRender {}
public sealed interface JexExtension permits JsonService, TemplateRender, JexPlugin {}
3 changes: 2 additions & 1 deletion avaje-jex/src/main/java/io/avaje/jex/spi/JexPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
/**
* A plugin that can register things like routes, exception handlers etc.
*/
public interface JexPlugin {
@FunctionalInterface
public non-sealed interface JexPlugin extends JexExtension{

/**
* Register the plugin features with jex.
Expand Down