Skip to content
Browse files

Remove metrics-guava.

CacheBuilder isn't as extensible as I'd like, so it doesn't offer much of a benefit.
  • Loading branch information...
1 parent ae81fcb commit 7619f1f132be3aa1caada29c61ef2308862073f9 @codahale codahale committed Jan 4, 2012
View
1 CHANGELOG.md
@@ -35,7 +35,6 @@ v2.0.0-BETA19: TBD
* Changed `MetricsRegistry#createName` to `protected`.
* All metric types are created exclusively through `MetricsRegistry` now.
* `Metrics.newJmxGauge` and `MetricsRegistry.newJmxGauge` are deprecated.
-* Added `metrics-guava`, which allows you to measure cache misses and evictions.
* Fixed heap metrics in `VirtualMachineMetrics`.
* Added `Snapshot`, which calculates quantiles.
* Renamed `Percentiled` to `Sampling` and dropped `percentile` and `percentiles` in favor of
View
31 metrics-guava/pom.xml
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>com.yammer.metrics</groupId>
- <artifactId>metrics-parent</artifactId>
- <version>2.0.0-BETA19-SNAPSHOT</version>
- </parent>
-
- <artifactId>metrics-guava</artifactId>
- <name>Metrics for Guava</name>
- <description>
- Metrics support for Guava, Google's Java library.
- </description>
-
- <dependencies>
- <dependency>
- <groupId>com.yammer.metrics</groupId>
- <artifactId>metrics-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>11.0</version>
- </dependency>
- </dependencies>
-</project>
View
50 metrics-guava/src/main/java/com/yammer/metrics/guava/InstrumentedCacheLoader.java
@@ -1,50 +0,0 @@
-package com.yammer.metrics.guava;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheLoader;
-import com.yammer.metrics.core.Meter;
-import com.yammer.metrics.core.MetricsRegistry;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * An instrumented {@link CacheLoader} implementation which records the number and rate of cache
- * misses.
- *
- * @param <K> the type of keys in the cache
- * @param <V> the type of values in the cache
- */
-public class InstrumentedCacheLoader<K, V> extends CacheLoader<K, V> {
- /**
- * Instruments an existing {@link CacheLoader}.
- *
- * @param registry a {@link MetricsRegistry}
- * @param loader an existing {@link CacheLoader}
- * @param cacheName the name of the cache
- * @param rateUnit the rate unit to measure misses in
- * @param <K> the type of keys in the cache
- * @param <V> the type of values in the cache
- * @return an instrumented decorator for {@code loader}
- */
- public static <K, V> CacheLoader<K, V> instrument(MetricsRegistry registry,
- CacheLoader<K, V> loader,
- String cacheName,
- TimeUnit rateUnit) {
- final Meter cacheMisses = registry.newMeter(Cache.class, "cache-misses", cacheName, "misses", rateUnit);
- return new InstrumentedCacheLoader<K, V>(loader, cacheMisses);
- }
-
- private final CacheLoader<K, V> loader;
- private final Meter cacheMisses;
-
- private InstrumentedCacheLoader(CacheLoader<K, V> loader, Meter cacheMisses) {
- this.loader = loader;
- this.cacheMisses = cacheMisses;
- }
-
- @Override
- public V load(K key) throws Exception {
- cacheMisses.mark();
- return loader.load(key);
- }
-}
View
44 metrics-guava/src/main/java/com/yammer/metrics/guava/InstrumentedRemovalListener.java
@@ -1,44 +0,0 @@
-package com.yammer.metrics.guava;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
-import com.yammer.metrics.core.Meter;
-import com.yammer.metrics.core.MetricsRegistry;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * An instrumented {@link RemovalListener} implementation which records the number and rate of cache
- * evictions.
- *
- * @param <K> the type of keys in the cache
- * @param <V> the type of values in the cache
- */
-public class InstrumentedRemovalListener<K, V> implements RemovalListener<K, V> {
- /**
- * Returns a {@link RemovalListener} which measures cache evictions.
- *
- * @param registry a {@link MetricsRegistry}
- * @param cacheName the name of the cache
- * @param rateUnit the rate unit to measure misses in
- * @param <K> the type of keys in the cache
- * @param <V> the type of values in the cache
- * @return an instrumented {@link RemovalListener}
- */
- public static <K, V> RemovalListener<K, V> newListener(MetricsRegistry registry, String cacheName, TimeUnit rateUnit) {
- final Meter evictions = registry.newMeter(Cache.class, "cache-evictions", cacheName, "evictions", rateUnit);
- return new InstrumentedRemovalListener<K, V>(evictions);
- }
-
- private final Meter meter;
-
- private InstrumentedRemovalListener(Meter meter) {
- this.meter = meter;
- }
-
- @Override
- public void onRemoval(RemovalNotification<K, V> notification) {
- meter.mark();
- }
-}
View
60 metrics-guava/src/test/java/com/yammer/metrics/guava/tests/InstrumentedCacheLoaderTest.java
@@ -1,60 +0,0 @@
-package com.yammer.metrics.guava.tests;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-import com.yammer.metrics.core.Meter;
-import com.yammer.metrics.core.MetricsRegistry;
-import com.yammer.metrics.guava.InstrumentedCacheLoader;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.concurrent.TimeUnit;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class InstrumentedCacheLoaderTest {
- private MetricsRegistry registry;
- private LoadingCache<String, String> cache;
-
- @Before
- @SuppressWarnings("unchecked")
- public void setUp() throws Exception {
- this.registry = new MetricsRegistry();
-
- final CacheLoader<String, String> loader = mock(CacheLoader.class);
- when(loader.load(anyString())).thenReturn("woo");
-
- this.cache = CacheBuilder.newBuilder().build(
- InstrumentedCacheLoader.instrument(registry, loader, "cache", TimeUnit.SECONDS)
- );
- }
-
- @After
- public void tearDown() throws Exception {
- registry.shutdown();
- }
-
- @Test
- public void marksCacheMissesViaAMeter() throws Exception {
- final Meter meter = registry.newMeter(Cache.class,
- "cache-misses",
- "cache",
- "misses",
- TimeUnit.SECONDS);
-
- cache.get("one");
- cache.get("one");
- cache.get("two");
- cache.get("two");
-
- assertThat(meter.count(),
- is(2L));
- }
-}
View
48 ...s-guava/src/test/java/com/yammer/metrics/guava/tests/InstrumentedRemovalListenerTest.java
@@ -1,48 +0,0 @@
-package com.yammer.metrics.guava.tests;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.RemovalListener;
-import com.yammer.metrics.core.Meter;
-import com.yammer.metrics.core.MetricsRegistry;
-import com.yammer.metrics.guava.InstrumentedRemovalListener;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.concurrent.TimeUnit;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-public class InstrumentedRemovalListenerTest {
- private MetricsRegistry registry;
-
- private RemovalListener<String, String> listener;
-
- @Before
- public void setUp() throws Exception {
- this.registry = new MetricsRegistry();
-
- this.listener = InstrumentedRemovalListener.newListener(registry, "cache", TimeUnit.SECONDS);
- }
-
- @After
- public void tearDown() throws Exception {
- registry.shutdown();
- }
-
- @Test
- public void measureEvictions() throws Exception {
- final Meter meter = registry.newMeter(Cache.class,
- "cache-evictions",
- "cache",
- "evictions",
- TimeUnit.SECONDS);
-
- listener.onRemoval(null);
- listener.onRemoval(null);
-
- assertThat(meter.count(),
- is(2L));
- }
-}
View
1 pom.xml
@@ -19,7 +19,6 @@
<module>metrics-ehcache</module>
<module>metrics-ganglia</module>
<module>metrics-graphite</module>
- <module>metrics-guava</module>
<module>metrics-guice</module>
<module>metrics-httpclient</module>
<module>metrics-jdbi</module>

0 comments on commit 7619f1f

Please sign in to comment.
Something went wrong with that request. Please try again.