我有一个 OSGI 调度程序包,其中包含 Quartz Scheduler Jar。
该捆绑包仅向其他捆绑包公开一个应用程序接口,并且当注册新作业时,它将被包装到临时作业(实现 StatefulJob)中并使用调度程序进行调度。
这样我就不必公开 Quartz Scheduler jar(它不太符合 osgi)。
这种方法的问题在于,由于 StatefulJob 避免并行执行作业,并且我只有一个实际作业(临时作业),所以我所有的实际作业一次运行一个。
不幸的是,标记接口似乎是表明该作业是有状态作业的唯一方法。
我能找到的唯一解决方案是让守护进程公开 StatefulJobInterface (删除假作业),但这样做,我遇到了很多类路径问题。
有没有更简单的解决方案?
I have an OSGI scheduler bundle that has the Quartz Scheduler Jar in it.
This bundle exposes just an application interface to other bundles and, when a new job is registered, it is wrapped into a temporaryJob (that implements StatefulJob) and scheduled using the scheduler.
In this way I don't have to expose Quartz Scheduler jar (that it is not so much osgi compliant).
The problem with this approach is that, since StatefulJob avoids to execute job in parallel and I have only one actual job (the temporaryJob), all my real jobs run one at a time.
Unfortunately it seems that the marker interface is the only way to say that the job is a stateful one.
The only solution I could find is to make the daemon exposing the StatefulJobInterface (removing the fake job), but doing so, I am having a lot of classpath problems.
Is there a simpler solution to this?
发布评论
评论(3)
使用真正的 Quartz OSGi 捆绑包,例如此处提供的捆绑包:
http://ebr.springsource.com/repository/app/bundle/detail?name=com.springsource.org.quartz
最新的 Quartz 版本是 1.6.2。如果您需要更新的版本,使用 bnd 或 bundlor。
然后,您可以将 StatefulJob 作为 OSGi 环境中任何位置的服务公开,并让您的调度程序包使用 Quartz 注册和取消注册这些作业。更好的是,让调度程序包侦听任何围绕触发器和作业信息进行包装的服务,例如 Spring CronTriggerBean 或 SimpleTriggerBean。这样,
1)您的内部 API / OSGi 服务不是 Quartz 特定的——只有调度捆绑包依赖于 Quartz 捆绑包,并且
2)您的应用程序捆绑包可以确定作业的调度,而不是调度捆绑包试图弄清楚这一点。
更新:ServiceMix 项目提供了较新的 Quartz OSGi 包: http://repo1.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.quartz/
Use a real Quartz OSGi bundle, such as the one available here:
http://ebr.springsource.com/repository/app/bundle/detail?name=com.springsource.org.quartz
The latest Quartz version available there is 1.6.2. If you need a newer version, building your own bundle is pretty easy with bnd or bundlor.
Then you can expose StatefulJob as a service anywhere in your OSGi environment, and have your scheduler bundle register and deregister those jobs with Quartz. Even better, have the scheduler bundle listen for any services that are wrappers around your trigger and job information, such as the Spring CronTriggerBean or SimpleTriggerBean. This way,
1) your internal API / OSGi services are not Quartz specific -- only the scheduling bundle has a dependency on the Quartz bundle, and
2) your application bundles can determine the job's schedule instead of the scheduling bundle trying to figure that out.
Update: Newer Quartz OSGi bundles are available from the ServiceMix project: http://repo1.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.quartz/
在这里您可以找到更新的 Quartz OSGI 包(撰写本文时最高版本为 2.2.0):
http://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.quartz
Here you can find newer Quartz OSGI bundles (up to version 2.2.0 at the time of writing):
http://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.quartz
您可以安装这些捆绑包
您将需要这些依赖项
You can install these bundles
You will need these dependency