package de.tblsoft.search.pipeline;

import de.tblsoft.search.pipeline.filter.Filter;

/**
 * Created by tbl on 11.11.17.
 */
public class PipelineExecuterService {

    private Pipeline pipeline;

    public PipelineExecuterService(Pipeline pipeline) {
        this.pipeline = pipeline;
    }

    public PipelineContainer execute(PipelineContainer pipelineContainer) throws PipelineContainerException {

        pipelineContainer.start();

        for(Filter filter : pipeline.getFilterList()) {
            filter.init();
        }


        for(Filter filter : pipeline.getFilterList()) {
            failOnError(pipelineContainer);
            try {
                filter.start();
                if(filter.isActive()) {
                    pipelineContainer = filter.filter(pipelineContainer);
                }
            } catch (Exception e) {
                filter.onError(pipelineContainer, e);
            }
        }

        failOnError(pipelineContainer);

        for(Filter filter : pipeline.getFilterList()) {
            filter.end();
        }

        return pipelineContainer;
    }

    public static void failOnError(PipelineContainer pipelineContainer) throws PipelineContainerException {
        if(pipelineContainer.isFailOnError() && !pipelineContainer.isSuccess()) {
            throw new PipelineContainerException(pipelineContainer.getMessage());
        }
    }

}

@@ -78,16 +78,73 @@
 .Filter;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0A/**%0A *
@@ -212,24 +212,113 @@
 rService %7B%0A%0A
+    private static Logger LOG = LoggerFactory.getLogger(PipelineExecuterService.class);%0A%0A
     private 
@@ -950,32 +950,139 @@
               %7D%0A
+                LOG.debug(%22The filter: %22 + filter.getId() + %22 took: %22 + filter.getCurrentTime() + %22 ms.%22);%0A
             %7D ca

add logging to log the duration of the filters in debug log level