com.jslsolucoes.elasticsearch.ee.ElasticSearch Maven / Gradle / Ivy
package com.jslsolucoes.elasticsearch.ee;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import javax.inject.Inject;
import org.apache.http.HttpHost;
import com.jslsolucoes.properties.ee.Properties;
import com.jslsolucoes.properties.ee.PropertyValue;
@Properties("elasticsearch.properties")
public class ElasticSearch {
@PropertyValue(key = "elasticsearch.endpoints", defaultValue = "http://localhost:9200")
@Inject
private String endpoints;
public HttpHost[] getHosts() {
List hosts = new ArrayList<>();
StringTokenizer stringTokenizer = new StringTokenizer(endpoints, ",");
while (stringTokenizer.hasMoreTokens()) {
try {
URL endpoint = new URL(stringTokenizer.nextToken());
hosts.add(new HttpHost(endpoint.getHost(), endpoint.getPort(), endpoint.getProtocol()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return hosts.toArray(new HttpHost[] {});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy