Expose setter for Map store in InMemoryMetricRepository

User can then use a weak reference map (for instance), if worried
about memory usage.
pull/408/merge
Dave Syer 11 years ago
parent 29982f5946
commit 82f49abeba

@ -20,6 +20,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.concurrent.ConcurrentNavigableMap;
import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.boot.actuate.metrics.reader.PrefixMetricReader; 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>(); private final Collection<String> groups = new HashSet<String>();
public void setValues(ConcurrentNavigableMap<String, Metric<?>> values) {
this.metrics.setValues(values);
}
@Override @Override
public void increment(Delta<?> delta) { public void increment(Delta<?> delta) {
final String metricName = delta.getName(); final String metricName = delta.getName();

@ -18,11 +18,12 @@ package org.springframework.boot.actuate.metrics.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.NavigableMap; import java.util.NavigableMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListMap;
import org.springframework.util.ConcurrentReferenceHashMap;
/** /**
* Repository utility that stores stuff in memory with period-separated String keys. * 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> { 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> { public static interface Callback<T> {
T modify(T current); T modify(T current);
@ -96,6 +97,10 @@ public class SimpleInMemoryRepository<T> {
.values()); .values());
} }
public void setValues(ConcurrentNavigableMap<String, T> values) {
this.values = values;
}
protected NavigableMap<String, T> getValues() { protected NavigableMap<String, T> getValues() {
return this.values; return this.values;
} }

Loading…
Cancel
Save