public Classpath addAllFilesInDirectory(File folder) { if (folder.isDirectory()) { File[] files = folder.listFiles(); return add(files); } else { throw new IllegalArgumentException("The specified file object must represent a directory."); } }
public static Classpath create(String deployName) { return new Classpath(deployName); }
@Override public Set<Classpath> getPluginClasspaths() { checkState(); Set<Classpath> deployedClasspaths = new HashSet<>(); // Remove the shared classpath Iterator<Classpath> it = deploymentMap.keySet() .iterator(); while (it.hasNext()) { Classpath classpath = it.next(); if (classpath.equals(getSharedClasspath())) { continue; } else { deployedClasspaths.add(classpath.clone()); } } return deployedClasspaths; }
@Override public void classpathUndeployed(Classpath classpath) { if (classpath.hasDeployName()) { removePlugin(classpath.getDeployName()); } }
private void deploy() throws LimbusException, IOException { LimbusEngine limbusEngine = system.getComponent(LimbusEngine.class); List<URL> urls = new LinkedList<>(); List<JavaArchive> archives = new LinkedList<>(dependencies); for (JavaArchive a : archives) { addJavaArchiveAsURL(urls, a, null); } addJavaArchiveAsURL(urls, deployment, null); this.classpath = Classpath.create(deployName) .add(urls); limbusEngine.deployPlugin(classpath, permissions); }
/** * Searches a plugin in the {@link #workFolder()} folder. The plugin name is used as folder name. If * present, the classpath object is created and returned. * * @param deployName * The plugin name is the folder that contains the deployment. * * @return Returns the classpath object if the plugin folder is present. * @throws LimbusException * Thrown if the plugin is not deployed. */ private Classpath findPlugin(String deployName) throws LimbusException { checkState(); try { File pluginDirectory = getOrFailPluginDirectory(deployName); return Classpath.create(deployName) .addAllFilesInDirectory(pluginDirectory); } catch (Exception e) { throw new LimbusException("Cannot find plugin due to exception.", e); } }
private void _deployPlugin(Classpath classpath, Set<Permission> permissions) throws LimbusException { if (deploymentMap.containsKey(classpath)) { return; } log.info("Deploy process started for plugin classpath."); LimbusUtil.logClasspath("plugin", classpath, log); LimbusUtil.logPermissions("plugin", permissions, log); PluginClassLoader pluginClassLoader = new PluginClassLoader(filesystem, sharedClassLoader, classpath.getClasspath()); pluginClassLoader.setPermissions(permissions); Deployment deployment = new Deployment(classpath, pluginClassLoader); deploymentMap.put(classpath, deployment); _deployClasspath(deployment); log.info("Deploy process finished successfully."); if (classpath.hasDeployName()) { deploynames.put(classpath.getDeployName(), classpath); } // Notify deployment subscribers deploymentListeners.multicastSilently() .classpathDeployed(classpath); }
@Override public void run() { loadedURLs.setText(""); for (URL url : classpath.getClasspath()) { loadedURLs.addLine("- " + url.toString()); } } });
private void _undeployClasspath(Deployment deployment) { // Close the logging environment for this classpath if this classpath is not anonymous // Get the classloader before finishing the deployment (this will erase the reference) URLClassLoader classloader = deployment.getClassloader(); // Enqueue the classloader reference to the reference observer this.referenceObserver.observeReferenceTo(classloader); try { // Finish the deploy context and delete references deployment.finish(); } finally { // Close logTarget for plugin Classpath classpath = deployment.getClasspath(); if (classpath.hasDeployName()) { logTarget.closeChannel(classloader); } // Try to ad-hoc garbage collect the classloadfer. WeakReference<Object> classloaderWeakRef = new WeakReference<Object>(classloader); classloader = null; boolean garbageCollected = LimbusUtil.isGarbageCollected(classloaderWeakRef); if (garbageCollected) { log.info("Classloader was unloaded - the ad-hoc garbage collection was successful!"); } else { log.info( "The ad-hoc garbage collection was not successful - see log output of LimbusReferenceObserver to get long-term garbage collection notifications."); } } }
@Override public void checkClasspath() throws LimbusClasspathException { try { filesystem.createFolder(LIB_FOLDER, false); List<URL> classpathURLs = filesystem.getFolderFiles(LIB_FOLDER); // Create the shared classpath with a speaking name to give hints about the creator. this.classpath = Classpath.create("sharedClassPath_" + getClass().getName()) .add(classpathURLs); LimbusUtil.logClasspath("shared", classpath, log); } catch (Exception e) { throw new LimbusClasspathException(String.format("Cannot create or access the shared classpath."), e); } }
/** * Starts the deploy process for an artifact already present in the containers work directory. * * @param deployName * The deploy name * @param permissions * The permissions to be granted for classes of this classpath. * @throws LimbusException * Thrown on any error while deploying. */ @Override public void deployFromFilesystem(String deployName, Set<Permission> permissions) throws LimbusException { checkState(); try { File pluginDirectory = getCreateOrFailPluginDirectory(deployName); // Create the classpath of the deployed files Classpath classpath = Classpath.create(deployName) .addAllFilesInDirectory(pluginDirectory); container.deployPlugin(classpath, permissions); } catch (Exception e) { // Clean deployed files from work removePlugin(deployName); // Forward deploy exception throw new LimbusException(String.format("Cannot deploy the specified classpath with deploy name %s", deployName), e); } }
deploymentMap.remove(classpath); if (classpath.hasDeployName()) { deploynames.remove(classpath.getDeployName()); if (classpath.hasDeployName()) { log.info("Undeploy process started for plugin classpath {}.", classpath.getDeployName()); } else { log.info("Undeploying anonymous classpath");
static void logClasspath(String classpathName, Classpath classPath, Logger log) { Lang.denyNull("classpath name", classpathName); Lang.denyNull("classpath", classPath); Lang.denyNull("log", log); if (log.isDebugEnabled()) { Set<URL> urls = classPath.getClasspath(); if (urls.isEmpty()) { log.info("Logging {} classpath: Empty classpath.", classpathName); } else { log.info("Logging {} classpath:", classpathName); for (URL url : urls) { log.debug("URL entry: {}", url.toString()); } } } }
if (classpath.hasDeployName()) { message = String.format("Error while accessing plugin %s for plugin interface %s in deployment %s.", classname, pluginInterface.getName(), classpath.getDeployName()); } else { message = String.format("Error while accessing plugin %s for plugin interface %s.", classname,
@Override protected void performInitialize() throws Exception { // schuettec - 05.04.2017 : In earlier versions this was done in Engine Launcher. Workarounds.executePreventiveWorkarounds(); this.deploymentListeners = EventMulticasterFactory.create(DeploymentListener.class); this.referenceObserver = new LimbusReferenceObserver<ClassLoader>(); this.referenceObserver.initialize(); this.deploymentMap = new ConcurrentHashMap<Classpath, Deployment>(); this.deploynames = new ConcurrentHashMap<String, Classpath>(); // Deploy all components from shared classpath sharedClassPathProvider.checkClasspath(); Classpath sharedClasspath = sharedClassPathProvider.getSharedClasspath(); this.sharedClassLoader = new SharedClassLoader(filesystem, LimbusEngine.class.getClassLoader(), getAllowedPackagePrefixes(), sharedClasspath.getClasspath()); Deployment sharedDeployment = new Deployment(sharedClasspath, sharedClassLoader); deploymentMap.put(sharedClasspath, sharedDeployment); try { _deployClasspath(sharedDeployment); } catch (Exception e) { // If plugins from shared classpath fail to deploy we are not forced to shutdown the whole engine. log.warn("Error while deploying plugins from shared classpath.", e); } }
public static Classpath create() { return new Classpath(); }
if (classpath.hasDeployName()) { String deployName = classpath.getDeployName(); logTarget.openChannel(classLoader, deployName);
@Override public Container getComponent(final LimbusMaintenanceConsole console) { Panel panel = new Panel(new BorderLayout()); Label headLine = new Label("The following list shows the loaded URLs loaded in the shared classpath."); panel.addComponent(headLine, BorderLayout.Location.TOP); TextBox sharedClasspath = new TextBox("", Style.MULTI_LINE); sharedClasspath.setReadOnly(true); Classpath classpath = container.getSharedClasspath(); for (URL url : classpath.getClasspath()) { sharedClasspath.addLine("- " + url.toString()); } panel.addComponent(sharedClasspath, BorderLayout.Location.CENTER); return panel; }
@Override public Classpath clone() { Classpath classpath = new Classpath(); classpath.urlSet = new HashSet<>(this.urlSet); return classpath; }