@Test public void testGetPluginClassloader() throws InterruptedException { final AtomicReference<ClassLoader> classLoaderAtomicReference = new AtomicReference<>( null ); final AtomicReference<KettlePluginException> exceptionAtomicReference = new AtomicReference<>( null ); final ClassLoader classLoader = mock( ClassLoader.class ); when( pluginRegistry.getPluginTypes() ).thenAnswer( new Answer<List<Class<? extends PluginTypeInterface>>>() { private int invocationNum = 0; @Override public List<Class<? extends PluginTypeInterface>> answer( InvocationOnMock invocation ) throws Throwable { if ( invocationNum == 0 ) { new Thread( new Runnable() { @Override public void run() { synchronized ( pluginRegistry ) { pluginRegistry.notifyAll(); } } } ).start(); invocationNum++; return new ArrayList<>(); } else if ( invocationNum == 1 ) { invocationNum++; return new ArrayList<Class<? extends PluginTypeInterface>>( Arrays.asList( StepPluginType.class, LifecyclePluginType.class ) ); } else { throw new Exception( "Only expected to be called twice" ); } } } ); when( pluginRegistry.getPlugin( LifecyclePluginType.class, ShimBridgingClassloader.HADOOP_SPOON_PLUGIN ) ) .thenAnswer( new Answer<PluginInterface>() { private int invocationNum = 0; @Override public PluginInterface answer( InvocationOnMock invocation ) throws Throwable { if ( invocationNum == 0 ) { new Thread( new Runnable() { @Override public void run() { synchronized ( pluginRegistry ) { pluginRegistry.notifyAll(); } } } ).start(); invocationNum++; return null; } else if ( invocationNum == 1 ) { invocationNum++; PluginInterface pluginInterface = mock( PluginInterface.class ); when( pluginRegistry.getClassLoader( pluginInterface ) ).thenReturn( classLoader ); return pluginInterface; } else { throw new Exception( "Only expected to be called twice" ); } } } ); 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 ); } } } ); thread.start(); thread.join(); assertNull( exceptionAtomicReference.get() ); assertEquals( classLoader, 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 );  }