List of usage examples for org.apache.solr.common.params CommonParams STREAM_CONTENTTYPE
String STREAM_CONTENTTYPE
To view the source code for org.apache.solr.common.params CommonParams STREAM_CONTENTTYPE.
Click Source Link
From source file:org.codeexample.jeffery.solr.ThreadedUpdateRequestHandler.java
License:Apache License
@Override public void handleRequestBody(final SolrQueryRequest req, final SolrQueryResponse rsp) throws Exception { List<ContentStream> streams = new ArrayList<ContentStream>(); handleReqStream(req, streams);//from w w w . j av a 2s . co m // here, we handle the new two parameters: stream.folder and // strem.filepattern handleStreamFolders(req, streams); handleFilePatterns(req, streams); if (streams.size() < 2) { // No need to use threadpool. SolrQueryRequestBase reqBase = (SolrQueryRequestBase) req; if (!streams.isEmpty()) { String contentType = req.getParams().get(CommonParams.STREAM_CONTENTTYPE); ContentStream stream = streams.get(0); if (stream instanceof ContentStreamBase) { ((ContentStreamBase) stream).setContentType(contentType); } } reqBase.setContentStreams(streams); super.handleRequestBody(req, rsp); } else { importStreamsMultiThreaded(req, rsp, streams); } }
From source file:org.codeexample.jeffery.solr.ThreadedUpdateRequestHandler.java
License:Apache License
private ExecutorService importStreamsMultiThreaded(final SolrQueryRequest req, final SolrQueryResponse rsp, List<ContentStream> streams) throws InterruptedException, IOException { ExecutorService executor = null; SolrParams params = req.getParams(); final UpdateRequestProcessorChain processorChain = req.getCore() .getUpdateProcessingChain(params.get(UpdateParams.UPDATE_CHAIN)); UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp); try {/*from ww w . j a v a2 s . c o m*/ Map<String, Object> resultMap = new LinkedHashMap<String, Object>(); resultMap.put("start_time", new Date()); List<Map<String, Object>> details = new ArrayList<Map<String, Object>>(); try { int threads = determineThreadsNumber(params, streams.size()); ThreadFactory threadFactory = new ThreadFactory() { public Thread newThread(Runnable r) { return new Thread(r, "threadedReqeustHandler-" + new Date()); } }; executor = Executors.newFixedThreadPool(threads, threadFactory); String contentType = params.get(CommonParams.STREAM_CONTENTTYPE); Iterator<ContentStream> iterator = streams.iterator(); while (iterator.hasNext()) { ContentStream stream = iterator.next(); iterator.remove(); if (stream instanceof ContentStreamBase) { ((ContentStreamBase) stream).setContentType(contentType); } submitTask(req, rsp, processorChain, executor, stream, details); } executor.shutdown(); boolean terminated = executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS); if (!terminated) { throw new RuntimeException("Request takes too much time"); } // Perhaps commit from the parameters RequestHandlerUtils.handleCommit(req, processor, params, false); RequestHandlerUtils.handleRollback(req, processor, params, false); } finally { resultMap.put("end_time", new Date()); // check whether there is error in details for (Map<String, Object> map : details) { Exception ex = (Exception) map.get("exception"); if (ex != null) { rsp.setException(ex); if (ex instanceof SolrException) { rsp.add("status", ((SolrException) ex).code()); } else { rsp.add("status", SolrException.ErrorCode.BAD_REQUEST); } break; } } } resultMap.put("details", details); rsp.add("result", resultMap); return executor; } finally { if (executor != null && !executor.isShutdown()) { executor.shutdownNow(); } // finish the request processor.finish(); } }