@Override public Map<String,String> namespaceIdMap() { return Namespaces.getNameToIdMap(context).entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().canonicalID(), (v1, v2) -> { throw new RuntimeException(String.format("Duplicate key for values %s and %s", v1, v2)); }, TreeMap::new)); }
@Override public SortedSet<String> list() { OpTimer timer = null; if (log.isTraceEnabled()) { log.trace("tid={} Fetching list of namespaces...", Thread.currentThread().getId()); timer = new OpTimer().start(); } TreeSet<String> namespaces = new TreeSet<>(Namespaces.getNameToIdMap(context).keySet()); if (timer != null) { timer.stop(); log.trace("tid={} Fetched {} namespaces in {}", Thread.currentThread().getId(), namespaces.size(), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS))); } return namespaces; }
/** * Lookup table ID in ZK. If not found, clears cache and tries again. */ public static Table.ID _getTableId(ClientContext context, String tableName) throws NamespaceNotFoundException, TableNotFoundException { Table.ID tableId = getNameToIdMap(context).get(tableName); if (tableId == null) { // maybe the table exist, but the cache was not updated yet... so try to clear the cache and // check again clearCache(context); tableId = getNameToIdMap(context).get(tableName); if (tableId == null) { String namespace = qualify(tableName).getFirst(); if (Namespaces.getNameToIdMap(context).containsKey(namespace)) throw new TableNotFoundException(null, tableName, null); else throw new NamespaceNotFoundException(null, namespace, null); } } return tableId; }