use of org.apache.solr.common.util.SolrjNamedThreadFactory in project lucene-solr by apache.
the class FeaturesSelectionStream 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("FeaturesSelectionStream"));
}
use of org.apache.solr.common.util.SolrjNamedThreadFactory in project lucene-solr by apache.
the class ShortestPathStream method open.
public void open() throws IOException {
List<Map<String, List<String>>> allVisited = new ArrayList();
Map visited = new HashMap();
visited.put(this.fromNode, null);
allVisited.add(visited);
int depth = 0;
Map<String, List<String>> nextVisited = null;
List<Edge> targets = new ArrayList();
ExecutorService threadPool = null;
try {
threadPool = ExecutorUtil.newMDCAwareFixedThreadPool(threads, new SolrjNamedThreadFactory("ShortestPathStream"));
//Breadth first search
TRAVERSE: while (targets.size() == 0 && depth < maxDepth) {
Set<String> nodes = visited.keySet();
Iterator<String> it = nodes.iterator();
nextVisited = new HashMap();
int batchCount = 0;
List<String> queryNodes = new ArrayList();
List<Future> futures = new ArrayList();
JOIN: //Queue up all the batches
while (it.hasNext()) {
String node = it.next();
queryNodes.add(node);
++batchCount;
if (batchCount == joinBatchSize || !it.hasNext()) {
try {
JoinRunner joinRunner = new JoinRunner(queryNodes);
Future<List<Edge>> future = threadPool.submit(joinRunner);
futures.add(future);
} catch (Exception e) {
throw new RuntimeException(e);
}
batchCount = 0;
queryNodes = new ArrayList();
}
}
try {
//Process the batches as they become available
OUTER: for (Future<List<Edge>> future : futures) {
List<Edge> edges = future.get();
INNER: for (Edge edge : edges) {
if (toNode.equals(edge.to)) {
targets.add(edge);
if (nextVisited.containsKey(edge.to)) {
List<String> parents = nextVisited.get(edge.to);
parents.add(edge.from);
} else {
List<String> parents = new ArrayList();
parents.add(edge.from);
nextVisited.put(edge.to, parents);
}
} else {
if (!cycle(edge.to, allVisited)) {
if (nextVisited.containsKey(edge.to)) {
List<String> parents = nextVisited.get(edge.to);
parents.add(edge.from);
} else {
List<String> parents = new ArrayList();
parents.add(edge.from);
nextVisited.put(edge.to, parents);
}
}
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
allVisited.add(nextVisited);
visited = nextVisited;
++depth;
}
} finally {
threadPool.shutdown();
}
Set<String> finalPaths = new HashSet();
if (targets.size() > 0) {
for (Edge edge : targets) {
List<LinkedList> paths = new ArrayList();
LinkedList<String> path = new LinkedList();
path.addFirst(edge.to);
paths.add(path);
//Walk back up the tree a collect the parent nodes.
INNER: for (int i = allVisited.size() - 1; i >= 0; --i) {
Map<String, List<String>> v = allVisited.get(i);
Iterator<LinkedList> it = paths.iterator();
List newPaths = new ArrayList();
while (it.hasNext()) {
LinkedList p = it.next();
List<String> parents = v.get(p.peekFirst());
if (parents != null) {
for (String parent : parents) {
LinkedList newPath = new LinkedList();
newPath.addAll(p);
newPath.addFirst(parent);
newPaths.add(newPath);
}
paths = newPaths;
}
}
}
for (LinkedList p : paths) {
String s = p.toString();
if (!finalPaths.contains(s)) {
Tuple shortestPath = new Tuple(new HashMap());
shortestPath.put("path", p);
shortestPaths.add(shortestPath);
finalPaths.add(s);
}
}
}
}
}
use of org.apache.solr.common.util.SolrjNamedThreadFactory in project lucene-solr by apache.
the class TopicStream method openStreams.
private void openStreams() throws IOException {
ExecutorService service = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrjNamedThreadFactory("TopicStream"));
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();
}
}
use of org.apache.solr.common.util.SolrjNamedThreadFactory in project lucene-solr by apache.
the class HttpSolrClient method httpUriRequest.
/**
* @lucene.experimental
*/
public HttpUriRequestResponse httpUriRequest(final SolrRequest request, final ResponseParser processor) throws SolrServerException, IOException {
HttpUriRequestResponse mrr = new HttpUriRequestResponse();
final HttpRequestBase method = createMethod(request, null);
ExecutorService pool = ExecutorUtil.newMDCAwareFixedThreadPool(1, new SolrjNamedThreadFactory("httpUriRequest"));
try {
MDC.put("HttpSolrClient.url", baseUrl);
mrr.future = pool.submit(() -> executeMethod(method, processor));
} finally {
pool.shutdown();
MDC.remove("HttpSolrClient.url");
}
assert method != null;
mrr.httpUriRequest = method;
return mrr;
}
use of org.apache.solr.common.util.SolrjNamedThreadFactory in project lucene-solr by apache.
the class ConcurrentUpdateSolrClientTest method testConcurrentCollectionUpdate.
@Test
public void testConcurrentCollectionUpdate() throws Exception {
int cussThreadCount = 2;
int cussQueueSize = 100;
int numDocs = 100;
int numRunnables = 5;
int expected = numDocs * numRunnables;
try (ConcurrentUpdateSolrClient concurrentClient = (new ConcurrentUpdateSolrClient.Builder(jetty.getBaseUrl().toString())).withQueueSize(cussQueueSize).withThreadCount(cussThreadCount).build()) {
concurrentClient.setPollQueueTime(0);
// ensure it doesn't block where there's nothing to do yet
concurrentClient.blockUntilFinished();
// Delete all existing documents.
concurrentClient.deleteByQuery("collection1", "*:*");
int poolSize = 5;
ExecutorService threadPool = ExecutorUtil.newMDCAwareFixedThreadPool(poolSize, new SolrjNamedThreadFactory("testCUSS"));
for (int r = 0; r < numRunnables; r++) threadPool.execute(new SendDocsRunnable(String.valueOf(r), numDocs, concurrentClient, "collection1"));
// ensure all docs are sent
threadPool.awaitTermination(5, TimeUnit.SECONDS);
threadPool.shutdown();
concurrentClient.commit("collection1");
assertEquals(expected, concurrentClient.query("collection1", new SolrQuery("*:*")).getResults().getNumFound());
// wait until all requests are processed by CUSS
concurrentClient.blockUntilFinished();
concurrentClient.shutdownNow();
}
try (ConcurrentUpdateSolrClient concurrentClient = (new ConcurrentUpdateSolrClient.Builder(jetty.getBaseUrl().toString() + "/collection1")).withQueueSize(cussQueueSize).withThreadCount(cussThreadCount).build()) {
assertEquals(expected, concurrentClient.query(new SolrQuery("*:*")).getResults().getNumFound());
}
}
Aggregations