154 */ 155 public static ServicesCatalog getServicesCatalogOrNull(ClassLoader loader) { 156 return CLV.get(loader); 157 } 158 159 /** 160 * Returns the ServicesCatalog for the given class loader, creating it if 161 * needed. 162 */ 163 public static ServicesCatalog getServicesCatalog(ClassLoader loader) { 164 // CLV.computeIfAbsent(loader, (cl, clv) -> create()); 165 ServicesCatalog catalog = CLV.get(loader); 166 if (catalog == null) { 167 catalog = create(); 168 ServicesCatalog previous = CLV.putIfAbsent(loader, catalog); 169 if (previous != null) catalog = previous; 170 } 171 return catalog; 172 } 173 174 // the ServicesCatalog registered to a class loader 175 private static final ClassLoaderValue<ServicesCatalog> CLV = new ClassLoaderValue<>(); 176 } | 154 */ 155 public static ServicesCatalog getServicesCatalogOrNull(ClassLoader loader) { 156 return CLV.get(loader); 157 } 158 159 /** 160 * Returns the ServicesCatalog for the given class loader, creating it if 161 * needed. 162 */ 163 public static ServicesCatalog getServicesCatalog(ClassLoader loader) { 164 // CLV.computeIfAbsent(loader, (cl, clv) -> create()); 165 ServicesCatalog catalog = CLV.get(loader); 166 if (catalog == null) { 167 catalog = create(); 168 ServicesCatalog previous = CLV.putIfAbsent(loader, catalog); 169 if (previous != null) catalog = previous; 170 } 171 return catalog; 172 } 173 174 static void setServicesCatalog(ClassLoader loader, ServicesCatalog catalog) { 175 ServicesCatalog previous = CLV.putIfAbsent(loader, catalog); 176 if (previous != null) { 177 throw new RuntimeException("unexpected: " + previous); 178 } 179 } 180 181 // the ServicesCatalog registered to a class loader 182 private static final ClassLoaderValue<ServicesCatalog> CLV = new ClassLoaderValue<>(); 183 } |