Add ClusterListener Support for Cluster Node Failure Detection
Problem Statement
Quartz currently provides three types of listeners (JobListener, TriggerListener, SchedulerListener) to monitor various aspects of job scheduling. However, there is no mechanism to notify applications when a cluster node fails in a clustered Quartz environment.
This creates a critical monitoring gap for production deployments where operational teams need immediate awareness of cluster health issues.
Motivation / Use Cases
Operational Alerting: When a Quartz node fails, operations teams need immediate notification via tools like Slack to respond to potential issues.
Monitoring Integration: Cloud-native deployments need to export cluster health metrics to Prometheus, Datadog, etc. for dashboard visualization and alerting rules.
Audit & Compliance: Organizations need complete logs of cluster topology changes for security auditing.
Proposed Solution
Introduce a new ClusterListener interface that follows the existing Quartz listener pattern:
public interface ClusterListener {
String getName();
void clusterNodeFailed(String failedInstanceId);
}A support class ClusterListenerSupport will also be provided for convenience.
Integration Flow
ClusterManager detects failed node
↓
JobStoreSupport.clusterRecover()
↓
SchedulerSignaler.notifyClusterListenersNodeFailed()
↓
QuartzScheduler.notifyClusterListenersNodeFailed()
↓
All registered ClusterListeners receive notificationKey Design Decisions:
- Notification occurs after acquiring
LOCK_TRIGGER_ACCESSto ensure accuracy (only the node that actually performs recovery sends notifications) - Exception isolation: failure in one listener doesn't affect others
- Fully backward compatible and optional
Usage Example
public class AlertingClusterListener extends ClusterListenerSupport {
@Override
public void clusterNodeFailed(String failedInstanceId) {
sendAlert("Quartz cluster node failed: " + failedInstanceId);
}
}
// Register
scheduler.getListenerManager().addClusterListener(new AlertingClusterListener());Implementation Plan
I have implemented this feature and will submit a PR shortly. The implementation includes:
New Files:
org.quartz.ClusterListener- Core interfaceorg.quartz.listeners.ClusterListenerSupport- Abstract support class
Modified Files:
ListenerManager/ListenerManagerImpl- Add management methodsQuartzScheduler- Notification mechanismSchedulerSignaler/SchedulerSignalerImpl- SPI integrationJobStoreSupport- Trigger notification on node failure detection
Test Coverage:
- Unit tests for listener management
- Integration tests for notification flow
- Concurrent access tests
Benefits
✅ Solves Real Problems - Enables immediate response to cluster node failures ✅ Clean Design - Follows existing Quartz listener patterns
Backward Compatibility
Fully backward compatible. No breaking changes. This is an optional feature that users can adopt by registering listeners.
Source: quartz-scheduler/quartz