From 8197c1232547c66993cd597145c473a45a527f61 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 6 Feb 2020 16:32:19 +0100 Subject: [PATCH] Code cleanup. Signed-off-by: Simone Bordet --- .../jetty/server/AbstractConnector.java | 53 ++++++++----------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java index 56a225803a8..51624b0fceb 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java @@ -181,12 +181,17 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co { _server = server; _executor = executor != null ? executor : _server.getThreadPool(); + addBean(_executor); + if (executor == null) + unmanage(_executor); // inherited from server if (scheduler == null) scheduler = _server.getBean(Scheduler.class); _scheduler = scheduler != null ? scheduler : new ScheduledExecutorScheduler(String.format("Connector-Scheduler-%x", hashCode()), false); + addBean(_scheduler); if (pool == null) pool = _server.getBean(ByteBufferPool.class); _byteBufferPool = pool != null ? pool : new ArrayByteBufferPool(); + addBean(_byteBufferPool); addEventListener(new Container.Listener() { @@ -205,13 +210,6 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co } }); - addBean(_server, false); - addBean(_executor); - if (executor == null) - unmanage(_executor); // inherited from server - addBean(_scheduler); - addBean(_byteBufferPool); - for (ConnectionFactory factory : factories) { addConnectionFactory(factory); @@ -380,7 +378,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co // Reduce the idle timeout of existing connections for (EndPoint ep : _endpoints) - ep.setIdleTimeout(_shutdownIdleTimeout); + ep.setIdleTimeout(getShutdownIdleTimeout()); // Return Future that waits for no acceptors and no connections. return done; @@ -519,35 +517,23 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co throw new IllegalStateException(getState()); List existings = new ArrayList<>(_factories.values()); - _factories.clear(); + clearConnectionFactories(); addConnectionFactory(factory); for (ConnectionFactory existing : existings) { addConnectionFactory(existing); } - _defaultProtocol = factory.getProtocol(); } + // Used from XML, do not remove. public void addIfAbsentConnectionFactory(ConnectionFactory factory) { if (isRunning()) throw new IllegalStateException(getState()); String key = StringUtil.asciiToLowerCase(factory.getProtocol()); - if (_factories.containsKey(key)) - { - if (LOG.isDebugEnabled()) - LOG.debug("{} addIfAbsent ignored {}", this, factory); - } - else - { - _factories.put(key, factory); - addBean(factory); - if (_defaultProtocol == null) - _defaultProtocol = factory.getProtocol(); - if (LOG.isDebugEnabled()) - LOG.debug("{} addIfAbsent added {}", this, factory); - } + if (!_factories.containsKey(key)) + addConnectionFactory(factory); } public ConnectionFactory removeConnectionFactory(String protocol) @@ -556,6 +542,8 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co throw new IllegalStateException(getState()); ConnectionFactory factory = _factories.remove(StringUtil.asciiToLowerCase(protocol)); + if (_factories.isEmpty()) + _defaultProtocol = null; removeBean(factory); return factory; } @@ -583,6 +571,15 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co } } + public void clearConnectionFactories() + { + if (isRunning()) + throw new IllegalStateException(getState()); + + _factories.clear(); + _defaultProtocol = null; + } + @ManagedAttribute("The priority delta to apply to acceptor threads") public int getAcceptorPriorityDelta() { @@ -618,14 +615,6 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co return new ArrayList<>(_factories.keySet()); } - public void clearConnectionFactories() - { - if (isRunning()) - throw new IllegalStateException(getState()); - - _factories.clear(); - } - @ManagedAttribute("This connector's default protocol") public String getDefaultProtocol() {