allow override of shared CompressionPools in WebSocketServerComponents
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
0e3cfe8fc2
commit
4690aa51ba
|
@ -20,7 +20,7 @@ package org.eclipse.jetty.util.compression;
|
||||||
|
|
||||||
import java.util.zip.Deflater;
|
import java.util.zip.Deflater;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
import org.eclipse.jetty.util.component.Container;
|
||||||
import org.eclipse.jetty.util.thread.ThreadPool;
|
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||||
|
|
||||||
public class DeflaterPool extends CompressionPool<Deflater>
|
public class DeflaterPool extends CompressionPool<Deflater>
|
||||||
|
@ -64,19 +64,19 @@ public class DeflaterPool extends CompressionPool<Deflater>
|
||||||
deflater.reset();
|
deflater.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DeflaterPool ensurePool(ContainerLifeCycle containerLifeCycle)
|
public static DeflaterPool ensurePool(Container container)
|
||||||
{
|
{
|
||||||
DeflaterPool pool = containerLifeCycle.getBean(DeflaterPool.class);
|
DeflaterPool pool = container.getBean(DeflaterPool.class);
|
||||||
if (pool != null)
|
if (pool != null)
|
||||||
return pool;
|
return pool;
|
||||||
|
|
||||||
int capacity = CompressionPool.DEFAULT_CAPACITY;
|
int capacity = CompressionPool.DEFAULT_CAPACITY;
|
||||||
ThreadPool.SizedThreadPool threadPool = containerLifeCycle.getBean(ThreadPool.SizedThreadPool.class);
|
ThreadPool.SizedThreadPool threadPool = container.getBean(ThreadPool.SizedThreadPool.class);
|
||||||
if (threadPool != null)
|
if (threadPool != null)
|
||||||
capacity = threadPool.getMaxThreads();
|
capacity = threadPool.getMaxThreads();
|
||||||
|
|
||||||
pool = new DeflaterPool(capacity, Deflater.DEFAULT_COMPRESSION, true);
|
pool = new DeflaterPool(capacity, Deflater.DEFAULT_COMPRESSION, true);
|
||||||
containerLifeCycle.addBean(pool);
|
container.addBean(pool);
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.eclipse.jetty.util.compression;
|
||||||
|
|
||||||
import java.util.zip.Inflater;
|
import java.util.zip.Inflater;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
import org.eclipse.jetty.util.component.Container;
|
||||||
import org.eclipse.jetty.util.thread.ThreadPool;
|
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||||
|
|
||||||
public class InflaterPool extends CompressionPool<Inflater>
|
public class InflaterPool extends CompressionPool<Inflater>
|
||||||
|
@ -61,19 +61,19 @@ public class InflaterPool extends CompressionPool<Inflater>
|
||||||
inflater.reset();
|
inflater.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InflaterPool ensurePool(ContainerLifeCycle containerLifeCycle)
|
public static InflaterPool ensurePool(Container container)
|
||||||
{
|
{
|
||||||
InflaterPool pool = containerLifeCycle.getBean(InflaterPool.class);
|
InflaterPool pool = container.getBean(InflaterPool.class);
|
||||||
if (pool != null)
|
if (pool != null)
|
||||||
return pool;
|
return pool;
|
||||||
|
|
||||||
int capacity = CompressionPool.DEFAULT_CAPACITY;
|
int capacity = CompressionPool.DEFAULT_CAPACITY;
|
||||||
ThreadPool.SizedThreadPool threadPool = containerLifeCycle.getBean(ThreadPool.SizedThreadPool.class);
|
ThreadPool.SizedThreadPool threadPool = container.getBean(ThreadPool.SizedThreadPool.class);
|
||||||
if (threadPool != null)
|
if (threadPool != null)
|
||||||
capacity = threadPool.getMaxThreads();
|
capacity = threadPool.getMaxThreads();
|
||||||
|
|
||||||
pool = new InflaterPool(capacity, true);
|
pool = new InflaterPool(capacity, true);
|
||||||
containerLifeCycle.addBean(pool);
|
container.addBean(pool);
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,8 @@ import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
|
||||||
public class WebSocketServerComponents extends WebSocketComponents
|
public class WebSocketServerComponents extends WebSocketComponents
|
||||||
{
|
{
|
||||||
public static final String WEBSOCKET_COMPONENTS_ATTRIBUTE = WebSocketComponents.class.getName();
|
public static final String WEBSOCKET_COMPONENTS_ATTRIBUTE = WebSocketComponents.class.getName();
|
||||||
|
public static final String WEBSOCKET_INFLATER_POOL_ATTRIBUTE = "jetty.websocket.inflater";
|
||||||
|
public static final String WEBSOCKET_DEFLATER_POOL_ATTRIBUTE = "jetty.websocket.deflater";
|
||||||
|
|
||||||
WebSocketServerComponents(InflaterPool inflaterPool, DeflaterPool deflaterPool)
|
WebSocketServerComponents(InflaterPool inflaterPool, DeflaterPool deflaterPool)
|
||||||
{
|
{
|
||||||
|
@ -49,8 +51,14 @@ public class WebSocketServerComponents extends WebSocketComponents
|
||||||
WebSocketComponents components = server.getBean(WebSocketComponents.class);
|
WebSocketComponents components = server.getBean(WebSocketComponents.class);
|
||||||
if (components == null)
|
if (components == null)
|
||||||
{
|
{
|
||||||
InflaterPool inflaterPool = InflaterPool.ensurePool(server);
|
InflaterPool inflaterPool = (InflaterPool)servletContext.getAttribute(WEBSOCKET_INFLATER_POOL_ATTRIBUTE);
|
||||||
DeflaterPool deflaterPool = DeflaterPool.ensurePool(server);
|
if (inflaterPool == null)
|
||||||
|
inflaterPool = InflaterPool.ensurePool(server);
|
||||||
|
|
||||||
|
DeflaterPool deflaterPool = (DeflaterPool)servletContext.getAttribute(WEBSOCKET_DEFLATER_POOL_ATTRIBUTE);
|
||||||
|
if (deflaterPool == null)
|
||||||
|
deflaterPool = DeflaterPool.ensurePool(server);
|
||||||
|
|
||||||
components = new WebSocketServerComponents(inflaterPool, deflaterPool);
|
components = new WebSocketServerComponents(inflaterPool, deflaterPool);
|
||||||
server.addBean(components);
|
server.addBean(components);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue