List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender.java
private List<Map<String, Element>> getElementsAndCounts(Map<String, SortedMap<Long, Integer>> map, List<Long> cutoffs, SortedSet<PurgeElement> purgeInformation) { if (purgeInformation.size() > maxUniqueMessages) { ErrorAndWarningsCleanup cleanup = new ErrorAndWarningsCleanup(); long cutoff = Time.now() - (messageAgeLimitSeconds * 1000); cutoff = (cutoff / 1000);//from w w w . j a v a 2 s .c o m cleanup.cleanupMessages(map, purgeInformation, cutoff, maxUniqueMessages); } List<Map<String, Element>> ret = new ArrayList<>(cutoffs.size()); for (int i = 0; i < cutoffs.size(); ++i) { ret.add(new HashMap<String, Element>()); } synchronized (lock) { for (Map.Entry<String, SortedMap<Long, Integer>> element : map.entrySet()) { for (int i = 0; i < cutoffs.size(); ++i) { Map<String, Element> retMap = ret.get(i); SortedMap<Long, Integer> qualifyingTimes = element.getValue().tailMap(cutoffs.get(i)); long count = 0; for (Map.Entry<Long, Integer> entry : qualifyingTimes.entrySet()) { count += entry.getValue(); } if (!qualifyingTimes.isEmpty()) { retMap.put(element.getKey(), new Element(count, qualifyingTimes.lastKey())); } } } } return ret; }
From source file:com.blacklocus.metrics.CloudWatchReporter.java
private <T> SortedMap<String, T> mapNames(SortedMap<String, T> original) { return original.entrySet().stream() .collect(Collectors.toMap(e -> nameTransformer.apply(e.getKey()), Map.Entry::getValue, (k, v) -> { throw new RuntimeException(String.format("Duplicate key %s", k)); }, TreeMap::new)); }
From source file:org.apache.hadoop.hbase.regionserver.transactional.THLogRecoveryManager.java
private SortedMap<Long, List<KeyValue>> resolvePendingTransaction( SortedMap<Long, List<KeyValue>> pendingTransactionsById) { SortedMap<Long, List<KeyValue>> commitedTransactionsById = new TreeMap<Long, List<KeyValue>>(); LOG.info("Region log has " + pendingTransactionsById.size() + " unfinished transactions. Going to the transaction log to resolve"); for (Entry<Long, List<KeyValue>> entry : pendingTransactionsById.entrySet()) { if (entry.getValue().isEmpty()) { LOG.debug("Skipping resolving trx [" + entry.getKey() + "] has no writes."); }/* ww w . j a va 2 s.c o m*/ TransactionLogger.TransactionStatus transactionStatus = getGlobalTransactionLog() .getStatusForTransaction(entry.getKey()); if (transactionStatus == null) { throw new RuntimeException( "Cannot resolve tranasction [" + entry.getKey() + "] from global tx log."); } switch (transactionStatus) { case ABORTED: break; case COMMITTED: commitedTransactionsById.put(entry.getKey(), entry.getValue()); break; case PENDING: LOG.warn("Transaction [" + entry.getKey() + "] is still pending. Asumming it will not commit." + " If it eventually does commit, then we loose transactional semantics."); // TODO this could possibly be handled by waiting and seeing what happens. break; } } return commitedTransactionsById; }
From source file:com.cloudera.flume.reporter.ReportEvent.java
/** * Returns event in string form: host [ priority date ] {attr1:val1} * {attr2:val2} {metric1:val1} {metric2:val2} body *//*w ww.j av a 2 s .co m*/ public String toString() { StringBuilder metrics = new StringBuilder(); // Iterate over strings, doubles and longs building a { key : value } string SortedMap<String, String> sortedStrings = new TreeMap<String, String>(this.getAllStringMetrics()); for (Entry<String, String> e : sortedStrings.entrySet()) { metrics.append("{ " + e.getKey() + " : "); String o = e.getValue(); metrics.append(o + " } "); } SortedMap<String, Double> sortedDoubles = new TreeMap<String, Double>(this.getAllDoubleMetrics()); for (Entry<String, Double> e : sortedDoubles.entrySet()) { metrics.append("{ " + e.getKey() + " : "); String o = e.getValue().toString(); metrics.append(o + " } "); } SortedMap<String, Long> sortedLongs = new TreeMap<String, Long>(this.getAllLongMetrics()); for (Entry<String, Long> e : sortedLongs.entrySet()) { metrics.append("{ " + e.getKey() + " : "); String o = e.getValue().toString(); metrics.append(o + " } "); } // This implementation taken from EventImpl String mbody = StringEscapeUtils.escapeJava(new String(getBody())); StringBuilder attrs = new StringBuilder(); SortedMap<String, byte[]> sorted = new TreeMap<String, byte[]>(this.fields); for (Entry<String, byte[]> e : sorted.entrySet()) { attrs.append("{ " + e.getKey() + " : "); String o = Attributes.toString(this, e.getKey()); attrs.append(o + " } "); } return getHost() + " [" + getPriority().toString() + " " + new Date(getTimestamp()) + "] " + attrs.toString() + metrics.toString() + mbody; }
From source file:org.apache.hadoop.hive.metastore.utils.MetaStoreServerUtils.java
/** * Produce a hash for the storage descriptor * @param sd storage descriptor to hash/* w w w. j a v a2 s. c o m*/ * @param md message descriptor to use to generate the hash * @return the hash as a byte array */ public static synchronized byte[] hashStorageDescriptor(StorageDescriptor sd, MessageDigest md) { // Note all maps and lists have to be absolutely sorted. Otherwise we'll produce different // results for hashes based on the OS or JVM being used. md.reset(); // In case cols are null if (sd.getCols() != null) { for (FieldSchema fs : sd.getCols()) { md.update(fs.getName().getBytes(ENCODING)); md.update(fs.getType().getBytes(ENCODING)); if (fs.getComment() != null) { md.update(fs.getComment().getBytes(ENCODING)); } } } if (sd.getInputFormat() != null) { md.update(sd.getInputFormat().getBytes(ENCODING)); } if (sd.getOutputFormat() != null) { md.update(sd.getOutputFormat().getBytes(ENCODING)); } md.update(sd.isCompressed() ? "true".getBytes(ENCODING) : "false".getBytes(ENCODING)); md.update(Integer.toString(sd.getNumBuckets()).getBytes(ENCODING)); if (sd.getSerdeInfo() != null) { SerDeInfo serde = sd.getSerdeInfo(); if (serde.getName() != null) { md.update(serde.getName().getBytes(ENCODING)); } if (serde.getSerializationLib() != null) { md.update(serde.getSerializationLib().getBytes(ENCODING)); } if (serde.getParameters() != null) { SortedMap<String, String> params = new TreeMap<>(serde.getParameters()); for (Map.Entry<String, String> param : params.entrySet()) { md.update(param.getKey().getBytes(ENCODING)); md.update(param.getValue().getBytes(ENCODING)); } } } if (sd.getBucketCols() != null) { List<String> bucketCols = new ArrayList<>(sd.getBucketCols()); for (String bucket : bucketCols) { md.update(bucket.getBytes(ENCODING)); } } if (sd.getSortCols() != null) { SortedSet<Order> orders = new TreeSet<>(sd.getSortCols()); for (Order order : orders) { md.update(order.getCol().getBytes(ENCODING)); md.update(Integer.toString(order.getOrder()).getBytes(ENCODING)); } } if (sd.getSkewedInfo() != null) { SkewedInfo skewed = sd.getSkewedInfo(); if (skewed.getSkewedColNames() != null) { SortedSet<String> colnames = new TreeSet<>(skewed.getSkewedColNames()); for (String colname : colnames) { md.update(colname.getBytes(ENCODING)); } } if (skewed.getSkewedColValues() != null) { SortedSet<String> sortedOuterList = new TreeSet<>(); for (List<String> innerList : skewed.getSkewedColValues()) { SortedSet<String> sortedInnerList = new TreeSet<>(innerList); sortedOuterList.add(org.apache.commons.lang.StringUtils.join(sortedInnerList, ".")); } for (String colval : sortedOuterList) { md.update(colval.getBytes(ENCODING)); } } if (skewed.getSkewedColValueLocationMaps() != null) { SortedMap<String, String> sortedMap = new TreeMap<>(); for (Map.Entry<List<String>, String> smap : skewed.getSkewedColValueLocationMaps().entrySet()) { SortedSet<String> sortedKey = new TreeSet<>(smap.getKey()); sortedMap.put(org.apache.commons.lang.StringUtils.join(sortedKey, "."), smap.getValue()); } for (Map.Entry<String, String> e : sortedMap.entrySet()) { md.update(e.getKey().getBytes(ENCODING)); md.update(e.getValue().getBytes(ENCODING)); } } md.update(sd.isStoredAsSubDirectories() ? "true".getBytes(ENCODING) : "false".getBytes(ENCODING)); } return md.digest(); }
From source file:com.espertech.esper.filter.FilterParamIndexDoubleRange.java
public final void matchEvent(EventBean theEvent, Collection<FilterHandle> matches) { Object objAttributeValue = lookupable.getGetter().get(theEvent); if (objAttributeValue == null) { return;// w w w .ja v a 2 s. c o m } double attributeValue = ((Number) objAttributeValue).doubleValue(); DoubleRange rangeStart = new DoubleRange(attributeValue - largestRangeValueDouble, attributeValue); DoubleRange rangeEnd = new DoubleRange(attributeValue, Double.MAX_VALUE); SortedMap<DoubleRange, EventEvaluator> subMap = ranges.subMap(rangeStart, rangeEnd); // For not including either endpoint // A bit awkward to duplicate the loop code, however better than checking the boolean many times over // This may be a bit of an early performance optimization - the optimizer after all may do this better if (this.getFilterOperator() == FilterOperator.RANGE_OPEN) // include neither endpoint { for (Map.Entry<DoubleRange, EventEvaluator> entry : subMap.entrySet()) { if ((attributeValue > entry.getKey().getMin()) && (attributeValue < entry.getKey().getMax())) { entry.getValue().matchEvent(theEvent, matches); } } } else if (this.getFilterOperator() == FilterOperator.RANGE_CLOSED) // include all endpoints { for (Map.Entry<DoubleRange, EventEvaluator> entry : subMap.entrySet()) { if ((attributeValue >= entry.getKey().getMin()) && (attributeValue <= entry.getKey().getMax())) { entry.getValue().matchEvent(theEvent, matches); } } } else if (this.getFilterOperator() == FilterOperator.RANGE_HALF_CLOSED) // include high endpoint not low endpoint { for (Map.Entry<DoubleRange, EventEvaluator> entry : subMap.entrySet()) { if ((attributeValue > entry.getKey().getMin()) && (attributeValue <= entry.getKey().getMax())) { entry.getValue().matchEvent(theEvent, matches); } } } else if (this.getFilterOperator() == FilterOperator.RANGE_HALF_OPEN) // include low endpoint not high endpoint { for (Map.Entry<DoubleRange, EventEvaluator> entry : subMap.entrySet()) { if ((attributeValue >= entry.getKey().getMin()) && (attributeValue < entry.getKey().getMax())) { entry.getValue().matchEvent(theEvent, matches); } } } else { throw new IllegalStateException("Invalid filter operator " + this.getFilterOperator()); } }
From source file:com.splicemachine.derby.utils.SpliceAdmin.java
public static void SYSCS_GET_REGION_SERVER_CONFIG_INFO(final String configRoot, final int showDisagreementsOnly, final ResultSet[] resultSet) throws StandardException, SQLException { Map<String, DatabaseVersion> dbVersions = EngineDriver.driver().dbAdministrator() .getClusterDatabaseVersions(); boolean matchName = (configRoot != null && !configRoot.equals("")); int hostIdx = 0; String hostName;/*from w w w .j av a 2 s .co m*/ ResultSetBuilder rsBuilder; RowBuilder rowBuilder; try { rsBuilder = new ResultSetBuilder(); rsBuilder.getColumnBuilder().addColumn("HOST_NAME", Types.VARCHAR, 32) .addColumn("CONFIG_NAME", Types.VARCHAR, 128).addColumn("CONFIG_VALUE", Types.VARCHAR, 128); rowBuilder = rsBuilder.getRowBuilder(); // We arbitrarily pick DatabaseVersion MBean even though // we do not fetch anything from it. We just use it as our // mechanism for our region server context. SortedMap<String, String> configMap = new TreeMap<>(); SConfiguration config = EngineDriver.driver().getConfiguration(); Map<String, Object> configRootMap = config.getConfigMap(); for (Map.Entry<String, DatabaseVersion> databaseVersion : dbVersions.entrySet()) { hostName = databaseVersion.getKey(); configMap.clear(); for (Map.Entry<String, Object> conf : configRootMap.entrySet()) { configMap.put(conf.getKey(), conf.getValue().toString()); } // Iterate through sorted configs and add to result set Set<Entry<String, String>> configSet = configMap.entrySet(); for (Entry<String, String> configEntry : configSet) { rowBuilder.getDvd(0).setValue(hostName); rowBuilder.getDvd(1).setValue(configEntry.getKey()); rowBuilder.getDvd(2).setValue(configEntry.getValue()); rowBuilder.addRow(); } hostIdx++; } resultSet[0] = rsBuilder.buildResultSet((EmbedConnection) getDefaultConn()); configMap.clear(); } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } }
From source file:com.ngdata.hbaseindexer.mr.HBaseIndexerMapper.java
private void copyIndexingMetricsToCounters(Context context) { final String COUNTER_GROUP = "HBase Indexer Metrics"; SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics = Metrics.defaultRegistry() .groupedMetrics(new IndexerMetricsUtil.IndexerMetricPredicate()); for (Entry<String, SortedMap<MetricName, Metric>> metricsGroupEntry : groupedMetrics.entrySet()) { SortedMap<MetricName, Metric> metricsGroupMap = metricsGroupEntry.getValue(); for (Entry<MetricName, Metric> metricEntry : metricsGroupMap.entrySet()) { MetricName metricName = metricEntry.getKey(); Metric metric = metricEntry.getValue(); String counterName = metricName.getType() + ": " + metricName.getName(); if (metric instanceof Counter) { Counter counter = (Counter) metric; context.getCounter(COUNTER_GROUP, counterName).increment(counter.count()); } else if (metric instanceof Meter) { Meter meter = (Meter) metric; context.getCounter(COUNTER_GROUP, counterName).increment(meter.count()); } else if (metric instanceof Timer) { Timer timer = (Timer) metric; context.getCounter(COUNTER_GROUP, counterName).increment((long) timer.sum()); }/*from w w w.ja v a 2 s. com*/ } } }
From source file:org.hk.jt.client.core.Request.java
private String getRequestParameters() throws UnsupportedEncodingException { SortedMap<String, String> map = authParameter; if (postParameter != null && postParameter.size() > 0) { for (Map.Entry<String, String> param : postParameter.entrySet()) { map.put(param.getKey(), encodeURL(param.getValue())); }// ww w .jav a 2 s .c om } StringBuilder builder = new StringBuilder(); for (Map.Entry<String, String> param : map.entrySet()) { builder.append(param.getKey()); builder.append("="); builder.append(param.getValue()); builder.append("&"); } String parameters = builder.toString(); if (parameters != null && parameters.length() != 0) { parameters = builder.toString().substring(0, builder.length() - 1); } return parameters; }
From source file:cn.ctyun.amazonaws.auth.AWS3Signer.java
protected String getCanonicalizedHeadersForStringToSign(Request<?> request) { List<String> headersToSign = getHeadersForStringToSign(request); for (int i = 0; i < headersToSign.size(); i++) { headersToSign.set(i, headersToSign.get(i).toLowerCase()); }//ww w. ja va 2 s. c o m SortedMap<String, String> sortedHeaderMap = new TreeMap<String, String>(); for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) { if (headersToSign.contains(entry.getKey().toLowerCase())) { sortedHeaderMap.put(entry.getKey().toLowerCase(), entry.getValue()); } } StringBuilder builder = new StringBuilder(); for (Map.Entry<String, String> entry : sortedHeaderMap.entrySet()) { builder.append(entry.getKey().toLowerCase()).append(":").append(entry.getValue()).append("\n"); } return builder.toString(); }