Example usage for org.apache.solr.client.solrj.impl LBHttpSolrClient setConnectionTimeout

List of usage examples for org.apache.solr.client.solrj.impl LBHttpSolrClient setConnectionTimeout

Introduction

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

Prototype

@Deprecated
public void setConnectionTimeout(int timeout) 

Source Link

Usage

From source file:com.frank.search.solr.server.support.HttpSolrClientFactoryBean.java

License:Apache License

private void createLoadBalancedHttpSolrClient() {
    try {//ww  w  .  java2  s .  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:org.apache.ranger.audit.destination.SolrAuditDestination.java

License:Apache License

synchronized void connect() {
    SolrClient me = solrClient;//from  w w  w. j av  a  2 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  w  ww .  j av a2s .  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. j a va 2 s. c  o  m

    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.springframework.data.solr.server.support.SolrClientFactoryBean.java

License:Apache License

/**
 * Creates a {@link LBHttpSolrClient}./* www.  j  a va2 s .  c o m*/
 */
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);
    }
}