BpPC(Breakpoint Producer-Consumer)
项目介绍:
实现文件读取的断点记录,下次在断点位置继续读取。 解决读取文件时突然中断的问题,如断电导致电脑关机。
设计模式:
Created with Raphaël 2.1.0
输入文件:File
生产者:BpProducer
输入队列:Queue
中间消费者:MidConsumer
输出队列:Queue
写出消费者:BpConsumer
输出文件:File
项目组成:
archon.bppc.model.
BpContext: 上下文对象,保存输入输出文件、队列以及常量配置类BpProperties等;
BpObject: 输入输出队列的通用数据类型;
BpProperties: 常量配置类。
archon.bppc.pruducer.
abstract BpProducer: 生产者;
StringBpProducer: String类型的生产者。
archon.bppc.consumer.
abstract BpConsumer: 写出消费者;
abstract MidConsumer: 中间消费者;
StringBpConsumer: String类型的写出消费者。
archon.bppc.controller.
final BpController: 主控类,控制生产到消费的全过程。
archon.bppc.delegate: 代理接口。
archon.bppc.example: 演示程序。
功能:
串行处理多目录下的多文件,但不包含子目录。每个目录都需要单独配置。(可以实现并行处理)
简单使用:
public final class StringExample {
private static final String IN_DIR =
"F:/bppc/in/";
private static final String OUT_DIR =
"F:/bppc/out/";
private static final String TMP_DIR =
"F:/bppc/tmp/";
public static void main(String[] args) {
BpProperties bpProperties = BpProperties.getDefaultBpProperties();
bpProperties.setInDirPath(IN_DIR);
bpProperties.setOutDirPath(OUT_DIR);
bpProperties.setTmpDirPath(TMP_DIR);
BpProducer bpProducer =
new StringBpProducer();
BpConsumer bpConsumer =
new StringBpConsumer();
MidConsumer midConsumer =
new MidConsumer() {
@Override
protected String
transform(String inValue) {
try {
Thread.sleep(
100);
}
catch (InterruptedException e) {
e.printStackTrace();
}
return inValue +
"\ta";
}
}
BpController<String, String> controller =
new BpController<>(bpProperties, bpProducer, midConsumer, bpConsumer);
controller.run();
}
}
更多用法在example包里。
资源
Github: AlexGumHub / BreakpointProducerConsumer
OSChina: AlexGum / BreakpointProducerConsumer
转载请注明原文地址: https://ju.6miu.com/read-1298731.html