Search in sources :

Example 1 with JobHandler

use of com.xxl.job.core.handler.annotation.JobHandler in project xxl-job by xuxueli.

the class XxlJobExecutor method initJobHandlerRepository.

private static void initJobHandlerRepository(ApplicationContext applicationContext) {
    if (applicationContext == null) {
        return;
    }
    // init job handler action
    Map<String, Object> serviceBeanMap = applicationContext.getBeansWithAnnotation(JobHandler.class);
    if (serviceBeanMap != null && serviceBeanMap.size() > 0) {
        for (Object serviceBean : serviceBeanMap.values()) {
            if (serviceBean instanceof IJobHandler) {
                String name = serviceBean.getClass().getAnnotation(JobHandler.class).value();
                IJobHandler handler = (IJobHandler) serviceBean;
                if (loadJobHandler(name) != null) {
                    throw new RuntimeException("xxl-job jobhandler naming conflicts.");
                }
                registJobHandler(name, handler);
            }
        }
    }
}
Also used : IJobHandler(com.xxl.job.core.handler.IJobHandler) JobHandler(com.xxl.job.core.handler.annotation.JobHandler) IJobHandler(com.xxl.job.core.handler.IJobHandler)

Example 2 with JobHandler

use of com.xxl.job.core.handler.annotation.JobHandler in project xxl-job by xuxueli.

the class NutzSetup method init.

@Override
public void init(NutConfig cfg) {
    // regist JobHandler
    String[] beanNames = cfg.getIoc().getNamesByType(IJobHandler.class);
    if (beanNames == null || beanNames.length == 0) {
        return;
    }
    for (String beanName : beanNames) {
        IJobHandler jobHandler = cfg.getIoc().get(IJobHandler.class, beanName);
        String name = jobHandler.getClass().getAnnotation(JobHandler.class).value();
        XxlJobExecutor.registJobHandler(name, jobHandler);
    }
    // load executor prop
    PropertiesProxy xxlJobProp = new PropertiesProxy("xxl-job-executor.properties");
    // init executor
    xxlJobExecutor = new XxlJobExecutor();
    xxlJobExecutor.setAdminAddresses(xxlJobProp.get("xxl.job.admin.addresses"));
    xxlJobExecutor.setAppName(xxlJobProp.get("xxl.job.executor.appname"));
    xxlJobExecutor.setIp(xxlJobProp.get("xxl.job.executor.ip"));
    xxlJobExecutor.setPort(xxlJobProp.getInt("xxl.job.executor.port"));
    xxlJobExecutor.setAccessToken(xxlJobProp.get("xxl.job.accessToken"));
    xxlJobExecutor.setLogPath(xxlJobProp.get("xxl.job.executor.logpath"));
    xxlJobExecutor.setLogRetentionDays(xxlJobProp.getInt("xxl.job.executor.logretentiondays"));
    // start executor
    try {
        xxlJobExecutor.start();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : IJobHandler(com.xxl.job.core.handler.IJobHandler) JobHandler(com.xxl.job.core.handler.annotation.JobHandler) IJobHandler(com.xxl.job.core.handler.IJobHandler) PropertiesProxy(org.nutz.ioc.impl.PropertiesProxy) XxlJobExecutor(com.xxl.job.core.executor.XxlJobExecutor)

Example 3 with JobHandler

use of com.xxl.job.core.handler.annotation.JobHandler in project nutzboot by nutzam.

the class XxlJobStarter method start.

public void start() throws Exception {
    // 从ioc容器中找出所有实现了IJobHandler接口的对象,注册到XxlJobExecutor
    for (IJobHandler jobHandler : appContext.getBeans(IJobHandler.class)) {
        // 看看有没有@JobHandler注解
        JobHandler annoJobHandler = jobHandler.getClass().getAnnotation(JobHandler.class);
        // 得到jobHandlerName
        String jobHandlerName = jobHandler.getClass().getSimpleName();
        if (annoJobHandler != null && !Strings.isBlank(annoJobHandler.value()))
            jobHandlerName = annoJobHandler.value();
        // 注册到XxlJobExecutor上下文
        XxlJobExecutor.registJobHandler(jobHandlerName, jobHandler);
    }
    // 获取XxlJobExecutor,从而触发XxlJobExecutor的初始化
    appContext.getIoc().getByType(XxlJobExecutor.class);
}
Also used : IJobHandler(com.xxl.job.core.handler.IJobHandler) JobHandler(com.xxl.job.core.handler.annotation.JobHandler) IJobHandler(com.xxl.job.core.handler.IJobHandler)

Aggregations

IJobHandler (com.xxl.job.core.handler.IJobHandler)3 JobHandler (com.xxl.job.core.handler.annotation.JobHandler)3 XxlJobExecutor (com.xxl.job.core.executor.XxlJobExecutor)1 PropertiesProxy (org.nutz.ioc.impl.PropertiesProxy)1