Skip to content

Commit

Permalink
Issue #6566 - fix WebSocketComponents LifeCycle issue
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <[email protected]>
  • Loading branch information
lachlan-roberts committed Aug 4, 2021
1 parent bbabaee commit 14c09e3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
*/
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()
{
Expand All @@ -52,48 +52,48 @@ public WebSocketComponents(WebSocketExtensionRegistry extensionRegistry, Decorat
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

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;
Expand All @@ -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
{
Expand All @@ -59,22 +64,27 @@ public static void stopContainer() throws Exception
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()
{
return Behavior.CLIENT;
}

@Override
public WebSocketComponents getWebSocketComponents()
components = new WebSocketComponents();
endpointFactory = new JettyWebSocketFrameHandlerFactory(container, components);
coreSession = new CoreSession.Empty()
{
return components;
}
};
@Override
public Behavior getBehavior()
{
return Behavior.CLIENT;
}

@Override
public WebSocketComponents getWebSocketComponents()
{
return components;
}
};

LifeCycle.start(components);
}

private JettyWebSocketFrameHandler newLocalFrameHandler(Object wsEndpoint)
{
Expand Down

0 comments on commit 14c09e3

Please sign in to comment.