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/02 17:03:42 UTC

svn commit: r1488727 - in /ofbiz/trunk/framework/service/src/org/ofbiz/service/config: ServiceConfigListener.java ServiceConfigUtil.java

Author: adrianc
Date: Sun Jun  2 15:03:41 2013
New Revision: 1488727

URL: http://svn.apache.org/r1488727
Log:
ServiceConfigUtil improvement - notify listeners when the config file is reloaded.

Added:
    ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigListener.java   (with props)
Modified:
    ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java

Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigListener.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigListener.java?rev=1488727&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigListener.java (added)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigListener.java Sun Jun  2 15:03:41 2013
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.service.config;
+
+import org.ofbiz.service.config.model.ServiceConfig;
+
+/**
+ * An object that receives notifications when the <code>serviceengine.xml</code> file is reloaded.
+ */
+public interface ServiceConfigListener {
+
+    /**
+     * Processes <code>serviceengine.xml</code> changes.
+     * 
+     * @param serviceConfig The new <code>ServiceConfig</code> instance.
+     */
+    void onServiceConfigChange(ServiceConfig serviceConfig);
+
+}

Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigListener.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Rev URL

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=1488727&r1=1488726&r2=1488727&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 Sun Jun  2 15:03:41 2013
@@ -22,12 +22,14 @@ import java.io.Serializable;
 import java.net.URL;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import javolution.util.FastList;
 import javolution.util.FastMap;
 
 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;
 import org.ofbiz.base.util.UtilXml;
@@ -49,9 +51,9 @@ public final class ServiceConfigUtil {
     public static final String SERVICE_ENGINE_XML_FILENAME = "serviceengine.xml";
     // Remove this cache in the new implementation.
     private static final UtilCache<String, Map<String, NotificationGroup>> notificationGroupCache = UtilCache.createUtilCache("service.NotificationGroups", 0, 0, false);
-    // New Implementation: Create a cache for the ServiceConfig instance - so the configuration can be reloaded at run-time.
-    // There will be only one ServiceConfig instance in the cache.
+    // Keep the ServiceConfig instance in a cache - so the configuration can be reloaded at run-time. There will be only one ServiceConfig instance in the cache.
     private static final UtilCache<String, ServiceConfig> serviceConfigCache = UtilCache.createUtilCache("service.ServiceConfig", 0, 0, false);
+    private static final List<ServiceConfigListener> configListeners = new CopyOnWriteArrayList<ServiceConfigListener>();
 
     /**
      * Returns the <code>ServiceConfig</code> instance.
@@ -64,6 +66,13 @@ public final class ServiceConfigUtil {
             instance = ServiceConfig.create(serviceConfigElement);
             serviceConfigCache.putIfAbsent("instance", instance);
             instance = serviceConfigCache.get("instance");
+            for (ServiceConfigListener listener : configListeners) {
+                try {
+                    listener.onServiceConfigChange(instance);
+                } catch (Exception e) {
+                    Debug.logError(e, "Exception thrown while notifying listener " + listener + ": ", module);
+                }
+            }
         }
         return instance;
     }
@@ -95,6 +104,11 @@ public final class ServiceConfigUtil {
         return UtilXml.firstChildElement(root, "service-engine"); // only look at the first one for now
     }
 
+    public static void registerServiceConfigListener(ServiceConfigListener listener) {
+        Assert.notNull("listener", listener);
+        configListeners.add(listener);
+    }
+
     public static Element getElement(String elementName) {
         Element rootElement = null;