public static void buildMappings(URL[] urls, final String driverName, final JDBCMetaDataConfiguration result) throws Exception { ClassLoaders.executeIn(urls, new Callable<Void>() { @Override public Void call() throws Exception { Driver driver = (Driver) Class.forName(driverName, true, Thread.currentThread().getContextClassLoader()) .newInstance(); DelegatingDriver delegatingDriver = new DelegatingDriver(driver); try { DriverManager.registerDriver(delegatingDriver); result.readFromJDBC(); } finally { DriverManager.deregisterDriver(delegatingDriver); } return null; } }); }
testClass = ClassLoaders.loadClass(addon.getClassLoader(), testClassName);
for (Addon addon : registry.getAddons(AddonFilters.allStarted())) if (ClassLoaders.containsClass(addon.getClassLoader(), serviceType))
@Override public void run() { try { ClassLoaders.executeIn(loader, new Callable<Object>() { @Override public Object call() throws Exception { System.setProperty(FurnaceImpl.TEST_MODE_PROPERTY, "true"); furnace.setServerMode(true); furnace.start(loader); SecurityActions.cleanupThreadLocals(thread); return null; } }); } catch (Exception e) { throw new RuntimeException("Failed to start Furnace container.", e); } }
public static <T extends Descriptor> DescriptorImporter<T> importAs(final Class<T> type, final String descriptorName) throws IllegalArgumentException { try { return ClassLoaders.executeIn(type.getClassLoader(), new Callable<DescriptorImporter<T>>() { @Override public DescriptorImporter<T> call() throws Exception { return org.jboss.shrinkwrap.descriptor.api.Descriptors.importAs(type, descriptorName); } }); } catch (Exception e) { throw new RuntimeException(e); } } }
public static <T extends Descriptor> T create(final Class<T> type) throws IllegalArgumentException { try { return ClassLoaders.executeIn(type.getClassLoader(), new Callable<T>() { @Override public T call() throws Exception { return org.jboss.shrinkwrap.descriptor.api.Descriptors.create(type); } }); } catch (Exception e) { throw new RuntimeException(e); } }
public static <T extends Descriptor> T create(final Class<T> type, final String descriptorName) throws IllegalArgumentException { try { return ClassLoaders.executeIn(type.getClassLoader(), new Callable<T>() { @Override public T call() throws Exception { return org.jboss.shrinkwrap.descriptor.api.Descriptors.create(type, descriptorName); } }); } catch (Exception e) { throw new RuntimeException(e); } }
public static <T extends Descriptor> DescriptorImporter<T> importAs(final Class<T> type) throws IllegalArgumentException { try { return ClassLoaders.executeIn(type.getClassLoader(), new Callable<DescriptorImporter<T>>() { @Override public DescriptorImporter<T> call() throws Exception { return org.jboss.shrinkwrap.descriptor.api.Descriptors.importAs(type); } }); } catch (Exception e) { throw new RuntimeException(e); } }
public <T> T lookup(final Class<T> type) { try { return ClassLoaders.executeIn(Thread.currentThread().getContextClassLoader(), new Callable<T>() { @Override public T call() throws Exception { return getPlexusContainer().lookup(type); } }); } catch (Exception e) { throw new RuntimeException("Could not look up component of type [" + type.getName() + "]", e); } }
@Override protected void handleThisPreShutdown() { try { ClassLoaders.executeIn(Thread.currentThread().getContextClassLoader(), new Callable<Void>() { @Override public Void call() throws Exception { if (plexusContainer != null) { plexusContainer.dispose(); plexusContainer = null; } return null; } }); } catch (Exception e) { throw new RuntimeException("Error encountered while disposing PlexusContainer", e); } }
plexusContainer = ClassLoaders.executeIn(Thread.currentThread().getContextClassLoader(), new Callable<DefaultPlexusContainer>()
/** * Execute the given {@link Callable} by creating an {@link URLClassLoader} from the given {@link URL} array. * <p/> * Return the result, if any. */ public static <T> T executeIn(URL[] urls, Callable<T> callable) throws Exception { ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader(); URLClassLoader newClassLoader = null; try { newClassLoader = new URLClassLoader(urls, savedClassLoader); return executeIn(newClassLoader, callable); } finally { Streams.closeQuietly(newClassLoader); } }
ClassLoaders.executeIn(TransformerFactory.class.getClassLoader(), new Callable<Object>()
@SuppressWarnings("unchecked") public Object get(final InjectionPoint injectionPoint) { // FIXME remove the need for this method (which is currently still not working right for producer methods that // require an InjectionPoint Callable<Object> task = new Callable<Object>() { @Override public Object call() throws Exception { Bean<R> bean = (Bean<R>) manager.resolve(manager.getBeans(actualType, ServiceRegistryImpl.getQualifiersFrom(actualType))); context = manager.createCreationalContext(bean); Object delegate = manager.getInjectableReference(injectionPoint, context); return Proxies.enhance(addon.getClassLoader(), delegate, new ClassLoaderInterceptor(addon.getClassLoader(), delegate)); } }; try { return ClassLoaders.executeIn(addon.getClassLoader(), task); } catch (Exception e) { throw new ContainerException("Failed to get instance of [" + actualType + "] from addon [" + addon + "]", e); } }
String userName = p.getProperty("hibernate.connection.username"); String password = p.getProperty("hibernate.connection.password"); return ClassLoaders.executeIn(urls, new Callable<Database>()
ClassLoaders.executeIn(TransformerFactory.class.getClassLoader(), () -> { xsltTransformer = transformerFactory.newTransformer(xsltSource); return null;
@Override @SuppressWarnings("unchecked") public R get() { Callable<Object> task = new Callable<Object>() { @Override public Object call() throws Exception { context = manager.createCreationalContext(requestedBean); Object delegate = manager.getReference(requestedBean, actualType, context); return Proxies.enhance(addon.getClassLoader(), delegate, new ClassLoaderInterceptor(addon.getClassLoader(), delegate)); } }; try { return (R) ClassLoaders.executeIn(addon.getClassLoader(), task); } catch (Exception e) { throw new ContainerException("Failed to enhance instance of [" + actualType + "] with proxy for ClassLoader [" + addon.getClassLoader() + "]", e); } }