io.github.lukehutch.fastclasspathscanner.scanner.ScanResult Java Examples
The following examples show how to use
io.github.lukehutch.fastclasspathscanner.scanner.ScanResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractServiceAutomaticHandlerRegistrationTest.java From ja-micro with Apache License 2.0 | 6 votes |
@Test public void it_should_find_handlers() throws Exception { TestService service = new TestService(); service.initializeGuice(); FastClasspathScanner scanner = new FastClasspathScanner(); ScanResult scanResult = scanner.scan(); List<String> rpcHandlers = scanResult.getNamesOfClassesWithAnnotation(RpcHandler.class); service.registerMethodHandlers(rpcHandlers); Map<String, ServiceMethodHandler<? extends Message, ? extends Message>> s = service.getMethodHandlers(); assertThat(s.size() == 2); assertThat(s.containsKey("Test.handler1")); assertThat(s.containsKey("Test.handler2")); assertThat(s.get("Test.handler1").getClass().equals(TestHandler.class)); assertThat(s.get("Test.handler2").getClass().equals(TestHandler2.class)); }
Example #2
Source File: ClassScanner.java From bender with Apache License 2.0 | 6 votes |
public static Set<Class> getSubtypes(List<Class> clazzes) throws InterruptedException, ExecutionException { Set<Class> classSet = new HashSet<Class>(); int threads = Runtime.getRuntime().availableProcessors(); ExecutorService pool = Executors.newFixedThreadPool(threads); Future<ScanResult> futureScan = new FastClasspathScanner("com.nextdoor.bender").scanAsync(pool, threads); ScanResult s = futureScan.get(); for (Class<? extends AbstractConfig<?>> clazz : clazzes) { s.getNamesOfSubclassesOf(clazz).forEach(c -> { try { classSet.add((Class<? extends AbstractConfig<?>>) Class.forName(c)); } catch (ClassNotFoundException e) { } }); } pool.shutdown(); /* * Remove abstract classes as they are not allowed in the mapper */ classSet.removeIf(p -> Modifier.isAbstract(p.getModifiers()) == true); return classSet; }
Example #3
Source File: ProtocolSerializer.java From reef with Apache License 2.0 | 6 votes |
/** * Finds all of the messages in the specified packaged and calls register. * @param messagePackage A string which contains the full name of the * package containing the protocol messages. */ @Inject private ProtocolSerializer( @Parameter(ProtocolSerializerNamespace.class) final String messagePackage) { // Build a list of the message reflection classes. final ScanResult scanResult = new FastClasspathScanner(messagePackage).scan(); final List<String> scanNames = scanResult.getNamesOfSubclassesOf(SpecificRecordBase.class); final List<Class<?>> messageClasses = scanResult.classNamesToClassRefs(scanNames); // Add the header message from the org.apache.reef.wake.avro.message package. messageClasses.add(Header.class); // Register all of the messages in the specified package. for (final Class<?> cls : messageClasses) { this.register(cls); } }
Example #4
Source File: RpcMethodScanner.java From ja-micro with Apache License 2.0 | 5 votes |
public List<String> getGeneratedProtoClasses(String serviceName) { FastClasspathScanner cpScanner = new FastClasspathScanner(); ScanResult scanResult = cpScanner.scan(); List<String> oldProtobuf = scanResult.getNamesOfSubclassesOf(GeneratedMessage.class); List<String> newProtobuf = scanResult.getNamesOfSubclassesOf(GeneratedMessageV3.class); List<String> retval = Stream.concat(oldProtobuf.stream(), newProtobuf.stream()).collect(Collectors.toList()); String[] packageTokens = serviceName.split("\\."); return retval.stream().filter(s -> protoFilePackageMatches(s, packageTokens)).collect(Collectors.toList()); }
Example #5
Source File: MethodIdentifier.java From typesafeconfig-guice with Apache License 2.0 | 5 votes |
public boolean matchesMethod(Class<?> clazz, Method method, ScanResult scanResult) { if (clazz.getName().equals(className) && method.getName().equals(methodName) && method.getParameterCount() == parameterTypeSignature.length) { boolean paramsMatch = true; for (int i = 0; i < parameterTypeSignature.length; i++) { paramsMatch = paramsMatch && parameterTypeSignature[i].instantiate(scanResult) == method.getParameters()[i].getType(); } return paramsMatch; } return false; }
Example #6
Source File: MethodIdentifier.java From typesafeconfig-guice with Apache License 2.0 | 5 votes |
public boolean matchesConstructor(Class<?> clazz, Constructor<?> constructor, ScanResult scanResult) { if (clazz.getCanonicalName().equals(className) && methodName.equals("<init>") && constructor.getParameterCount() == parameterTypeSignature.length) { boolean paramsMatch = true; for (int i = 0; i < parameterTypeSignature.length; i++) { paramsMatch = paramsMatch && parameterTypeSignature[i].instantiate(scanResult) == constructor.getParameters()[i].getType(); } return paramsMatch; } return false; }
Example #7
Source File: FastclassPathScannerProvider.java From nubes with Apache License 2.0 | 5 votes |
public FastclassPathScannerProvider(String ppackage){ packageName = ppackage; if (cachedScans.containsKey(ppackage)){ }else{ FastClasspathScanner fastClasspathScanner = new FastClasspathScanner(ppackage); ScanResult scanResult = fastClasspathScanner.scan(); cachedScans.put(ppackage, scanResult); } }