[jboss-cvs] JBossAS SVN: r104826 - in projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency: policy and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat May 15 11:21:05 EDT 2010
Author: alesj
Date: 2010-05-15 11:21:04 -0400 (Sat, 15 May 2010)
New Revision: 104826
Added:
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardClassLoaderPolicy.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardClassLoaderPolicyFactory.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardDelegateLoader.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardRequirementDependencyItem.java
Removed:
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicyFactory.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardDelegateLoader.java
Modified:
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/RequirementDependencyItem.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java
Log:
Ignore undeploy demand for wildcards - we bounce it ourselves or we delegate to refresh.
Add refresh information for non cascading dependant modules.
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java 2010-05-15 14:22:19 UTC (rev 104825)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java 2010-05-15 15:21:04 UTC (rev 104826)
@@ -36,6 +36,7 @@
import org.jboss.classloader.spi.filter.ClassFilter;
import org.jboss.classloading.plugins.metadata.PackageCapability;
import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.spi.dependency.wildcard.WildcardRequirementDependencyItem;
import org.jboss.classloading.spi.helpers.NameAndVersionSupport;
import org.jboss.classloading.spi.metadata.*;
import org.jboss.classloading.spi.visitor.ResourceFilter;
@@ -112,11 +113,11 @@
modulesByClassLoader.put(classLoader, module);
// This is a hack - we might not know until the classloader gets constructed whether
- // it is in a domain that specifies lazy shutdown of the classloader
+ // it is in a domain that specifies lazy shutdown of the classloader.
module.cascadeShutdown = module.isCascadeShutdown();
if (module.cascadeShutdown == false)
module.enableLazyShutdown();
-
+
LifeCycle lifeCycle = module.getLifeCycle();
if (lifeCycle != null)
lifeCycle.fireResolved();
@@ -1173,8 +1174,11 @@
requirementDependencies = new ArrayList<RequirementDependencyItem>();
for (Requirement requirement : requirements)
{
- // [JBCL-113] RequirementDependencyItems can only resolve againt INSTALLED contexts
- RequirementDependencyItem item = new RequirementDependencyItem(this, requirement, classLoaderState, classLoaderState);
+ RequirementDependencyItem item;
+ if (requirement instanceof PackageRequirement && ((PackageRequirement)requirement).isWildcard())
+ item = new WildcardRequirementDependencyItem(this, requirement, classLoaderState, classLoaderState);
+ else
+ item = new RequirementDependencyItem(this, requirement, classLoaderState, classLoaderState);
addIDependOn(item);
requirementDependencies.add(item);
}
@@ -1364,8 +1368,10 @@
return super.equals(obj);
}
- // It is lazy shutdown so remove anything that depends upon us for a requirement
- // We can still handle it after the classloader gets unregistered
+ /**
+ * It is lazy shutdown so remove anything that depends upon us for a requirement
+ * We can still handle it after the classloader gets unregistered
+ */
private void enableLazyShutdown()
{
ControllerContext ctx = getControllerContext();
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/RequirementDependencyItem.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/RequirementDependencyItem.java 2010-05-15 14:22:19 UTC (rev 104825)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/RequirementDependencyItem.java 2010-05-15 15:21:04 UTC (rev 104826)
@@ -116,12 +116,12 @@
public boolean resolve(Controller controller)
{
- Requirement requirement = getRequirement();
Module module = getModule().resolveModule(this, true);
// No module present
if (module == null)
{
+ Requirement requirement = getRequirement();
setResolved(requirement.isOptional() || requirement.isDynamic());
return isResolved();
}
@@ -145,7 +145,7 @@
if (resolved)
{
setIDependOn(context.getName());
- module.addDepends(this);
+ addDepends(module);
if (module.getClassLoadingSpace() == null)
log.warn(getModule() + " resolved " + getRequirement() + " to " + module + " which has import-all=true. Cannot check its consistency.");
}
@@ -156,6 +156,26 @@
return isResolved();
}
+ /**
+ * Add this dependency on module.
+ *
+ * @param current the current module
+ */
+ protected void addDepends(Module current)
+ {
+ current.addDepends(this);
+ }
+
+ /**
+ * Remove this dependency from module.
+ *
+ * @param current the current module
+ */
+ protected void removeDepends(Module current)
+ {
+ current.removeDepends(this);
+ }
+
@Override
protected void addDependsOnMe(Controller controller, ControllerContext context)
{
@@ -179,7 +199,7 @@
Module resolvedModule = getResolvedModule();
if (resolved == ResolvedState.UNRESOLVED && resolvedModule != null)
{
- resolvedModule.removeDepends(this);
+ removeDepends(resolvedModule);
resolvedModule.removeDependsOnMe(this);
this.resolvedModule = null;
}
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java 2010-05-15 14:22:19 UTC (rev 104825)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java 2010-05-15 15:21:04 UTC (rev 104826)
@@ -38,6 +38,8 @@
import org.jboss.classloading.spi.dependency.Module;
import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
import org.jboss.classloading.spi.dependency.helpers.ClassLoadingMetaDataModule;
+import org.jboss.classloading.spi.dependency.wildcard.WildcardClassLoaderPolicyFactory;
+import org.jboss.classloading.spi.dependency.wildcard.WildcardDelegateLoader;
import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
import org.jboss.classloading.spi.metadata.Requirement;
import org.jboss.dependency.spi.Controller;
Deleted: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java 2010-05-15 14:22:19 UTC (rev 104825)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java 2010-05-15 15:21:04 UTC (rev 104826)
@@ -1,362 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2007, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.classloading.spi.dependency.policy;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.jboss.classloader.plugins.ClassLoaderUtils;
-import org.jboss.classloader.spi.ClassLoaderPolicy;
-import org.jboss.classloader.spi.base.BaseClassLoader;
-import org.jboss.classloader.spi.base.ClassLoadingTask;
-import org.jboss.classloader.spi.filter.ClassFilter;
-import org.jboss.classloading.plugins.metadata.PackageRequirement;
-import org.jboss.classloading.spi.dependency.*;
-import org.jboss.util.collection.ConcurrentSet;
-
-/**
- * WildcardClassLoaderPolicy.
- *
- * TODO -- module order rules actually need more work; parent of a parent, ...
- *
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- */
-public class WildcardClassLoaderPolicy extends ClassLoaderPolicy implements ModuleRegistry
-{
- /** The domain */
- private Domain domain;
-
- /** The package requirement */
- private PackageRequirement requirement;
-
- /** The module */
- private Module module;
-
- /** The matching imported modules */
- private List<Module> modules = new CopyOnWriteArrayList<Module>();
-
- /** The parents before index */
- private int parentsBefore;
-
- /** The resources cache */
- private Map<String, Module> resourceCache = new ConcurrentHashMap<String, Module>();
-
- /** The used modules - track what we're using, so we know when to bounce */
- private Set<Module> used = new ConcurrentSet<Module>();
-
- public WildcardClassLoaderPolicy(Domain domain, PackageRequirement requirement, Module module)
- {
- if (domain == null)
- throw new IllegalArgumentException("Null domain");
- if (requirement == null)
- throw new IllegalArgumentException("Null reqirement");
- if (module == null)
- throw new IllegalArgumentException("Null module");
-
- this.domain = domain;
- this.requirement = requirement;
- this.module = module;
-
- fillModules(domain);
- }
-
- /**
- * Is the module resolved.
- *
- * @param m the module
- * @return true if resolved, false otherwise
- */
- protected boolean isResolved(Module m)
- {
- ClassLoader cl = ClassLoading.getClassLoaderForModule(m);
- return cl != null;
- }
-
- /**
- * Find module which has a resource parameter.
- *
- * @param resource the resource
- * @return found module or null
- */
- protected Module findModule(String resource)
- {
- Module cached = resourceCache.get(resource);
- if (cached != null)
- return cached;
-
- ClassFilter filter = requirement.toClassFilter();
- if (filter.matchesResourcePath(resource))
- {
- for (Module m : modules)
- {
- if (isResolved(m))
- {
- URL url = m.getResource(resource);
- if (url != null)
- {
- resourceCache.put(resource, m);
- used.add(m);
- return m;
- }
- }
- }
- }
- return null;
- }
-
- public URL getResource(String path)
- {
- Module cached = resourceCache.get(path);
- if (cached != null)
- return cached.getResource(path);
-
- ClassFilter filter = requirement.toClassFilter();
- if (filter.matchesResourcePath(path))
- {
- for (Module m : modules)
- {
- if (isResolved(m))
- {
- URL url = m.getResource(path);
- if (url != null)
- {
- resourceCache.put(path, m);
- used.add(m);
- return url;
- }
- }
- }
- }
- return null;
- }
-
- public void getResources(String name, Set<URL> urls) throws IOException
- {
- ClassFilter filter = requirement.toClassFilter();
- if (filter.matchesResourcePath(name))
- {
- for (Module m : modules)
- {
- if (isResolved(m))
- {
- boolean visited = false;
- Enumeration<URL> eu = m.getResources(name);
- while (eu.hasMoreElements())
- {
- if (visited == false)
- {
- used.add(m);
- visited = true;
- }
- urls.add(eu.nextElement());
- }
- }
- }
- }
- }
-
- @Override
- protected boolean isCacheable()
- {
- return false; // don't cache
- }
-
- /**
- * Get module's domain if it's connected to ours, null otherwise.
- *
- * @param module the module
- * @return module's domain if we're connected, null otherwise
- */
- protected Domain getDomain(Module module)
- {
- String domainName = module.getDeterminedDomainName();
- Domain current = domain;
- while (current != null && domainName.equals(domain.getName()) == false)
- current = current.getParentDomain();
-
- return current;
- }
-
- /**
- * Clear this policy.
- */
- protected void reset()
- {
- resourceCache.clear();
- }
-
- public void addModule(Module current)
- {
- Domain md = getDomain(current);
- if (md != null && current.canResolve(requirement))
- {
- boolean isAncestor = (domain != md); // not the same domain, so it must be ancestor
- synchronized (this)
- {
- boolean isParentFirst = domain.isParentFirst();
- addModule(current, isAncestor, isParentFirst);
- }
-
- reset();
- }
- }
-
- /**
- * Add module, following order rules.
- * This method needs to be part of synch block or done in ctor.
- *
- * @param current the current module
- * @param isAncestor is ancestor
- * @param isParentFirst is parent first
- */
- private void addModule(Module current, boolean isAncestor, boolean isParentFirst)
- {
- if (isAncestor)
- {
- if (isParentFirst)
- {
- // leave previous parents infront of current module
- modules.add(parentsBefore, current);
- parentsBefore++;
- }
- else
- modules.add(current);
- }
- else
- modules.add(parentsBefore, current);
- }
-
- public void removeModule(Module current)
- {
- boolean sameModule = module == current;
- boolean resolvedModule = false;
-
- synchronized (this)
- {
- if (modules.remove(current))
- {
- if (sameModule == false)
- {
- resolvedModule = true; // we were part of matching modules, but not our module
- Domain md = getDomain(current);
- boolean isAncestor = (domain != md);
- if (isAncestor && domain.isParentFirst())
- parentsBefore--;
-
- }
- reset();
- }
- }
-
- // Unregister this policy as module listener
- if (sameModule)
- {
- ClassLoading classLoading = domain.getClassLoading();
- classLoading.removeModuleRegistry(this);
- this.module = null;
- }
-
- // It's not us (we're already uninstalling) and we used this, let's bounce.
- if (resolvedModule && used.remove(current))
- {
- LifeCycle lifeCycle = module.getLifeCycle();
- if (lifeCycle != null)
- {
- if (current.isCascadeShutdown())
- {
- try
- {
- lifeCycle.bounce(); // let's refresh the wired resources
- }
- catch (Exception e)
- {
- throw new RuntimeException("Error bouncing module: " + this.module, e);
- }
- }
- else
- {
- // TODO -- make this module somehow available for refresh
- }
- }
- }
- }
-
- /**
- * Fill modules according to domain rules.
- *
- * @param current the current domain
- */
- protected void fillModules(Domain current)
- {
- Domain parent = current.getParentDomain();
- boolean parentFirst = current.isParentFirst();
-
- if (parent != null && parentFirst)
- fillModules(parent);
-
- Collection<ExportPackage> eps = current.getExportedPackages(requirement.getName(), requirement.getVersionRange());
- if (eps != null && eps.isEmpty() == false)
- {
- boolean isAncestor = (current != domain);
- boolean isParentFirst = domain.isParentFirst();
- for (ExportPackage ep : eps)
- {
- Module m = ep.getModule();
- addModule(m, isAncestor, isParentFirst);
- }
- }
-
- if (parent != null && parentFirst == false)
- fillModules(parent);
- }
-
- /**
- * Get BaseClassLoader from module.
- *
- * @param context the context
- * @return matching classloader or null
- */
- BaseClassLoader getBaseClassLoader(String context)
- {
- Module m = findModule(context);
- if (m != null)
- {
- ClassLoader cl = ClassLoading.getClassLoaderForModule(m);
- if (cl instanceof BaseClassLoader)
- return BaseClassLoader.class.cast(cl);
- }
- return null;
- }
-
- @Override
- protected BaseClassLoader getClassLoader(ClassLoadingTask task)
- {
- if (task == null)
- throw new IllegalArgumentException("Null task");
-
- String path = ClassLoaderUtils.classNameToPath(task.getClassName());
- return getBaseClassLoader(path);
- }
-}
Deleted: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicyFactory.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicyFactory.java 2010-05-15 14:22:19 UTC (rev 104825)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicyFactory.java 2010-05-15 15:21:04 UTC (rev 104826)
@@ -1,81 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2007, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.classloading.spi.dependency.policy;
-
-import org.jboss.classloader.spi.ClassLoaderPolicy;
-import org.jboss.classloader.spi.ClassLoaderPolicyFactory;
-import org.jboss.classloading.plugins.metadata.PackageRequirement;
-import org.jboss.classloading.spi.dependency.ClassLoading;
-import org.jboss.classloading.spi.dependency.Domain;
-import org.jboss.classloading.spi.dependency.Module;
-import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
-import org.jboss.classloading.spi.metadata.Requirement;
-
-/**
- * WildcardClassLoaderPolicyFactory.
- *
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- */
-public class WildcardClassLoaderPolicyFactory implements ClassLoaderPolicyFactory
-{
- /** The domain */
- private Domain domain;
-
- /** The package requirement */
- private PackageRequirement requirement;
-
- /** The module */
- private Module module;
-
- /**
- * Create a new WildcardClassLoaderPolicyFactory.
- *
- * @param domain the domain
- * @param item the requirement item
- */
- public WildcardClassLoaderPolicyFactory(Domain domain, RequirementDependencyItem item)
- {
- if (domain == null)
- throw new IllegalArgumentException("Null domain");
- if (item == null)
- throw new IllegalArgumentException("Null item");
- Requirement requirement = item.getRequirement();
- if (requirement == null || requirement instanceof PackageRequirement == false)
- throw new IllegalArgumentException("Illegal requirement: " + requirement);
- PackageRequirement pr = (PackageRequirement) requirement;
- if (pr.isWildcard() == false)
- throw new IllegalArgumentException("Requirement is not wildcard: " + pr);
- if (item.getModule() == null)
- throw new IllegalArgumentException("Null module");
- this.domain = domain;
- this.requirement = pr;
- this.module = item.getModule();
- }
-
- public ClassLoaderPolicy createClassLoaderPolicy()
- {
- WildcardClassLoaderPolicy policy = new WildcardClassLoaderPolicy(domain, requirement, module);
- ClassLoading classLoading = domain.getClassLoading();
- classLoading.addModuleRegistry(policy); // so we know when to reset on module change
- return policy;
- }
-}
\ No newline at end of file
Deleted: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardDelegateLoader.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardDelegateLoader.java 2010-05-15 14:22:19 UTC (rev 104825)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardDelegateLoader.java 2010-05-15 15:21:04 UTC (rev 104826)
@@ -1,53 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.classloading.spi.dependency.policy;
-
-import org.jboss.classloader.spi.ClassLoaderPolicy;
-import org.jboss.classloader.spi.ClassLoaderPolicyFactory;
-import org.jboss.classloader.spi.base.BaseClassLoader;
-import org.jboss.classloader.spi.filter.ClassFilter;
-import org.jboss.classloader.spi.filter.FilteredDelegateLoader;
-
-/**
- * Wildcard delegate loader.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public class WildcardDelegateLoader extends FilteredDelegateLoader
-{
- public WildcardDelegateLoader(ClassLoaderPolicyFactory factory, ClassFilter filter)
- {
- super(factory, filter);
- }
-
- @Override
- protected BaseClassLoader getBaseClassLoader(String message, String context)
- {
- ClassLoaderPolicy policy = getPolicy();
- if (policy instanceof WildcardClassLoaderPolicy == false)
- throw new IllegalArgumentException("Can only handle wildcard policy: " + policy);
-
- WildcardClassLoaderPolicy wclp = (WildcardClassLoaderPolicy) policy;
- return wclp.getBaseClassLoader(context);
- }
-}
Copied: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardClassLoaderPolicy.java (from rev 104824, projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java)
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardClassLoaderPolicy.java (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardClassLoaderPolicy.java 2010-05-15 15:21:04 UTC (rev 104826)
@@ -0,0 +1,380 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.classloading.spi.dependency.wildcard;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.base.BaseClassLoader;
+import org.jboss.classloader.spi.base.ClassLoadingTask;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.spi.dependency.*;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.util.collection.ConcurrentSet;
+
+/**
+ * WildcardClassLoaderPolicy.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WildcardClassLoaderPolicy extends ClassLoaderPolicy implements ModuleRegistry
+{
+ /** The domain */
+ private Domain domain;
+
+ /** The wildcard requirement dependency item */
+ private WildcardRequirementDependencyItem item;
+
+ /** The package requirement */
+ private PackageRequirement requirement;
+
+ /** The module */
+ private Module module;
+
+ /** The matching imported modules */
+ private List<Module> modules = new CopyOnWriteArrayList<Module>();
+
+ /** The parents before index */
+ private int parentsBefore;
+
+ /** The resources cache */
+ private Map<String, Module> resourceCache = new ConcurrentHashMap<String, Module>();
+
+ /** The used modules - track what we're using, so we know when to bounce */
+ private Set<Module> used = new ConcurrentSet<Module>();
+
+ public WildcardClassLoaderPolicy(Domain domain, WildcardRequirementDependencyItem item)
+ {
+ if (domain == null)
+ throw new IllegalArgumentException("Null domain");
+ if (item == null)
+ throw new IllegalArgumentException("Null item");
+
+ Requirement requirement = item.getRequirement();
+ if (requirement == null || requirement instanceof PackageRequirement == false)
+ throw new IllegalArgumentException("Illegal requirement: " + requirement);
+ PackageRequirement pr = (PackageRequirement) requirement;
+ if (pr.isWildcard() == false)
+ throw new IllegalArgumentException("Requirement is not wildcard: " + pr);
+ if (item.getModule() == null)
+ throw new IllegalArgumentException("Null module");
+
+ this.domain = domain;
+ this.item = item;
+ this.requirement = pr;
+ this.module = item.getModule();
+
+ fillModules(domain);
+ }
+
+ /**
+ * Is the module resolved.
+ *
+ * @param m the module
+ * @return true if resolved, false otherwise
+ */
+ protected boolean isResolved(Module m)
+ {
+ ClassLoader cl = ClassLoading.getClassLoaderForModule(m);
+ return cl != null;
+ }
+
+ /**
+ * Add used.
+ *
+ * @param m the module
+ */
+ protected void addUsed(Module m)
+ {
+ // Add refresh info if the module is not cascade shutdown.
+ if (used.add(m) && m.isCascadeShutdown() == false)
+ item.addIDependOn(m);
+ }
+
+ /**
+ * Find module which has a resource parameter.
+ *
+ * @param resource the resource
+ * @return found module or null
+ */
+ protected Module findModule(String resource)
+ {
+ Module cached = resourceCache.get(resource);
+ if (cached != null)
+ return cached;
+
+ ClassFilter filter = requirement.toClassFilter();
+ if (filter.matchesResourcePath(resource))
+ {
+ for (Module m : modules)
+ {
+ if (isResolved(m))
+ {
+ URL url = m.getResource(resource);
+ if (url != null)
+ {
+ resourceCache.put(resource, m);
+ addUsed(m);
+ return m;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public URL getResource(String path)
+ {
+ Module cached = resourceCache.get(path);
+ if (cached != null)
+ return cached.getResource(path);
+
+ ClassFilter filter = requirement.toClassFilter();
+ if (filter.matchesResourcePath(path))
+ {
+ for (Module m : modules)
+ {
+ if (isResolved(m))
+ {
+ URL url = m.getResource(path);
+ if (url != null)
+ {
+ resourceCache.put(path, m);
+ addUsed(m);
+ return url;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public void getResources(String name, Set<URL> urls) throws IOException
+ {
+ ClassFilter filter = requirement.toClassFilter();
+ if (filter.matchesResourcePath(name))
+ {
+ for (Module m : modules)
+ {
+ if (isResolved(m))
+ {
+ boolean visited = false;
+ Enumeration<URL> eu = m.getResources(name);
+ while (eu.hasMoreElements())
+ {
+ if (visited == false)
+ {
+ addUsed(m);
+ visited = true;
+ }
+ urls.add(eu.nextElement());
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ protected boolean isCacheable()
+ {
+ return false; // don't cache
+ }
+
+ /**
+ * Get module's domain if it's connected to ours, null otherwise.
+ *
+ * @param module the module
+ * @return module's domain if we're connected, null otherwise
+ */
+ protected Domain getDomain(Module module)
+ {
+ String domainName = module.getDeterminedDomainName();
+ Domain current = domain;
+ while (current != null && domainName.equals(domain.getName()) == false)
+ current = current.getParentDomain();
+
+ return current;
+ }
+
+ /**
+ * Clear this policy.
+ */
+ protected void reset()
+ {
+ resourceCache.clear();
+ }
+
+ public void addModule(Module current)
+ {
+ Domain md = getDomain(current);
+ if (md != null && current.canResolve(requirement))
+ {
+ boolean isAncestor = (domain != md); // not the same domain, so it must be ancestor
+ synchronized (this)
+ {
+ boolean isParentFirst = domain.isParentFirst();
+ addModule(current, isAncestor, isParentFirst);
+ }
+
+ reset();
+ }
+ }
+
+ /**
+ * Add module, following order rules.
+ * This method needs to be part of synch block or done in ctor.
+ *
+ * @param current the current module
+ * @param isAncestor is ancestor
+ * @param isParentFirst is parent first
+ */
+ private void addModule(Module current, boolean isAncestor, boolean isParentFirst)
+ {
+ if (isAncestor)
+ {
+ if (isParentFirst)
+ {
+ // leave previous parents infront of current module
+ modules.add(parentsBefore, current);
+ parentsBefore++;
+ }
+ else
+ modules.add(current);
+ }
+ else
+ modules.add(parentsBefore, current);
+ }
+
+ public void removeModule(Module current)
+ {
+ boolean sameModule = module == current;
+ boolean resolvedModule = false;
+
+ synchronized (this)
+ {
+ if (modules.remove(current))
+ {
+ if (sameModule == false)
+ {
+ resolvedModule = true; // we were part of matching modules, but not our module
+ Domain md = getDomain(current);
+ boolean isAncestor = (domain != md);
+ if (isAncestor && domain.isParentFirst())
+ parentsBefore--;
+
+ }
+ reset();
+ }
+ }
+
+ // Unregister this policy as module listener
+ if (sameModule)
+ {
+ ClassLoading classLoading = domain.getClassLoading();
+ classLoading.removeModuleRegistry(this);
+ this.module = null;
+ }
+
+ // It's not us (we're already uninstalling) and we used this, let's bounce.
+ if (resolvedModule && used.remove(current))
+ {
+ LifeCycle lifeCycle = module.getLifeCycle();
+ if (lifeCycle != null)
+ {
+ if (current.isCascadeShutdown())
+ {
+ try
+ {
+ lifeCycle.bounce(); // let's refresh the wired resources
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error bouncing module: " + this.module, e);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Fill modules according to domain rules.
+ *
+ * @param current the current domain
+ */
+ protected void fillModules(Domain current)
+ {
+ Domain parent = current.getParentDomain();
+ boolean parentFirst = current.isParentFirst();
+
+ if (parent != null && parentFirst)
+ fillModules(parent);
+
+ Collection<ExportPackage> eps = current.getExportedPackages(requirement.getName(), requirement.getVersionRange());
+ if (eps != null && eps.isEmpty() == false)
+ {
+ boolean isAncestor = (current != domain);
+ boolean isParentFirst = domain.isParentFirst();
+ for (ExportPackage ep : eps)
+ {
+ Module m = ep.getModule();
+ addModule(m, isAncestor, isParentFirst);
+ }
+ }
+
+ if (parent != null && parentFirst == false)
+ fillModules(parent);
+ }
+
+ /**
+ * Get BaseClassLoader from module.
+ *
+ * @param context the context
+ * @return matching classloader or null
+ */
+ BaseClassLoader getBaseClassLoader(String context)
+ {
+ Module m = findModule(context);
+ if (m != null)
+ {
+ ClassLoader cl = ClassLoading.getClassLoaderForModule(m);
+ if (cl instanceof BaseClassLoader)
+ return BaseClassLoader.class.cast(cl);
+ }
+ return null;
+ }
+
+ @Override
+ protected BaseClassLoader getClassLoader(ClassLoadingTask task)
+ {
+ if (task == null)
+ throw new IllegalArgumentException("Null task");
+
+ String path = ClassLoaderUtils.classNameToPath(task.getClassName());
+ return getBaseClassLoader(path);
+ }
+}
Copied: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardClassLoaderPolicyFactory.java (from rev 104820, projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicyFactory.java)
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardClassLoaderPolicyFactory.java (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardClassLoaderPolicyFactory.java 2010-05-15 15:21:04 UTC (rev 104826)
@@ -0,0 +1,67 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.classloading.spi.dependency.wildcard;
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderPolicyFactory;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.Domain;
+import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
+
+/**
+ * WildcardClassLoaderPolicyFactory.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WildcardClassLoaderPolicyFactory implements ClassLoaderPolicyFactory
+{
+ /** The domain */
+ private Domain domain;
+
+ /** The requirement dependency item */
+ private WildcardRequirementDependencyItem item;
+
+ /**
+ * Create a new WildcardClassLoaderPolicyFactory.
+ *
+ * @param domain the domain
+ * @param item the requirement item
+ */
+ public WildcardClassLoaderPolicyFactory(Domain domain, RequirementDependencyItem item)
+ {
+ if (domain == null)
+ throw new IllegalArgumentException("Null domain");
+ if (item == null || item instanceof WildcardRequirementDependencyItem == false)
+ throw new IllegalArgumentException("Illegal item: " + item);
+
+ this.domain = domain;
+ this.item = (WildcardRequirementDependencyItem) item;
+ }
+
+ public ClassLoaderPolicy createClassLoaderPolicy()
+ {
+ WildcardClassLoaderPolicy policy = new WildcardClassLoaderPolicy(domain, item);
+ ClassLoading classLoading = domain.getClassLoading();
+ classLoading.addModuleRegistry(policy); // so we know when to reset on module change
+ return policy;
+ }
+}
\ No newline at end of file
Copied: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardDelegateLoader.java (from rev 104820, projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardDelegateLoader.java)
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardDelegateLoader.java (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardDelegateLoader.java 2010-05-15 15:21:04 UTC (rev 104826)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.classloading.spi.dependency.wildcard;
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderPolicyFactory;
+import org.jboss.classloader.spi.base.BaseClassLoader;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloader.spi.filter.FilteredDelegateLoader;
+
+/**
+ * Wildcard delegate loader.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WildcardDelegateLoader extends FilteredDelegateLoader
+{
+ public WildcardDelegateLoader(ClassLoaderPolicyFactory factory, ClassFilter filter)
+ {
+ super(factory, filter);
+ }
+
+ @Override
+ protected BaseClassLoader getBaseClassLoader(String message, String context)
+ {
+ ClassLoaderPolicy policy = getPolicy();
+ if (policy instanceof WildcardClassLoaderPolicy == false)
+ throw new IllegalArgumentException("Can only handle wildcard policy: " + policy);
+
+ WildcardClassLoaderPolicy wclp = (WildcardClassLoaderPolicy) policy;
+ return wclp.getBaseClassLoader(context);
+ }
+}
Copied: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardRequirementDependencyItem.java (from rev 104824, projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java)
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardRequirementDependencyItem.java (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/wildcard/WildcardRequirementDependencyItem.java 2010-05-15 15:21:04 UTC (rev 104826)
@@ -0,0 +1,75 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.classloading.spi.dependency.wildcard;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * WildcardRequirementDependencyItem.
+
+ * We don't want to be undeployed when our
+ * wildcarded dependency goes away, hence ignoring iDependOn and dependsOnMe.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WildcardRequirementDependencyItem extends RequirementDependencyItem
+{
+ public WildcardRequirementDependencyItem(Module module, Requirement requirement, ControllerState state)
+ {
+ super(module, requirement, state);
+ }
+
+ public WildcardRequirementDependencyItem(Module module, Requirement requirement, ControllerState whenRequired, ControllerState dependentState)
+ {
+ super(module, requirement, whenRequired, dependentState);
+ }
+
+ @Override
+ public boolean resolve(Controller controller)
+ {
+ // Always resolved
+ setResolved(true);
+ return isResolved();
+ }
+
+ @Override
+ protected void addDependsOnMe(Controller controller, ControllerContext context)
+ {
+ // ignore
+ }
+
+ /**
+ * We depend on this module.
+ * e.g. add dependency for refresh callback.
+ *
+ * @param module the module
+ */
+ void addIDependOn(Module module)
+ {
+ addDepends(module);
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list