Skip to content

Commit 58c5f1e

Browse files
authored
Merge branch '2.16' into issue388
2 parents 9790707 + 58cc7ef commit 58c5f1e

File tree

69 files changed

+739
-452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+739
-452
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
fail-fast: false
2727
matrix:
28-
java_version: ['8', '11', '17']
28+
java_version: ['8', '11', '17', '21']
2929
os: ['ubuntu-20.04']
3030
env:
3131
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ syntax: glob
99

1010
# building
1111
target
12+
.mvn/wrapper/maven-wrapper.jar
1213

1314
# Eclipse
1415
.classpath

.mvn/wrapper/maven-wrapper.jar

-49.5 KB
Binary file not shown.

avro/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>com.fasterxml.jackson.dataformat</groupId>
1111
<artifactId>jackson-dataformats-binary</artifactId>
12-
<version>2.16.0-SNAPSHOT</version>
12+
<version>2.16.3-SNAPSHOT</version>
1313
</parent>
1414
<artifactId>jackson-dataformat-avro</artifactId>
1515
<name>Jackson dataformat: Avro</name>
@@ -54,7 +54,7 @@ abstractions.
5454
<dependency>
5555
<groupId>ch.qos.logback</groupId>
5656
<artifactId>logback-classic</artifactId>
57-
<version>1.2.11</version>
57+
<version>1.2.13</version>
5858
<scope>test</scope>
5959
</dependency>
6060
<!-- For validating more complex comparisons -->

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroFactory.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import com.fasterxml.jackson.core.format.InputAccessor;
88
import com.fasterxml.jackson.core.format.MatchStrength;
99
import com.fasterxml.jackson.core.io.IOContext;
10-
10+
import com.fasterxml.jackson.core.util.RecyclerPool;
11+
import com.fasterxml.jackson.dataformat.avro.apacheimpl.ApacheCodecRecycler;
12+
import com.fasterxml.jackson.dataformat.avro.apacheimpl.AvroRecyclerPools;
1113
import com.fasterxml.jackson.dataformat.avro.deser.*;
1214

1315
/**
@@ -40,6 +42,12 @@ public class AvroFactory extends JsonFactory
4042
/**********************************************************
4143
*/
4244

45+
/**
46+
* @since 2.16
47+
*/
48+
protected RecyclerPool<ApacheCodecRecycler> _avroRecyclerPool
49+
= AvroRecyclerPools.defaultPool();
50+
4351
protected int _avroParserFeatures;
4452

4553
protected int _avroGeneratorFeatures;
@@ -463,6 +471,7 @@ protected AvroGenerator _createGenerator(OutputStream out, IOContext ctxt) throw
463471
{
464472
int feats = _avroGeneratorFeatures;
465473
AvroGenerator gen = new AvroGenerator(ctxt, _generatorFeatures, feats,
474+
_avroRecyclerPool.acquireAndLinkPooled(),
466475
_objectCodec, out);
467476
return gen;
468477
}

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroGenerator.java

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import java.io.OutputStream;
55
import java.math.BigDecimal;
66
import java.math.BigInteger;
7+
import java.nio.charset.StandardCharsets;
78

89
import org.apache.avro.io.BinaryEncoder;
10+
import org.apache.avro.io.EncoderFactory;
911

1012
import com.fasterxml.jackson.core.*;
1113
import com.fasterxml.jackson.core.base.GeneratorBase;
@@ -67,7 +69,7 @@ public static int collectDefaults()
6769
return flags;
6870
}
6971

70-
private Feature(boolean defaultState) {
72+
Feature(boolean defaultState) {
7173
_defaultState = defaultState;
7274
_mask = (1 << ordinal());
7375
}
@@ -88,6 +90,16 @@ private Feature(boolean defaultState) {
8890
/**********************************************************
8991
*/
9092

93+
/**
94+
* @since 2.16
95+
*/
96+
protected final static EncoderFactory ENCODER_FACTORY = EncoderFactory.get();
97+
98+
/**
99+
* @since 2.16
100+
*/
101+
protected ApacheCodecRecycler _apacheCodecRecycler;
102+
91103
/**
92104
* @since 2.16
93105
*/
@@ -138,6 +150,7 @@ private Feature(boolean defaultState) {
138150
*/
139151

140152
public AvroGenerator(IOContext ctxt, int jsonFeatures, int avroFeatures,
153+
ApacheCodecRecycler apacheCodecRecycler,
141154
ObjectCodec codec, OutputStream output)
142155
throws IOException
143156
{
@@ -146,7 +159,13 @@ public AvroGenerator(IOContext ctxt, int jsonFeatures, int avroFeatures,
146159
_formatFeatures = avroFeatures;
147160
_output = output;
148161
_avroContext = AvroWriteContext.nullContext();
149-
_encoder = ApacheCodecRecycler.encoder(_output, isEnabled(Feature.AVRO_BUFFERING));
162+
163+
_apacheCodecRecycler = apacheCodecRecycler;
164+
final boolean buffering = isEnabled(Feature.AVRO_BUFFERING);
165+
BinaryEncoder encoderToReuse = _apacheCodecRecycler.acquireEncoder();
166+
_encoder = buffering
167+
? ENCODER_FACTORY.binaryEncoder(output, encoderToReuse)
168+
: ENCODER_FACTORY.directBinaryEncoder(output, encoderToReuse);
150169
}
151170

152171
public void setSchema(AvroSchema schema)
@@ -463,7 +482,7 @@ public void writeRawUTF8String(byte[] text, int offset, int len) throws IOExcept
463482

464483
@Override
465484
public final void writeUTF8String(byte[] text, int offset, int len) throws IOException {
466-
writeString(new String(text, offset, len, "UTF-8"));
485+
writeString(new String(text, offset, len, StandardCharsets.UTF_8));
467486
}
468487

469488
/*
@@ -550,12 +569,12 @@ public void writeNull() throws IOException {
550569

551570
@Override
552571
public void writeNumber(int i) throws IOException {
553-
_avroContext.writeValue(Integer.valueOf(i));
572+
_avroContext.writeValue(i);
554573
}
555574

556575
@Override
557576
public void writeNumber(long l) throws IOException {
558-
_avroContext.writeValue(Long.valueOf(l));
577+
_avroContext.writeValue(l);
559578
}
560579

561580
@Override
@@ -570,12 +589,12 @@ public void writeNumber(BigInteger v) throws IOException
570589

571590
@Override
572591
public void writeNumber(double d) throws IOException {
573-
_avroContext.writeValue(Double.valueOf(d));
592+
_avroContext.writeValue(d);
574593
}
575594

576595
@Override
577596
public void writeNumber(float f) throws IOException {
578-
_avroContext.writeValue(Float.valueOf(f));
597+
_avroContext.writeValue(f);
579598
}
580599

581600
@Override
@@ -615,10 +634,15 @@ protected final void _verifyValueWrite(String typeMsg) throws IOException {
615634
@Override
616635
protected void _releaseBuffers() {
617636
// no super implementation to call
618-
BinaryEncoder e = _encoder;
619-
if (e != null) {
620-
_encoder = null;
621-
ApacheCodecRecycler.release(e);
637+
ApacheCodecRecycler recycler = _apacheCodecRecycler;
638+
if (recycler != null) {
639+
_apacheCodecRecycler = null;
640+
BinaryEncoder e = _encoder;
641+
if (e != null) {
642+
_encoder = null;
643+
recycler.release(e);
644+
}
645+
recycler.releaseToPool();
622646
}
623647
}
624648

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static int collectDefaults()
5555
return flags;
5656
}
5757

58-
private Feature(boolean defaultState) {
58+
Feature(boolean defaultState) {
5959
_defaultState = defaultState;
6060
_mask = (1 << ordinal());
6161
}

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class AvroSchema implements FormatSchema
3535
/**
3636
* Lazily instantiated value reader for this schema.
3737
*/
38-
protected final AtomicReference<AvroStructureReader> _reader = new AtomicReference<AvroStructureReader>();
38+
protected final AtomicReference<AvroStructureReader> _reader = new AtomicReference<>();
3939

4040
public AvroSchema(Schema asch)
4141
{

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/apacheimpl/ApacheAvroFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ public AvroFactory copy()
4545
@Override
4646
protected AvroParser _createParser(InputStream in, IOContext ctxt) throws IOException {
4747
return new ApacheAvroParserImpl(ctxt, _parserFeatures, _avroParserFeatures,
48+
_avroRecyclerPool.acquireAndLinkPooled(),
4849
_objectCodec, in);
4950
}
5051

5152
@Override
5253
protected AvroParser _createParser(byte[] data, int offset, int len, IOContext ctxt) throws IOException {
5354
return new ApacheAvroParserImpl(ctxt, _parserFeatures, _avroParserFeatures,
55+
_avroRecyclerPool.acquireAndLinkPooled(),
5456
_objectCodec, data, offset, len);
5557
}
5658
}

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/apacheimpl/ApacheAvroParserImpl.java

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.io.Writer;
66

77
import org.apache.avro.io.BinaryDecoder;
8+
import org.apache.avro.io.BinaryEncoder;
9+
import org.apache.avro.io.DecoderFactory;
810

911
import com.fasterxml.jackson.core.*;
1012
import com.fasterxml.jackson.core.io.IOContext;
@@ -17,6 +19,22 @@
1719
*/
1820
public class ApacheAvroParserImpl extends AvroParserImpl
1921
{
22+
/*
23+
/**********************************************************
24+
/* Configuration
25+
/**********************************************************
26+
*/
27+
28+
/**
29+
* @since 2.16
30+
*/
31+
protected final static DecoderFactory DECODER_FACTORY = DecoderFactory.get();
32+
33+
/**
34+
* @since 2.16
35+
*/
36+
protected ApacheCodecRecycler _apacheCodecRecycler;
37+
2038
/*
2139
/**********************************************************
2240
/* Input source config
@@ -65,6 +83,7 @@ public class ApacheAvroParserImpl extends AvroParserImpl
6583
*/
6684

6785
public ApacheAvroParserImpl(IOContext ctxt, int parserFeatures, int avroFeatures,
86+
ApacheCodecRecycler apacheCodecRecycler,
6887
ObjectCodec codec, InputStream in)
6988
{
7089
super(ctxt, parserFeatures, avroFeatures, codec);
@@ -74,17 +93,24 @@ public ApacheAvroParserImpl(IOContext ctxt, int parserFeatures, int avroFeatures
7493
_inputEnd = 0;
7594
_bufferRecyclable = true;
7695

77-
_decoder = ApacheCodecRecycler.decoder(in,
78-
Feature.AVRO_BUFFERING.enabledIn(avroFeatures));
96+
_apacheCodecRecycler = apacheCodecRecycler;
97+
final boolean buffering = Feature.AVRO_BUFFERING.enabledIn(avroFeatures);
98+
BinaryDecoder decoderToReuse = apacheCodecRecycler.acquireDecoder();
99+
_decoder = buffering
100+
? DECODER_FACTORY.binaryDecoder(in, decoderToReuse)
101+
: DECODER_FACTORY.directBinaryDecoder(in, decoderToReuse);
79102
}
80103

81104
public ApacheAvroParserImpl(IOContext ctxt, int parserFeatures, int avroFeatures,
105+
ApacheCodecRecycler apacheCodecRecycler,
82106
ObjectCodec codec,
83-
byte[] data, int offset, int len)
107+
byte[] buffer, int offset, int len)
84108
{
85109
super(ctxt, parserFeatures, avroFeatures, codec);
86110
_inputStream = null;
87-
_decoder = ApacheCodecRecycler.decoder(data, offset, len);
111+
_apacheCodecRecycler = apacheCodecRecycler;
112+
BinaryDecoder decoderToReuse = apacheCodecRecycler.acquireDecoder();
113+
_decoder = DECODER_FACTORY.binaryDecoder(buffer, offset, len, decoderToReuse);
88114
}
89115

90116
@Override
@@ -97,14 +123,18 @@ protected void _releaseBuffers() throws IOException {
97123
_ioContext.releaseReadIOBuffer(buf);
98124
}
99125
}
100-
BinaryDecoder d = _decoder;
101-
if (d != null) {
102-
_decoder = null;
103-
ApacheCodecRecycler.release(d);
126+
ApacheCodecRecycler recycler = _apacheCodecRecycler;
127+
if (recycler != null) {
128+
_apacheCodecRecycler = null;
129+
BinaryDecoder d = _decoder;
130+
if (d != null) {
131+
_decoder = null;
132+
recycler.release(d);
133+
}
134+
recycler.releaseToPool();
104135
}
105136
}
106137

107-
108138
/*
109139
/**********************************************************
110140
/* Abstract method impls, i/o access

0 commit comments

Comments
 (0)