- 授权协议: Apache
- 开发语言: Java
- 操作系统: 跨平台
- 软件首页: https://github.com/jiuxiantuan/mossrose
- 软件文档: https://github.com/jiuxiantuan/mossrose/blob/master/README.md
- 官方下载: https://github.com/jiuxiantuan/mossrose/archive/master.zip
软件介绍
Mossrose,高可用分布式调度框架
环境要求:
Zookeeper
Java 8
安装
<dependency> <groupId>com.jiuxian</groupId> <artifactId>mossrose</artifactId> <version>1.1.0-RELEASE</version> </dependency>
核心概念
SimpleJob
简单任务
DistributedJob
分布式任务,通过slice()方法将作业分隔成多个子任务,子任务在集群内分布执行
MossroseProcess
多个MossroseProcess组成集群,集群保证有且只有一个节点竞选成为主节点,主节点负责触发作业;所有节点都是工作节点,主节点触发的任务会在所有工作节点上分布执行
MossroseConfig
Mossrose配置,包括集群元信息和任务元信息
快速上手
实现一个简单任务
public class SomeJob implements SimpleJob {
@Override
public void execute() {
System.out.println("SimpleJob: " + UUID.randomUUID());
}
}配置任务 - mossrose.yaml
# Mossrose config info --- cluster: name: mossrose-example # 集群命名空间 loadBalancingMode: ROUND_ROBIN # 集群负载均衡策略,可选:ROUND_ROBIN/RANDOM jobs: - id: 1 # 作业ID group: test # 作业分组(可选) cron: 0/5 * * * * ? # 作业cron表达式 runInCluster: true # 是否在集群中分布执行,如果为false,则只在主节点上执行 main: com.jiuxian.mossrose.test.SomeJob # 作业类全名
运行mossrose主类
public class MainTest {
@Test
public void test() throws Exception {
String zks = "localhost"; // zookeeper集群地址
try (MossroseProcess process = new MossroseProcess(
MossroseConfigFactory.fromClasspathYamlFile("mossrose.yaml"),
new ZookeeperClusterDiscovery("/mossrose/jobtest", zks), zks)) {
process.run();
try {
// Block the unit test
Thread.sleep(60 * 60 * 1000);
} catch (InterruptedException e) {
}
}
}
}分布式任务
实现一个分布式任务
public class SomeDistributedJob implements DistributedJob {
@Override
public List slice() {
return Splitter.on(" ").splitToList("This is a test on the mossrose distributed job, how are you feeling?");
}
@Override
public void execute(String item) {
System.out.println(Thread.currentThread() + " DistributedJob: " + item);
}
}
算法竞赛入门经典
刘汝佳、陈锋 / 2012-10 / 52.80元
《算法竞赛入门经典:训练指南》是《算法竞赛入门经典》的重要补充,旨在补充原书中没有涉及或者讲解得不够详细的内容,从而构建一个较完整的知识体系,并且用大量有针对性的题目,让抽象复杂的算法和数学具体化、实用化。《算法竞赛入门经典:训练指南》共6章,分别为算法设计基础、数学基础、实用数据结构、几何问题、图论算法与模型和更多算法专题,全书通过近200道例题深入浅出地介绍了上述领域的各个知识点、经典思维方式......一起来看看 《算法竞赛入门经典》 这本书的介绍吧!
