Issue #5287 - Changes from review & fix broken tests from NPE

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-09-23 12:10:42 +10:00
parent d241c6694b
commit 5dc0242986
5 changed files with 32 additions and 29 deletions

View File

@ -70,6 +70,7 @@ public class GZIPContentDecoder implements Destroyable
public GZIPContentDecoder(InflaterPool inflaterPool, ByteBufferPool pool, int bufferSize)
{
_inflaterEntry = inflaterPool.acquire();
_inflater = _inflaterEntry.get();
_bufferSize = bufferSize;
_pool = pool;
reset();

View File

@ -56,7 +56,7 @@ public abstract class CompressionPool<T> extends AbstractLifeCycle
_capacity = capacity;
}
protected abstract T newObject();
protected abstract T newPooled();
protected abstract void end(T object);
@ -70,15 +70,12 @@ public abstract class CompressionPool<T> extends AbstractLifeCycle
Entry entry = null;
if (_pool != null)
{
Pool<Entry>.Entry acquiredEntry = _pool.acquire(e -> new Entry(newObject()));
Pool<Entry>.Entry acquiredEntry = _pool.acquire(e -> new Entry(newPooled(), e));
if (acquiredEntry != null)
{
entry = acquiredEntry.getPooled();
entry.setEntry(acquiredEntry);
}
}
return (entry == null) ? new Entry(newObject()) : entry;
return (entry == null) ? new Entry(newPooled()) : entry;
}
/**
@ -107,17 +104,20 @@ public abstract class CompressionPool<T> extends AbstractLifeCycle
public class Entry implements Closeable
{
private T _value;
private Pool<Entry>.Entry _entry;
private final T _value;
private final Pool<Entry>.Entry _entry;
Entry(T value)
{
_value = value;
_entry = null;
this(value, null);
}
void setEntry(Pool<Entry>.Entry entry)
Entry(T value, Pool<Entry>.Entry entry)
{
if (entry != null && entry.getPooled() != value)
throw new IllegalArgumentException("value does not match pooled entry");
_value = value;
_entry = entry;
}
@ -139,8 +139,6 @@ public abstract class CompressionPool<T> extends AbstractLifeCycle
if (_pool.remove(_entry))
close();
}
_entry = null;
}
}
@ -148,8 +146,6 @@ public abstract class CompressionPool<T> extends AbstractLifeCycle
public void close()
{
end(_value);
_value = null;
_entry = null;
}
}

View File

@ -44,7 +44,7 @@ public class DeflaterPool extends CompressionPool<Deflater>
}
@Override
protected Deflater newObject()
protected Deflater newPooled()
{
return new Deflater(compressionLevel, nowrap);
}

View File

@ -41,7 +41,7 @@ public class InflaterPool extends CompressionPool<Inflater>
}
@Override
protected Inflater newObject()
protected Inflater newPooled()
{
return new Inflater(nowrap);
}

View File

@ -54,8 +54,8 @@ public class PerMessageDeflateExtension extends AbstractExtension
private final TransformingFlusher outgoingFlusher;
private final TransformingFlusher incomingFlusher;
private DeflaterPool.Entry deflaterEntry;
private InflaterPool.Entry inflaterEntry;
private DeflaterPool.Entry deflaterHolder;
private InflaterPool.Entry inflaterHolder;
private boolean incomingCompressed;
private ExtensionConfig configRequested;
@ -180,28 +180,34 @@ public class PerMessageDeflateExtension extends AbstractExtension
public Deflater getDeflater()
{
if (deflaterEntry == null)
deflaterEntry = getDeflaterPool().acquire();
return deflaterEntry.get();
if (deflaterHolder == null)
deflaterHolder = getDeflaterPool().acquire();
return deflaterHolder.get();
}
public Inflater getInflater()
{
if (inflaterEntry == null)
inflaterEntry = getInflaterPool().acquire();
return inflaterEntry.get();
if (inflaterHolder == null)
inflaterHolder = getInflaterPool().acquire();
return inflaterHolder.get();
}
public void releaseInflater()
{
inflaterEntry.release();
inflaterEntry = null;
if (inflaterHolder != null)
{
inflaterHolder.release();
inflaterHolder = null;
}
}
public void releaseDeflater()
{
deflaterEntry.release();
deflaterEntry = null;
if (deflaterHolder != null)
{
deflaterHolder.release();
deflaterHolder = null;
}
}
@Override