private void handleFeedIntakeJobFinishMessage(FeedIntakeInfo intakeInfo, Message message)
      throws Exception {
    IHyracksClientConnection hcc = AsterixAppContextInfo.getInstance().getHcc();
    JobInfo info = hcc.getJobInfo(message.jobId);
    JobStatus status = info.getStatus();
    FeedLifecycleEvent event;
    event =
        status.equals(JobStatus.FAILURE)
            ? FeedLifecycleEvent.FEED_INTAKE_FAILURE
            : FeedLifecycleEvent.FEED_ENDED;

    // remove feed joints
    deregisterFeedIntakeJob(message.jobId);

    // notify event listeners
    notifyFeedEventSubscribers(intakeInfo, event);
  }
  private void handleFeedCollectJobFinishMessage(FeedConnectJobInfo cInfo) throws Exception {
    FeedConnectionId connectionId = cInfo.getConnectionId();

    IHyracksClientConnection hcc = AsterixAppContextInfo.getInstance().getHcc();
    JobInfo info = hcc.getJobInfo(cInfo.getJobId());
    JobStatus status = info.getStatus();
    boolean failure = status != null && status.equals(JobStatus.FAILURE);
    FeedPolicyAccessor fpa = new FeedPolicyAccessor(cInfo.getFeedPolicy());

    boolean removeJobHistory = !failure;
    boolean retainSubsription =
        cInfo.getState().equals(FeedJobState.UNDER_RECOVERY)
            || (failure && fpa.continueOnHardwareFailure());

    if (!retainSubsription) {
      IFeedJoint feedJoint = cInfo.getSourceFeedJoint();
      feedJoint.removeReceiver(connectionId);
      if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info(
            "Subscription "
                + cInfo.getConnectionId()
                + " completed successfully. Removed subscription");
      }
      removeFeedJointsPostPipelineTermination(cInfo.getConnectionId());
    }

    if (removeJobHistory) {
      connectJobInfos.remove(connectionId);
      jobInfos.remove(cInfo.getJobId());
      feedIntakeProgressTrackers.remove(cInfo.getConnectionId());
    }
    deregisterFeedActivity(cInfo);

    // notify event listeners
    FeedLifecycleEvent event =
        failure ? FeedLifecycleEvent.FEED_COLLECT_FAILURE : FeedLifecycleEvent.FEED_ENDED;
    notifyFeedEventSubscribers(cInfo, event);
  }