User: jules_gosnell
Date: 01/06/21 15:24:46
Modified: jetty/src/main/org/jboss/jetty JettyService.java
Log:
implement PublishMBeans property
ensure Service methods will not break if called more than once
general tidy up
Revision Changes Path
1.16 +102 -64 contrib/jetty/src/main/org/jboss/jetty/JettyService.java
Index: JettyService.java
===================================================================
RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JettyService.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- JettyService.java 2001/06/14 00:21:37 1.15
+++ JettyService.java 2001/06/21 22:24:46 1.16
@@ -36,7 +36,7 @@
*
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Julian Gosnell</a>
- * @version $Revision: 1.15 $
+ * @version $Revision: 1.16 $
*/
class JettyMBean extends HttpServerMBean
@@ -85,22 +85,8 @@
// NOTES
-// 1. it would be better if performUndeploy() passed us the appData,
-// so we did not have to maintain our own warUrl:userData hashtable
+// Logging is in serious need of tidying up...
-// 2. DOM is not the fastest way of parsing an XML file. Does Scott
-// really need the DOM lying around after he has set up all the
-// naming? could he make use of the fact that Greg has already done a
-// pass over web.xml
-
-// 3. Can Greg provide me with a method for retrieving web.xml and
-// jboss-web.xml InputStreams ?
-
-// 4. Looks like Greg may have to split up his start() method so that
-// we can ensure that all naming and security services are started
-// before the webapp itself. We need to get at the jboss-web.xml file
-// and parse it before he fires up the webapp - or do we ??
-
public class JettyService extends AbstractWebContainer
implements JettyServiceMBean, MBeanRegistration
{
@@ -140,7 +126,7 @@
}
catch (Exception e)
{
- com.mortbay.Util.Log.event("Could not figure out JBOSS_HOME -
com.mortbay.HTTP.HttpServer displaced");
+ com.mortbay.Util.Log.warning("Could not figure out JBOSS_HOME -
com.mortbay.HTTP.HttpServer displaced");
}
return null;
@@ -190,8 +176,10 @@
{
// make a Jetty...
_jetty = new Jetty();
+
_jetty.setJettyHome(_jettyHome);
- _jetty.setWebDefault(_webDefault);
+ _jetty.setWebDefault(getWebDefault());
+ _jetty.setUnpackWars(getUnpackWars());
com.mortbay.Util.Log.event("Jetty instantiated and initialised");
@@ -201,20 +189,30 @@
}
protected void
- ensureMBean()
+ ensureConfig()
{
- try
+ // this must be done before config is read otherwise configs
+ // defined therein will not receive MBean peers.
+ if (getPublishMBeans())
{
- _mbean = new JettyMBean(_jetty);
- _server.registerMBean(_mbean, new ObjectName(_mbean.newObjectName(_server)));
- }
- catch (Exception e)
- {
- e.printStackTrace();
+ try
+ {
+ _mbean = new JettyMBean(_jetty);
+ _server.registerMBean(_mbean, new ObjectName(_mbean.newObjectName(_server)));
+ com.mortbay.Util.Log.event("MBean peers WILL be created for Jetty Contexts");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ catch (Error e)
+ {
+ e.printStackTrace();
+ }
}
- catch (Error e)
+ else
{
- e.printStackTrace();
+ com.mortbay.Util.Log.event("MBean peers WILL NOT be created for Jetty
Contexts");
}
for (int i=0; i<_configuration.size(); i++)
@@ -236,7 +234,7 @@
{
ensureProperties();
ensureJetty();
- ensureMBean();
+ ensureConfig();
}
//----------------------------------------------------------------------------
@@ -258,57 +256,58 @@
//----------------------------------------------------------------------------
// 'service' interface
-
- // called by lifecycle methods as defined in ServiceMBeanSupport.
-
-
- // we should probably bind our instance of Jetty directly into our
- // own lifecycle, so that when init(), start(), stop() and destroy()
- // are called on us, the equivalent is done to our delegate.
-
- // How should we do it ?
-
- // a). We delegate to the JettyMBean which delegates to Jetty
- // b). We do it directly to Jetty and the MBean recieves notification if necessary
-
//----------------------------------------------------------------------------
public void
initService()
throws Exception
{
- super.initService();
-
- try {ensureService();} catch (Exception e) {e.printStackTrace();}
+ if (!isInitialised())
+ {
+ super.initService();
+ try {ensureService();} catch (Exception e) {e.printStackTrace();}
+ }
+ else
+ com.mortbay.Util.Log.warning("Jetty has already been initialised");
}
-
+
public void
startService()
throws Exception
{
- Log.setLog(_log);
- com.mortbay.Util.Log.event("Starting (jetty.mortbay.com)");
- super.startService();
- com.mortbay.Util.Log.event("Started successfully");
- Log.unsetLog();
+ if (!isStarted())
+ {
+ super.startService();
+ _jetty.start();
+ }
+ else
+ com.mortbay.Util.Log.warning("Jetty has already been started");
}
public void
stopService()
{
- com.mortbay.Util.Log.event("Stopping: if using sun jdk 1.3 on linux, waits 1
minute for Sun bug 4386498... ");
- super.stopService();
- com.mortbay.Util.Log.event("Stopped Successfully");
+ if (!isStopped())
+ {
+ super.stopService();
+ try {_jetty.stop();} catch (Exception e) {e.printStackTrace();}
+ }
+ else
+ com.mortbay.Util.Log.warning("Jetty has already been stopped");
}
public void
destroyService()
{
- Log.setLog(_log);
- com.mortbay.Util.Log.event("Destroying (jetty.mortbay.com)");
- super.destroyService();
- com.mortbay.Util.Log.event("Destroyed successfully");
- Log.unsetLog();
+ if (!isDestroyed())
+ {
+ super.destroyService();
+ _jetty.destroy();
+ _jetty=null;
+ _mbean=null;
+ }
+ else
+ com.mortbay.Util.Log.warning("Jetty has already been destroyed");
}
//----------------------------------------------------------------------------
@@ -329,11 +328,11 @@
_jetty.undeploy(warUrl);
}
-// public boolean
-// isDeployed(String warUrl)
-// {
-// return _jetty.isDeployed(warUrl);
-// }
+ // public boolean
+ // isDeployed(String warUrl)
+ // {
+ // return _jetty.isDeployed(warUrl);
+ // }
//----------------------------------------------------------------------------
@@ -343,9 +342,44 @@
return (_jetty!=null);
}
+ protected boolean
+ isStarted()
+ {
+ return (_jetty!=null && _jetty.isStarted());
+ }
+
+ protected boolean
+ isStopped()
+ {
+ return (_jetty!=null && !_jetty.isStarted());
+ }
+
+ protected boolean
+ isDestroyed()
+ {
+ return (_jetty==null);
+ }
+
//----------------------------------------------------------------------------
+ protected boolean _publishMBeans=false;
+
+ public boolean
+ getPublishMBeans()
+ {
+ return _publishMBeans;
+ }
+
+ public void
+ setPublishMBeans(boolean publishMBeans)
+ {
+ com.mortbay.Util.Log.event("setting PublishMBeans to "+publishMBeans);
+
+ _publishMBeans=publishMBeans;
+ }
+ //----------------------------------------------------------------------------
+
protected boolean _unpackWars=false;
public boolean
@@ -360,6 +394,8 @@
public void
setUnpackWars(boolean unpackWars)
{
+ com.mortbay.Util.Log.event("setting UnpackWars to "+unpackWars);
+
if (isInitialised())
_jetty.setUnpackWars(unpackWars);
else
@@ -382,6 +418,8 @@
public void
setWebDefault(String webDefault)
{
+ com.mortbay.Util.Log.event("setting WebDefault to "+webDefault);
+
if (isInitialised())
_jetty.setWebDefault(webDefault);
else
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development