1 37 package net.sourceforge.cruisecontrol; 38 39 import net.sourceforge.cruisecontrol.util.Util; 40 import org.apache.log4j.Logger; 41 import org.jdom.Attribute; 42 import org.jdom.DataConversionException; 43 import org.jdom.Element; 44 45 import java.io.File ; 46 47 53 54 public class ServerXMLHelper { 55 private static final Logger LOG = Logger.getLogger(ServerXMLHelper.class); 56 57 private int numThreads = 1; 58 59 public ServerXMLHelper(File configFile) { 60 try { 61 Element configLogElement = Util.loadConfigFile(configFile); 62 Element systemElement = configLogElement.getChild("system"); 63 if (systemElement == null) { 64 LOG.debug("no system element found in config.xml"); 65 return; 66 } 67 Element configurationElement = systemElement.getChild("configuration"); 68 if (configurationElement == null) { 69 LOG.debug("no configuraiton element found in config.xml"); 70 return; 71 } 72 Element threadElement = configurationElement.getChild("threads"); 73 if (threadElement == null) { 74 LOG.debug("no threads element found in config.xml"); 75 return; 76 } 77 Attribute threadCount = threadElement.getAttribute("count"); 78 LOG.debug("count attribute on threads is " + threadCount.toString()); 79 try { 80 numThreads = threadCount.getIntValue(); 81 } catch (DataConversionException dce) { 82 LOG.error("Expected a numeric value for system-configuration-threads-count in config.xml but found " 83 + threadCount.toString(), dce); 84 numThreads = 1; 85 } 86 } catch (Exception e) { 87 LOG.warn("error parsing thread count from config file; defaulting to 1 thread.", e); 88 numThreads = 1; 89 } 90 } 91 92 96 public int getNumThreads() { 97 return numThreads; 98 } 99 } 100 | Popular Tags |