houzhongjian
2024-11-22 49b510c77474fed0eff94e27f8d7a2d4e4cb7879
提交 | 用户 | 时间
e7c126 1 package com.xxl.job.admin.core.route;
H 2
3 import com.xxl.job.admin.core.route.strategy.*;
4 import com.xxl.job.admin.core.util.I18nUtil;
5
6 /**
7  * Created by xuxueli on 17/3/10.
8  */
9 public enum ExecutorRouteStrategyEnum {
10
11     FIRST(I18nUtil.getString("jobconf_route_first"), new ExecutorRouteFirst()),
12     LAST(I18nUtil.getString("jobconf_route_last"), new ExecutorRouteLast()),
13     ROUND(I18nUtil.getString("jobconf_route_round"), new ExecutorRouteRound()),
14     RANDOM(I18nUtil.getString("jobconf_route_random"), new ExecutorRouteRandom()),
15     CONSISTENT_HASH(I18nUtil.getString("jobconf_route_consistenthash"), new ExecutorRouteConsistentHash()),
16     LEAST_FREQUENTLY_USED(I18nUtil.getString("jobconf_route_lfu"), new ExecutorRouteLFU()),
17     LEAST_RECENTLY_USED(I18nUtil.getString("jobconf_route_lru"), new ExecutorRouteLRU()),
18     FAILOVER(I18nUtil.getString("jobconf_route_failover"), new ExecutorRouteFailover()),
19     BUSYOVER(I18nUtil.getString("jobconf_route_busyover"), new ExecutorRouteBusyover()),
20     SHARDING_BROADCAST(I18nUtil.getString("jobconf_route_shard"), null);
21
22     ExecutorRouteStrategyEnum(String title, ExecutorRouter router) {
23         this.title = title;
24         this.router = router;
25     }
26
27     private String title;
28     private ExecutorRouter router;
29
30     public String getTitle() {
31         return title;
32     }
33     public ExecutorRouter getRouter() {
34         return router;
35     }
36
37     public static ExecutorRouteStrategyEnum match(String name, ExecutorRouteStrategyEnum defaultItem){
38         if (name != null) {
39             for (ExecutorRouteStrategyEnum item: ExecutorRouteStrategyEnum.values()) {
40                 if (item.name().equals(name)) {
41                     return item;
42                 }
43             }
44         }
45         return defaultItem;
46     }
47
48 }