User: user57
Date: 02/02/11 19:22:02
Modified: src/main/org/jboss/deployment EARDeployer.java
MainDeployer.java MainDeployerMBean.java
SARDeployer.java
Log:
o Adding SafeObjectFactory, which simply makes ObjectNames and
turns ant malformed exceptions into Errors. This is used to
create ObjectName OBJECT_NAME fields, so we don't have to keep
creating new ObjectNames all the time.
o MainDeployer & ServiceController use new ObjectName OBJECT_NAME
o Updated refering classes to not wrap OBJECT_NAME with new ObjectName
o Using MBeanProxy to talk to ServiceController (and MainDeployer
in some areas). MBeanProxy is a central location to put in that
pesky JMX exception handling + is tidies up the code base. Can
evevntually optimize this to make it veru efficient too.
o Putting org.jboss.util classes into lib/ext/jboss-util.jar and adding
it to the bootlibraries, so that the core system components have access
to these when loading (not just when running, aka after
jboss-service.xml loads).
* Need to clean up jboss-util, move deployable stuff out of it and such
(they don't really belong there).
o updated modules that needed util, to include jboss-util.jar in there
external module config
Revision Changes Path
1.5 +3 -3 jboss/src/main/org/jboss/deployment/EARDeployer.java
Index: EARDeployer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/EARDeployer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- EARDeployer.java 9 Feb 2002 16:09:17 -0000 1.4
+++ EARDeployer.java 12 Feb 2002 03:22:02 -0000 1.5
@@ -49,7 +49,7 @@
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.4 $
+* @version $Revision: 1.5 $
*/
public class EARDeployer
extends ServiceMBeanSupport
@@ -189,7 +189,7 @@
{
// Register with the main deployer
server.invoke(
- new ObjectName(org.jboss.deployment.MainDeployerMBean.OBJECT_NAME),
+ org.jboss.deployment.MainDeployerMBean.OBJECT_NAME,
"addDeployer",
new Object[] {this},
new String[] {"org.jboss.deployment.DeployerMBean"});
@@ -211,7 +211,7 @@
{
// Register with the main deployer
server.invoke(
- new ObjectName(org.jboss.deployment.MainDeployerMBean.OBJECT_NAME),
+ org.jboss.deployment.MainDeployerMBean.OBJECT_NAME,
"removeDeployer",
new Object[] {this},
new String[] {"org.jboss.deployment.DeployerMBean"});
1.13 +138 -101 jboss/src/main/org/jboss/deployment/MainDeployer.java
Index: MainDeployer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/MainDeployer.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- MainDeployer.java 10 Feb 2002 17:44:32 -0000 1.12
+++ MainDeployer.java 12 Feb 2002 03:22:02 -0000 1.13
@@ -37,49 +37,54 @@
import javax.management.MalformedObjectNameException;
import org.jboss.system.ServiceMBeanSupport;
+
import org.jboss.util.DirectoryBuilder;
+import org.jboss.util.MBeanProxy;
+
/**
- * MainDeployer
- *
- * Takes a series of URL to watch, detects changes and calls the appropriate
Deployers
- *
+ * Takes a series of URL to watch, detects changes and calls the appropriate
Deployers.
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.12 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
+ * @version $Revision: 1.13 $
*/
public class MainDeployer
extends ServiceMBeanSupport
implements MainDeployerMBean, Runnable
{
/** JMX Server **/
- MBeanServer server;
+ private MBeanServer server;
/** Deployers **/
- Set deployers = new HashSet();
+ private Set deployers = new HashSet();
/** Scanned Directories **/
- ArrayList directories = new ArrayList();
+ private ArrayList directories = new ArrayList();
/** I always feel like somebody is watching me, contains DeploymentInfo **/
- Map deployments = new HashMap();
- ArrayList deploymentsList = new ArrayList();
+ private Map deployments = new HashMap();
+ private ArrayList deploymentsList = new ArrayList();
/** Thread running **/
- boolean running = false;
+ private boolean running = false;
/** period of scanning **/
- int period = 5000;
+ private int period = 5000;
/** an increment for tmp files **/
- int id = 0;
+ private int id = 0;
/** Given a flat set of files, this is the order of deployment **/
- String[] order = {"sar", "service.xml", "rar", "jar", "war", "ear", "zip"};
-
- /** Get on period **/
- public void setPeriod(int period) { this.period = period; }
- public int getPeriod() {return period;}
+ private String[] order = { "sar", "service.xml", "rar", "jar", "war", "ear",
"zip" };
+ public void setPeriod(int period) {
+ this.period = period;
+ }
+
+ public int getPeriod() {
+ return period;
+ }
/**
* Directory get set logic, these are "scanning" directories
@@ -101,23 +106,27 @@
// We are dealing with a relative path URL
if (!( url.startsWith("file:") || url.startsWith("http:")))
{
- url = "file:"+System.getProperty("jboss.system.home")+File.separator+url;
+ url = "file:" + System.getProperty("jboss.system.home") + "/" + url;
}
+
// Only one entry
try
{
URL dir = new URL(url);
-
- if (!directories.contains(dir)) directories.add(dir);
+ if (!directories.contains(dir)) {
+ directories.add(dir);
+ }
}
catch (MalformedURLException bad)
{
- log.warn("Failed to add directory scan "+url);
+ log.warn("Failed to add directory scan " + url);
return;
}
- if (log.isDebugEnabled())
+
+ if (log.isDebugEnabled()) {
log.debug("Added directory scan "+url);
+ }
}
public void removeDirectory(String url)
@@ -125,13 +134,15 @@
// We are dealing with a relative path URL
if (!( url.startsWith("file:") || url.startsWith("http:")))
{
- url = System.getProperty("jboss.system.home")+url;
+ url = System.getProperty("jboss.system.home") + url;
}
try
{
int index = directories.lastIndexOf(new URL(url));
- if (index != -1) directories.remove(index);
+ if (index != -1) {
+ directories.remove(index);
+ }
}
catch (MalformedURLException bad)
{
@@ -139,8 +150,9 @@
return;
}
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled()) {
log.debug("Removed directory scan "+url);
+ }
}
public String[] getDeployed()
@@ -156,9 +168,13 @@
return urls;
}
- public void addDeployer(DeployerMBean deployer) { deployers.add(deployer); }
+ public void addDeployer(DeployerMBean deployer) {
+ deployers.add(deployer);
+ }
- public void removeDeployer(DeployerMBean deployer) { deployers.remove(deployer);
}
+ public void removeDeployer(DeployerMBean deployer) {
+ deployers.remove(deployer);
+ }
// ServiceMBeanSupport overrides ---------------------------------
@@ -170,29 +186,31 @@
*/
public String getName()
{
+ //
+ // What is this used for? Should this method be depricated?
+ //
+
return "Main Deployer";
}
/**
* Gets the ObjectName attribute of the AutoDeployer object
- *
- * @param server Description of Parameter
- * @param name Description of Parameter
- * @return The ObjectName value
- * @exception MalformedObjectNameException Description of Exception
*/
protected ObjectName getObjectName(MBeanServer server, ObjectName name)
- throws MalformedObjectNameException
+ throws MalformedObjectNameException
{
this.server = server;
- return name == null ? new ObjectName(OBJECT_NAME) : name;
+ return name == null ? OBJECT_NAME : name;
}
protected void startService()
- throws Exception
+ throws Exception
{
// watch the deploy directory, it is a set so multiple adds
// (start/stop) only one entry is present
+
+ // FIXME: Should pull this from ServerConfig
+
addDirectory("deploy");
// Do a first pass
@@ -211,8 +229,13 @@
running = false;
}
- public boolean getScan() { return running; }
- public void setScan(boolean scan) { running = scan; }
+ public boolean getScan() {
+ return running;
+ }
+
+ public void setScan(boolean scan) {
+ running = scan;
+ }
/**
* Main processing method for the MainDeployer object
@@ -221,6 +244,8 @@
{
do
{
+ scan();
+
// Sleep
try
{
@@ -230,7 +255,6 @@
{
log.debug("interrupted");
}
- scan();
}
while (running);
}
@@ -239,23 +263,27 @@
{
try
{
+ Iterator iter;
+
// Scan diretories for new deployments
- Iterator newDeployments = scanNew().listIterator();
- while (newDeployments.hasNext())
+ iter = scanNew().listIterator();
+ while (iter.hasNext())
{
- deploy((URL) newDeployments.next());
+ deploy((URL)iter.next());
}
- // Undeploy and redeployto the modified ones
- Iterator modified = scanModified().listIterator();
+ // Undeploy and redeploy to the modified ones
+ iter = scanModified().listIterator();
- while (modified.hasNext())
+ while (iter.hasNext())
{
- DeploymentInfo di = (DeploymentInfo) modified.next();
+ DeploymentInfo di = (DeploymentInfo)iter.next();
try
{
// if the url is a file that doesn't exist, it was removed ->
undeploy
+
// TODO: check connection on http protocol and see if it is removed.
+
if (di.url.getProtocol().startsWith("file") && !new
File(di.url.getFile()).exists())
{
undeploy(di);
@@ -284,8 +312,9 @@
{
DeploymentInfo sdi = (DeploymentInfo) deployments.get(new URL(url));
- if (sdi!= null)
+ if (sdi!= null) {
undeploy(sdi);
+ }
}
catch (Exception e)
{
@@ -296,9 +325,7 @@
public void undeploy(DeploymentInfo di)
{
- boolean infoEnabled = log.isInfoEnabled();
- if (infoEnabled)
- log.info("Undeploying "+di.url);
+ log.info("Undeploying "+di.url);
// First remove all sub-deployments
Iterator subs = di.subDeployments.iterator();
@@ -321,15 +348,14 @@
// remove from local maps
deployments.remove(di.url);
- if (deploymentsList.lastIndexOf(di) != -1)
+ if (deploymentsList.lastIndexOf(di) != -1) {
deploymentsList.remove(deploymentsList.lastIndexOf(di));
+ }
// Nuke my stuff, this includes the class loader
di.cleanup(log);
- if (infoEnabled)
- log.info("Undeployed "+di.url);
-
+ log.info("Undeployed "+di.url);
}
catch (Exception e)
{
@@ -372,7 +398,7 @@
}
catch (DeploymentException e)
{
- log.error("Couldn't deploy URL "+url, e);
+ log.error("Could not deploy URL "+url, e);
}
}
@@ -387,8 +413,7 @@
if (deployments.containsKey(deployment.url))
return;
- if (log.isInfoEnabled());
- log.info("Deploying: " + deployment.url.toString());
+ log.info("Deploying: " + deployment.url.toString());
// Create a local copy of that File, the sdi keeps track of the copy
directory
makeLocalCopy(deployment);
@@ -399,24 +424,27 @@
// What deployer is able to deploy this file
findDeployer(deployment);
- if(deployment.deployer != null)
+ if(deployment.deployer != null) {
deployment.deployer.init(deployment);
+ }
// create subdeployments as needed
deploySubPackages(deployment);
// Deploy this SDI, if it is a deployable type
- if (deployment.deployer != null)
+ if (deployment.deployer != null) {
deployment.deployer.deploy(deployment);
+ }
- deployment.status="Deployed";
+ deployment.status = "Deployed";
- if (debug)
+ if (debug) {
log.debug("Done deploying " + deployment.shortName);
+ }
}
catch (DeploymentException e)
{
- deployment.status="Deployment FAILED reason: "+e.getMessage();
+ deployment.status = "Deployment FAILED reason: " + e.getMessage();
throw e;
}
finally
@@ -424,15 +452,19 @@
// whether you do it or not, for the autodeployer
deployment.lastDeployed = System.currentTimeMillis();
- //watch it, it will be picked up as modified below, deployments is a map
duplicates are ok
+ // watch it, it will be picked up as modified below, deployments is a map
duplicates are ok
deployments.put(deployment.url, deployment);
// Do we watch it?
- if
(!deployment.url.toString().startsWith("file:"+System.getProperty("jboss.system.home")+File.separator+"tmp"+File.separator+"deploy"))
+
+ // FIXME: Should not hardcode deployment tmp dir
+
+ if
(!deployment.url.toString().startsWith("file:"+System.getProperty("jboss.system.home")+
"/tmp/deploy"))
{
deploymentsList.add(deployment);
- if (debug)
+ if (debug) {
log.debug("Watching new file: " + deployment.url);
+ }
}
}
}
@@ -448,10 +480,11 @@
// To deploy directories of beans one should just name the directory
// mybean.ear/bla...bla, so that the directory gets picked up by the right
deployer
//
- Iterator iterator = deployers.iterator();
- while (iterator.hasNext())
+
+ Iterator iter = deployers.iterator();
+ while (iter.hasNext())
{
- DeployerMBean deployer = (DeployerMBean) iterator.next();
+ DeployerMBean deployer = (DeployerMBean) iter.next();
if (deployer.accepts(sdi))
{
sdi.deployer = deployer;
@@ -483,10 +516,10 @@
HashSet newDeployments = new HashSet();
boolean trace = log.isTraceEnabled();
// Scan directories
- Iterator iterator = directories.listIterator();
- while (iterator.hasNext())
+ Iterator iter = directories.listIterator();
+ while (iter.hasNext())
{
- File dir = new File(((URL) iterator.next()).getFile());
+ File dir = new File(((URL) iter.next()).getFile());
if (trace)
log.trace("Scanning directory: " + dir);
File[] files = dir.listFiles();
@@ -528,12 +561,11 @@
log.trace("Scanning installed deployments");
// People already deployed, scan for modifications
- Iterator it = deploymentsList.listIterator();
+ Iterator iter = deploymentsList.listIterator();
- while (it.hasNext())
+ while (iter.hasNext())
{
- DeploymentInfo deployment = (DeploymentInfo) it.next();
-
+ DeploymentInfo deployment = (DeploymentInfo) iter.next();
long lastModified = 0;
// Get lastModified of file from file system
@@ -611,11 +643,11 @@
// b- a class in a normal directory structure
// is a "package" and will be deployed
if (name.endsWith(".jar")
- || name.endsWith(".sar")
- || name.endsWith(".ear")
- || name.endsWith(".rar")
- || name.endsWith(".war")
- || name.endsWith(".zip"))
+ || name.endsWith(".sar")
+ || name.endsWith(".ear")
+ || name.endsWith(".rar")
+ || name.endsWith(".war")
+ || name.endsWith(".zip"))
{
// Make sure the name is flat no directory structure in subs name
// example war's WEBINF/lib/myjar.jar appears as myjar.jar in
@@ -626,7 +658,7 @@
try
{
DirectoryBuilder builder =
- new DirectoryBuilder(System.getProperty("jboss.system.home"));
+ new DirectoryBuilder(System.getProperty("jboss.system.home"));
File localCopyDir = builder.cd("tmp").cd("deploy").get();
// We use the name of the entry as the name of the file under deploy
@@ -656,7 +688,7 @@
{
log.error("Error in subDeployment with name "+name, ex);
throw new DeploymentException
- ("Could not deploy sub deployment "+name+" of deployment "+di.url);
+ ("Could not deploy sub deployment "+name+" of deployment
"+di.url);
}
}
@@ -673,14 +705,14 @@
}
// Order the deployments
- Iterator lt = sortDeployments(subDeployments).listIterator();
+ Iterator iter = sortDeployments(subDeployments).listIterator();
// Deploy them all
- while (lt.hasNext())
+ while (iter.hasNext())
{
try
{
- deploy((DeploymentInfo) lt.next());
+ deploy((DeploymentInfo)iter.next());
}
catch (DeploymentException e)
{
@@ -708,8 +740,9 @@
{
ArrayList tmp = new ArrayList();
StringTokenizer st = new StringTokenizer(classPath);
- if (debug)
- log.debug("resolveLibraries: "+classPath);
+ if (debug) {
+ log.debug("resolveLibraries: " + classPath);
+ }
while (st.hasMoreTokens())
{
@@ -719,8 +752,9 @@
DeploymentInfo sub = null;
- if (debug)
+ if (debug) {
log.debug("new manifest entry for sdi at "+sdi.shortName+" entry is
"+tk);
+ }
try
{
@@ -737,7 +771,7 @@
catch (Exception ignore)
{
log.warn("The manifest entry in "+sdi.url+" references URL "+lib+
- " which could not be opened, entry ignored");
+ " which could not be opened, entry ignored");
}
}
}
@@ -767,10 +801,13 @@
sdi.localUrl = sdi.url;
return;
- // FIXME TODO add support for Directory copying over
}
// Are we already in the localCopyDir?
+
+ // FIXME: Should not hard code deploy tmp dir, should also reference it as a
URL, instead
+ // of this mixed mode crap (is this a file or a URL, url should not
use File.sep)
+
else if
(sdi.url.toString().indexOf(System.getProperty("jboss.system.home")+File.separator+"tmp"+File.separator+"deploy")
!= -1)
{
sdi.localUrl = sdi.url;
@@ -778,15 +815,13 @@
}
else
{
- // return new URL("file:"+f.getCanonicalPath());
-
sdi.localUrl = new File (localCopyDir, getNextID
()+"."+sdi.shortName).toURL();
copy(sdi.url, sdi.localUrl);
}
}
catch (Exception e)
{
- log.error("Could not make local copy for "+sdi.url.toString(), e);
+ log.error("Could not make local copy for " + sdi.url, e);
}
}
@@ -801,10 +836,10 @@
}
}
- protected void copy (URL _src, URL _dest) throws IOException
+ protected void copy(URL _src, URL _dest) throws IOException
{
if (!_dest.getProtocol ().equals ("file"))
- throw new IOException ("only file: protocol is allowed as destination!");
+ throw new IOException("only file: protocol is allowed as destination!");
InputStream in;
OutputStream out;
@@ -886,20 +921,22 @@
public boolean isDeployed(String url)
throws MalformedURLException
{
- URL deployURL = new URL(url);
- DeploymentInfo di = getDeployment(deployURL);
- return ( di != null );
+ DeploymentInfo di = getDeployment(new URL(url));
+
+ return (di != null);
}
public DeploymentInfo getDeployment(URL url)
{
- return (DeploymentInfo) deployments.get(url);
+ return (DeploymentInfo)deployments.get(url);
}
public DeploymentInfo removeDeployment(DeploymentInfo di)
{
- return (DeploymentInfo) deployments.remove(di.url);
+ return (DeploymentInfo)deployments.remove(di.url);
}
- private int getNextID() { return id++;}
+ private int getNextID() {
+ return id++;
+ }
}
1.3 +32 -28 jboss/src/main/org/jboss/deployment/MainDeployerMBean.java
Index: MainDeployerMBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/MainDeployerMBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MainDeployerMBean.java 29 Jan 2002 21:12:23 -0000 1.2
+++ MainDeployerMBean.java 12 Feb 2002 03:22:02 -0000 1.3
@@ -1,49 +1,53 @@
/*
-* JBoss, the OpenSource J2EE webOS
-*
-* Distributable under LGPL license.
-* See terms of license at gnu.org.
-*/
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
package org.jboss.deployment;
import java.net.URL;
+
import javax.management.ObjectName;
+
import org.jboss.system.ServiceMBean;
+import org.jboss.util.SafeObjectNameFactory;
/**
-* This is the interface of the AutoDeployer that is exposed for
-* administration
-*
-* @see AutoDeployer
-*
-* @author <a href="mailto:[EMAIL PROTECTED]">Rickard Öberg</a>
-* @author <a href="mailto:[EMAIL PROTECTED]">Toby Allsopp</a>
-* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.2 $
-* <p><b>20011223 marc fleury:</b>
-* <ul>
-* <li>add/RemoveURL, added the capacity to dynamically add a URL to watch
-* <li>add/Removedeployer, dynamically add a new deployer
-* <li>Changed ObjectName to JBOSs-SYSTEM realm (from EJB realm)
-* <li>Rewrite
-* </ul>
-*/
+ * This is the interface of the AutoDeployer that is exposed for
+ * administration
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Rickard Öberg</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Toby Allsopp</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+ * @version $Revision: 1.3 $
+ *
+ * <p><b>20011223 marc fleury:</b>
+ * <ul>
+ * <li>add/RemoveURL, added the capacity to dynamically add a URL to watch
+ * <li>add/Removedeployer, dynamically add a new deployer
+ * <li>Changed ObjectName to JBOSs-SYSTEM realm (from EJB realm)
+ * <li>Rewrite
+ * </ul>
+ */
public interface MainDeployerMBean
-extends ServiceMBean
+ extends ServiceMBean
{
/** The default object name. */
- String OBJECT_NAME = "jboss.system:service=MainDeployer";
-
+ ObjectName OBJECT_NAME = SafeObjectNameFactory.create("jboss.system",
+ "service",
+ "MainDeployer");
/** individual URLs for dynamically deploying **/
void deploy(String URL);
void undeploy(String URL);
void deploy(DeploymentInfo sdi)
- throws DeploymentException;
+ throws DeploymentException;
public void undeploy(DeploymentInfo sdi)
- throws DeploymentException;
+ throws DeploymentException;
/** Dynamically add directories to scan **/
@@ -57,7 +61,7 @@
/** get all the watched URLs in this deployment **/
String[] getDeployed();
- /** Get set scan-period**/
+ /** Get set scan-period **/
void setScan( boolean scan);
boolean getScan();
void setPeriod(int period);
1.10 +189 -275 jboss/src/main/org/jboss/deployment/SARDeployer.java
Index: SARDeployer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/SARDeployer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SARDeployer.java 11 Feb 2002 23:04:25 -0000 1.9
+++ SARDeployer.java 12 Feb 2002 03:22:02 -0000 1.10
@@ -13,8 +13,10 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;
+
import java.net.MalformedURLException;
import java.net.URL;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -29,6 +31,7 @@
import java.util.jar.JarFile;
import java.util.Enumeration;
import java.util.jar.JarEntry;
+
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanServer;
@@ -40,11 +43,14 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+
import org.jboss.deployment.DeploymentInfo;
import org.jboss.system.Service;
import org.jboss.system.ServiceControllerMBean;
import org.jboss.system.ServiceLibraries;
import org.jboss.system.ServiceMBeanSupport;
+import org.jboss.util.MBeanProxy;
+
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -59,7 +65,8 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">David Maplesden</a>
* @author <a href="mailto:[EMAIL PROTECTED]">David Jencks</a>
- * @version $Revision: 1.9 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
+ * @version $Revision: 1.10 $
*
* <p><b>20010830 marc fleury:</b>
* <ul>
@@ -100,44 +107,42 @@
extends ServiceMBeanSupport
implements SARDeployerMBean
{
- // Attributes --------------------------------------------------------
- // private ObjectName objectName;
-
- // Find all the deployment info for a url
- // private final Map urlToDeploymentInfoMap = new HashMap();
-
- // Find what package an mbean came from.
- // private final Map objectNameToSupplyingPackageMap = new HashMap();
-
+ /** A proxy to the ServiceController. */
+ private ServiceControllerMBean serviceController;
+
+ /** A proxy to the MainDeployer. */
+ private MainDeployerMBean mainDeployer;
// Public --------------------------------------------------------
/**
- * Gets the Name of the ServiceDeployer object
- *
- * @return returns "ServiceDeployer"
- */
+ * Gets the Name of the ServiceDeployer object
+ *
+ * @return returns "ServiceDeployer"
+ */
public String getName()
{
return "ServiceDeployer";
}
/**
- * Gets the FilenameFilter that the AutoDeployer uses to decide which files
- * will be deployed by the ServiceDeployer. Currently .jsr, .sar, and files
- * ending in service.xml are accepted.
- *
- * @return The FileNameFilter for use by the AutoDeployer.
- */
+ * Gets the FilenameFilter that the AutoDeployer uses to decide which files
+ * will be deployed by the ServiceDeployer. Currently .jsr, .sar, and files
+ * ending in service.xml are accepted.
+ *
+ * @return The FileNameFilter for use by the AutoDeployer.
+ */
public boolean accepts(DeploymentInfo di)
{
return (di.url.toString().endsWith(".sar")
- || di.url.toString().endsWith("service.xml"));
+ || di.url.toString().endsWith("service.xml"));
}
public void init(DeploymentInfo di)
throws DeploymentException
{
+ boolean debug = log.isDebugEnabled();
+
try
{
// resolve the watch
@@ -152,10 +157,13 @@
File file = new File (di.url.getFile());
// If not directory we watch the package
- if (!file.isDirectory()) di.watch = di.url;
-
+ if (!file.isDirectory()) {
+ di.watch = di.url;
+ }
// If directory we watch the xml files
- else di.watch = new URL(di.url, "META-INF/jboss-service.xml");
+ else {
+ di.watch = new URL(di.url, "META-INF/jboss-service.xml");
+ }
}
// Get the document
@@ -169,17 +177,26 @@
//Copy local directory if local-directory element is present
NodeList lds = di.document.getElementsByTagName("local-directory");
- log.debug("about to copy " + lds.getLength() + " local directories");
+ if (debug) {
+ log.debug("about to copy " + lds.getLength() + " local directories");
+ }
+
for (int i = 0; i< lds.getLength(); i++)
{
Element ld = (Element)lds.item(i);
String path = ld.getAttribute("path");
- log.debug("about to copy local directory at " + path);
+ if (debug) {
+ log.debug("about to copy local directory at " + path);
+ }
+
File jbossHomeDir = new File(System.getProperty("jboss.system.home"));
File localBaseDir = new File(jbossHomeDir, "db"+File.separator);
+
//Get the url of the local copy from the classloader.
- log.debug("copying from " + di.localUrl.toString() + path);
- log.debug("copying to " + localBaseDir);
+ if (debug) {
+ log.debug("copying from " + di.localUrl.toString() + path);
+ log.debug("copying to " + localBaseDir);
+ }
inflateJar(di.localUrl, localBaseDir, path);
} // end of for ()
@@ -203,8 +220,6 @@
log.debug("Deploying SAR: url " + di.url);
}
- ObjectName serviceController = getServiceControllerName();
-
List mbeans = di.mbeans;
mbeans.clear();
@@ -215,12 +230,7 @@
Element mbean = (Element)nl.item(i);
log.debug("deploying with ServiceController mbean " + mbean);
-
- ObjectName service = (ObjectName)invoke(
- serviceController,
- "install",
- new Object[]{ mbean },
- new String[]{ "org.w3c.dom.Element" });
+ ObjectName service = serviceController.install(mbean);
if (service != null)
{
@@ -239,11 +249,7 @@
service = (ObjectName)iter.next();
// The service won't be created until explicitely dependent mbeans are
created
- invoke(
- serviceController,
- "create",
- new Object[]{ service },
- new String[]{ "javax.management.ObjectName" });
+ serviceController.create(service);
}
// start the services
@@ -253,14 +259,11 @@
service = (ObjectName)iter.next();
// The service won't be started until explicitely dependent mbeans are
started
- invoke(
- serviceController,
- "start",
- new Object[]{ service },
- new String[]{ "javax.management.ObjectName" });
+ serviceController.start(service);
}
}
catch (Exception e) {
+ log.error("operation failed", e);
throw new DeploymentException(e);
}
}
@@ -268,13 +271,16 @@
protected void parseXMLClasspath(DeploymentInfo di)
throws DeploymentException
{
+ boolean debug = log.isDebugEnabled();
Set classpath = new HashSet();
NodeList classpaths = di.document.getElementsByTagName("classpath");
for (int i = 0; i < classpaths.getLength(); i++)
{
Element classpathElement = (Element)classpaths.item(i);
- log.debug("Found classpath element: " + classpathElement);
+ if (debug) {
+ log.debug("Found classpath element: " + classpathElement);
+ }
//String codebase = System.getProperty("jboss.system.libraryDirectory");
String codebase = "";
@@ -285,7 +291,9 @@
{
// Load the codebase
codebase = classpathElement.getAttribute("codebase").trim();
- log.debug("Setting up classpath from raw codebase: " + codebase);
+ if (debug) {
+ log.debug("Setting up classpath from raw codebase: " + codebase);
+ }
if ("".equals(codebase) || ".".equals(codebase))
{
@@ -309,10 +317,16 @@
{
codebase += "/";
}
- log.debug("codebase is " + codebase);
+
+ if (debug) {
+ log.debug("codebase is " + codebase);
+ }
+
//get the archives string
archives = classpathElement.getAttribute("archives").trim();
- log.debug("archives are " + archives);
+ if (debug) {
+ log.debug("archives are " + archives);
+ }
}
if (codebase.startsWith("file:") && archives.equals("*"))
@@ -326,21 +340,20 @@
new java.io.FileFilter()
{
/**
- * filters for jar and zip files in the local directory.
- *
- * @param pathname Path to the candidate file.
- * @return True if the file is a jar or zip
- * file.
- */
+ * filters for jar and zip files in the local directory.
+ *
+ * @param pathname Path to the candidate file.
+ * @return True if the file is a jar or zip
+ * file.
+ */
public boolean accept(File pathname)
{
String name2 = pathname.getName();
return
-
- (name2.endsWith(".jar") || name2.endsWith(".zip"));
+ (name2.endsWith(".jar") || name2.endsWith(".zip"));
}
- }
- );
+ });
+
for (int j = 0; jars != null && j < jars.length; j++)
{
classpath.add(jars[j].getCanonicalFile().toURL());
@@ -391,19 +404,19 @@
new java.io.FileFilter()
{
/**
- * filters for jar and zip files in the local directory.
- *
- * @param pathname Path to the candidate file.
- * @return True if the file is a jar or zip
- * file.
- */
+ * filters for jar and zip files in the local directory.
+ *
+ * @param pathname Path to the candidate file.
+ * @return True if the file is a jar or zip
+ * file.
+ */
public boolean accept(File pathname)
{
String name2 = pathname.getName();
return name2.endsWith(".jar") || name2.endsWith(".zip");
}
- }
- );
+ });
+
for (int j = 0; jars != null && j < jars.length; j++)
{
classpath.add(jars[j].getCanonicalFile().toURL());
@@ -460,143 +473,125 @@
// An external package is not a "subdeployment" it is a stand alone
// deployment scanned as such
DeploymentInfo sub = new DeploymentInfo(neededUrl, null);
-
- invoke(
- new ObjectName(org.jboss.deployment.MainDeployerMBean.OBJECT_NAME),
- "deploy",
- new Object[] {sub},
- new String[] {"org.jboss.deployment.DeploymentInfo"});
+ mainDeployer.deploy(sub);
+
}
catch (Exception e)
{
log.error("operation failed", e);
}
- log.debug("deployed classes for " + neededUrl);
- } // end of while ()
+
+ if (debug) {
+ log.debug("deployed classes for " + neededUrl);
+ }
+ }
}
/**
- * Undeploys the package at the url string specified. This will: Undeploy
- * packages depending on this one. Stop, destroy, and unregister all the
- * specified mbeans Unload this package and packages this package deployed
- * via the classpath tag. Keep track of packages depending on this one that
- * we undeployed so that they can be redeployed should this one be
- * redeployed.
- *
- * @param urlString The location of the package to be
- * undeployed (used to index the packages, not to read service.xml on
- * undeploy!
- * @exception MalformedURLException Thrown if the url string is not valid.
- * @exception IOException Thrown if something could not be read.
- * @exception DeploymentException Thrown if the package could not be
- * undeployed
- */
+ * Undeploys the package at the url string specified. This will: Undeploy
+ * packages depending on this one. Stop, destroy, and unregister all the
+ * specified mbeans Unload this package and packages this package deployed
+ * via the classpath tag. Keep track of packages depending on this one that
+ * we undeployed so that they can be redeployed should this one be
+ * redeployed.
+ *
+ * @param urlString The location of the package to be
+ * undeployed (used to index the packages, not to read
+ * service.xml on undeploy!
+ *
+ * @exception MalformedURLException Thrown if the url string is not valid.
+ * @exception IOException Thrown if something could not be read.
+ * @exception DeploymentException Thrown if the package could not be
+ * undeployed
+ */
public void undeploy(DeploymentInfo sdi)
throws DeploymentException
{
- log.debug("undeploying document " + sdi.url);
+ boolean debug = log.isDebugEnabled();
+
+ if (debug) {
+ log.debug("undeploying document " + sdi.url);
+ }
List services = sdi.mbeans;
int lastService = services.size();
- //stop services in reverse order.
- for (ListIterator i = services.listIterator(lastService); i.hasPrevious();)
- {
- ObjectName name = (ObjectName)i.previous();
- log.debug("stopping mbean " + name);
- invoke(getServiceControllerName(),
- "stop",
- new Object[] {name},
- new String[] {"javax.management.ObjectName"});
- }
- for (ListIterator i = services.listIterator(lastService); i.hasPrevious();)
- {
- ObjectName name = (ObjectName)i.previous();
- log.debug("destroying mbean " + name);
- invoke(getServiceControllerName(),
- "destroy",
- new Object[] {name},
- new String[] {"javax.management.ObjectName"});
- }
- for (ListIterator i = services.listIterator(lastService); i.hasPrevious();)
- {
- ObjectName name = (ObjectName)i.previous();
- log.debug("removing mbean " + name);
- invoke(getServiceControllerName(),
- "remove",
- new Object[] {name},
- new String[] {"javax.management.ObjectName"});
- //we don't supply it any more, maybe someone else will later.
- // objectNameToSupplyingPackageMap.remove(name);
+
+ try {
+ // stop services in reverse order.
+ for (ListIterator i = services.listIterator(lastService); i.hasPrevious();)
+ {
+ ObjectName name = (ObjectName)i.previous();
+ if (debug) {
+ log.debug("stopping mbean " + name);
+ }
+ serviceController.stop(name);
+ }
+
+ for (ListIterator i = services.listIterator(lastService); i.hasPrevious();)
+ {
+ ObjectName name = (ObjectName)i.previous();
+ if (debug) {
+ log.debug("destroying mbean " + name);
+ }
+ serviceController.destroy(name);
+ }
+
+ for (ListIterator i = services.listIterator(lastService); i.hasPrevious();)
+ {
+ ObjectName name = (ObjectName)i.previous();
+ if (debug) {
+ log.debug("removing mbean " + name);
+ }
+ serviceController.remove(name);
+ }
+ }
+ catch (Exception e) {
+ throw new DeploymentException(e);
}
}
-
/**
- * MBeanRegistration interface. Get the mbean server.
- * This is the only deployer that registers with the MainDeployer here
- *
- * @param server Our mbean server.
- * @param name our proposed object name.
- * @return our actual object name
- * @exception java.lang.Exception Thrown if we are supplied an invalid name.
- */
+ * MBeanRegistration interface. Get the mbean server.
+ * This is the only deployer that registers with the MainDeployer here
+ *
+ * @param server Our mbean server.
+ * @param name our proposed object name.
+ * @return our actual object name
+ * @exception java.lang.Exception Thrown if we are supplied an invalid name.
+ */
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws Exception
{
super.preRegister(server, name);
log.debug("ServiceDeployer preregistered with mbean server");
+ mainDeployer = (MainDeployerMBean)
+ MBeanProxy.create(MainDeployerMBean.class,
+ MainDeployerMBean.OBJECT_NAME);
+
// Register with the main deployer
- server.invoke(
- new ObjectName(org.jboss.deployment.MainDeployerMBean.OBJECT_NAME),
- "addDeployer",
- new Object[] {this},
- new String[] {"org.jboss.deployment.DeployerMBean"});
+ mainDeployer.addDeployer(this);
return name == null ? new ObjectName(OBJECT_NAME) : name;
}
-
+
/**
- * PostRegister initialized the ServiceDeployed mbean and tries to load a
- * spine package to set up basic jboss. At the moment the spine package
- * should be jboss-service.xml or (deprecated) jboss.jcml. Soon we should
- * have an actual sar with the code as well as configuration info.
- *
- * @param registrationDone Description of Parameter
- */
- /*public void postRegister(java.lang.Boolean registrationDone)
- {
- try
- {
- super.postRegister(registrationDone);
-
- //Start us up, which also sets up the deploy temp directory
- invoke(getServiceControllerName(),
- "create",
- new Object[] {objectName},
- new String[] {"javax.management.ObjectName"});
-
- invoke(getServiceControllerName(),
- "start",
- new Object[] {objectName},
- new String[] {"javax.management.ObjectName"});
- }
- catch (Exception e)
- {
- log.error("Problem postregistering ServiceDeployer", e);
- }
+ * Once registration has finished, create a proxy to the ServiceController
+ * for later use.
+ */
+ public void postRegister(Boolean done) {
+ super.postRegister(done);
+
+ serviceController = (ServiceControllerMBean)
+ MBeanProxy.create(ServiceControllerMBean.class,
+ ServiceControllerMBean.OBJECT_NAME,
+ server);
}
- */
public void preDeregister()
throws Exception
{
- server.invoke(
- new ObjectName(org.jboss.deployment.MainDeployerMBean.OBJECT_NAME),
- "removeDeployer",
- new Object[] {this},
- new String[] {"org.jboss.deployment.DeployerMBean"});
-
+ mainDeployer.removeDeployer(this);
}
protected void parseDocument(DeploymentInfo di)
@@ -620,55 +615,28 @@
InputSource is = new InputSource(stream);
di.document = parser.parse(is);
}
- catch (SAXException e)
- {
- log.warn("SaxException getting document:", e);
- throw new DeploymentException(e.getMessage());
- }
- catch (ParserConfigurationException pce)
- {
- log.warn("ParserConfigurationException getting document:", pce);
- throw new DeploymentException(pce.getMessage());
- }
catch (Exception e)
{
- log.warn("Exception getting document:", e);
- throw new DeploymentException(e.getMessage());
- } // end of try-catch
+ throw new DeploymentException("Exception getting document", e);
+ }
}
// Private --------------------------------------------------------
- private ObjectName getServiceControllerName()
- throws DeploymentException
- {
- try
- {
- return new ObjectName(ServiceControllerMBean.OBJECT_NAME);
- }
- catch (Exception e)
- {
- throw new DeploymentException ("Couldn't get the ObjectName for the
ServiceControllerMBean");
- }
- }
-
- private void removeMBeans(URL url, DeploymentInfo sdi) throws DeploymentException
- {
- }
-
/**
- * The <code>inflateJar</code> copies the jar entries
- * from the jar url jarUrl to the directory destDir.
- * It can be used on the whole jar, a directory, or
- * a specific file in the jar.
- *
- * @param jarUrl the <code>URL</code> if the directory or entry to copy.
- * @param destDir the <code>File</code> value of the directory in which to
- * place the inflated copies.
- * @exception DeploymentException if an error occurs
- * @exception IOException if an error occurs
- */
+ * The <code>inflateJar</code> copies the jar entries
+ * from the jar url jarUrl to the directory destDir.
+ * It can be used on the whole jar, a directory, or
+ * a specific file in the jar.
+ *
+ * @param jarUrl the <code>URL</code> if the directory or entry to copy.
+ * @param destDir the <code>File</code> value of the directory in which to
+ * place the inflated copies.
+ *
+ * @exception DeploymentException if an error occurs
+ * @exception IOException if an error occurs
+ */
protected void inflateJar(URL url, File destDir, String path)
throws DeploymentException, IOException
{
@@ -688,6 +656,8 @@
(JarURLConnection)jarUrl.openConnection();
JarFile jarFile = jarConnection.getJarFile();
*/
+
+
String filename = url.getFile();
JarFile jarFile = new JarFile(filename);
try
@@ -702,10 +672,10 @@
if (!outFile.exists())
{
- if (entry.isDirectory()) outFile.mkdirs();
-
- else
- {
+ if (entry.isDirectory()) {
+ outFile.mkdirs();
+ }
+ else {
InputStream in = jarFile.getInputStream(entry);
OutputStream out = new FileOutputStream(outFile);
@@ -713,7 +683,9 @@
{
byte[] buffer = new byte[1024];
int read;
- while ((read = in.read(buffer)) > 0) out.write(buffer, 0,
read);
+ while ((read = in.read(buffer)) > 0) {
+ out.write(buffer, 0, read);
+ }
}
finally
{
@@ -728,63 +700,5 @@
{
jarFile.close();
}
- }
-
-
- /**
- * Parse an object name from the given element attribute 'name'.
- *
- * @param element Element to parse name from.
- * @return Object name.
- *
- * @throws ConfigurationException Missing attribute 'name'
- * (thrown if 'name' is null or "").
- * @throws MalformedObjectNameException
- */
- private ObjectName parseObjectName(final Element element)
- throws org.jboss.system.ConfigurationException, MalformedObjectNameException
- {
- String name = ((org.w3c.dom.Text)element.getFirstChild()).getData().trim();
- if (name == null || name.trim().equals("")) {
- throw new org.jboss.system.ConfigurationException
- ("Name element must have a value.");
- }
- return new ObjectName(name);
- }
-
-
- /* Calls server.invoke, unwraps exceptions, and returns server output
- */
- private Object invoke(ObjectName name, String method, Object[] args, String[]
sig)
- {
- try
- {
- return server.invoke(name, method, args, sig);
- }
- catch (MBeanException mbe)
- {
- log.error("Mbean exception while executing " + method + " on " + args,
mbe.getTargetException());
- }
- catch (RuntimeMBeanException rbe)
- {
- log.error("Runtime Mbean exception while executing " + method + " on " +
args, rbe.getTargetException());
- }
- catch (RuntimeErrorException ree)
- {
- log.error("Runtime Error exception while executing " + method + " on " +
args, ree.getTargetError());
- }
- catch (ReflectionException re)
- {
- log.error("ReflectionException while executing " + method + " on " + args,
re);
- }
- catch (InstanceNotFoundException re)
- {
- log.error("InstanceNotFoundException while executing " + method + " on " +
args, re);
- }
- catch (Exception e)
- {
- log.error("Exception while executing " + method + " on " + args, e);
- }
- return null;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development