本文整理汇总了Java中org.apache.solr.client.solrj.impl.CloudSolrClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java CloudSolrClient.close方法的具体用法?Java CloudSolrClient.close怎么用?Java CloudSolrClient.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.impl.CloudSolrClient
的用法示例。
在下文中一共展示了CloudSolrClient.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupSolrDocuments
import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
private static void setupSolrDocuments() throws SolrServerException, IOException {
Builder builder = new CloudSolrClient.Builder();
builder.withZkHost(
Arrays.asList(new String[] { "192.168.204.181:2181,192.168.204.182:2181,192.168.204.183:2181" }));
CloudSolrClient client = builder.build();
client.setDefaultCollection("sql");
client.deleteByQuery("*:*");
insertDocument(client, 1, "bluejoe", 38);
insertDocument(client, 2, "even", 35);
insertDocument(client, 3, "alex", 8);
client.commit();
client.close();
}
示例2: getSplits
import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
@Override
public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {
this.conf = job;
boolean isZk = false;
String connectionUri = job.get(SOLR_ZKHOST);
String collection = job.get(SOLR_COLLECTION);
List<String> shards = null;
if (collection == null) {
throw new IOException(SOLR_COLLECTION + " not provided or is empty");
}
if (connectionUri != null && connectionUri != "") {
isZk = true;
CloudSolrClient solrCloud = null;
try {
solrCloud = new CloudSolrClient.Builder()
.withZkHost(connectionUri)
.build();
solrCloud.setDefaultCollection(collection);
solrCloud.connect();
// first get a list of replicas to query for this collection
shards = buildShardList(solrCloud, collection);
} catch (Exception ex) {
log.warn("Error getting the Shard: " + ex.getMessage());
} finally {
if (solrCloud != null) {
solrCloud.close();
}
}
} else {
connectionUri = job.get(SOLR_SERVER_URL);
}
if (connectionUri == null || connectionUri == "") {
throw new IOException(SOLR_ZKHOST + " nor " + SOLR_SERVER_URL + " provided or is empty");
}
InputSplit[] splits = null;
if (shards != null) {
//Create more splits.
splits = new InputSplit[shards.size()];
for (int i = 0; i < shards.size(); i++) {
splits[i] = new LWInputSplit(isZk, true, shards.get(i));
}
} else {
splits = new InputSplit[] { new LWInputSplit(isZk, false, connectionUri) };
}
return splits;
}
示例3: getShardList
import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
/**
* Returns the list of shards of the default collection.
*
* @param zkHost ZooKeeper URL
* @param chronixCollection Solr collection name for chronix time series data
* @return the list of shards of the default collection
*/
public List<String> getShardList(String zkHost, String chronixCollection) throws IOException {
CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost);
List<String> shards = new ArrayList<>();
try {
cloudSolrClient.connect();
ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
ClusterState clusterState = zkStateReader.getClusterState();
String[] collections;
if (clusterState.hasCollection(chronixCollection)) {
collections = new String[]{chronixCollection};
} else {
// might be a collection alias?
Aliases aliases = zkStateReader.getAliases();
String aliasedCollections = aliases.getCollectionAlias(chronixCollection);
if (aliasedCollections == null)
throw new IllegalArgumentException("Collection " + chronixCollection + " not found!");
collections = aliasedCollections.split(",");
}
Set<String> liveNodes = clusterState.getLiveNodes();
Random random = new Random(5150);
for (String coll : collections) {
for (Slice slice : clusterState.getSlices(coll)) {
List<String> replicas = new ArrayList<>();
for (Replica r : slice.getReplicas()) {
if (r.getState().equals(Replica.State.ACTIVE)) {
ZkCoreNodeProps replicaCoreProps = new ZkCoreNodeProps(r);
if (liveNodes.contains(replicaCoreProps.getNodeName()))
replicas.add(replicaCoreProps.getCoreUrl());
}
}
int numReplicas = replicas.size();
if (numReplicas == 0)
throw new IllegalStateException("Shard " + slice.getName() + " in collection " +
coll + " does not have any active replicas!");
String replicaUrl = (numReplicas == 1) ? replicas.get(0) : replicas.get(random.nextInt(replicas.size()));
shards.add(replicaUrl);
}
}
} finally {
cloudSolrClient.close();
}
return shards;
}