User: hugo
Date: 00/12/12 16:22:16
Modified: src/main/org/jboss/util ServiceControl.java
Log:
Added one method to run over all MBeans on a server. Start, Stop, Init and Destroy
all use this method.
Implemented stop and destroy, since the server wasn't shutting down at all.
Hugo Pinto.
Revision Changes Path
1.4 +58 -3 jboss/src/main/org/jboss/util/ServiceControl.java
Index: ServiceControl.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/util/ServiceControl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ServiceControl.java 2000/12/07 18:16:13 1.3
+++ ServiceControl.java 2000/12/13 00:22:16 1.4
@@ -14,12 +14,15 @@
import org.jboss.logging.Log;
+
+
/**
* <description>
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.3 $
+ * @author Hugo Pinto (mailto:[EMAIL PROTECTED])
+ * @version $Revision: 1.4 $
*/
public class ServiceControl
implements ServiceControlMBean, MBeanRegistration, NotificationListener
@@ -41,6 +44,9 @@
public void init()
throws Exception
{
+ invokeOnMBeans ("init", "Initializing", "initialize", "Initialized");
+
+ /*
log.log("Initializing "+mbeans.size()+" MBeans");
List mbeansCopy = new ArrayList(mbeans);
@@ -73,11 +79,15 @@
}
}
log.log("Initialized "+mbeansCopy.size()+" services");
+ */
}
public void start()
throws Exception
- {
+ {
+ invokeOnMBeans ("start", "Starting", "start", "Started");
+
+ /*
log.log("Starting "+mbeans.size()+" MBeans");
List mbeansCopy = new ArrayList(mbeans);
@@ -107,18 +117,61 @@
}
}
log.log("Started "+mbeansCopy.size()+" services");
+ */
}
public void stop()
{
-
+ invokeOnMBeans ("stop", "Stopping", "stop", "Stopped");
}
public void destroy()
{
+ invokeOnMBeans ("destroy", "Destroying", "destroy", "Destroyed");
+ }
+
+ public void invokeOnMBeans (String methodname, String aboutaction, String
action, String pastaction)
+ {
+ log.log(aboutaction + " "+mbeans.size()+" MBeans");
+
+ List mbeansCopy = new ArrayList(mbeans);
+ Iterator enum = mbeansCopy.iterator();
+ int serviceCounter = 0;
+ while (enum.hasNext())
+ {
+ ObjectName name = (ObjectName)enum.next();
+ try
+ {
+ server.invoke(name, methodname, new Object[0], new String[0]);
+ serviceCounter++;
+
+ // Register start/stop listener
+ try {
+ server.addNotificationListener(name,
+ this,
+ null,
+ name);
+ } catch (Exception ex) {
+ log.error ("Warning: " + ex.getMessage());
+ }
+ } catch (ReflectionException e)
+ {
+ // Not a service - ok
+ } catch (RuntimeMBeanException e)
+ {
+ log.error("Could not " + action+" "+name);
+ log.exception(e.getTargetException());
+ } catch (Exception e)
+ {
+ log.error("Could not "+action +" "+name);
+ log.exception(e);
+ }
+ }
+ log.log(pastaction+" "+mbeansCopy.size()+" services");
}
+
// MBeanRegistration implementation ------------------------------
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws java.lang.Exception
@@ -175,6 +228,8 @@
}
}
}
+
+
}