User: d_jencks
Date: 01/11/11 22:52:17
Modified: src/main/org/jboss/system Service.java
ServiceController.java ServiceControllerMBean.java
ServiceMBeanSupport.java Shutdown.java
Log:
Changes to move toward eliminating init and destroy from Service interface, and make
J2eeDeployer use mbean-refs. (2nd try at committing - is cvs acting weird?
Revision Changes Path
1.3 +8 -4 jboss/src/main/org/jboss/system/Service.java
Index: Service.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/Service.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Service.java 2001/09/08 00:53:57 1.2
+++ Service.java 2001/11/12 06:52:17 1.3
@@ -10,20 +10,24 @@
* The Service interface for the JBOSS-SYSTEM.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>.
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*
* <p><b>20010830 marc fleury:</b>
* <ul>
* <li>Initial import
* </ul>
+ * <p><b>20011111 david jencks:</b>
+ * <ul>
+ * <li>removed init and destroy methods
+ * </ul>
+
*/
public interface Service
{
- void init() throws Exception;
-
void start() throws Exception;
void stop();
-
+ //well I tried... maybe later.
+ void init() throws Exception;
void destroy();
}
1.12 +48 -159 jboss/src/main/org/jboss/system/ServiceController.java
Index: ServiceController.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/ServiceController.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ServiceController.java 2001/11/10 21:38:06 1.11
+++ ServiceController.java 2001/11/12 06:52:17 1.12
@@ -33,6 +33,7 @@
import javax.management.RuntimeOperationsException;
import org.w3c.dom.Element;
import javax.management.IntrospectionException;
+import org.jboss.logging.Logger;
/**
* This is the main Service Controller. A controller can deploy a service to a
@@ -41,7 +42,7 @@
* @see org.jboss.system.Service
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">David Jencks</a>
- * @version $Revision: 1.11 $ <p>
+ * @version $Revision: 1.12 $ <p>
*
* <b>Revisions:</b> <p>
*
@@ -57,9 +58,13 @@
* </ol>
*/
public class ServiceController
- extends ServiceMBeanSupport
+ //extends ServiceMBeanSupport
implements ServiceControllerMBean, MBeanRegistration
{
+
+ private final Logger log = Logger.create(getClass());
+
+
/**
* A mapping from the Service interface method names to the corresponding
* index into the ServiceProxy.hasOp array.
@@ -111,6 +116,11 @@
// Public --------------------------------------------------------
+ public Logger getLog()
+ {
+ return log;
+ }
+
/**
* Gets the Name attribute of the ServiceController object
*
@@ -293,7 +303,6 @@
public void undeploy(ObjectName objectName) throws Exception
{
stop(objectName);
- destroy(objectName);
//We are not needing anyone or waiting for anyone
ArrayList weNeededList = (ArrayList)mbeanToMBeanRefsMap.remove(objectName);
if (weNeededList != null)
@@ -349,7 +358,10 @@
// Remove the MBeanClassLoader used by the MBean
ObjectName loader =
new ObjectName("ZClassLoaders:id=" + objectName.hashCode());
- server.unregisterMBean(loader);
+ if (server.isRegistered(loader))
+ {
+ server.unregisterMBean(loader);
+ } // end of if ()
}
else
{
@@ -383,6 +395,23 @@
return name == null ? new ObjectName(OBJECT_NAME) : name;
}
+ public void postRegister(Boolean registrationDone)
+ {
+ if (!registrationDone.booleanValue())
+ {
+ log.info( "Registration of ServiceController failed" );
+ }
+ }
+
+ public void preDeregister()
+ throws Exception
+ {
+ }
+
+ public void postDeregister()
+ {
+ }
+
// methods about suspension.
public synchronized boolean isSuspended(ObjectName objectName)
@@ -392,167 +421,49 @@
// Service implementation ----------------------------------------
- /**
- * #Description of the Method
- *
- * @exception Exception Description of Exception
- */
- public void init()
- throws Exception
- {
-
- log.info("Initializing " + startedServices.size() + " startedServices");
-
- List servicesCopy = new ArrayList(startedServices);
- Iterator enum = servicesCopy.iterator();
- int serviceCounter = 0;
- ObjectName name = null;
-
- while (enum.hasNext())
- {
- name = (ObjectName)enum.next();
- try
- {
- ((Service)nameToServiceMap.get(name)).init();
- serviceCounter++;
- }
- catch (Throwable e)
- {
- log.error("Could not initialize " + name, e);
- }
- }
-
- log.info("Initialized " + serviceCounter + " services");
- }
/**
- * #Description of the Method
- *
- * @exception Exception Description of Exception
- */
- public void start()
- throws Exception
- {
- log.info("Starting " + startedServices.size() + " services");
-
- List servicesCopy = new ArrayList(startedServices);
- Iterator enum = servicesCopy.iterator();
- int serviceCounter = 0;
- ObjectName name = null;
-
- while (enum.hasNext())
- {
- name = (ObjectName)enum.next();
-
- try
- {
- ((Service)nameToServiceMap.get(name)).start();
- serviceCounter++;
- }
- catch (Throwable e)
- {
- log.error("Could not start " + name, e);
- }
- }
- log.info("Started " + serviceCounter + " services");
- }
-
- /**
* This is the only one we should have of these lifecycle methods!
*/
- public void stop()
+ public synchronized void shutdown()
{
log.info("Stopping " + startedServices.size() + " services");
List servicesCopy = new ArrayList(startedServices);
- ListIterator enum = servicesCopy.listIterator();
+ //ListIterator enum = servicesCopy.listIterator();
int serviceCounter = 0;
ObjectName name = null;
- while (enum.hasNext())
- {
- enum.next();
- }
- // pass them all
- while (enum.hasPrevious())
+ for (ListIterator i = servicesCopy.listIterator(servicesCopy.size() - 1);
+ i.hasPrevious(); )
{
- name = (ObjectName)enum.previous();
+ name = (ObjectName)i.previous();
try
{
- ((Service)nameToServiceMap.get(name)).stop();
+ undeploy(name);
+ //((Service)nameToServiceMap.get(name)).stop();
+ //((Service)nameToServiceMap.get(name)).destroy();//should be obsolete
soon
+ //server.unregisterMBean(name);
serviceCounter++;
}
catch (Throwable e)
{
- log.error("Could not stop " + name, e);
+ log.error("Could not undeploy " + name, e);
}
}
log.info("Stopped " + serviceCounter + " services");
}
- /**
- * #Description of the Method
- */
- public void destroy()
- {
-
- // We now iterate the destroy one and one to be able to filter out
- // some services and are handeling this code in the class Shutdown
- // until we have a new (un)dependency mechanism ...
-
- log.info("ServiceController destroy commented out for now ...");
-
- /*
- log.info("Destroying " + services.size() + " services");
- List servicesCopy = new ArrayList(startedServices);
- ListIterator enum = servicesCopy.listIterator();
- int serviceCounter = 0;
- ObjectName name = null;
-
- while (enum.hasNext())
- {
- enum.next();
- }
- // pass them all
- while (enum.hasPrevious())
- {
- name = (ObjectName)enum.previous();
- try
- {
- ((Service)nameToServiceMap.get(name)).destroy();
- serviceCounter++;
- }
- catch (Throwable e)
- {
- log.error("Could not destroy" + name, e);
- }
- }
-
- log.info("Destroyed " + serviceCounter + " services");
- */
- }
-
/**
* #Description of the Method
*
* @param serviceName Description of Parameter
* @exception Exception Description of Exception
*/
- public void init(ObjectName serviceName) throws Exception
- {
- throw new Exception("init(serviceName) is obsolete");
- }
-
- /**
- * #Description of the Method
- *
- * @param serviceName Description of Parameter
- * @exception Exception Description of Exception
- */
public void start(ObjectName serviceName) throws Exception
{
if (suspendedToMissingMBeanMap.containsKey(serviceName))
@@ -564,7 +475,6 @@
if (nameToServiceMap.containsKey(serviceName))
{
- ((Service)nameToServiceMap.get(serviceName)).init();
((Service)nameToServiceMap.get(serviceName)).start();
startedServices.add(serviceName);
}
@@ -593,7 +503,6 @@
//not waiting for anyone else, can finish deploying.
log.debug("missing mbeans now present, finishing deployment of " +
waitingName);
suspendedToMissingMBeanMap.remove(waitingName);
- //init(waitingName);
start(waitingName);
} // end of if ()
else
@@ -620,17 +529,16 @@
ArrayList usingList = (ArrayList)mbeanRefToMBeansMap.get(serviceName);
if (usingList != null)
{
- //we have to stop and destroy these beans that depend on serviceName.
+ //we have to stop these beans that depend on serviceName.
Iterator using = usingList.iterator();
while (using.hasNext())
{
ObjectName usingName = (ObjectName)using.next();
- log.debug("stopping/destroying object " + usingName + " using " +
serviceName);
+ log.debug("stopping object " + usingName + " using " + serviceName);
if (!isWaitingFor(serviceName, usingName))
{
markWaiting(serviceName, usingName);
stop(usingName);
- destroy(usingName);
} // end of if ()
} // end of while ()
@@ -649,25 +557,6 @@
}
}
- /**
- * #Description of the Method
- *
- * @param serviceName Description of Parameter
- * @exception Exception Description of Exception
- */
- public void destroy(ObjectName serviceName) throws Exception
- {
- if (nameToServiceMap.containsKey(serviceName))
- {
-
- ((Service)nameToServiceMap.get(serviceName)).destroy();
- }
- else
- {
- throw new InstanceNotFoundException
- ("Could not find " + serviceName.toString());
- }
- }
/**
* Get the Service interface through which the mbean given by objectName
@@ -801,7 +690,7 @@
/**
* An implementation of InvocationHandler used to proxy of the Service
- * interface for mbeans. It determines which of the init/start/stop/destroy
+ * interface for mbeans. It determines which of the start/stop
* methods of the Service interface an mbean implements by inspecting its
* MBeanOperationInfo values. Each Service interface method that has a
* matching operation is forwarded to the mbean by invoking the method
@@ -903,9 +792,9 @@
*/
static
{
- serviceOpMap.put("init", new Integer(0));
+ //serviceOpMap.put("init", new Integer(0));
serviceOpMap.put("start", new Integer(1));
- serviceOpMap.put("destroy", new Integer(2));
+ //serviceOpMap.put("destroy", new Integer(2));
serviceOpMap.put("stop", new Integer(3));
}
}
1.4 +7 -4 jboss/src/main/org/jboss/system/ServiceControllerMBean.java
Index: ServiceControllerMBean.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/system/ServiceControllerMBean.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ServiceControllerMBean.java 2001/11/10 21:38:06 1.3
+++ ServiceControllerMBean.java 2001/11/12 06:52:17 1.4
@@ -20,7 +20,7 @@
* @see Service
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*
* <p><b>20010830 marc fleury:</b>
* <ul>
@@ -28,7 +28,7 @@
* </ul>
*/
public interface ServiceControllerMBean
- extends Service
+ // extends Service
{
/** The default object name. */
String OBJECT_NAME = "JBOSS-SYSTEM:spine=ServiceController";
@@ -46,14 +46,17 @@
void undeploy(Element mbean) throws Exception;
void undeploy(ObjectName mbeanName) throws Exception;
+
+ void shutdown();
//
// State calls, init, start, stop, destroy
//
- void init(ObjectName mbean) throws Exception;
+ //void init(ObjectName mbean) throws Exception;
+ //Are these really useful??
void start(ObjectName mbean) throws Exception;
void stop(ObjectName mbean) throws Exception;
- void destroy(ObjectName mbean) throws Exception;
+ //void destroy(ObjectName mbean) throws Exception;
/** Get a list of deployed elements, in the order they were deployed */
ObjectName[] getDeployed();
1.5 +15 -15 jboss/src/main/org/jboss/system/ServiceMBeanSupport.java
Index: ServiceMBeanSupport.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/ServiceMBeanSupport.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ServiceMBeanSupport.java 2001/09/15 00:19:16 1.4
+++ ServiceMBeanSupport.java 2001/11/12 06:52:17 1.5
@@ -22,15 +22,14 @@
* An abstract base class JBoss services can subclass to implement a
* service that conforms to the ServiceMBean interface. Subclasses must
* override {@link #getName} method and should override
- * {@link #initService}, {@link #startService}, {@link #stopService} AND
- * {@link #destroyService} as approriate.
+ * {@link #startService}, and {@link #stopService} as approriate.
*
*
* @see ServiceMBean
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*
* Revisions:
* 20010619 scott.stark: use the full service class name as the log4j
@@ -81,7 +80,7 @@
return log;
}
- public void init()
+ /* public void init()
throws Exception
{
NDC.push(getName());
@@ -101,7 +100,7 @@
}
log.info("Initialized");
}
-
+ */
public void start()
throws Exception
{
@@ -162,6 +161,13 @@
NDC.pop();
}
+ public void init() throws Exception
+ {
+ throw new Exception("Don't call init");
+ }
+
+ public void destroy() {};
+ /*
public void destroy()
{
if (getState() != STOPPED)
@@ -180,7 +186,7 @@
log.info("Destroyed");
NDC.pop();
}
-
+ */
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws Exception
{
@@ -194,7 +200,7 @@
if (!registrationDone.booleanValue())
{
log.info( "Registration is not done -> destroy" );
- destroy();
+ stop();
}
}
@@ -205,7 +211,8 @@
public void postDeregister()
{
- destroy();
+ stop();//this is presumably redundant.... ServiceController should have called
+ //stop already.
}
// Protected -----------------------------------------------------
@@ -216,10 +223,6 @@
return name;
}
- protected void initService()
- throws Exception
- {
- }
protected void startService()
throws Exception
@@ -230,7 +233,4 @@
{
}
- protected void destroyService()
- {
- }
}
1.8 +13 -98 jboss/src/main/org/jboss/system/Shutdown.java
Index: Shutdown.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/Shutdown.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Shutdown.java 2001/11/06 21:59:31 1.7
+++ Shutdown.java 2001/11/12 06:52:17 1.8
@@ -25,7 +25,7 @@
* provides the ability to handle user shutdown requests.
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*/
public class Shutdown implements MBeanRegistration, ShutdownMBean {
// Constants -----------------------------------------------------
@@ -91,107 +91,22 @@
// empty
}
- /**
- * Attempt to <em>stop</em> and <em>destroy</em> all services
- * running inside of the MBean server which we are attached too by
- * asking the <tt>ServiceControl</tt> to do the dirty work.
- */
- protected void shutdownServices() {
+ /**
+ * The <code>shutdownServices</code> method calls the one and only
+ * ServiceController to shut down all the mbeans registered with it.
+ * We could make the ServiceController an mbean-ref...
+ *
+ */
+ protected void shutdownServices() {
try {
// set to true for detailed name printouts
boolean verbose = false;
// get the deployed objects from ServiceController
- ObjectName[] deployed = (ObjectName[]) server.invoke(new ObjectName(
- "JBOSS-SYSTEM:spine=ServiceController"), "getDeployed",
- new Object[0], new String[0]);
- List servicesCopy = Arrays.asList(deployed);
- ListIterator enum = servicesCopy.listIterator();
- ListIterator beanEnum = servicesCopy.listIterator();
- ObjectName name = null;
- String[] sig = { "javax.management.ObjectName" };
-
- // filo ( first in last out )
- while (enum.hasNext())
- {
- enum.next();
-
- // filter out some services here ?
-
- }
-
-
- // Stop / Destroy / Unload all MBeans from ServiceController
- // Stop
- log.info("********************** Stop MBeans
************************************");
-
log.info("***********************************************************************");
- //while (enum.hasNext())
- while (enum.hasPrevious())
- {
- //name = (ObjectName)enum.next();
- name = (ObjectName)enum.previous();
- Object[] args = { name };
- if (verbose)
- log.info("********************** Looking at MBean : " +
name.getCanonicalName());
- // Stop services
- if (!name.getCanonicalName().equals("JMX:name=Connector,type=RMI")
&&
- !name.getCanonicalName().equals("Adaptor:name=html") &&
- !name.getCanonicalName().equals("JBOSS-SYSTEM:service=Naming"))
{
- if (verbose)
- log.info("********************** Stopping MBean : " +
name.getCanonicalName());
- server.invoke(new
ObjectName("JBOSS-SYSTEM:spine=ServiceController"),
- "stop", args, sig);
- // Destroy services
- // Unload services
- }
- }
- // Destroy
- log.info("********************** Destroy MBeans
************************************");
-
log.info("**************************************************************************");
- //while (enum.hasPrevious())
- while (enum.hasNext())
- {
- //name = (ObjectName)enum.previous();
- name = (ObjectName)enum.next();
- Object[] args = { name };
- if (verbose)
- log.info("********************** Looking at MBean : " +
name.getCanonicalName());
- // Destroy services
- if (!name.getCanonicalName().equals("JMX:name=Connector,type=RMI")
&&
- !name.getCanonicalName().equals("Adaptor:name=html") &&
- !name.getCanonicalName().equals("JBOSS-SYSTEM:service=Naming"))
{
- if (verbose)
- log.info("********************** Destroying MBean : " +
name.getCanonicalName());
- server.invoke(new
ObjectName("JBOSS-SYSTEM:spine=ServiceController"),
- "destroy", args, sig);
- }
- }
- // Unload all MBeans from MBean Server
- Set allMBeans = server.queryNames(null, null);
- Iterator i = allMBeans.iterator();
- // write the Mbeans Out
-
- /*
- while(i.hasNext()) {
- name = (ObjectName) i.next();
- log.info("**********************Looking at MBean : " +
name.getCanonicalName());
- }
- */
-
- log.info("********************** Unloading MBeans
************************************");
-
log.info("****************************************************************************");
- while (i.hasNext()) {
- name = (ObjectName)i.next();
- if (verbose)
- log.info("********************** Looking at MBean : " +
name.getCanonicalName());
- if
(!name.getCanonicalName().equals("JMImplementation:type=MBeanServerDelegate") &&
- !name.getCanonicalName().equals("JMX:name=Connector,type=RMI")
&&
- !name.getCanonicalName().equals("Adaptor:name=html") &&
- !name.getCanonicalName().equals("JBOSS-SYSTEM:service=Naming"))
{
- if (verbose)
- log.info("********************** Unloading MBean : " +
name.getCanonicalName());
- server.unregisterMBean(name);
- }
- }
+ server.invoke(new ObjectName(
+ "JBOSS-SYSTEM:spine=ServiceController"),
+ "shutdown",
+ new Object[0],
+ new String[0]);
}
catch (RuntimeMBeanException rmbe) {
rmbe.getTargetException().printStackTrace();
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development