@Component
public class WorkerService {
private static final Logger logger = LoggerFactory
.getLogger(WorkerService.class);
@Autowired
private QueueService queueService;
@Autowired
private NoticeClient noticeClient;
@Value("${file.store.path}")
private String fileStorePath;
public final int BUFSIZE = 1024 * 8;
@PostConstruct
public void init() {
this.processMerge();
this.processNotice();
}
/**
* 启动发送上传完成通知的线程
*/
private void processMerge() {
queueService.rightPop("merge", new Worker() {
@Override
public void process(final String content) {
String[] array = content.split(",");
String name = array[0];
long size = Long.valueOf(array[1]);
File iso = new File(fileStorePath, name + ".iso");
if (!iso.exists()) {
long block = size / 1048576 + (size % 1048576 > 0 ? 1 : 0);
List<File> fileList = new ArrayList<>();
for (long i = 0; i < block; i++) {
fileList.add(new File(fileStorePath + "/" + name, String.valueOf(i)));
}
mergeFiles(iso,fileList);
}
if(name.startsWith("97")) {
queueService.leftPush("state", content);
}
if(iso.exists()){
File folder = new File(fileStorePath, name);
try {
FileUtils.deleteDirectory(folder);
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}