@Test public void testGetPluginClassloaderInterrupted() throws InterruptedException { final AtomicReference<ClassLoader> classLoaderAtomicReference = new AtomicReference<>( null ); final AtomicReference<KettlePluginException> exceptionAtomicReference = new AtomicReference<>( null ); final Thread thread = new Thread( new Runnable() { @Override public void run() { try { classLoaderAtomicReference.set( pluginClassloaderGetter .getPluginClassloader( LifecyclePluginType.class.getCanonicalName(), ShimBridgingClassloader.HADOOP_SPOON_PLUGIN ) ); } catch ( KettlePluginException e ) { exceptionAtomicReference.set( e ); } } } ); when( pluginRegistry.getPluginTypes() ).thenAnswer( new Answer<List<Class<? extends PluginTypeInterface>>>() { @Override public List<Class<? extends PluginTypeInterface>> answer( InvocationOnMock invocation ) throws Throwable { new Thread( new Runnable() { @Override public void run() { synchronized ( pluginRegistry ) { thread.interrupt(); } } } ).start(); return new ArrayList<>(); } } ); thread.start(); thread.join(); assertTrue( exceptionAtomicReference.get() instanceof KettlePluginException ); assertNull( classLoaderAtomicReference.get() ); }
public ClassLoader getPluginClassloader( String pluginType, String pluginId ) throws KettlePluginException { Class<? extends PluginTypeInterface> pluginTypeInterface = null; PluginRegistry pluginRegistry = this.pluginRegistry; while ( true ) { synchronized ( pluginRegistry ) { if ( pluginTypeInterface == null ) { for ( Class<? extends PluginTypeInterface> potentialPluginTypeInterface : pluginRegistry.getPluginTypes() ) { if ( pluginType.equals( potentialPluginTypeInterface.getCanonicalName() ) ) { pluginTypeInterface = potentialPluginTypeInterface; } } } PluginInterface plugin = pluginRegistry.getPlugin( pluginTypeInterface, pluginId ); if ( plugin != null ) { return pluginRegistry.getClassLoader( plugin ); } try { pluginRegistry.wait(); } catch ( InterruptedException e ) { throw new KettlePluginException( e ); } } } }
PluginClassloaderGetter { public ClassLoader getPluginClassloader( String pluginType, String pluginId ) throws KettlePluginException { Class<? extends PluginTypeInterface> pluginTypeInterface = null; PluginRegistry pluginRegistry = this.pluginRegistry; while ( true ) { synchronized ( pluginRegistry ) { if ( pluginTypeInterface == null ) { for ( Class<? extends PluginTypeInterface> potentialPluginTypeInterface : pluginRegistry.getPluginTypes() ) { if ( pluginType.equals( potentialPluginTypeInterface.getCanonicalName() ) ) { pluginTypeInterface = potentialPluginTypeInterface; } } } PluginInterface plugin = pluginRegistry.getPlugin( pluginTypeInterface, pluginId ); if ( plugin != null ) { return pluginRegistry.getClassLoader( plugin ); } try { pluginRegistry.wait(); } catch ( InterruptedException e ) { throw new KettlePluginException( e ); } } } } }
PluginClassloaderGetter { public ClassLoader getPluginClassloader( String pluginType, String pluginId ) throws KettlePluginException { Class<? extends PluginTypeInterface> pluginTypeInterface = null; PluginRegistry pluginRegistry = this.pluginRegistry; while ( true ) { synchronized ( pluginRegistry ) { if ( pluginTypeInterface == null ) { for ( Class<? extends PluginTypeInterface> potentialPluginTypeInterface : pluginRegistry.getPluginTypes() ) { if ( pluginType.equals( potentialPluginTypeInterface.getCanonicalName() ) ) { pluginTypeInterface = potentialPluginTypeInterface; } } } PluginInterface plugin = pluginRegistry.getPlugin( pluginTypeInterface, pluginId ); if ( plugin != null ) { return pluginRegistry.getClassLoader( plugin ); } try { pluginRegistry.wait(); } catch ( InterruptedException e ) { throw new KettlePluginException( e ); } } } } PluginClassloaderGetter();  PluginClassloaderGetter( PluginRegistry pluginRegistry ); }
PluginClassloaderGetter { public ClassLoader getPluginClassloader( String pluginType, String pluginId ) throws KettlePluginException { Class<? extends PluginTypeInterface> pluginTypeInterface = null; PluginRegistry pluginRegistry = this.pluginRegistry; while ( true ) { synchronized ( pluginRegistry ) { if ( pluginTypeInterface == null ) { for ( Class<? extends PluginTypeInterface> potentialPluginTypeInterface : pluginRegistry.getPluginTypes() ) { if ( pluginType.equals( potentialPluginTypeInterface.getCanonicalName() ) ) { pluginTypeInterface = potentialPluginTypeInterface; } } } PluginInterface plugin = pluginRegistry.getPlugin( pluginTypeInterface, pluginId ); if ( plugin != null ) { return pluginRegistry.getClassLoader( plugin ); } try { pluginRegistry.wait(); } catch ( InterruptedException e ) { throw new KettlePluginException( e ); } } } } PluginClassloaderGetter();  PluginClassloaderGetter( PluginRegistry pluginRegistry ); ClassLoader getPluginClassloader( String pluginType, String pluginId ); }
PluginClassloaderGetter { public ClassLoader getPluginClassloader( String pluginType, String pluginId ) throws KettlePluginException { Class<? extends PluginTypeInterface> pluginTypeInterface = null; PluginRegistry pluginRegistry = this.pluginRegistry; while ( true ) { synchronized ( pluginRegistry ) { if ( pluginTypeInterface == null ) { for ( Class<? extends PluginTypeInterface> potentialPluginTypeInterface : pluginRegistry.getPluginTypes() ) { if ( pluginType.equals( potentialPluginTypeInterface.getCanonicalName() ) ) { pluginTypeInterface = potentialPluginTypeInterface; } } } PluginInterface plugin = pluginRegistry.getPlugin( pluginTypeInterface, pluginId ); if ( plugin != null ) { return pluginRegistry.getClassLoader( plugin ); } try { pluginRegistry.wait(); } catch ( InterruptedException e ) { throw new KettlePluginException( e ); } } } } PluginClassloaderGetter();  PluginClassloaderGetter( PluginRegistry pluginRegistry ); ClassLoader getPluginClassloader( String pluginType, String pluginId );  }