diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/DeflaterPool.java b/jetty-server/src/main/java/org/eclipse/jetty/server/DeflaterPool.java deleted file mode 100644 index ff3b1c41a98..00000000000 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/DeflaterPool.java +++ /dev/null @@ -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 _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; - } - } - } - } -} diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java index ac10d9b324c..5c590b2d3e5 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHandler.java @@ -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; diff --git a/jetty-util/src/main/java/module-info.java b/jetty-util/src/main/java/module-info.java index 6c0666eaff8..1d5b30905d0 100644 --- a/jetty-util/src/main/java/module-info.java +++ b/jetty-util/src/main/java/module-info.java @@ -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; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/compression/CompressionPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/compression/CompressionPool.java new file mode 100644 index 00000000000..042ca327607 --- /dev/null +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/compression/CompressionPool.java @@ -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 extends AbstractLifeCycle +{ + public static final int INFINITE_CAPACITY = -1; + + private final Queue _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); + } +} \ No newline at end of file diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/compression/DeflaterPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/compression/DeflaterPool.java new file mode 100644 index 00000000000..9afffd89bdb --- /dev/null +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/compression/DeflaterPool.java @@ -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 +{ + private final int compressionLevel; + private final boolean nowrap; + + /** + * 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) + { + 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(); + } +} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/compression/InflaterPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/compression/InflaterPool.java new file mode 100644 index 00000000000..3c912af2977 --- /dev/null +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/compression/InflaterPool.java @@ -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 +{ + private final boolean nowrap; + + /** + * Create a Pool of {@link Inflater} instances. + *

+ * 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(); + } +} diff --git a/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java b/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java index 644482f7891..274fc1d8c26 100644 --- a/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java +++ b/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/CoreServer.java @@ -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; } } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java index 9e5c0ff9b4d..6f50cc5d4fb 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/AbstractExtension.java @@ -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() { diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java index 5a4472cfd6a..0fd66060372 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/Extension.java @@ -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. diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketComponents.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketComponents.java index e2c6c63a492..60c451d6554 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketComponents.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketComponents.java @@ -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; + } } \ No newline at end of file diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketExtensionRegistry.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketExtensionRegistry.java index 49459e90d8e..0e71b730ed3 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketExtensionRegistry.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketExtensionRegistry.java @@ -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> @@ -73,7 +71,7 @@ public class WebSocketExtensionRegistry implements Iterable 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 offeredConfigs, List negotiatedConfigs) + public void negotiate(List offeredConfigs, List 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) { diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java index 1c9bec9f605..cf2ed8cacbc 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FragmentExtension.java @@ -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); } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameCaptureExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameCaptureExtension.java index 5a1cbbdafc6..99b51b5b06c 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameCaptureExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameCaptureExtension.java @@ -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)) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/IdentityExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/IdentityExtension.java index e7da3a8a781..20ddd17f8af 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/IdentityExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/IdentityExtension.java @@ -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()); diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java index 425bbcc9d34..496ea84eb16 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ValidationExtension.java @@ -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 parameters = config.getParameters(); diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/CompressExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/CompressExtension.java index d40a7879965..adc99d598bc 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/CompressExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/CompressExtension.java @@ -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 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. diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/PerMessageDeflateExtension.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/PerMessageDeflateExtension.java index 9304ab28436..d5f883d9a78 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/PerMessageDeflateExtension.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/compress/PerMessageDeflateExtension.java @@ -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 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 diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java index 2dc0c1f469d..7db266a0d24 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java @@ -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 offeredExtensions; private final List 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 available = registry.getAvailableExtensionNames(); + Set 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()) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketNegotiator.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketNegotiator.java index db329df6939..e02a110dc76 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketNegotiator.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketNegotiator.java @@ -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 negotiate) { return new AbstractNegotiator() @@ -50,7 +53,7 @@ public interface WebSocketNegotiator extends FrameHandler.Customizer static WebSocketNegotiator from(Function 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 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() diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java index 010f43bf30f..b5c7db8dbd7 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java @@ -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); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorFrameFlagsTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorFrameFlagsTest.java index e6c87ee8fd9..93aba40780d 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorFrameFlagsTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorFrameFlagsTest.java @@ -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 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)); } } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorTest.java index e168b4f3b6b..fec7167ae8f 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/GeneratorTest.java @@ -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)); } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserCapture.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserCapture.java index cbf4868853c..a15fe771eed 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserCapture.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/ParserCapture.java @@ -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) diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/TestWebSocketNegotiator.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/TestWebSocketNegotiator.java index 1c170fec6f2..53430af39e5 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/TestWebSocketNegotiator.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/TestWebSocketNegotiator.java @@ -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; } } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java index f398f1ff0a7..2e56a37c6ab 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java @@ -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); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/AbstractExtensionTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/AbstractExtensionTest.java index fe45a8dd83b..9ae85a0e924 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/AbstractExtensionTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/AbstractExtensionTest.java @@ -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()); } } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/DeflateFrameExtensionTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/DeflateFrameExtensionTest.java index 6da52cbe9a2..0d7476a78f6 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/DeflateFrameExtensionTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/DeflateFrameExtensionTest.java @@ -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); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java index 4fdbadb6ee3..e50008ec0a3 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java @@ -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 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 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 requestedConfigs = ExtensionConfig.parseList(chromeRequest); - stack.negotiate(objectFactory, bufferPool, requestedConfigs, requestedConfigs); + stack.negotiate(requestedConfigs, requestedConfigs); List negotiated = stack.getNegotiatedExtensions(); String response = ExtensionConfig.toHeaderValue(negotiated); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java index adb912a9f8f..2fbbc0cd998 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java @@ -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; } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/FragmentExtensionTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/FragmentExtensionTest.java index 9d5d79e872f..3f0ed25ba42 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/FragmentExtensionTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/FragmentExtensionTest.java @@ -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); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java index cc6790e31a2..e9e0e499368 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflateExtensionTest.java @@ -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(); diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java index 0d340ed8da7..f89476b6ab2 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java @@ -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; } diff --git a/tests/jetty-jmh/src/main/java/org/eclipse/jetty/server/jmh/DeflaterPoolBenchmark.java b/tests/jetty-jmh/src/main/java/org/eclipse/jetty/server/jmh/DeflaterPoolBenchmark.java index 8a31e8913ce..04172bb6b8a 100644 --- a/tests/jetty-jmh/src/main/java/org/eclipse/jetty/server/jmh/DeflaterPoolBenchmark.java +++ b/tests/jetty-jmh/src/main/java/org/eclipse/jetty/server/jmh/DeflaterPoolBenchmark.java @@ -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;