@Override public void subscribe(Class<?> service, String version) throws Exception { for (String each : this.zoo.getChildren( this.road.roadmap(this.road.path(service, version)), ZkContext.WATCH)) { try { String path = this.road.path(service, version, each); ZkSerial node = this.serial.serial(this.zoo.getData(path, ZkContext.WATCH, null), ZkSerial.class); if (node.version(version)) { this.put(node, path); } } catch (Exception e) { e.printStackTrace(); ZkContext.LOGGER.error(e.getMessage(), e); } } }
private void put(ZkSerial node, String path) throws Exception { // 加锁Service all version (粗粒度) synchronized (node.service()) { // 同步GetOrCreate this.context.get(node.service(), node.version()).put(node.host()); } this.imported.put(path, node.host()); this.connect.connect(node.host()); }