|
@@ -4,14 +4,44 @@ import com.zskk.dicom.monitor.config.Configs;
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+/**
|
|
|
+ * 所有runner基类
|
|
|
+ */
|
|
|
public abstract class BaseRunner implements Runnable{
|
|
|
|
|
|
- private int MIN_FAIL_SLEEP_TIME = 1;
|
|
|
- private int MAX_FAIL_SLEEP_TIME = 5;
|
|
|
+ /**
|
|
|
+ * 操作失败最小休眠时间(s)
|
|
|
+ */
|
|
|
+ private final int MIN_FAIL_SLEEP_TIME = 1;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 操作失败最大休眠时间(s)
|
|
|
+ */
|
|
|
+ private final int MAX_FAIL_SLEEP_TIME = 5;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 队列为空最小休眠时间(s)
|
|
|
+ */
|
|
|
+ private final int MIN_EMPTY_SLEEP_TIME = 2;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 队列为空最大休眠时间(s)
|
|
|
+ */
|
|
|
+ private final int MAX_EMPTY_SLEEP_TIME = 10;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 操作成功休眠时间(ms)
|
|
|
+ */
|
|
|
+ private final int SUCCESS_SLEEP_TIME = 10;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 操作失败休眠时间(s)
|
|
|
+ */
|
|
|
private int failSleepTime = 0;
|
|
|
|
|
|
- private int MIN_EMPTY_SLEEP_TIME = 2;
|
|
|
- private int MAX_EMPTY_SLEEP_TIME = 10;
|
|
|
+ /**
|
|
|
+ * 队列为空休眠时间
|
|
|
+ */
|
|
|
private int emptySleepTime = 0;
|
|
|
|
|
|
@Override
|
|
@@ -35,6 +65,10 @@ public abstract class BaseRunner implements Runnable{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 打印操作失败日志并休眠,同时操作失败休眠时间增加
|
|
|
+ * @throws InterruptedException
|
|
|
+ */
|
|
|
protected void printFailAndSleep() throws InterruptedException {
|
|
|
Configs.sysLog.warn(getRunnerName() + ": " + action() + " fail");
|
|
|
if(failSleepTime < MAX_FAIL_SLEEP_TIME) {
|
|
@@ -43,12 +77,21 @@ public abstract class BaseRunner implements Runnable{
|
|
|
TimeUnit.SECONDS.sleep(failSleepTime);
|
|
|
}
|
|
|
|
|
|
- protected void printSuccessAndSleep() {
|
|
|
- Configs.sysLog.info(getRunnerName() + ": " + action() + " success!" + getQueueName() + " size :" + size());
|
|
|
+ /**
|
|
|
+ * 打印操作成功日志并短暂休眠, 同时 操作失败(和队列为空)休眠时间 重置
|
|
|
+ * @throws InterruptedException
|
|
|
+ */
|
|
|
+ protected void printSuccessAndSleep() throws InterruptedException {
|
|
|
+ Configs.sysLog.info(getRunnerName() + ": " + action().getValue() + " success!" + getQueueName() + " size :" + size());
|
|
|
failSleepTime = 0;
|
|
|
emptySleepTime = 0;
|
|
|
+ TimeUnit.SECONDS.sleep(SUCCESS_SLEEP_TIME);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *打印队列为空日志并休眠,同时队列为空休眠时间增加
|
|
|
+ * @throws InterruptedException
|
|
|
+ */
|
|
|
protected void printEmptyAndSleep() throws InterruptedException {
|
|
|
Configs.sysLog.warn(getRunnerName() + ": " + getQueueName() + " is empty");
|
|
|
if(emptySleepTime < MAX_EMPTY_SLEEP_TIME) {
|
|
@@ -57,11 +100,45 @@ public abstract class BaseRunner implements Runnable{
|
|
|
TimeUnit.SECONDS.sleep(emptySleepTime);
|
|
|
}
|
|
|
|
|
|
- protected abstract String action();
|
|
|
+ /**
|
|
|
+ * 当前动作名
|
|
|
+ * @return 上传 移动 文件
|
|
|
+ */
|
|
|
+ protected abstract RunnerAction action();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 队列是否为空
|
|
|
+ * @return
|
|
|
+ */
|
|
|
protected abstract boolean empty();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当前队列大小
|
|
|
+ * @return
|
|
|
+ */
|
|
|
protected abstract int size();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取队列名称
|
|
|
+ * @return
|
|
|
+ */
|
|
|
protected abstract String getQueueName();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取runner名称
|
|
|
+ * @return
|
|
|
+ */
|
|
|
protected abstract String getRunnerName();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * runner操作
|
|
|
+ * @return
|
|
|
+ */
|
|
|
protected abstract boolean handle();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否runner执行完毕退出
|
|
|
+ * @return
|
|
|
+ */
|
|
|
protected abstract boolean exit();
|
|
|
}
|