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
{
private final DecoratedObjectFactory objectFactory;
private final WebSocketExtensionRegistry extensionRegistry;
private final Executor executor;
private final ByteBufferPool bufferPool;
private final InflaterPool inflaterPool;
private final DeflaterPool deflaterPool;
private final DecoratedObjectFactory _objectFactory;
private final WebSocketExtensionRegistry _extensionRegistry;
private final Executor _executor;
private final ByteBufferPool _bufferPool;
private final InflaterPool _inflaterPool;
private final DeflaterPool _deflaterPool;
public WebSocketComponents()
{
@ -52,48 +52,48 @@ public class WebSocketComponents extends ContainerLifeCycle
public WebSocketComponents(WebSocketExtensionRegistry extensionRegistry, DecoratedObjectFactory objectFactory,
ByteBufferPool bufferPool, InflaterPool inflaterPool, DeflaterPool deflaterPool, Executor executor)
{
this.extensionRegistry = (extensionRegistry == null) ? new WebSocketExtensionRegistry() : extensionRegistry;
this.objectFactory = (objectFactory == null) ? new DecoratedObjectFactory() : objectFactory;
this.bufferPool = (bufferPool == null) ? new MappedByteBufferPool() : bufferPool;
this.inflaterPool = (inflaterPool == null) ? new InflaterPool(CompressionPool.DEFAULT_CAPACITY, true) : inflaterPool;
this.deflaterPool = (deflaterPool == null) ? new DeflaterPool(CompressionPool.DEFAULT_CAPACITY, Deflater.DEFAULT_COMPRESSION, true) : deflaterPool;
this.executor = (executor == null) ? new QueuedThreadPool() : executor;
_extensionRegistry = (extensionRegistry == null) ? new WebSocketExtensionRegistry() : extensionRegistry;
_objectFactory = (objectFactory == null) ? new DecoratedObjectFactory() : objectFactory;
_bufferPool = (bufferPool == null) ? new MappedByteBufferPool() : bufferPool;
_inflaterPool = (inflaterPool == null) ? new InflaterPool(CompressionPool.DEFAULT_CAPACITY, true) : inflaterPool;
_deflaterPool = (deflaterPool == null) ? new DeflaterPool(CompressionPool.DEFAULT_CAPACITY, Deflater.DEFAULT_COMPRESSION, true) : deflaterPool;
_executor = (executor == null) ? new QueuedThreadPool() : executor;
addBean(inflaterPool);
addBean(deflaterPool);
addBean(bufferPool);
addBean(extensionRegistry);
addBean(objectFactory);
addBean(executor);
addBean(_inflaterPool);
addBean(_deflaterPool);
addBean(_bufferPool);
addBean(_extensionRegistry);
addBean(_objectFactory);
addBean(_executor);
}
public ByteBufferPool getBufferPool()
{
return bufferPool;
return _bufferPool;
}
public Executor getExecutor()
{
return executor;
return _executor;
}
public WebSocketExtensionRegistry getExtensionRegistry()
{
return extensionRegistry;
return _extensionRegistry;
}
public DecoratedObjectFactory getObjectFactory()
{
return objectFactory;
return _objectFactory;
}
public InflaterPool getInflaterPool()
{
return inflaterPool;
return _inflaterPool;
}
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.IO;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.WebSocketConnectionListener;
@ -46,6 +47,10 @@ public class JettyWebSocketFrameHandlerTest
{
private static DummyContainer container;
private final WebSocketComponents components;
private final JettyWebSocketFrameHandlerFactory endpointFactory;
private final CoreSession coreSession;
@BeforeAll
public static void startContainer() throws Exception
{
@ -59,22 +64,27 @@ public class JettyWebSocketFrameHandlerTest
container.stop();
}
private final WebSocketComponents components = new WebSocketComponents();
private final JettyWebSocketFrameHandlerFactory endpointFactory = new JettyWebSocketFrameHandlerFactory(container, components);
private final CoreSession coreSession = new CoreSession.Empty()
public JettyWebSocketFrameHandlerTest()
{
@Override
public Behavior getBehavior()
components = new WebSocketComponents();
endpointFactory = new JettyWebSocketFrameHandlerFactory(container, components);
coreSession = new CoreSession.Empty()
{
return Behavior.CLIENT;
}
@Override
public Behavior getBehavior()
{
return Behavior.CLIENT;
}
@Override
public WebSocketComponents getWebSocketComponents()
{
return components;
}
};
@Override
public WebSocketComponents getWebSocketComponents()
{
return components;
}
};
LifeCycle.start(components);
}
private JettyWebSocketFrameHandler newLocalFrameHandler(Object wsEndpoint)
{