NIFI-9741: Make the close() method of WriteAvroResultWithExternalSchema idempotent

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes #5818
This commit is contained in:
Mark Payne 2022-03-01 11:25:03 -05:00 committed by Matthew Burgess
parent d17fcf6427
commit a327ba478a
No known key found for this signature in database
GPG Key ID: 05D3DEB8126DAD24

View File

@ -43,6 +43,7 @@ public class WriteAvroResultWithExternalSchema extends AbstractRecordSetWriter {
private final OutputStream buffered;
private final DatumWriter<GenericRecord> datumWriter;
private final BlockingQueue<BinaryEncoder> recycleQueue;
private boolean closed = false;
public WriteAvroResultWithExternalSchema(final Schema avroSchema, final RecordSchema recordSchema, final SchemaAccessWriter schemaAccessWriter,
final OutputStream out, final BlockingQueue<BinaryEncoder> recycleQueue, final ComponentLog logger) {
@ -102,6 +103,11 @@ public class WriteAvroResultWithExternalSchema extends AbstractRecordSetWriter {
@Override
public void close() throws IOException {
if (closed) {
return;
}
closed = true;
if (encoder != null) {
flush();
recycleQueue.offer(encoder);