Search in sources :

Example 6 with GetNodesParameters

use of org.alfresco.solr.client.GetNodesParameters in project SearchServices by Alfresco.

the class MetadataTracker method indexBatchOfTransactions.

private int indexBatchOfTransactions(List<Transaction> txBatch) throws AuthenticationException, IOException, JSONException {
    int nodeCount = 0;
    ArrayList<Transaction> nonEmptyTxs = new ArrayList<>(txBatch.size());
    GetNodesParameters gnp = new GetNodesParameters();
    ArrayList<Long> txIds = new ArrayList<Long>();
    for (Transaction tx : txBatch) {
        if (tx.getUpdates() > 0 || tx.getDeletes() > 0) {
            nonEmptyTxs.add(tx);
            txIds.add(tx.getId());
        }
    }
    gnp.setTransactionIds(txIds);
    gnp.setStoreProtocol(storeRef.getProtocol());
    gnp.setStoreIdentifier(storeRef.getIdentifier());
    gnp.setShardProperty(shardProperty);
    List<Node> nodes = client.getNodes(gnp, Integer.MAX_VALUE);
    ArrayList<Node> nodeBatch = new ArrayList<>();
    for (Node node : nodes) {
        if (log.isDebugEnabled()) {
            log.debug(node.toString());
        }
        nodeBatch.add(node);
        if (nodeBatch.size() > nodeBatchSize) {
            nodeCount += nodeBatch.size();
            NodeIndexWorkerRunnable niwr = new NodeIndexWorkerRunnable(this.threadHandler, nodeBatch, this.infoSrv);
            this.threadHandler.scheduleTask(niwr);
            nodeBatch = new ArrayList<>();
        }
    }
    if (nodeBatch.size() > 0) {
        nodeCount += nodeBatch.size();
        NodeIndexWorkerRunnable niwr = new NodeIndexWorkerRunnable(this.threadHandler, nodeBatch, this.infoSrv);
        this.threadHandler.scheduleTask(niwr);
        nodeBatch = new ArrayList<>();
    }
    return nodeCount;
}
Also used : Transaction(org.alfresco.solr.client.Transaction) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) Node(org.alfresco.solr.client.Node) ArrayList(java.util.ArrayList)

Aggregations

GetNodesParameters (org.alfresco.solr.client.GetNodesParameters)6 ArrayList (java.util.ArrayList)5 Node (org.alfresco.solr.client.Node)4 IOException (java.io.IOException)3 AuthenticationException (org.alfresco.httpclient.AuthenticationException)3 Transaction (org.alfresco.solr.client.Transaction)3 JSONException (org.json.JSONException)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 Transactions (org.alfresco.solr.client.Transactions)2 NodeReport (org.alfresco.solr.NodeReport)1