diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectorHttpClientTransport.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectorHttpClientTransport.java index 2845f1fbf929..e6d717f3aeb8 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectorHttpClientTransport.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectorHttpClientTransport.java @@ -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() diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java index 100376aff51d..7edbf36e20b2 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java @@ -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() diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpClientTransportDynamic.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpClientTransportDynamic.java index 8f7da5848174..31f2d5fbcf3e 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpClientTransportDynamic.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpClientTransportDynamic.java @@ -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) ); diff --git a/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java b/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java index 44278c50c3a2..01d395d5699c 100644 --- a/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java +++ b/jetty-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java @@ -90,7 +90,7 @@ protected ScanningAppProvider() protected ScanningAppProvider(FilenameFilter filter) { _filenameFilter = filter; - addBean(_appMap); + installBean(_appMap); } @Override diff --git a/jetty-core/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/DelegatingThreadPool.java b/jetty-core/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/DelegatingThreadPool.java index 37af842dad5c..7c3e202eea36 100644 --- a/jetty-core/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/DelegatingThreadPool.java +++ b/jetty-core/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/DelegatingThreadPool.java @@ -33,7 +33,7 @@ public DelegatingThreadPool(Executor executor) { _executor = executor; _tryExecutor = TryExecutor.asTryExecutor(executor); - addBean(_executor); + installBean(_executor); } public Executor getExecutor() diff --git a/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/ClientConnectionFactoryOverHTTP2.java b/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/ClientConnectionFactoryOverHTTP2.java index 567f27db9392..2958bf141ced 100644 --- a/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/ClientConnectionFactoryOverHTTP2.java +++ b/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/ClientConnectionFactoryOverHTTP2.java @@ -43,7 +43,7 @@ public class ClientConnectionFactoryOverHTTP2 extends ContainerLifeCycle impleme public ClientConnectionFactoryOverHTTP2(HTTP2Client http2Client) { this.http2Client = http2Client; - addBean(http2Client); + installBean(http2Client); } @Override diff --git a/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/HttpClientTransportOverHTTP2.java b/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/HttpClientTransportOverHTTP2.java index cd56a974030e..a5178b522418 100644 --- a/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/HttpClientTransportOverHTTP2.java +++ b/jetty-core/jetty-http2/jetty-http2-client-transport/src/main/java/org/eclipse/jetty/http2/client/transport/HttpClientTransportOverHTTP2.java @@ -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(); diff --git a/jetty-core/jetty-http2/jetty-http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java b/jetty-core/jetty-http2/jetty-http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java index 77263270b914..b49687bac794 100644 --- a/jetty-core/jetty-http2/jetty-http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java +++ b/jetty-core/jetty-http2/jetty-http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java @@ -127,7 +127,7 @@ public HTTP2Client() public HTTP2Client(ClientConnector connector) { this.connector = connector; - addBean(connector); + installBean(connector); } public ClientConnector getClientConnector() diff --git a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java index 0b0a753d2495..43e24fea1183 100644 --- a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java +++ b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java @@ -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 diff --git a/jetty-core/jetty-http2/jetty-http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java b/jetty-core/jetty-http2/jetty-http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java index bcd57d9172ec..3b69140b4d76 100644 --- a/jetty-core/jetty-http2/jetty-http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java +++ b/jetty-core/jetty-http2/jetty-http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java @@ -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()); diff --git a/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/ClientConnectionFactoryOverHTTP3.java b/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/ClientConnectionFactoryOverHTTP3.java index f6fa9a5a6dcd..a27ee788578f 100644 --- a/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/ClientConnectionFactoryOverHTTP3.java +++ b/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/ClientConnectionFactoryOverHTTP3.java @@ -35,7 +35,7 @@ public class ClientConnectionFactoryOverHTTP3 extends ContainerLifeCycle impleme public ClientConnectionFactoryOverHTTP3(HTTP3Client http3Client) { - addBean(http3Client); + installBean(http3Client); } @Override diff --git a/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/HttpClientTransportOverHTTP3.java b/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/HttpClientTransportOverHTTP3.java index ef2b3bc65234..490ae2970f48 100644 --- a/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/HttpClientTransportOverHTTP3.java +++ b/jetty-core/jetty-http3/jetty-http3-client-transport/src/main/java/org/eclipse/jetty/http3/client/transport/HttpClientTransportOverHTTP3.java @@ -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(); diff --git a/jetty-core/jetty-http3/jetty-http3-client/src/main/java/org/eclipse/jetty/http3/client/ClientHTTP3Session.java b/jetty-core/jetty-http3/jetty-http3-client/src/main/java/org/eclipse/jetty/http3/client/ClientHTTP3Session.java index 50c87abeeecb..34869280a893 100644 --- a/jetty-core/jetty-http3/jetty-http3-client/src/main/java/org/eclipse/jetty/http3/client/ClientHTTP3Session.java +++ b/jetty-core/jetty-http3/jetty-http3-client/src/main/java/org/eclipse/jetty/http3/client/ClientHTTP3Session.java @@ -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()) @@ -69,7 +69,7 @@ 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); @@ -77,19 +77,19 @@ public ClientHTTP3Session(HTTP3Configuration configuration, ClientQuicSession qu 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() diff --git a/jetty-core/jetty-http3/jetty-http3-client/src/main/java/org/eclipse/jetty/http3/client/HTTP3Client.java b/jetty-core/jetty-http3/jetty-http3-client/src/main/java/org/eclipse/jetty/http3/client/HTTP3Client.java index b8bfe7f32010..922c051ed3e4 100644 --- a/jetty-core/jetty-http3/jetty-http3-client/src/main/java/org/eclipse/jetty/http3/client/HTTP3Client.java +++ b/jetty-core/jetty-http3/jetty-http3-client/src/main/java/org/eclipse/jetty/http3/client/HTTP3Client.java @@ -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); diff --git a/jetty-core/jetty-http3/jetty-http3-server/src/main/java/org/eclipse/jetty/http3/server/internal/ServerHTTP3Session.java b/jetty-core/jetty-http3/jetty-http3-server/src/main/java/org/eclipse/jetty/http3/server/internal/ServerHTTP3Session.java index 4cd60a409829..0bf47b12e260 100644 --- a/jetty-core/jetty-http3/jetty-http3-server/src/main/java/org/eclipse/jetty/http3/server/internal/ServerHTTP3Session.java +++ b/jetty-core/jetty-http3/jetty-http3-server/src/main/java/org/eclipse/jetty/http3/server/internal/ServerHTTP3Session.java @@ -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()) diff --git a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java index 0d4a4bdf90da..b08dac5a5837 100644 --- a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java +++ b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java @@ -122,7 +122,7 @@ public ClientConnector() public ClientConnector(Configurator configurator) { this.configurator = Objects.requireNonNull(configurator); - addBean(configurator); + installBean(configurator); configurator.addBean(this, false); } diff --git a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java index 265e890f8bb6..c78d7bb7bf94 100644 --- a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java +++ b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java @@ -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() diff --git a/jetty-core/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdConfiguration.java b/jetty-core/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdConfiguration.java index 0a6f96a06e54..fcd9049c990d 100644 --- a/jetty-core/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdConfiguration.java +++ b/jetty-core/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdConfiguration.java @@ -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 diff --git a/jetty-core/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdLoginService.java b/jetty-core/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdLoginService.java index dc783c3f8098..f4dcb0d61404 100644 --- a/jetty-core/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdLoginService.java +++ b/jetty-core/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdLoginService.java @@ -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()); } diff --git a/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/util/Util.java b/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/util/Util.java index 7aa2fa7b7c47..282de78f31db 100644 --- a/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/util/Util.java +++ b/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/util/Util.java @@ -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; diff --git a/jetty-core/jetty-quic/jetty-quic-common/src/main/java/org/eclipse/jetty/quic/common/ProtocolSession.java b/jetty-core/jetty-quic/jetty-quic-common/src/main/java/org/eclipse/jetty/quic/common/ProtocolSession.java index 7eb2fd1a48b2..452fdcbacc02 100644 --- a/jetty-core/jetty-quic/jetty-quic-common/src/main/java/org/eclipse/jetty/quic/common/ProtocolSession.java +++ b/jetty-core/jetty-quic/jetty-quic-common/src/main/java/org/eclipse/jetty/quic/common/ProtocolSession.java @@ -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() diff --git a/jetty-core/jetty-quic/jetty-quic-common/src/main/java/org/eclipse/jetty/quic/common/QuicSession.java b/jetty-core/jetty-quic/jetty-quic-common/src/main/java/org/eclipse/jetty/quic/common/QuicSession.java index 664522383b34..c853fd1aec86 100644 --- a/jetty-core/jetty-quic/jetty-quic-common/src/main/java/org/eclipse/jetty/quic/common/QuicSession.java +++ b/jetty-core/jetty-quic/jetty-quic-common/src/main/java/org/eclipse/jetty/quic/common/QuicSession.java @@ -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()); } diff --git a/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewriteHandler.java b/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewriteHandler.java index 82648394030a..72660597b355 100644 --- a/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewriteHandler.java +++ b/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewriteHandler.java @@ -60,7 +60,7 @@ public RewriteHandler(Handler handler, RuleContainer rules) { super(handler); _rules = rules; - addBean(_rules); + installBean(_rules); } /** diff --git a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java b/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java index af5fb04a3a5d..a04def5f1386 100644 --- a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java +++ b/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java @@ -40,7 +40,7 @@ public abstract class AbstractLoginService extends ContainerLifeCycle implements protected AbstractLoginService() { - addBean(_identityService); + installBean(_identityService); } @Override diff --git a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/SPNEGOLoginService.java b/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/SPNEGOLoginService.java index ee45735ba79c..ec95a5fdd9a7 100644 --- a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/SPNEGOLoginService.java +++ b/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/SPNEGOLoginService.java @@ -67,7 +67,7 @@ public SPNEGOLoginService(String realm, LoginService loginService) { _realm = realm; _loginService = loginService; - addBean(_loginService); + installBean(_loginService); } /** diff --git a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java b/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java index 6d16baf2bda7..eba634c5bed7 100644 --- a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java +++ b/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java @@ -98,7 +98,7 @@ protected SecurityHandler() protected SecurityHandler(Handler handler) { super(handler); - addBean(new DumpableCollection("knownAuthenticatorFactories", __knownAuthenticatorFactories)); + installBean(new DumpableCollection("knownAuthenticatorFactories", __knownAuthenticatorFactories)); } /** diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java index b50095800557..5be4f03d2a35 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java @@ -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) { diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java index c3c04f910a12..2c9f3e716c67 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java @@ -336,7 +336,7 @@ public CustomRequestLog(RequestLog.Writer writer, String formatString) { _formatString = formatString; _requestLogWriter = writer; - addBean(_requestLogWriter); + installBean(_requestLogWriter); try { diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/DetectorConnectionFactory.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/DetectorConnectionFactory.java index befd3afe2f36..c68a69e6324c 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/DetectorConnectionFactory.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/DetectorConnectionFactory.java @@ -49,7 +49,7 @@ public DetectorConnectionFactory(Detecting... detectingConnectionFactories) _detectingConnectionFactories = Arrays.asList(detectingConnectionFactories); for (Detecting detectingConnectionFactory : detectingConnectionFactories) { - addBean(detectingConnectionFactory); + installBean(detectingConnectionFactory); } } diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Handler.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Handler.java index 691a741f67ca..3344f065d25c 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Handler.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Handler.java @@ -355,7 +355,7 @@ default Singleton getTail() } /** - *
Utility method to perform sanity checks before adding the given {@code Handler} to + *
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)}.
*The sanity checks are:
*Utility method to perform sanity checks on a {{@link Handler} to be added to + * the given {@code Singleton}.
+ *The sanity checks are:
+ *This method should not be called from a constructor, instead use {@link #installBean(Object)}
* * @param o the bean object to add * @return true if the bean was added, false if it was already present @@ -309,12 +310,12 @@ public boolean addBean(Object o) { if (o instanceof LifeCycle l) return addBean(o, l.isRunning() ? Managed.UNMANAGED : Managed.AUTO); - return addBean(o, Managed.POJO); } /** - * Adds the given bean, explicitly managing it or not. + *Adds the given bean, explicitly managing it or not.
+ *This method should not be called from a constructor, instead use {@link #installBean(Object)}
* * @param o The bean object to add * @param managed whether to manage the lifecycle of the bean @@ -413,6 +414,56 @@ else if (isStarted()) return true; } + /** + * Add a bean in a way that is safe to call from a super constructor of this {@code ContainerLifeCycle}: + * there are no {@link Container.Listener}s registered; + * the object itself is not a {@link Container.Listener}; + * this {@link LifeCycle} is not started or starting; + * and the is no debugging call to {@code this.toString()}. + * @param o The bean to add + * @return true if the bean was added + */ + protected final boolean installBean(Object o) + { + return installBean(o, o instanceof LifeCycle l ? (l.isRunning() ? Managed.UNMANAGED : Managed.AUTO) : Managed.POJO); + } + + /** + * Add a bean in a way that is safe to call from a super constructor of this {@code ContainerLifeCycle}: + * there are no {@link Container.Listener}s registered; + * the object itself is not a {@link Container.Listener}; + * this {@link LifeCycle} is not started or starting; + * and the is no debugging call to {@code this.toString()}. + * @param o The bean to add + * @param managed true if the bean is to be managed. + * @return true if the bean was added + */ + protected final boolean installBean(Object o, boolean managed) + { + return installBean(o, o instanceof LifeCycle + ? (managed ? Managed.MANAGED : Managed.UNMANAGED) + : (managed ? Managed.POJO : Managed.UNMANAGED)); + } + + private boolean installBean(Object o, Managed managed) + { + if (o == null || contains(o)) + return false; + if (o instanceof Container.Listener || !_listeners.isEmpty()) + throw new IllegalArgumentException("Cannot call Container.Listeners from constructor"); + + if (o instanceof EventListener eventListener) + addEventListener(eventListener); + + Bean newBean = new Bean(o); + newBean._managed = managed; + _beans.add(newBean); + + if (LOG.isDebugEnabled()) + LOG.debug("{}@{} added {}", getClass().getSimpleName(), hashCode(), newBean); + return true; + } + /** * Adds a managed lifecycle. *This is a convenience method that uses addBean(lifecycle,true)
diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/KeyStoreScanner.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/KeyStoreScanner.java
index 1be738b27889..6f823479d873 100644
--- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/KeyStoreScanner.java
+++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/KeyStoreScanner.java
@@ -68,7 +68,7 @@ public KeyStoreScanner(SslContextFactory sslContextFactory)
_scanner.setReportExistingFilesOnStartup(false);
_scanner.setScanDepth(1);
_scanner.addListener(this);
- addBean(_scanner);
+ installBean(_scanner);
}
private Path getRealKeyStorePath()
diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/MonitoredQueuedThreadPool.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/MonitoredQueuedThreadPool.java
index fdc39f85b1b2..275608eb6339 100644
--- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/MonitoredQueuedThreadPool.java
+++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/MonitoredQueuedThreadPool.java
@@ -47,10 +47,10 @@ public MonitoredQueuedThreadPool(int maxThreads)
public MonitoredQueuedThreadPool(int maxThreads, int minThreads, int idleTimeOut, BlockingQueue