User: starksm
Date: 01/04/13 12:06:59
Modified: src/main/org/jboss/util ServiceControl.java
ServiceControlMBean.java
Added: src/main/org/jboss/util ServiceFactory.java
Log:
Change the ServiceControl to be a passive service with which services
requiring lifecycle events must register.
Change ConfigurationService to register all mbean found in the jboss.jcml
file with the ServiceControl service and make jboss-auto.jcml write only.
Revision Changes Path
1.9 +37 -114 jboss/src/main/org/jboss/util/ServiceControl.java
Index: ServiceControl.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/util/ServiceControl.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ServiceControl.java 2001/02/08 03:54:44 1.8
+++ ServiceControl.java 2001/04/13 19:06:59 1.9
@@ -15,18 +15,16 @@
import org.jboss.logging.Log;
-
-/**
- * <description>
- *
- * @see <related>
+/** ServiceControl manages the JBoss services lifecycle.
+ *
+ * @see org.jboss.util.Service
* @author Rickard �berg ([EMAIL PROTECTED])
* @author Hugo Pinto (mailto:[EMAIL PROTECTED])
- * @version $Revision: 1.8 $
+ * @author [EMAIL PROTECTED]
+ * @version $Revision: 1.9 $
*/
public class ServiceControl
-
- implements ServiceControlMBean, MBeanRegistration, NotificationListener
+ implements ServiceControlMBean, MBeanRegistration
{
// Constants -----------------------------------------------------
public static final String OBJECT_NAME = ":service=ServiceControl";
@@ -36,8 +34,6 @@
Log log = Log.createLog("Service Control");
List mbeans = new ArrayList();
- MBeanServer server;
-
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -53,27 +49,15 @@
int serviceCounter = 0;
while (enum.hasNext())
{
- ObjectName name = (ObjectName)enum.next();
+ Service service = (Service)enum.next();
try
{
- server.invoke(name, "init", new Object[0], new String[0]);
+ service.init();
serviceCounter++;
-
- // Register start/stop listener
- server.addNotificationListener(name,
- this,
- null,
- name);
- } catch (ReflectionException e)
- {
- // Not a service - ok
- } catch (RuntimeMBeanException e)
- {
- log.error("Could not initialize "+name);
- log.exception(e.getTargetException());
- } catch (Exception e)
+ }
+ catch(Throwable e)
{
- log.error("Could not initialize "+name);
+ log.error("Could not initialize "+service);
log.exception(e);
}
}
@@ -90,31 +74,16 @@
int serviceCounter = 0;
while (enum.hasNext())
{
- ObjectName name = (ObjectName)enum.next();
+ Service service = (Service)enum.next();
try
{
- server.invoke(name, "start", new Object[0], new String[0]);
+ service.start();
serviceCounter++;
- } catch (ReflectionException e)
- {
- // Not a service - ok
- } catch (Throwable e)
+ }
+ catch(Throwable e)
{
- log.error("Could not start "+name);
-
- if (e instanceof RuntimeErrorException)
- {
- e = ((RuntimeErrorException)e).getTargetError();
- }
- else if( e instanceof RuntimeMBeanException )
- {
- e = ((RuntimeMBeanException)e).getTargetException();
- }
- else if( e instanceof MBeanException )
- {
- e = ((MBeanException)e).getTargetException();
- }
+ log.error("Could not start "+service);
log.exception(e);
}
}
@@ -131,24 +100,16 @@
while (enum.hasNext()) enum.next(); // pass them all
while (enum.hasPrevious())
{
- ObjectName name = (ObjectName)enum.previous();
+ Service service = (Service) enum.previous();
try
{
- server.invoke(name, "stop", new Object[0], new String[0]);
+ service.stop();
serviceCounter++;
- } catch (ReflectionException e)
- {
- // Not a service - ok
- } catch (Throwable e)
+ }
+ catch (Throwable e)
{
- log.error("Could not stop "+name);
-
- if (e instanceof RuntimeErrorException)
- {
- e = ((RuntimeErrorException)e).getTargetError();
- }
-
+ log.error("Could not stop "+service);
log.exception(e);
}
}
@@ -165,89 +126,51 @@
while (enum.hasNext()) enum.next(); // pass them all
while (enum.hasPrevious())
{
- ObjectName name = (ObjectName)enum.previous();
+ Service service = (Service) enum.previous();
try
{
- server.invoke(name, "destroy", new Object[0], new String[0]);
+ service.destroy();
serviceCounter++;
- } catch (ReflectionException e)
- {
- // Not a service - ok
- } catch (Throwable e)
+ }
+ catch (Throwable e)
{
- log.error("Could not destroy "+name);
-
- if (e instanceof RuntimeErrorException)
- {
- e = ((RuntimeErrorException)e).getTargetError();
- }
-
+ log.error("Could not destroy"+service);
log.exception(e);
}
}
log.log("Destroyed "+mbeansCopy.size()+" services");
}
-
-
+
+ public void register(Service service)
+ {
+ mbeans.add(service);
+ }
+ public void unregister(Service service)
+ {
+ mbeans.remove(service);
+ }
+
// MBeanRegistration implementation ------------------------------
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws java.lang.Exception
{
- this.server = server;
return name == null ? new ObjectName(OBJECT_NAME) : name;
}
public void postRegister(java.lang.Boolean registrationDone)
{
- try
- {
- server.addNotificationListener(new
ObjectName("JMImplementation:type=MBeanServerDelegate"),
- this,
- null,
- null);
- log.log("Registered with server");
- } catch (Exception e)
- {
- log.error("Could not register with server");
- log.exception(e);
- }
}
public void preDeregister()
throws java.lang.Exception
{
- server.removeNotificationListener(new
ObjectName("JMImplementation:type=MBeanServerDelegate"), this);
- log.log("Deregistered from server");
}
public void postDeregister()
{
}
-
- // NotificationListener implementation ---------------------------
- public void handleNotification(Notification notification,
- java.lang.Object handback)
- {
- if (notification instanceof AttributeChangeNotification)
- {
- AttributeChangeNotification attrChg =
(AttributeChangeNotification)notification;
-//
log.log(handback+":"+attrChg.getAttributeName()+":"+attrChg.getNewValue());
- } else if (notification instanceof MBeanServerNotification)
- {
- MBeanServerNotification reg = (MBeanServerNotification)notification;
-
- if
(reg.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION))
- {
- mbeans.add(reg.getMBeanName());
- } else if
(reg.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION))
- {
- mbeans.remove(reg.getMBeanName());
- }
- }
- }
-
-
+
}
1.2 +8 -5 jboss/src/main/org/jboss/util/ServiceControlMBean.java
Index: ServiceControlMBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/util/ServiceControlMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServiceControlMBean.java 2000/12/07 15:48:14 1.1
+++ ServiceControlMBean.java 2001/04/13 19:06:59 1.2
@@ -6,16 +6,19 @@
*/
package org.jboss.util;
-/**
- * <description>
- *
- * @see <related>
+/** The interface for the ServiceControl MBean. This service
+manages the lifecycle of JBoss services.
+
+ * @see org.jboss.util.Service
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.1 $
+ * @author [EMAIL PROTECTED]
+ * @version $Revision: 1.2 $
*/
public interface ServiceControlMBean
extends Service
{
// Public --------------------------------------------------------
+ public void register(Service service);
+ public void unregister(Service service);
}
1.1 jboss/src/main/org/jboss/util/ServiceFactory.java
Index: ServiceFactory.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.util;
import javax.management.MBeanServer;
import javax.management.ObjectName;
/** The ServiceFactory interface is used to obtain a Service
proxy instance for a named MBean.
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public interface ServiceFactory
{
/** Create a Service proxy instance for the MBean given by name.
@param server, the MBeanServer instance
@param name, the name of the MBean that wishes to be managed by
the JBoss ServiceControl service.
*/
public Service createService(MBeanServer server, ObjectName name);
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development