Class AbstractTransaction

java.lang.Object
org.apache.nifi.remote.AbstractTransaction
All Implemented Interfaces:
Transaction
Direct Known Subclasses:
HttpClientTransaction, SocketClientTransaction

public abstract class AbstractTransaction extends Object implements Transaction
  • Field Details

    • logger

      protected final org.slf4j.Logger logger
    • peer

      protected final Peer peer
    • direction

      protected final TransferDirection direction
    • crc

      private final CRC32 crc
    • compress

      private final boolean compress
    • codec

      protected final FlowFileCodec codec
    • eventReporter

      protected final EventReporter eventReporter
    • protocolVersion

      protected final int protocolVersion
    • penaltyMillis

      private final int penaltyMillis
    • destinationId

      protected final String destinationId
    • state

    • dataAvailable

      protected boolean dataAvailable
    • creationNanoTime

      private final long creationNanoTime
    • transfers

      private int transfers
    • contentBytes

      private long contentBytes
  • Constructor Details

  • Method Details

    • close

      protected void close() throws IOException
      Throws:
      IOException
    • send

      public void send(byte[] content, Map<String,String> attributes) throws IOException
      Description copied from interface: Transaction
      Sends the given byte array as the content of a DataPacket along with the provided attributes
      Specified by:
      send in interface Transaction
      Parameters:
      content - to send
      attributes - 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 interface Transaction
    • getState

      public Transaction.TransactionState getState()
      Specified by:
      getState in interface Transaction
      Returns:
      the current state of the Transaction.
    • getCommunicant

      public Peer getCommunicant()
      Specified by:
      getCommunicant in interface Transaction
      Returns:
      a Communicant that represents the other side of this Transaction (i.e., the remote NiFi instance)
    • receive

      public final DataPacket receive() throws IOException
      Description copied from interface: Transaction
      Retrieves information from the remote NiFi instance, if any is available. If no data is available, will return null. 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.
      Specified by:
      receive in interface Transaction
      Returns:
      the DataPacket received, or null if there is no more data to receive.
      Throws:
      IOException - if unable to receive
    • readTransactionResponse

      protected abstract Response readTransactionResponse() throws IOException
      Throws:
      IOException
    • writeTransactionResponse

      protected final void writeTransactionResponse(ResponseCode response) throws IOException
      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

      public final void confirm() throws IOException
      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 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).

      Specified by:
      confirm in interface Transaction
      Throws:
      IOException - if unable to confirm transaction
    • complete

      public final TransactionCompletion complete() throws IOException
      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 interface Transaction
      Returns:
      a TransactionCompletion that contains details about the Transaction
      Throws:
      IOException - if unable to complete
    • cancel

      public final void cancel(String explanation) throws IOException
      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 interface Transaction
      Parameters:
      explanation - an explanation to tell the other party why the transaction was canceled.
      Throws:
      IOException - if unable to cancel
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • send

      public final void send(DataPacket dataPacket) throws IOException
      Description copied from interface: Transaction
      Sends information to the remote NiFi instance.
      Specified by:
      send in interface Transaction
      Parameters:
      dataPacket - the data packet to send
      Throws:
      IOException - if unable to send