All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cattleframework.quartz.QuartzServiceInitializer Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.cattleframework.quartz;

import java.util.Set;

import org.cattleframework.aop.reflections.ReflectionsFactory;
import org.cattleframework.exception.CommonException;
import org.cattleframework.exception.ExceptionWrapUtils;
import org.cattleframework.quartz.annotation.ConfigureQuartzJob;
import org.cattleframework.quartz.annotation.CronQuartzJob;
import org.cattleframework.quartz.annotation.QuartzJob;
import org.cattleframework.quartz.job.Job;

import jakarta.annotation.PostConstruct;

/**
 * Quartz服务初始化
 * 
 * @author orange
 *
 */
public class QuartzServiceInitializer {

    private final QuartzService quartzService;

    public QuartzServiceInitializer(QuartzService quartzService) {
	this.quartzService = quartzService;
    }

    @PostConstruct
    public void initialize() {
	Set> jobClasses = ReflectionsFactory.getSubTypesOf(Job.class);
	for (Class jobClass : jobClasses) {
	    try {
		QuartzJob quartzJob = jobClass.getAnnotation(QuartzJob.class);
		if (quartzJob != null) {
		    quartzService.add(quartzJob, jobClass);
		    continue;
		}
		CronQuartzJob cronQuartzJob = jobClass.getAnnotation(CronQuartzJob.class);
		if (cronQuartzJob != null) {
		    quartzService.add(cronQuartzJob, jobClass);
		    continue;
		}
		ConfigureQuartzJob configureQuartzJob = jobClass.getAnnotation(ConfigureQuartzJob.class);
		if (configureQuartzJob != null) {
		    quartzService.add(configureQuartzJob, jobClass);
		    continue;
		}
	    } catch (CommonException e) {
		throw ExceptionWrapUtils.wrapRuntime(e);
	    }
	}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy