package com.zy.core;
|
|
import com.core.common.SpringUtils;
|
import com.zy.core.plugin.MainProcessPluginApi;
|
import com.zy.core.properties.SystemProperties;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Component;
|
import javax.annotation.PreDestroy;
|
|
/**
|
* WCS主流程
|
*/
|
@Slf4j
|
@Component
|
public class MainProcess {
|
|
@Value("${mainProcessPlugin}")
|
private String mainProcessPlugin;
|
private MainProcessPluginApi mainProcessPluginApi;
|
// 所属线程
|
private Thread thread;
|
|
/**
|
* =====>> 开始工作
|
*/
|
public void start(){
|
thread = new Thread(() -> {
|
while (!Thread.currentThread().isInterrupted()) {
|
try {
|
if (mainProcessPluginApi == null) {
|
String className = mainProcessPlugin.contains(".") ? mainProcessPlugin : "com.zy.core.plugin." + mainProcessPlugin;
|
Class<? extends MainProcessPluginApi> clazz = Class.forName(className).asSubclass(MainProcessPluginApi.class);
|
mainProcessPluginApi = SpringUtils.getBean(clazz);
|
}
|
|
// 系统运行状态判断
|
if (!SystemProperties.WCS_RUNNING_STATUS.get()) {
|
continue;
|
}
|
|
mainProcessPluginApi.run();
|
// 间隔
|
Thread.sleep(200);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
});
|
thread.start();
|
}
|
|
@PreDestroy
|
public void shutDown(){
|
if (thread != null) thread.interrupt();
|
}
|
|
}
|