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.river.jdbc;
017
018import org.elasticsearch.client.Client;
019import org.elasticsearch.common.metrics.MeterMetric;
020import org.elasticsearch.common.settings.Settings;
021import org.elasticsearch.river.RiverName;
022import org.xbib.elasticsearch.plugin.jdbc.client.IngestFactory;
023
024import java.util.Queue;
025
026/**
027 * A RiverFlow is the controlling component for creatin RiverContexts
028 * which can be processed independently from each other. By doing this,
029 * RiverContexts can be processed
030 *
031 * @param <RC>
032 */
033public interface RiverFlow<RC extends RiverContext> {
034
035    /**
036     * The name of the strategy the river flow belongs to
037     *
038     * @return the strategy name
039     */
040    String strategy();
041
042    RiverFlow<RC> newInstance();
043
044    /**
045     * Create a new river context for a river run
046     *
047     * @return a new river context
048     */
049    RC newRiverContext();
050
051    /**
052     * Sets the river name
053     *
054     * @param riverName the river name
055     * @return this river name
056     */
057    RiverFlow setRiverName(RiverName riverName);
058
059    /**
060     * Gets the river name
061     *
062     * @return the river name
063     */
064    RiverName getRiverName();
065
066    /**
067     * Set the settings
068     *
069     * @param settings the settings
070     * @return this river flow
071     */
072    RiverFlow setSettings(Settings settings);
073
074    /**
075     * Get the settings
076     *
077     * @return the settings
078     */
079    Settings getSettings();
080
081    /**
082     * Set ingest factory
083     *
084     * @param ingestFactory ingest factory
085     * @return this river flow
086     */
087    RiverFlow setIngestFactory(IngestFactory ingestFactory);
088
089    RiverFlow setClient(Client client);
090
091    /**
092     * Get the client
093     *
094     * @return the client
095     */
096    Client getClient();
097
098    /**
099     * Log metrics
100     *
101     * @param cause the cause why metrics are logged
102     */
103    void logMetrics(RiverContext riverContext, String cause);
104
105    /**
106     * Execute this river flow
107     *
108     * @throws Exception
109     */
110    void execute(RC riverContext) throws Exception;
111
112    /**
113     * Set metric
114     *
115     * @param meterMetric the meter metric
116     * @return this river flow
117     */
118    RiverFlow setMetric(MeterMetric meterMetric);
119
120    /**
121     * Get metric
122     *
123     * @return river metric
124     */
125    MeterMetric getMetric();
126
127    /**
128     * Set queue for processing RiverContext requests
129     *
130     * @param queue the queue
131     * @return this river flow
132     */
133    RiverFlow setQueue(Queue<RiverContext> queue);
134
135    /**
136     * Get queue for RiverContext processing
137     *
138     * @return the queue for processing RiverContext requests
139     */
140    Queue<RiverContext> getQueue();
141
142}