Quartz调度器和OSGI

发布于 2024-10-17 19:01:13 字数 362 浏览 7 评论 0 原文

我有一个 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晨曦慕雪 2024-10-24 19:01:13

使用真正的 Quartz OSGi 捆绑包,例如此处提供的捆绑包:

http://ebr.springsource.com/repository/app/bundle/detail?name=com.springsource.org.quartz

最新的 Quartz 版本是 1.6.2。如果您需要更新的版本,使用 bndbundlor

然后,您可以将 StatefulJob 作为 OSGi 环境中任何位置的服务公开,并让您的调度程序包使用 Quartz 注册和取消注册这些作业。更好的是,让调度程序包侦听任何围绕触发器和作业信息进行包装的服务,例如 Spring CronTriggerBeanSimpleTriggerBean。这样,

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/

樱娆 2024-10-24 19:01:13

在这里您可以找到更新的 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

霊感 2024-10-24 19:01:13

您可以安装这些捆绑包

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

您将需要这些依赖项

       <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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文