@Override // @wjw_note: 在Zookeeper上注册ScheduleServer public void registerScheduleServer(ScheduleServer server) throws Exception { if (server.isRegisted() == true) { throw new Exception(server.getUuid() + " 被重复注册"); } String realPath = null; // 此处必须增加UUID作为唯一性保障 StringBuilder id = new StringBuilder(); id.append(server.getIp()) .append("$") .append(UUID.randomUUID().toString().replaceAll("-", "").toUpperCase()); String zkServerPath = pathServer + "/" + id.toString() + "$"; realPath = this.getZooKeeper() .create(zkServerPath, null, this.zkManager.getAcl(), CreateMode.PERSISTENT_SEQUENTIAL); server.setUuid(realPath.substring(realPath.lastIndexOf("/") + 1)); Timestamp heartBeatTime = new Timestamp(getSystemTime()); server.setHeartBeatTime(heartBeatTime); String valueString = this.gson.toJson(server); this.getZooKeeper().setData(realPath, valueString.getBytes(), -1); server.setRegisted(true); }