Osgi 调度不';添加数组值时不执行
我创建了一个非常简单的调度程序,每分钟执行一次,如下所示:Osgi 调度不';添加数组值时不执行,osgi,aem,Osgi,Aem,我创建了一个非常简单的调度程序,每分钟执行一次,如下所示: @Service(value = Runnable.class) @Component(name = "Job A", label = "Job A", description = "Job will run after 1 min", metatype = true, immediate = true) @Properties({ @Property(label = "Quartz Cron Expression",
@Service(value = Runnable.class)
@Component(name = "Job A", label = "Job A", description = "Job will run after 1 min", metatype = true, immediate = true)
@Properties({
@Property(label = "Quartz Cron Expression", description = "Quartz Scheduler specific cron expression.", name = "scheduler.expression", value = "0 0/1 * 1/1 * ? *"),
@Property(unbounded=PropertyUnbounded.ARRAY, value={"*"}, label = "Root Path", name = "domain.rootpath",
description = "Root Page"),
@Property(
label = "Allow concurrent executions",
description = "Allow concurrent executions of this Scheduled Service",
name = "scheduler.concurrent",
boolValue = true,
propertyPrivate = true
)
})
public class SimpleSchedular implements Runnable {
private static Logger logger = LoggerFactory.getLogger(SimpleSchedular.class);
private String[] rootPath;
public void run() {
logger.info("JOB A ::: "+rootPath.length);
}
@Activate
private void activate(final ComponentContext componentContext) {
final Dictionary<?, ?> properties = componentContext.getProperties();
this.rootPath = (String [])properties.get("domain.rootpath");
logger.info("JOB A Length of array ::: "+this.rootPath.length); //prints correct length
}
@Modified
private void modified(final ComponentContext componentContext) {
activate(componentContext);
}
}
@Service(value=Runnable.class)
@组件(name=“Job A”,label=“Job A”,description=“Job将在1分钟后运行”,metatype=true,immediate=true)
@性质({
@属性(label=“Quartz-Cron-Expression”,description=“Quartz-Scheduler-specific-Cron-Expression.”,name=“Scheduler.Expression”,value=“0/1*1/1*?*”,
@属性(unbounded=propertyunbunded.ARRAY,value={“*”},label=“Root Path”,name=“domain.rootpath”,
description=“根页面”),
@财产(
label=“允许并发执行”,
description=“允许同时执行此计划服务”,
name=“scheduler.concurrent”,
布尔值=真,
propertyPrivate=true
)
})
公共类SimpleSchedular实现可运行{
私有静态记录器Logger=LoggerFactory.getLogger(SimpleSchedular.class);
私有字符串[]根路径;
公开募捐{
logger.info(“作业A::”+rootPath.length);
}
@激活
私有void激活(最终ComponentContext ComponentContext){
final Dictionary properties=componentContext.getProperties();
this.rootPath=(String[])properties.get(“domain.rootPath”);
logger.info(“作业数组的长度::”+this.rootPath.Length);//打印正确的长度
}
@修改
已修改私有void(最终ComponentContext ComponentContext){
激活(组件上下文);
}
}
当我构建代码时,这段代码运行良好,并在一分钟后打印
作业A:::1
。但是当我通过OSGi控制台通过域.rootpath
添加更多值时,它不会调用run方法。我可以在激活调用时看到正确的数组长度,但run menthod不执行。有什么想法吗?在使用sling文档后,运行调用和激活方法的问题似乎同时发生。我使用了不同的方法来创建调度器。下面是适用于我的示例代码
@Component(name = "Hello World Schedular", label = "Simple Schedular", metatype = true)
@Properties(
@Property(unbounded= PropertyUnbounded.ARRAY, value={"/content/PwC/en"}, label = "Root Path", name = "domain.rootpath",
description = "Root Page to create the sitemap")
)
public class HelloWorldScheduledService {
protected final Logger log = LoggerFactory.getLogger(this.getClass());
@Reference
private Scheduler scheduler;
protected void activate(ComponentContext componentContext) throws Exception {
final Dictionary<?, ?> properties = componentContext.getProperties();
final String arr[] = (String [])properties.get("domain.rootpath");
String schedulingExpression = "0 0/1 * 1/1 * ? *";
String jobName1 = "case1";
Map<String, Serializable> config1 = new HashMap<String, Serializable>();
boolean canRunConcurrently = true;
final Runnable job1 = new Runnable() {
public void run() {
log.info("Executing job1"+arr.length);
}
};
try {
this.scheduler.addJob(jobName1, job1, config1, schedulingExpression, canRunConcurrently);
} catch (Exception e) {
job1.run();
}
}
protected void deactivate(ComponentContext componentContext) {
log.info("Deactivated, goodbye!");
}
protected void modified(ComponentContext componentContext){
try{
activate(componentContext);
}catch (Exception e){
}
}
组件(name=“Hello World Schedular”,label=“Simple Schedular”,metatype=true)
@性质(
@属性(unbounded=propertyunbunded.ARRAY,value={”/content/PwC/en“},label=“Root Path”,name=“domain.rootpath”,
description=“创建站点地图的根页面”)
)
公共类HelloWorldScheduledService{
受保护的最终记录器日志=LoggerFactory.getLogger(this.getClass());
@参考文献
专用调度器;
受保护的无效激活(ComponentContext ComponentContext)引发异常{
final Dictionary properties=componentContext.getProperties();
最终字符串arr[]=(字符串[])properties.get(“domain.rootpath”);
字符串schedulingExpression=“0 0/1*1/1*?*”;
字符串jobName1=“case1”;
Map config1=新的HashMap();
布尔值=true;
最终可运行作业1=新可运行作业(){
公开募捐{
日志信息(“正在执行作业1”+arr.length);
}
};
试一试{
this.scheduler.addJob(jobName1、job1、config1、schedulingExpression、canrunconcurrent);
}捕获(例外e){
job1.run();
}
}
受保护的无效停用(ComponentContext ComponentContext){
log.info(“停用,再见!”);
}
已修改受保护的void(ComponentContext ComponentContext){
试一试{
激活(组件上下文);
}捕获(例外e){
}
}
我怀疑删除
@Modified
方法会解决问题。如果没有,组件将在其OSGi配置更改时被停用和重新激活,然后Sling调度程序子系统将正确接收更改