AEM 6.3:使用OSGi R6注释创建调度程序

AEM 6.3:使用OSGi R6注释创建调度程序,osgi,quartz-scheduler,aem,Osgi,Quartz Scheduler,Aem,我使用OSGi R6注释编写了一个调度程序,但它似乎没有运行: 包com.aem.sites.interfaces; 导入org.osgi.service.metatype.annotations.AttributeDefinition; 导入org.osgi.service.metatype.annotations.AttributeType; 导入org.osgi.service.metatype.annotations.ObjectClassDefinition; @ObjectClass

我使用OSGi R6注释编写了一个调度程序,但它似乎没有运行:

包com.aem.sites.interfaces;
导入org.osgi.service.metatype.annotations.AttributeDefinition;
导入org.osgi.service.metatype.annotations.AttributeType;
导入org.osgi.service.metatype.annotations.ObjectClassDefinition;
@ObjectClassDefinition(name=“天气调度程序配置”,description=“调度程序配置文件”)
public@interface SchedulerConfiguration{
@属性定义(
name=“示例参数”,
description=“示例字符串参数”,
type=AttributeType.STRING
)
公共字符串参数()默认为“调度程序”;
@属性定义(
name=“并发”,
description=“同时安排任务”,
类型=AttributeType.BOOLEAN
)
布尔调度程序_concurrent()默认为true;
@属性定义(
name=“Expression”,
description=“Cron作业表达式。默认值:每分钟运行一次。”,
type=AttributeType.STRING
)
字符串调度程序_expression()默认值为“0****?”;
}

包com.aem.sites.schedulers;
导入org.osgi.service.component.annotations.component;
导入org.osgi.service.component.annotations.Activate;
导入org.osgi.service.metatype.annotations.allow;
导入org.slf4j.Logger;
导入org.slf4j.LoggerFactory;
导入com.aem.sites.interfaces.SchedulerConfiguration;
@组件(立即=真,
configurationPid=“com.aem.sites.schedulers.WeatherServiceScheduler”)
@指定(ocd=SchedulerConfiguration.class)
公共类WeatherServiceScheduler实现可运行{
私有最终记录器Logger=LoggerFactory.getLogger(this.getClass());
私有字符串myParameter;
@凌驾
公开募捐{
logger.info(“****************************************************示例OSGi调度程序正在运行”,myParameter);
}
@激活
公共无效激活(SchedulerConfiguration配置){
logger.info(“***************************************************************天气服务计划程序”+myParameter);
myParameter=config.parameter();
}
}
我正在关注这一点,但看起来我做错了什么。但我不知道会发生什么


提前感谢在类注释中不需要
configurationPid
,而且您缺少
service=Runnable.class
,它应该紧跟在
immediate=true
之后,即类声明应该如下所示:

@组件(immediate=true,service=Runnable.class)
@指定(ocd=SchedulerConfiguration.class)
公共类WeatherServiceScheduler实现可运行{

在您的WeatherSchedulerService类中,您没有将其注册为服务。您可以这样做,而不是配置PID

使用注释创建SlingScheduler的正确方法如下-

  • 创建您的OSGi配置类
  • import org.osgi.service.metatype.annotations.AttributeDefinition;
    导入org.osgi.service.metatype.annotations.AttributeType;
    导入org.osgi.service.metatype.annotations.ObjectClassDefinition;
    @ObjectClassDefinition(name=“Sling调度器配置”,description=“此配置用于演示正在运行的Sling调度器”)
    public@interface SchedulerConfiguration{
    @属性定义(
    name=“调度器名称”,
    description=“调度程序的名称”,
    类型=AttributeType.STRING)
    public String name()默认值为“Custom Sling Scheduler”;
    @属性定义(
    name=“已启用”,
    description=“启用/禁用计划程序的标志”,
    类型=AttributeType.STRING)
    公共布尔启用()默认为false;
    @属性定义(
    name=“Cron表达式”,
    description=“调度程序使用的Cron表达式”,
    类型=AttributeType.STRING)
    公共字符串cronExpression()默认为“0****?”;
    @属性定义(
    name=“自定义参数”,
    description=“显示吊索调度器使用情况的自定义参数”,
    类型=AttributeType.STRING)
    公共字符串customParameter();
    }
    
  • 将计划程序类创建为服务。要使用R6注释创建OSGi服务,我们使用
    @Component(service=.class,…)
    。 因此,创建一个如下所示的服务
  • import org.apache.sling.commons.scheduler.ScheduleOptions;
    导入org.apache.sling.commons.scheduler.scheduler;
    导入org.osgi.service.component.annotations.Activate;
    导入org.osgi.service.component.annotations.component;
    导入org.osgi.service.component.annotations.Deactivate;
    导入org.osgi.service.component.annotations.Modified;
    导入org.osgi.service.component.annotations.Reference;
    导入org.osgi.service.metatype.annotations.allow;
    导入org.redquark.aem.learning.core.configurations.SchedulerConfiguration;
    导入org.slf4j.Logger;
    导入org.slf4j.LoggerFactory;
    @组件(immediate=true,service=Runnable.class)
    @指定(ocd=SchedulerConfiguration.class)
    公共类CustomScheduler实现可运行{
    //记录器
    私有最终记录器log=LoggerFactory.getLogger(this.getClass());
    //要从配置中读取的自定义参数
    私有字符串参数;
    //基于其名称的计划程序Id
    私有int调度;
    //注入调度程序实例
    @参考文献
    专用调度器;
    /**
    *激活方法来初始化内容
    * 
    *@param schedulerConfiguration
    */
    @激活
    受保护无效激活(SchedulerConfiguration SchedulerConfiguration){
    schedulerId=schedulerConfiguration.name().hashCode();