You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2013/06/06 05:29:51 UTC

svn commit: r1490116 - in /ofbiz/trunk: framework/service/dtd/ framework/service/src/org/ofbiz/service/ framework/service/src/org/ofbiz/service/config/ framework/service/src/org/ofbiz/service/engine/ framework/service/src/org/ofbiz/service/job/ special...

Author: adrianc
Date: Thu Jun  6 03:29:50 2013
New Revision: 1490116

URL: http://svn.apache.org/r1490116
Log:
A final pass through ServiceConfigUtil.java - moved some of the convenience method code to the call sites. The convenience methods don't add much now that the API is easier to use. Reorganized methods and added JavaDocs.

Modified:
    ofbiz/trunk/framework/service/dtd/service-config.xsd
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelNotification.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/GenericAsyncEngine.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobPoller.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java
    ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java

Modified: ofbiz/trunk/framework/service/dtd/service-config.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/dtd/service-config.xsd?rev=1490116&r1=1490115&r2=1490116&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/dtd/service-config.xsd (original)
+++ ofbiz/trunk/framework/service/dtd/service-config.xsd Thu Jun  6 03:29:50 2013
@@ -28,6 +28,12 @@ under the License.
     </xs:element>
 
     <xs:element name="service-engine">
+        <xs:annotation>
+            <xs:documentation>
+                A service engine configuration instance. The schema supports multiple configuration
+                instances, but the OFBiz framework supports only one - named "default". 
+            </xs:documentation>
+        </xs:annotation>
         <xs:complexType>
             <xs:sequence>
                 <xs:element ref="authorization" />

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelNotification.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelNotification.java?rev=1490116&r1=1490115&r2=1490116&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelNotification.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelNotification.java Thu Jun  6 03:29:50 2013
@@ -121,7 +121,7 @@ public class ModelNotification {
 
     private String getCommaSeparatedAddressList(String notifyType) {
         try {
-            NotificationGroup group = ServiceConfigUtil.getNotificationGroup(notificationGroupName);
+            NotificationGroup group = getNotificationGroup(notificationGroupName);
             return getCommaSeparatedAddressList(group, notifyType);
         } catch (GenericConfigException e) {
             Debug.logWarning(e, "Exception thrown while getting service configuration: ", module);
@@ -151,7 +151,7 @@ public class ModelNotification {
 
     public String getSubject() {
         try {
-            NotificationGroup group = ServiceConfigUtil.getNotificationGroup(notificationGroupName);
+            NotificationGroup group = getNotificationGroup(notificationGroupName);
             if (group != null) {
                 return group.getNotification().getSubject();
             }
@@ -163,7 +163,7 @@ public class ModelNotification {
 
     public String getScreen() {
         try {
-            NotificationGroup group = ServiceConfigUtil.getNotificationGroup(notificationGroupName);
+            NotificationGroup group = getNotificationGroup(notificationGroupName);
             if (group != null) {
                 return group.getNotification().getScreen();
             }
@@ -175,7 +175,7 @@ public class ModelNotification {
 
     public String getService() {
         try {
-            NotificationGroup group = ServiceConfigUtil.getNotificationGroup(notificationGroupName);
+            NotificationGroup group = getNotificationGroup(notificationGroupName);
             if (group != null) {
                 // only service supported at this time
                 return "sendMailFromScreen";
@@ -185,4 +185,15 @@ public class ModelNotification {
         }
         return null;
     }
+
+    public static NotificationGroup getNotificationGroup(String group) throws GenericConfigException {
+        List<NotificationGroup> notificationGroups;
+        notificationGroups = ServiceConfigUtil.getServiceEngine().getNotificationGroups();
+        for (NotificationGroup notificationGroup : notificationGroups) {
+            if (notificationGroup.getName().equals(group)) {
+                return notificationGroup;
+            }
+        }
+        return null;
+    }
 }

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=1490116&r1=1490115&r2=1490116&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 03:29:50 2013
@@ -845,7 +845,7 @@ public class ServiceDispatcher {
     private Map<String, Object> checkAuth(String localName, Map<String, Object> context, ModelService origService) throws ServiceAuthException, GenericServiceException {
         String service = null;
         try {
-            service = ServiceConfigUtil.getAuthorizationServiceName();
+            service = ServiceConfigUtil.getServiceEngine().getAuthorization().getServiceName();
         } catch (GenericConfigException e) {
             throw new GenericServiceException(e.getMessage(), e);
         }
@@ -989,7 +989,7 @@ public class ServiceDispatcher {
             String sendToPool = startupService.getRunInPool();
             if (UtilValidate.isEmpty(sendToPool)) {
                 try {
-                    sendToPool = ServiceConfigUtil.getSendPool();
+                    sendToPool = ServiceConfigUtil.getServiceEngine().getThreadPool().getSendToPool();
                 } catch (GenericConfigException e) {
                     Debug.logError(e, "Unable to get send pool in service [" + serviceName + "]: ", module);
                 }

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java?rev=1490116&r1=1490115&r2=1490116&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java Thu Jun  6 03:29:50 2013
@@ -376,8 +376,8 @@ public class ServiceUtil {
         String sendPool = null;
         Calendar cal = Calendar.getInstance();
         try {
-            sendPool = ServiceConfigUtil.getSendPool();
-            int daysToKeep = ServiceConfigUtil.getPurgeJobDays();
+            sendPool = ServiceConfigUtil.getServiceEngine().getThreadPool().getSendToPool();
+            int daysToKeep = ServiceConfigUtil.getServiceEngine().getThreadPool().getPurgeJobDays();
             cal.add(Calendar.DAY_OF_YEAR, -daysToKeep);
         } catch (GenericConfigException e) {
             Debug.logWarning(e, "Exception thrown while getting service configuration: ", module);

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=1490116&r1=1490115&r2=1490116&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 03:29:50 2013
@@ -19,7 +19,6 @@
 package org.ofbiz.service.config;
 
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
@@ -30,15 +29,19 @@ import org.ofbiz.base.util.UtilURL;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.base.util.cache.UtilCache;
 import org.ofbiz.service.config.model.Engine;
-import org.ofbiz.service.config.model.NotificationGroup;
-import org.ofbiz.service.config.model.RunFromPool;
 import org.ofbiz.service.config.model.ServiceConfig;
 import org.ofbiz.service.config.model.ServiceEngine;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 /**
- * Misc. utility method for dealing with the serviceengine.xml file
+ * A <code>ServiceConfig</code> factory and related utility methods.
+ * <p>The <code>ServiceConfig</code> instance models the <code>serviceengine.xml</code> file
+ * and the instance is kept in the "service.ServiceConfig" cache. Clearing the cache will reload
+ * the service configuration file. Client code that depends on the <code>serviceengine.xml</code>
+ * file can be notified when the file is reloaded by implementing <code>ServiceConfigListener</code>
+ * and registering itself using the {@link #registerServiceConfigListener(ServiceConfigListener)}
+ * method.<p>
  */
 public final class ServiceConfigUtil {
 
@@ -50,11 +53,20 @@ public final class ServiceConfigUtil {
     private static final List<ServiceConfigListener> configListeners = new CopyOnWriteArrayList<ServiceConfigListener>();
 
     /**
-     * Returns the default service engine configuration (named "default").
-     * @throws GenericConfigException 
+     * Returns the specified parameter value from the specified engine, or <code>null</code>
+     * if the engine or parameter are not found.
+     *  
+     * @param engineName
+     * @param parameterName
+     * @return
+     * @throws GenericConfigException
      */
-    public static ServiceEngine getServiceEngine() throws GenericConfigException {
-        return getServiceConfig().getServiceEngine(engine);
+    public static String getEngineParameter(String engineName, String parameterName) throws GenericConfigException {
+        Engine engine = getServiceEngine().getEngine(engineName);
+        if (engine != null) {
+            return engine.getParameterValue(parameterName);
+        }
+        return null;
     }
 
     /**
@@ -79,6 +91,24 @@ public final class ServiceConfigUtil {
         return instance;
     }
 
+    /**
+     * Returns the default service engine configuration (named "default").
+     * @throws GenericConfigException 
+     */
+    public static ServiceEngine getServiceEngine() throws GenericConfigException {
+        return getServiceConfig().getServiceEngine(engine);
+    }
+
+    /**
+     * Returns the specified <code>ServiceEngine</code> configuration instance,
+     * or <code>null</code> if the configuration does not exist.
+     * 
+     * @throws GenericConfigException
+     */
+    public static ServiceEngine getServiceEngine(String name) throws GenericConfigException {
+        return getServiceConfig().getServiceEngine(name);
+    }
+
     private static Document getXmlDocument() throws GenericConfigException {
         URL confUrl = UtilURL.fromResource(SERVICE_ENGINE_XML_FILENAME);
         if (confUrl == null) {
@@ -92,65 +122,13 @@ public final class ServiceConfigUtil {
     }
 
     /**
-     * Returns the specified <code>ServiceEngine</code> instance, or <code>null</code>
-     * if the engine does not exist.
+     * Register a <code>ServiceConfigListener</code> instance. The instance will be notified
+     * when the <code>serviceengine.xml</code> file is reloaded.
      * 
-     * @throws GenericConfigException
+     * @param listener
      */
-    public static ServiceEngine getServiceEngine(String name) throws GenericConfigException {
-        return getServiceConfig().getServiceEngine(name);
-    }
-
     public static void registerServiceConfigListener(ServiceConfigListener listener) {
         Assert.notNull("listener", listener);
         configListeners.add(listener);
     }
-
-    public static String getAuthorizationServiceName() throws GenericConfigException {
-        return getServiceEngine().getAuthorization().getServiceName();
-    }
-
-    public static boolean getPollEnabled() throws GenericConfigException {
-        return getServiceEngine().getThreadPool().getPollEnabled();
-    }
-
-    public static String getSendPool() throws GenericConfigException {
-        return getServiceEngine().getThreadPool().getSendToPool();
-    }
-
-    public static List<String> getRunPools() throws GenericConfigException {
-        List<RunFromPool> runFromPools = getServiceEngine().getThreadPool().getRunFromPools();
-        List<String> readPools = new ArrayList<String>(runFromPools.size());
-        for (RunFromPool runFromPool : runFromPools) {
-            readPools.add(runFromPool.getName());
-        }
-        return readPools;
-    }
-
-    public static int getPurgeJobDays() throws GenericConfigException {
-        return getServiceEngine().getThreadPool().getPurgeJobDays();
-    }
-
-    public static int getFailedRetryMin() throws GenericConfigException {
-        return getServiceEngine().getThreadPool().getFailedRetryMin();
-    }
-
-    public static NotificationGroup getNotificationGroup(String group) throws GenericConfigException {
-        List<NotificationGroup> notificationGroups;
-        notificationGroups = getServiceEngine().getNotificationGroups();
-        for (NotificationGroup notificationGroup : notificationGroups) {
-            if (notificationGroup.getName().equals(group)) {
-                return notificationGroup;
-            }
-        }
-        return null;
-    }
-
-    public static String getEngineParameter(String engineName, String parameterName) throws GenericConfigException {
-        Engine engine = getServiceEngine().getEngine(engineName);
-        if (engine != null) {
-            return engine.getParameterValue(parameterName);
-        }
-        return null;
-    }
 }

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/GenericAsyncEngine.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/GenericAsyncEngine.java?rev=1490116&r1=1490115&r2=1490116&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/GenericAsyncEngine.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/GenericAsyncEngine.java Thu Jun  6 03:29:50 2013
@@ -106,7 +106,7 @@ public abstract class GenericAsyncEngine
                 String jobName = Long.toString(System.currentTimeMillis());
 
                 Map<String, Object> jFields = UtilMisc.toMap("jobId", jobId, "jobName", jobName, "runTime", UtilDateTime.nowTimestamp());
-                jFields.put("poolId", ServiceConfigUtil.getSendPool());
+                jFields.put("poolId", ServiceConfigUtil.getServiceEngine().getThreadPool().getSendToPool());
                 jFields.put("statusId", "SERVICE_PENDING");
                 jFields.put("serviceName", modelService.name);
                 jFields.put("loaderName", localName);

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java?rev=1490116&r1=1490115&r2=1490116&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java Thu Jun  6 03:29:50 2013
@@ -51,6 +51,7 @@ import org.ofbiz.service.ServiceContaine
 import org.ofbiz.service.calendar.RecurrenceInfo;
 import org.ofbiz.service.calendar.RecurrenceInfoException;
 import org.ofbiz.service.config.ServiceConfigUtil;
+import org.ofbiz.service.config.model.RunFromPool;
 
 import com.ibm.icu.util.Calendar;
 
@@ -134,6 +135,15 @@ public final class JobManager {
         return JobPoller.getInstance().getPoolState();
     }
 
+    private static List<String> getRunPools() throws GenericConfigException {
+        List<RunFromPool> runFromPools = ServiceConfigUtil.getServiceEngine().getThreadPool().getRunFromPools();
+        List<String> readPools = new ArrayList<String>(runFromPools.size());
+        for (RunFromPool runFromPool : runFromPools) {
+            readPools.add(runFromPool.getName());
+        }
+        return readPools;
+    }
+
     /**
      * Scans the JobSandbox entity and returns a list of jobs that are due to run.
      * Returns an empty list if there are no jobs due to run.
@@ -158,7 +168,7 @@ public final class JobManager {
         // limit to just defined pools
         List<String> pools = null;
         try {
-            pools = ServiceConfigUtil.getRunPools();
+            pools = getRunPools();
         } catch (GenericConfigException e) {
             Debug.logWarning(e, "Unable to get run pools - not running job: ", module);
             return poll;
@@ -222,7 +232,7 @@ public final class JobManager {
             // No jobs to run, see if there are any jobs to purge
             Calendar cal = Calendar.getInstance();
             try {
-                int daysToKeep = ServiceConfigUtil.getPurgeJobDays();
+                int daysToKeep = ServiceConfigUtil.getServiceEngine().getThreadPool().getPurgeJobDays();
                 cal.add(Calendar.DAY_OF_YEAR, -daysToKeep);
             } catch (GenericConfigException e) {
                 Debug.logWarning(e, "Unable to get purge job days: ", module);
@@ -536,7 +546,7 @@ public final class JobManager {
             jFields.put("poolId", poolName);
         } else {
             try {
-                jFields.put("poolId", ServiceConfigUtil.getSendPool());
+                jFields.put("poolId", ServiceConfigUtil.getServiceEngine().getThreadPool().getSendToPool());
             } catch (GenericConfigException e) {
                 throw new JobManagerException(e.getMessage(), e);
             }

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=1490116&r1=1490115&r2=1490116&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 03:29:50 2013
@@ -153,7 +153,7 @@ public final class JobPoller implements 
 
     private boolean pollEnabled() {
         try {
-            return ServiceConfigUtil.getPollEnabled();
+            return ServiceConfigUtil.getServiceEngine().getThreadPool().getPollEnabled();
         } catch (GenericConfigException e) {
             Debug.logWarning(e, "Exception thrown while getting configuration: ", module);
             return false;

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java?rev=1490116&r1=1490115&r2=1490116&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java Thu Jun  6 03:29:50 2013
@@ -246,7 +246,7 @@ public class PersistedServiceJob extends
                 // create a recurrence
                 Calendar cal = Calendar.getInstance();
                 try {
-                    cal.add(Calendar.MINUTE, ServiceConfigUtil.getFailedRetryMin());
+                    cal.add(Calendar.MINUTE, ServiceConfigUtil.getServiceEngine().getThreadPool().getFailedRetryMin());
                 } catch (GenericConfigException e) {
                     Debug.logWarning(e, "Unable to get retry minutes for job [" + getJobId() + "], defaulting to now: ", module);
                 }

Modified: ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java?rev=1490116&r1=1490115&r2=1490116&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java (original)
+++ ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java Thu Jun  6 03:29:50 2013
@@ -314,7 +314,7 @@ public class EbayStoreHelper {
                         "serviceName", serviceName, "statusId", "SERVICE_PENDING", "recurrenceInfoId", infoId, "runtimeDataId", runtimeDataId);
 
                 // set the pool ID
-                jFields.put("poolId", ServiceConfigUtil.getSendPool());
+                jFields.put("poolId", ServiceConfigUtil.getServiceEngine().getThreadPool().getSendToPool());
 
                 // set the loader name
                 jFields.put("loaderName", delegator.getDelegatorName());