User: cgjung
Date: 01/05/21 01:35:18
Modified: src/main/org/jboss/deployment/scope
J2eeGlobalScopeDeployer.java
Log:
introduced the possibility of several scopes (not yet exported as MBean).
undeployment now homogenized (had uninstall twice
which lead to exception)
Revision Changes Path
1.2 +212 -141
jboss/src/main/org/jboss/deployment/scope/J2eeGlobalScopeDeployer.java
Index: J2eeGlobalScopeDeployer.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/deployment/scope/J2eeGlobalScopeDeployer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- J2eeGlobalScopeDeployer.java 2001/05/18 15:14:19 1.1
+++ J2eeGlobalScopeDeployer.java 2001/05/21 08:35:18 1.2
@@ -17,6 +17,7 @@
import java.util.List;
import java.util.Collection;
import java.util.Set;
+import java.util.Map;
import java.io.IOException;
import javax.management.ObjectName;
import javax.management.MBeanException;
@@ -26,22 +27,60 @@
/**
- * This is an example deployer that uses the J2ee application scoping facility and
- * implements a proper (re-)deployment procedure.
- * In this case, we introduce a global scope.
+ * This is a deployer that introduces a J2ee application scoping facility and
+ * proper (re-)deployment procedures. It implements a default global scope.
* @author cgjung
- * @version 0.8
+ * @version 0.9
*/
public class J2eeGlobalScopeDeployer extends org.jboss.deployment.J2eeDeployer {
- /** the global scope */
- protected Scope globalScope=null;
+ /** the scopes that are in effect */
+ final protected Map scopes=new java.util.HashMap();
/** Creates new J2eeDependencyDeployer */
public J2eeGlobalScopeDeployer() {
}
+ /** registers a new scope in this deployer
+ * @param name unique name of the new scope
+ *
+ * @param scope the scope to register
+ * @return the scope that has been isolated by that action
+ *
+ */
+ public Scope registerScope(String name, Scope scope) {
+ synchronized(scopes) {
+ return (Scope) scopes.put(name,scope);
+ }
+ }
+
+ /** looks up a scope
+ * @param name the unique name of the scope
+ *
+ * @return the registered scope
+ *
+ */
+ public Scope getScope(String name) {
+ synchronized(scopes) {
+ return (Scope) scopes.get(name);
+ }
+ }
+
+ /** deregisters a scope
+ * @param name unique name of the scope to deRegister
+ * @return the deRegistered scope
+ *
+ */
+ public Scope deRegisterScope(String name) {
+ synchronized(scopes) {
+ return (Scope) scopes.remove(name);
+ }
+ }
+
+ /** static name of the global scope */
+ final public static String GLOBAL_SCOPE="GLOBAL_SCOPE";
+
/** starts the service by first creating
* a new scope
* @throws Exception to indicate
@@ -49,7 +88,7 @@
* went wrong.
*/
public void startService() throws Exception {
- globalScope=createScope();
+ registerScope(GLOBAL_SCOPE,createScope());
super.startService();
}
@@ -71,7 +110,7 @@
*/
public void stopService() {
super.stopService();
- globalScope=null;
+ deRegisterScope(GLOBAL_SCOPE);
}
@@ -81,14 +120,14 @@
* tomcat via the contextclassloader
* we include all ejb and web-modules at this level
* to also be able to connect flat ejb-jars to each other
+ * @param scope the scope in which to create the classloader
* @param deployment the deployment that is about to be made,
* but is already installed
- *
* @throws J2eeDeploymentException to indicate
* problems with instantiating the classloader
* (maybe if reading some meta-data did not work properly)
*/
- protected void createContextClassLoader(Deployment deployment) throws
J2eeDeploymentException {
+ protected void createContextClassLoader(Deployment deployment, Scope scope)
throws J2eeDeploymentException {
try{
// get urls we want all classloaders of this application to share
@@ -121,7 +160,7 @@
// create classloader with parent from context
ClassLoader parent = Thread.currentThread().getContextClassLoader();
// using the factory method
- ScopedURLClassLoader appCl = createScopedContextClassLoader((URL[])
allUrls.toArray(new URL[allUrls.size()]),parent,deployment);
+ ScopedURLClassLoader appCl = createScopedContextClassLoader((URL[])
allUrls.toArray(new URL[allUrls.size()]),parent,deployment,scope);
// set the result loader as the context class
// loader for the deployment thread
@@ -133,24 +172,20 @@
/** factory method for scoped url classloaders factored out. May throw a general
* exception if this enterprise fails.
+ * @return a freshly instantiated and configured class loader
+ * @param scope the scope in which the classloader should be created
* @param urls the urls for which the scoped
* classloader should be generated
- *
* @param parent the parent loader
- *
* @param deployment the deployment to which this classloader is
* associated.
- *
* @throws Exception to indicate
* problems in constructing the
* classloader (maybe because
* meta-data was corrupt).
- *
- * @return a freshly instantiated and configured class loader
- *
*/
- protected ScopedURLClassLoader createScopedContextClassLoader(URL[]
urls,ClassLoader parent,Deployment deployment) throws Exception {
- return new ScopedURLClassLoader(urls,parent,deployment,globalScope);
+ protected ScopedURLClassLoader createScopedContextClassLoader(URL[]
urls,ClassLoader parent,Deployment deployment, Scope scope) throws Exception {
+ return new ScopedURLClassLoader(urls,parent,deployment,scope);
}
/** Overrides the normal (re-)deploy method in order to
@@ -162,6 +197,18 @@
* @throws IOException if trouble while file download occurs
*/
public void deploy(String _url) throws MalformedURLException, IOException,
J2eeDeploymentException {
+ deploy(_url,getScope(GLOBAL_SCOPE));
+ }
+
+ /** scoped (re-)deploy method.
+ *
+ * @param scope the scope in which the file should be deployed
+ * @param _url the url (file or http) to the archiv to deploy
+ * @throws MalformedURLException in case of a malformed url
+ * @throws J2eeDeploymentException if something went wrong...
+ * @throws IOException if trouble while file download occurs
+ */
+ public void deploy(String _url, Scope scope) throws MalformedURLException,
IOException, J2eeDeploymentException {
URL url = new URL(_url);
ObjectName lCollector = null;
@@ -207,7 +254,7 @@
d=installApplication(nextUrl);
try {
- startApplication(d);
+ startApplication(d, scope);
log.log("J2EE application: " + nextUrl + " is (re-)deployed.");
try {
// Now the application is deployed add it to the server
data collector
@@ -256,128 +303,21 @@
}
}
- /** A new stop method that stops a running deployment
- * and its dependent applications and that logs their
- * urls (where the current deployment will be redeployed under newUrl)
- * in a set for redeployment.
- *
- * @param _d deployment to stop
- *
- * @param redeployUrls collects the sourceUrls of the
- * undeployed apps
- *
- * @param newUrl the url under which the current deployment should be
redeployed, if at all
- *
- * @throws J2eeDeploymentException to
- * indicate problems in undeployment.
- */
- protected void stopApplication(Deployment _d, List redeployUrls, URL newUrl)
throws J2eeDeploymentException {
- // synchronize on the scope
- synchronized(globalScope.classLoaders) {
-
- // find out the corresponding classloader
- ScopedURLClassLoader source=(ScopedURLClassLoader)
- globalScope.classLoaders.get(_d.getLocalUrl());
-
- // its still here, so the thing is not already stopped
- if(source!=null) {
-
- try{
- log.log("About to stop application "+_d.getName());
-
- // add it to the stopped list
- redeployUrls.add(newUrl);
- // get dependency information
- Iterator
allDependencies=globalScope.getDependentClassLoaders(source).
- iterator();
- // deregister classloader
- globalScope.deRegisterClassLoader(source);
-
- // first stop the dependent stuff
- while(allDependencies.hasNext()) {
- ScopedURLClassLoader dependentLoader=(ScopedURLClassLoader)
allDependencies.next();
-
-
stopApplication(dependentLoader.deployment,redeployUrls,dependentLoader.deployment.getSourceUrl());
- }
-
- } finally {
-
- try{
- // now we do the real stopping
- super.stopApplication(_d);
-
- // and leave a last message to the classloader to
- // tear down meta-data or such
- source.onUndeploy();
- } finally {
- try{
- uninstallApplication(_d);
- } catch(IOException e) {
- log.error("could not properly uninstall "+_d.getName());
- }
- }
- }
-
- } // if
- } // sync
-
- }
-
- /** Overrides the proper stop in order to
- * be redirected to the dependency stopper
- * @param _d the deployment to stop
- * @throws J2eeDeploymentException if an error occures for one of these
- * modules
- */
- protected void stopApplication(Deployment _d) throws J2eeDeploymentException {
- stopApplication(_d,new java.util.ArrayList(),_d.getSourceUrl());
- }
-
- /** Undeploys the given URL (if it is deployed) and returns an array
- * of deployments that have been teared down
- * Actually only the file name is of interest, so it dont has to be
- * an URL to be undeployed, the file name is ok as well.
- * @param _app the stirng spec of the app to tear down
- *
- * @param allTearedDown collection of deployments that have been teared down as
a result.
- *
- * @param newUrl url under which the application is to be redeployed, if at all
- *
- * @throws J2eeDeploymentException if something went wrong (but should have
removed all files)
- * @throws IOException if file removement fails
- */
- public void undeployWithDependencies(String _app, List allTearedDown, URL
newUrl) throws IOException, J2eeDeploymentException {
- // find currect deployment
- Deployment d = installer.findDeployment(_app);
-
- if (d == null)
- throw new J2eeDeploymentException("The application \""+name+"\" has not
been deployed.");
-
- try {
- // use dependency stopper
- stopApplication(d, allTearedDown, newUrl);
- }
- catch (J2eeDeploymentException _e) {
- throw _e;
- }
-
- }
-
/** Starts the successful downloaded deployment. <br>
* Means the modules are deployed by the responsible container deployer
* This version of the method does indeed start necessary
* other applications as well.
+ * @param scope the scope in which the deployment should be started
* @param dep the deployment to start
- *
* @throws J2eeDeploymentException if an error occures for one of these
- * modules
+ * modules
*/
- protected void startApplication(Deployment dep) throws J2eeDeploymentException {
+ protected void startApplication(Deployment dep, Scope scope) throws
J2eeDeploymentException {
// here we collect all the started deployments (not only dep)
// indexed by the sourceUrl
Collection deployments=new java.util.ArrayList();
- startApplication(dep, deployments);
+ startApplication(dep, deployments,scope);
Iterator allDeployments=deployments.iterator();
@@ -391,7 +331,7 @@
// find out the corresponding classloader
ScopedURLClassLoader source=(ScopedURLClassLoader)
- globalScope.classLoaders.get(_d.getLocalUrl());
+ scope.classLoaders.get(_d.getLocalUrl());
Thread.currentThread().setContextClassLoader(source);
@@ -467,12 +407,12 @@
* @throws J2eeDeploymentException if an error occures for one of these
* modules
*/
- protected void startApplication(Deployment _d, Collection alreadyMarked) throws
J2eeDeploymentException {
+ protected void startApplication(Deployment _d, Collection alreadyMarked, Scope
scope) throws J2eeDeploymentException {
ClassLoader parent=Thread.currentThread().getContextClassLoader();
// set the context classloader for this application
- createContextClassLoader(_d);
+ createContextClassLoader(_d,scope);
// save the application classloader for later
ScopedURLClassLoader appCl = (ScopedURLClassLoader)
@@ -483,8 +423,8 @@
String[] dependentStuff=appCl.getDependingApplications();
for(int count=0;count<dependentStuff.length;count++) {
-
- // reinstall parent
+
+ // reinstall parent
Thread.currentThread().setContextClassLoader(parent);
try{
@@ -494,20 +434,151 @@
if(newD==null) {
newD = installApplication(absoluteUrl);
-
- startApplication(newD,alreadyMarked);
+
+ startApplication(newD,alreadyMarked,scope);
}
} catch(MalformedURLException e) {
throw new J2eeDeploymentException("could not construct url for
dependent application "+dependentStuff[count],e);
} catch(IOException e) {
throw new J2eeDeploymentException("io problem when trying to access
dependent application "+dependentStuff[count],e);
- }
+ }
} // for
- // reinstall parent
- Thread.currentThread().setContextClassLoader(parent);
+ // reinstall parent
+ Thread.currentThread().setContextClassLoader(parent);
+
+ }
+
+ /** A new stop method that stops a running deployment
+ * and its dependent applications and that logs their
+ * urls (where the current deployment will be redeployed under newUrl)
+ * in a set for redeployment.
+ *
+ * @param scope the scope in which the running deployment has been found and in
which the
+ * dependent ones must be found, too.
+ *
+ * @param _d deployment to stop
+ * @param redeployUrls collects the sourceUrls of the
+ * undeployed apps
+ * @param newUrl the url under which the current deployment should be
redeployed, if at all
+ * @throws J2eeDeploymentException to
+ * indicate problems in undeployment.
+ */
+ protected void stopApplication(Deployment _d, List redeployUrls, URL newUrl,
Scope scope) throws J2eeDeploymentException {
+
+ // synchronize on the scope
+ synchronized(scope.classLoaders) {
+
+ // find out the corresponding classloader
+ ScopedURLClassLoader source=(ScopedURLClassLoader)
+ scope.classLoaders.get(_d.getLocalUrl());
+
+ // its still here, so the thing is not already stopped
+ if(source!=null) {
+
+ try{
+ log.log("About to stop application "+_d.getName());
+
+ // add it to the stopped list
+ redeployUrls.add(newUrl);
+ // get dependency information
+ Iterator allDependencies=scope.getDependentClassLoaders(source).
+ iterator();
+ // deregister classloader
+ scope.deRegisterClassLoader(source);
+
+ // first stop the dependent stuff
+ while(allDependencies.hasNext()) {
+ ScopedURLClassLoader dependentLoader=(ScopedURLClassLoader)
+ allDependencies.next();
+
+ stopApplication(dependentLoader.deployment,
+
redeployUrls,dependentLoader.deployment.getSourceUrl(),scope);
+ }
+
+ } finally {
+
+ try{
+ // now we do the real stopping
+ super.stopApplication(_d);
+
+ // and leave a last message to the classloader to
+ // tear down meta-data or such
+ source.onUndeploy();
+ } finally {
+ try{
+ uninstallApplication(_d);
+ } catch(IOException e) {
+ log.error("could not properly uninstall "+_d.getName());
+ }
+ }
+ }
+
+ } // if
+ } // sync
+
+ }
+
+ /** Overloads the proper stop in order to
+ * be redirected to the dependency stopper
+ * @param scope the scope in which the deployment should be stopped.
+ *
+ * @param _d the deployment to stop
+ * @throws J2eeDeploymentException if an error occures for one of these
+ * modules
+ */
+ protected void stopApplication(Deployment _d, Scope scope) throws
J2eeDeploymentException {
+ stopApplication(_d,new java.util.ArrayList(),_d.getSourceUrl(),scope);
+ }
+
+ /** Undeploys the given URL (if it is deployed) and returns an array
+ * of deployments that have been teared down
+ * Actually only the file name is of interest, so it dont has to be
+ * an URL to be undeployed, the file name is ok as well.
+ * @param _app the stirng spec of the app to tear down
+ *
+ * @param allTearedDown collection of deployments that have been teared down as
a result.
+ *
+ * @param newUrl url under which the application is to be redeployed, if at all
+ *
+ * @throws J2eeDeploymentException if something went wrong (but should have
removed all files)
+ * @throws IOException if file removement fails
+ */
+ public void undeployWithDependencies(String _app, List allTearedDown, URL
newUrl) throws IOException, J2eeDeploymentException {
+ // find currect deployment
+ Deployment d = installer.findDeployment(_app);
+
+ if (d == null)
+ throw new J2eeDeploymentException("The application \""+name+"\" has not
been deployed.");
+
+ Iterator allScopes=scopes.values().iterator();
+
+ while(allScopes.hasNext()) {
+ Scope nextScope=(Scope) allScopes.next();
+ if(nextScope.classLoaders.get(d.getLocalUrl())!=null) {
+ // use dependency stopper that uninstalls already
+ stopApplication(d, allTearedDown, newUrl,nextScope);
+ return;
+ }
+ }
+
+ throw new J2eeDeploymentException("could not find scope for deployment
"+d.getName());
+
+
}
+
+ /** Overrides parent undeploy in order to dispatch
+ * to the dependency undeployer
+ * @param _app name of the application to tear down
+ *
+ * @throws J2eeDeploymentException if something went wrong (but should have
removed all files)
+ * @throws IOException if file removement fails
+ */
+ public void undeploy(String _app) throws IOException, J2eeDeploymentException {
+ undeployWithDependencies(_app,new java.util.ArrayList(),null);
+ }
+
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development