public class SolrClientFactory {
private static Map<String, SolrClient> SERVERS = new ConcurrentHashMap<String, SolrClient>();
/**
* Get a solrClient by a specified core/collection name
* @param coreName
* @return a SolrClient
*/
public static SolrClient getSolrClient(String coreName)
{
if(StringUtils.isBlank(coreName))
{
log.error("Failed to get available core name:"+coreName);
throw new SolrServerException("No found out any solr server for a EMPTY core/collection name.");
}
SolrClient solrClient = null;
if(!SERVERS.containsKey(coreName))
{
solrClient = SolrClientSingleton.getSolrClientInstance(coreName);
SERVERS.put(coreName, solrClient);
}
else
{
solrClient = SERVERS.get(coreName);
}
if(solrClient == null)
{
log.error("No found any solr server for a specified core/collection name:"+coreName);
throw new SolrServerException("No found any solr server for a specified core/collection name:"+coreName);
}
return solrClient;
}
}
public class SolrClientSingleton
{
private static ISolrConfiguration config = new SolrConfiguration();
private SolrClientSingleton() {}
private static class SingletonHolder
{
private static final SolrClientSingleton INSTANCE = new SolrClientSingleton();
}
/**
* Get HttpSolrClient for a single node mode
* @returnSolrClient
*/
public static SolrClient getSolrClientInstance(String coreName)
{
return SingletonHolder.INSTANCE.createSolrClient(coreName);
}
private SolrClient createSolrClient(String coreName)
{
try
{
if(config.isCloudMode())
{
CloudSolrClient cloudSolrClient = new CloudSolrClient(config.getZkHosts());
cloudSolrClient.setDefaultCollection(coreName);
cloudSolrClient.connect();
cloudSolrClient.setZkConnectTimeout(config.getZkConnectionTimeout());
cloudSolrClient.setZkClientTimeout(config.getZkClientTimeout());
return cloudSolrClient;
}
else
{
HttpSolrClient httpSolrClient = new HttpSolrClient(getSolrURL(config.getUrl(),coreName));
httpSolrClient.setConnectionTimeout(config.getConnectionTimeout());
httpSolrClient.setDefaultMaxConnectionsPerHost(config.getMaxConnectionsPerHost());
httpSolrClient.setMaxTotalConnections(config.getMaxTotalConnections());
return httpSolrClient;
}
}
catch(Exception e)
{
log.error("Failed to connect to the solr server due to:"+e.toString());
throw new SolrServerException("Failed to connect to the solr server.");
}
}
/**
* Get a String of which is combined by Solr server url and core name
* @param url
* @param coreName
* @return a url string
*/
private String getSolrURL(String url,String coreName)
{
if(StringUtils.isBlank(url) )
{
log.error("Solr url cannot be EMPTY.");
return null;
}
StringBuilder sb = new StringBuilder(url);
if(!url.endsWith("/"))
{
sb.append("/");
}
if(!StringUtils.isBlank(coreName))
{
sb.append(coreName);
}
return sb.toString();
}
}
相关推荐
此外,它还能与多种数据库系统(如Oracle、SQL Server、MySQL等)以及邮件系统(如Outlook Express、Thunderbird)配合,确保各类应用的数据安全。 在处理大数据增长方面,AnyBackup采用了一系列先进技术,如第三代...
marked-down shutdown-sessions on-marked-up shutdown-backup-sessions server redis-02 127.0.0.1:6381 check port 6381 check inter 2s weight 1 inter 2s downinter 5s rise 10 fall 2 backup bind *:6379 mode ...
sqlcmd -S YourServerName -U YourUsername -P YourPassword -d YourDatabaseName -Q "EXEC dbo.YourBackupProcedure" ``` 3. **设置Windows计划任务**:在Windows操作系统中,通过“任务计划程序”设置一个计划,让...
介绍Snebu-简单的网络备份实用程序,名义上的系统,一切都已备份Snebu是一种高效,增量,快照式,重复数据删除,压缩,加密,数据库支持,多主机,...server central-backup-server -k myhost.key \ -k corporate-s
http://finelybook.com/microsoft-sql-server-2016-a-beginners-guide-6th-edition/ Book Description to Finelybook sorting Up-to-date Microsoft SQL Server 2016 skills made easy! Get up and running on ...
### 基于SQL Server-DMO的数据库备份与恢复技术详解 #### 一、引言 在数据库管理中,数据的安全性和完整性至关重要。对于使用SQL Server的企业来说,确保数据的备份与恢复策略健全是非常重要的一步。本文将详细介绍...
描述中的"this script it's just to create a backup or restore your database."暗示了该脚本会涵盖这两个关键功能。备份部分可能涉及获取数据库信息,选择备份类型,设置备份位置,然后调用`Backup-DbaDatabase` ...
sqlcmd -S 服务器名称 -d 数据库名称 -Q "BACKUP DATABASE 数据库名称 TO DISK = '文件路径'" ``` 四、导出结果 ---------------- 无论使用 SSMS 还是 sqlcmd,导出带数据的脚本都可以用于恢复和部署数据库结构和...
文档中提到的“ BackupExec20.1 Administrator's Guide”指的是管理员指南,这是操作手册的一个组成部分,涵盖了Backup Exec的管理员所需了解的详细信息。管理员指南中介绍了Backup Exec的基本信息、工作原理、安装...
-b ip:port, set backup memcached server ip and port -l ip, local bind ip address, default is 0.0.0.0 -n number, set max connections, default is 4096 -D don't go to background -k use ketama key ...
在SQL Server 2008中,为了确保数据的安全性和防止意外丢失,设置自动备份是一项至关重要的任务。这里我们将详细探讨如何使用SQL Server自带的`sqlcmd`工具以及如何创建一个自定义的备份脚本来实现这一功能。 首先...
sqlcmd -S <server_name> -U <username> -P <password> -Q "RESTORE DATABASE <database_name> FROM DISK='<backup_file>' WITH REPLACE" ``` 这里的 `<backup_file>` 是数据库备份文件的路径。 总结来说,SQL ...
server backend3.example.com backup; } server { listen 80; server_name your_domain.com; location / { proxy_pass http://backend_servers; } } ``` 这样,nginx会根据权重分配请求到不同的后端服务器,...
-b ip:port, set backup memcached server ip and port -l ip, local bind ip address, default is 0.0.0.0 -n number, set max connections, default is 4096 -D don't go to background -k use ketama key ...
- 执行备份命令,例如`sqlcmd -S <server_name> -U <username> -P <password> -Q "BACKUP DATABASE <database_name> TO DISK = '<backup_path>\<database_name>_bak.bak'"`。 - 或者,它可能调用PowerShell脚本`...
- 在“添加参数”中,输入SQL脚本的路径以及执行备份的命令,如:`-S .\YourInstanceName -U YourUsername -P YourPassword -Q "YOUR_BACKUP_SCRIPT"`。 3. **考虑备份策略** - 定期性:根据业务需求设定备份频率...
SharePoint Server 2007管理员手册(全书)英文版 Get your mission-critical collaboration and information-management systems up and running with this ... Apply best practices for backup and recovery