001/*
002 * Copyright (C) 2014 Jörg Prante
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.xbib.elasticsearch.plugin.jdbc.pipeline.executor;
017
018import org.elasticsearch.common.metrics.MeterMetric;
019import org.xbib.elasticsearch.plugin.jdbc.pipeline.Pipeline;
020import org.xbib.elasticsearch.plugin.jdbc.pipeline.PipelineProvider;
021import org.xbib.elasticsearch.plugin.jdbc.pipeline.PipelineRequest;
022
023import java.util.concurrent.ExecutionException;
024
025public class MetricSimplePipelineExecutor<T, R extends PipelineRequest, P extends Pipeline<T, R>>
026        extends SimplePipelineExecutor<T, R, P> {
027
028    private final MeterMetric metric;
029
030    public MetricSimplePipelineExecutor(MeterMetric meterMetric) {
031        this.metric = meterMetric;
032    }
033
034    @Override
035    public MetricSimplePipelineExecutor<T, R, P> setConcurrency(int concurrency) {
036        super.setConcurrency(concurrency);
037        return this;
038    }
039
040    @Override
041    public MetricSimplePipelineExecutor<T, R, P> setPipelineProvider(PipelineProvider<P> provider) {
042        super.setPipelineProvider(provider);
043        return this;
044    }
045
046    @Override
047    public MetricSimplePipelineExecutor<T, R, P> prepare() {
048        super.prepare();
049        return this;
050    }
051
052    @Override
053    public MetricSimplePipelineExecutor<T, R, P> execute() {
054        super.execute();
055        return this;
056    }
057
058    @Override
059    public MetricSimplePipelineExecutor<T, R, P> waitFor()
060            throws InterruptedException, ExecutionException {
061        super.waitFor();
062        metric.stop();
063        return this;
064    }
065
066    public MeterMetric metric() {
067        return metric;
068    }
069}