OSGi karaf scheduler
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的更多相关文章
- Karaf 依赖equinox and felix,karaf 本Apache的很多项目作为基础框架
6月17日是Apache Karaf作为Apache顶级项目.Karaf是个运行时包,包含了一个OSGi框架(Equinox或Felix).一个命令shell(Felix Gogo)及默认情况下内置的 ...
- AndroidStudio3.0无法打开Android Device Monitor的解决办法(An error has occurred on Android Device Monitor)
---恢复内容开始--- 打开monitor时出现 An error has occurred. See the log file... ------------------------------- ...
- Karaf 基于 osgi
Karaf是Apache旗下的一个开源项目.Karaf同时也是一个基于OSGi的运行环境,Karaf提供了一个轻量级的OSGi容器,可以用于部署各种组件,应用程序.Karaf提供了很多特性用于帮助开发 ...
- 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 ...
- 关于Karaf Container 4.0.7
Karaf是Apache旗下的一个开源项目.Karaf同时也是一个基于OSGi的运行环境,Karaf提供了一个轻量级的OSGi容器,可以用于部署各种组件,应用程序.Karaf提供了很多 ...
- OSGI框架学习
OSGI框架三个重要概念 OSGi框架是根据OSGi规范中定义的三个概念层设计的:模块.模块生命周期.服务. 模块层定义了OSGi模块的概念(bundle,即包含一个元数据MANIFEST.MF的JA ...
- osgi实战学习之路:5.生命周期及利用命令、装饰者模式实现基于socket交互Bundle命令demo
生命周期中关键3个类: BundleActivator 入口点,类似main方法 BundleContext Bundle上下文对象,在执行期间,为应用程序提供操作osgi框架的方法 Bundle 代 ...
- osgi实战学习之路:3. osgi分层概念及相互合作demo
源码下载 分层: modual: 主要作用于包级管理与共享代码 lifecycle: 主要作用于执行期间的模块管理与訪问osgi底层框架 service: 主要作用于多模块之间的相互通信 demo: ...
- 深入理解OSGI:Java模块化之路
简介 Java可能是近20年来最成功的开发技术,因其具备通用性.高效性.平台移植性和安全性而成为不同硬件平台理想的开发工具.从笔记本电脑到数据中心,从游戏控制台到科学超级计算机,从手机到互联网,Jav ...
随机推荐
- 20180129周一之学习PYTHON笔记【安装、查看工作目录、】
一,安装过程中多选一个ADD的项,免去设置环境变量. 二,PYAUTOGUI模块控制键鼠. IMAGE模块. ----------------------python 如何查看与更换工作目录----- ...
- 通过cookie验证用户登录
# cookie # cookie# 当你在浏览器登陆时,浏览器记录这个登录信息(服务器响应时发送请求的数据和登录信息),再次访问时 浏览器会将访问请求和缓存的登录信息都发送到服务器, # 服务器通过 ...
- yum lnmp
1.关闭防火墙 [root@CentOS ~]# chkconfig iptables off 2.关闭selinux vi /etc/sysconfig/selinux //将SELINUX=e ...
- 写了个TP5下PHP和手机端通信的API接口校验
写了个PHP和手机端通信的API接口校验 直接发函数吧 public function _initialize() { //定义密码和盐 $password="123456"; $ ...
- 练习Laravel Homestead的安装
1 安装VirtualBox和Vagrant 在启动Homestead环境之前,你必须安装VirtualBox(https://www.virtualbox.org/wiki/Downloads)和V ...
- 13.mysql基本查询
1. 给表起个别名:但是,前面的也是需要进行修改的,否则会报错的: select * from s.name from students as s; 2. 为字段起别名 select s,name a ...
- ajax调用json
//var data_str='({"detail":[{"html":"科技科技科技有限公司"},{"html":&q ...
- 字符串和JSON对象互转的方法
采用Ajax的项目开发过程中,经常需要将JSON格式的字符串返回到前端,前端解析成JS对象(JSON ).字符串转JSON对象 1.eval方式解析.function strToJson(str){ ...
- as3 关闭加载流
/** Loader 取消加载**/ function closeQueueLoader():void { if (cur_loader && cur_loader.contentLo ...
- MySQL设置快速删除
SET FOREIGN_KEY_CHECKS=0; DROP DATABASE ... SET FOREIGN_KEY_CHECKS=1;