Quartz scheduler and OSGI

核能气质少年 提交于 2019-12-09 21:59:18

问题


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?


回答1:


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/




回答2:


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




回答3:


You can install these bundles

bundle:install wrap:mvn:c3p0/c3p0/0.9.1.2
bundle:install mvn:org.quartz-scheduler/quartz/2.2.2
bundle:install wrap:mvn:org.quartz-scheduler/quartz-jobs/2.2.2

You will need these dependency

       <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.quartz</artifactId>
            <version>2.2.2_1</version>
        </dependency>

        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>


来源:https://stackoverflow.com/questions/5006548/quartz-scheduler-and-osgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!