List of usage examples for java.util Spliterator ORDERED
int ORDERED
To view the source code for java.util Spliterator ORDERED.
Click Source Link
From source file:org.apache.nifi.minifi.c2.provider.nifi.rest.NiFiRestConfigurationProvider.java
private Pair<Stream<Pair<String, String>>, Closeable> getIdAndFilenameStream() throws ConfigurationProviderException, IOException { TemplatesIterator templatesIterator = new TemplatesIterator(httpConnector, jsonFactory); return new Pair<>(StreamSupport .stream(Spliterators.spliteratorUnknownSize(templatesIterator, Spliterator.ORDERED), false), templatesIterator);/*from w w w . ja v a 2 s. c o m*/ }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraPagesRepository.java
Stream<AppPage> getAppPagesFromCassandra(Application.Name applicationName) { Optional<Iterator<AppPage>> optionalResult = Optional.empty(); try {/*w w w .j av a 2s. c o m*/ optionalResult = Optional .ofNullable(appPageIndexAccessor.selectBy(applicationName.toString()).iterator()); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException( "Could not retrieve the pages and its associated experiments for application:\"" + applicationName + "\"", e); } return StreamSupport.stream(Spliterators.spliteratorUnknownSize( optionalResult.orElse(Collections.emptyIterator()), Spliterator.ORDERED), false); }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraAssignmentsRepository.java
Stream<ExperimentUserByUserIdContextAppNameExperimentId> getUserIndexStream(String userId, String appName, String context) {//from w w w.j a v a 2 s . c om Stream<ExperimentUserByUserIdContextAppNameExperimentId> resultStream = Stream.empty(); try { final Result<ExperimentUserByUserIdContextAppNameExperimentId> result = experimentUserIndexAccessor .selectBy(userId, appName, context); resultStream = StreamSupport .stream(Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not retrieve assignments for " + "experimentID = \"" + appName + "\" userID = \"" + userId + "\" and context " + context, e); } return resultStream; }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraPagesRepository.java
@Override public ExperimentPageList getExperimentPages(Experiment.ID experimentID) { ExperimentPageList experimentPageList = new ExperimentPageList(); try {//w w w . j ava 2 s. c om Result<PageExperimentByAppNamePage> result = experimentPageAccessor.selectBy(experimentID.getRawID()); Stream<PageExperimentByAppNamePage> resultList = StreamSupport .stream(Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); List<ExperimentPage> experimentPages = resultList .map(t -> ExperimentPage.withAttributes(Page.Name.valueOf(t.getPage()), t.isAssign()).build()) .collect(Collectors.toList()); experimentPageList.setPages(experimentPages); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not retrieve the pages for experiment: \"" + experimentID + "\"", e); } return experimentPageList; }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraPagesRepository.java
@Override public List<PageExperiment> getExperiments(Application.Name applicationName, Page.Name pageName) { Stream<PageExperimentByAppNamePage> resultList = Stream.empty(); try {/*ww w . j a v a 2s. c om*/ Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor .selectBy(applicationName.toString(), pageName.toString()); resultList = StreamSupport .stream(Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException( new StringBuilder("Could not retrieve the experiments for applicationName:\"") .append(applicationName).append("\", page:\"").append(pageName).append("\"").toString(), e); } //TODO: make the experiment label part of the pageExperimentIndex to save a query per page return resultList.map(t -> { Optional<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experiment = Optional .ofNullable(experimentAccessor.selectBy(t.getExperimentId()).one()); PageExperiment.Builder builder = new PageExperiment.Builder(Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign()); if (experiment.isPresent()) { builder.setLabel(Experiment.Label.valueOf(experiment.get().getLabel())); } return builder.build(); }).filter(t -> t.getLabel() != null).collect(Collectors.toList()); }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraPagesRepository.java
@Override public List<PageExperiment> getExperimentsWithoutLabels(Application.Name applicationName, Page.Name pageName) { Stream<PageExperimentByAppNamePage> resultList = Stream.empty(); try {/*from ww w . ja v a 2 s. c o m*/ Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor .selectBy(applicationName.toString(), pageName.toString()); resultList = StreamSupport .stream(Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not retrieve the experiments for applicationName:\"" + applicationName + "\", page:\"" + pageName, e); } return resultList.map(t -> { PageExperiment.Builder builder = new PageExperiment.Builder(Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign()); return builder.build(); }).collect(Collectors.toList()); }
From source file:com.ikanow.aleph2.analytics.services.BatchEnrichmentContext.java
/** Utility to mutate objects * @param original_json/*from ww w . j a v a2 s .co m*/ * @param mutations * @return */ protected static JsonNode handleMutations(JsonNode original_json, Optional<ObjectNode> mutations) { return mutations.map(o -> StreamSupport.<Map.Entry<String, JsonNode>>stream( Spliterators.spliteratorUnknownSize(o.fields(), Spliterator.ORDERED), false).reduce(original_json, (acc, kv) -> ((ObjectNode) acc).set(kv.getKey(), kv.getValue()), (val1, val2) -> val2)) .orElse(original_json); }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraPagesRepository.java
@Override public Map<Pair<Application.Name, Page.Name>, List<PageExperiment>> getExperimentsWithoutLabels( Collection<Pair<Application.Name, Page.Name>> appAndPagePairs) { logger.debug("getExperimentsWithoutLabels {}", appAndPagePairs); Map<Pair<Application.Name, Page.Name>, List<PageExperiment>> resultMap = new HashMap<>(); try {//w ww . j av a 2s . c om Map<Pair<Application.Name, Page.Name>, ListenableFuture<Result<PageExperimentByAppNamePage>>> expFutureMap = new HashMap<>(); appAndPagePairs.forEach(pair -> { expFutureMap.put(pair, pageExperimentIndexAccessor.asyncSelectBy(pair.getLeft().toString(), pair.getRight().toString())); }); for (Pair<Application.Name, Page.Name> pair : expFutureMap.keySet()) { ListenableFuture<Result<PageExperimentByAppNamePage>> expFuture = expFutureMap.get(pair); Stream<PageExperimentByAppNamePage> resultList = StreamSupport.stream( Spliterators.spliteratorUnknownSize( UninterruptibleUtil.getUninterruptibly(expFuture).iterator(), Spliterator.ORDERED), false); List<PageExperiment> pageExperimentsList = resultList.map(t -> { PageExperiment.Builder builder = new PageExperiment.Builder( Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign()); return builder.build(); }).collect(Collectors.toList()); resultMap.put(pair, pageExperimentsList); } } catch (Exception e) { logger.error("getExperimentsWithoutLabels for {} failed", appAndPagePairs, e); throw new RepositoryException("Could not getExperimentsWithoutLabels", e); } logger.debug("Returning PageExperimentList map {}", resultMap); return resultMap; }
From source file:com.ikanow.aleph2.harvest.logstash.utils.LogstashUtils.java
/** * Reads the given output file and outputs it to the logger with the spec'd log level. * @param logger/*from ww w. j ava 2 s .co m*/ * @param level * @param output_file * @throws IOException */ public static void sendOutputToLogger(final IBucketLogger logger, final Level level, final File output_file, final Optional<Long> max_lines) throws IOException { // _logger.error("Reading output file: " + output_file + " to send to logger at level: " + level); Files.lines(output_file.toPath()).limit(max_lines.orElse(10000L)).forEach(line -> { try { //convert line to valid json, then parse json, build BMB object from it final String fixed_line = line.replaceAll(logstash_colon_search, logstash_colon_replace) .replaceAll(logstash_arrow_search, logstash_arrow_replace) .replaceAll(logstash_newline_search, logstash_newline_replace); final String plugin_fixed = fixPlugin(fixed_line); final ObjectNode line_object = (ObjectNode) _mapper.readTree(plugin_fixed); //move specific fields we want into BMB final Date date = parseLogstashDate(line_object.remove("timestamp").asText()); final Level logstash_level = Level.valueOf(line_object.remove("level").asText()); final String message = line_object.remove("message").asText(); //move everything else into details map logger.inefficientLog(logstash_level, new BasicMessageBean(date, true, LogstashHarvestService.class.getSimpleName(), "test_output", null, message, StreamSupport .stream(Spliterators.spliteratorUnknownSize(line_object.fields(), Spliterator.ORDERED), true) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().asText())))); } catch (Exception ex) { //fallback on conversion failure logger.inefficientLog(level, ErrorUtils .buildSuccessMessage(LogstashHarvestService.class.getSimpleName(), "test_output", line)); } }); //TODO should we delete log file after we've read it? }
From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.ElasticsearchIndexUtils.java
/** Recursive function that will return all fields in an insert (eg "geoip", "geoip.location") * @param index/*from ww w. j a v a 2 s .c o m*/ * @return */ protected static Stream<String> getAllFixedFields_internal(final JsonNode index) { return Optional.ofNullable(index.get("properties")).filter(p -> !p.isNull()).map(p -> { if (!p.isObject()) throw new RuntimeException("properties must be object"); return p; }).map(p -> { return StreamSupport.stream(Spliterators.spliteratorUnknownSize(p.fields(), Spliterator.ORDERED), false) .map(kv -> { return kv; }).<String>flatMap(kv -> { final Stream<String> parent_element = Stream.of(kv.getKey()); return Stream.concat(parent_element, getAllFixedFields_internal(kv.getValue()).map(s -> kv.getKey() + "." + s)); }); }).orElse(Stream.<String>empty()); }