public static Class<?> loadClass(ClassLoader loader, String typeName) { if (loader == null) throw new IllegalArgumentException("Class loader to inspect must not be null."); if (typeName == null) throw new IllegalArgumentException("Class name to find must not be null."); try { return loader.loadClass(typeName); } catch (ClassNotFoundException | LinkageError e) { throw new ContainerException("Could not locate class [" + typeName + "] in Loader [" + loader + "]", e); } }
public static Class<?> loadClass(ClassLoader loader, Class<?> type) { if (loader == null) throw new IllegalArgumentException("Class loader to inspect must not be null."); if (type == null) throw new IllegalArgumentException("Class to find must not be null."); try { return loader.loadClass(type.getName()); } catch (ClassNotFoundException | LinkageError e) { throw new ContainerException("Could not locate class [" + type.getName() + "] in Loader [" + loader + "]", e); } }
public static void waitUntilStarted(Addon addon) { try { while (!addon.getStatus().isStarted()) { Thread.sleep(10); } } catch (Exception e) { throw new ContainerException("Addon [" + addon + "] was not started.", e); } }
private void waitUntilStarted() { while (furnace.getStatus().isStarting()) { try { Thread.sleep(10); } catch (InterruptedException e) { throw new ContainerException("Interrputed while waiting for STARTED state.", e); } } }
public static void waitUntilStopped(Addon addon) { if (addon != null) { try { while (addon.getStatus().isStarted()) { Thread.sleep(10); } } catch (Exception e) { throw new ContainerException("Addon [" + addon + "] was not stopped.", e); } } }
public static void waitUntilStarted(Addon addon, int quantity, TimeUnit unit) throws TimeoutException { long start = System.currentTimeMillis(); long threshold = start + TimeUnit.MILLISECONDS.convert(quantity, unit); while (!addon.getStatus().isStarted()) { if (System.currentTimeMillis() > threshold) { throw new TimeoutException("Timeout expired waiting for [" + addon + "] to start."); } try { Thread.sleep(10); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new ContainerException("Addon [" + addon + "] was not started.", e); } } }
public static void waitUntilStopped(Addon addon, int quantity, TimeUnit unit) throws TimeoutException { if (addon != null) { long start = System.currentTimeMillis(); long threshold = start + TimeUnit.MILLISECONDS.convert(quantity, unit); while (addon.getStatus().isStarted()) { if (System.currentTimeMillis() > threshold) { throw new TimeoutException("Timeout expired waiting for [" + addon + "] to stop."); } try { Thread.sleep(10); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new ContainerException("Addon [" + addon + "] was not stopped.", e); } } } }
@Override public T get() { T delegate = null; try { delegate = type.newInstance(); delegate = Proxies.enhance(addon.getClassLoader(), delegate, new ClassLoaderInterceptor(addon.getClassLoader(), delegate)); } catch (Exception e) { throw new ContainerException("Could not create instance of [" + type.getName() + "] through reflection.", e); } return delegate; }
/** * Waits until the specified {@link Addon} starts or is missing */ public static void waitUntilStartedOrMissing(Addon addon, int quantity, TimeUnit unit) throws TimeoutException { if (addon != null) { long start = System.currentTimeMillis(); long threshold = start + TimeUnit.MILLISECONDS.convert(quantity, unit); while (!addon.getStatus().isStarted() && !addon.getStatus().isMissing()) { if (System.currentTimeMillis() > threshold) { throw new TimeoutException("Timeout expired waiting for [" + addon + "] to load."); } try { Thread.sleep(10); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new ContainerException("Addon [" + addon + "] was not loaded.", e); } } } }
@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); } }
@Override public T get() { if (delegate == null) { try { delegate = type.newInstance(); delegate = Proxies.enhance(addon.getClassLoader(), delegate, new ClassLoaderInterceptor( addon.getClassLoader(), delegate)); } catch (Exception e) { throw new ContainerException("Could not create instance of [" + type.getName() + "] through reflection.", e); } } return delegate; }
private T newInstance() { try { T delegate = producer.newInstance().get(); delegate = Proxies.enhance(addon.getClassLoader(), delegate, new ClassLoaderInterceptor(addon.getClassLoader(), delegate)); return delegate; } catch (Exception e) { throw new ContainerException("Could not create instance of [" + type.getName() + "] through reflection.", e); } }
throw new ContainerException( "Cannot handle producer for non-Field and non-Method member type: " + member);
throw new ContainerException("Problems encountered during propagation of event [" + event + "] with qualifiers [" + qualifiers + "]", e);
@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); } }
throw new ContainerException("Command [" + line + "] did not respond.", e);