Introducing new features.两种一致性hash 算法+轮询
正在显示
4 个修改的文件
包含
9 行增加
和
4 行删除
| @@ -11,5 +11,10 @@ import java.util.List; | @@ -11,5 +11,10 @@ import java.util.List; | ||
| 11 | */ | 11 | */ |
| 12 | public interface RouteHandle { | 12 | public interface RouteHandle { |
| 13 | 13 | ||
| 14 | - String selectServer(List<String> values) ; | 14 | + /** |
| 15 | + * 再一批服务器里进行路由 | ||
| 16 | + * @param values | ||
| 17 | + * @return | ||
| 18 | + */ | ||
| 19 | + String routeServer(List<String> values) ; | ||
| 15 | } | 20 | } |
| @@ -17,7 +17,7 @@ public class ConsistentHashHandle implements RouteHandle { | @@ -17,7 +17,7 @@ public class ConsistentHashHandle implements RouteHandle { | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | @Override | 19 | @Override |
| 20 | - public String selectServer(List<String> values) { | 20 | + public String routeServer(List<String> values) { |
| 21 | return null; | 21 | return null; |
| 22 | } | 22 | } |
| 23 | } | 23 | } |
| @@ -16,7 +16,7 @@ public class LoopHandle implements RouteHandle { | @@ -16,7 +16,7 @@ public class LoopHandle implements RouteHandle { | ||
| 16 | private AtomicLong index = new AtomicLong(); | 16 | private AtomicLong index = new AtomicLong(); |
| 17 | 17 | ||
| 18 | @Override | 18 | @Override |
| 19 | - public String selectServer(List<String> values) { | 19 | + public String routeServer(List<String> values) { |
| 20 | if (values.size() == 0) { | 20 | if (values.size() == 0) { |
| 21 | throw new RuntimeException("CIM 服务器可用服务列表为空"); | 21 | throw new RuntimeException("CIM 服务器可用服务列表为空"); |
| 22 | } | 22 | } |
| @@ -151,7 +151,7 @@ public class RouteController { | @@ -151,7 +151,7 @@ public class RouteController { | ||
| 151 | StatusEnum status = accountService.login(loginReqVO); | 151 | StatusEnum status = accountService.login(loginReqVO); |
| 152 | if (status == StatusEnum.SUCCESS) { | 152 | if (status == StatusEnum.SUCCESS) { |
| 153 | 153 | ||
| 154 | - String server = routeHandle.selectServer(serverCache.getAll()); | 154 | + String server = routeHandle.routeServer(serverCache.getAll()); |
| 155 | String[] serverInfo = server.split(":"); | 155 | String[] serverInfo = server.split(":"); |
| 156 | CIMServerResVO vo = new CIMServerResVO(serverInfo[0], Integer.parseInt(serverInfo[1]),Integer.parseInt(serverInfo[2])); | 156 | CIMServerResVO vo = new CIMServerResVO(serverInfo[0], Integer.parseInt(serverInfo[1]),Integer.parseInt(serverInfo[2])); |
| 157 | 157 |
-
请 注册 或 登录 后发表评论