List of usage examples for com.google.common.util.concurrent ListeningExecutorService isTerminated
boolean isTerminated();
From source file:org.eclipse.osee.executor.admin.internal.ExecutorCache.java
public ListeningExecutorService getById(String id) { if (id == null || id.length() <= 0) { throw new OseeArgumentException("Error - executorId cannot be null"); }/*from w w w . j a v a 2 s. c om*/ ListeningExecutorService executor = executors.get(id); if (executor != null && (executor.isShutdown() || executor.isTerminated())) { executors.remove(id); executor = null; } return executor; }
From source file:org.eclipse.osee.executor.admin.internal.ExecutorAdminImpl.java
public ListeningExecutorService getExecutor(String id) { ListeningExecutorService service = null; synchronized (cache) { service = cache.getById(id);//from w ww . j a va2 s . c o m if (service == null) { service = createExecutor(id, -1); } } if (service == null) { throw new OseeStateException("Error creating executor [%s].", id); } if (service.isShutdown() || service.isTerminated()) { throw new OseeStateException("Error executor [%s] was previously shutdown.", id); } return service; }
From source file:org.n52.lod.triplestore.AbstractWorkerTripleSink.java
@Override protected int addRecordsToModel(Map<String, GetRecordByIdResponseDocument> records, final Model m, final Report report) { final MutableInt counter = new MutableInt(0); final long modelSizeBefore = m.size(); ListeningExecutorService executorService = MoreExecutors .listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS)); for (Entry<String, GetRecordByIdResponseDocument> entry : records.entrySet()) { final String id = entry.getKey(); log.debug("Adding {} to the model", id); CallableMapper c = new CallableMapper(this.mapper.replicate(), entry.getValue()); ListenableFuture<Model> modelFuture = executorService.submit(c); Futures.addCallback(modelFuture, new FutureCallback<Model>() { @Override// www . ja v a 2 s. com public void onFailure(Throwable t) { log.error("Error mapping xml to model", t); report.issues.put(id, "Error while adding to model: " + t.getMessage()); } @Override public void onSuccess(Model result) { log.trace("Adding result to model: {}", result); m.add(result); log.trace("ADDED result to mode."); counter.increment(); report.added++; report.addedIds.add(id); } }); } executorService.shutdown(); while (!executorService.isTerminated()) { try { executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { log.error("Could not await termination", e); } } log.debug("Added {} of {} records to model {}, which now has size {} (before {})", counter, records.size(), m.getClass(), m.size(), modelSizeBefore); return counter.intValue(); }
From source file:org.n52.lod.csw.CSWLoDEnabler.java
protected Map<String, GetRecordByIdResponseDocument> retrieveRecordsThreaded(int startPos, int maxRecords, long recordsInTotal) { log.info("Retrieve {} records, starting from {} of {}", maxRecords, startPos, recordsInTotal); // one thread for getting ids List<String> recordIdList = getRecordIds(startPos, maxRecords); // many threads getting records descriptions final Map<String, GetRecordByIdResponseDocument> recordDescriptions = Maps.newConcurrentMap(); ListeningExecutorService executorService = MoreExecutors .listeningDecorator(Executors.newFixedThreadPool(maxRecords)); for (String id : recordIdList) { final String recordId = id; log.debug("Adding {} to the model", recordId); CallableRecordDescription c = new CallableRecordDescription(id, csw); ListenableFuture<GetRecordByIdResponseDocument> responseFuture = executorService.submit(c); Futures.addCallback(responseFuture, new FutureCallback<GetRecordByIdResponseDocument>() { private final Logger logger = LoggerFactory.getLogger("Record Downloader"); @Override//from w w w . j av a 2 s . co m public void onFailure(Throwable t) { logger.error("Error retrieving and parsing record {}", t); report.retrievalIssues.put(recordId, t); } @Override public void onSuccess(GetRecordByIdResponseDocument result) { logger.trace("SUCCESS with {}", result); recordDescriptions.put(recordId, result); report.added++; report.addedIds.add(recordId); } }); } executorService.shutdown(); while (!executorService.isTerminated()) { try { executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { log.error("Could not await termination", e); } } log.info("Done with requests and parsing, have {} GetRecordById documents.", recordDescriptions.size()); return recordDescriptions; }
From source file:edu.dirla.app.ws.rest.services.LogsRestService.java
@ResponseBody @RequestMapping(method = RequestMethod.POST) public DataTrafficResult addLogs(@RequestBody CheckTrafficRep checkTrafficRep) { List<LogData> results = null; long t1 = Calendar.getInstance().getTimeInMillis(); final List<String> filesToUpload = checkTrafficRep.getFilesToUpload(); ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(3)); for (final String fileName : filesToUpload) { Callable<Integer> job = new Callable<Integer>() { @Override/*from w ww . j a va2s . c om*/ public Integer call() throws Exception { List<LogData> lines = new ArrayList<LogData>(); try { lines.addAll(readFile(fileName)); } catch (IOException e) { e.printStackTrace(); } Map<String, Long> data = new HashMap<String, Long>(); for (LogData res : lines) { String key = res.getDomain(); long value = res.getSize(); Long oldValue = data.get(key); data.put(key, value + (oldValue != null ? oldValue : 0)); } logsService.pushLogs("accessLogs." + fileName, data); return 0; } }; // create the job here ListenableFuture<Integer> completion = executor.submit(job); Futures.addCallback(completion, new FutureCallback<Integer>() { @Override public void onFailure(Throwable t) { // log error } @Override public void onSuccess(Integer result) { // do something with the result } }); } executor.shutdown(); while (!executor.isTerminated()) { try { executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { e.printStackTrace(); } } UserDataTrafficResult userTrafficData = logsService.checkDataTraffic(checkTrafficRep.getClientAddress()); long t2 = Calendar.getInstance().getTimeInMillis(); DataTrafficResult dtr = new DataTrafficResult(); dtr.setCheckTrafficRequest(checkTrafficRep); dtr.setTrafficValue(userTrafficData); dtr.setTime(t2 - t1); return dtr; }