List of usage examples for org.apache.solr.client.solrj.impl HttpClientUtil PROP_MAX_CONNECTIONS
String PROP_MAX_CONNECTIONS
To view the source code for org.apache.solr.client.solrj.impl HttpClientUtil PROP_MAX_CONNECTIONS.
Click Source Link
From source file:com.comm.sr.common.solr.SolrQueryService.java
public SolrQueryService(CacheService<String, String> cacheService, Properties settings) { super(cacheService, settings); try {/* w w w. j a v a2 s. com*/ String zkHost = settings.getProperty("solrcloud.zkHost"); int max_connections = Integer.parseInt(settings.getProperty("solrcloud.max_connections")); int max_connections_per_host = Integer .parseInt(settings.getProperty("solrcloud.max_connections_per_host")); int zkConnectTimeout = Integer.parseInt(settings.getProperty("solrcloud.zkConnectTimeout")); int zkClientTimeout = Integer.parseInt(settings.getProperty("solrcloud.zkClientTimeout")); ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, max_connections); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, max_connections_per_host); HttpClient client = HttpClientUtil.createClient(params); LBHttpSolrServer lbServer = new LBHttpSolrServer(client); cloudSolrServer = new CloudSolrServer(zkHost, lbServer); cloudSolrServer.setZkConnectTimeout(zkConnectTimeout); cloudSolrServer.setZkClientTimeout(zkClientTimeout); } catch (Exception e) { } }
From source file:com.comm.sr.service.solr.SolrUpdateService.java
private void populateCloudServers() throws MalformedURLException { String collectNames = solrProperties.getString("solrcloud.collectionNames"); String[] collectionNames_ = collectNames.split(","); for (String collectionNames_1 : collectionNames_) { CloudSolrServer cloudSolrServer = null; String zkHost = solrProperties.getString("solrcloud.zkHost"); int max_connections = Integer.parseInt(solrProperties.getString("solrcloud.max_connections")); int max_connections_per_host = Integer .parseInt(solrProperties.getString("solrcloud.max_connections_per_host")); int zkConnectTimeout = Integer.parseInt(solrProperties.getString("solrcloud.zkConnectTimeout")); int zkClientTimeout = Integer.parseInt(solrProperties.getString("solrcloud.zkClientTimeout")); ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, max_connections); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, max_connections_per_host); HttpClient client = HttpClientUtil.createClient(params); LBHttpSolrServer lbServer = new LBHttpSolrServer(client); cloudSolrServer = new CloudSolrServer(zkHost, lbServer); cloudSolrServer.setZkConnectTimeout(zkConnectTimeout); cloudSolrServer.setZkClientTimeout(zkClientTimeout); cloudSolrServer.setDefaultCollection(collectionNames_1); serverMap.put(collectionNames_1, cloudSolrServer); }//w w w . ja v a2s .c om }
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 a2s . c o m*/ if (zkConnectTimeout != null) { cloudSolrClient.setZkConnectTimeout(zkConnectTimeout.intValue()); } if (StringUtils.isNoneBlank(collection)) { cloudSolrClient.setDefaultCollection(collection); } cloudSolrClient.connect(); this.setSolrClient(cloudSolrClient); }
From source file:com.ilscipio.scipio.solr.util.ScipioHttpSolrClient.java
License:Apache License
/** * Creates a new client from URL and username/password, where all operations will use * the given auth./* w ww .ja v a2s . c om*/ * <p> * DEV NOTE: Implementation must be maintained with the superclass; the default values * are taken from {@link HttpSolrClient.Builder} and are subject to change at solrj updates. */ public static HttpSolrClient create(String baseURL, HttpClient httpClient, String solrUsername, String solrPassword, Integer maxConnections, Integer maxConnectionsPerHost, Integer connectTimeout, Integer socketTimeout) { if (httpClient == null) { ModifiableSolrParams params = new ModifiableSolrParams(); if (maxConnections != null) { params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections); } if (maxConnectionsPerHost != null) { params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost); } params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, true); httpClient = HttpClientUtil.createClient(params); } // DEV NOTE: the defaults must match what HttpSolrClient.Builder does! Must keep up to date! HttpSolrClient client = new ScipioHttpSolrClient(baseURL, httpClient, new BinaryResponseParser(), false, new ModifiableSolrParams(), solrUsername, solrPassword); // TODO: In Solr 7, these are deprecated and moved to Builder/constructor if (connectTimeout != null) { client.setConnectionTimeout(connectTimeout); } if (socketTimeout != null) { client.setSoTimeout(socketTimeout); } return client; }
From source file:com.nkang.kxmoment.util.SolrUtils.HttpSolrServer.java
License:Apache License
public HttpSolrServer(String baseURL, HttpClient client, ResponseParser parser) { this.baseUrl = baseURL; if (baseUrl.endsWith("/")) { baseUrl = baseUrl.substring(0, baseUrl.length() - 1); }//from w ww . ja va 2 s .com if (baseUrl.indexOf('?') >= 0) { throw new RuntimeException( "Invalid base url for solrj. The base URL must not contain parameters: " + baseUrl); } if (client != null) { httpClient = client; internalClient = false; } else { internalClient = true; ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 128); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 32); params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, followRedirects); httpClient = HttpClientUtil.createClient(params); } this.parser = parser; }
From source file:com.thinkaurelius.titan.diskstorage.solr.Solr5Index.java
License:Apache License
public Solr5Index(final Configuration config) throws BackendException { Preconditions.checkArgument(config != null); configuration = config;/*from ww w .j a v a 2 s. c o m*/ mode = Mode.parse(config.get(SOLR_MODE)); dynFields = config.get(DYNAMIC_FIELDS); keyFieldIds = parseKeyFieldsForCollections(config); maxResults = config.get(GraphDatabaseConfiguration.INDEX_MAX_RESULT_SET_SIZE); ttlField = config.get(TTL_FIELD); waitSearcher = config.get(WAIT_SEARCHER); if (mode == Mode.CLOUD) { String zookeeperUrl = config.get(Solr5Index.ZOOKEEPER_URL); CloudSolrClient cloudServer = new CloudSolrClient(zookeeperUrl, true); cloudServer.connect(); solrClient = cloudServer; } else if (mode == Mode.HTTP) { HttpClient clientParams = HttpClientUtil.createClient(new ModifiableSolrParams() { { add(HttpClientUtil.PROP_ALLOW_COMPRESSION, config.get(HTTP_ALLOW_COMPRESSION).toString()); add(HttpClientUtil.PROP_CONNECTION_TIMEOUT, config.get(HTTP_CONNECTION_TIMEOUT).toString()); add(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, config.get(HTTP_MAX_CONNECTIONS_PER_HOST).toString()); add(HttpClientUtil.PROP_MAX_CONNECTIONS, config.get(HTTP_GLOBAL_MAX_CONNECTIONS).toString()); } }); solrClient = new LBHttpSolrClient(clientParams, config.get(HTTP_URLS)); } else { throw new IllegalArgumentException("Unsupported Solr operation mode: " + mode); } }
From source file:org.apache.nifi.processors.solr.SolrUtils.java
License:Apache License
public static SolrClient createSolrClient(final PropertyContext context, final String solrLocation) { final Integer socketTimeout = context.getProperty(SOLR_SOCKET_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS) .intValue();/*from w w w . ja v a 2s . co m*/ final Integer connectionTimeout = context.getProperty(SOLR_CONNECTION_TIMEOUT) .asTimePeriod(TimeUnit.MILLISECONDS).intValue(); final Integer maxConnections = context.getProperty(SOLR_MAX_CONNECTIONS).asInteger(); final Integer maxConnectionsPerHost = context.getProperty(SOLR_MAX_CONNECTIONS_PER_HOST).asInteger(); final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE) .asControllerService(SSLContextService.class); final String jaasClientAppName = context.getProperty(JAAS_CLIENT_APP_NAME).getValue(); final ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_SO_TIMEOUT, socketTimeout); params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost); // has to happen before the client is created below so that correct configurer would be set if neeeded if (!StringUtils.isEmpty(jaasClientAppName)) { System.setProperty("solr.kerberos.jaas.appname", jaasClientAppName); HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); } final HttpClient httpClient = HttpClientUtil.createClient(params); if (sslContextService != null) { final SSLContext sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED); final SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext); final Scheme httpsScheme = new Scheme("https", 443, sslSocketFactory); httpClient.getConnectionManager().getSchemeRegistry().register(httpsScheme); } if (SOLR_TYPE_STANDARD.equals(context.getProperty(SOLR_TYPE).getValue())) { return new HttpSolrClient(solrLocation, httpClient); } else { final String collection = context.getProperty(COLLECTION).evaluateAttributeExpressions().getValue(); final Integer zkClientTimeout = context.getProperty(ZK_CLIENT_TIMEOUT) .asTimePeriod(TimeUnit.MILLISECONDS).intValue(); final Integer zkConnectionTimeout = context.getProperty(ZK_CONNECTION_TIMEOUT) .asTimePeriod(TimeUnit.MILLISECONDS).intValue(); CloudSolrClient cloudSolrClient = new CloudSolrClient(solrLocation, httpClient); cloudSolrClient.setDefaultCollection(collection); cloudSolrClient.setZkClientTimeout(zkClientTimeout); cloudSolrClient.setZkConnectTimeout(zkConnectionTimeout); return cloudSolrClient; } }
From source file:org.janusgraph.diskstorage.solr.SolrIndex.java
License:Apache License
public SolrIndex(final Configuration config) throws BackendException { Preconditions.checkArgument(config != null); configuration = config;//from w w w.ja va2 s. com mode = Mode.parse(config.get(SOLR_MODE)); kerberosEnabled = config.get(KERBEROS_ENABLED); dynFields = config.get(DYNAMIC_FIELDS); keyFieldIds = parseKeyFieldsForCollections(config); batchSize = config.get(INDEX_MAX_RESULT_SET_SIZE); ttlField = config.get(TTL_FIELD); waitSearcher = config.get(WAIT_SEARCHER); if (kerberosEnabled) { logger.debug("Kerberos is enabled. Configuring SOLR for Kerberos."); configureSolrClientsForKerberos(); } else { logger.debug("Kerberos is NOT enabled."); logger.debug("KERBEROS_ENABLED name is " + KERBEROS_ENABLED.getName() + " and it is" + (KERBEROS_ENABLED.isOption() ? " " : " not") + " an option."); logger.debug("KERBEROS_ENABLED type is " + KERBEROS_ENABLED.getType().name()); } final ModifiableSolrParams clientParams = new ModifiableSolrParams(); switch (mode) { case CLOUD: final String[] zookeeperUrl = config.get(SolrIndex.ZOOKEEPER_URL); // Process possible zookeeper chroot. e.g. localhost:2181/solr // chroot has to be the same assuming one Zookeeper ensemble. // Parse from the last string. If found, take it as the chroot. String chroot = null; for (int i = zookeeperUrl.length - 1; i >= 0; i--) { int chrootIndex = zookeeperUrl[i].indexOf("/"); if (chrootIndex != -1) { String hostAndPort = zookeeperUrl[i].substring(0, chrootIndex); if (chroot == null) { chroot = zookeeperUrl[i].substring(chrootIndex); } zookeeperUrl[i] = hostAndPort; } } final CloudSolrClient.Builder builder = new CloudSolrClient.Builder() .withLBHttpSolrClientBuilder(new LBHttpSolrClient.Builder() .withHttpSolrClientBuilder( new HttpSolrClient.Builder().withInvariantParams(clientParams)) .withBaseSolrUrls(config.get(HTTP_URLS))) .withZkHost(Arrays.asList(zookeeperUrl)).sendUpdatesOnlyToShardLeaders(); if (chroot != null) { builder.withZkChroot(chroot); } final CloudSolrClient cloudServer = builder.build(); cloudServer.connect(); solrClient = cloudServer; break; case HTTP: clientParams.add(HttpClientUtil.PROP_ALLOW_COMPRESSION, config.get(HTTP_ALLOW_COMPRESSION).toString()); clientParams.add(HttpClientUtil.PROP_CONNECTION_TIMEOUT, config.get(HTTP_CONNECTION_TIMEOUT).toString()); clientParams.add(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, config.get(HTTP_MAX_CONNECTIONS_PER_HOST).toString()); clientParams.add(HttpClientUtil.PROP_MAX_CONNECTIONS, config.get(HTTP_GLOBAL_MAX_CONNECTIONS).toString()); final HttpClient client = HttpClientUtil.createClient(clientParams); solrClient = new LBHttpSolrClient.Builder().withHttpClient(client) .withBaseSolrUrls(config.get(HTTP_URLS)).build(); break; default: throw new IllegalArgumentException("Unsupported Solr operation mode: " + mode); } }
From source file:org.opencommercesearch.CloudSearchServer.java
License:Apache License
public synchronized void initSolrServer() throws MalformedURLException { ModifiableSolrParams params = new ModifiableSolrParams(); if (maxConnections > 0) { params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections); }//from w w w .j a v a 2 s . c om if (maxConnectionsPerHost > 0) { params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost); } if (connectTimeout > 0) { params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectTimeout); } if (socketTimeout > 0) { params.set(HttpClientUtil.PROP_SO_TIMEOUT, socketTimeout); } HttpClient httpClient = HttpClientUtil.createClient(params); LBHttpSolrServer newLbServer = new LBHttpSolrServer(httpClient); for (Locale locale : SUPPORTED_LOCALES) { CloudSolrServer catalogSolrServer = getSolrServer(getCatalogCollection(), locale); String languagePrefix = "_" + locale.getLanguage(); if (catalogSolrServer != null) { catalogSolrServer.shutdown(); } catalogSolrServer = new CloudSolrServer(getHost(), newLbServer); catalogSolrServer.setDefaultCollection(getCatalogCollection() + languagePrefix); catalogSolrServer.setZkConnectTimeout(getZkConnectTimeout()); catalogSolrServer.setZkClientTimeout(getZkClientTimeout()); setCatalogSolrServer(catalogSolrServer, locale); CloudSolrServer rulesSolrServer = getSolrServer(getRulesCollection(), locale); if (rulesSolrServer != null) { rulesSolrServer.shutdown(); } rulesSolrServer = new CloudSolrServer(getHost(), newLbServer); rulesSolrServer.setDefaultCollection(getRulesCollection() + languagePrefix); rulesSolrServer.setZkConnectTimeout(getZkConnectTimeout()); rulesSolrServer.setZkClientTimeout(getZkClientTimeout()); setRulesSolrServer(rulesSolrServer, locale); CloudSolrServer autocompleteSolrServer = getSolrServer(getAutocompleteCollection(), locale); if (autocompleteSolrServer != null) { autocompleteSolrServer.shutdown(); } autocompleteSolrServer = new CloudSolrServer(getHost(), newLbServer); //TODO gsegura: we may need to add the language prefix here autocompleteSolrServer.setDefaultCollection(getAutocompleteCollection()); autocompleteSolrServer.setZkConnectTimeout(getZkConnectTimeout()); autocompleteSolrServer.setZkClientTimeout(getZkClientTimeout()); setAutocompleteSolrServers(autocompleteSolrServer, locale); } if (lbServer != null) { lbServer.shutdown(); } lbServer = newLbServer; }
From source file:org.opencommercesearch.lucene.queries.function.valuesource.BoostValueSourceParser.java
License:Apache License
@Override public void init(NamedList args) { boostLimit = getParameter(args, BOOST_LIMIT, boostLimit); boostApiHost = getParameter(args, BOOST_API_HOST, boostApiHost); soTimeout = getParameter(args, HttpClientUtil.PROP_SO_TIMEOUT, soTimeout); connectionTimeout = getParameter(args, HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout); maxConnections = getParameter(args, HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnections); maxConnectionsPerHost = getParameter(args, HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost);/*from ww w .j a v a2 s . c o m*/ ModifiableSolrParams clientParams = new ModifiableSolrParams(); clientParams.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections); clientParams.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost); clientParams.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections); clientParams.set(HttpClientUtil.PROP_SO_TIMEOUT, soTimeout); clientParams.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout); clientParams.set(HttpClientUtil.PROP_USE_RETRY, false); defaultClient = HttpClientUtil.createClient(clientParams); }