List of usage examples for java.util List parallelStream
default Stream<E> parallelStream()
From source file:com.spotify.styx.api.BackfillResource.java
private List<RunStateData> retrieveBackfillStatuses(Backfill backfill) { final List<RunStateData> processedStates; final List<RunStateData> waitingStates; Map<WorkflowInstance, Long> activeWorkflowInstances; try {//from w w w . j av a 2s . c o m activeWorkflowInstances = storage.readActiveWorkflowInstances(); } catch (IOException e) { throw Throwables.propagate(e); } final List<Instant> processedInstants = rangeOfInstants(backfill.start(), backfill.nextTrigger(), backfill.schedule()); processedStates = processedInstants.parallelStream().map(instant -> { final WorkflowInstance wfi = WorkflowInstance.create(backfill.workflowId(), toParameter(backfill.schedule(), instant)); Optional<RunState> restoredStateOpt = ReplayEvents.getBackfillRunState(wfi, activeWorkflowInstances, storage, backfill.id()); if (restoredStateOpt.isPresent()) { RunState state = restoredStateOpt.get(); return RunStateData.create(state.workflowInstance(), state.state().name(), state.data()); } else { return RunStateData.create(wfi, UNKNOWN, StateData.zero()); } }).collect(toList()); final List<Instant> waitingInstants = rangeOfInstants(backfill.nextTrigger(), backfill.end(), backfill.schedule()); waitingStates = waitingInstants.stream().map(instant -> { final WorkflowInstance wfi = WorkflowInstance.create(backfill.workflowId(), toParameter(backfill.schedule(), instant)); return RunStateData.create(wfi, WAITING, StateData.zero()); }).collect(toList()); return Stream.concat(processedStates.stream(), waitingStates.stream()).collect(toList()); }
From source file:fr.ortolang.diffusion.client.cmd.CheckBagCommand.java
private void checkOrtolangItemJson(Path filepath) { String jsonContent = getContent(filepath); if (jsonContent != null) { List<String> keys = extractOrtolangKeys(jsonContent); System.out.println("Looking for keys in registry : " + keys); keys.parallelStream().forEach((key) -> checkObject(key, "referential")); }/*from w w w . j av a2 s .c o m*/ }
From source file:org.wso2.security.tools.reposcanner.repository.GitHubRepoInfoGenerator.java
@Override public List<Repo> getRepoList(String consoleTag, List<String> users) { RepositoryService repositoryService = new RepositoryService(client); List<Repo> repoList = Collections.synchronizedList(new ArrayList()); //Get the list of git repositories for each GitHub user account users.parallelStream().forEach(user -> { log.info(consoleTag + "Fetching repositories for GitHub user account: " + user); try {//from w w w . j a v a 2s . co m List<Repository> userRepositoryList = repositoryService.getRepositories(user); log.info(consoleTag + userRepositoryList.size() + " repositories found for user account: " + user); //Download master branches only if download-master flag is enabled if (AppConfig.isDownloadMaster()) { userRepositoryList.parallelStream().forEach(repository -> { if (AppConfig.getGithubRepos() == null || AppConfig.getGithubRepos().contains(repository.getName())) { try { log.info(consoleTag + "[DownloadMaster] Started downloading master branch of: " + repository.getName()); Repo tempRepo = new Repo(RepoType.GIT, repository.getOwner().getLogin(), repository.getName(), repository.getCloneUrl(), null, null, null); gitMasterDownloader.downloadRepo(tempRepo, masterDownloadFolder, false); log.info(consoleTag + "[DownloadMaster] Completed downloading master branch of: " + repository.getName()); } catch (Exception e) { log.error(consoleTag + "Error in downloading master branch ZIP for GitHub user account: " + user + " repository: " + repository.getName(), e); } } else { log.info(consoleTag + "[DownloadMaster][Skipping] Skipping since the repo is not in include list : " + repository.getName()); } }); } //Do this only if scan should be done (skip skip-flag is not set) or skip-flag is set but tag download should happen if (!AppConfig.isSkipScan() || AppConfig.isDownloadTags()) { //Get the list of tags for each repository userRepositoryList.parallelStream().forEach(repository -> { if (AppConfig.getGithubRepos() == null || AppConfig.getGithubRepos().contains(repository.getName())) { log.info(consoleTag + "Fetching tags for GitHub user account: " + user + " repository: " + repository.getName()); try { List<RepositoryTag> repositoryTagLists = repositoryService.getTags(repository); log.info(consoleTag + repositoryTagLists.size() + " tags found for user account: " + user + " repository:" + repository.getName()); //Create persistable Repo object with repository and tag information repositoryTagLists.parallelStream().forEach(repositoryTag -> { Repo repo = new Repo(RepoType.GIT, repository.getOwner().getLogin(), repository.getName(), repository.getCloneUrl(), repositoryTag.getName(), repositoryTag.getZipballUrl(), new Date()); repoList.add(repo); //Download tags only if download-tag flag is enabled if (AppConfig.isDownloadTags()) { try { log.info(consoleTag + "[DownloadTags] Started downloading tag: " + repo.getTagName() + " of: " + repository.getName()); gitTagDownloader.downloadRepo(repo, tagsDownloadFolder, false); log.info(consoleTag + "[DownloadTags] Completed downloading tag: " + repo.getTagName() + " of: " + repository.getName()); } catch (Exception e) { log.error(consoleTag + "Error in downloading master branch ZIP for GitHub user account: " + user + " repository: " + repository.getName(), e); } } }); } catch (Exception e) { log.error(consoleTag + "Error in fetching tags for GitHub user account: " + user + " repository: " + repository.getName(), e); } } else { log.info(consoleTag + "[Skipping] Skipping since the repo is not in include list : " + repository.getName()); } }); } else { log.warn(consoleTag + "[Skipping] SkipScan parameter is set and tag download is not enabled. Skipping tag information retrieval."); } } catch (Exception e) { log.error("Error in fetching repositories for GitHub user account: " + user, e); } }); return repoList; }
From source file:core.Annotator.java
private boolean annotateVariants() { final List<Integer> starts = getStarts(); final AtomicInteger total = new AtomicInteger(); starts.parallelStream().forEachOrdered(start -> { try {//from w w w .ja v a 2 s.c om annotate(start); } catch (Exception e) { e.printStackTrace(); } }); return true; }
From source file:it.polimi.diceH2020.SPACE4CloudWS.core.CoarseGrainedOptimizer.java
private boolean hillClimbing(SolutionPerJob solPerJob, Technology technology) { boolean success = false; Pair<Optional<Double>, Long> simulatorResult = dataProcessor.simulateClass(solPerJob); Optional<Double> maybeResult = simulatorResult.getLeft(); if (maybeResult.isPresent()) { success = true;/*from w w w. j a va 2s .c o m*/ PerformanceSolver currentSolver = dataProcessor.getPerformanceSolver(); Function<Double, Double> fromResult = currentSolver.transformationFromSolverResult(solPerJob, technology); Predicate<Double> feasibilityCheck = currentSolver.feasibilityCheck(solPerJob, technology); Consumer<Double> metricUpdater = currentSolver.metricUpdater(solPerJob, technology); final double tolerance = settings.getOptimization().getTolerance(); BiPredicate<Double, Double> incrementCheck; Function<Integer, Integer> updateFunction; Predicate<Double> stoppingCondition; Predicate<Integer> vmCheck; double responseTime = fromResult.apply(maybeResult.get()); if (feasibilityCheck.test(responseTime)) { updateFunction = n -> n - 1; stoppingCondition = feasibilityCheck.negate(); vmCheck = n -> n == 1; incrementCheck = (prev, curr) -> false; } else { updateFunction = n -> n + 1; stoppingCondition = feasibilityCheck; vmCheck = n -> false; incrementCheck = (prev, curr) -> Math.abs((prev - curr) / prev) < tolerance; } List<Triple<Integer, Optional<Double>, Boolean>> resultsList = alterUntilBreakPoint(solPerJob, updateFunction, fromResult, feasibilityCheck, stoppingCondition, incrementCheck, vmCheck); Optional<Triple<Integer, Optional<Double>, Boolean>> result = resultsList.parallelStream() .filter(t -> t.getRight() && t.getMiddle().isPresent()) .min(Comparator.comparing(Triple::getLeft)); result.ifPresent(triple -> triple.getMiddle().ifPresent(output -> { int nVM = triple.getLeft(); switch (technology) { case HADOOP: case SPARK: solPerJob.setThroughput(output); break; case STORM: break; default: throw new RuntimeException("Unexpected technology"); } solPerJob.updateNumberVM(nVM); double metric = fromResult.apply(output); metricUpdater.accept(metric); logger.info(String.format( "class%s-> MakeFeasible ended, result = %f, other metric = %f, obtained with: %d VMs", solPerJob.getId(), output, metric, nVM)); })); } else { logger.info("class" + solPerJob.getId() + "-> MakeFeasible ended with ERROR"); solPerJob.setFeasible(false); } return success; }
From source file:com.netflix.spinnaker.igor.gitlabci.GitlabCiBuildMonitor.java
@Override protected BuildPollingDelta generateDelta(PollContext ctx) { final String master = ctx.partitionName; log.info("Checking for new builds for {}", kv("master", master)); final AtomicInteger updatedBuilds = new AtomicInteger(); final GitlabCiService gitlabCiService = (GitlabCiService) buildMasters.getMap().get(master); long startTime = System.currentTimeMillis(); final List<Project> projects = gitlabCiService.getProjects(); log.info("Took {} ms to retrieve {} repositories (master: {})", System.currentTimeMillis() - startTime, projects.size(), kv("master", master)); List<BuildDelta> delta = new ArrayList<>(); projects.parallelStream().forEach(project -> { List<Pipeline> pipelines = filterOldPipelines( gitlabCiService.getPipelines(project, MAX_NUMBER_OF_PIPELINES)); for (Pipeline pipeline : pipelines) { String branchedRepoSlug = GitlabCiPipelineUtis.getBranchedPipelineSlug(project, pipeline); boolean isPipelineRunning = GitlabCiResultConverter.running(pipeline.getStatus()); int cachedBuildId = buildCache.getLastBuild(master, branchedRepoSlug, isPipelineRunning); // In case of Gitlab CI the pipeline ids are increasing so we can use it for ordering if (pipeline.getId() > cachedBuildId) { updatedBuilds.incrementAndGet(); delta.add(new BuildDelta(branchedRepoSlug, project, pipeline, isPipelineRunning)); }/*ww w.ja v a 2 s . com*/ } }); if (!delta.isEmpty()) { log.info("Found {} new builds (master: {})", updatedBuilds.get(), kv("master", master)); } return new BuildPollingDelta(delta, master, startTime); }
From source file:com.firewalld.sentimentanalysis.IDSentiWordNet.java
private Map<String, Double> createDictionary() throws IOException { Map<String, Double> dict = IOUtils .readLines(getClass().getClassLoader().getResourceAsStream(firewallConf.get(SWN_FILE))) .parallelStream()//from w w w. j ava 2 s .com /* If it's a comment, skip this line */ .filter(line -> !line.trim().startsWith("#")).flatMap(line -> { String[] data = line.split("\t"); String wordTypeMarker = data[0]; // Example line: // POS ID PosS NegS SynsetTerm#sensenumber Desc // a 00009618 0.5 0.25 spartan#4 austere#3 ascetical#2 ascetic#2 practicing great self-denial;...etc // Is it a valid line? Otherwise, through exception. if (data.length != 6) { throw new IllegalArgumentException( String.format("Incorrect tabulation format in file, line: %s", line)); } // Calculate synset score as score = PosS - NegS Double synsetScore = Double.parseDouble(data[2]) - Double.parseDouble(data[3]); // Get all Synset terms String[] synTermsSplit = data[4].split(" "); // Go through all terms of current synset. Stream<Tuple2<String, Tuple2<Double, Double>>> synSets = Arrays.asList(synTermsSplit) .parallelStream().map(synTermSplit -> { // Get synterm and synterm rank String[] synTermAndRank = synTermSplit.split("#"); String synTerm = synTermAndRank[0] + "#" + wordTypeMarker; double synTermRank = Double.parseDouble(synTermAndRank[1]); // What we get here is a (term, (rank, score)) return new Tuple2<>(synTerm, new Tuple2<>(synTermRank, synsetScore)); }); return synSets; }) // What we get here is a map of the type: // term -> {score of synset#1, score of synset#2...} .collect(Collectors.groupingBy(synSet -> synSet._1, Collectors.mapping(synSet -> synSet._2, Collectors.toList()))) .entrySet().parallelStream().map(synSet -> { String word = synSet.getKey(); List<Tuple2<Double, Double>> synSetScoreList = synSet.getValue(); // Calculate weighted average. Weigh the synsets according to // their rank. // Score= 1/2*first + 1/3*second + 1/4*third ..... etc. // Sum = 1/1 + 1/2 + 1/3 ... Tuple2<Double, Double> scoreSum = synSetScoreList.parallelStream() .reduce(new Tuple2<>(0.0, 0.0), (s1, s2) -> new Tuple2<>( ((s1._1 == 0.0) ? 0.0 : s1._2 / s1._1) + ((s2._1 == 0.0) ? 0.0 : s2._2 / s2._1), ((s1._1 == 0.0) ? 0.0 : 1 / s1._1) + ((s2._1 == 0.0) ? 0.0 : 1 / s2._1))); double score = scoreSum._1 / scoreSum._2; return new Tuple2<>(word, score); }).collect(Collectors.toMap(synSet -> synSet._1, synSet -> synSet._2)); return dict; }
From source file:de.steilerdev.myVerein.server.controller.user.MessageController.java
/** * This function retrieves all unread messages of a user. The function is invoked bu GETting the URI /api/user/message. * @param currentUser The currently logged in user. * @return An HTTP response with a status code, together with the JSON list-object of all unread messages, or only an error code if an error occurred. *//*from w ww . ja va 2 s. c o m*/ @RequestMapping(produces = "application/json", method = RequestMethod.GET) public ResponseEntity<List<Message>> getMessages(@CurrentUser User currentUser, @RequestParam(required = false) String all) { logger.trace("[{}] Getting unread messages", currentUser); List<Message> messages = messageRepository.findAllByPrefixedReceiverIDAndMessageStatus( Message.receiverIDForUser(currentUser), Message.MessageStatus.PENDING); if (messages == null) { logger.debug("[{}] Unable to find any undelivered messages", currentUser); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } else { messages.parallelStream().forEach(message -> message.setDelivered(currentUser)); if (all != null && !all.isEmpty()) { logger.debug("[{}] Retrieving all messages", currentUser); messages.addAll(messageRepository.findAllByPrefixedReceiverIDAndMessageStatus( Message.receiverIDForUser(currentUser), Message.MessageStatus.DELIVERED)); messages.addAll(messageRepository.findAllByPrefixedReceiverIDAndMessageStatus( Message.receiverIDForUser(currentUser), Message.MessageStatus.READ)); } try { messageRepository.save(messages); messages.replaceAll(Message::getSendingObjectOnlyId); logger.info("[{}] Returning messages", currentUser); return new ResponseEntity<>(messages, HttpStatus.OK); } catch (IllegalArgumentException e) { logger.warn("[" + currentUser + "] Unable to save messages for " + currentUser.getEmail() + ": " + e.getMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } }
From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java
private double getSum(List<Transaction> transactions) { return abs(transactions.parallelStream() .flatMapToDouble(trx -> DoubleStream.of(trx.getAmount().doubleValue())).sum()); }
From source file:com.netflix.spinnaker.igor.travis.TravisBuildMonitor.java
public List<BuildDelta> changedBuilds(final String master, final TravisService travisService) { log.info("({}) Checking for new builds", kv("master", master)); long startTime = System.currentTimeMillis(); List<Repo> repos = filterOutOldBuilds(travisService.getReposForAccounts()); log.info("({}) Took {}ms to retrieve {} repositories", kv("master", master), System.currentTimeMillis() - startTime, repos.size()); List<BuildDelta> results = repos.parallelStream().map(repo -> travisService.getBuilds(repo, 5)) .flatMap(builds -> processBuilds(builds, master, travisService).stream()) .collect(Collectors.toList()); if (!results.isEmpty()) { log.info("({}) Found {} new builds", kv("master", master), results.size()); }/*ww w . j a v a 2s. com*/ log.info("({}) Last poll took {}ms", kv("master", master), System.currentTimeMillis() - startTime); if (travisProperties.getRepositorySyncEnabled()) { startTime = System.currentTimeMillis(); travisService.syncRepos(); log.info("({}) repositorySync: Took {}ms to sync repositories", kv("master", master), System.currentTimeMillis() - startTime); } return results; }