/** * Extract all service records under a list of stat operations...this * non-atomic action skips entries that are too short or simply not matching. * <p> * @param operations operation support for fetches * @param parentpath path of the parent of all the entries * @return a possibly empty map of fullpath:record. * @throws IOException for any IO Operation that wasn't ignored. */ public static Map<String, ServiceRecord> extractServiceRecords( RegistryOperations operations, String parentpath, Map<String , RegistryPathStatus> stats) throws IOException { return extractServiceRecords(operations, parentpath, stats.values()); }
/** * Extract all service records under a list of stat operations...this * non-atomic action skips entries that are too short or simply not matching. * <p> * @param operations operation support for fetches * @param parentpath path of the parent of all the entries * @return a possibly empty map of fullpath:record. * @throws IOException for any IO Operation that wasn't ignored. */ public static Map<String, ServiceRecord> extractServiceRecords( RegistryOperations operations, String parentpath, Map<String , RegistryPathStatus> stats) throws IOException { return extractServiceRecords(operations, parentpath, stats.values()); }
/** * Extract all service records under a list of stat operations...this * non-atomic action skips entries that are too short or simply not matching. * <p> * @param operations operation support for fetches * @param parentpath path of the parent of all the entries * @return a possibly empty map of fullpath:record. * @throws IOException for any IO Operation that wasn't ignored. */ public static Map<String, ServiceRecord> extractServiceRecords( RegistryOperations operations, String parentpath) throws IOException { return extractServiceRecords(operations, parentpath, statChildren(operations, parentpath).values()); }
/** * Extract all service records under a list of stat operations...this * non-atomic action skips entries that are too short or simply not matching. * <p> * @param operations operation support for fetches * @param parentpath path of the parent of all the entries * @return a possibly empty map of fullpath:record. * @throws IOException for any IO Operation that wasn't ignored. */ public static Map<String, ServiceRecord> extractServiceRecords( RegistryOperations operations, String parentpath) throws IOException { return extractServiceRecords(operations, parentpath, statChildren(operations, parentpath).values()); }
/** * List service records directly under a path * @param registryOperations registry operations instance * @param path path to list * @return a mapping of the service records that were resolved, indexed * by their full path * @throws IOException */ public static Map<String, ServiceRecord> listServiceRecords( RegistryOperations registryOperations, String path) throws IOException { Map<String, RegistryPathStatus> children = statChildren(registryOperations, path); return extractServiceRecords(registryOperations, path, children.values()); }
/** * List service records directly under a path * @param registryOperations registry operations instance * @param path path to list * @return a mapping of the service records that were resolved, indexed * by their full path * @throws IOException */ public static Map<String, ServiceRecord> listServiceRecords( RegistryOperations registryOperations, String path) throws IOException { Map<String, RegistryPathStatus> children = statChildren(registryOperations, path); return extractServiceRecords(registryOperations, path, children.values()); }
@Override public void nodeAdded(String path) throws IOException { // get a listing of service records String relativePath = getPathRelativeToRegistryRoot(path); String child = RegistryPathUtils.lastPathEntry(path); Map<String, RegistryPathStatus> map = new HashMap<>(); map.put(child, registryOperations.stat(relativePath)); Map<String, ServiceRecord> records = RegistryUtils.extractServiceRecords(registryOperations, getAdjustedParentPath(path), map); processServiceRecords(records, register); pathToRecordMap.putAll(records); }
try { znodes = statChildren(registryOperations, path); recordMap = extractServiceRecords(registryOperations, path, znodes.values());
try { znodes = statChildren(registryOperations, path); recordMap = extractServiceRecords(registryOperations, path, znodes.values());
@Test public void testLsParent() throws Throwable { ServiceRecord written = putExampleServiceEntry(ENTRY_PATH, 0); RegistryPathStatus stat = operations.stat(ENTRY_PATH); List<String> children = operations.list(PARENT_PATH); assertEquals(1, children.size()); assertEquals(NAME, children.get(0)); Map<String, RegistryPathStatus> childStats = RegistryUtils.statChildren(operations, PARENT_PATH); assertEquals(1, childStats.size()); assertEquals(stat, childStats.get(NAME)); Map<String, ServiceRecord> records = RegistryUtils.extractServiceRecords(operations, PARENT_PATH, childStats.values()); assertEquals(1, records.size()); ServiceRecord record = records.get(ENTRY_PATH); RegistryTypeUtils.validateServiceRecord(ENTRY_PATH, record); assertMatches(written, record); }
@Test public void testLsParent() throws Throwable { ServiceRecord written = putExampleServiceEntry(ENTRY_PATH, 0); RegistryPathStatus stat = operations.stat(ENTRY_PATH); List<String> children = operations.list(PARENT_PATH); assertEquals(1, children.size()); assertEquals(NAME, children.get(0)); Map<String, RegistryPathStatus> childStats = RegistryUtils.statChildren(operations, PARENT_PATH); assertEquals(1, childStats.size()); assertEquals(stat, childStats.get(NAME)); Map<String, ServiceRecord> records = RegistryUtils.extractServiceRecords(operations, PARENT_PATH, childStats.values()); assertEquals(1, records.size()); ServiceRecord record = records.get(ENTRY_PATH); RegistryTypeUtils.validateServiceRecord(ENTRY_PATH, record); assertMatches(written, record); }
componentStats = children.values(); Map<String, ServiceRecord> records = RegistryUtils.extractServiceRecords(operations, componentsPath, componentStats); assertEquals(2, records.size()); RegistryUtils.extractServiceRecords(operations, componentsPath, childrenUpdated);