public class DefaultInstrumentRegistry extends Object implements InstrumentRegistry
Instrument's.
It can create new Instrument objects directly via is pull() methods. This makes it easier to manage the
creation of performance statistics.
Names of instruments MUST be unique. For example you cannot have a Counter and a Gauge with the same
name. If an Instrument exists with the a specified name and its not of the requested type, then an
IllegalStateException will be thrown.
THREAD SAFETY : ConcurrentHashMap is used under the covers to ensure that @{link Instrument}s are created once and only once.
| Constructor and Description |
|---|
DefaultInstrumentRegistry()
Creates a default implementation that uses a
SimpleOpTimerFactory |
DefaultInstrumentRegistry(OpTimerFactory opTimerFactory,
RegistryConfiguration registryConfiguration)
Creates an implementation that used the passed in OpTimerFactory
|
| Modifier and Type | Method and Description |
|---|---|
Instrument |
getInstrument(String name)
Returns an
Instrument from the registry with the specified name |
int |
getNumberOfInstruments()
Returns the number of instruments that exist.
|
RegistryConfiguration |
getRegistryConfiguration() |
AbsoluteCounter |
pullAbsoluteCounter(String name)
This is a pull through operation that guarantees to ATOMICALLY create a AbsoluteCounter under the name if its not
present OR return the previously created one if its there.
|
CacheCollector |
pullCacheCollector(String name)
This is a pull through operation that guarantees to ATOMICALLY create a
CacheCounter under the name if its not present
OR return the previously created one if its there. |
CacheCollector |
pullCacheCollector(String name,
CacheCollector.Sizer sizer)
This is a pull through operation that guarantees to ATOMICALLY create a
CacheCollector under the name if its not present
OR return the previously created one if its there. |
CacheCounter |
pullCacheCounter(String name)
This is a pull through operation that guarantees to ATOMICALLY create a
CacheCounter under the name if its not present
OR return the previously created one if its there. |
CacheCounter |
pullCacheCounter(String name,
CacheCounter.Sizer sizer)
This is a pull through operation that guarantees to ATOMICALLY create a
CacheCounter under the name if its not present
OR return the previously created one if its there. |
Counter |
pullCounter(String name)
This is a pull through operation that guarantees to ATOMICALLY create a Counter under the name if its not present
OR return the previously created one if its there.
|
DerivedCounter |
pullDerivedCounter(String name)
This is a pull through operation that guarantees to ATOMICALLY create a DerivedCounter under the name if its not
present OR return the previously created one if its there.
|
Gauge |
pullGauge(String name)
This is a pull through operation that guarantees to ATOMICALLY create a Gauge under the name if its not present
OR return the previously created one if its there.
|
OpCounter |
pullOpCounter(String name)
This is a pull through operation that guarantees to ATOMICALLY create an
OpCounter under the name if its
not present OR return the previously created one if its there. |
OpTimer |
pullTimer(String name)
This is a pull through operation that guarantees to ATOMICALLY create a OpCounter under the name if its not
present OR use the previously created one if its there.
|
protected Instrument |
putIfAbsent(String name,
Instrument possiblyNeeded)
This will be called if a
Instrument may be put into the map of known
instruments. |
Instrument |
putInstrument(Instrument instrument)
This will put an
Instrument into the registry, ATOMICALLY overwriting any previous Instrument
value. |
List<Instrument> |
snapshotInstruments()
This returns a snapshot list of
Instrument objects in the InstrumentRegistry at the time the method was
called. |
public DefaultInstrumentRegistry()
SimpleOpTimerFactorypublic DefaultInstrumentRegistry(OpTimerFactory opTimerFactory, RegistryConfiguration registryConfiguration)
opTimerFactory - the factory to useregistryConfiguration - the configuration for the registrypublic RegistryConfiguration getRegistryConfiguration()
getRegistryConfiguration in interface InstrumentRegistrypublic Instrument putInstrument(Instrument instrument)
Instrument into the registry, ATOMICALLY overwriting any previous Instrument
value.putInstrument in interface InstrumentRegistryinstrument - the NON NULL instrument to addpublic Instrument getInstrument(String name)
Instrument from the registry with the specified namegetInstrument in interface InstrumentRegistryname - the name of the Instrument to returnprotected Instrument putIfAbsent(String name, Instrument possiblyNeeded)
Instrument may be put into the map of known
instruments. This follows the ConcurrentMap.putIfAbsent(Object, Object) semanticsname - the name of the instrumentpossiblyNeeded - the possible needed Instrumentpublic AbsoluteCounter pullAbsoluteCounter(String name)
THREAD-SAFE - Uses ConcurrentHashMap under the covers
pullAbsoluteCounter in interface InstrumentRegistryname - the name of the DerivedCounter to pullIllegalArgumentException - if there is already a named Instrument in the registry but is not a
DerivedCounterpublic Counter pullCounter(String name)
THREAD-SAFE - Uses ConcurrentHashMap under the covers
pullCounter in interface InstrumentRegistryname - the name of the Counter to pullIllegalArgumentException - if there is already a named Instrument in the registry but is not a Counterpublic DerivedCounter pullDerivedCounter(String name)
THREAD-SAFE - Uses ConcurrentHashMap under the covers
pullDerivedCounter in interface InstrumentRegistryname - the name of the DerivedCounter to pullIllegalArgumentException - if there is already a named Instrument in the registry but is not a
DerivedCounterpublic Gauge pullGauge(String name)
THREAD-SAFE - Uses ConcurrentHashMap under the covers
pullGauge in interface InstrumentRegistryname - the name of the Gauge to pullIllegalArgumentException - if there is already a named Instrument in the registry but is not a Gaugepublic CacheCollector pullCacheCollector(String name, CacheCollector.Sizer sizer)
InstrumentRegistryCacheCollector under the name if its not present
OR return the previously created one if its there.
THREAD-SAFE - Uses ConcurrentHashMap under the covers
pullCacheCollector in interface InstrumentRegistryname - the name of the CacheCounter to pullsizer - the CacheCollector.Sizer to use that can work out the size of the cachepublic CacheCollector pullCacheCollector(String name)
InstrumentRegistryCacheCounter under the name if its not present
OR return the previously created one if its there.
THREAD-SAFE - Uses ConcurrentHashMap under the covers
pullCacheCollector in interface InstrumentRegistryname - the name of the CacheCounter to pullpublic CacheCounter pullCacheCounter(String name, CacheCounter.Sizer sizer)
InstrumentRegistryCacheCounter under the name if its not present
OR return the previously created one if its there.
THREAD-SAFE - Uses ConcurrentHashMap under the covers
pullCacheCounter in interface InstrumentRegistryname - the name of the CacheCounter to pullsizer - the CacheCounter.Sizer to use that can work out the size of the cachepublic CacheCounter pullCacheCounter(String name)
InstrumentRegistryCacheCounter under the name if its not present
OR return the previously created one if its there.
THREAD-SAFE - Uses ConcurrentHashMap under the covers
pullCacheCounter in interface InstrumentRegistryname - the name of the CacheCounter to pullpublic OpCounter pullOpCounter(String name)
OpCounter under the name if its
not present OR return the previously created one if its there.
THREAD-SAFE - Uses ConcurrentHashMap under the covers
pullOpCounter in interface InstrumentRegistryname - the name of the OpCounter to pullIllegalArgumentException - if there is already a named Instrument in the registry but is not a OpCounterpublic OpTimer pullTimer(String name)
OpTimer.end()
is called, the value of the timer will be placed inside the named OpCounter.
You code can use it something like this
OpTimer timer = registry.pullOpTimer("some.operation");
try {
..
.. do some operation
..
} finally {
opTimer.end()
// and OpCounter will now exist
OpCounter opCounter = (OpCounter) registry.getInstrument("some.operation");
}
THREAD-SAFE - Uses ConcurrentHashMap under the covers
pullTimer in interface InstrumentRegistryname - the name of the OpTimer to pullIllegalArgumentException - if there is already a named Instrument in the registry but is not a OpCounterpublic List<Instrument> snapshotInstruments()
Instrument objects in the InstrumentRegistry at the time the method was
called.
The list is MUTABLE and a copy of the underlying values. So feel free to mutate it by sorting it and filtering it.
snapshotInstruments in interface InstrumentRegistrypublic int getNumberOfInstruments()
InstrumentRegistryInstrumentRegistry.snapshotInstruments().size()
but more efficient.getNumberOfInstruments in interface InstrumentRegistryCopyright © 2016 Atlassian. All rights reserved.