@Test public void loadUnloadApplication() throws Exception { LocalResourcePool resourcePool = new LocalResourcePool("pool1"); DependencyResolver dep = new DependencyResolver(tmpDir.getAbsolutePath()); ApplicationLoader appLoader = new ApplicationLoader(resourcePool, dep); HeliumPackage pkg1 = createPackageInfo(MockApplication1.class.getName(), "artifact1"); ApplicationContext context1 = createContext("note1", "paragraph1", "app1"); MockApplication1 app = (MockApplication1) ((ClassLoaderApplication) appLoader.load(pkg1, context1)).getInnerApplication(); assertFalse(app.isUnloaded()); assertEquals(0, app.getNumRun()); app.unload(); assertTrue(app.isUnloaded()); assertEquals(0, app.getNumRun()); }
public Application load(HeliumPackage packageInfo, ApplicationContext context) throws Exception { if (packageInfo.getType() != HeliumPackage.Type.APPLICATION) { throw new ApplicationException( "Can't instantiate " + packageInfo.getType() + " package using ApplicationLoader"); } RunningApplication key = new RunningApplication(packageInfo, context.getNoteId(), context.getParagraphId()); ResourceSet resources = findRequiredResourceSet(packageInfo.getResources(), context.getNoteId(), context.getParagraphId()); Class<Application> appClass = loadClass(packageInfo); ClassLoader oldcl = Thread.currentThread().getContextClassLoader(); ClassLoader cl = appClass.getClassLoader(); Thread.currentThread().setContextClassLoader(cl); try { Constructor<Application> constructor = appClass.getConstructor(ApplicationContext.class); Application app = new ClassLoaderApplication(constructor.newInstance(context), cl); return app; } catch (Exception e) { throw new ApplicationException(e); } finally { Thread.currentThread().setContextClassLoader(oldcl); } }
ApplicationLoader { public Application load(HeliumPackage packageInfo, ApplicationContext context) throws Exception { if (packageInfo.getType() != HeliumPackage.Type.APPLICATION) { throw new ApplicationException( "Can't instantiate " + packageInfo.getType() + " package using ApplicationLoader"); } RunningApplication key = new RunningApplication(packageInfo, context.getNoteId(), context.getParagraphId()); ResourceSet resources = findRequiredResourceSet(packageInfo.getResources(), context.getNoteId(), context.getParagraphId()); Class<Application> appClass = loadClass(packageInfo); ClassLoader oldcl = Thread.currentThread().getContextClassLoader(); ClassLoader cl = appClass.getClassLoader(); Thread.currentThread().setContextClassLoader(cl); try { Constructor<Application> constructor = appClass.getConstructor(ApplicationContext.class); Application app = new ClassLoaderApplication(constructor.newInstance(context), cl); return app; } catch (Exception e) { throw new ApplicationException(e); } finally { Thread.currentThread().setContextClassLoader(oldcl); } } }
ApplicationLoader { public Application load(HeliumPackage packageInfo, ApplicationContext context) throws Exception { if (packageInfo.getType() != HeliumPackage.Type.APPLICATION) { throw new ApplicationException( "Can't instantiate " + packageInfo.getType() + " package using ApplicationLoader"); } RunningApplication key = new RunningApplication(packageInfo, context.getNoteId(), context.getParagraphId()); ResourceSet resources = findRequiredResourceSet(packageInfo.getResources(), context.getNoteId(), context.getParagraphId()); Class<Application> appClass = loadClass(packageInfo); ClassLoader oldcl = Thread.currentThread().getContextClassLoader(); ClassLoader cl = appClass.getClassLoader(); Thread.currentThread().setContextClassLoader(cl); try { Constructor<Application> constructor = appClass.getConstructor(ApplicationContext.class); Application app = new ClassLoaderApplication(constructor.newInstance(context), cl); return app; } catch (Exception e) { throw new ApplicationException(e); } finally { Thread.currentThread().setContextClassLoader(oldcl); } } ApplicationLoader(ResourcePool resourcePool, DependencyResolver depResolver); }
ApplicationLoader { public Application load(HeliumPackage packageInfo, ApplicationContext context) throws Exception { if (packageInfo.getType() != HeliumPackage.Type.APPLICATION) { throw new ApplicationException( "Can't instantiate " + packageInfo.getType() + " package using ApplicationLoader"); } RunningApplication key = new RunningApplication(packageInfo, context.getNoteId(), context.getParagraphId()); ResourceSet resources = findRequiredResourceSet(packageInfo.getResources(), context.getNoteId(), context.getParagraphId()); Class<Application> appClass = loadClass(packageInfo); ClassLoader oldcl = Thread.currentThread().getContextClassLoader(); ClassLoader cl = appClass.getClassLoader(); Thread.currentThread().setContextClassLoader(cl); try { Constructor<Application> constructor = appClass.getConstructor(ApplicationContext.class); Application app = new ClassLoaderApplication(constructor.newInstance(context), cl); return app; } catch (Exception e) { throw new ApplicationException(e); } finally { Thread.currentThread().setContextClassLoader(oldcl); } } ApplicationLoader(ResourcePool resourcePool, DependencyResolver depResolver); Application load(HeliumPackage packageInfo, ApplicationContext context); ResourceSet findRequiredResourceSet(
      String [][] requiredResources, String noteId, String paragraphId); }
ApplicationLoader { public Application load(HeliumPackage packageInfo, ApplicationContext context) throws Exception { if (packageInfo.getType() != HeliumPackage.Type.APPLICATION) { throw new ApplicationException( "Can't instantiate " + packageInfo.getType() + " package using ApplicationLoader"); } RunningApplication key = new RunningApplication(packageInfo, context.getNoteId(), context.getParagraphId()); ResourceSet resources = findRequiredResourceSet(packageInfo.getResources(), context.getNoteId(), context.getParagraphId()); Class<Application> appClass = loadClass(packageInfo); ClassLoader oldcl = Thread.currentThread().getContextClassLoader(); ClassLoader cl = appClass.getClassLoader(); Thread.currentThread().setContextClassLoader(cl); try { Constructor<Application> constructor = appClass.getConstructor(ApplicationContext.class); Application app = new ClassLoaderApplication(constructor.newInstance(context), cl); return app; } catch (Exception e) { throw new ApplicationException(e); } finally { Thread.currentThread().setContextClassLoader(oldcl); } } ApplicationLoader(ResourcePool resourcePool, DependencyResolver depResolver); Application load(HeliumPackage packageInfo, ApplicationContext context); ResourceSet findRequiredResourceSet(
      String [][] requiredResources, String noteId, String paragraphId);  }