List of usage examples for java.util List forEach
default void forEach(Consumer<? super T> action)
From source file:edu.pitt.dbmi.ccd.queue.task.SlurmAlgorithmJob.java
@Scheduled(fixedRate = 5000) public void manageJobsInQueue() { List<JobStatus> finishedJobList = algorithmSlurmService.getFinishedJobs(); Map<Long, JobStatus> finishedJobMap = new HashMap<>(); if (finishedJobList != null && !finishedJobList.isEmpty()) { finishedJobList.forEach(jobStatus -> { finishedJobMap.put(new Long(jobStatus.getJobId()), jobStatus); });// w w w. j av a 2 s.com } int numRunningJobs = 0; List<JobQueueInfo> runningJobList = jobQueueInfoService.findByStatus(1); for (JobQueueInfo job : runningJobList) { Long pid = job.getPid(); if (pid != null && finishedJobMap.containsKey(pid)) { if (finishedJobMap.containsKey(pid)) { Long queueId = job.getId(); jobQueueInfoService.deleteJobById(queueId); JobStatus status = finishedJobMap.get(pid); JobStat stat = algorithmSlurmService.getJobStat(pid); Set<UserAccount> userAccounts = job.getUserAccounts(); UserAccount userAccount = (UserAccount) userAccounts.toArray()[0]; String username = userAccount.getUsername(); LOGGER.info("JobUsage{" + "JobId=" + queueId + ", " + "HPCjobId=" + pid + ", " + "User='" + username + "', " + "State='" + status.getState() + "', " + "Elapsed='" + status.getTime() + "', " + "Start='" + stat.getStart() + "', " + "End='" + stat.getEnd() + "', " + "Partition='" + status.getPartition() + "', " + "AllocCPUS=" + stat.getAllocCPUS() + ", " + "AllocNodes=" + stat.getAllocNodes() + ", " + "NodeList='" + status.getNodelist() + "'}"); algorithmSlurmService.downloadJobResult(job); } else { numRunningJobs++; } } } if (numRunningJobs < queueSize) { // Waiting list to execute List<JobQueueInfo> jobList = jobQueueInfoService.findByStatus(0); if (!jobList.isEmpty()) { // Execute one at a time JobQueueInfo jobQueueInfo = jobList.get(0); LOGGER.info("Run Job ID: " + jobQueueInfo.getId()); try { LOGGER.info("Set Job's status to be 1 (running): " + jobQueueInfo.getId()); jobQueueInfo.setStatus(1); jobQueueInfoService.saveJobIntoQueue(jobQueueInfo); algorithmSlurmService.submitJobtoSlurm(jobQueueInfo); } catch (Exception exception) { LOGGER.error("Unable to run " + jobQueueInfo.getAlgorName(), exception); } } } // Waiting list to terminate List<JobQueueInfo> jobList = jobQueueInfoService.findByStatus(2); jobList.forEach(job -> { killJob(job.getId()); }); }
From source file:com.denkbares.semanticcore.utils.ResultTableModel.java
public ResultTableModel(List<TableRow> rows, List<String> variables) { this.variables = variables; rows.forEach(this::importRow); }
From source file:it.polimi.diceH2020.SPACE4CloudWS.solvers.AbstractSolver.java
protected void sendFiles(@NotNull String remoteDirectory, List<File> lstFiles) { try {/*from w w w .ja v a 2 s . c o m*/ connector.exec("mkdir -p " + remoteDirectory, getClass()); } catch (JSchException | IOException e1) { logger.error("Cannot create new Simulation Folder!", e1); } lstFiles.forEach((File file) -> { try { connector.sendFile(file.getAbsolutePath(), remoteDirectory + File.separator + file.getName(), getClass()); } catch (JSchException | IOException e) { logger.error("Error sending file: " + file.toString(), e); } }); }
From source file:am.ik.categolj3.api.git.GitStore.java
void syncHead() { log.info("Syncing HEAD..."); ObjectId oldHead = this.currentHead.get(); ObjectId newHead = this.head(); try (Repository repository = this.git.getRepository()) { DiffFormatter diffFormatter = new DiffFormatter(System.out); diffFormatter.setRepository(repository); RevWalk walk = new RevWalk(repository); try {// w w w .ja v a2s.c o m RevCommit fromCommit = walk.parseCommit(oldHead); RevCommit toCommit = walk.parseCommit(newHead); List<DiffEntry> list = diffFormatter.scan(fromCommit.getTree(), toCommit.getTree()); list.forEach(diff -> { log.info("[{}]\tnew={}\told={}", diff.getChangeType(), diff.getNewPath(), diff.getOldPath()); if (diff.getOldPath() != null) { Path path = Paths .get(gitProperties.getBaseDir().getAbsolutePath() + "/" + diff.getOldPath()); if (Entry.isPublic(path)) { Long entryId = Entry.parseEntryId(path); log.info("evict Entry({})", entryId); this.entryCache.evict(entryId); } } if (diff.getNewPath() != null) { Path path = Paths .get(gitProperties.getBaseDir().getAbsolutePath() + "/" + diff.getNewPath()); this.loadEntry(path).ifPresent(entry -> { log.info("put Entry({})", entry.getEntryId()); this.entryCache.put(entry.getEntryId(), entry); }); } }); } finally { walk.dispose(); } } catch (IOException e) { throw new UncheckedIOException(e); } catch (Exception e) { throw new IllegalStateException(e); } this.currentHead.set(newHead); }
From source file:hr.diskobolos.controller.EvaluationController.java
@RequestMapping(value = "/findAllByMemberRegisterAndQuestionnaireType/{memberRegisterId}/{questionnaireType}", method = RequestMethod.GET) @ResponseBody/*from ww w . ja va 2s . c o m*/ @PreAuthorize("hasRole('ADMIN')") public String findAllByMemberRegisterAndQuestionnaireType(@PathVariable Integer memberRegisterId, @PathVariable String questionnaireType) { JSONObject resultMap = new JSONObject(); MemberRegister memberRegister = memberRegisterService.findById(memberRegisterId); List<EvaluationAnswer> evaluationAnswers = evaluationAnswerService .findAllByMemberRegisterAndQuestionnaireType(memberRegister, QuestionnaireType.getInstance(questionnaireType)); evaluationAnswers.forEach((EvaluationAnswer e) -> { e.getAnswer().setValue(e.getAnswer().getValue()); }); JSONArray evaluationAnswersJson = jsonMapper.getJSONArray(evaluationAnswers); resultMap.put("evaluationAnswersJson", evaluationAnswersJson); return resultMap.toString(); }
From source file:com.liferay.apio.architect.internal.test.jaxrs.resource.RootResourceTest.java
@Test public void testResourceEndpoints() { List<String> endpoints = asList("hello", "hello/hi", "hello/hi/bye"); List<String> methods = asList("DELETE", "GET", "PATCH", "POST", "PUT"); endpoints.forEach(endpoint -> methods.forEach(method -> _testEndpoint(endpoint, method))); }
From source file:clientapi.load.ClientTransformer.java
@Override public byte[] transform(String name, String transformedName, byte[] basicClass) { List<ITransformer> transformers = getTransformers(transformedName); if (!transformers.isEmpty()) { try {//from ww w.jav a2s .c om ClassNode cn = getClassNode(basicClass); if (cn == null) return basicClass; // Run all transformers on the Class transformers.forEach(transformer -> transformer.transform(cn)); // Return transformed class bytecode ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); cn.accept(cw); return cw.toByteArray(); } catch (Exception ignored) { } } return basicClass; }
From source file:org.obiba.mica.taxonomy.rest.TaxonomiesSearchResource.java
@GET @Path("/_search") @Timed//from w w w. j av a2s .co m public List<Opal.TaxonomyBundleDto> search(@QueryParam("query") String query, @QueryParam("locale") String locale, @Nullable @QueryParam("target") String target) { logger.debug("TaxonomiesSearchResource#search called with query [%s], locale [%s] and target [%s]", query, locale, target); List<Opal.TaxonomyBundleDto> results = Lists.newArrayList(); List<TaxonomyTarget> targets = target == null ? taxonomyService.getTaxonomyTaxonomy().getVocabularies().stream() .map(t -> TaxonomyTarget.valueOf(t.getName().toUpperCase())).collect(Collectors.toList()) : Lists.newArrayList(TaxonomyTarget.valueOf(target.toUpperCase())); targets.forEach(t -> filter(t.name(), query, locale).stream().map(taxo -> Opal.TaxonomyBundleDto .newBuilder().setTarget(t.name().toLowerCase()).setTaxonomy(taxo).build()).forEach(results::add)); return results; }
From source file:com.qwazr.crawler.web.driver.PhantomJSBrowserDriver.java
private Map<String, String> getHeaders() { if (endEntry == null) return null; if (headers != null) return headers; List<Map<String, ?>> entries = (List<Map<String, ?>>) endEntry.get("headers"); if (entries == null) return null; final Map<String, String> headers = new LinkedHashMap<>(); entries.forEach(new Consumer<Map<String, ?>>() { @Override/*from w w w . j av a2 s . com*/ public void accept(Map<String, ?> map) { Object name = map.get("name"); Object value = map.get("value"); if (name == null || value == null) return; headers.put(name.toString().trim().toLowerCase(), value.toString()); } }); return this.headers = headers; }