List of usage examples for org.apache.solr.client.solrj.impl LBHttpSolrClient LBHttpSolrClient
protected LBHttpSolrClient(Builder builder)
From source file:com.frank.search.solr.server.support.HttpSolrClientFactoryBean.java
License:Apache License
private void createCloudClient() { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections);// 1000 params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost);// 5000 params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, timeout); params.set(HttpClientUtil.PROP_SO_TIMEOUT, timeout); HttpClient client = HttpClientUtil.createClient(params); LBHttpSolrClient lbHttpSolrClient = new LBHttpSolrClient(client); CloudSolrClient cloudSolrClient = new CloudSolrClient(url, lbHttpSolrClient); if (zkClientTimeout != null) { cloudSolrClient.setZkClientTimeout(zkClientTimeout.intValue()); }/* w w w .j a v a 2 s . co m*/ if (zkConnectTimeout != null) { cloudSolrClient.setZkConnectTimeout(zkConnectTimeout.intValue()); } if (StringUtils.isNoneBlank(collection)) { cloudSolrClient.setDefaultCollection(collection); } cloudSolrClient.connect(); this.setSolrClient(cloudSolrClient); }
From source file:com.frank.search.solr.server.support.HttpSolrClientFactoryBean.java
License:Apache License
private void createLoadBalancedHttpSolrClient() { try {/*from w w w .ja v a 2s . c om*/ LBHttpSolrClient lbHttpSolrClient = new LBHttpSolrClient( StringUtils.split(this.url, SERVER_URL_SEPARATOR)); if (timeout != null) { lbHttpSolrClient.setConnectionTimeout(timeout.intValue()); } this.setSolrClient(lbHttpSolrClient); } catch (MalformedURLException e) { throw new IllegalArgumentException("Unable to create Load Balanced Http Solr Server", e); } }
From source file:com.frank.search.solr.server.support.SolrClientUtils.java
License:Apache License
private static LBHttpSolrClient cloneSolr3LBHttpServer(SolrClient solrClient, String core) throws MalformedURLException { CopyOnWriteArrayList<?> list = readField(solrClient, "aliveServers"); String[] servers = new String[list.size()]; for (int i = 0; i < list.size(); i++) { servers[i] = appendCoreToBaseUrl(list.get(i).toString(), core); }//w w w. ja v a 2 s . c o m return new LBHttpSolrClient(servers); }
From source file:org.apache.ranger.audit.destination.SolrAuditDestination.java
License:Apache License
synchronized void connect() { SolrClient me = solrClient;/* w w w . j a va2 s . c om*/ if (me == null) { synchronized (SolrAuditDestination.class) { me = solrClient; if (solrClient == null) { String urls = MiscUtil.getStringProperty(props, propPrefix + "." + PROP_SOLR_URLS); if (urls != null) { urls = urls.trim(); } if (urls != null && urls.equalsIgnoreCase("NONE")) { urls = null; } List<String> solrURLs = new ArrayList<String>(); String zkHosts = null; solrURLs = MiscUtil.toArray(urls, ","); zkHosts = MiscUtil.getStringProperty(props, propPrefix + "." + PROP_SOLR_ZK); if (zkHosts != null && zkHosts.equalsIgnoreCase("NONE")) { zkHosts = null; } String collectionName = MiscUtil.getStringProperty(props, propPrefix + "." + PROP_SOLR_COLLECTION); if (collectionName == null || collectionName.equalsIgnoreCase("none")) { collectionName = DEFAULT_COLLECTION_NAME; } LOG.info("Solr zkHosts=" + zkHosts + ", solrURLs=" + urls + ", collectionName=" + collectionName); if (zkHosts != null && !zkHosts.isEmpty()) { LOG.info("Connecting to solr cloud using zkHosts=" + zkHosts); try { // Instantiate HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); final String zkhosts = zkHosts; PrivilegedExceptionAction<CloudSolrClient> action = new PrivilegedExceptionAction<CloudSolrClient>() { @Override public CloudSolrClient run() throws Exception { CloudSolrClient solrCloudClient = new CloudSolrClient(zkhosts); return solrCloudClient; }; }; CloudSolrClient solrCloudClient = null; UserGroupInformation ugi = MiscUtil.getUGILoginUser(); if (ugi != null) { solrCloudClient = ugi.doAs(action); } else { solrCloudClient = action.run(); } solrCloudClient.setDefaultCollection(collectionName); me = solrClient = solrCloudClient; } catch (Throwable t) { LOG.fatal("Can't connect to Solr server. ZooKeepers=" + zkHosts, t); } finally { resetInitializerInSOLR(); } } else if (solrURLs != null && !solrURLs.isEmpty()) { try { LOG.info("Connecting to Solr using URLs=" + solrURLs); HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); final List<String> solrUrls = solrURLs; PrivilegedExceptionAction<LBHttpSolrClient> action = new PrivilegedExceptionAction<LBHttpSolrClient>() { @Override public LBHttpSolrClient run() throws Exception { LBHttpSolrClient lbSolrClient = new LBHttpSolrClient(solrUrls.get(0)); return lbSolrClient; }; }; LBHttpSolrClient lbSolrClient = null; UserGroupInformation ugi = MiscUtil.getUGILoginUser(); if (ugi != null) { lbSolrClient = ugi.doAs(action); } else { lbSolrClient = action.run(); } lbSolrClient.setConnectionTimeout(1000); for (int i = 1; i < solrURLs.size(); i++) { lbSolrClient.addSolrServer(solrURLs.get(i)); } me = solrClient = lbSolrClient; } catch (Throwable t) { LOG.fatal("Can't connect to Solr server. URL=" + solrURLs, t); } finally { resetInitializerInSOLR(); } } } } } }
From source file:org.dbflute.solr.bhv.AbstractSolrBehavior.java
License:Apache License
/** * Create LBHttpSolrClient associated with the assigned list of URLs. * @param urlList List of URL (NotNull)/*from ww w . jav a 2s.c om*/ * @return LBHttpSolrClient (NotNull) */ protected LBHttpSolrClient createLBHttpSolrClient(List<String> urlList) { LBHttpSolrClient client; try { client = new LBHttpSolrClient(urlList.toArray(new String[] {})); } catch (MalformedURLException e) { throw new SolrException("Failed to create Select Solr Client", e); } client.setConnectionTimeout(getConnectionTimeout()); client.setSoTimeout(getSocketTimeout()); client.setAliveCheckInterval(getAliveCheckInterval()); adjustHttpClient(client.getHttpClient()); return client; }
From source file:org.seedstack.solr.internal.SolrPlugin.java
License:Mozilla Public License
private SolrClient buildLBSolrClient(Configuration solrClientConfiguration, String[] lbUrls) throws MalformedURLException { LBHttpSolrClient lbHttpSolrClient = new LBHttpSolrClient(lbUrls); if (solrClientConfiguration.containsKey(SolrConfigurationConstants.CONNECTION_TIMEOUT)) { lbHttpSolrClient.setConnectionTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.CONNECTION_TIMEOUT)); }//from w w w.ja v a 2s.c om if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ALIVE_CHECK_INTERVAL)) { lbHttpSolrClient.setAliveCheckInterval( solrClientConfiguration.getInt(SolrConfigurationConstants.ALIVE_CHECK_INTERVAL)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.QUERY_PARAMS)) { lbHttpSolrClient.setQueryParams(Sets .newHashSet(solrClientConfiguration.getStringArray(SolrConfigurationConstants.QUERY_PARAMS))); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.SO_TIMEOUT)) { lbHttpSolrClient.setSoTimeout(solrClientConfiguration.getInt(SolrConfigurationConstants.SO_TIMEOUT)); } return lbHttpSolrClient; }
From source file:org.seedstack.solr.internal.SolrPlugin.java
License:Mozilla Public License
private CloudSolrClient buildCloudSolrClient(Configuration solrClientConfiguration, String[] zooKeeperUrls) throws MalformedURLException { String[] lbUrls = solrClientConfiguration.getStringArray(SolrConfigurationConstants.LB_URLS); CloudSolrClient cloudSolrClient;//from www .j a va 2s .c o m if (lbUrls != null && lbUrls.length > 0) { cloudSolrClient = new CloudSolrClient(zooKeeperUrls[0], new LBHttpSolrClient(lbUrls), solrClientConfiguration.getBoolean(SolrConfigurationConstants.UPDATE_TO_LEADERS, true)); } else { cloudSolrClient = new CloudSolrClient(Lists.newArrayList(zooKeeperUrls), solrClientConfiguration.getString(SolrConfigurationConstants.CHROOT)); } String defaultCollection = solrClientConfiguration.getString(SolrConfigurationConstants.DEFAULT_COLLECTION); if (defaultCollection != null && !defaultCollection.isEmpty()) { cloudSolrClient.setDefaultCollection(defaultCollection); } String idField = solrClientConfiguration.getString(SolrConfigurationConstants.ID_FIELD); if (idField != null && !idField.isEmpty()) { cloudSolrClient.setIdField(idField); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.COLLECTION_CACHE_TTL)) { cloudSolrClient.setCollectionCacheTTl( solrClientConfiguration.getInt(SolrConfigurationConstants.COLLECTION_CACHE_TTL)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.PARALLEL_CACHE_REFRESHES)) { cloudSolrClient.setParallelCacheRefreshes( solrClientConfiguration.getInt(SolrConfigurationConstants.PARALLEL_CACHE_REFRESHES)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.PARALLEL_UPDATES)) { cloudSolrClient.setParallelUpdates( solrClientConfiguration.getBoolean(SolrConfigurationConstants.PARALLEL_UPDATES)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ZK_CLIENT_TIMEOUT)) { cloudSolrClient.setZkClientTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.ZK_CLIENT_TIMEOUT)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ZK_CONNECT_TIMEOUT)) { cloudSolrClient.setZkConnectTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.ZK_CONNECT_TIMEOUT)); } return cloudSolrClient; }
From source file:org.springframework.data.solr.server.support.SolrClientFactoryBean.java
License:Apache License
/** * Creates a {@link LBHttpSolrClient}.//from w w w. ja v a2 s . c om */ private void createLoadBalancedHttpSolrClient() { try { final LBHttpSolrClient solrClient = new LBHttpSolrClient(StringUtils.split(path, PATH_SEPARATOR)); if (timeout != null) { solrClient.setConnectionTimeout(timeout); } setSolrClient(solrClient); } catch (final MalformedURLException e) { throw new IllegalArgumentException( "Unable to create load-balanced Solr server with paths [" + path + "].", e); } }
From source file:uk.bl.wa.solr.SolrWebServer.java
License:Open Source License
/** * Initializes the Solr connection//w ww. jav a 2 s. co m */ public SolrWebServer(Config conf) { try { if (conf.hasPath(CONF_HTTP_SERVER)) { log.info("Setting up HttpSolrServer client from a url: " + conf.getString(CONF_HTTP_SERVER)); solrServer = new HttpSolrClient(conf.getString(CONF_HTTP_SERVER)); } else if (conf.hasPath(CONF_ZOOKEEPERS)) { log.info("Setting up CloudSolrServer client via zookeepers."); solrServer = new CloudSolrClient(conf.getString(CONF_ZOOKEEPERS)); ((CloudSolrClient) solrServer).setDefaultCollection(conf.getString(COLLECTION)); } else if (conf.hasPath(CONF_HTTP_SERVERS)) { log.info("Setting up LBHttpSolrServer client from servers list."); solrServer = new LBHttpSolrClient(conf.getString(CONF_HTTP_SERVERS).split(",")); } else { log.error("No valid SOLR config found."); } } catch (MalformedURLException e) { log.error("WARCIndexerReducer.configure(): " + e.getMessage()); } if (solrServer == null) { System.out.println("Cannot connect to Solr Server!"); } }