Issue #5287 - Changes from review & fix broken tests from NPE
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
d241c6694b
commit
5dc0242986
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public class DeflaterPool extends CompressionPool<Deflater>
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Deflater newObject()
|
||||
protected Deflater newPooled()
|
||||
{
|
||||
return new Deflater(compressionLevel, nowrap);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class InflaterPool extends CompressionPool<Inflater>
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Inflater newObject()
|
||||
protected Inflater newPooled()
|
||||
{
|
||||
return new Inflater(nowrap);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue