Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented addBeanFromConstructor #11319

Merged
merged 15 commits into from
Mar 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class AbstractConnectorHttpClientTransport extends AbstractHttpC
protected AbstractConnectorHttpClientTransport(ClientConnector connector)
{
this.connector = Objects.requireNonNull(connector);
addBean(connector);
installBean(connector);
}

public ClientConnector getClientConnector()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ public HttpClient()
public HttpClient(HttpClientTransport transport)
{
this.transport = Objects.requireNonNull(transport);
addBean(transport);
installBean(transport);
this.connector = ((AbstractHttpClientTransport)transport).getContainedBeans(ClientConnector.class).stream().findFirst().orElseThrow();
addBean(requestListeners);
addBean(handlers);
addBean(decoderFactories);
installBean(requestListeners);
installBean(handlers);
installBean(decoderFactories);
}

public HttpClientTransport getTransport()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public HttpClientTransportDynamic(ClientConnector connector, ClientConnectionFac
{
super(connector);
this.infos = infos.length == 0 ? List.of(HttpClientConnectionFactory.HTTP11) : List.of(infos);
this.infos.forEach(this::addBean);
this.infos.forEach(this::installBean);
setConnectionPoolFactory(destination ->
new MultiplexConnectionPool(destination, destination.getHttpClient().getMaxConnectionsPerDestination(), 1)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected ScanningAppProvider()
protected ScanningAppProvider(FilenameFilter filter)
{
_filenameFilter = filter;
addBean(_appMap);
installBean(_appMap);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public DelegatingThreadPool(Executor executor)
{
_executor = executor;
_tryExecutor = TryExecutor.asTryExecutor(executor);
addBean(_executor);
installBean(_executor);
}

public Executor getExecutor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ClientConnectionFactoryOverHTTP2 extends ContainerLifeCycle impleme
public ClientConnectionFactoryOverHTTP2(HTTP2Client http2Client)
{
this.http2Client = http2Client;
addBean(http2Client);
installBean(http2Client);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class HttpClientTransportOverHTTP2 extends AbstractHttpClientTransport
public HttpClientTransportOverHTTP2(HTTP2Client http2Client)
{
this.http2Client = http2Client;
addBean(http2Client);
installBean(http2Client);
setConnectionPoolFactory(destination ->
{
HttpClient httpClient = getHttpClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public HTTP2Client()
public HTTP2Client(ClientConnector connector)
{
this.connector = connector;
addBean(connector);
installBean(connector);
}

public ClientConnector getClientConnector()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public HTTP2Session(Scheduler scheduler, EndPoint endPoint, Parser parser, Gener
this.recvWindow.set(FlowControlStrategy.DEFAULT_WINDOW_SIZE);
this.writeThreshold = 32 * 1024;
this.pushEnabled = true; // SPEC: by default, push is enabled.
addBean(flowControl);
addBean(flusher);
installBean(flowControl);
installBean(flusher);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ protected AbstractHTTP2ServerConnectionFactory(@Name("config") HttpConfiguration
if (!isProtocolSupported(p))
throw new IllegalArgumentException("Unsupported HTTP2 Protocol variant: " + p);
}
addBean(sessionContainer);
installBean(sessionContainer);
this.httpConfiguration = Objects.requireNonNull(httpConfiguration);
addBean(httpConfiguration);
installBean(httpConfiguration);
setInputBufferSize(Frame.DEFAULT_MAX_SIZE + Frame.HEADER_LENGTH);
setUseInputDirectByteBuffers(httpConfiguration.isUseInputDirectByteBuffers());
setUseOutputDirectByteBuffers(httpConfiguration.isUseOutputDirectByteBuffers());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ClientConnectionFactoryOverHTTP3 extends ContainerLifeCycle impleme

public ClientConnectionFactoryOverHTTP3(HTTP3Client http3Client)
{
addBean(http3Client);
installBean(http3Client);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class HttpClientTransportOverHTTP3 extends AbstractHttpClientTransport im
public HttpClientTransportOverHTTP3(HTTP3Client http3Client)
{
this.http3Client = Objects.requireNonNull(http3Client);
addBean(http3Client);
installBean(http3Client);
setConnectionPoolFactory(destination ->
{
HttpClient httpClient = getHttpClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ClientHTTP3Session(HTTP3Configuration configuration, ClientQuicSession qu
super(quicSession);
this.configuration = configuration;
session = new HTTP3SessionClient(this, listener, promise);
addBean(session);
installBean(session);
session.setStreamIdleTimeout(configuration.getStreamIdleTimeout());

if (LOG.isDebugEnabled())
Expand All @@ -69,27 +69,27 @@ public ClientHTTP3Session(HTTP3Configuration configuration, ClientQuicSession qu
InstructionFlusher encoderInstructionFlusher = new InstructionFlusher(quicSession, encoderEndPoint, EncoderStreamConnection.STREAM_TYPE);
encoder = new QpackEncoder(new InstructionHandler(encoderInstructionFlusher));
encoder.setMaxHeadersSize(configuration.getMaxRequestHeadersSize());
addBean(encoder);
installBean(encoder);
if (LOG.isDebugEnabled())
LOG.debug("created encoder stream #{} on {}", encoderStreamId, encoderEndPoint);

long decoderStreamId = newStreamId(StreamType.CLIENT_UNIDIRECTIONAL);
QuicStreamEndPoint decoderEndPoint = openInstructionEndPoint(decoderStreamId);
InstructionFlusher decoderInstructionFlusher = new InstructionFlusher(quicSession, decoderEndPoint, DecoderStreamConnection.STREAM_TYPE);
decoder = new QpackDecoder(new InstructionHandler(decoderInstructionFlusher));
addBean(decoder);
installBean(decoder);
if (LOG.isDebugEnabled())
LOG.debug("created decoder stream #{} on {}", decoderStreamId, decoderEndPoint);

long controlStreamId = newStreamId(StreamType.CLIENT_UNIDIRECTIONAL);
QuicStreamEndPoint controlEndPoint = openControlEndPoint(controlStreamId);
controlFlusher = new ControlFlusher(quicSession, controlEndPoint, true);
addBean(controlFlusher);
installBean(controlFlusher);
if (LOG.isDebugEnabled())
LOG.debug("created control stream #{} on {}", controlStreamId, controlEndPoint);

messageFlusher = new MessageFlusher(quicSession.getByteBufferPool(), encoder, configuration.isUseOutputDirectByteBuffers());
addBean(messageFlusher);
installBean(messageFlusher);
}

public QpackDecoder getQpackDecoder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public HTTP3Client(ClientQuicConfiguration quicConfiguration, ClientConnector co
{
this.quicConfiguration = quicConfiguration;
this.connector = connector;
addBean(connector);
installBean(connector);
connector.setSslContextFactory(quicConfiguration.getSslContextFactory());
// Allow the mandatory unidirectional streams, plus pushed streams.
quicConfiguration.setMaxUnidirectionalRemoteStreams(48);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ServerHTTP3Session(HTTP3Configuration configuration, ServerQuicSession qu
super(quicSession);
this.configuration = configuration;
session = new HTTP3SessionServer(this, listener);
addBean(session);
installBean(session);
session.setStreamIdleTimeout(configuration.getStreamIdleTimeout());

if (LOG.isDebugEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public ClientConnector()
public ClientConnector(Configurator configurator)
{
this.configurator = Objects.requireNonNull(configurator);
addBean(configurator);
installBean(configurator);
configurator.addBean(this, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ManagedSelector(SelectorManager selectorManager, int id)
SelectorProducer producer = new SelectorProducer();
Executor executor = selectorManager.getExecutor();
_strategy = new AdaptiveExecutionStrategy(producer, executor);
addBean(_strategy, true);
installBean(_strategy, true);
}

public Selector getSelector()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public OpenIdConfiguration(@Name("issuer") String issuer,
if (this.issuer == null)
throw new IllegalArgumentException("Issuer was not configured");

addBean(this.httpClient);
installBean(this.httpClient);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public OpenIdLoginService(OpenIdConfiguration configuration, LoginService loginS
{
this.configuration = Objects.requireNonNull(configuration);
this.loginService = loginService;
addBean(this.configuration);
addBean(this.loginService);
installBean(this.configuration);
installBean(this.loginService);

setAuthenticateNewUsers(configuration.isAuthenticateNewUsers());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Dictionary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ProtocolSession(QuicSession session)
{
this.session = session;
this.strategy = new AdaptiveExecutionStrategy(producer, session.getExecutor());
addBean(strategy);
installBean(strategy);
}

public QuicSession getQuicSession()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected QuicSession(Executor executor, Scheduler scheduler, ByteBufferPool byt
this.quicheConnection = quicheConnection;
this.connection = connection;
this.flusher = new Flusher(scheduler);
addBean(flusher);
installBean(flusher);
this.remoteAddress = remoteAddress;
Arrays.setAll(ids, i -> new AtomicLong());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public RewriteHandler(Handler handler, RuleContainer rules)
{
super(handler);
_rules = rules;
addBean(_rules);
installBean(_rules);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class AbstractLoginService extends ContainerLifeCycle implements

protected AbstractLoginService()
{
addBean(_identityService);
installBean(_identityService);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public SPNEGOLoginService(String realm, LoginService loginService)
{
_realm = realm;
_loginService = loginService;
addBean(_loginService);
installBean(_loginService);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected SecurityHandler()
protected SecurityHandler(Handler handler)
{
super(handler);
addBean(new DumpableCollection("knownAuthenticatorFactories", __knownAuthenticatorFactories));
installBean(new DumpableCollection("knownAuthenticatorFactories", __knownAuthenticatorFactories));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ public AbstractConnector(
_server = Objects.requireNonNull(server);

_executor = executor != null ? executor : _server.getThreadPool();
addBean(_executor, executor != null);
installBean(_executor, executor != null);

_scheduler = scheduler != null ? scheduler : _server.getScheduler();
addBean(_scheduler, scheduler != null);
installBean(_scheduler, scheduler != null);

_bufferPool = bufferPool != null ? bufferPool : server.getByteBufferPool();
addBean(_bufferPool, bufferPool != null);
installBean(_bufferPool, bufferPool != null);

for (ConnectionFactory factory : factories)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public CustomRequestLog(RequestLog.Writer writer, String formatString)
{
_formatString = formatString;
_requestLogWriter = writer;
addBean(_requestLogWriter);
installBean(_requestLogWriter);

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public DetectorConnectionFactory(Detecting... detectingConnectionFactories)
_detectingConnectionFactories = Arrays.asList(detectingConnectionFactories);
for (Detecting detectingConnectionFactory : detectingConnectionFactories)
{
addBean(detectingConnectionFactory);
installBean(detectingConnectionFactory);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ default Singleton getTail()
}

/**
* <p>Utility method to perform sanity checks before adding the given {@code Handler} to
* <p>Utility method to perform sanity checks before updating the given {@code Handler} to
* the given {@code Singleton}, typically used in implementations of {@link #setHandler(Handler)}.</p>
* <p>The sanity checks are:</p>
* <ul>
Expand All @@ -364,15 +364,41 @@ default Singleton getTail()
* <li>Sets the {@code Server} on the {@code Handler}</li>
* <li>Update the beans on the {@code Singleton} if it is a {@link ContainerLifeCycle}</li>
* </ul>
* @param singleton the {@code Singleton} to set the {@code Handler}
* @param handler the {@code Handler} to set
* @see #checkHandler(Singleton, Handler)
* @return The {@code Handler} to set
*/
static Handler updateHandler(Singleton singleton, Handler handler)
{
// check state
checkHandler(singleton, handler);

if (singleton instanceof org.eclipse.jetty.util.component.ContainerLifeCycle container)
container.updateBean(singleton.getHandler(), handler);

return handler;
}

/**
* <p>Utility method to perform sanity checks on a {{@link Handler} to be added to
* the given {@code Singleton}.</p>
* <p>The sanity checks are:</p>
* <ul>
* <li>Check for the server start state and whether the invocation type is compatible</li>
* <li>Check for {@code Handler} loops</li>
* <li>Sets the {@code Server} on the {@code Handler}</li>
* <li>Update the beans on the {@code Singleton} if it is a {@link ContainerLifeCycle}</li>
* </ul>
*
* @param wrapper the {@code Singleton} to set the {@code Handler}
* @param singleton the {@code Singleton} to set the {@code Handler}
* @param handler the {@code Handler} to set
* @return The {@code Handler} to set
*/
static Handler updateHandler(Singleton wrapper, Handler handler)
static Handler checkHandler(Singleton singleton, Handler handler)
{
// check state
Server server = wrapper.getServer();
Server server = singleton.getServer();

// If the collection is changed whilst started, then the risk is that if we switch from NON_BLOCKING to BLOCKING
// whilst the execution strategy may have already dispatched the very last available thread, thinking it would
Expand All @@ -386,16 +412,13 @@ static Handler updateHandler(Singleton wrapper, Handler handler)
}

// Check for loops.
if (handler == wrapper || (handler instanceof Handler.Container container &&
container.getDescendants().contains(wrapper)))
if (handler == singleton || (handler instanceof Handler.Container container &&
container.getDescendants().contains(singleton)))
throw new IllegalStateException("Handler loop");

if (handler != null && server != null)
handler.setServer(server);

if (wrapper instanceof org.eclipse.jetty.util.component.ContainerLifeCycle container)
container.updateBean(wrapper.getHandler(), handler);

return handler;
}
}
Expand Down Expand Up @@ -692,7 +715,8 @@ public Wrapper(Handler handler)
public Wrapper(boolean dynamic, Handler handler)
{
super(dynamic);
_handler = handler == null ? null : Singleton.updateHandler(this, handler);
_handler = handler == null ? null : Singleton.checkHandler(this, handler);
installBean(_handler);
}

@Override
Expand Down
Loading
Loading