Example usage for org.apache.solr.client.solrj.impl HttpClientUtil PROP_CONNECTION_TIMEOUT

List of usage examples for org.apache.solr.client.solrj.impl HttpClientUtil PROP_CONNECTION_TIMEOUT

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.impl HttpClientUtil PROP_CONNECTION_TIMEOUT.

Prototype

String PROP_CONNECTION_TIMEOUT

To view the source code for org.apache.solr.client.solrj.impl HttpClientUtil PROP_CONNECTION_TIMEOUT.

Click Source Link

Usage

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());
    }//from   w  w w  .ja va 2  s  . c om
    if (zkConnectTimeout != null) {
        cloudSolrClient.setZkConnectTimeout(zkConnectTimeout.intValue());
    }

    if (StringUtils.isNoneBlank(collection)) {
        cloudSolrClient.setDefaultCollection(collection);
    }
    cloudSolrClient.connect();
    this.setSolrClient(cloudSolrClient);
}

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;/*  ww  w.  ja v a  2  s . com*/

    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  2 s  .  c  om
    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;/* w ww. jav a2 s  .  c  o m*/
    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);
    }/*w  w  w. j ava 2 s. co m*/
    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);/*  ww w.  j  a  v  a  2 s . co 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);
}