Expose setter for Map store in InMemoryMetricRepository
User can then use a weak reference map (for instance), if worried about memory usage.
This commit is contained in:
@@ -20,6 +20,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.ConcurrentNavigableMap;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.actuate.metrics.reader.PrefixMetricReader;
|
||||
@@ -40,6 +41,10 @@ public class InMemoryMetricRepository implements MetricRepository, MultiMetricRe
|
||||
|
||||
private final Collection<String> groups = new HashSet<String>();
|
||||
|
||||
public void setValues(ConcurrentNavigableMap<String, Metric<?>> values) {
|
||||
this.metrics.setValues(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increment(Delta<?> delta) {
|
||||
final String metricName = delta.getName();
|
||||
|
||||
@@ -18,11 +18,12 @@ package org.springframework.boot.actuate.metrics.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ConcurrentNavigableMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||
|
||||
/**
|
||||
* Repository utility that stores stuff in memory with period-separated String keys.
|
||||
*
|
||||
@@ -30,9 +31,9 @@ import java.util.concurrent.ConcurrentSkipListMap;
|
||||
*/
|
||||
public class SimpleInMemoryRepository<T> {
|
||||
|
||||
private final ConcurrentNavigableMap<String, T> values = new ConcurrentSkipListMap<String, T>();
|
||||
private ConcurrentNavigableMap<String, T> values = new ConcurrentSkipListMap<String, T>();
|
||||
|
||||
private final ConcurrentMap<String, Object> locks = new ConcurrentHashMap<String, Object>();
|
||||
private final ConcurrentMap<String, Object> locks = new ConcurrentReferenceHashMap<String, Object>();
|
||||
|
||||
public static interface Callback<T> {
|
||||
T modify(T current);
|
||||
@@ -96,6 +97,10 @@ public class SimpleInMemoryRepository<T> {
|
||||
.values());
|
||||
}
|
||||
|
||||
public void setValues(ConcurrentNavigableMap<String, T> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
protected NavigableMap<String, T> getValues() {
|
||||
return this.values;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user