shuzheng 9 лет назад
Родитель
Сommit
f0e00693c3

+ 9 - 0
cms/cms-web/pom.xml

@@ -35,6 +35,15 @@
             <groupId>javax.servlet</groupId>
             <artifactId>jstl</artifactId>
         </dependency>
+        <!-- tbschedule -->
+        <dependency>
+            <groupId>com.taobao.pamirs.schedule</groupId>
+            <artifactId>tbschedule</artifactId>
+            <version>3.2.8-SNAPSHOT</version>
+            <scope>system</scope>
+            <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/tbschedule-3.2.8-SNAPSHOT.jar
+            </systemPath>
+        </dependency>
     </dependencies>
 
     <profiles>

+ 58 - 0
cms/cms-web/src/main/java/com/zheng/cms/schedule/LongSchedule.java

@@ -0,0 +1,58 @@
+package com.zheng.cms.schedule;
+
+import com.taobao.pamirs.schedule.IScheduleTaskDealSingle;
+import com.taobao.pamirs.schedule.TaskItemDefine;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * 测试任务
+ * Created by zhangshuzheng on 2016/11/14.
+ */
+public class LongSchedule implements IScheduleTaskDealSingle<Long> {
+
+    /**
+     * 执行单个任务
+     * @param item Object
+     * @param ownSign 当前环境名称
+     * @throws Exception
+     */
+    @Override
+    public boolean execute(Long item, String ownSign) throws Exception {
+        System.out.println("执行任务:" + item);
+        return true;
+    }
+
+    /**
+     * 根据条件,查询当前调度服务器可处理的任务
+     * @param taskParameter 任务的自定义参数
+     * @param ownSign 当前环境名称
+     * @param taskItemNum 当前任务类型的任务队列数量
+     * @param taskItemList 当前调度服务器,分配到的可处理队列
+     * @param eachFetchDataNum 每次获取数据的数量
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public List<Long> selectTasks(String taskParameter, String ownSign, int taskItemNum, List<TaskItemDefine> taskItemList, int eachFetchDataNum) throws Exception {
+        List<Long> allDrawList = new ArrayList<>();
+        allDrawList.add(System.currentTimeMillis());
+        return allDrawList;
+    }
+
+    /**
+     * 获取任务的比较器,只有在NotSleep模式下需要用到
+     * @return
+     */
+    @Override
+    public Comparator<Long> getComparator() {
+        return new Comparator<Long>() {
+            public int compare(Long o1, Long o2) {
+                return o1.compareTo(o2);
+            }
+        };
+    }
+
+}

+ 63 - 0
cms/cms-web/src/main/java/com/zheng/cms/schedule/MapSchedule.java

@@ -0,0 +1,63 @@
+package com.zheng.cms.schedule;
+
+import com.taobao.pamirs.schedule.IScheduleTaskDealSingle;
+import com.taobao.pamirs.schedule.TaskItemDefine;
+
+import java.util.*;
+
+/**
+ * 测试任务
+ * Created by zhangshuzheng on 2016/11/14.
+ */
+public class MapSchedule implements IScheduleTaskDealSingle<Map> {
+
+    /**
+     * 执行单个任务
+     * @param item Object
+     * @param ownSign 当前环境名称
+     * @throws Exception
+     */
+    @Override
+    public boolean execute(Map item, String ownSign) throws Exception {
+        System.out.println("执行任务:" + item);
+        return true;
+    }
+
+    /**
+     * 根据条件,查询当前调度服务器可处理的任务
+     * @param taskParameter 任务的自定义参数
+     * @param ownSign 当前环境名称
+     * @param taskItemNum 当前任务类型的任务队列数量
+     * @param taskItemList 当前调度服务器,分配到的可处理队列
+     * @param eachFetchDataNum 每次获取数据的数量
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public List<Map> selectTasks(String taskParameter, String ownSign, int taskItemNum, List<TaskItemDefine> taskItemList, int eachFetchDataNum) throws Exception {
+        List<Map> allDrawList = new ArrayList<>();
+        Map map = new HashMap();
+        map.put("ID", System.currentTimeMillis());
+        allDrawList.add(map);
+        return allDrawList;
+    }
+
+    /**
+     * 获取任务的比较器,只有在NotSleep模式下需要用到
+     * @return
+     */
+    @Override
+    public Comparator<Map> getComparator() {
+        return new Comparator<Map>() {
+            public int compare(Map o1, Map o2) {
+                Long l1 = (Long) o1.get("ID");
+                Long l2 = (Long) o2.get("ID");
+                return l1.compareTo(l2);
+            }
+            public boolean equals(Object obj) {
+                return this == obj;
+            }
+        };
+    }
+
+}

BIN
cms/cms-web/src/main/webapp/WEB-INF/lib/tbschedule-3.2.8-SNAPSHOT.jar