Package org.terracotta.statistics
Class StatisticMapper<SOURCE extends java.lang.Enum<SOURCE>,TARGET extends java.lang.Enum<TARGET>>
- java.lang.Object
-
- org.terracotta.statistics.StatisticMapper<SOURCE,TARGET>
-
- All Implemented Interfaces:
OperationObserver<TARGET>,OperationStatistic<TARGET>,SourceStatistic<ChainedOperationObserver<? super TARGET>>
public class StatisticMapper<SOURCE extends java.lang.Enum<SOURCE>,TARGET extends java.lang.Enum<TARGET>> extends java.lang.Object implements OperationStatistic<TARGET>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ConcurrentMap<ChainedOperationObserver<? super TARGET>,ChainedOperationObserver<SOURCE>>derivedStatsprivate java.util.Map<SOURCE,TARGET>reverseTranslationprivate java.lang.Class<SOURCE>sourceTypeprivate OperationStatistic<SOURCE>statisticprivate java.lang.Class<TARGET>targetTypeprivate java.util.Map<TARGET,java.util.Set<SOURCE>>translation
-
Constructor Summary
Constructors Constructor Description StatisticMapper(java.util.Map<TARGET,java.util.Set<SOURCE>> translation, OperationStatistic<SOURCE> statistic)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDerivedStatistic(ChainedOperationObserver<? super TARGET> derived)Register the givenObserverto be called by thisSourceStatisticvoidbegin()Called immediately prior to the operation beginning.longcount(TARGET type)Return the count of operations with the given type.voidend(TARGET result)Called immediately after the operation completes with no interesting parameters, and with the same thread the called {OperationObserver.begin()} before.java.util.Collection<ChainedOperationObserver<? super TARGET>>getDerivedStatistics()Retrieve all registered statistics.voidremoveDerivedStatistic(ChainedOperationObserver<? super TARGET> derived)Remove the given registeredObserverfrom thisSourceStatistic.private static <B extends java.lang.Enum<B>,A extends java.lang.Enum<A>>
java.util.Map<B,A>reverse(java.util.Map<A,java.util.Set<B>> map)ValueStatistic<java.lang.Long>statistic(java.util.Set<TARGET> results)ValueStatistic<java.lang.Long>statistic(TARGET result)Return aValueStatisticreturning the count for the given result.longsum()longsum(java.util.Set<TARGET> types)java.lang.Class<TARGET>type()
-
-
-
Field Detail
-
statistic
private final OperationStatistic<SOURCE extends java.lang.Enum<SOURCE>> statistic
-
translation
private final java.util.Map<TARGET extends java.lang.Enum<TARGET>,java.util.Set<SOURCE extends java.lang.Enum<SOURCE>>> translation
-
reverseTranslation
private final java.util.Map<SOURCE extends java.lang.Enum<SOURCE>,TARGET extends java.lang.Enum<TARGET>> reverseTranslation
-
derivedStats
private final java.util.concurrent.ConcurrentMap<ChainedOperationObserver<? super TARGET extends java.lang.Enum<TARGET>>,ChainedOperationObserver<SOURCE extends java.lang.Enum<SOURCE>>> derivedStats
-
-
Constructor Detail
-
StatisticMapper
public StatisticMapper(java.util.Map<TARGET,java.util.Set<SOURCE>> translation, OperationStatistic<SOURCE> statistic)
-
-
Method Detail
-
reverse
private static <B extends java.lang.Enum<B>,A extends java.lang.Enum<A>> java.util.Map<B,A> reverse(java.util.Map<A,java.util.Set<B>> map)
-
type
public java.lang.Class<TARGET> type()
- Specified by:
typein interfaceOperationStatistic<SOURCE extends java.lang.Enum<SOURCE>>
-
statistic
public ValueStatistic<java.lang.Long> statistic(TARGET result)
Description copied from interface:OperationStatisticReturn aValueStatisticreturning the count for the given result.- Specified by:
statisticin interfaceOperationStatistic<SOURCE extends java.lang.Enum<SOURCE>>- Parameters:
result- the result of interest- Returns:
- a
ValueStatisticinstance
-
statistic
public ValueStatistic<java.lang.Long> statistic(java.util.Set<TARGET> results)
- Specified by:
statisticin interfaceOperationStatistic<SOURCE extends java.lang.Enum<SOURCE>>
-
count
public long count(TARGET type)
Description copied from interface:OperationStatisticReturn the count of operations with the given type.- Specified by:
countin interfaceOperationStatistic<SOURCE extends java.lang.Enum<SOURCE>>- Parameters:
type- the result type- Returns:
- the operation count
-
sum
public long sum(java.util.Set<TARGET> types)
- Specified by:
sumin interfaceOperationStatistic<SOURCE extends java.lang.Enum<SOURCE>>
-
sum
public long sum()
- Specified by:
sumin interfaceOperationStatistic<SOURCE extends java.lang.Enum<SOURCE>>
-
addDerivedStatistic
public void addDerivedStatistic(ChainedOperationObserver<? super TARGET> derived)
Description copied from interface:SourceStatisticRegister the givenObserverto be called by thisSourceStatistic- Specified by:
addDerivedStatisticin interfaceSourceStatistic<SOURCE extends java.lang.Enum<SOURCE>>- Parameters:
derived- statistic to be registered
-
removeDerivedStatistic
public void removeDerivedStatistic(ChainedOperationObserver<? super TARGET> derived)
Description copied from interface:SourceStatisticRemove the given registeredObserverfrom thisSourceStatistic.- Specified by:
removeDerivedStatisticin interfaceSourceStatistic<SOURCE extends java.lang.Enum<SOURCE>>- Parameters:
derived- statistic to be removed
-
getDerivedStatistics
public java.util.Collection<ChainedOperationObserver<? super TARGET>> getDerivedStatistics()
Description copied from interface:SourceStatisticRetrieve all registered statistics.- Specified by:
getDerivedStatisticsin interfaceSourceStatistic<SOURCE extends java.lang.Enum<SOURCE>>- Returns:
- an unmodifiable collection of all derived statistics
-
begin
public void begin()
Description copied from interface:OperationObserverCalled immediately prior to the operation beginning.- Specified by:
beginin interfaceOperationObserver<SOURCE extends java.lang.Enum<SOURCE>>
-
end
public void end(TARGET result)
Description copied from interface:OperationObserverCalled immediately after the operation completes with no interesting parameters, and with the same thread the called {OperationObserver.begin()} before.- Specified by:
endin interfaceOperationObserver<SOURCE extends java.lang.Enum<SOURCE>>- Parameters:
result- the operation result
-
-