CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-quartz-scheduler--quartz

Quartz Enterprise Job Scheduler - A richly featured, open source job scheduling library that can be integrated within virtually any Java application

Pending
Overview
Eval results
Files

matcher-framework.mddocs/

Matcher Framework

Advanced pattern matching system for selecting jobs and triggers in Quartz based on various criteria. Matchers provide flexible, type-safe selection mechanisms for bulk operations on jobs and triggers, supporting complex filtering and group operations.

Capabilities

Matcher Interface

Base interface for all matcher implementations that define selection criteria.

/**
 * Interface for matching jobs and triggers based on criteria
 * @param <T> the type being matched (JobKey or TriggerKey)
 */
interface Matcher<T extends Key<T>> extends Serializable {
    /**
     * Determine if the given key matches this matcher's criteria
     * @param key the key to test
     * @return true if the key matches
     */
    boolean isMatch(T key);
}

GroupMatcher Class

Matcher for selecting keys based on group patterns.

/**
 * Matcher that matches keys based on group patterns
 * @param <T> the key type (JobKey or TriggerKey)
 */
class GroupMatcher<T extends Key<T>> implements Matcher<T> {
    /**
     * Create matcher for exact group name
     * @param group the exact group name to match
     * @return GroupMatcher for the group
     */
    static <T extends Key<T>> GroupMatcher<T> groupEquals(String group);
    
    /**
     * Create matcher for groups starting with prefix
     * @param groupPrefix the group prefix to match
     * @return GroupMatcher for the prefix
     */
    static <T extends Key<T>> GroupMatcher<T> groupStartsWith(String groupPrefix);
    
    /**
     * Create matcher for groups ending with suffix
     * @param groupSuffix the group suffix to match
     * @return GroupMatcher for the suffix
     */
    static <T extends Key<T>> GroupMatcher<T> groupEndsWith(String groupSuffix);
    
    /**
     * Create matcher for groups containing substring
     * @param groupContains the substring that groups must contain
     * @return GroupMatcher for the substring
     */
    static <T extends Key<T>> GroupMatcher<T> groupContains(String groupContains);
    
    /**
     * Create matcher for any group (matches all)
     * @return GroupMatcher that matches any group
     */
    static <T extends Key<T>> GroupMatcher<T> anyGroup();
    
    /**
     * Create matcher for jobs in any of the specified groups
     * @return GroupMatcher for job groups
     */
    static GroupMatcher<JobKey> anyJobGroup();
    
    /**
     * Create matcher for triggers in any of the specified groups
     * @return GroupMatcher for trigger groups
     */
    static GroupMatcher<TriggerKey> anyTriggerGroup();
    
    /**
     * Create matcher for specific job group
     * @param group the job group name
     * @return GroupMatcher for the job group
     */
    static GroupMatcher<JobKey> jobGroupEquals(String group);
    
    /**
     * Create matcher for specific trigger group
     * @param group the trigger group name
     * @return GroupMatcher for the trigger group
     */
    static GroupMatcher<TriggerKey> triggerGroupEquals(String group);
    
    /**
     * Create matcher for job groups starting with prefix
     * @param groupPrefix the job group prefix
     * @return GroupMatcher for the job group prefix
     */
    static GroupMatcher<JobKey> jobGroupStartsWith(String groupPrefix);
    
    /**
     * Create matcher for trigger groups starting with prefix
     * @param groupPrefix the trigger group prefix
     * @return GroupMatcher for the trigger group prefix
     */
    static GroupMatcher<TriggerKey> triggerGroupStartsWith(String groupPrefix);
    
    /**
     * Create matcher for job groups ending with suffix
     * @param groupSuffix the job group suffix
     * @return GroupMatcher for the job group suffix
     */
    static GroupMatcher<JobKey> jobGroupEndsWith(String groupSuffix);
    
    /**
     * Create matcher for trigger groups ending with suffix
     * @param groupSuffix the trigger group suffix
     * @return GroupMatcher for the trigger group suffix
     */
    static GroupMatcher<TriggerKey> triggerGroupEndsWith(String groupSuffix);
    
    /**
     * Create matcher for job groups containing substring
     * @param groupContains the substring for job groups
     * @return GroupMatcher for job groups containing substring
     */
    static GroupMatcher<JobKey> jobGroupContains(String groupContains);
    
    /**
     * Create matcher for trigger groups containing substring
     * @param groupContains the substring for trigger groups
     * @return GroupMatcher for trigger groups containing substring
     */
    static GroupMatcher<TriggerKey> triggerGroupContains(String groupContains);
}

NameMatcher Class

Matcher for selecting keys based on name patterns.

/**
 * Matcher that matches keys based on name patterns
 * @param <T> the key type (JobKey or TriggerKey)
 */
class NameMatcher<T extends Key<T>> implements Matcher<T> {
    /**
     * Create matcher for exact name
     * @param name the exact name to match
     * @return NameMatcher for the name
     */
    static <T extends Key<T>> NameMatcher<T> nameEquals(String name);
    
    /**
     * Create matcher for names starting with prefix
     * @param namePrefix the name prefix to match
     * @return NameMatcher for the prefix
     */
    static <T extends Key<T>> NameMatcher<T> nameStartsWith(String namePrefix);
    
    /**
     * Create matcher for names ending with suffix
     * @param nameSuffix the name suffix to match
     * @return NameMatcher for the suffix
     */
    static <T extends Key<T>> NameMatcher<T> nameEndsWith(String nameSuffix);
    
    /**
     * Create matcher for names containing substring
     * @param nameContains the substring that names must contain
     * @return NameMatcher for the substring
     */
    static <T extends Key<T>> NameMatcher<T> nameContains(String nameContains);
}

KeyMatcher Class

Matcher for selecting specific keys.

/**
 * Matcher that matches specific keys
 * @param <T> the key type (JobKey or TriggerKey)
 */
class KeyMatcher<T extends Key<T>> implements Matcher<T> {
    /**
     * Create matcher for a specific key
     * @param key the key to match
     * @return KeyMatcher for the key
     */
    static <T extends Key<T>> KeyMatcher<T> keyEquals(T key);
}

EverythingMatcher Class

Matcher that matches all keys.

/**
 * Matcher that matches everything
 * @param <T> the key type (JobKey or TriggerKey)
 */
class EverythingMatcher<T extends Key<T>> implements Matcher<T> {
    /**
     * Create matcher that matches all keys
     * @return EverythingMatcher instance
     */
    static <T extends Key<T>> EverythingMatcher<T> allJobs();
    static <T extends Key<T>> EverythingMatcher<T> allTriggers();
}

AndMatcher Class

Matcher that combines multiple matchers with logical AND.

/**
 * Matcher that performs logical AND of multiple matchers
 * @param <T> the key type (JobKey or TriggerKey)
 */
class AndMatcher<T extends Key<T>> implements Matcher<T> {
    /**
     * Create AND matcher from multiple matchers
     * @param matchers the matchers to combine with AND
     * @return AndMatcher combining all matchers
     */
    @SafeVarargs
    static <T extends Key<T>> AndMatcher<T> and(Matcher<T>... matchers);
    
    /**
     * Create AND matcher from list of matchers
     * @param matchers the list of matchers to combine
     * @return AndMatcher combining all matchers
     */
    static <T extends Key<T>> AndMatcher<T> and(List<Matcher<T>> matchers);
}

OrMatcher Class

Matcher that combines multiple matchers with logical OR.

/**
 * Matcher that performs logical OR of multiple matchers
 * @param <T> the key type (JobKey or TriggerKey)
 */
class OrMatcher<T extends Key<T>> implements Matcher<T> {
    /**
     * Create OR matcher from multiple matchers
     * @param matchers the matchers to combine with OR
     * @return OrMatcher combining all matchers
     */
    @SafeVarargs
    static <T extends Key<T>> OrMatcher<T> or(Matcher<T>... matchers);
    
    /**
     * Create OR matcher from list of matchers
     * @param matchers the list of matchers to combine
     * @return OrMatcher combining all matchers
     */
    static <T extends Key<T>> OrMatcher<T> or(List<Matcher<T>> matchers);
}

NotMatcher Class

Matcher that negates another matcher.

/**
 * Matcher that performs logical NOT of another matcher
 * @param <T> the key type (JobKey or TriggerKey)
 */
class NotMatcher<T extends Key<T>> implements Matcher<T> {
    /**
     * Create NOT matcher that negates another matcher
     * @param matcher the matcher to negate
     * @return NotMatcher that negates the given matcher
     */
    static <T extends Key<T>> NotMatcher<T> not(Matcher<T> matcher);
}

StringMatcher Class

Advanced string pattern matcher with various comparison operations.

/**
 * Utility for advanced string pattern matching
 */
class StringMatcher implements Serializable {
    /**
     * String comparison operations
     */
    enum StringOperatorName {
        EQUALS, STARTS_WITH, ENDS_WITH, CONTAINS, ANYTHING
    }
    
    /**
     * Create string matcher with operation
     * @param value the value to compare against
     * @param operation the comparison operation
     * @return StringMatcher instance
     */
    static StringMatcher stringMatcher(String value, StringOperatorName operation);
    
    /**
     * Create exact match string matcher
     * @param value the exact value to match
     * @return StringMatcher for exact match
     */
    static StringMatcher equals(String value);
    
    /**
     * Create starts-with string matcher
     * @param prefix the prefix to match
     * @return StringMatcher for starts-with
     */
    static StringMatcher startsWith(String prefix);
    
    /**
     * Create ends-with string matcher
     * @param suffix the suffix to match
     * @return StringMatcher for ends-with
     */
    static StringMatcher endsWith(String suffix);
    
    /**
     * Create contains string matcher
     * @param substring the substring to match
     * @return StringMatcher for contains
     */
    static StringMatcher contains(String substring);
    
    /**
     * Create matcher that matches anything
     * @return StringMatcher that matches any string
     */
    static StringMatcher anything();
    
    /**
     * Test if a value matches this matcher
     * @param value the value to test
     * @return true if the value matches
     */
    boolean compare(String value);
}

Usage Examples:

import org.quartz.*;
import org.quartz.impl.matchers.*;
import static org.quartz.impl.matchers.GroupMatcher.*;
import static org.quartz.impl.matchers.NameMatcher.*;
import static org.quartz.impl.matchers.KeyMatcher.*;

// Group-based matching
Matcher<JobKey> reportJobs = jobGroupEquals("reports");
scheduler.pauseJobs(reportJobs);

Matcher<TriggerKey> batchTriggers = triggerGroupStartsWith("batch");
scheduler.pauseTriggers(batchTriggers);

// Name-based matching
Matcher<JobKey> importJobs = nameStartsWith("import");
scheduler.deleteJobs(scheduler.getJobKeys(importJobs));

Matcher<TriggerKey> dailyTriggers = nameEndsWith("Daily");
for (TriggerKey key : scheduler.getTriggerKeys(dailyTriggers)) {
    System.out.println("Daily trigger: " + key);
}

// Specific key matching
JobKey specificJob = jobKey("myJob", "myGroup");
Matcher<JobKey> specificMatcher = keyEquals(specificJob);
if (scheduler.checkExists(specificJob)) {
    scheduler.pauseJobs(specificMatcher);
}

// Logical combinations - pause all report jobs except monthly reports
Matcher<JobKey> allReports = jobGroupEquals("reports");
Matcher<JobKey> monthlyReports = nameContains("monthly");
Matcher<JobKey> nonMonthlyReports = and(allReports, not(monthlyReports));
scheduler.pauseJobs(nonMonthlyReports);

// Complex matching - all batch jobs or any trigger in maintenance group
Matcher<JobKey> batchJobMatcher = jobGroupEquals("batch");
Matcher<TriggerKey> maintenanceTriggerMatcher = triggerGroupEquals("maintenance");

// Pause batch jobs
scheduler.pauseJobs(batchJobMatcher);
// Pause maintenance triggers
scheduler.pauseTriggers(maintenanceTriggerMatcher);

// Multiple group operations
Matcher<JobKey> importOrExportJobs = or(
    jobGroupEquals("import"),
    jobGroupEquals("export")
);
scheduler.resumeJobs(importOrExportJobs);

// Pattern matching for cleanup - delete all temporary jobs
Matcher<JobKey> tempJobs = and(
    nameStartsWith("temp_"),
    jobGroupContains("cleanup")
);

List<JobKey> tempJobKeys = new ArrayList<>(scheduler.getJobKeys(tempJobs));
for (JobKey key : tempJobKeys) {
    scheduler.deleteJob(key);
}

// Advanced string matching for trigger management
Matcher<TriggerKey> hourlyTriggers = new Matcher<TriggerKey>() {
    @Override
    public boolean isMatch(TriggerKey key) {
        return key.getName().matches(".*[Hh]ourly.*");
    }
};

// Get all triggers and filter
Set<TriggerKey> allTriggers = scheduler.getTriggerKeys(GroupMatcher.anyTriggerGroup());
for (TriggerKey key : allTriggers) {
    if (hourlyTriggers.isMatch(key)) {
        Trigger trigger = scheduler.getTrigger(key);
        System.out.println("Hourly trigger: " + key + " next fire: " + trigger.getNextFireTime());
    }
}

// Utility methods with matchers
public void pauseJobsWithPrefix(Scheduler scheduler, String prefix) throws SchedulerException {
    Matcher<JobKey> matcher = nameStartsWith(prefix);
    scheduler.pauseJobs(matcher);
}

public void deleteTriggersInGroups(Scheduler scheduler, String... groups) throws SchedulerException {
    List<Matcher<TriggerKey>> matchers = new ArrayList<>();
    for (String group : groups) {
        matchers.add(triggerGroupEquals(group));
    }
    Matcher<TriggerKey> combinedMatcher = or(matchers);
    
    Set<TriggerKey> keys = scheduler.getTriggerKeys(combinedMatcher);
    for (TriggerKey key : keys) {
        scheduler.unscheduleJob(key);
    }
}

Static Import Usage

For cleaner syntax, use static imports:

import static org.quartz.impl.matchers.GroupMatcher.*;
import static org.quartz.impl.matchers.NameMatcher.*;
import static org.quartz.impl.matchers.KeyMatcher.*;
import static org.quartz.impl.matchers.EverythingMatcher.*;

// Much cleaner syntax
scheduler.pauseJobs(jobGroupEquals("reports"));
scheduler.pauseTriggers(triggerGroupStartsWith("batch"));
scheduler.resumeJobs(nameContains("import"));
scheduler.deleteJobs(and(jobGroupEquals("temp"), nameStartsWith("old_")));

Install with Tessl CLI

npx tessl i tessl/maven-org-quartz-scheduler--quartz

docs

calendar-management.md

core-scheduling.md

enterprise-features.md

exception-handling.md

index.md

job-management.md

listeners-events.md

matcher-framework.md

persistence-storage.md

schedule-builders.md

trigger-management.md

utilities-helpers.md

tile.json