Skip to content

Commit 2640def

Browse files
authored
Fix #1114: make BufferRecyclerPool generic (#1115)
1 parent 55b4873 commit 2640def

File tree

8 files changed

+417
-294
lines changed

8 files changed

+417
-294
lines changed

src/main/java/com/fasterxml/jackson/core/JsonFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public static int collectDefaults() {
262262
/**
263263
* @since 2.16
264264
*/
265-
protected BufferRecyclerPool _bufferRecyclerPool;
265+
protected BufferRecyclerPool<BufferRecycler> _bufferRecyclerPool;
266266

267267
/**
268268
* Object that implements conversion functionality between
@@ -368,7 +368,7 @@ public static int collectDefaults() {
368368
public JsonFactory() { this((ObjectCodec) null); }
369369

370370
public JsonFactory(ObjectCodec oc) {
371-
_bufferRecyclerPool = BufferRecyclerPool.defaultPool();
371+
_bufferRecyclerPool = JsonBufferRecyclers.defaultPool();
372372
_objectCodec = oc;
373373
_quoteChar = DEFAULT_QUOTE_CHAR;
374374
_streamReadConstraints = StreamReadConstraints.defaults();
@@ -1152,7 +1152,7 @@ public String getRootValueSeparator() {
11521152
/**********************************************************
11531153
*/
11541154

1155-
public JsonFactory setBufferRecyclerPool(BufferRecyclerPool p) {
1155+
public JsonFactory setBufferRecyclerPool(BufferRecyclerPool<BufferRecycler> p) {
11561156
_bufferRecyclerPool = Objects.requireNonNull(p);
11571157
return this;
11581158
}
@@ -2150,7 +2150,7 @@ protected JsonGenerator _decorate(JsonGenerator g) {
21502150
*/
21512151
public BufferRecycler _getBufferRecycler()
21522152
{
2153-
return _getBufferRecyclerPool().acquireAndLinkBufferRecycler();
2153+
return _getBufferRecyclerPool().acquireAndLinkPooled();
21542154
}
21552155

21562156
/**
@@ -2159,12 +2159,12 @@ public BufferRecycler _getBufferRecycler()
21592159
*
21602160
* @since 2.16
21612161
*/
2162-
public BufferRecyclerPool _getBufferRecyclerPool() {
2162+
public BufferRecyclerPool<BufferRecycler> _getBufferRecyclerPool() {
21632163
// 23-Apr-2015, tatu: Let's allow disabling of buffer recycling
21642164
// scheme, for cases where it is considered harmful (possibly
21652165
// on Android, for example)
21662166
if (!Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING.enabledIn(_factoryFeatures)) {
2167-
return BufferRecyclerPool.nonRecyclingPool();
2167+
return JsonBufferRecyclers.nonRecyclingPool();
21682168
}
21692169
return _bufferRecyclerPool;
21702170
}

src/main/java/com/fasterxml/jackson/core/TSFBuilder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import com.fasterxml.jackson.core.io.OutputDecorator;
99
import com.fasterxml.jackson.core.json.JsonReadFeature;
1010
import com.fasterxml.jackson.core.json.JsonWriteFeature;
11+
import com.fasterxml.jackson.core.util.BufferRecycler;
1112
import com.fasterxml.jackson.core.util.BufferRecyclerPool;
13+
import com.fasterxml.jackson.core.util.JsonBufferRecyclers;
1214
import com.fasterxml.jackson.core.util.JsonGeneratorDecorator;
1315

1416
/**
@@ -74,7 +76,7 @@ public abstract class TSFBuilder<F extends JsonFactory,
7476
/**
7577
* @since 2.16
7678
*/
77-
protected BufferRecyclerPool _bufferRecyclerPool;
79+
protected BufferRecyclerPool<BufferRecycler> _bufferRecyclerPool;
7880

7981
/**
8082
* Optional helper object that may decorate input sources, to do
@@ -141,7 +143,7 @@ protected TSFBuilder(JsonFactory base)
141143
protected TSFBuilder(int factoryFeatures,
142144
int parserFeatures, int generatorFeatures)
143145
{
144-
_bufferRecyclerPool = BufferRecyclerPool.defaultPool();
146+
_bufferRecyclerPool = JsonBufferRecyclers.defaultPool();
145147

146148
_factoryFeatures = factoryFeatures;
147149
_streamReadFeatures = parserFeatures;
@@ -169,7 +171,7 @@ protected static <T> List<T> _copy(List<T> src) {
169171
public int streamReadFeatures() { return _streamReadFeatures; }
170172
public int streamWriteFeatures() { return _streamWriteFeatures; }
171173

172-
public BufferRecyclerPool bufferRecyclerPool() {
174+
public BufferRecyclerPool<BufferRecycler> bufferRecyclerPool() {
173175
return _bufferRecyclerPool;
174176
}
175177

@@ -321,7 +323,7 @@ public B configure(JsonWriteFeature f, boolean state) {
321323
*
322324
* @since 2.16
323325
*/
324-
public B bufferRecyclerPool(BufferRecyclerPool p) {
326+
public B bufferRecyclerPool(BufferRecyclerPool<BufferRecycler> p) {
325327
_bufferRecyclerPool = Objects.requireNonNull(p);
326328
return _this();
327329
}

src/main/java/com/fasterxml/jackson/core/util/BufferRecycler.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Rewritten in 2.16 to work with {@link BufferRecyclerPool} abstraction.
1919
*/
2020
public class BufferRecycler
21+
implements BufferRecyclerPool.WithPool<BufferRecycler>
2122
{
2223
/**
2324
* Buffer used for reading byte-based input.
@@ -86,7 +87,7 @@ public class BufferRecycler
8687
// Note: changed from simple array in 2.10:
8788
protected final AtomicReferenceArray<char[]> _charBuffers;
8889

89-
private BufferRecyclerPool _pool;
90+
private BufferRecyclerPool<BufferRecycler> _pool;
9091

9192
/*
9293
/**********************************************************
@@ -202,7 +203,8 @@ protected int charBufferLength(int ix) {
202203
*
203204
* @since 2.16
204205
*/
205-
BufferRecycler withPool(BufferRecyclerPool pool) {
206+
@Override
207+
public BufferRecycler withPool(BufferRecyclerPool<BufferRecycler> pool) {
206208
if (this._pool != null) {
207209
throw new IllegalStateException("BufferRecycler already linked to pool: "+pool);
208210
}
@@ -220,11 +222,11 @@ BufferRecycler withPool(BufferRecyclerPool pool) {
220222
*/
221223
public void release() {
222224
if (_pool != null) {
223-
BufferRecyclerPool tmpPool = _pool;
225+
BufferRecyclerPool<BufferRecycler> tmpPool = _pool;
224226
// nullify the reference to the pool in order to avoid the risk of releasing
225227
// the same BufferRecycler more than once, thus compromising the pool integrity
226228
_pool = null;
227-
tmpPool.releaseBufferRecycler(this);
229+
tmpPool.releasePooled(this);
228230
}
229231
}
230232
}

0 commit comments

Comments
 (0)