User: ejort
Date: 02/01/05 04:08:54
Modified: src/main/org/jboss/system ServiceConfigurator.java
ServiceController.java ServiceCreator.java
Log:
Guarded debug logging
Revision Changes Path
1.16 +30 -22 jboss/src/main/org/jboss/system/ServiceConfigurator.java
Index: ServiceConfigurator.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/ServiceConfigurator.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ServiceConfigurator.java 2001/12/20 06:12:09 1.15
+++ ServiceConfigurator.java 2002/01/05 12:08:54 1.16
@@ -40,7 +40,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Hiram Chirino</a>
-* @version $Revision: 1.15 $
+* @version $Revision: 1.16 $
*
* <p><b>20010830 marc fleury:</b>
* <ul>
@@ -92,14 +92,16 @@
public String getConfiguration(ObjectName[] objectNames)
throws Exception
{
+ boolean debug = log.isDebugEnabled();
+
Writer out = new StringWriter();
-
+
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
-
+
Element serverElement = doc.createElement("server");
-
+
// Store attributes as XML
for (int j = 0 ; j<objectNames.length ; j++)
{
@@ -107,7 +109,7 @@
ObjectName name = (ObjectName)instance.getObjectName();
Element mbeanElement = doc.createElement("mbean");
mbeanElement.setAttribute("name", name.toString());
-
+
MBeanInfo info = server.getMBeanInfo(name);
mbeanElement.setAttribute("code", info.getClassName());
MBeanAttributeInfo[] attributes = info.getAttributes();
@@ -118,13 +120,14 @@
{
if (!attributes[i].isWritable())
{
- log.debug("Detected JMX Bug: Server reports attribute
'"+attributes[i].getName() + "' is not writeable for MBean '" +
name.getCanonicalName() + "'");
+ if (debug)
+ log.debug("Detected JMX Bug: Server reports attribute
'"+attributes[i].getName() + "' is not writeable for MBean '" +
name.getCanonicalName() + "'");
}
Element attributeElement = doc.createElement("attribute");
Object value = server.getAttribute(name, attributes[i].getName());
-
+
attributeElement.setAttribute("name", attributes[i].getName());
-
+
if (value != null)
{
attributeElement.appendChild(doc.createTextNode(value.toString()));
@@ -147,14 +150,14 @@
(new DOMWriter(out, false)).print(doc, true);
out.close();
-
+
// Return configuration
return out.toString();
}
-
-
+
+
// Public -----------------------------------------------------
-
+
/**
* The <code>configure</code> method configures an mbean based on the xml element
configuration
* passed in. Three formats are supported:
@@ -171,12 +174,14 @@
public ArrayList configure(Element mbeanElement)
throws Exception
{
-
+
// Set configuration to MBeans from XML
-
+
+ boolean debug = log.isDebugEnabled();
+
// get the name of the mbean
ObjectName objectName = parseObjectName(mbeanElement);
-
+
MBeanInfo info;
try
{
@@ -186,7 +191,7 @@
// The MBean is no longer available
throw new DeploymentException("trying to configure nonexistent mbean: " +
objectName);
}
-
+
// Set attributes
MBeanAttributeInfo[] attributes = info.getAttributes();
NodeList attrs = mbeanElement.getElementsByTagName("attribute");
@@ -204,7 +209,7 @@
{
attributeText = ((Text)n).getData().trim();
}
-
+
for (int k = 0; k < attributes.length; k++)
{
if (attributeName.equals(attributes[k].getName()))
@@ -219,9 +224,9 @@
{
typeClass = Class.forName(typeName);
}
-
+
Object value = null;
-
+
// HRC: Is the attribute type a org.w3c.dom.Element??
if (typeClass.equals(Element.class))
{
@@ -246,7 +251,8 @@
value = editor.getValue();
}
- log.debug(attributeName + " set to " + value + " in " +
objectName);
+ if (debug)
+ log.debug(attributeName + " set to " + value + " in " +
objectName);
server.setAttribute(objectName, new Attribute(attributeName,
value));
@@ -261,7 +267,8 @@
ArrayList mbeans = new ArrayList();
NodeList dependsElements = mbeanElement.getElementsByTagName("depends");
- log.debug("found " + dependsElements.getLength() + " depends elements");
+ if (debug)
+ log.debug("found " + dependsElements.getLength() + " depends elements");
for (int j = 0; j < dependsElements.getLength(); j++) {
Element dependsElement = (Element)dependsElements.item(j);
dependAttrFound:
@@ -285,7 +292,8 @@
{
mbeans.add(dependsObjectName);
} // end of if ()
- log.debug("considering " + ((mbeanRefName == null)? "<anonymous>":
mbeanRefName.toString()) + " with object name " + dependsObjectName);
+ if (debug)
+ log.debug("considering " + ((mbeanRefName == null)? "<anonymous>":
mbeanRefName.toString()) + " with object name " + dependsObjectName);
if (mbeanRefName != null)
{
//if if doesn't exist or has wrong type, we'll get an exception
1.22 +46 -33 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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ServiceController.java 2002/01/03 04:01:00 1.21
+++ ServiceController.java 2002/01/05 12:08:54 1.22
@@ -42,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.21 $ <p>
+ * @version $Revision: 1.22 $ <p>
*
* <b>Revisions:</b> <p>
*
@@ -137,18 +137,20 @@
public synchronized ObjectName install(Element mbeanElement)
throws Exception
{
+ boolean debug = log.isDebugEnabled();
+
// Create a Service Context for the service, or get one if it exists
ServiceContext ctx = getServiceContext(parseObjectName(mbeanElement));
-
+
// MARCF FIXME THINK ABOUT REMOVe IF ACTIVE HERE
//at least make a new version!
//remove(objectName);
-
+
// It is not there so really create the component now, this registers the
component in the mbeanserver
try
{
creator.install(mbeanElement);
- }
+ }
catch (MBeanException mbe)
{
mbe.getTargetException().printStackTrace();
@@ -176,28 +178,29 @@
throw (Exception)e;
if (e instanceof Error)
throw (Error)e;
-
+
throw new Error("unexpected throwable: " + e);
}
-
+
// We got this far
ctx.state = ServiceContext.INSTALLED;
-
- try {
+
+ try {
// Configure the MBean
synchronized (this)
{
// The return is a list of MBeans this MBean "depends" on
List mbeans = configurator.configure(mbeanElement);
-
+
// Link the dependency me.idependOn(them) and them.dependsOnMe(me)
Iterator iterator = mbeans.iterator();
while (iterator.hasNext()) {
-
+
// We work from the service context, if it doesn't exist yet, we
have a wrapper (OK)
ServiceContext service = getServiceContext((ObjectName)
iterator.next());
-
- log.debug("recording that " + ctx.objectName + " depends on " +
service.objectName);
+
+ if (debug)
+ log.debug("recording that " + ctx.objectName + " depends on " +
service.objectName);
// ctx depends on service
ctx.iDependOn.add(service);
@@ -346,30 +349,35 @@
* @exception Exception Description of Exception
*/
public void stop(ObjectName serviceName) throws Exception
- {
+ {
+ boolean debug = log.isDebugEnabled();
+
ServiceContext ctx = (ServiceContext) nameToServiceMap.get(serviceName);
- log.debug("stopping service: " + serviceName);
- if (ctx != null)
+ if (debug)
+ log.debug("stopping service: " + serviceName);
+ if (ctx != null)
{
// If we are already stopped (can happen in dependencies) just return
if (ctx.state == ServiceContext.STOPPED) return;
-
+
// JSR 77 and to avoid circular dependencies
ctx.state = ServiceContext.STOPPED;
-
- log.debug("service context has " + ctx.dependsOnMe.size() + " depending
services");
+
+ if (debug)
+ log.debug("service context has " + ctx.dependsOnMe.size() + " depending
services");
Iterator iterator = ctx.dependsOnMe.iterator();
while (iterator.hasNext())
{
// stop all the mbeans that depend on me
ObjectName other = ((ServiceContext) iterator.next()).objectName;
- log.debug("stopping dependent service " + other);
+ if (debug)
+ log.debug("stopping dependent service " + other);
stop(other);
}
-
- // Call create on the service Proxy
+
+ // Call create on the service Proxy
try { ctx.proxy.stop(); }
-
+
catch (Exception e){ ctx.state = ServiceContext.FAILED; throw e;}
}
}
@@ -381,9 +389,12 @@
* @exception Exception Description of Exception
*/
public void destroy(ObjectName serviceName) throws Exception
- {
+ {
+ boolean debug = log.isDebugEnabled();
+
ServiceContext ctx = (ServiceContext) nameToServiceMap.get(serviceName);
- log.debug("destroying service: " + serviceName);
+ if (debug)
+ log.debug("destroying service: " + serviceName);
if (ctx != null)
{
@@ -398,7 +409,8 @@
{
// destroy all the mbeans that depend on me
ObjectName other = ((ServiceContext) iterator.next()).objectName;
- log.debug("destroying dependent service " + other);
+ if (debug)
+ log.debug("destroying dependent service " + other);
destroy(other);
}
@@ -432,12 +444,15 @@
*/
public void remove(ObjectName objectName) throws Exception
{
- ServiceContext ctx = getServiceContext(objectName);
- log.debug("removing service: " + objectName);
-
+ boolean debug = log.isDebugEnabled();
+
+ ServiceContext ctx = getServiceContext(objectName);
+ if (debug)
+ log.debug("removing service: " + objectName);
+
// Notify those that think I depend on them
Iterator iterator = ctx.iDependOn.iterator();
- while (iterator.hasNext())
+ while (iterator.hasNext())
{
((ServiceContext) iterator.next()).dependsOnMe.remove(ctx);
}
@@ -445,9 +460,8 @@
// Do we have a deployed MBean?
if (server.isRegistered(objectName))
{
- if (log.isDebugEnabled()) {
+ if (debug)
log.debug("removing " + objectName + " from server");
- }
nameToServiceMap.remove(objectName);
@@ -458,9 +472,8 @@
}
else
{
- if (log.isDebugEnabled()) {
+ if (debug)
log.debug("no need to remove " + objectName + " from server");
- }
}
}
1.10 +19 -14 jboss/src/main/org/jboss/system/ServiceCreator.java
Index: ServiceCreator.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/ServiceCreator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ServiceCreator.java 2002/01/03 04:01:00 1.9
+++ ServiceCreator.java 2002/01/05 12:08:54 1.10
@@ -25,7 +25,7 @@
* @see Service
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
*
* <p><b>Revisions:</b>
* <p><b>2001/08/03 marcf </b>
@@ -58,30 +58,33 @@
*/
public ObjectInstance install(Element mbeanElement) throws Exception
{
+ boolean debug = log.isDebugEnabled();
+
ObjectName name = parseObjectName(mbeanElement);
-
+
// marcf fixme add and remove the classlaoder from the controller
-
- ObjectName loader = new ObjectName("jboss.system.classloader:id=" +
+
+ ObjectName loader = new ObjectName("jboss.system.classloader:id=" +
name.hashCode());
-
+
MBeanClassLoader cl = new MBeanClassLoader(name);
-
+
if (!server.isRegistered(loader))
server.registerMBean(cl, loader);
-
+
// If class is given, instantiate it
String code = mbeanElement.getAttribute("code");
if (code == null)
{
throw new ConfigurationException("missing 'code' attribute");
}
-
+
// get the constructor params/sig to use
ConstructorInfo constructor =
ConstructorInfo.create(mbeanElement);
- log.debug("About to create bean: "+name);
+ if (debug)
+ log.debug("About to create bean: "+name);
// Create the MBean instance
try
@@ -91,7 +94,8 @@
loader,
constructor.params,
constructor.signature);
- log.debug("Created bean: "+name);
+ if (debug)
+ log.debug("Created bean: "+name);
return instance;
}
@@ -116,16 +120,17 @@
if (domain == null || "".equals(domain)) {
name = new ObjectName(server.getDefaultDomain() + name);
}
-
+
// Remove the MBean from the MBeanServer
server.unregisterMBean(name);
-
+
// Remove the MBeanClassLoader used by the MBean
ObjectName loader = new ObjectName("jboss.system.classloader:id=" + hcode);
- if (server.isRegistered(loader))
+ if (server.isRegistered(loader))
{
server.unregisterMBean(loader);
- log.debug("unregistered caossloader for: " + name);
+ if (log.isDebugEnabled())
+ log.debug("unregistered caossloader for: " + name);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development