public static void scanClassPathForFormattingAnnotations ( ) { ExecutorService executorService = Executors . newFixedThreadPool ( Runtime . getRuntime ( ) . availableProcessors ( ) * 2 ) ; // scan classpath and filter out classes that don't begin with "com.nds" Reflections reflections = new Reflections ( "com.nds" , "com.cisco" ) ; Set < Class < ? > > annotated = reflections . getTypesAnnotatedWith ( DefaultFormat . class ) ; // Reflections ciscoReflections = new Reflections("com.cisco"); // // annotated.addAll(ciscoReflections.getTypesAnnotatedWith(DefaultFormat.class)); for ( Class < ? > markerClass : annotated ) { // if the marker class is indeed implementing FoundationLoggingMarker // interface if ( FoundationLoggingMarker . class . isAssignableFrom ( markerClass ) ) { final Class < ? extends FoundationLoggingMarker > clazz = ( Class < ? extends FoundationLoggingMarker > ) markerClass ; executorService . execute ( new Runnable ( ) { @ Override public void run ( ) { if ( markersMap . get ( clazz ) == null ) { try { // generate formatter class for this marker // class generateAndUpdateFormatterInMap ( clazz ) ; } catch ( Exception e ) { LOGGER . trace ( "problem generating formatter class from static scan method. error is: " + e . toString ( ) ) ; } } } } ) ; } else { // if marker class does not implement FoundationLoggingMarker // interface, log ERROR // verify the LOGGER was initialized. It might not be as this // Method is called in a static block if ( LOGGER == null ) { LOGGER = LoggerFactory . getLogger ( AbstractFoundationLoggingMarker . class ) ; } LOGGER . error ( "Formatter annotations should only appear on foundationLoggingMarker implementations" ) ; } } try { TimeUnit . SECONDS . sleep ( 30 ) ; } catch ( InterruptedException e ) { LOGGER . trace ( e . toString ( ) , e ) ; } executorService . shutdown ( ) ; // try { // executorService.awaitTermination(15, TimeUnit.SECONDS); // } catch (InterruptedException e) { // LOGGER.error("creation of formatters has been interrupted"); // } }
Scan all the class path and look for all classes that have the Format Annotations .