Issue #6566 - fix WebSocketComponents LifeCycle issue

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2021-08-04 13:28:10 +10:00
parent bbabaee8cc
commit 14c09e3c98
2 changed files with 47 additions and 37 deletions

View File

@ -31,12 +31,12 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
*/ */
public class WebSocketComponents extends ContainerLifeCycle public class WebSocketComponents extends ContainerLifeCycle
{ {
private final DecoratedObjectFactory objectFactory; private final DecoratedObjectFactory _objectFactory;
private final WebSocketExtensionRegistry extensionRegistry; private final WebSocketExtensionRegistry _extensionRegistry;
private final Executor executor; private final Executor _executor;
private final ByteBufferPool bufferPool; private final ByteBufferPool _bufferPool;
private final InflaterPool inflaterPool; private final InflaterPool _inflaterPool;
private final DeflaterPool deflaterPool; private final DeflaterPool _deflaterPool;
public WebSocketComponents() public WebSocketComponents()
{ {
@ -52,48 +52,48 @@ public class WebSocketComponents extends ContainerLifeCycle
public WebSocketComponents(WebSocketExtensionRegistry extensionRegistry, DecoratedObjectFactory objectFactory, public WebSocketComponents(WebSocketExtensionRegistry extensionRegistry, DecoratedObjectFactory objectFactory,
ByteBufferPool bufferPool, InflaterPool inflaterPool, DeflaterPool deflaterPool, Executor executor) ByteBufferPool bufferPool, InflaterPool inflaterPool, DeflaterPool deflaterPool, Executor executor)
{ {
this.extensionRegistry = (extensionRegistry == null) ? new WebSocketExtensionRegistry() : extensionRegistry; _extensionRegistry = (extensionRegistry == null) ? new WebSocketExtensionRegistry() : extensionRegistry;
this.objectFactory = (objectFactory == null) ? new DecoratedObjectFactory() : objectFactory; _objectFactory = (objectFactory == null) ? new DecoratedObjectFactory() : objectFactory;
this.bufferPool = (bufferPool == null) ? new MappedByteBufferPool() : bufferPool; _bufferPool = (bufferPool == null) ? new MappedByteBufferPool() : bufferPool;
this.inflaterPool = (inflaterPool == null) ? new InflaterPool(CompressionPool.DEFAULT_CAPACITY, true) : inflaterPool; _inflaterPool = (inflaterPool == null) ? new InflaterPool(CompressionPool.DEFAULT_CAPACITY, true) : inflaterPool;
this.deflaterPool = (deflaterPool == null) ? new DeflaterPool(CompressionPool.DEFAULT_CAPACITY, Deflater.DEFAULT_COMPRESSION, true) : deflaterPool; _deflaterPool = (deflaterPool == null) ? new DeflaterPool(CompressionPool.DEFAULT_CAPACITY, Deflater.DEFAULT_COMPRESSION, true) : deflaterPool;
this.executor = (executor == null) ? new QueuedThreadPool() : executor; _executor = (executor == null) ? new QueuedThreadPool() : executor;
addBean(inflaterPool); addBean(_inflaterPool);
addBean(deflaterPool); addBean(_deflaterPool);
addBean(bufferPool); addBean(_bufferPool);
addBean(extensionRegistry); addBean(_extensionRegistry);
addBean(objectFactory); addBean(_objectFactory);
addBean(executor); addBean(_executor);
} }
public ByteBufferPool getBufferPool() public ByteBufferPool getBufferPool()
{ {
return bufferPool; return _bufferPool;
} }
public Executor getExecutor() public Executor getExecutor()
{ {
return executor; return _executor;
} }
public WebSocketExtensionRegistry getExtensionRegistry() public WebSocketExtensionRegistry getExtensionRegistry()
{ {
return extensionRegistry; return _extensionRegistry;
} }
public DecoratedObjectFactory getObjectFactory() public DecoratedObjectFactory getObjectFactory()
{ {
return objectFactory; return _objectFactory;
} }
public InflaterPool getInflaterPool() public InflaterPool getInflaterPool()
{ {
return inflaterPool; return _inflaterPool;
} }
public DeflaterPool getDeflaterPool() public DeflaterPool getDeflaterPool()
{ {
return deflaterPool; return _deflaterPool;
} }
} }

View File

@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.WebSocketConnectionListener; import org.eclipse.jetty.websocket.api.WebSocketConnectionListener;
@ -46,6 +47,10 @@ public class JettyWebSocketFrameHandlerTest
{ {
private static DummyContainer container; private static DummyContainer container;
private final WebSocketComponents components;
private final JettyWebSocketFrameHandlerFactory endpointFactory;
private final CoreSession coreSession;
@BeforeAll @BeforeAll
public static void startContainer() throws Exception public static void startContainer() throws Exception
{ {
@ -59,9 +64,11 @@ public class JettyWebSocketFrameHandlerTest
container.stop(); container.stop();
} }
private final WebSocketComponents components = new WebSocketComponents(); public JettyWebSocketFrameHandlerTest()
private final JettyWebSocketFrameHandlerFactory endpointFactory = new JettyWebSocketFrameHandlerFactory(container, components); {
private final CoreSession coreSession = new CoreSession.Empty() components = new WebSocketComponents();
endpointFactory = new JettyWebSocketFrameHandlerFactory(container, components);
coreSession = new CoreSession.Empty()
{ {
@Override @Override
public Behavior getBehavior() public Behavior getBehavior()
@ -76,6 +83,9 @@ public class JettyWebSocketFrameHandlerTest
} }
}; };
LifeCycle.start(components);
}
private JettyWebSocketFrameHandler newLocalFrameHandler(Object wsEndpoint) private JettyWebSocketFrameHandler newLocalFrameHandler(Object wsEndpoint)
{ {
return endpointFactory.newJettyFrameHandler(wsEndpoint); return endpointFactory.newJettyFrameHandler(wsEndpoint);