public ClasspathScanningPrimitiveTypeRegistry(ClassLoader classLoader) { Map<String, PrimitiveType> types = CACHE.computeIfAbsent(classLoader, cl -> { final Map<String, PrimitiveType> result = new ConcurrentHashMap<>(); final String[] whitelistPackages = StringUtils.split(System.getProperty("io.atomix.whitelistPackages"), ","); final ClassGraph classGraph = whitelistPackages != null ? new ClassGraph().enableClassInfo().whitelistPackages(whitelistPackages).addClassLoader(classLoader) : new ClassGraph().enableClassInfo().addClassLoader(classLoader); try (final ScanResult scanResult = classGraph.scan()) { scanResult.getClassesImplementing(PrimitiveType.class.getName()).forEach(classInfo -> { if (classInfo.isInterface() || classInfo.isAbstract() || Modifier.isPrivate(classInfo.getModifiers())) { return; } final PrimitiveType primitiveType = newInstance(classInfo.loadClass()); final PrimitiveType oldPrimitiveType = result.put(primitiveType.name(), primitiveType); if (oldPrimitiveType != null) { LOGGER.warn("Found multiple primitives types name={}, classes=[{}, {}]", primitiveType.name(), oldPrimitiveType.getClass().getName(), primitiveType.getClass().getName()); } }); } return Collections.unmodifiableMap(result); }); primitiveTypes.putAll(types); }
@SuppressWarnings("unchecked") private ClasspathScanningRegistry(ClassLoader classLoader, Set<String> whitelistPackages) { final Map<Class<? extends NamedType>, Map<String, NamedType>> registrations = CACHE.computeIfAbsent(classLoader, cl -> { final ClassGraph classGraph = !whitelistPackages.isEmpty() ? new ClassGraph().enableClassInfo().whitelistPackages(whitelistPackages.toArray(new String[0])).addClassLoader(classLoader) : new ClassGraph().enableClassInfo().addClassLoader(classLoader); try (final ScanResult scanResult = classGraph.scan()) { final Map<Class<? extends NamedType>, Map<String, NamedType>> result = new ConcurrentHashMap<>(); scanResult.getClassesImplementing(NamedType.class.getName()).forEach(classInfo -> { if (classInfo.isInterface() || classInfo.isAbstract() || Modifier.isPrivate(classInfo.getModifiers())) { return; } final Class<?> type = classInfo.loadClass(); final Class<? extends NamedType> classType = getClassType(type); final NamedType instance = newInstance(type); final NamedType oldInstance = result.computeIfAbsent(classType, t -> new HashMap<>()).put(instance.name(), instance); if (oldInstance != null) { LOGGER.warn("Found multiple types with name={}, classes=[{}, {}]", instance.name(), oldInstance.getClass().getName(), instance.getClass().getName()); } }); return result; } }); this.registrations.putAll(registrations); }
scanResult.getClassesWithAnnotation(AtomixResource.class.getName()).forEach(classInfo -> { deployment.getRegistry().addPerInstanceResource(classInfo.loadClass(), "/v1"); });
@SuppressWarnings("unchecked") private ClasspathScanningRegistry(ClassLoader classLoader, Set<String> whitelistPackages) { final Map<Class<? extends NamedType>, Map<String, NamedType>> registrations = CACHE.computeIfAbsent(classLoader, cl -> { final ClassGraph classGraph = !whitelistPackages.isEmpty() ? new ClassGraph().enableClassInfo().whitelistPackages(whitelistPackages.toArray(new String[0])).addClassLoader(classLoader) : new ClassGraph().enableClassInfo().addClassLoader(classLoader); try (final ScanResult scanResult = classGraph.scan()) { final Map<Class<? extends NamedType>, Map<String, NamedType>> result = new ConcurrentHashMap<>(); scanResult.getClassesImplementing(NamedType.class.getName()).forEach(classInfo -> { if (classInfo.isInterface() || classInfo.isAbstract() || Modifier.isPrivate(classInfo.getModifiers())) { return; } final Class<?> type = classInfo.loadClass(); final Class<? extends NamedType> classType = getClassType(type); final NamedType instance = newInstance(type); final NamedType oldInstance = result.computeIfAbsent(classType, t -> new HashMap<>()).put(instance.name(), instance); if (oldInstance != null) { LOGGER.warn("Found multiple types with name={}, classes=[{}, {}]", instance.name(), oldInstance.getClass().getName(), instance.getClass().getName()); } }); return result; } }); this.registrations.putAll(registrations); }
scanResult.getClassesWithAnnotation(AtomixResource.class.getName()).forEach(classInfo -> { deployment.getRegistry().addPerInstanceResource(classInfo.loadClass(), "/v1"); });