public class MonitorServiceImpl extends java.lang.Object implements MonitorService, EventSubscriber
| Modifier and Type | Class and Description |
|---|---|
protected static class |
MonitorServiceImpl.CacheContainer
A container that holds a cache of monitors of a given type with the related settings and info for that type.
|
protected static class |
MonitorServiceImpl.MonitorItem
A container object that holds a monitor together with the supplier used to generate the monitor.
|
| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.ScheduledExecutorService |
cleanupExecutor |
protected static long |
DEFAULT_CLEANUP_INTERVAL_NANOS |
protected static java.util.Map<java.lang.Class<? extends Monitor>,java.util.function.Supplier<MonitorServiceImpl.CacheContainer>> |
defaultSuppliers |
protected java.util.Map<java.lang.Class<? extends Monitor>,MonitorServiceImpl.CacheContainer> |
monitorCaches |
protected EventPublisher |
publisher |
| Constructor and Description |
|---|
MonitorServiceImpl(EventPublisher publisher) |
MonitorServiceImpl(long cleanupIntervalNanos,
EventPublisher publisher)
Constructs a MonitorServiceImpl instance, subscribes to the given publisher's data access events, and submits a
cleanup thread to supervise submitted monitors.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkMonitors() |
<T extends Monitor> |
get(java.lang.Class<T> monitorClass,
java.lang.Object key)
Gets the monitor stored at the given key.
|
protected void |
handleMonitorError(MonitorServiceImpl.CacheContainer cacheContainer,
java.lang.Object key,
MonitorServiceImpl.MonitorItem errorMonitorItem) |
protected void |
initCleanupThread(long cleanupIntervalNanos) |
void |
processEvent(Event event)
Processes an event.
|
<T extends Monitor> |
registerMonitorTypeIfAbsent(java.lang.Class<T> monitorClass,
long expirationTimeoutNanos,
long heartbeatTimeoutNanos,
java.util.Set<MonitorErrorResponse> errorResponses,
@Nullable java.lang.Class<?> producedDataClass)
Registers a new monitor type with the monitor service.
|
void |
releaseResources()
Releases any resources opened by the monitor service, stops all monitors, and removes all monitors from the monitor
service.
|
<T extends Monitor> |
remove(java.lang.Class<T> monitorClass,
java.lang.Object key)
Removes the monitor stored at the given key.
|
<T extends Monitor> |
runIfAbsent(java.lang.Class<T> monitorClass,
java.lang.Object key,
StorageService storageService,
TelemetryFactory telemetryFactory,
java.lang.String originalUrl,
java.lang.String driverProtocol,
TargetDriverDialect driverDialect,
Dialect dbDialect,
java.util.Properties originalProps,
MonitorInitializer initializer)
Creates and starts the given monitor if it does not already exist and stores it under the given monitor type and
key.
|
<T extends Monitor> |
stopAndRemove(java.lang.Class<T> monitorClass,
java.lang.Object key)
Stops the given monitor and removes it from the monitor service.
|
void |
stopAndRemoveAll()
Stops all monitors and removes them from the monitor service.
|
<T extends Monitor> |
stopAndRemoveMonitors(java.lang.Class<T> monitorClass)
Stops all monitors for the given type and removes them from the monitor service.
|
protected static final long DEFAULT_CLEANUP_INTERVAL_NANOS
protected static final java.util.Map<java.lang.Class<? extends Monitor>,java.util.function.Supplier<MonitorServiceImpl.CacheContainer>> defaultSuppliers
protected final EventPublisher publisher
protected final java.util.Map<java.lang.Class<? extends Monitor>,MonitorServiceImpl.CacheContainer> monitorCaches
protected final java.util.concurrent.ScheduledExecutorService cleanupExecutor
public MonitorServiceImpl(EventPublisher publisher)
public MonitorServiceImpl(long cleanupIntervalNanos,
EventPublisher publisher)
cleanupIntervalNanos - the interval at which the cleanup thread should check on submitted monitors, in
nanoseconds.publisher - the publisher to subscribe to for data access events.protected void initCleanupThread(long cleanupIntervalNanos)
protected void checkMonitors()
protected void handleMonitorError(MonitorServiceImpl.CacheContainer cacheContainer, java.lang.Object key, MonitorServiceImpl.MonitorItem errorMonitorItem)
public <T extends Monitor> void registerMonitorTypeIfAbsent(java.lang.Class<T> monitorClass, long expirationTimeoutNanos, long heartbeatTimeoutNanos, java.util.Set<MonitorErrorResponse> errorResponses, @Nullable java.lang.Class<?> producedDataClass)
MonitorServiceregisterMonitorTypeIfAbsent in interface MonitorServiceT - the type of the monitor.monitorClass - the class of the monitor, eg `CustomEndpointMonitorImpl.class`.expirationTimeoutNanos - how long a monitor should be stored without use before being considered expired, in
nanoseconds. Expired monitors may be removed and stopped.heartbeatTimeoutNanos - a duration in nanoseconds defining the maximum amount of time that a monitor should
take between updating its last-updated timestamp. If a monitor has not updated its
last-updated timestamp within this duration it will be considered stuck.errorResponses - a Set defining actions to take if the monitor is stuck or in an error state.producedDataClass - the class of data produced by the monitor.public <T extends Monitor> T runIfAbsent(java.lang.Class<T> monitorClass, java.lang.Object key, StorageService storageService, TelemetryFactory telemetryFactory, java.lang.String originalUrl, java.lang.String driverProtocol, TargetDriverDialect driverDialect, Dialect dbDialect, java.util.Properties originalProps, MonitorInitializer initializer) throws java.sql.SQLException
MonitorServicerunIfAbsent in interface MonitorServiceT - the type of the monitor.monitorClass - the concrete class of the monitor, eg `CustomEndpointMonitorImpl.class`.key - the key for the monitor, eg
"custom-endpoint.cluster-custom-XYZ.us-east-2.rds.amazonaws.com:5432".storageService - the storage service for the monitor to use.telemetryFactory - the telemetry factory for creating telemetry data.originalUrl - the URL of the original database connection.driverProtocol - the protocol for the underlying target driver.driverDialect - the target driver dialect.dbDialect - the database dialect.originalProps - the properties of the original database connection.initializer - an initializer function to use to create the monitor if it does not already exist.java.sql.SQLException - if an error occurs while trying to create the monitor.public <T extends Monitor> T get(java.lang.Class<T> monitorClass, java.lang.Object key)
MonitorServiceget in interface MonitorServiceT - the type of the monitor.monitorClass - the expected class of the monitor.key - the key for the monitor.public <T extends Monitor> T remove(java.lang.Class<T> monitorClass, java.lang.Object key)
MonitorServiceremove in interface MonitorServiceT - the type of the monitor.monitorClass - the expected class of the monitor.key - the key for the monitor.public <T extends Monitor> void stopAndRemove(java.lang.Class<T> monitorClass, java.lang.Object key)
MonitorServicestopAndRemove in interface MonitorServiceT - the type of the monitor.monitorClass - the class of the monitor, eg `CustomEndpointMonitorImpl.class`.key - the key for the monitor, eg
"custom-endpoint.cluster-custom-XYZ.us-east-2.rds.amazonaws.com:5432".public <T extends Monitor> void stopAndRemoveMonitors(java.lang.Class<T> monitorClass)
MonitorServicestopAndRemoveMonitors in interface MonitorServiceT - the type of the monitor.monitorClass - the class of the monitor, eg `CustomEndpointMonitorImpl.class`.public void stopAndRemoveAll()
MonitorServicestopAndRemoveAll in interface MonitorServicepublic void releaseResources()
MonitorServicereleaseResources in interface MonitorServicepublic void processEvent(Event event)
EventSubscriberEventPublisher.subscribe(software.amazon.jdbc.util.events.EventSubscriber, java.util.Set<java.lang.Class<? extends software.amazon.jdbc.util.events.Event>>).processEvent in interface EventSubscriberevent - the event to process.