@ SuppressWarnings ( "unchecked" ) private static List < Class < RDDProcessor > > findProcessorClassesInPackage ( String packageName ) { List < Class < RDDProcessor >> streamProcClasses = new ArrayList < Class < RDDProcessor > > ( ) ; try { ClassLoader classLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; String path = packageName . replace ( ' ' , ' ' ) ; Enumeration < URL > resources = classLoader . getResources ( path ) ; Set < String > classes = new TreeSet < String > ( ) ; while ( resources . hasMoreElements ( ) ) { URL resource = ( URL ) resources . nextElement ( ) ; classes . addAll ( findClasses ( resource . getFile ( ) , packageName ) ) ; } for ( String classInPackage : classes ) { Class < ? > theClass = classLoader . loadClass ( classInPackage ) ; if ( RDDProcessor . class . isAssignableFrom ( theClass ) ) streamProcClasses . add ( ( Class < RDDProcessor > ) theClass ) ; } } catch ( Exception e ) { // safe to squelch this as it's just looking for streamProcs to run e . printStackTrace ( ) ; } return streamProcClasses ; }
Scans Jar files on the classpath for RDDProcessor implementations to activate .