break; case PORT_IDENTIFIER: { checkPortStatus(peer, value);
@Override public int commitReceiveTransaction(Peer peer) throws IOException, IllegalStateException { logger.debug("{} Committing the receive transaction. peer={}", this, peer); HttpServerCommunicationsSession commSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession(); String transactionId = commSession.getTransactionId(); FlowFileTransaction transaction = transactionManager.finalizeTransaction(transactionId); commSession.setStatus(Transaction.TransactionState.TRANSACTION_CONFIRMED); return super.commitReceiveTransaction(peer, transaction); }
writeTransactionResponse(true, ResponseCode.NO_MORE_DATA, commsSession); return 0; writeTransactionResponse(true, ResponseCode.MORE_DATA, commsSession); bytesSent += flowFile.getSize(); final String transitUri = createTransitUri(peer, flowFile.getAttribute(CoreAttributes.UUID.key())); session.getProvenanceReporter().send(flowFile, transitUri, "Remote Host=" + peer.getHost() + ", Remote DN=" + remoteDn, transmissionMillis, false); session.remove(flowFile); if (continueTransaction) { logger.debug("{} Sending ContinueTransaction indicator to {}", this, peer); writeTransactionResponse(true, ResponseCode.CONTINUE_TRANSACTION, commsSession); } else { logger.debug("{} Sending FinishTransaction indicator to {}", this, peer); writeTransactionResponse(true, ResponseCode.FINISH_TRANSACTION, commsSession); calculatedCRC = String.valueOf(checkedOutputStream.getChecksum().getValue()); return commitTransferTransaction(peer, transaction);
protected int commitReceiveTransaction(Peer peer, FlowFileTransaction transaction) throws IOException { CommunicationsSession commsSession = peer.getCommunicationsSession(); ProcessSession session = transaction.getSession(); final Response confirmTransactionResponse = readTransactionResponse(false, commsSession); logger.debug("{} Received {} from {}", this, confirmTransactionResponse, peer); writeTransactionResponse(false, ResponseCode.TRANSACTION_FINISHED_BUT_DESTINATION_FULL, commsSession); } else { writeTransactionResponse(false, ResponseCode.TRANSACTION_FINISHED, commsSession);
final Response transactionConfirmationResponse = readTransactionResponse(true, commsSession); if (transactionConfirmationResponse.getCode() == ResponseCode.CONFIRM_TRANSACTION) { final String receivedCRC = transactionConfirmationResponse.getMessage(); if (getVersionNegotiator().getVersion() > 3) { String calculatedCRC = transaction.getCalculatedCRC(); if (!receivedCRC.equals(calculatedCRC)) { writeTransactionResponse(true, ResponseCode.BAD_CHECKSUM, commsSession); session.rollback(); throw new IOException(this + " Sent data to peer " + peer + " but calculated CRC32 Checksum as " writeTransactionResponse(true, ResponseCode.CONFIRM_TRANSACTION, commsSession, ""); transactionResponse = readTransactionResponse(true, commsSession); } catch (final IOException e) { logger.error("{} Failed to receive a response from {} when expecting a TransactionFinished Indicator."
final String transitUri = createTransitUri(peer, sourceSystemFlowFileUuid); session.getProvenanceReporter().receive(flowFile, transitUri, sourceSystemFlowFileUuid == null ? null : "urn:nifi:" + sourceSystemFlowFileUuid, "Remote Host=" + peer.getHost() + ", Remote DN=" + remoteDn, transferMillis); bytesReceived += flowFile.getSize(); final Response transactionResponse = readTransactionResponse(false, commsSession); switch (transactionResponse.getCode()) { case CONTINUE_TRANSACTION: writeTransactionResponse(false, ResponseCode.CONFIRM_TRANSACTION, commsSession, calculatedCRC); return commitReceiveTransaction(peer, transaction);
@Override public int commitTransferTransaction(Peer peer, String clientChecksum) throws IOException, IllegalStateException { logger.debug("{} Committing the transfer transaction. peer={} clientChecksum={}", this, peer, clientChecksum); HttpServerCommunicationsSession commSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession(); String transactionId = commSession.getTransactionId(); FlowFileTransaction transaction = transactionManager.finalizeTransaction(transactionId); commSession.setChecksum(clientChecksum); commSession.setStatus(Transaction.TransactionState.DATA_EXCHANGED); return super.commitTransferTransaction(peer, transaction); }
@Override public final void handshake(final Peer peer) throws IOException, HandshakeException { if (handshakeCompleted) { throw new IllegalStateException("Handshake has already been completed"); } if (shutdown) { throw new IllegalStateException("Protocol is shutdown"); } logger.debug("{} Handshaking with {}", this, peer); this.handshakeProperties = doHandshake(peer); logger.debug("{} Finished handshake with {}", this, peer); handshakeCompleted = true; }
protected final void writeTransactionResponse(boolean isTransfer, ResponseCode response, CommunicationsSession commsSession) throws IOException { writeTransactionResponse(isTransfer, response, commsSession, null); }
if (getVersionNegotiator().getVersion() > 1) { for (final Connection connection : port.getConnections()) { if (connection.getFlowFileQueue().isFull()) {
final String transitUri = createTransitUri(peer, sourceSystemFlowFileUuid); session.getProvenanceReporter().receive(flowFile, transitUri, sourceSystemFlowFileUuid == null ? null : "urn:nifi:" + sourceSystemFlowFileUuid, "Remote Host=" + peer.getHost() + ", Remote DN=" + remoteDn, transferMillis); bytesReceived += flowFile.getSize(); final Response transactionResponse = readTransactionResponse(false, commsSession); switch (transactionResponse.getCode()) { case CONTINUE_TRANSACTION: writeTransactionResponse(false, ResponseCode.CONFIRM_TRANSACTION, commsSession, calculatedCRC); return commitReceiveTransaction(peer, transaction);
final Response transactionConfirmationResponse = readTransactionResponse(true, commsSession); if (transactionConfirmationResponse.getCode() == ResponseCode.CONFIRM_TRANSACTION) { final String receivedCRC = transactionConfirmationResponse.getMessage(); if (getVersionNegotiator().getVersion() > 3) { String calculatedCRC = transaction.getCalculatedCRC(); if (!receivedCRC.equals(calculatedCRC)) { writeTransactionResponse(true, ResponseCode.BAD_CHECKSUM, commsSession); session.rollback(); throw new IOException(this + " Sent data to peer " + peer + " but calculated CRC32 Checksum as " writeTransactionResponse(true, ResponseCode.CONFIRM_TRANSACTION, commsSession, ""); transactionResponse = readTransactionResponse(true, commsSession); } catch (final IOException e) { logger.error("{} Failed to receive a response from {} when expecting a TransactionFinished Indicator."
protected int commitReceiveTransaction(Peer peer, FlowFileTransaction transaction) throws IOException { CommunicationsSession commsSession = peer.getCommunicationsSession(); ProcessSession session = transaction.getSession(); final Response confirmTransactionResponse = readTransactionResponse(false, commsSession); logger.debug("{} Received {} from {}", this, confirmTransactionResponse, peer); writeTransactionResponse(false, ResponseCode.TRANSACTION_FINISHED_BUT_DESTINATION_FULL, commsSession); } else { writeTransactionResponse(false, ResponseCode.TRANSACTION_FINISHED, commsSession);
@Override public int commitTransferTransaction(Peer peer, String clientChecksum) throws IOException, IllegalStateException { logger.debug("{} Committing the transfer transaction. peer={} clientChecksum={}", this, peer, clientChecksum); HttpServerCommunicationsSession commSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession(); String transactionId = commSession.getTransactionId(); FlowFileTransaction transaction = transactionManager.finalizeTransaction(transactionId); commSession.setChecksum(clientChecksum); commSession.setStatus(Transaction.TransactionState.DATA_EXCHANGED); return super.commitTransferTransaction(peer, transaction); }
@Override public final void handshake(final Peer peer) throws IOException, HandshakeException { if (handshakeCompleted) { throw new IllegalStateException("Handshake has already been completed"); } if (shutdown) { throw new IllegalStateException("Protocol is shutdown"); } logger.debug("{} Handshaking with {}", this, peer); this.handshakeProperties = doHandshake(peer); logger.debug("{} Finished handshake with {}", this, peer); handshakeCompleted = true; }
protected final void writeTransactionResponse(boolean isTransfer, ResponseCode response, CommunicationsSession commsSession) throws IOException { writeTransactionResponse(isTransfer, response, commsSession, null); }
if (getVersionNegotiator().getVersion() > 1) { for (final Connection connection : port.getConnections()) { if (connection.getFlowFileQueue().isFull()) {
writeTransactionResponse(true, ResponseCode.NO_MORE_DATA, commsSession); return 0; writeTransactionResponse(true, ResponseCode.MORE_DATA, commsSession); bytesSent += flowFile.getSize(); final String transitUri = createTransitUri(peer, flowFile.getAttribute(CoreAttributes.UUID.key())); session.getProvenanceReporter().send(flowFile, transitUri, "Remote Host=" + peer.getHost() + ", Remote DN=" + remoteDn, transmissionMillis, false); session.remove(flowFile); if (continueTransaction) { logger.debug("{} Sending ContinueTransaction indicator to {}", this, peer); writeTransactionResponse(true, ResponseCode.CONTINUE_TRANSACTION, commsSession); } else { logger.debug("{} Sending FinishTransaction indicator to {}", this, peer); writeTransactionResponse(true, ResponseCode.FINISH_TRANSACTION, commsSession); calculatedCRC = String.valueOf(checkedOutputStream.getChecksum().getValue()); return commitTransferTransaction(peer, transaction);
@Override public int commitReceiveTransaction(Peer peer) throws IOException, IllegalStateException { logger.debug("{} Committing the receive transaction. peer={}", this, peer); HttpServerCommunicationsSession commSession = (HttpServerCommunicationsSession) peer.getCommunicationsSession(); String transactionId = commSession.getTransactionId(); FlowFileTransaction transaction = transactionManager.finalizeTransaction(transactionId); commSession.setStatus(Transaction.TransactionState.TRANSACTION_CONFIRMED); return super.commitReceiveTransaction(peer, transaction); }
break; case PORT_IDENTIFIER: { checkPortStatus(peer, value);