当前位置: 首页>>代码示例>>Java>>正文


Java CommonsHttpSolrServer.setSoTimeout方法代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.setSoTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java CommonsHttpSolrServer.setSoTimeout方法的具体用法?Java CommonsHttpSolrServer.setSoTimeout怎么用?Java CommonsHttpSolrServer.setSoTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.client.solrj.impl.CommonsHttpSolrServer的用法示例。


在下文中一共展示了CommonsHttpSolrServer.setSoTimeout方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入方法依赖的package包/类
public void init()
{
   	ParameterCheck.mandatory("solrHost", solrHost);
   	ParameterCheck.mandatory("solrPort", solrPort);
   	ParameterCheck.mandatory("solrUser", solrUser);
   	ParameterCheck.mandatory("solrPassword", solrPassword);
   	ParameterCheck.mandatory("solrPingCronExpression", solrPingCronExpression);
   	ParameterCheck.mandatory("solrConnectTimeout", solrConnectTimeout);

	try
	{
    	StringBuilder sb = new StringBuilder();
    	sb.append(httpClientFactory.isSSL() ? "https://" : "http://");
    	sb.append(solrHost);
    	sb.append(":");
    	sb.append(httpClientFactory.isSSL() ? solrSSLPort: solrPort);
    	sb.append(baseUrl);
		this.solrUrl = sb.toString();
		HttpClient httpClient = httpClientFactory.getHttpClient();

		server = new CommonsHttpSolrServer(solrUrl, httpClient);
		server.setParser(new XMLResponseParser());
		// TODO remove credentials because we're using SSL?
		Credentials defaultcreds = new UsernamePasswordCredentials(solrUser, solrPassword); 
		server.getHttpClient().getState().setCredentials(new AuthScope(solrHost, solrPort, AuthScope.ANY_REALM), 
				defaultcreds);
		server.setConnectionTimeout(solrConnectTimeout);
		server.setSoTimeout(20000);

		this.solrTracker = new SolrTracker(scheduler);
	}
	catch(MalformedURLException e)
	{
		throw new AlfrescoRuntimeException("Cannot initialise Solr admin http client", e);
	}
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:37,代码来源:SOLRAdminClient.java

示例2: getSolrServer

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入方法依赖的package包/类
/**
 * Gets the instance of the Apache Solr server used for indexing.
 *
 * @return Instance of the Apache Solr server
 * @throws IllegalStateException If the search engine is not properly
 * configured
 */
private SolrServer getSolrServer() {
    try {
        String url = cfgService.getString(ConfigurationKey.SEARCH_ENGINE_URL);
        Integer socketTimeout = cfgService.getInteger(ConfigurationKey.SEARCH_ENGINE_SOCKET_TIMEOUT);
        Integer connectionTimeout = cfgService.getInteger(ConfigurationKey.SEARCH_ENGINE_CONNECTION_TIMEOUT);
        Integer maxTotalConnectionsPerHost = cfgService.getInteger(ConfigurationKey.SEARCH_ENGINE_MAX_TOTAL_CONNECTIONS_PER_HOST);
        Integer maxTotalConnections = cfgService.getInteger(ConfigurationKey.SEARCH_ENGINE_MAX_TOTAL_CONNECTIONS);
        Integer maxRetries = cfgService.getInteger(ConfigurationKey.SEARCH_ENGINE_MAX_RETRIES);
        Boolean followRedirects = cfgService.getBoolean(ConfigurationKey.SEARCH_ENGINE_FOLLOW_REDIRECTS);
        Boolean allowCompression = cfgService.getBoolean(ConfigurationKey.SEARCH_ENGINE_ALLOW_COMPRESSION);

        CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(url);
        solrServer.setRequestWriter(new BinaryRequestWriter());
        solrServer.setSoTimeout(socketTimeout);
        solrServer.setConnectionTimeout(connectionTimeout);
        solrServer.setDefaultMaxConnectionsPerHost(maxTotalConnectionsPerHost);
        solrServer.setMaxTotalConnections(maxTotalConnections);
        solrServer.setFollowRedirects(followRedirects);
        solrServer.setAllowCompression(allowCompression);
        solrServer.setMaxRetries(maxRetries);

        return solrServer;
    } catch (MalformedURLException ex) {
        LOG.log(Level.SEVERE, "Invalid search engine configuration. {0}", ex.getMessage());
        LOG.log(Level.FINEST, "", ex);
        throw new IllegalStateException("Invalid search engine configuration", ex);
    }
}
 
开发者ID:getconverge,项目名称:converge-1.x,代码行数:36,代码来源:SearchEngineBean.java

示例3: check

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入方法依赖的package包/类
@Override
public void check(CommandLine commandLine) throws Exception {
	
	// get url
	String url = commandLine.getOptionValue(SolrParameter.URL.toString());
	
	// get query
	String query = commandLine.getOptionValue(SolrParameter.QUERY.toString());

	// get connect timeout
	int connectTimeout = (Integer) SolrParameter.CONNECT_TIMEOUT.getDefaultValue();
	String connectTimeoutString = commandLine.getOptionValue(SolrParameter.CONNECT_TIMEOUT.toString());
	if (StringUtils.isNotEmpty(connectTimeoutString)) {
		connectTimeout = Integer.parseInt(connectTimeoutString);
	}
	
	// get response timeout
	int responseTimeout = (Integer) SolrParameter.RESPONSE_TIMEOUT.getDefaultValue();
	String responseTimeoutString = commandLine.getOptionValue(SolrParameter.RESPONSE_TIMEOUT.toString());
	if (StringUtils.isNotEmpty(responseTimeoutString)) {
		responseTimeout = Integer.parseInt(connectTimeoutString);
	}
	
	// get pattern
	Pattern pattern = (Pattern) SolrParameter.PATTERN.getDefaultValue();
	String patternString = commandLine.getOptionValue(SolrParameter.PATTERN.toString());
	if (StringUtils.isNotEmpty(patternString)) {
		pattern = Pattern.compile(patternString);
	}
	
	// create solr server client
	CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(url);
	solrServer.setConnectionTimeout(connectTimeout);
	solrServer.setSoTimeout(responseTimeout);
	
	// create solr query
	SolrQuery solrQuery = new SolrQuery(query);
	
	// execute solr query
	QueryResponse queryResponse = solrServer.query(solrQuery);
	
	// get query result
	StringBuffer resultBuffer = new StringBuffer(); 
	for (SolrDocument document : queryResponse.getResults()) {
		resultBuffer.append(ClientUtils.toXML(ClientUtils.toSolrInputDocument(document)));
		resultBuffer.append("\n");
	}
	
	// get result as string
	String result = resultBuffer.toString();
	if (StringUtils.isNotEmpty(result)) {

		System.out.println(result);
		
		// check if query result matches the given pattern
		Matcher matcher = pattern.matcher(result);
		if (!matcher.find()) {
			throw new Exception("The pattern does not match the solr result text");
		}
	}
}
 
开发者ID:chrisipa,项目名称:health-checker,代码行数:62,代码来源:SolrHealthChecker.java

示例4: getSolrServer

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入方法依赖的package包/类
/**
 * Gets the instance of the Apache Solr server used for indexing.
 *
 * @return Instance of the Apache Solr server
 * @throws IllegalStateException If the search engine is not properly
 * configured
 */
private SolrServer getSolrServer() {
    try {
        String url = cfgService.getString(
                ConfigurationKey.SEARCH_ENGINE_NEWSWIRE_URL);
        Integer socketTimeout = cfgService.getInteger(
                ConfigurationKey.SEARCH_ENGINE_SOCKET_TIMEOUT);
        Integer connectionTimeout = cfgService.getInteger(
                ConfigurationKey.SEARCH_ENGINE_CONNECTION_TIMEOUT);
        Integer maxTotalConnectionsPerHost =
                cfgService.getInteger(
                ConfigurationKey.SEARCH_ENGINE_MAX_TOTAL_CONNECTIONS_PER_HOST);
        Integer maxTotalConnections =
                cfgService.getInteger(
                ConfigurationKey.SEARCH_ENGINE_MAX_TOTAL_CONNECTIONS);
        Integer maxRetries = cfgService.getInteger(
                ConfigurationKey.SEARCH_ENGINE_MAX_RETRIES);
        Boolean followRedirects = cfgService.getBoolean(
                ConfigurationKey.SEARCH_ENGINE_FOLLOW_REDIRECTS);
        Boolean allowCompression = cfgService.getBoolean(
                ConfigurationKey.SEARCH_ENGINE_ALLOW_COMPRESSION);

        CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(url);
        solrServer.setRequestWriter(new BinaryRequestWriter());
        solrServer.setSoTimeout(socketTimeout);
        solrServer.setConnectionTimeout(connectionTimeout);
        solrServer.setDefaultMaxConnectionsPerHost(
                maxTotalConnectionsPerHost);
        solrServer.setMaxTotalConnections(maxTotalConnections);
        solrServer.setFollowRedirects(followRedirects);
        solrServer.setAllowCompression(allowCompression);
        solrServer.setMaxRetries(maxRetries);

        return solrServer;
    } catch (MalformedURLException ex) {
        LOG.log(Level.SEVERE, "Invalid search engine configuration. {0}",
                ex.getMessage());
        LOG.log(Level.FINE, "", ex);
        throw new java.lang.IllegalStateException(
                "Invalid search engine configuration", ex);
    }
}
 
开发者ID:getconverge,项目名称:converge-1.x,代码行数:49,代码来源:NewswireServiceBean.java


注:本文中的org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.setSoTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。