org.javasimon.source
Class CachedMonitorSource<L,M extends Simon,K>

java.lang.Object
  extended by org.javasimon.source.CachedMonitorSource<L,M,K>
Type Parameters:
L - Location/invocation context
M - Simon type
K - Location key
All Implemented Interfaces:
MonitorSource<L,M>
Direct Known Subclasses:
CachedStopwatchSource

public abstract class CachedMonitorSource<L,M extends Simon,K>
extends Object
implements MonitorSource<L,M>

Monitor source playing the role of cache for delegate monitor source.

Author:
gquintana

Nested Class Summary
private static class CachedMonitorSource.MonitorInformation
          Monitor/location information.
 
Field Summary
private  MonitorSource<L,M> delegate
          Real monitor source.
private  Map<K,CachedMonitorSource.MonitorInformation> monitorInformations
          Map location key → monitor information.
private static CachedMonitorSource.MonitorInformation NULL_MONITOR_INFORMATION
          Not monitored monitor information.
 
Constructor Summary
CachedMonitorSource(MonitorSource<L,M> delegate)
          Constructor with real MonitorSource.
 
Method Summary
protected abstract  K getLocationKey(L location)
          Get location for given location.
 Manager getManager()
          Returns the Manager used as a real source of monitors.
 M getMonitor(L location)
          Get Simon for the specified location.
private  CachedMonitorSource.MonitorInformation getMonitorInformation(L location)
          Get monitor information for given location.
private  M getMonitorOnce(L location)
           
 boolean isMonitored(L location)
          Check whether location should be monitored.
private  void removeMonitorInformation(L location)
          Remove monitor information for given location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

delegate

private final MonitorSource<L,M extends Simon> delegate
Real monitor source.


NULL_MONITOR_INFORMATION

private static final CachedMonitorSource.MonitorInformation NULL_MONITOR_INFORMATION
Not monitored monitor information.


monitorInformations

private final Map<K,CachedMonitorSource.MonitorInformation> monitorInformations
Map location key → monitor information.

Constructor Detail

CachedMonitorSource

public CachedMonitorSource(MonitorSource<L,M> delegate)
Constructor with real MonitorSource.

Parameters:
delegate - Delegate provider monitors for real
Method Detail

getLocationKey

protected abstract K getLocationKey(L location)
Get location for given location.


getMonitorInformation

private CachedMonitorSource.MonitorInformation getMonitorInformation(L location)
Get monitor information for given location. First monitor information is looked up in cache. Then, when not found, delegate is called.

Parameters:
location - Location
Returns:
Monitor information

removeMonitorInformation

private void removeMonitorInformation(L location)
Remove monitor information for given location.


isMonitored

public boolean isMonitored(L location)
Check whether location should be monitored. Response is entirely based on cache

Specified by:
isMonitored in interface MonitorSource<L,M extends Simon>
Parameters:
location - Location
Returns:
true means monitored

getMonitorOnce

private M getMonitorOnce(L location)

getMonitor

public M getMonitor(L location)
Get Simon for the specified location. Simon is retrieved from name in cache.

Specified by:
getMonitor in interface MonitorSource<L,M extends Simon>
Parameters:
location - Location
Returns:
Simon for the specified location

getManager

public Manager getManager()
Description copied from interface: MonitorSource
Returns the Manager used as a real source of monitors.

Specified by:
getManager in interface MonitorSource<L,M extends Simon>
Returns:
Manager to get the monitors from


Copyright © 2013. All Rights Reserved.