本文整理汇总了Java中org.apache.solr.client.solrj.impl.LBHttpSolrServer类的典型用法代码示例。如果您正苦于以下问题:Java LBHttpSolrServer类的具体用法?Java LBHttpSolrServer怎么用?Java LBHttpSolrServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LBHttpSolrServer类属于org.apache.solr.client.solrj.impl包,在下文中一共展示了LBHttpSolrServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReliability
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
public void testReliability() throws Exception {
String[] s = new String[solr.length];
for (int i = 0; i < solr.length; i++) {
s[i] = solr[i].getUrl();
}
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, 250);
params.set(HttpClientUtil.PROP_SO_TIMEOUT, 250);
HttpClient myHttpClient = HttpClientUtil.createClient(params);
LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(myHttpClient, s);
lbHttpSolrServer.setAliveCheckInterval(500);
// Kill a server and test again
solr[1].jetty.stop();
solr[1].jetty = null;
// query the servers
for (String value : s)
lbHttpSolrServer.query(new SolrQuery("*:*"));
// Start the killed server once again
solr[1].startJetty();
// Wait for the alive check to complete
waitForServer(30000, lbHttpSolrServer, 3, "solr1");
}
示例2: setUrlScheme
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
private void setUrlScheme(String value) throws Exception {
@SuppressWarnings("rawtypes")
Map m = makeMap("action", CollectionAction.CLUSTERPROP.toString()
.toLowerCase(Locale.ROOT), "name", "urlScheme", "val", value);
@SuppressWarnings("unchecked")
SolrParams params = new MapSolrParams(m);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
List<String> urls = new ArrayList<String>();
for(Replica replica : getReplicas()) {
urls.add(replica.getStr(ZkStateReader.BASE_URL_PROP));
}
//Create new SolrServer to configure new HttpClient w/ SSL config
new LBHttpSolrServer(urls.toArray(new String[]{})).request(request);
}
示例3: createAndConfigure
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
@Override
public SolrServer createAndConfigure(final String proxyRole, final Configuration<Map<String, Object>> configuration) {
final List<String> servers = new ArrayList<String>();
for (int i = 0;; i++) {
final String server = configuration.getParameter(
new StringBuilder(proxyRole)
.append(i)
.append(ADDRESS)
.toString(),
null);
if (server == null) {
break;
}
servers.add(server);
}
try {
return (!servers.isEmpty()
? new LBHttpSolrServer(servers.toArray(new String[servers.size()]))
: new HttpSolrServer(DEFAULT_ADDRESS));
} catch (final Exception exception) {
return new HttpSolrServer(DEFAULT_ADDRESS);
}
}
示例4: buildQuerySolrServer
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
/**
* 建造查询用SolrServer
*/
private void buildQuerySolrServer() {
this.validConf(); // 必须是已配置的对象
Type type = this.conf.getType();
if (this.isSingle()) { // 单服务器节点
if (type.accept(HttpSolrServer.class)) {
this.querySolrServer = this.buildHttpSolrServer();
this.httpSolrServer = this.querySolrServer;
}
}
if (this.querySolrServer == null) { // 负载均衡SolrServer
if (type.accept(LBHttpSolrServer.class)) {
this.querySolrServer = this.buildLBHttpSolrServer();
}
}
this.querySolrServerBuilt = true;
}
示例5: accept
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
@Override
public boolean accept(Class<?> solrServerClass) {
if (solrServerClass == null) {
return false;
}
if (LBHttpSolrServer.class.equals(solrServerClass)) {
return true;
}
if (HttpSolrServer.class.equals(solrServerClass)) {
return true;
}
if (this.accept(solrServerClass.getSuperclass())) {
return true;
}
return false;
}
示例6: testFactory
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
@Test
@Ignore
public void testFactory() {
assertNotNull(masterFactory);
SolrServer solrServer = this.masterFactory.getUpdateSolrServer();
assertTrue(solrServer instanceof ConcurrentUpdateSolrServer);
solrServer = this.masterFactory.getUpdateSolrServer(true);
assertTrue(solrServer.getClass().equals(HttpSolrServer.class));
solrServer = this.masterFactory.getQuerySolrServer();
assertTrue(solrServer.getClass().equals(HttpSolrServer.class));
assertNotNull(slavesFactory);
solrServer = this.slavesFactory.getUpdateSolrServer();
assertTrue(solrServer == null);
solrServer = this.slavesFactory.getUpdateSolrServer(true);
assertTrue(solrServer == null);
solrServer = this.slavesFactory.getQuerySolrServer();
assertTrue(solrServer instanceof LBHttpSolrServer);
}
示例7: cloneLBHttpSolrServer
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
private static LBHttpSolrServer cloneLBHttpSolrServer(SolrServer solrServer, String core) {
if (solrServer == null) {
return null;
}
LBHttpSolrServer clone = null;
try {
if (VersionUtil.isSolr3XAvailable()) {
clone = cloneSolr3LBHttpServer(solrServer, core);
} else if (VersionUtil.isSolr4XAvailable()) {
clone = cloneSolr4LBHttpServer(solrServer, core);
}
} catch (MalformedURLException e) {
throw new BeanInstantiationException(solrServer.getClass(), "Cannot create instace of " + solrServer.getClass()
+ ". ", e);
}
Object o = readField(solrServer, "interval");
if (o != null) {
clone.setAliveCheckInterval(Integer.valueOf(o.toString()).intValue());
}
return clone;
}
示例8: cloneCloudSolrServer
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
private static SolrServer cloneCloudSolrServer(SolrServer solrServer, String core) {
if (VersionUtil.isSolr3XAvailable() || solrServer == null) {
return null;
}
CloudSolrServer cloudServer = (CloudSolrServer) solrServer;
String zkHost = readField(solrServer, "zkHost");
Constructor<? extends SolrServer> constructor = (Constructor<? extends SolrServer>) ClassUtils
.getConstructorIfAvailable(solrServer.getClass(), String.class, LBHttpSolrServer.class);
CloudSolrServer clone = (CloudSolrServer) BeanUtils.instantiateClass(constructor, zkHost,
cloneLBHttpSolrServer(cloudServer.getLbServer(), core));
if (org.springframework.util.StringUtils.hasText(core)) {
clone.setDefaultCollection(core);
}
return clone;
}
示例9: testClonesCloudSolrServerForCoreCorrectlyWhenCoreNameIsNotEmpty
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testClonesCloudSolrServerForCoreCorrectlyWhenCoreNameIsNotEmpty() throws MalformedURLException {
LBHttpSolrServer lbSolrServer = new LBHttpSolrServer(BASE_URL, ALTERNATE_BASE_URL);
CloudSolrServer cloudServer = new CloudSolrServer(ZOO_KEEPER_URL, lbSolrServer);
CloudSolrServer clone = SolrServerUtils.clone(cloudServer, CORE_NAME);
Assert.assertEquals(ZOO_KEEPER_URL, ReflectionTestUtils.getField(clone, FIELD_ZOO_KEEPER));
LBHttpSolrServer lbClone = clone.getLbServer();
Map<String, ?> aliveServers = (Map<String, ?>) ReflectionTestUtils.getField(lbClone, FIELD_ALIVE_SERVERS);
Assert.assertThat(aliveServers.keySet(), hasItems(CORE_URL, ALTERNATE_CORE_URL));
assertLBHttpSolrServerProperties(lbSolrServer, lbClone);
Assert.assertThat(clone.getDefaultCollection(), equalTo(CORE_NAME));
}
示例10: getLBHttpSolrServer
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
/**
* create SolrProvider with LBHttpSolrServer.
*/
private static SolrProvider getLBHttpSolrServer(String solrServerUrls,
String coreName, int commitWithinMs) {
String[] solrURLs = solrServerUrls.split(",");
String description = solrServerUrls;
// handle coreName
if (coreName != null && coreName.length() > 0) {
description = "";
for (int i = 0; i < solrURLs.length; i++) {
solrURLs[i] = solrURLs[i] + "/" + coreName;
description += "," + solrURLs[i];
}
description = description.replaceFirst(",", "");
}
try {
return new SolrProvider(new LBHttpSolrServer(solrURLs),
commitWithinMs, "LBHttpSolrServer(\"" + description + "\")");
} catch (MalformedURLException murlEx) {
// LBHttpSolrServer does not throw this exception
return null;
}
}
示例11: testTwoServers
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
public void testTwoServers() throws Exception {
LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient, solr[0].getUrl(), solr[1].getUrl());
lbHttpSolrServer.setAliveCheckInterval(500);
SolrQuery solrQuery = new SolrQuery("*:*");
QueryResponse resp = null;
solr[0].jetty.stop();
solr[0].jetty = null;
resp = lbHttpSolrServer.query(solrQuery);
String name = resp.getResults().get(0).getFieldValue("name").toString();
Assert.assertEquals("solr/collection11", name);
resp = lbHttpSolrServer.query(solrQuery);
name = resp.getResults().get(0).getFieldValue("name").toString();
Assert.assertEquals("solr/collection11", name);
solr[1].jetty.stop();
solr[1].jetty = null;
solr[0].startJetty();
Thread.sleep(1200);
try {
resp = lbHttpSolrServer.query(solrQuery);
} catch(SolrServerException e) {
// try again after a pause in case the error is lack of time to start server
Thread.sleep(3000);
resp = lbHttpSolrServer.query(solrQuery);
}
name = resp.getResults().get(0).getFieldValue("name").toString();
Assert.assertEquals("solr/collection10", name);
}
示例12: waitForServer
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
private void waitForServer(int maximum, LBHttpSolrServer server, int nServers, String serverName) throws Exception {
long endTime = System.currentTimeMillis() + maximum;
while (System.currentTimeMillis() < endTime) {
QueryResponse resp;
try {
resp = server.query(new SolrQuery("*:*"));
} catch (Exception e) {
log.warn("", e);
continue;
}
String name = resp.getResults().get(0).getFieldValue("name").toString();
if (name.equals(serverName))
return;
}
}
示例13: createLoadBalancedHttpSolrServer
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
private void createLoadBalancedHttpSolrServer() {
try {
LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(StringUtils.split(this.url, SERVER_URL_SEPARATOR));
if (timeout != null) {
lbHttpSolrServer.setConnectionTimeout(timeout.intValue());
}
this.setSolrServer(lbHttpSolrServer);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Unable to create Load Balanced Http Solr Server", e);
}
}
示例14: cloneSolr3LBHttpServer
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
private static LBHttpSolrServer cloneSolr3LBHttpServer(SolrServer solrServer, String core)
throws MalformedURLException {
CopyOnWriteArrayList<?> list = readField(solrServer, "aliveServers");
String[] servers = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
servers[i] = appendCoreToBaseUrl(list.get(i).toString(), core);
}
return new LBHttpSolrServer(servers);
}
示例15: cloneSolr4LBHttpServer
import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入依赖的package包/类
private static LBHttpSolrServer cloneSolr4LBHttpServer(SolrServer solrServer, String core)
throws MalformedURLException {
Map<String, ?> map = readField(solrServer, "aliveServers");
String[] servers = new String[map.size()];
int i = 0;
for (String key : map.keySet()) {
servers[i] = appendCoreToBaseUrl(key, core);
i++;
}
return new LBHttpSolrServer(servers);
}