Skip to content

Commit

Permalink
Use new StatisticsService to send stats to collector (close #1684)
Browse files Browse the repository at this point in the history
  • Loading branch information
henri-tremblay committed Jan 11, 2017
1 parent 5f3a062 commit e2ec7cc
Show file tree
Hide file tree
Showing 18 changed files with 1,292 additions and 417 deletions.
Expand Up @@ -16,6 +16,7 @@
package org.ehcache.jsr107;

import org.ehcache.core.spi.service.StatisticsService;
import org.ehcache.core.statistics.CacheStatistics;

import java.net.URI;

Expand All @@ -35,62 +36,65 @@ class Eh107CacheStatisticsMXBean extends Eh107MXBean implements javax.cache.mana

@Override
public void clear() {
statisticsService.clear(cacheName);
getCacheStatistics().clear();
}

@Override
public long getCacheHits() {
return statisticsService.getCacheHits(cacheName);
return getCacheStatistics().getCacheHits();
}

@Override
public float getCacheHitPercentage() {
return statisticsService.getCacheHitPercentage(cacheName);
return getCacheStatistics().getCacheHitPercentage();
}

@Override
public long getCacheMisses() {
return statisticsService.getCacheMisses(cacheName);
return getCacheStatistics().getCacheMisses();
}

@Override
public float getCacheMissPercentage() {
return statisticsService.getCacheMissPercentage(cacheName);
return getCacheStatistics().getCacheMissPercentage();
}

@Override
public long getCacheGets() {
return statisticsService.getCacheGets(cacheName);
return getCacheStatistics().getCacheGets();
}

@Override
public long getCachePuts() {
return statisticsService.getCachePuts(cacheName);
return getCacheStatistics().getCachePuts();
}

@Override
public long getCacheRemovals() {
return statisticsService.getCacheRemovals(cacheName);
return getCacheStatistics().getCacheRemovals();
}

@Override
public long getCacheEvictions() {
return statisticsService.getCacheEvictions(cacheName);
return getCacheStatistics().getCacheEvictions();
}

@Override
public float getAverageGetTime() {
return statisticsService.getAverageGetTime(cacheName);
return getCacheStatistics().getCacheAverageGetTime();
}

@Override
public float getAveragePutTime() {
return statisticsService.getAveragePutTime(cacheName);
return getCacheStatistics().getCacheAveragePutTime();
}

@Override
public float getAverageRemoveTime() {
return statisticsService.getAverageRemoveTime(cacheName);
return getCacheStatistics().getCacheAverageRemoveTime();
}

private CacheStatistics getCacheStatistics() {
return statisticsService.getCacheStatistics(cacheName);
}
}
12 changes: 8 additions & 4 deletions 107/src/main/java/org/ehcache/jsr107/EhcacheCachingProvider.java
Expand Up @@ -136,16 +136,20 @@ Eh107CacheManager getCacheManager(ConfigSupplier configSupplier, Properties prop

private Eh107CacheManager createCacheManager(URI uri, Configuration config, Properties properties) {
Eh107CacheLoaderWriterProvider cacheLoaderWriterFactory = new Eh107CacheLoaderWriterProvider();
Jsr107Service jsr107Service = new DefaultJsr107Service(ServiceLocator.findSingletonAmongst(Jsr107Configuration.class, config.getServiceCreationConfigurations().toArray()));

StatisticsService statisticsService = new DefaultStatisticsService();
Object[] serviceCreationConfigurations = config.getServiceCreationConfigurations().toArray();

Jsr107Service jsr107Service = new DefaultJsr107Service(ServiceLocator.findSingletonAmongst(Jsr107Configuration.class, serviceCreationConfigurations));

Collection<Service> services = new ArrayList<Service>(4);
services.add(cacheLoaderWriterFactory);
services.add(jsr107Service);
services.add(statisticsService);

if (ServiceLocator.findSingletonAmongst(DefaultSerializationProviderConfiguration.class, config.getServiceCreationConfigurations().toArray()) == null) {
if(ServiceLocator.findSingletonAmongst(StatisticsService.class, serviceCreationConfigurations) == null) {
services.add(new DefaultStatisticsService());
}

if (ServiceLocator.findSingletonAmongst(DefaultSerializationProviderConfiguration.class, serviceCreationConfigurations) == null) {
services.add(new DefaultJsr107SerializationProvider());
}

Expand Down

Large diffs are not rendered by default.

Expand Up @@ -16,36 +16,13 @@

package org.ehcache.core.spi.service;

import org.ehcache.core.statistics.CacheStatistics;
import org.ehcache.spi.service.Service;

/**
* Service providing raw statistics for cache and tier usage.
*
* @author Henri Tremblay
*/
public interface StatisticsService extends Service {

void clear(String cacheName);

long getCacheHits(String cacheName);

float getCacheHitPercentage(String cacheName);

long getCacheMisses(String cacheName);

float getCacheMissPercentage(String cacheName);

long getCacheGets(String cacheName);

long getCachePuts(String cacheName);

long getCacheRemovals(String cacheName);

long getCacheEvictions(String cacheName);

float getAverageGetTime(String cacheName);

float getAveragePutTime(String cacheName);

float getAverageRemoveTime(String cacheName);
CacheStatistics getCacheStatistics(String cacheName);
}
@@ -0,0 +1,60 @@
/*
* Copyright Terracotta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ehcache.core.statistics;

import java.util.Map;

/**
* All statistics relative to a cache and its underlying tiers.
*
* @author Henri Tremblay
*/
public interface CacheStatistics {

Map<String, TypedValueStatistic> getKnownStatistics();

/**
* Reset the values for this cache and its underlying tiers.
* <p>
* <b>Implementation note:</b> Calling clear doesn't really clear the data. It freezes the actual values and compensate
* for them when returning a result.
*/
void clear();

long getCacheHits();

float getCacheHitPercentage();

long getCacheMisses();

float getCacheMissPercentage();

long getCacheGets();

long getCachePuts();

long getCacheRemovals();

long getCacheEvictions();

float getCacheAverageGetTime();

float getCacheAveragePutTime();

float getCacheAverageRemoveTime();

}
50 changes: 50 additions & 0 deletions core/src/main/java/org/ehcache/core/statistics/TierStatistics.java
@@ -0,0 +1,50 @@
/*
* Copyright Terracotta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ehcache.core.statistics;

import java.util.Map;

/**
* All statistics relative to a tier
*/
public interface TierStatistics {

Map<String, TypedValueStatistic> getKnownStatistics();

/**
* Reset the values for this tier. However, note that {@code mapping, maxMappings, allocatedMemory, occupiedMemory}
* but be reset since it doesn't make sense.
* <p>
* <b>Implementation note:</b> Calling clear doesn't really clear the data. It freezes the actual values and compensate
* for them when returning a result.
*/
void clear();

long getHits();

long getMisses();

long getEvictions();

long getMappings();

long getMaxMappings();

long getAllocatedByteSize();

long getOccupiedByteSize();
}
@@ -0,0 +1,40 @@
/*
* Copyright Terracotta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ehcache.core.statistics;

import org.terracotta.statistics.ValueStatistic;
import org.terracotta.statistics.extended.StatisticType;

/**
* Represent a {@code ValueStatistic} that knows its {@code StatisticType}.
*/
public abstract class TypedValueStatistic implements ValueStatistic<Number> {
private final StatisticType type;

/**
* Type of this value statistic. Can be COUNTER or SIZE.
*
* @param type {@code StatisticType}
*/
public TypedValueStatistic(StatisticType type) {
this.type = type;
}

public StatisticType getType() {
return type;
}
}

0 comments on commit e2ec7cc

Please sign in to comment.