OSGi karaf scheduler

karaf 中提供了定时任务管理,只需安装 feature:install scheduler 即可,然后在 karaf 容器中发布 org.apache.karaf.scheduler.Job 服务,具体见 4.19. Scheduler

1. 环境准备

<parent>
<groupId>org.apache.karaf</groupId>
<artifactId>karaf</artifactId>
<version>4.1.5</version>
</parent>
<groupId>com.github.binarylei</groupId>
<artifactId>osgi-scheduler</artifactId>
<packaging>bundle</packaging> <dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.apache.karaf.scheduler</groupId>
<artifactId>org.apache.karaf.scheduler.core</artifactId>
</dependency>
</dependencies> <build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<!-- <obrRepository>NONE</obrRepository>
<instructions>
<_include>-bnd.bnd</_include>
</instructions>-->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.aries.blueprint</groupId>
<artifactId>blueprint-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<goals>
<goal>blueprint-generate</goal>
</goals>
</execution>
</executions>
<configuration>
<scanPaths>
<scanPath>com.github.binarylei</scanPath>
</scanPaths>
</configuration>
</plugin>
</plugins>
</build>

2. 编写定时任务

package com.github.binarylei.scheduler;

import org.apache.karaf.scheduler.Job;
import org.apache.karaf.scheduler.JobContext;
import org.apache.karaf.scheduler.Scheduler;
import org.osgi.service.component.annotations.Component; /**
* @author: leigang
* @version: 2018-03-22
*/
public class SchedulerPing implements Job { @Override
public void execute(JobContext context) {
context.getConfiguration();
System.out.println("---------------");
}
}

在 OSGI-INF/blueprint 中 blueprint.xml 配制文件发布 Job 服务:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <bean id="schedulerPing" class="com.github.binarylei.scheduler.SchedulerPing"/>
<service interface="org.apache.karaf.scheduler.Job" ref="schedulerPing">
<service-properties>
<entry key="scheduler.expression" value="0/2 * * * * ?"/>
</service-properties>
</service>
</blueprint>

OSGi karaf scheduler的更多相关文章

  1. Karaf 依赖equinox and felix,karaf 本Apache的很多项目作为基础框架

    6月17日是Apache Karaf作为Apache顶级项目.Karaf是个运行时包,包含了一个OSGi框架(Equinox或Felix).一个命令shell(Felix Gogo)及默认情况下内置的 ...

  2. AndroidStudio3.0无法打开Android Device Monitor的解决办法(An error has occurred on Android Device Monitor)

    ---恢复内容开始--- 打开monitor时出现 An error has occurred. See the log file... ------------------------------- ...

  3. Karaf 基于 osgi

    Karaf是Apache旗下的一个开源项目.Karaf同时也是一个基于OSGi的运行环境,Karaf提供了一个轻量级的OSGi容器,可以用于部署各种组件,应用程序.Karaf提供了很多特性用于帮助开发 ...

  4. osgi实战学习之路:2. maven+maven-bundle-plugin+karaf搭建osgi之HelloWorld

    环境准备: jdk版本号 jdk:1.7 karaf: 版本号:apache-karaf-3.0.1 下载地址: http://pan.baidu.com/s/1qWM4Y1u http://kara ...

  5. 关于Karaf Container 4.0.7

            Karaf是Apache旗下的一个开源项目.Karaf同时也是一个基于OSGi的运行环境,Karaf提供了一个轻量级的OSGi容器,可以用于部署各种组件,应用程序.Karaf提供了很多 ...

  6. OSGI框架学习

    OSGI框架三个重要概念 OSGi框架是根据OSGi规范中定义的三个概念层设计的:模块.模块生命周期.服务. 模块层定义了OSGi模块的概念(bundle,即包含一个元数据MANIFEST.MF的JA ...

  7. osgi实战学习之路:5.生命周期及利用命令、装饰者模式实现基于socket交互Bundle命令demo

    生命周期中关键3个类: BundleActivator 入口点,类似main方法 BundleContext Bundle上下文对象,在执行期间,为应用程序提供操作osgi框架的方法 Bundle 代 ...

  8. osgi实战学习之路:3. osgi分层概念及相互合作demo

    源码下载 分层: modual: 主要作用于包级管理与共享代码 lifecycle: 主要作用于执行期间的模块管理与訪问osgi底层框架 service: 主要作用于多模块之间的相互通信 demo: ...

  9. 深入理解OSGI:Java模块化之路

    简介 Java可能是近20年来最成功的开发技术,因其具备通用性.高效性.平台移植性和安全性而成为不同硬件平台理想的开发工具.从笔记本电脑到数据中心,从游戏控制台到科学超级计算机,从手机到互联网,Jav ...

随机推荐

  1. python之Web服务器案例

    HTTP协议简介 1. 使用谷歌/火狐浏览器分析 在Web应用中,服务器把网页传给浏览器,实际上就是把网页的HTML代码发送给浏览器,让浏览器显示出来.而浏览器和服务器之间的传输协议是HTTP,所以: ...

  2. forward与redirect的区别

    1.从地址栏显示来说forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,然后把这些内容再发给浏览器.浏览器根本不知道服务器发送的内容从哪里来的,所以它的地址 ...

  3. servletConfig的使用案例

    servletConfig参数的使用案例 首先,建立Dynamic Web Project ,同样命名FirstServlet,然后建立Servlet:Login.java,包名为cc.openhom ...

  4. 机器学习入门-交叉验证选择参数(数据切分)train_test_split(under_x, under_y, test_size, random_state), (交叉验证的数据切分)KFold, recall_score(召回率)

    1. train_test_split(under_x, under_y, test_size=0.3, random_state=0)  # under_x, under_y 表示输入数据, tes ...

  5. mysql 1292-Truncated incorrect double value

    sql = "select id from company where date_year_month = %s" % "2017-3" 出错 将%s改为'%s ...

  6. Mysql 知识(2)

    1. 为查询缓存优化你的查询 大多数的MySQL服务器都开启了查询缓存.这是提高性最有效的方法之一,而且这是被MySQL的数据库引擎处理的.当有很多相同的查询被执行了多次的时候,这些查询结果会被放到一 ...

  7. Centos 安装golang beego

    刚开始用go和beego,真的还好多不懂~希望对看到的朋友有帮助~ 本人环境:centos 6.3x86_64 1.我在机器上创建了一个用户zww(useradd zww),登录zww(su zww) ...

  8. fabric应用

    安装: easy_install fabric 或 pip install fabric 验证: #python >>> import  fabric 有时候我们可以直接使用命令行的 ...

  9. python语法学习之函数、类、模块

    Python中通过使用类(class)和对象(object)来实现面向对象(object-oriented programming,简称OOP)的编程. 面向对象编程的最主要目的是提高程序的重复使用性 ...

  10. 根据class操作div显示与隐藏

    <div class="otherComment" > <!-- style="display:none" --> 测试 </di ...