Class AbstractTransaction
- All Implemented Interfaces:
Transaction
- Direct Known Subclasses:
HttpClientTransaction
,SocketClientTransaction
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.nifi.remote.Transaction
Transaction.TransactionState
-
Field Summary
Modifier and TypeFieldDescriptionprotected final FlowFileCodec
private final boolean
private long
private final CRC32
private final long
protected boolean
protected final String
protected final TransferDirection
protected final EventReporter
protected final org.slf4j.Logger
protected final Peer
private final int
protected final int
protected Transaction.TransactionState
private int
-
Constructor Summary
ConstructorDescriptionAbstractTransaction
(Peer peer, TransferDirection direction, boolean useCompression, FlowFileCodec codec, EventReporter eventReporter, int protocolVersion, int penaltyMillis, String destinationId) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
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()
final TransactionCompletion
complete()
Completes the transaction and indicates to both the sender and receiver that the data transfer was successful.final 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 toTransaction.TransactionState.ERROR
, and closes the Transaction.getState()
protected abstract Response
final DataPacket
receive()
Retrieves information from the remote NiFi instance, if any is available.void
Sends the given byte array as the content of aDataPacket
along with the provided attributesfinal void
send
(DataPacket dataPacket) Sends information to the remote NiFi instance.final String
toString()
protected final void
writeTransactionResponse
(ResponseCode response) protected void
writeTransactionResponse
(ResponseCode response, String explanation) protected abstract void
writeTransactionResponse
(ResponseCode response, String explanation, boolean flush)
-
Field Details
-
logger
protected final org.slf4j.Logger logger -
peer
-
direction
-
crc
-
compress
private final boolean compress -
codec
-
eventReporter
-
protocolVersion
protected final int protocolVersion -
penaltyMillis
private final int penaltyMillis -
destinationId
-
state
-
dataAvailable
protected boolean dataAvailable -
creationNanoTime
private final long creationNanoTime -
transfers
private int transfers -
contentBytes
private long contentBytes
-
-
Constructor Details
-
AbstractTransaction
public AbstractTransaction(Peer peer, TransferDirection direction, boolean useCompression, FlowFileCodec codec, EventReporter eventReporter, int protocolVersion, int penaltyMillis, String destinationId)
-
-
Method Details
-
close
- Throws:
IOException
-
send
Description copied from interface:Transaction
Sends the given byte array as the content of aDataPacket
along with the provided attributes- Specified by:
send
in interfaceTransaction
- Parameters:
content
- to sendattributes
- of the content- Throws:
IOException
- if unable to send
-
error
public void error()Description copied from interface: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.- Specified by:
error
in interfaceTransaction
-
getState
- Specified by:
getState
in interfaceTransaction
- Returns:
- the current state of the Transaction.
-
getCommunicant
- Specified by:
getCommunicant
in interfaceTransaction
- Returns:
- a Communicant that represents the other side of this Transaction (i.e., the remote NiFi instance)
-
receive
Description copied from interface:Transaction
Retrieves information from the remote NiFi instance, if any is available. If no data is available, will returnnull
. It is important to consume all data from the remote NiFi instance before attempting to callTransaction.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.- Specified by:
receive
in interfaceTransaction
- Returns:
- the DataPacket received, or
null
if there is no more data to receive. - Throws:
IOException
- if unable to receive
-
readTransactionResponse
- Throws:
IOException
-
writeTransactionResponse
- Throws:
IOException
-
writeTransactionResponse
protected void writeTransactionResponse(ResponseCode response, String explanation) throws IOException - Throws:
IOException
-
writeTransactionResponse
protected abstract void writeTransactionResponse(ResponseCode response, String explanation, boolean flush) throws IOException - Throws:
IOException
-
confirm
Description copied from interface:Transaction
Confirms 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 toTransaction.receive()
returnsnull
).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 toTransaction.send(DataPacket)
.- Specified by:
confirm
in interfaceTransaction
- Throws:
IOException
- if unable to confirm transaction
-
complete
Description copied from interface:Transaction
Completes the transaction and indicates to both the sender and receiver that the data transfer was successful.
- Specified by:
complete
in interfaceTransaction
- Returns:
- a TransactionCompletion that contains details about the Transaction
- Throws:
IOException
- if unable to complete
-
cancel
Description copied from interface:Transaction
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.
- Specified by:
cancel
in interfaceTransaction
- Parameters:
explanation
- an explanation to tell the other party why the transaction was canceled.- Throws:
IOException
- if unable to cancel
-
toString
-
send
Description copied from interface:Transaction
Sends information to the remote NiFi instance.- Specified by:
send
in interfaceTransaction
- Parameters:
dataPacket
- the data packet to send- Throws:
IOException
- if unable to send
-