Search in sources :

Example 6 with SolrjNamedThreadFactory

use of org.apache.solr.common.util.SolrjNamedThreadFactory in project lucene-solr by apache.

the class TextLogitStream method open.

/**
   * Opens the CloudSolrStream
   *
   ***/
public void open() throws IOException {
    if (cache == null) {
        isCloseCache = true;
        cache = new SolrClientCache();
    } else {
        isCloseCache = false;
    }
    this.cloudSolrClient = this.cache.getCloudSolrClient(zkHost);
    this.executorService = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrjNamedThreadFactory("TextLogitSolrStream"));
}
Also used : SolrjNamedThreadFactory(org.apache.solr.common.util.SolrjNamedThreadFactory) SolrClientCache(org.apache.solr.client.solrj.io.SolrClientCache)

Example 7 with SolrjNamedThreadFactory

use of org.apache.solr.common.util.SolrjNamedThreadFactory in project lucene-solr by apache.

the class IterativeMergeStrategy method merge.

public void merge(ResponseBuilder rb, ShardRequest sreq) {
    // Null pointers will occur otherwise.
    rb._responseDocs = new SolrDocumentList();
    // Turn off the second pass distributed.
    rb.onePassDistributedQuery = true;
    executorService = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrjNamedThreadFactory("IterativeMergeStrategy"));
    try {
        process(rb, sreq);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        executorService.shutdownNow();
    }
}
Also used : SolrjNamedThreadFactory(org.apache.solr.common.util.SolrjNamedThreadFactory) SolrDocumentList(org.apache.solr.common.SolrDocumentList)

Example 8 with SolrjNamedThreadFactory

use of org.apache.solr.common.util.SolrjNamedThreadFactory in project lucene-solr by apache.

the class GatherNodesStream method read.

public Tuple read() throws IOException {
    if (out == null) {
        List<String> joinBatch = new ArrayList();
        List<Future<List<Tuple>>> futures = new ArrayList();
        Map<String, Node> level = new HashMap();
        ExecutorService threadPool = null;
        try {
            threadPool = ExecutorUtil.newMDCAwareFixedThreadPool(4, new SolrjNamedThreadFactory("GatherNodesStream"));
            Map<String, Node> roots = new HashMap();
            while (true) {
                Tuple tuple = tupleStream.read();
                if (tuple.EOF) {
                    if (joinBatch.size() > 0) {
                        JoinRunner joinRunner = new JoinRunner(joinBatch);
                        Future future = threadPool.submit(joinRunner);
                        futures.add(future);
                    }
                    break;
                }
                String value = tuple.getString(traverseFrom);
                if (traversal.getDepth() == 0) {
                    //This gathers the root nodes
                    //We check to see if there are dupes in the root nodes because root streams may not have been uniqued.
                    String key = collection + "." + value;
                    if (!roots.containsKey(key)) {
                        Node node = new Node(value, trackTraversal);
                        if (metrics != null) {
                            List<Metric> _metrics = new ArrayList();
                            for (Metric metric : metrics) {
                                _metrics.add(metric.newInstance());
                            }
                            node.setMetrics(_metrics);
                        }
                        roots.put(key, node);
                    } else {
                        continue;
                    }
                }
                joinBatch.add(value);
                if (joinBatch.size() == 400) {
                    JoinRunner joinRunner = new JoinRunner(joinBatch);
                    Future future = threadPool.submit(joinRunner);
                    futures.add(future);
                    joinBatch = new ArrayList();
                }
            }
            if (traversal.getDepth() == 0) {
                traversal.addLevel(roots, collection, traverseFrom);
            }
            this.traversal.setScatter(scatter);
            if (useDefaultTraversal) {
                this.trackTraversal = traversal.getTrackTraversal();
            } else {
                this.traversal.setTrackTraversal(trackTraversal);
            }
            for (Future<List<Tuple>> future : futures) {
                List<Tuple> tuples = future.get();
                for (Tuple tuple : tuples) {
                    String _traverseTo = tuple.getString(traverseTo);
                    String _gather = tuple.getString(gather);
                    String key = collection + "." + _gather;
                    if (!traversal.visited(key, _traverseTo, tuple)) {
                        Node node = level.get(key);
                        if (node != null) {
                            node.add((traversal.getDepth() - 1) + "^" + _traverseTo, tuple);
                        } else {
                            node = new Node(_gather, trackTraversal);
                            if (metrics != null) {
                                List<Metric> _metrics = new ArrayList();
                                for (Metric metric : metrics) {
                                    _metrics.add(metric.newInstance());
                                }
                                node.setMetrics(_metrics);
                            }
                            node.add((traversal.getDepth() - 1) + "^" + _traverseTo, tuple);
                            level.put(key, node);
                        }
                    }
                }
            }
            traversal.addLevel(level, collection, gather);
            out = traversal.iterator();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            threadPool.shutdown();
        }
    }
    if (out.hasNext()) {
        return out.next();
    } else {
        Map map = new HashMap();
        map.put("EOF", true);
        Tuple tuple = new Tuple(map);
        return tuple;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ExecutorService(java.util.concurrent.ExecutorService) SolrjNamedThreadFactory(org.apache.solr.common.util.SolrjNamedThreadFactory) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 9 with SolrjNamedThreadFactory

use of org.apache.solr.common.util.SolrjNamedThreadFactory in project lucene-solr by apache.

the class SignificantTermsStream method open.

public void open() throws IOException {
    if (cache == null) {
        isCloseCache = true;
        cache = new SolrClientCache();
    } else {
        isCloseCache = false;
    }
    this.executorService = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrjNamedThreadFactory("SignificantTermsStream"));
}
Also used : SolrjNamedThreadFactory(org.apache.solr.common.util.SolrjNamedThreadFactory) SolrClientCache(org.apache.solr.client.solrj.io.SolrClientCache)

Example 10 with SolrjNamedThreadFactory

use of org.apache.solr.common.util.SolrjNamedThreadFactory in project lucene-solr by apache.

the class CloudSolrStream method openStreams.

private void openStreams() throws IOException {
    ExecutorService service = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrjNamedThreadFactory("CloudSolrStream"));
    try {
        List<Future<TupleWrapper>> futures = new ArrayList();
        for (TupleStream solrStream : solrStreams) {
            StreamOpener so = new StreamOpener((SolrStream) solrStream, comp);
            Future<TupleWrapper> future = service.submit(so);
            futures.add(future);
        }
        try {
            for (Future<TupleWrapper> f : futures) {
                TupleWrapper w = f.get();
                if (w != null) {
                    tuples.add(w);
                }
            }
        } catch (Exception e) {
            throw new IOException(e);
        }
    } finally {
        service.shutdown();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) SolrjNamedThreadFactory(org.apache.solr.common.util.SolrjNamedThreadFactory) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

SolrjNamedThreadFactory (org.apache.solr.common.util.SolrjNamedThreadFactory)12 ExecutorService (java.util.concurrent.ExecutorService)8 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Future (java.util.concurrent.Future)3 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 Tuple (org.apache.solr.client.solrj.io.Tuple)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)1