ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r1490112 - in /ofbiz/trunk/framework/service/src/org/ofbiz/service: ./ config/ config/model/ eca/ engine/ group/ jms/ job/ mail/
Date Thu, 06 Jun 2013 02:16:41 GMT
Author: adrianc
Date: Thu Jun  6 02:16:40 2013
New Revision: 1490112

URL: http://svn.apache.org/r1490112
Log:
More work on ServiceConfigUtil.java - based on a patch from Christoph Neuroth with modifications
by me. Client code now uses the new models and the DOM parsing static methods have been removed.
The serviceengine.xml file handling is now thread-safe.

https://issues.apache.org/jira/browse/OFBIZ-5204

Modified:
    ofbiz/trunk/framework/service/src/org/ofbiz/service/DispatchContext.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/config/model/Server.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaUtil.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/AbstractEngine.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/GenericEngineFactory.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupReader.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/jms/JmsListenerFactory.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/jms/JmsServiceEngine.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/ServiceMcaUtil.java

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/DispatchContext.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/DispatchContext.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/DispatchContext.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/DispatchContext.java Thu Jun  6 02:16:40
2013
@@ -44,6 +44,7 @@ import org.ofbiz.entity.config.Delegator
 import org.ofbiz.entity.config.EntityConfigUtil;
 import org.ofbiz.security.Security;
 import org.ofbiz.service.config.ServiceConfigUtil;
+import org.ofbiz.service.config.model.GlobalServices;
 import org.ofbiz.service.eca.ServiceEcaUtil;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -242,20 +243,17 @@ public class DispatchContext implements 
         if (serviceMap == null) {
             serviceMap = FastMap.newInstance();
 
-            Element rootElement;
-
+            List<Future<Map<String, ModelService>>> futures = FastList.newInstance();
+            List<GlobalServices> globalServicesList = null;
             try {
-                rootElement = ServiceConfigUtil.getXmlRootElement();
+                globalServicesList = ServiceConfigUtil.getServiceEngine().getGlobalServices();
             } catch (GenericConfigException e) {
-                Debug.logError(e, "Error getting Service Engine XML root element", module);
-                return null;
+                // FIXME: Refactor API so exceptions can be thrown and caught.
+                Debug.logError(e, module);
+                throw new RuntimeException(e.getMessage());
             }
-
-            List<Future<Map<String, ModelService>>> futures = FastList.newInstance();
-            for (Element globalServicesElement: UtilXml.childElementList(rootElement, "global-services"))
{
-                ResourceHandler handler = new MainResourceHandler(
-                        ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME, globalServicesElement);
-
+            for (GlobalServices globalServices : globalServicesList) {
+                ResourceHandler handler = new MainResourceHandler(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME,
globalServices.getLoader(), globalServices.getLocation());
                 futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createServiceReaderCallable(handler)));
             }
 

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Thu Jun  6
02:16:40 2013
@@ -47,6 +47,7 @@ import org.ofbiz.security.Security;
 import org.ofbiz.security.SecurityConfigurationException;
 import org.ofbiz.security.SecurityFactory;
 import org.ofbiz.service.config.ServiceConfigUtil;
+import org.ofbiz.service.config.model.*;
 import org.ofbiz.service.eca.ServiceEcaRule;
 import org.ofbiz.service.eca.ServiceEcaUtil;
 import org.ofbiz.service.engine.GenericEngine;
@@ -842,7 +843,12 @@ public class ServiceDispatcher {
 
     // checks if parameters were passed for authentication
     private Map<String, Object> checkAuth(String localName, Map<String, Object>
context, ModelService origService) throws ServiceAuthException, GenericServiceException {
-        String service = ServiceConfigUtil.getElementAttr("authorization", "service-name");
+        String service = null;
+        try {
+            service = ServiceConfigUtil.getAuthorizationServiceName();
+        } catch (GenericConfigException e) {
+            throw new GenericServiceException(e.getMessage(), e);
+        }
 
         if (service == null) {
             throw new GenericServiceException("No Authentication Service Defined");
@@ -966,48 +972,35 @@ public class ServiceDispatcher {
 
     // run startup services
     private synchronized int runStartupServices() {
-        if (jm == null) return 0;
-
-        Element root;
+        if (jm == null)
+            return 0;
+        int servicesScheduled = 0;
+        List<StartupService> startupServices = null;
         try {
-            root = ServiceConfigUtil.getXmlRootElement();
+            startupServices = ServiceConfigUtil.getServiceEngine().getStartupServices();
         } catch (GenericConfigException e) {
-            Debug.logError(e, module);
+            Debug.logWarning(e, "Exception thrown while getting service config: ", module);
             return 0;
         }
-
-        int servicesScheduled = 0;
-        List<? extends Element> startupServices = UtilXml.childElementList(root, "startup-service");
-        if (UtilValidate.isNotEmpty(startupServices)) {
-            for (Element ss: startupServices) {
-                String serviceName = ss.getAttribute("name");
-                String runtimeDataId = ss.getAttribute("runtime-data-id");
-                String delayStr = ss.getAttribute("runtime-delay");
-                String sendToPool = ss.getAttribute("run-in-pool");
-                if (UtilValidate.isEmpty(sendToPool)) {
-                    try {
-                        sendToPool = ServiceConfigUtil.getSendPool();
-                    } catch (GenericConfigException e) {
-                        Debug.logError(e, "Unable to get send pool in service [" + serviceName
+ "]: ", module);
-                    }
-                }
-
-                long runtimeDelay;
-                try {
-                    runtimeDelay = Long.parseLong(delayStr);
-                } catch (Exception e) {
-                    Debug.logError(e, "Unable to parse runtime-delay value; using 0", module);
-                    runtimeDelay = 0;
-                }
-
-                // current time + 1 sec delay + extended delay
-                long runtime = System.currentTimeMillis() + 1000 + runtimeDelay;
+        for (StartupService startupService : startupServices) {
+            String serviceName = startupService.getName();
+            String runtimeDataId = startupService.getRuntimeDataId();
+            int runtimeDelay = startupService.getRuntimeDelay();
+            String sendToPool = startupService.getRunInPool();
+            if (UtilValidate.isEmpty(sendToPool)) {
                 try {
-                    jm.schedule(sendToPool, serviceName, runtimeDataId, runtime);
-                } catch (JobManagerException e) {
-                    Debug.logError(e, "Unable to schedule service [" + serviceName + "]",
module);
+                    sendToPool = ServiceConfigUtil.getSendPool();
+                } catch (GenericConfigException e) {
+                    Debug.logError(e, "Unable to get send pool in service [" + serviceName
+ "]: ", module);
                 }
             }
+            // current time + 1 sec delay + extended delay
+            long runtime = System.currentTimeMillis() + 1000 + runtimeDelay;
+            try {
+                jm.schedule(sendToPool, serviceName, runtimeDataId, runtime);
+            } catch (JobManagerException e) {
+                Debug.logError(e, "Unable to schedule service [" + serviceName + "]", module);
+            }
         }
 
         return servicesScheduled;

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java Thu
Jun  6 02:16:40 2013
@@ -24,7 +24,6 @@ import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.ofbiz.base.config.GenericConfigException;
-import org.ofbiz.base.config.ResourceLoader;
 import org.ofbiz.base.util.Assert;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilURL;
@@ -51,10 +50,10 @@ public final class ServiceConfigUtil {
     private static final List<ServiceConfigListener> configListeners = new CopyOnWriteArrayList<ServiceConfigListener>();
 
     /**
-     * Returns the service engine configuration (currently always the default one).
+     * Returns the default service engine configuration (named "default").
      * @throws GenericConfigException 
      */
-    private static ServiceEngine getServiceEngine() throws GenericConfigException {
+    public static ServiceEngine getServiceEngine() throws GenericConfigException {
         return getServiceConfig().getServiceEngine(engine);
     }
 
@@ -154,27 +153,4 @@ public final class ServiceConfigUtil {
         }
         return null;
     }
-
-    public static Element getXmlRootElement() throws GenericConfigException {
-        Element root = ResourceLoader.getXmlRootElement(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME);
-        return UtilXml.firstChildElement(root, "service-engine"); // only look at the first
one for now
-    }
-
-    public static Element getElement(String elementName) {
-        Element rootElement = null;
-
-        try {
-            rootElement = ServiceConfigUtil.getXmlRootElement();
-        } catch (GenericConfigException e) {
-            Debug.logError(e, "Error getting Service Engine XML root element", module);
-        }
-        return  UtilXml.firstChildElement(rootElement, elementName);
-    }
-
-    public static String getElementAttr(String elementName, String attrName) {
-        Element element = getElement(elementName);
-
-        if (element == null) return null;
-        return element.getAttribute(attrName);
-    }
 }

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/config/model/Server.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/config/model/Server.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/config/model/Server.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/config/model/Server.java Thu Jun 
6 02:16:40 2013
@@ -31,7 +31,7 @@ public final class Server {
     private final String clientId;
     private final String jndiName;
     private final String jndiServerName;
-    private final String listen;
+    private final boolean listen;
     private final String listenerClass;
     private final String password;
     private final String topicQueue;
@@ -62,11 +62,7 @@ public final class Server {
         this.username = serverElement.getAttribute("username").intern();
         this.password = serverElement.getAttribute("password").intern();
         this.clientId = serverElement.getAttribute("client-id").intern();
-        String listen = serverElement.getAttribute("listen").intern();
-        if (listen.isEmpty()) {
-            listen = "false";
-        }
-        this.listen = listen;
+        this.listen = "true".equals(serverElement.getAttribute("listen"));
         this.listenerClass = serverElement.getAttribute("listener-class").intern();
     }
 
@@ -82,7 +78,7 @@ public final class Server {
         return jndiServerName;
     }
 
-    public String getListen() {
+    public boolean getListen() {
         return listen;
     }
 

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaUtil.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaUtil.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaUtil.java Thu Jun  6
02:16:40 2013
@@ -40,6 +40,7 @@ import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.service.DispatchContext;
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.config.ServiceConfigUtil;
+import org.ofbiz.service.config.model.ServiceEcas;
 import org.w3c.dom.Element;
 
 import freemarker.template.utility.StringUtil;
@@ -64,17 +65,18 @@ public class ServiceEcaUtil {
         if (UtilValidate.isNotEmpty(ecaCache)) {
             return;
         }
-        Element rootElement = null;
+
+        List<Future<List<ServiceEcaRule>>> futures = FastList.newInstance();
+        List<ServiceEcas> serviceEcasList = null;
         try {
-            rootElement = ServiceConfigUtil.getXmlRootElement();
+            serviceEcasList = ServiceConfigUtil.getServiceEngine().getServiceEcas();
         } catch (GenericConfigException e) {
-            Debug.logError(e, "Error getting Service Engine XML root element", module);
-            return;
+            // FIXME: Refactor API so exceptions can be thrown and caught.
+            Debug.logError(e, module);
+            throw new RuntimeException(e.getMessage());
         }
-
-        List<Future<List<ServiceEcaRule>>> futures = FastList.newInstance();
-        for (Element serviceEcasElement: UtilXml.childElementList(rootElement, "service-ecas"))
{
-            ResourceHandler handler = new MainResourceHandler(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME,
serviceEcasElement);
+        for (ServiceEcas serviceEcas : serviceEcasList) {
+            ResourceHandler handler = new MainResourceHandler(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME,
serviceEcas.getLoader(), serviceEcas.getLocation());
             futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createEcaLoaderCallable(handler)));
         }
 

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/AbstractEngine.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/AbstractEngine.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/AbstractEngine.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/AbstractEngine.java Thu Jun
 6 02:16:40 2013
@@ -20,20 +20,18 @@ package org.ofbiz.service.engine;
 
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Map;
-import java.util.List;
 import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
-import org.ofbiz.service.ServiceDispatcher;
-import org.ofbiz.service.ModelService;
-import org.ofbiz.service.GenericServiceException;
-import org.ofbiz.service.GenericServiceCallback;
-import org.ofbiz.service.config.ServiceConfigUtil;
 import org.ofbiz.base.config.GenericConfigException;
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.UtilXml;
-
-import org.w3c.dom.Element;
+import org.ofbiz.service.GenericServiceCallback;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.ModelService;
+import org.ofbiz.service.ServiceDispatcher;
+import org.ofbiz.service.config.ServiceConfigUtil;
+import org.ofbiz.service.config.model.ServiceLocation;
 
 /**
  * Abstract Service Engine
@@ -53,21 +51,18 @@ public abstract class AbstractEngine imp
     protected static Map<String, String> createLocationMap() {
         Map<String, String> tmpMap = new HashMap<String, String>();
 
-        Element root = null;
+        List<ServiceLocation> locationsList = null;
         try {
-            root = ServiceConfigUtil.getXmlRootElement();
+            locationsList = ServiceConfigUtil.getServiceEngine().getServiceLocations();
         } catch (GenericConfigException e) {
+            // FIXME: Refactor API so exceptions can be thrown and caught.
             Debug.logError(e, module);
+            throw new RuntimeException(e.getMessage());
         }
-
-        if (root != null) {
-            List<? extends Element> locationElements = UtilXml.childElementList(root,
"service-location");
-            if (locationElements != null) {
-                for (Element e: locationElements) {
-                    tmpMap.put(e.getAttribute("name"), e.getAttribute("location"));
-                }
-            }
+        for (ServiceLocation e: locationsList) {
+            tmpMap.put(e.getName(), e.getLocation());
         }
+
         Debug.logInfo("Loaded Service Locations: " + tmpMap, module);
         return Collections.unmodifiableMap(tmpMap);
     }

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/GenericEngineFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/GenericEngineFactory.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/GenericEngineFactory.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/GenericEngineFactory.java Thu
Jun  6 02:16:40 2013
@@ -28,8 +28,6 @@ import org.ofbiz.service.GenericServiceE
 import org.ofbiz.service.ServiceDispatcher;
 import org.ofbiz.service.config.ServiceConfigUtil;
 import org.ofbiz.base.util.UtilGenerics;
-import org.ofbiz.base.util.UtilXml;
-import org.w3c.dom.Element;
 
 /**
  * Generic Engine Factory
@@ -50,23 +48,14 @@ public class GenericEngineFactory {
      *@return GenericEngine that corresponds to the engineName
      */
     public GenericEngine getGenericEngine(String engineName) throws GenericServiceException
{
-        Element rootElement = null;
-
+        String className = null;
         try {
-            rootElement = ServiceConfigUtil.getXmlRootElement();
+            className = ServiceConfigUtil.getServiceEngine().getEngine(engineName).getClassName();
         } catch (GenericConfigException e) {
-            throw new GenericServiceException("Error getting Service Engine XML root element",
e);
-        }
-        Element engineElement = UtilXml.firstChildElement(rootElement, "engine", "name",
engineName);
-
-        if (engineElement == null) {
-            throw new GenericServiceException("Cannot find a service engine definition for
the engine name [" + engineName + "] in the serviceengine.xml file");
+            throw new GenericServiceException(e);
         }
 
-        String className = engineElement.getAttribute("class");
-
         GenericEngine engine = engines.get(engineName);
-
         if (engine == null) {
             synchronized (GenericEngineFactory.class) {
                 engine = engines.get(engineName);

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupReader.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupReader.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/group/ServiceGroupReader.java Thu
Jun  6 02:16:40 2013
@@ -18,9 +18,9 @@
  *******************************************************************************/
 package org.ofbiz.service.group;
 
+import java.util.List;
 import java.util.Map;
 
-import freemarker.template.utility.StringUtil;
 import javolution.util.FastMap;
 
 import org.ofbiz.base.component.ComponentConfig;
@@ -30,8 +30,11 @@ import org.ofbiz.base.config.ResourceHan
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.service.config.ServiceConfigUtil;
+import org.ofbiz.service.config.model.ServiceGroups;
 import org.w3c.dom.Element;
 
+import freemarker.template.utility.StringUtil;
+
 /**
  * ServiceGroupReader.java
  */
@@ -43,17 +46,16 @@ public class ServiceGroupReader {
     public static Map<String, GroupModel> groupsCache = FastMap.newInstance();
 
     public static void readConfig() {
-        Element rootElement = null;
-
+        List<ServiceGroups> serviceGroupsList = null;
         try {
-            rootElement = ServiceConfigUtil.getXmlRootElement();
+            serviceGroupsList = ServiceConfigUtil.getServiceEngine().getServiceGroups();
         } catch (GenericConfigException e) {
-            Debug.logError(e, "Error getting Service Engine XML root element", module);
-            return;
+            // FIXME: Refactor API so exceptions can be thrown and caught.
+            Debug.logError(e, module);
+            throw new RuntimeException(e.getMessage());
         }
-
-        for (Element serviceGroupElement: UtilXml.childElementList(rootElement, "service-groups"))
{
-            ResourceHandler handler = new MainResourceHandler(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME,
serviceGroupElement);
+        for (ServiceGroups serviceGroup : serviceGroupsList) {
+            ResourceHandler handler = new MainResourceHandler(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME,
serviceGroup.getLoader(), serviceGroup.getLocation());
             addGroupDefinitions(handler);
         }
 

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/jms/JmsListenerFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/jms/JmsListenerFactory.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/jms/JmsListenerFactory.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/jms/JmsListenerFactory.java Thu Jun
 6 02:16:40 2013
@@ -18,21 +18,20 @@
  *******************************************************************************/
 package org.ofbiz.service.jms;
 
-import java.lang.reflect.Constructor;
-import java.util.Map;
-
 import javolution.util.FastMap;
-
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
-import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.config.ServiceConfigUtil;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
+import org.ofbiz.service.config.model.JmsService;
+import org.ofbiz.service.config.model.Server;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+import java.util.Map;
 
 /**
  * JmsListenerFactory
@@ -45,7 +44,7 @@ public class JmsListenerFactory implemen
     public static final String QUEUE_LISTENER_CLASS = "org.ofbiz.service.jms.JmsQueueListener";
 
     protected static Map<String, GenericMessageListener> listeners = FastMap.newInstance();
-    protected static Map<String, Element> servers = FastMap.newInstance();
+    protected static Map<String, Server> servers = FastMap.newInstance();
 
     protected static JmsListenerFactory jlf = null;
 
@@ -96,23 +95,18 @@ public class JmsListenerFactory implemen
     // Load the JMS listeners
     private void loadListeners() {
         try {
-            Element rootElement = ServiceConfigUtil.getXmlRootElement();
-            NodeList nodeList = rootElement.getElementsByTagName("jms-service");
+            List<JmsService> jmsServices = ServiceConfigUtil.getServiceEngine().getJmsServices();
 
             if (Debug.verboseOn()) Debug.logVerbose("Loading JMS Listeners.", module);
-            for (int i = 0; i < nodeList.getLength(); i++) {
-                Element element = (Element) nodeList.item(i);
+            for (JmsService service: jmsServices) {
                 StringBuilder serverKey = new StringBuilder();
-                for (Element server: UtilXml.childElementList(element, "server")) {
+                for (Server server: service.getServers()) {
                     try {
-                        String listenerEnabled = server.getAttribute("listen");
-
-                        if (listenerEnabled.equalsIgnoreCase("true")) {
+                        if (server.getListen()) {
                             // create a server key
-
-                            serverKey.append(server.getAttribute("jndi-server-name") + ":");
-                            serverKey.append(server.getAttribute("jndi-name") + ":");
-                            serverKey.append(server.getAttribute("topic-queue"));
+                            serverKey.append(server.getJndiServerName() + ":");
+                            serverKey.append(server.getJndiName() + ":");
+                            serverKey.append(server.getTopicQueue());
                             // store the server element
                             servers.put(serverKey.toString(), server);
                             // load the listener
@@ -129,21 +123,19 @@ public class JmsListenerFactory implemen
                     }
                 }
             }
-        } catch (org.ofbiz.base.config.GenericConfigException gce) {
-            Debug.logError(gce, "Cannot get serviceengine.xml root element.", module);
         } catch (Exception e) {
-            Debug.logError(e, "Uncaught exception.", module);
+            Debug.logError(e, "Exception thrown while loading JMS listeners: ", module);
         }
     }
 
-    private GenericMessageListener loadListener(String serverKey, Element server) throws
GenericServiceException {
-        String serverName = server.getAttribute("jndi-server-name");
-        String jndiName = server.getAttribute("jndi-name");
-        String queueName = server.getAttribute("topic-queue");
-        String type = server.getAttribute("type");
-        String userName = server.getAttribute("username");
-        String password = server.getAttribute("password");
-        String className = server.getAttribute("listener-class");
+    private GenericMessageListener loadListener(String serverKey, Server server) throws GenericServiceException
{
+        String serverName = server.getJndiServerName();
+        String jndiName = server.getJndiName();
+        String queueName = server.getTopicQueue();
+        String type = server.getType();
+        String userName = server.getUsername();
+        String password = server.getPassword();
+        String className = server.getListenerClass();
 
         if (UtilValidate.isEmpty(className)) {
             if (type.equals("topic"))
@@ -189,7 +181,7 @@ public class JmsListenerFactory implemen
      * @throws GenericServiceException
      */
     public void loadListener(String serverKey) throws GenericServiceException {
-        Element server = servers.get(serverKey);
+        Server server = servers.get(serverKey);
 
         if (server == null)
             throw new GenericServiceException("No listener found with that serverKey.");

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/jms/JmsServiceEngine.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/jms/JmsServiceEngine.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/jms/JmsServiceEngine.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/jms/JmsServiceEngine.java Thu Jun
 6 02:16:40 2013
@@ -59,6 +59,8 @@ import org.ofbiz.service.ModelService;
 import org.ofbiz.service.ServiceDispatcher;
 import org.ofbiz.service.ServiceUtil;
 import org.ofbiz.service.config.ServiceConfigUtil;
+import org.ofbiz.service.config.model.JmsService;
+import org.ofbiz.service.config.model.Server;
 import org.ofbiz.service.engine.AbstractEngine;
 import org.w3c.dom.Element;
 
@@ -73,23 +75,13 @@ public class JmsServiceEngine extends Ab
         super(dispatcher);
     }
 
-    protected Element getServiceElement(ModelService modelService) throws GenericServiceException
{
-        Element rootElement = null;
-
+    protected JmsService getServiceElement(ModelService modelService) throws GenericServiceException
{
+        String location = this.getLocation(modelService);
         try {
-            rootElement = ServiceConfigUtil.getXmlRootElement();
+            return ServiceConfigUtil.getServiceEngine().getJmsServiceByName(location);
         } catch (GenericConfigException e) {
-            throw new GenericServiceException("Error getting JMS Service element", e);
-        }
-
-        String location = this.getLocation(modelService);
-
-        Element serviceElement = UtilXml.firstChildElement(rootElement, "jms-service", "name",
location);
-
-        if (serviceElement == null) {
-            throw new GenericServiceException("Cannot find an JMS service definition for
the name [" + location + "] in the serviceengine.xml file");
+            throw new GenericServiceException(e);
         }
-        return serviceElement;
     }
 
     protected Message makeMessage(Session session, ModelService modelService, Map<String,
Object> context)
@@ -126,13 +118,13 @@ public class JmsServiceEngine extends Ab
         }
     }
 
-    protected Map<String, Object> runTopic(ModelService modelService, Map<String,
Object> context, Element server) throws GenericServiceException {
-        String serverName = server.getAttribute("jndi-server-name");
-        String jndiName = server.getAttribute("jndi-name");
-        String topicName = server.getAttribute("topic-queue");
-        String userName = server.getAttribute("username");
-        String password = server.getAttribute("password");
-        String clientId = server.getAttribute("client-id");
+    protected Map<String, Object> runTopic(ModelService modelService, Map<String,
Object> context, Server server) throws GenericServiceException {
+        String serverName = server.getJndiServerName();
+        String jndiName = server.getJndiName();
+        String topicName = server.getTopicQueue();
+        String userName = server.getUsername();
+        String password = server.getPassword();
+        String clientId = server.getClientId();
 
         InitialContext jndi = null;
         TopicConnectionFactory factory = null;
@@ -185,13 +177,13 @@ public class JmsServiceEngine extends Ab
 
     }
 
-    protected Map<String, Object> runQueue(ModelService modelService, Map<String,
Object> context, Element server) throws GenericServiceException {
-        String serverName = server.getAttribute("jndi-server-name");
-        String jndiName = server.getAttribute("jndi-name");
-        String queueName = server.getAttribute("topic-queue");
-        String userName = server.getAttribute("username");
-        String password = server.getAttribute("password");
-        String clientId = server.getAttribute("client-id");
+    protected Map<String, Object> runQueue(ModelService modelService, Map<String,
Object> context, Server server) throws GenericServiceException {
+        String serverName = server.getJndiServerName();
+        String jndiName = server.getJndiName();
+        String queueName = server.getTopicQueue();
+        String userName = server.getUsername();
+        String password = server.getPassword();
+        String clientId = server.getClientId();
 
         InitialContext jndi = null;
         QueueConnectionFactory factory = null;
@@ -315,13 +307,12 @@ public class JmsServiceEngine extends Ab
     }
 
     protected Map<String, Object> run(ModelService modelService, Map<String, Object>
context) throws GenericServiceException {
-        Element serviceElement = getServiceElement(modelService);
-        List<? extends Element> serverList = serverList(serviceElement);
+        JmsService serviceElement = getServiceElement(modelService);
+        List<Server> serverList = serviceElement.getServers();
 
         Map<String, Object> result = FastMap.newInstance();
-        for (Element server: serverList) {
-            String serverType = server.getAttribute("type");
-
+        for (Server server: serverList) {
+            String serverType = server.getType();
             if (serverType.equals("topic"))
                 result.putAll(runTopic(modelService, context, server));
             else if (serverType.equals("queue"))

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java Thu Jun  6 02:16:40
2013
@@ -152,8 +152,12 @@ public final class JobPoller implements 
     }
 
     private boolean pollEnabled() {
-        String enabled = ServiceConfigUtil.getElementAttr("thread-pool", "poll-enabled");
-        return !"false".equalsIgnoreCase(enabled);
+        try {
+            return ServiceConfigUtil.getPollEnabled();
+        } catch (GenericConfigException e) {
+            Debug.logWarning(e, "Exception thrown while getting configuration: ", module);
+            return false;
+        }
     }
 
     /**

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/ServiceMcaUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/ServiceMcaUtil.java?rev=1490112&r1=1490111&r2=1490112&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/ServiceMcaUtil.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/ServiceMcaUtil.java Thu Jun 
6 02:16:40 2013
@@ -24,7 +24,6 @@ import java.util.TreeSet;
 
 import org.ofbiz.base.component.ComponentConfig;
 import org.ofbiz.base.config.GenericConfigException;
-import org.ofbiz.base.config.MainResourceHandler;
 import org.ofbiz.base.config.ResourceHandler;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilXml;
@@ -32,7 +31,6 @@ import org.ofbiz.base.util.cache.UtilCac
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.LocalDispatcher;
-import org.ofbiz.service.config.ServiceConfigUtil;
 import org.w3c.dom.Element;
 
 public class ServiceMcaUtil {
@@ -46,18 +44,7 @@ public class ServiceMcaUtil {
     }
 
     public static void readConfig() {
-        Element rootElement = null;
-        try {
-            rootElement = ServiceConfigUtil.getXmlRootElement();
-        } catch (GenericConfigException e) {
-            Debug.logError(e, "Error getting Service Engine XML root element", module);
-            return;
-        }
-
-        for (Element serviceMcasElement: UtilXml.childElementList(rootElement, "service-mcas"))
{
-            ResourceHandler handler = new MainResourceHandler(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME,
serviceMcasElement);
-            addMcaDefinitions(handler);
-        }
+        // TODO: Missing in XSD file.
 
         // get all of the component resource eca stuff, ie specified in each ofbiz-component.xml
file
         for (ComponentConfig.ServiceResourceInfo componentResourceInfo: ComponentConfig.getAllServiceResourceInfos("mca"))
{



Mime
View raw message