public static void hasText(String text) { hasText(text, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank"); }
public static void hasText(String text) { hasText(text, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank"); }
public HttpCmdProc getCmdProcessor(String nodeIdentity, String command) { Assert.hasText(nodeIdentity, "nodeIdentity can't be empty"); Map<String, HttpCmdProc> cmdProcessorMap = NODE_PROCESSOR_MAP.get(nodeIdentity); if (cmdProcessorMap == null) { return null; } return cmdProcessorMap.get(command); }
public HttpCmdProc getCmdProcessor(String nodeIdentity, String command) { Assert.hasText(nodeIdentity, "nodeIdentity can't be empty"); Map<String, HttpCmdProc> cmdProcessorMap = NODE_PROCESSOR_MAP.get(nodeIdentity); if (cmdProcessorMap == null) { return null; } return cmdProcessorMap.get(command); }
public void addCmdProcessor(HttpCmdProc proc) { if (proc == null) { throw new IllegalArgumentException("proc can not be null"); } String identity = proc.nodeIdentity(); Assert.hasText(identity, "nodeIdentity can't be empty"); String command = proc.getCommand(); Assert.hasText(command, "command can't be empty"); Map<String, HttpCmdProc> cmdProcessorMap = NODE_PROCESSOR_MAP.get(identity); if (cmdProcessorMap == null) { lock.lock(); cmdProcessorMap = NODE_PROCESSOR_MAP.get(identity); if (cmdProcessorMap == null) { cmdProcessorMap = new ConcurrentHashMap<String, HttpCmdProc>(); NODE_PROCESSOR_MAP.put(identity, cmdProcessorMap); } lock.unlock(); } cmdProcessorMap.put(command, proc); }
public void addCmdProcessor(HttpCmdProc proc) { if (proc == null) { throw new IllegalArgumentException("proc can not be null"); } String identity = proc.nodeIdentity(); Assert.hasText(identity, "nodeIdentity can't be empty"); String command = proc.getCommand(); Assert.hasText(command, "command can't be empty"); Map<String, HttpCmdProc> cmdProcessorMap = NODE_PROCESSOR_MAP.get(identity); if (cmdProcessorMap == null) { lock.lock(); cmdProcessorMap = NODE_PROCESSOR_MAP.get(identity); if (cmdProcessorMap == null) { cmdProcessorMap = new ConcurrentHashMap<String, HttpCmdProc>(); NODE_PROCESSOR_MAP.put(identity, cmdProcessorMap); } lock.unlock(); } cmdProcessorMap.put(command, proc); }
@Override public void checkProperties() throws ConfigPropertiesIllegalException { Assert.hasText(getClusterName(), "clusterName must have value."); Assert.hasText(getNodeGroup(), "nodeGroup must have value."); Assert.hasText(getRegistryAddress(), "registryAddress must have value."); Assert.isTrue(getWorkThreads() >= 0, "workThreads must >= 0."); }
@Override public void checkProperties() throws ConfigPropertiesIllegalException { Assert.hasText(getClusterName(), "clusterName must have value."); Assert.hasText(getNodeGroup(), "nodeGroup must have value."); Assert.hasText(getRegistryAddress(), "registryAddress must have value."); Assert.isTrue(getWorkThreads() >= 0, "workThreads must >= 0."); }
/** * 执行命令, 内部也就是一个http请求 */ public static <Resp extends HttpCmdResponse> Resp doGet(String ip, int port, HttpCmd<Resp> cmd) { Assert.hasText(cmd.getNodeIdentity(), "nodeIdentity can't be empty"); Assert.hasText(cmd.getCommand(), "command can't be empty"); StringBuilder sb = new StringBuilder(); sb.append("http://").append(ip).append(":").append(port).append("/").append(cmd.getNodeIdentity()).append("/").append(cmd.getCommand()); try { Map<String, String> params = cmd.getParams(); if (CollectionUtils.isNotEmpty(params)) { String prefix = "?"; for (Map.Entry<String, String> entry : params.entrySet()) { sb.append(prefix); prefix = "&"; sb.append(String.format("%s=%s", entry.getKey(), URLEncoder.encode(entry.getValue(), "UTF-8"))); } } return cmd.doGet(sb.toString()); } catch (Exception e) { throw new HttpCmdException(e); } }
/** * 执行命令, 内部也就是一个http请求 */ public static <Resp extends HttpCmdResponse> Resp doGet(String ip, int port, HttpCmd<Resp> cmd) { Assert.hasText(cmd.getNodeIdentity(), "nodeIdentity can't be empty"); Assert.hasText(cmd.getCommand(), "command can't be empty"); StringBuilder sb = new StringBuilder(); sb.append("http://").append(ip).append(":").append(port).append("/").append(cmd.getNodeIdentity()).append("/").append(cmd.getCommand()); try { Map<String, String> params = cmd.getParams(); if (CollectionUtils.isNotEmpty(params)) { String prefix = "?"; for (Map.Entry<String, String> entry : params.entrySet()) { sb.append(prefix); prefix = "&"; sb.append(String.format("%s=%s", entry.getKey(), URLEncoder.encode(entry.getValue(), "UTF-8"))); } } return cmd.doGet(sb.toString()); } catch (Exception e) { throw new HttpCmdException(e); } }
public static <Resp extends HttpCmdResponse> Resp doPost(String ip, int port, HttpCmd<Resp> cmd) { Assert.hasText(cmd.getNodeIdentity(), "nodeIdentity can't be empty"); Assert.hasText(cmd.getCommand(), "command can't be empty"); try { return cmd.doPost("http://" + ip + ":" + port + "/" + cmd.getNodeIdentity() + "/" + cmd.getCommand(), cmd.getParams()); } catch (Exception e) { throw new HttpCmdException(e); } } }
public static <Resp extends HttpCmdResponse> Resp doPost(String ip, int port, HttpCmd<Resp> cmd) { Assert.hasText(cmd.getNodeIdentity(), "nodeIdentity can't be empty"); Assert.hasText(cmd.getCommand(), "command can't be empty"); try { return cmd.doPost("http://" + ip + ":" + port + "/" + cmd.getNodeIdentity() + "/" + cmd.getCommand(), cmd.getParams()); } catch (Exception e) { throw new HttpCmdException(e); } } }
@Override public void run() { try { // 解析请求 HttpCmdRequest request = parseRequest(); Assert.notNull(request, "Request Error"); Assert.hasText(request.getCommand(), "Command is blank"); Assert.hasText(request.getNodeIdentity(), "nodeIdentity is blank"); HttpCmdProc httpCmdProc = context.getCmdProcessor(request.getNodeIdentity(), request.getCommand()); Assert.notNull(httpCmdProc, "Can not find the command:[" + request.getCommand() + "]"); sendResponse(HTTP_OK, JSON.toJSONString(httpCmdProc.execute(request))); } catch (HttpCMDErrorException ignored) { // 忽略 } catch (IllegalArgumentException e) { sendError(HTTP_BADREQUEST, JSON.toJSONString(HttpCmdResponse.newResponse(false, e.getMessage())), false); } catch (Throwable t) { LOGGER.error("Error When Execute Command", t); sendError(HTTP_INTERNALERROR, JSON.toJSONString(HttpCmdResponse.newResponse(false, "Error:" + t.getMessage())), false); } }
@Override public void run() { try { // 解析请求 HttpCmdRequest request = parseRequest(); Assert.notNull(request, "Request Error"); Assert.hasText(request.getCommand(), "Command is blank"); Assert.hasText(request.getNodeIdentity(), "nodeIdentity is blank"); HttpCmdProc httpCmdProc = context.getCmdProcessor(request.getNodeIdentity(), request.getCommand()); Assert.notNull(httpCmdProc, "Can not find the command:[" + request.getCommand() + "]"); sendResponse(HTTP_OK, JSON.toJSONString(httpCmdProc.execute(request))); } catch (HttpCMDErrorException ignored) { // 忽略 } catch (IllegalArgumentException e) { sendError(HTTP_BADREQUEST, JSON.toJSONString(HttpCmdResponse.newResponse(false, e.getMessage())), false); } catch (Throwable t) { LOGGER.error("Error When Execute Command", t); sendError(HTTP_INTERNALERROR, JSON.toJSONString(HttpCmdResponse.newResponse(false, "Error:" + t.getMessage())), false); } }