| 642 | } |
| 643 | |
| 644 | bool SiteToSiteClient::receiveFlowFiles(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSession> &session) { |
| 645 | uint64_t bytes = 0; |
| 646 | int transfers = 0; |
| 647 | std::shared_ptr<Transaction> transaction = NULL; |
| 648 | |
| 649 | if (peer_state_ != READY) { |
| 650 | if (!bootstrap()) { |
| 651 | return false; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | if (peer_state_ != READY) { |
| 656 | context->yield(); |
| 657 | tearDown(); |
| 658 | throw Exception(SITE2SITE_EXCEPTION, "Can not establish handshake with peer"); |
| 659 | } |
| 660 | |
| 661 | // Create the transaction |
| 662 | transaction = createTransaction(RECEIVE); |
| 663 | |
| 664 | if (transaction == NULL) { |
| 665 | context->yield(); |
| 666 | tearDown(); |
| 667 | throw Exception(SITE2SITE_EXCEPTION, "Can not create transaction"); |
| 668 | } |
| 669 | |
| 670 | utils::Identifier transactionID = transaction->getUUID(); |
| 671 | |
| 672 | try { |
| 673 | while (true) { |
| 674 | std::map<std::string, std::string> empty; |
| 675 | uint64_t startTime = utils::timeutils::getTimeMillis(); |
| 676 | std::string payload; |
| 677 | DataPacket packet(getLogger(), transaction, empty, payload); |
| 678 | bool eof = false; |
| 679 | |
| 680 | if (!receive(transactionID, &packet, eof)) { |
| 681 | throw Exception(SITE2SITE_EXCEPTION, "Receive Failed " + transactionID.to_string()); |
| 682 | } |
| 683 | if (eof) { |
| 684 | // transaction done |
| 685 | break; |
| 686 | } |
| 687 | auto flowFile = session->create(); |
| 688 | |
| 689 | if (!flowFile) { |
| 690 | throw Exception(SITE2SITE_EXCEPTION, "Flow File Creation Failed"); |
| 691 | } |
| 692 | std::map<std::string, std::string>::iterator it; |
| 693 | std::string sourceIdentifier; |
| 694 | for (it = packet._attributes.begin(); it != packet._attributes.end(); it++) { |
| 695 | if (it->first == core::SpecialFlowAttribute::UUID) |
| 696 | sourceIdentifier = it->second; |
| 697 | flowFile->addAttribute(it->first, it->second); |
| 698 | } |
| 699 | |
| 700 | if (packet._size > 0) { |
| 701 | sitetosite::WriteCallback callback(&packet); |
nothing calls this directly
no test coverage detected