public abstract class AbstractTransaction extends Object implements Transaction
Transaction.TransactionState| Modifier and Type | Field and Description |
|---|---|
protected FlowFileCodec |
codec |
private boolean |
compress |
private long |
contentBytes |
private CRC32 |
crc |
private long |
creationNanoTime |
protected boolean |
dataAvailable |
protected String |
destinationId |
protected TransferDirection |
direction |
protected EventReporter |
eventReporter |
protected org.slf4j.Logger |
logger |
protected Peer |
peer |
private int |
penaltyMillis |
protected int |
protocolVersion |
protected Transaction.TransactionState |
state |
private int |
transfers |
| Constructor and Description |
|---|
AbstractTransaction(Peer peer,
TransferDirection direction,
boolean useCompression,
FlowFileCodec codec,
EventReporter eventReporter,
int protocolVersion,
int penaltyMillis,
String destinationId) |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel(String explanation)
Cancels this transaction, indicating to the sender that the data has not
been successfully received so that the sender can retry or handle however
is appropriate.
|
protected void |
close() |
TransactionCompletion |
complete()
Completes the transaction and indicates to both the sender and receiver
that the data transfer was successful.
|
void |
confirm()
Confirms the data that was sent or received by comparing CRC32's of the
data sent and the data received.
|
void |
error()
Sets the TransactionState of the Transaction to
Transaction.TransactionState.ERROR, and closes the Transaction. |
Peer |
getCommunicant() |
Transaction.TransactionState |
getState() |
protected abstract Response |
readTransactionResponse() |
DataPacket |
receive()
Retrieves information from the remote NiFi instance, if any is available.
|
void |
send(byte[] content,
Map<String,String> attributes)
Sends the given byte array as the content of a
DataPacket along
with the provided attributes |
void |
send(DataPacket dataPacket)
Sends information to the remote NiFi instance.
|
String |
toString() |
protected void |
writeTransactionResponse(ResponseCode response) |
protected void |
writeTransactionResponse(ResponseCode response,
String explanation) |
protected abstract void |
writeTransactionResponse(ResponseCode response,
String explanation,
boolean flush) |
protected final org.slf4j.Logger logger
protected final Peer peer
protected final TransferDirection direction
private final CRC32 crc
private final boolean compress
protected final FlowFileCodec codec
protected final EventReporter eventReporter
protected final int protocolVersion
private final int penaltyMillis
protected final String destinationId
protected Transaction.TransactionState state
protected boolean dataAvailable
private final long creationNanoTime
private int transfers
private long contentBytes
public AbstractTransaction(Peer peer, TransferDirection direction, boolean useCompression, FlowFileCodec codec, EventReporter eventReporter, int protocolVersion, int penaltyMillis, String destinationId)
protected void close()
throws IOException
IOExceptionpublic void send(byte[] content,
Map<String,String> attributes)
throws IOException
TransactionDataPacket along
with the provided attributessend in interface Transactioncontent - to sendattributes - of the contentIOException - if unable to sendpublic void error()
Transaction
Sets the TransactionState of the Transaction to
Transaction.TransactionState.ERROR, and closes the Transaction. The
underlying connection should not be returned to a connection pool in this
case.
error in interface Transactionpublic Transaction.TransactionState getState()
getState in interface Transactionpublic Peer getCommunicant()
getCommunicant in interface Transactionpublic final DataPacket receive() throws IOException
Transactionnull. It is important to
consume all data from the remote NiFi instance before attempting to call
Transaction.confirm(). This is because the sender is always responsible for
determining when the Transaction has finished. This is done in order to
prevent the need for a round-trip network request to receive data for
each data packet.receive in interface Transactionnull if there is no more data
to receive.IOException - if unable to receiveprotected abstract Response readTransactionResponse() throws IOException
IOExceptionprotected final void writeTransactionResponse(ResponseCode response) throws IOException
IOExceptionprotected void writeTransactionResponse(ResponseCode response, String explanation) throws IOException
IOExceptionprotected abstract void writeTransactionResponse(ResponseCode response, String explanation, boolean flush) throws IOException
IOExceptionpublic final void confirm()
throws IOException
TransactionConfirms the data that was sent or received by comparing CRC32's of the data sent and the data received.
Even if the protocol being used to send the data is reliable and guarantees ordering of packets (such as TCP), it is still required that we confirm the transaction before completing the transaction. This is done as "safety net" or a defensive programming technique. Mistakes happen, and this mechanism helps to ensure that if a bug exists somewhere along the line that we do not end up sending or receiving corrupt data. If the CRC32 of the sender and the CRC32 of the receiver do not match, an IOException will be thrown and both the sender and receiver will cancel the transaction automatically.
If the TransferDirection of this Transaction is RECEIVE, this
method will throw an Exception unless all data from the remote instance
has been consumed (i.e., a call to Transaction.receive() returns
null).
If the TransferDirection of this Transaction is SEND, calling
this method dictates that no more data will be sent in this transaction.
I.e., there will be no more calls to Transaction.send(DataPacket).
confirm in interface TransactionIOException - if unable to confirm transactionpublic final TransactionCompletion complete() throws IOException
TransactionCompletes the transaction and indicates to both the sender and receiver that the data transfer was successful.
complete in interface TransactionIOException - if unable to completepublic final void cancel(String explanation) throws IOException
TransactionCancels this transaction, indicating to the sender that the data has not been successfully received so that the sender can retry or handle however is appropriate.
cancel in interface Transactionexplanation - an explanation to tell the other party why the
transaction was canceled.IOException - if unable to cancelpublic final void send(DataPacket dataPacket) throws IOException
Transactionsend in interface TransactiondataPacket - the data packet to sendIOException - if unable to sendCopyright © 2023 Apache NiFi Project. All rights reserved.