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.common.settings.Settings; 019import org.xbib.elasticsearch.plugin.jdbc.client.IngestFactory; 020import org.xbib.elasticsearch.plugin.jdbc.client.Metric; 021import org.xbib.elasticsearch.plugin.jdbc.util.IndexableObject; 022 023import java.io.IOException; 024import java.util.Map; 025 026/** 027 * The river mouth is the abstraction of the destination where all the data 028 * is flowing from the river source. 029 */ 030public interface RiverMouth<RC extends RiverContext> { 031 032 /** 033 * The river strategy 034 * 035 * @return the strategy 036 */ 037 String strategy(); 038 039 /** 040 * Create a new river mouth instance 041 * 042 * @return new river mouth instance 043 */ 044 RiverMouth<RC> newInstance(); 045 046 /** 047 * Set the river context 048 * 049 * @param context the river context 050 * @return this river mouth 051 */ 052 RiverMouth<RC> setRiverContext(RC context); 053 054 /** 055 * Set ingest factory 056 * 057 * @param ingestFactory the ingest factory 058 * @return this river mouth 059 */ 060 RiverMouth setIngestFactory(IngestFactory ingestFactory); 061 062 /** 063 * Get the metrics of this river mouth 064 * 065 * @return this river mouth 066 */ 067 Metric getMetric(); 068 069 /** 070 * Set index settings 071 * 072 * @param indexSettings the index settings 073 * @return this river mouth 074 */ 075 RiverMouth setIndexSettings(Settings indexSettings); 076 077 /** 078 * Set index type mappings 079 * 080 * @param typeMapping the index type mappings 081 * @return this river mouth 082 */ 083 RiverMouth setTypeMapping(Map<String, String> typeMapping); 084 085 /** 086 * Executed before river source fetch 087 * 088 * @throws Exception 089 */ 090 void beforeFetch() throws Exception; 091 092 /** 093 * Executed after river source fetch 094 * 095 * @throws Exception 096 */ 097 void afterFetch() throws Exception; 098 099 /** 100 * Set default index name for this river mouth 101 * 102 * @param index the default index name 103 * @return this river mouth 104 */ 105 RiverMouth setIndex(String index); 106 107 /** 108 * Get default index name of this river mouth 109 * 110 * @return the index name 111 */ 112 String getIndex(); 113 114 /** 115 * Set default index type name for this river mouth 116 * 117 * @param type the default index type name for this river mouth 118 * @return this river mouth 119 */ 120 RiverMouth setType(String type); 121 122 /** 123 * Get default index type name of this river mouth 124 * 125 * @return the default index type name of this river mouth 126 */ 127 String getType(); 128 129 /** 130 * Set document identifier for next document to be indexed 131 * 132 * @param id the id 133 * @return this river mouth 134 */ 135 RiverMouth setId(String id); 136 137 /** 138 * Get document identifier 139 * 140 * @return the document identifier 141 */ 142 String getId(); 143 144 /** 145 * Index operation. Indicating that an object has been built and is ready to be indexed. 146 * The source of the document is held by the XContentBuilder. 147 * 148 * @param object the indexable object 149 * @param create true if the document should be created 150 * @throws IOException when indexing fails 151 */ 152 void index(IndexableObject object, boolean create) throws IOException; 153 154 /** 155 * Delete operation. Indicating that an object should be deleted from the index. 156 * 157 * @param object the structured object 158 * @throws IOException when delete fails 159 */ 160 void delete(IndexableObject object) throws IOException; 161 162 /** 163 * Flush data to the river mouth 164 * 165 * @throws IOException when flush fails 166 */ 167 void flush() throws IOException; 168 169 /** 170 * Shutdown river mouth and release all resources, e.g. bulk processor and client 171 */ 172 void shutdown() throws IOException; 173 174 /** 175 * Suspend river mouth. Do not proceed with indexing and wait for resume. 176 * 177 * @throws Exception 178 */ 179 void suspend() throws Exception; 180 181 /** 182 * Resume river mouth after suspend. 183 * 184 * @throws Exception 185 */ 186 void resume() throws Exception; 187 188}