Merge pull request #3844 from eclipse/jetty-10.0.x-300-CompressionPool

Issue #300 - Deflater / Inflater Object Pool (Jetty-10)
This commit is contained in:
Lachlan 2019-07-04 12:36:04 +10:00 committed by GitHub
commit 9d37c470d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 442 additions and 318 deletions

View File

@ -1,128 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.Deflater;
public class DeflaterPool
{
private final Queue<Deflater> _pool;
private final int _compressionLevel;
private final boolean _nowrap;
private final AtomicInteger _numDeflaters = new AtomicInteger(0);
private final int _capacity;
/**
* Create a Pool of {@link Deflater} instances.
*
* If given a capacity equal to zero the Deflaters will not be pooled
* and will be created on acquire and ended on release.
* If given a negative capacity equal to zero there will be no size restrictions on the DeflaterPool
*
* @param capacity maximum number of Deflaters which can be contained in the pool
* @param compressionLevel the default compression level for new Deflater objects
* @param nowrap if true then use GZIP compatible compression for all new Deflater objects
*/
public DeflaterPool(int capacity, int compressionLevel, boolean nowrap)
{
_capacity = capacity;
_compressionLevel = compressionLevel;
_nowrap = nowrap;
if (_capacity != 0)
_pool = new ConcurrentLinkedQueue<>();
else
_pool = null;
}
protected Deflater newDeflater()
{
return new Deflater(_compressionLevel, _nowrap);
}
/**
* @return Deflater taken from the pool if it is not empty or a newly created Deflater
*/
public Deflater acquire()
{
Deflater deflater;
if (_capacity == 0)
deflater = newDeflater();
else if (_capacity < 0)
{
deflater = _pool.poll();
if (deflater == null)
deflater = newDeflater();
}
else
{
deflater = _pool.poll();
if (deflater == null)
deflater = newDeflater();
else
_numDeflaters.decrementAndGet();
}
return deflater;
}
/**
* @param deflater returns this Deflater to the pool or calls deflater.end() if the pool is full.
*/
public void release(Deflater deflater)
{
if (deflater == null)
return;
if (_capacity == 0)
{
deflater.end();
return;
}
else if (_capacity < 0)
{
deflater.reset();
_pool.add(deflater);
}
else
{
while (true)
{
int d = _numDeflaters.get();
if (d >= _capacity)
{
deflater.end();
break;
}
if (_numDeflaters.compareAndSet(d, d + 1))
{
deflater.reset();
_pool.add(deflater);
break;
}
}
}
}
}

View File

@ -25,6 +25,7 @@ import java.util.ListIterator;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.zip.Deflater;
import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@ -39,7 +40,6 @@ import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.http.PreEncodedHttpField;
import org.eclipse.jetty.http.pathmap.PathSpecSet;
import org.eclipse.jetty.server.DeflaterPool;
import org.eclipse.jetty.server.HttpOutput;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.HandlerWrapper;
@ -47,6 +47,7 @@ import org.eclipse.jetty.util.IncludeExclude;
import org.eclipse.jetty.util.RegexSet;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.compression.DeflaterPool;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

View File

@ -31,6 +31,7 @@ module org.eclipse.jetty.util
exports org.eclipse.jetty.util.statistic;
exports org.eclipse.jetty.util.thread;
exports org.eclipse.jetty.util.thread.strategy;
exports org.eclipse.jetty.util.compression;
// Only required if using AppContextLeakPreventer/AWTLeakPreventer.
requires static java.desktop;

View File

@ -0,0 +1,128 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.util.compression;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
public abstract class CompressionPool<T> extends AbstractLifeCycle
{
public static final int INFINITE_CAPACITY = -1;
private final Queue<T> _pool;
private final AtomicInteger _numObjects = new AtomicInteger(0);
private final int _capacity;
/**
* Create a Pool of {@link T} instances.
*
* If given a capacity equal to zero the Objects will not be pooled
* and will be created on acquire and ended on release.
* If given a negative capacity equal to zero there will be no size restrictions on the Pool
*
* @param capacity maximum number of Objects which can be contained in the pool
*/
public CompressionPool(int capacity)
{
_capacity = capacity;
_pool = (_capacity == 0) ? null : new ConcurrentLinkedQueue<>();
}
abstract protected T newObject();
abstract protected void end(T object);
abstract protected void reset(T object);
/**
* @return Object taken from the pool if it is not empty or a newly created Object
*/
public T acquire()
{
T object;
if (_capacity == 0)
object = newObject();
else
{
object = _pool.poll();
if (object == null)
object = newObject();
else if (_capacity > 0)
_numObjects.decrementAndGet();
}
return object;
}
/**
* @param object returns this Object to the pool or calls {@link #end(Object)} if the pool is full.
*/
public void release(T object)
{
if (object == null)
return;
if (_capacity == 0 || !isRunning())
{
end(object);
return;
}
else if (_capacity < 0)
{
reset(object);
_pool.add(object);
}
else
{
while (true)
{
int d = _numObjects.get();
if (d >= _capacity)
{
end(object);
break;
}
if (_numObjects.compareAndSet(d, d + 1))
{
reset(object);
_pool.add(object);
break;
}
}
}
}
@Override
public void doStop()
{
T t = _pool.poll();
while (t != null)
{
end(t);
t = _pool.poll();
}
_numObjects.set(0);
}
}

View File

@ -0,0 +1,63 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.util.compression;
import java.util.zip.Deflater;
public class DeflaterPool extends CompressionPool<Deflater>
{
private final int compressionLevel;
private final boolean nowrap;
/**
* Create a Pool of {@link Deflater} instances.
* <p>
* If given a capacity equal to zero the Deflaters will not be pooled
* and will be created on acquire and ended on release.
* If given a negative capacity equal to zero there will be no size restrictions on the DeflaterPool
*
* @param capacity maximum number of Deflaters which can be contained in the pool
* @param compressionLevel the default compression level for new Deflater objects
* @param nowrap if true then use GZIP compatible compression for all new Deflater objects
*/
public DeflaterPool(int capacity, int compressionLevel, boolean nowrap)
{
super(capacity);
this.compressionLevel = compressionLevel;
this.nowrap = nowrap;
}
@Override
protected Deflater newObject()
{
return new Deflater(compressionLevel, nowrap);
}
@Override
protected void end(Deflater deflater)
{
deflater.end();
}
@Override
protected void reset(Deflater deflater)
{
deflater.reset();
}
}

View File

@ -0,0 +1,60 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.util.compression;
import java.util.zip.Inflater;
public class InflaterPool extends CompressionPool<Inflater>
{
private final boolean nowrap;
/**
* Create a Pool of {@link Inflater} instances.
* <p>
* If given a capacity equal to zero the Inflaters will not be pooled
* and will be created on acquire and ended on release.
* If given a negative capacity equal to zero there will be no size restrictions on the InflaterPool
*
* @param capacity maximum number of Inflaters which can be contained in the pool
* @param nowrap if true then use GZIP compatible compression for all new Inflater objects
*/
public InflaterPool(int capacity, boolean nowrap)
{
super(capacity);
this.nowrap = nowrap;
}
@Override
protected Inflater newObject()
{
return new Inflater(nowrap);
}
@Override
protected void end(Inflater inflater)
{
inflater.end();
}
@Override
protected void reset(Inflater inflater)
{
inflater.reset();
}
}

View File

@ -24,7 +24,6 @@ import java.util.List;
import java.util.function.Function;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.DefaultHandler;
@ -33,6 +32,7 @@ import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
@ -108,15 +108,11 @@ public class CoreServer extends ContainerLifeCycle
public abstract static class BaseNegotiator implements WebSocketNegotiator
{
protected final WebSocketExtensionRegistry extensionRegistry;
protected final DecoratedObjectFactory objectFactory;
protected final ByteBufferPool bufferPool;
protected final WebSocketComponents components;
public BaseNegotiator()
{
this.extensionRegistry = new WebSocketExtensionRegistry();
this.objectFactory = new DecoratedObjectFactory();
this.bufferPool = new MappedByteBufferPool();
this.components = new WebSocketComponents();
}
@Override
@ -127,19 +123,25 @@ public class CoreServer extends ContainerLifeCycle
@Override
public WebSocketExtensionRegistry getExtensionRegistry()
{
return extensionRegistry;
return components.getExtensionRegistry();
}
@Override
public DecoratedObjectFactory getObjectFactory()
{
return objectFactory;
return components.getObjectFactory();
}
@Override
public ByteBufferPool getByteBufferPool()
{
return bufferPool;
return components.getBufferPool();
}
@Override
public WebSocketComponents getWebSocketComponents()
{
return components;
}
}

View File

@ -22,6 +22,8 @@ import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.compression.DeflaterPool;
import org.eclipse.jetty.util.compression.InflaterPool;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
@ -35,6 +37,8 @@ public abstract class AbstractExtension implements Extension
private OutgoingFrames nextOutgoing;
private IncomingFrames nextIncoming;
private WebSocketCoreSession coreSession;
private DeflaterPool deflaterPool;
private InflaterPool inflaterPool;
public AbstractExtension()
{
@ -42,10 +46,12 @@ public abstract class AbstractExtension implements Extension
}
@Override
public void init(ExtensionConfig config, ByteBufferPool bufferPool)
public void init(ExtensionConfig config, WebSocketComponents components)
{
this.config = config;
this.bufferPool = bufferPool;
this.bufferPool = components.getBufferPool();
this.deflaterPool = components.getDeflaterPool();
this.inflaterPool = components.getInflaterPool();
}
public ByteBufferPool getBufferPool()
@ -59,6 +65,16 @@ public abstract class AbstractExtension implements Extension
return config;
}
public DeflaterPool getDeflaterPool()
{
return deflaterPool;
}
public InflaterPool getInflaterPool()
{
return inflaterPool;
}
@Override
public String getName()
{

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.websocket.core;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
/**
@ -29,7 +28,7 @@ import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
public interface Extension extends IncomingFrames, OutgoingFrames
{
void init(ExtensionConfig config, ByteBufferPool bufferPool);
void init(ExtensionConfig config, WebSocketComponents components);
/**
* The active configuration for this extension.

View File

@ -18,11 +18,15 @@
package org.eclipse.jetty.websocket.core;
import java.util.zip.Deflater;
import javax.servlet.ServletContext;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.compression.CompressionPool;
import org.eclipse.jetty.util.compression.DeflaterPool;
import org.eclipse.jetty.util.compression.InflaterPool;
/**
* A collection of components which are the resources needed for websockets such as
@ -50,19 +54,26 @@ public class WebSocketComponents
public WebSocketComponents()
{
this(new WebSocketExtensionRegistry(), new DecoratedObjectFactory(), new MappedByteBufferPool());
this(new WebSocketExtensionRegistry(), new DecoratedObjectFactory(), new MappedByteBufferPool(),
new InflaterPool(CompressionPool.INFINITE_CAPACITY, true),
new DeflaterPool(CompressionPool.INFINITE_CAPACITY, Deflater.DEFAULT_COMPRESSION, true));
}
public WebSocketComponents(WebSocketExtensionRegistry extensionRegistry, DecoratedObjectFactory objectFactory, ByteBufferPool bufferPool)
public WebSocketComponents(WebSocketExtensionRegistry extensionRegistry, DecoratedObjectFactory objectFactory,
ByteBufferPool bufferPool, InflaterPool inflaterPool, DeflaterPool deflaterPool)
{
this.extensionRegistry = extensionRegistry;
this.objectFactory = objectFactory;
this.bufferPool = bufferPool;
this.deflaterPool = deflaterPool;
this.inflaterPool = inflaterPool;
}
private DecoratedObjectFactory objectFactory;
private WebSocketExtensionRegistry extensionRegistry;
private ByteBufferPool bufferPool;
private InflaterPool inflaterPool;
private DeflaterPool deflaterPool;
public ByteBufferPool getBufferPool()
{
@ -78,4 +89,14 @@ public class WebSocketComponents
{
return objectFactory;
}
public InflaterPool getInflaterPool()
{
return inflaterPool;
}
public DeflaterPool getDeflaterPool()
{
return deflaterPool;
}
}

View File

@ -25,8 +25,6 @@ import java.util.ServiceLoader;
import java.util.Set;
import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.StringUtil;
public class WebSocketExtensionRegistry implements Iterable<Class<? extends Extension>>
@ -73,7 +71,7 @@ public class WebSocketExtensionRegistry implements Iterable<Class<? extends Exte
return availableExtensions.values().iterator();
}
public Extension newInstance(DecoratedObjectFactory objectFactory, ByteBufferPool bufferPool, ExtensionConfig config)
public Extension newInstance(ExtensionConfig config, WebSocketComponents components)
{
if (config == null)
{
@ -94,8 +92,8 @@ public class WebSocketExtensionRegistry implements Iterable<Class<? extends Exte
try
{
Extension ext = objectFactory.createInstance(extClass);
ext.init(config, bufferPool);
Extension ext = components.getObjectFactory().createInstance(extClass);
ext.init(config, components);
return ext;
}

View File

@ -330,8 +330,8 @@ public abstract class ClientUpgradeRequest extends HttpRequest implements Respon
// Negotiate the extension stack
HttpClient httpClient = wsClient.getHttpClient();
ExtensionStack extensionStack = new ExtensionStack(wsClient.getExtensionRegistry(), Behavior.CLIENT);
extensionStack.negotiate(wsClient.getObjectFactory(), httpClient.getByteBufferPool(), offeredExtensions, negotiatedExtensions);
ExtensionStack extensionStack = new ExtensionStack(wsClient.getWebSocketComponents(), Behavior.CLIENT);
extensionStack.negotiate(offeredExtensions, negotiatedExtensions);
// Get the negotiated subprotocol
String negotiatedSubProtocol = null;

View File

@ -26,9 +26,7 @@ import java.util.ListIterator;
import java.util.stream.Collectors;
import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.Dumpable;
@ -40,8 +38,8 @@ import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.IncomingFrames;
import org.eclipse.jetty.websocket.core.OutgoingFrames;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.WebSocketException;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
/**
* Represents the stack of Extensions.
@ -51,16 +49,16 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable
{
private static final Logger LOG = Log.getLogger(ExtensionStack.class);
private final WebSocketExtensionRegistry factory;
private final WebSocketComponents components;
private final Behavior behavior;
private List<Extension> extensions;
private IncomingFrames incoming;
private OutgoingFrames outgoing;
private Extension[] rsvClaims = new Extension[3];
public ExtensionStack(WebSocketExtensionRegistry factory, Behavior behavior)
public ExtensionStack(WebSocketComponents components, Behavior behavior)
{
this.factory = factory;
this.components = components;
this.behavior = behavior;
}
@ -116,7 +114,7 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable
* @param offeredConfigs the configurations being requested by the client
* @param negotiatedConfigs the configurations accepted by the server
*/
public void negotiate(DecoratedObjectFactory objectFactory, ByteBufferPool bufferPool, List<ExtensionConfig> offeredConfigs, List<ExtensionConfig> negotiatedConfigs)
public void negotiate(List<ExtensionConfig> offeredConfigs, List<ExtensionConfig> negotiatedConfigs)
{
if (LOG.isDebugEnabled())
LOG.debug("Extension Configs={}", negotiatedConfigs);
@ -129,7 +127,7 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable
try
{
ext = factory.newInstance(objectFactory, bufferPool, config);
ext = components.getExtensionRegistry().newInstance(config, components);
}
catch (Throwable t)
{

View File

@ -22,7 +22,6 @@ import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.Queue;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IteratingCallback;
import org.eclipse.jetty.util.log.Log;
@ -31,6 +30,7 @@ import org.eclipse.jetty.websocket.core.AbstractExtension;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
/**
* Fragment Extension
@ -74,9 +74,9 @@ public class FragmentExtension extends AbstractExtension
}
@Override
public void init(ExtensionConfig config, ByteBufferPool bufferPool)
public void init(ExtensionConfig config, WebSocketComponents components)
{
super.init(config, bufferPool);
super.init(config, components);
maxLength = config.getParameter("maxLength", -1);
}

View File

@ -27,7 +27,6 @@ import java.nio.file.Path;
import java.util.Calendar;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IO;
@ -37,6 +36,7 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.AbstractExtension;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.WRITE;
@ -140,9 +140,9 @@ public class FrameCaptureExtension extends AbstractExtension
}
@Override
public void init(ExtensionConfig config, ByteBufferPool bufferPool)
public void init(ExtensionConfig config, WebSocketComponents components)
{
super.init(config, bufferPool);
super.init(config, components);
String cfgOutputDir = config.getParameter("output-dir", null);
if (StringUtil.isNotBlank(cfgOutputDir))

View File

@ -18,13 +18,13 @@
package org.eclipse.jetty.websocket.core.internal;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.websocket.core.AbstractExtension;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
@ManagedObject("Identity Extension")
public class IdentityExtension extends AbstractExtension
@ -57,9 +57,9 @@ public class IdentityExtension extends AbstractExtension
}
@Override
public void init(ExtensionConfig config, ByteBufferPool bufferPool)
public void init(ExtensionConfig config, WebSocketComponents components)
{
super.init(config, bufferPool);
super.init(config, components);
StringBuilder s = new StringBuilder();
s.append(config.getName());

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.websocket.core.internal;
import java.util.Map;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -29,6 +28,7 @@ import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.NullAppendable;
import org.eclipse.jetty.websocket.core.ProtocolException;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import static org.eclipse.jetty.websocket.core.OpCode.CONTINUATION;
import static org.eclipse.jetty.websocket.core.OpCode.TEXT;
@ -100,9 +100,9 @@ public class ValidationExtension extends AbstractExtension
}
@Override
public void init(ExtensionConfig config, ByteBufferPool bufferPool)
public void init(ExtensionConfig config, WebSocketComponents components)
{
super.init(config, bufferPool);
super.init(config, components);
Map<String, String> parameters = config.getParameters();

View File

@ -83,15 +83,13 @@ public abstract class CompressExtension extends AbstractExtension
*/
private static final int DECOMPRESS_BUF_SIZE = 8 * 1024;
private static final boolean NOWRAP = true;
private final Queue<FrameEntry> entries = new ArrayDeque<>();
private final IteratingCallback flusher = new Flusher();
private Deflater deflaterImpl;
private Inflater inflaterImpl;
protected AtomicInteger decompressCount = new AtomicInteger(0);
private int tailDrop = TAIL_DROP_NEVER;
private int rsvUse = RSV_USE_ALWAYS;
private int tailDrop;
private int rsvUse;
protected CompressExtension()
{
@ -102,21 +100,29 @@ public abstract class CompressExtension extends AbstractExtension
public Deflater getDeflater()
{
if (deflaterImpl == null)
{
deflaterImpl = new Deflater(Deflater.DEFAULT_COMPRESSION, NOWRAP);
}
deflaterImpl = getDeflaterPool().acquire();
return deflaterImpl;
}
public Inflater getInflater()
{
if (inflaterImpl == null)
{
inflaterImpl = new Inflater(NOWRAP);
}
inflaterImpl = getInflaterPool().acquire();
return inflaterImpl;
}
public void releaseInflater()
{
getInflaterPool().release(inflaterImpl);
inflaterImpl = null;
}
public void releaseDeflater()
{
getInflaterPool().release(inflaterImpl);
inflaterImpl = null;
}
/**
* Indicates use of RSV1 flag for indicating deflation is in use.
*/
@ -409,6 +415,8 @@ public abstract class CompressExtension extends AbstractExtension
@Override
public void failed(Throwable cause)
{
releaseInflater();
releaseDeflater();
notifyCallbackFailure(current.callback, cause);
// If something went wrong, very likely the compression context
// will be invalid, so we need to fail this IteratingCallback.

View File

@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.zip.DataFormatException;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -32,6 +31,7 @@ import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.ProtocolException;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
/**
* Per Message Deflate Compression extension for WebSocket.
@ -117,7 +117,7 @@ public class PerMessageDeflateExtension extends CompressExtension
{
LOG.debug("Incoming Context Reset");
decompressCount.set(0);
getInflater().reset();
releaseInflater();
}
super.nextIncomingFrame(frame, callback);
}
@ -128,7 +128,7 @@ public class PerMessageDeflateExtension extends CompressExtension
if (frame.isFin() && !outgoingContextTakeover)
{
LOG.debug("Outgoing Context Reset");
getDeflater().reset();
releaseDeflater();
}
super.nextOutgoingFrame(frame, callback, batch);
}
@ -146,7 +146,7 @@ public class PerMessageDeflateExtension extends CompressExtension
}
@Override
public void init(final ExtensionConfig config, ByteBufferPool bufferPool)
public void init(final ExtensionConfig config, WebSocketComponents components)
{
configRequested = new ExtensionConfig(config);
Map<String, String> paramsNegotiated = new HashMap<>();
@ -185,7 +185,7 @@ public class PerMessageDeflateExtension extends CompressExtension
configNegotiated = new ExtensionConfig(config.getName(), paramsNegotiated);
LOG.debug("config: outgoingContextTakover={}, incomingContextTakeover={} : {}", outgoingContextTakeover, incomingContextTakeover, this);
super.init(configNegotiated, bufferPool);
super.init(configNegotiated, components);
}
@Override

View File

@ -30,12 +30,10 @@ import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.QuotedCSV;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.websocket.core.Behavior;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
public class Negotiation
@ -45,9 +43,7 @@ public class Negotiation
private final HttpServletResponse response;
private final List<ExtensionConfig> offeredExtensions;
private final List<String> offeredSubprotocols;
private final WebSocketExtensionRegistry registry;
private final DecoratedObjectFactory objectFactory;
private final ByteBufferPool bufferPool;
private final WebSocketComponents components;
private final String version;
private final Boolean upgrade;
private final String key;
@ -63,16 +59,12 @@ public class Negotiation
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response,
WebSocketExtensionRegistry registry,
DecoratedObjectFactory objectFactory,
ByteBufferPool bufferPool) throws BadMessageException
WebSocketComponents components) throws BadMessageException
{
this.baseRequest = baseRequest;
this.request = request;
this.response = response;
this.registry = registry;
this.objectFactory = objectFactory;
this.bufferPool = bufferPool;
this.components = components;
Boolean upgrade = null;
String key = null;
@ -131,7 +123,7 @@ public class Negotiation
this.key = key;
this.upgrade = upgrade != null && connectionCSVs != null && connectionCSVs.getValues().stream().anyMatch(s -> s.equalsIgnoreCase("Upgrade"));
Set<String> available = registry.getAvailableExtensionNames();
Set<String> available = components.getExtensionRegistry().getAvailableExtensionNames();
offeredExtensions = extensions == null
? Collections.emptyList()
: extensions.getValues().stream()
@ -227,8 +219,8 @@ public class Negotiation
if (extensionStack == null)
{
// Extension stack can decide to drop any of these extensions or their parameters
extensionStack = new ExtensionStack(registry, Behavior.SERVER);
extensionStack.negotiate(objectFactory, bufferPool, offeredExtensions, negotiatedExtensions);
extensionStack = new ExtensionStack(components, Behavior.SERVER);
extensionStack.negotiate(offeredExtensions, negotiatedExtensions);
negotiatedExtensions = extensionStack.getNegotiatedExtensions();
if (extensionStack.hasNegotiatedExtensions())

View File

@ -24,6 +24,7 @@ import java.util.function.Function;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
public interface WebSocketNegotiator extends FrameHandler.Customizer
@ -36,6 +37,8 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer
ByteBufferPool getByteBufferPool();
WebSocketComponents getWebSocketComponents();
static WebSocketNegotiator from(Function<Negotiation, FrameHandler> negotiate)
{
return new AbstractNegotiator()
@ -50,7 +53,7 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer
static WebSocketNegotiator from(Function<Negotiation, FrameHandler> negotiate, FrameHandler.Customizer customizer)
{
return new AbstractNegotiator(null, null, null, customizer)
return new AbstractNegotiator(null, customizer)
{
@Override
public FrameHandler negotiate(Negotiation negotiation)
@ -62,12 +65,10 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer
static WebSocketNegotiator from(
Function<Negotiation, FrameHandler> negotiate,
WebSocketExtensionRegistry extensionRegistry,
DecoratedObjectFactory objectFactory,
ByteBufferPool bufferPool,
WebSocketComponents components,
FrameHandler.Customizer customizer)
{
return new AbstractNegotiator(extensionRegistry, objectFactory, bufferPool, customizer)
return new AbstractNegotiator(components, customizer)
{
@Override
public FrameHandler negotiate(Negotiation negotiation)
@ -79,25 +80,17 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer
abstract class AbstractNegotiator implements WebSocketNegotiator
{
final WebSocketExtensionRegistry extensionRegistry;
final DecoratedObjectFactory objectFactory;
final ByteBufferPool bufferPool;
final WebSocketComponents components;
final FrameHandler.Customizer customizer;
public AbstractNegotiator()
{
this(null, null, null, null);
this(null, null);
}
public AbstractNegotiator(
WebSocketExtensionRegistry extensionRegistry,
DecoratedObjectFactory objectFactory,
ByteBufferPool bufferPool,
FrameHandler.Customizer customizer)
public AbstractNegotiator(WebSocketComponents components, FrameHandler.Customizer customizer)
{
this.extensionRegistry = extensionRegistry == null ? new WebSocketExtensionRegistry() : extensionRegistry;
this.objectFactory = objectFactory == null ? new DecoratedObjectFactory() : objectFactory;
this.bufferPool = bufferPool;
this.components = components == null ? new WebSocketComponents() : components;
this.customizer = customizer;
}
@ -111,19 +104,25 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer
@Override
public WebSocketExtensionRegistry getExtensionRegistry()
{
return extensionRegistry;
return components.getExtensionRegistry();
}
@Override
public DecoratedObjectFactory getObjectFactory()
{
return objectFactory;
return components.getObjectFactory();
}
@Override
public ByteBufferPool getByteBufferPool()
{
return bufferPool;
return components.getBufferPool();
}
@Override
public WebSocketComponents getWebSocketComponents()
{
return components;
}
public FrameHandler.Customizer getCustomizer()

View File

@ -46,6 +46,7 @@ import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.websocket.core.Behavior;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.WebSocketConstants;
import org.eclipse.jetty.websocket.core.WebSocketException;
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
@ -100,9 +101,7 @@ public final class RFC6455Handshaker implements Handshaker
baseRequest,
request,
response,
negotiator.getExtensionRegistry(),
negotiator.getObjectFactory(),
pool);
new WebSocketComponents());
if (LOG.isDebugEnabled())
LOG.debug("negotiation {}", negotiation);

View File

@ -22,9 +22,6 @@ import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.stream.Stream;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
import org.eclipse.jetty.websocket.core.internal.Generator;
import org.eclipse.jetty.websocket.core.internal.Negotiated;
@ -40,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
*/
public class GeneratorFrameFlagsTest
{
private static ByteBufferPool bufferPool = new MappedByteBufferPool();
private static WebSocketComponents components = new WebSocketComponents();
private WebSocketCoreSession coreSession;
public static Stream<Arguments> data()
@ -63,8 +60,8 @@ public class GeneratorFrameFlagsTest
public void setup(Frame invalidFrame)
{
ExtensionStack exStack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER);
exStack.negotiate(new DecoratedObjectFactory(), bufferPool, new LinkedList<>(), new LinkedList<>());
ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER);
exStack.negotiate(new LinkedList<>(), new LinkedList<>());
this.coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.CLIENT, Negotiated.from(exStack));
}
@ -75,7 +72,7 @@ public class GeneratorFrameFlagsTest
setup(invalidFrame);
ByteBuffer buffer = ByteBuffer.allocate(100);
new Generator(bufferPool).generateWholeFrame(invalidFrame, buffer);
new Generator(components.getBufferPool()).generateWholeFrame(invalidFrame, buffer);
assertThrows(ProtocolException.class, () -> coreSession.assertValidOutgoing(invalidFrame));
}
}

View File

@ -24,12 +24,10 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.ByteBufferAssert;
import org.eclipse.jetty.toolchain.test.Hex;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -53,9 +51,9 @@ public class GeneratorTest
private static WebSocketCoreSession newWebSocketCoreSession(Behavior behavior)
{
ByteBufferPool bufferPool = new MappedByteBufferPool();
ExtensionStack exStack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER);
exStack.negotiate(new DecoratedObjectFactory(), bufferPool, new LinkedList<>(), new LinkedList<>());
WebSocketComponents components = new WebSocketComponents();
ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER);
exStack.negotiate(new LinkedList<>(), new LinkedList<>());
return new WebSocketCoreSession(new TestMessageHandler(), behavior, Negotiated.from(exStack));
}

View File

@ -23,9 +23,6 @@ import java.util.LinkedList;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
import org.eclipse.jetty.websocket.core.internal.Negotiated;
import org.eclipse.jetty.websocket.core.internal.Parser;
@ -56,11 +53,11 @@ public class ParserCapture
{
this.copy = copy;
ByteBufferPool bufferPool = new MappedByteBufferPool();
ExtensionStack exStack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER);
exStack.negotiate(new DecoratedObjectFactory(), bufferPool, new LinkedList<>(), new LinkedList<>());
WebSocketComponents components = new WebSocketComponents();
ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER);
exStack.negotiate(new LinkedList<>(), new LinkedList<>());
this.coreSession = new WebSocketCoreSession(new TestMessageHandler(), behavior, Negotiated.from(exStack));
this.parser = new Parser(bufferPool, coreSession);
this.parser = new Parser(components.getBufferPool(), coreSession);
}
public void parse(ByteBuffer buffer)

View File

@ -22,32 +22,23 @@ import java.io.IOException;
import java.util.List;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator;
public class TestWebSocketNegotiator implements WebSocketNegotiator
{
final DecoratedObjectFactory objectFactory;
final WebSocketExtensionRegistry extensionRegistry;
final ByteBufferPool bufferPool;
final WebSocketComponents components;
private final FrameHandler frameHandler;
public TestWebSocketNegotiator(FrameHandler frameHandler)
{
this.objectFactory = new DecoratedObjectFactory();
this.extensionRegistry = new WebSocketExtensionRegistry();
this.bufferPool = new MappedByteBufferPool();
this.frameHandler = frameHandler;
this (frameHandler, new WebSocketComponents());
}
public TestWebSocketNegotiator(DecoratedObjectFactory objectFactory, WebSocketExtensionRegistry extensionRegistry, ByteBufferPool bufferPool,
FrameHandler frameHandler)
public TestWebSocketNegotiator(FrameHandler frameHandler, WebSocketComponents components)
{
this.objectFactory = objectFactory;
this.extensionRegistry = extensionRegistry;
this.bufferPool = bufferPool;
this.components = components;
this.frameHandler = frameHandler;
}
@ -69,18 +60,24 @@ public class TestWebSocketNegotiator implements WebSocketNegotiator
@Override
public WebSocketExtensionRegistry getExtensionRegistry()
{
return extensionRegistry;
return components.getExtensionRegistry();
}
@Override
public DecoratedObjectFactory getObjectFactory()
{
return objectFactory;
return components.getObjectFactory();
}
@Override
public ByteBufferPool getByteBufferPool()
{
return bufferPool;
return components.getBufferPool();
}
@Override
public WebSocketComponents getWebSocketComponents()
{
return components;
}
}

View File

@ -31,7 +31,6 @@ import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -551,8 +550,7 @@ public class WebSocketCloseTest extends WebSocketTester
ContextHandler context = new ContextHandler("/");
server.setHandler(context);
WebSocketNegotiator negotiator = new TestWebSocketNegotiator(new DecoratedObjectFactory(), new WebSocketExtensionRegistry(),
connector.getByteBufferPool(), frameHandler);
WebSocketNegotiator negotiator = new TestWebSocketNegotiator(frameHandler);
WebSocketUpgradeHandler upgradeHandler = new TestWebSocketUpgradeHandler(negotiator);
context.setHandler(upgradeHandler);

View File

@ -18,13 +18,12 @@
package org.eclipse.jetty.websocket.core.extensions;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.junit.jupiter.api.BeforeEach;
public abstract class AbstractExtensionTest
{
public ByteBufferPool bufferPool = new MappedByteBufferPool();
public WebSocketComponents components = new WebSocketComponents();
protected ExtensionTool clientExtensions;
protected ExtensionTool serverExtensions;
@ -32,7 +31,7 @@ public abstract class AbstractExtensionTest
@BeforeEach
public void init()
{
clientExtensions = new ExtensionTool(bufferPool);
serverExtensions = new ExtensionTool(bufferPool);
clientExtensions = new ExtensionTool(components.getBufferPool());
serverExtensions = new ExtensionTool(components.getBufferPool());
}
}

View File

@ -28,13 +28,10 @@ import java.util.Random;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.io.RuntimeIOException;
import org.eclipse.jetty.toolchain.test.ByteBufferAssert;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
@ -47,7 +44,6 @@ import org.eclipse.jetty.websocket.core.IncomingFramesCapture;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.OutgoingNetworkBytesCapture;
import org.eclipse.jetty.websocket.core.TestMessageHandler;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
import org.eclipse.jetty.websocket.core.internal.Generator;
import org.eclipse.jetty.websocket.core.internal.Negotiated;
@ -78,7 +74,7 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest
// Wire up stack
ext.setNextIncomingFrames(capture);
Parser parser = new Parser(bufferPool);
Parser parser = new Parser(components.getBufferPool());
ByteBuffer buffer = ByteBuffer.wrap(raw);
while (BufferUtil.hasContent(buffer))
{
@ -113,7 +109,7 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest
DeflateFrameExtension ext = new DeflateFrameExtension();
init(ext);
Generator generator = new Generator(bufferPool);
Generator generator = new Generator(components.getBufferPool());
OutgoingNetworkBytesCapture capture = new OutgoingNetworkBytesCapture(generator);
ext.setNextOutgoingFrames(capture);
@ -238,7 +234,7 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest
private void init(DeflateFrameExtension ext)
{
ext.setWebSocketCoreSession(sessionWithMaxMessageSize(20 * 1024 * 1024));
ext.init(new ExtensionConfig(ext.getName()), bufferPool);
ext.init(new ExtensionConfig(ext.getName()), components);
}
@Test
@ -290,7 +286,7 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest
DeflateFrameExtension ext = new DeflateFrameExtension();
init(ext);
Generator generator = new Generator(bufferPool);
Generator generator = new Generator(components.getBufferPool());
OutgoingNetworkBytesCapture capture = new OutgoingNetworkBytesCapture(generator);
ext.setNextOutgoingFrames(capture);
@ -417,9 +413,8 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest
private WebSocketCoreSession sessionWithMaxMessageSize(int maxMessageSize)
{
ByteBufferPool bufferPool = new MappedByteBufferPool();
ExtensionStack exStack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER);
exStack.negotiate(new DecoratedObjectFactory(), bufferPool, new LinkedList<>(), new LinkedList<>());
ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER);
exStack.negotiate(new LinkedList<>(), new LinkedList<>());
WebSocketCoreSession coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.SERVER, Negotiated.from(exStack));
coreSession.setMaxFrameSize(maxMessageSize);

View File

@ -21,9 +21,6 @@ package org.eclipse.jetty.websocket.core.extensions;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.Behavior;
@ -33,7 +30,7 @@ import org.eclipse.jetty.websocket.core.IncomingFrames;
import org.eclipse.jetty.websocket.core.IncomingFramesCapture;
import org.eclipse.jetty.websocket.core.OutgoingFrames;
import org.eclipse.jetty.websocket.core.OutgoingFramesCapture;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
import org.eclipse.jetty.websocket.core.internal.IdentityExtension;
import org.junit.jupiter.api.BeforeAll;
@ -46,17 +43,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class ExtensionStackTest
{
private static final Logger LOG = Log.getLogger(ExtensionStackTest.class);
private static DecoratedObjectFactory objectFactory;
private static ByteBufferPool bufferPool;
private static ExtensionStack stack;
@BeforeAll
public static void init()
{
objectFactory = new DecoratedObjectFactory();
bufferPool = new MappedByteBufferPool();
stack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER);
stack = new ExtensionStack(new WebSocketComponents(), Behavior.SERVER);
}
@SuppressWarnings("unchecked")
@ -76,7 +68,7 @@ public class ExtensionStackTest
// 1 extension
List<ExtensionConfig> configs = new ArrayList<>();
configs.add(ExtensionConfig.parse("identity"));
stack.negotiate(objectFactory, bufferPool, configs, configs);
stack.negotiate(configs, configs);
// Setup Listeners
IncomingFrames session = new IncomingFramesCapture();
@ -99,7 +91,7 @@ public class ExtensionStackTest
List<ExtensionConfig> configs = new ArrayList<>();
configs.add(ExtensionConfig.parse("identity; id=A"));
configs.add(ExtensionConfig.parse("identity; id=B"));
stack.negotiate(objectFactory, bufferPool, configs, configs);
stack.negotiate(configs, configs);
// Setup Listeners
IncomingFrames session = new IncomingFramesCapture();
@ -129,7 +121,7 @@ public class ExtensionStackTest
{
String chromeRequest = "permessage-deflate; client_max_window_bits, x-webkit-deflate-frame";
List<ExtensionConfig> requestedConfigs = ExtensionConfig.parseList(chromeRequest);
stack.negotiate(objectFactory, bufferPool, requestedConfigs, requestedConfigs);
stack.negotiate(requestedConfigs, requestedConfigs);
List<ExtensionConfig> negotiated = stack.getNegotiatedExtensions();
String response = ExtensionConfig.toHeaderValue(negotiated);

View File

@ -26,7 +26,6 @@ import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.toolchain.test.ByteBufferAssert;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.websocket.core.Behavior;
import org.eclipse.jetty.websocket.core.Extension;
@ -35,7 +34,7 @@ import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.IncomingFramesCapture;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.TestMessageHandler;
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
import org.eclipse.jetty.websocket.core.internal.Negotiated;
import org.eclipse.jetty.websocket.core.internal.Parser;
@ -61,7 +60,7 @@ public class ExtensionTool
{
this.requestedExtParams = parameterizedExtension;
this.extConfig = ExtensionConfig.parse(parameterizedExtension);
Class<?> extClass = factory.getExtension(extConfig.getName());
Class<?> extClass = components.getExtensionRegistry().getExtension(extConfig.getName());
assertThat("extClass", extClass, notNullValue());
this.capture = new IncomingFramesCapture();
@ -75,7 +74,7 @@ public class ExtensionTool
public void assertNegotiated(String expectedNegotiation)
{
this.ext = factory.newInstance(objectFactory, bufferPool, extConfig);
this.ext = components.getExtensionRegistry().newInstance(extConfig, components);
this.ext.setNextIncomingFrames(capture);
this.ext.setWebSocketCoreSession(newWebSocketCoreSession());
}
@ -136,15 +135,11 @@ public class ExtensionTool
}
}
private final DecoratedObjectFactory objectFactory;
private final ByteBufferPool bufferPool;
private final WebSocketExtensionRegistry factory;
private final WebSocketComponents components;
public ExtensionTool(ByteBufferPool bufferPool)
{
this.objectFactory = new DecoratedObjectFactory();
this.bufferPool = bufferPool;
this.factory = new WebSocketExtensionRegistry();
this.components = new WebSocketComponents();
}
public Tester newTester(String parameterizedExtension)
@ -154,9 +149,8 @@ public class ExtensionTool
private WebSocketCoreSession newWebSocketCoreSession()
{
ByteBufferPool bufferPool = new MappedByteBufferPool();
ExtensionStack exStack = new ExtensionStack(new WebSocketExtensionRegistry(), Behavior.SERVER);
exStack.negotiate(new DecoratedObjectFactory(), bufferPool, new LinkedList<>(), new LinkedList<>());
ExtensionStack exStack = new ExtensionStack(components, Behavior.SERVER);
exStack.negotiate(new LinkedList<>(), new LinkedList<>());
WebSocketCoreSession coreSession = new WebSocketCoreSession(new TestMessageHandler(), Behavior.SERVER, Negotiated.from(exStack));
return coreSession;
}

View File

@ -52,7 +52,7 @@ public class FragmentExtensionTest extends AbstractExtensionTest
FragmentExtension ext = new FragmentExtension();
ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=4");
ext.init(config, bufferPool);
ext.init(config, components);
ext.setNextIncomingFrames(capture);
@ -101,7 +101,7 @@ public class FragmentExtensionTest extends AbstractExtensionTest
FragmentExtension ext = new FragmentExtension();
ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=4");
ext.init(config, bufferPool);
ext.init(config, components);
ext.setNextIncomingFrames(capture);
@ -136,7 +136,7 @@ public class FragmentExtensionTest extends AbstractExtensionTest
FragmentExtension ext = new FragmentExtension();
ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=20");
ext.init(config, bufferPool);
ext.init(config, components);
ext.setNextOutgoingFrames(capture);
@ -208,7 +208,7 @@ public class FragmentExtensionTest extends AbstractExtensionTest
FragmentExtension ext = new FragmentExtension();
ExtensionConfig config = ExtensionConfig.parse("fragment");
ext.init(config, bufferPool);
ext.init(config, components);
ext.setNextOutgoingFrames(capture);
@ -272,7 +272,7 @@ public class FragmentExtensionTest extends AbstractExtensionTest
FragmentExtension ext = new FragmentExtension();
ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=4");
ext.init(config, bufferPool);
ext.init(config, components);
ext.setNextOutgoingFrames(capture);

View File

@ -53,7 +53,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
{
private void init(PerMessageDeflateExtension ext)
{
ext.init(new ExtensionConfig(ext.getName()), bufferPool);
ext.init(new ExtensionConfig(ext.getName()), components);
}
private void assertEndsWithTail(String hexStr, boolean expectedResult)
@ -284,7 +284,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
{
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.init(config, bufferPool);
ext.init(config, components);
// Setup capture of incoming frames
IncomingFramesCapture capture = new IncomingFramesCapture();
@ -319,7 +319,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
{
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.init(config, bufferPool);
ext.init(config, components);
// Setup capture of incoming frames
IncomingFramesCapture capture = new IncomingFramesCapture();
@ -354,7 +354,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
{
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.init(config, bufferPool);
ext.init(config, components);
// Setup capture of incoming frames
IncomingFramesCapture capture = new IncomingFramesCapture();
@ -409,7 +409,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
{
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
ext.init(config, bufferPool);
ext.init(config, components);
// Setup capture of outgoing frames
OutgoingFramesCapture capture = new OutgoingFramesCapture();
@ -447,7 +447,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
public void testOutgoingFragmentedMessage() throws IOException, InterruptedException
{
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
ext.init(ExtensionConfig.parse("permessage-deflate"), bufferPool);
ext.init(ExtensionConfig.parse("permessage-deflate"), components);
// Setup capture of outgoing frames
OutgoingFramesCapture capture = new OutgoingFramesCapture();

View File

@ -246,7 +246,7 @@ public class WebSocketMapping implements Dumpable, LifeCycle.Listener
public Negotiator(WebSocketCreator creator, FrameHandlerFactory factory, FrameHandler.Customizer customizer)
{
super(components.getExtensionRegistry(), components.getObjectFactory(), components.getBufferPool(), customizer);
super(components, customizer);
this.creator = creator;
this.factory = factory;
}

View File

@ -21,7 +21,7 @@ package org.eclipse.jetty.server.jmh;
import java.util.concurrent.TimeUnit;
import java.util.zip.Deflater;
import org.eclipse.jetty.server.DeflaterPool;
import org.eclipse.jetty.util.compression.DeflaterPool;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;