Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.solr.embedded;

import jakarta.servlet.Filter;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
Expand All @@ -40,53 +41,33 @@ public class JettyConfig {
/** If true, serve the Admin UI static files and index.html like the production web.xml does. */
public final boolean enableAdminUi;

private JettyConfig(
boolean onlyHttp1,
int port,
int portRetryTime,
boolean stopAtShutdown,
Long waitForLoadingCoresToFinishMs,
Map<ServletHolder, String> extraServlets,
Map<Class<? extends Filter>, String> extraFilters,
SSLConfig sslConfig,
boolean enableV2,
boolean enableGracefulShutdown,
boolean enableAdminUi) {
this.onlyHttp1 = onlyHttp1;
this.port = port;
this.portRetryTime = portRetryTime;
this.stopAtShutdown = stopAtShutdown;
this.waitForLoadingCoresToFinishMs = waitForLoadingCoresToFinishMs;
this.extraServlets = extraServlets;
this.extraFilters = extraFilters;
this.sslConfig = sslConfig;
this.enableV2 = enableV2;
this.enableGracefulShutdown = enableGracefulShutdown;
this.enableAdminUi = enableAdminUi;
/** Snapshot of the builder that built this config; enables {@link #builder(JettyConfig)}. */
private final Builder builder;

private JettyConfig(Builder builder) {
this.builder = builder;
this.onlyHttp1 = builder.onlyHttp1;
this.port = builder.port;
this.portRetryTime = builder.portRetryTime;
this.stopAtShutdown = builder.stopAtShutdown;
this.waitForLoadingCoresToFinishMs = builder.waitForLoadingCoresToFinishMs;
this.extraServlets = Collections.unmodifiableMap(builder.extraServlets);
this.extraFilters = Collections.unmodifiableMap(builder.extraFilters);
this.sslConfig = builder.sslConfig;
this.enableV2 = builder.enableV2;
this.enableGracefulShutdown = builder.enableGracefulShutdown;
this.enableAdminUi = builder.enableAdminUi;
}

public static Builder builder() {
return new Builder();
}

public static Builder builder(JettyConfig other) {
Builder builder = new Builder();

builder.onlyHttp1 = other.onlyHttp1;
builder.port = other.port;
builder.portRetryTime = other.portRetryTime;
builder.stopAtShutdown = other.stopAtShutdown;
builder.waitForLoadingCoresToFinishMs = other.waitForLoadingCoresToFinishMs;
builder.extraServlets = other.extraServlets;
builder.extraFilters = other.extraFilters;
builder.sslConfig = other.sslConfig;
builder.enableV2 = other.enableV2;
builder.enableGracefulShutdown = other.enableGracefulShutdown;
builder.enableAdminUi = other.enableAdminUi;
return builder;
return other.builder.clone();
}

public static class Builder {
public static class Builder implements Cloneable {

boolean onlyHttp1 = false;
int port = 0;
Expand Down Expand Up @@ -166,19 +147,22 @@ public Builder withPortRetryTime(int portRetryTime) {
return this;
}

/** Copies the maps too, so the clone is fully independent; the SSLConfig is shared. */
@Override
public Builder clone() {
try {
Builder clone = (Builder) super.clone();
clone.extraServlets = new TreeMap<>(extraServlets);
clone.extraFilters = new LinkedHashMap<>(extraFilters);
return clone;
} catch (CloneNotSupportedException e) {
throw new AssertionError(e);
}
}

public JettyConfig build() {
return new JettyConfig(
onlyHttp1,
port,
portRetryTime,
stopAtShutdown,
waitForLoadingCoresToFinishMs,
extraServlets,
extraFilters,
sslConfig,
enableV2,
enableGracefulShutdown,
enableAdminUi);
// clone so later mutations of this builder don't leak into the built config's snapshot
return new JettyConfig(clone());
}
}
}
Loading