ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1162742 - in /incubator/ace/trunk/ace-gateway-log-store/src: main/java/org/apache/ace/gateway/log/store/impl/ test/java/org/apache/ace/gateway/log/store/impl/
Date Mon, 29 Aug 2011 11:17:58 GMT
Author: marrs
Date: Mon Aug 29 11:17:58 2011
New Revision: 1162742

URL: http://svn.apache.org/viewvc?rev=1162742&view=rev
Log:
ACE-170 Updated the stores to accept an optional 'ma' parameter. Fixed the tests, they were
not run because of the name of the test class.

Added:
    incubator/ace/trunk/ace-gateway-log-store/src/test/java/org/apache/ace/gateway/log/store/impl/GatewayLogStoreTest.java
      - copied, changed from r1161449, incubator/ace/trunk/ace-gateway-log-store/src/test/java/org/apache/ace/gateway/log/store/impl/GatewayLogStoreTester.java
Modified:
    incubator/ace/trunk/ace-gateway-log-store/src/main/java/org/apache/ace/gateway/log/store/impl/Activator.java
    incubator/ace/trunk/ace-gateway-log-store/src/test/java/org/apache/ace/gateway/log/store/impl/GatewayLogStoreTester.java

Modified: incubator/ace/trunk/ace-gateway-log-store/src/main/java/org/apache/ace/gateway/log/store/impl/Activator.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-gateway-log-store/src/main/java/org/apache/ace/gateway/log/store/impl/Activator.java?rev=1162742&r1=1162741&r2=1162742&view=diff
==============================================================================
--- incubator/ace/trunk/ace-gateway-log-store/src/main/java/org/apache/ace/gateway/log/store/impl/Activator.java
(original)
+++ incubator/ace/trunk/ace-gateway-log-store/src/main/java/org/apache/ace/gateway/log/store/impl/Activator.java
Mon Aug 29 11:17:58 2011
@@ -36,12 +36,12 @@ import org.osgi.service.cm.ManagedServic
 import org.osgi.service.log.LogService;
 
 public class Activator extends DependencyActivatorBase implements ManagedServiceFactory {
-
+    private static final String MA_NAME = "ma";
     private static final String LOG_NAME = "name";
 
     private DependencyManager m_manager;
     private BundleContext m_context;
-    private final Map m_instances = new HashMap(); // String -> Service
+    private final Map /*<String, Component>*/ m_instances = new HashMap();
     private volatile LogService m_log;
 
     public void init(BundleContext context, DependencyManager manager) throws Exception {
@@ -52,15 +52,22 @@ public class Activator extends Dependenc
         manager.add(createComponent()
             .setInterface(ManagedServiceFactory.class.getName(), props)
             .setImplementation(this)
-            .add(createServiceDependency().setService(LogService.class).setRequired(false)));
+            .add(createServiceDependency()
+                .setService(LogService.class)
+                .setRequired(false)
+            )
+        );
     }
 
     public void destroy(BundleContext context, DependencyManager manager) throws Exception
{
         // Nothing we need to do
     }
 
-    public synchronized void deleted(String pid) {
-        Component log = (Component) m_instances.remove(pid);
+    public void deleted(String pid) {
+        Component log;
+        synchronized (m_instances) {
+            log = (Component) m_instances.remove(pid);
+        }
         if (log != null) {
             m_manager.remove(log);
             delete(new File(m_context.getDataFile(""), pid));
@@ -81,25 +88,43 @@ public class Activator extends Dependenc
         root.delete();
     }
 
-    public synchronized void updated(String pid, Dictionary dict) throws ConfigurationException
{
+    public void updated(String pid, Dictionary dict) throws ConfigurationException {
+        String ma = (String) dict.get(MA_NAME);
         String name = (String) dict.get(LOG_NAME);
         if ((name == null) || "".equals(name)) {
             throw new ConfigurationException(LOG_NAME, "Log name has to be specified.");
         }
 
-        Component service = (Component) m_instances.get(pid);
-        if (service == null) {
-            Properties props = new Properties();
-            props.put(LOG_NAME, name);
-            File baseDir = new File(m_context.getDataFile(""), pid);
-            service = m_manager.createComponent()
-                .setInterface(LogStore.class.getName(), props)
-                .setImplementation(new LogStoreImpl(baseDir))
-                .add(createServiceDependency().setService(Identification.class).setRequired(true))
-                .add(createServiceDependency().setService(LogService.class).setRequired(false));
-            m_instances.put(pid, service);
-            m_manager.add(service);
-        } else {
+        boolean needToAddComponent = false;
+        Component component;
+        synchronized (m_instances) {
+            component = (Component) m_instances.get(pid);
+            if (component == null) {
+                Properties props = new Properties();
+                props.put(LOG_NAME, name);
+                if ((ma != null) && (ma.length() > 0)) {
+                    props.put(MA_NAME, ma);
+                }
+                File baseDir = new File(m_context.getDataFile(""), pid);
+                component = m_manager.createComponent()
+                    .setInterface(LogStore.class.getName(), props)
+                    .setImplementation(new LogStoreImpl(baseDir))
+                    .add(createServiceDependency()
+                        .setService(Identification.class)
+                        .setRequired(true)
+                    )
+                    .add(createServiceDependency()
+                        .setService(LogService.class)
+                        .setRequired(false)
+                    );
+                m_instances.put(pid, component);
+                needToAddComponent = true;
+            }
+        }
+        if (needToAddComponent) {
+            m_manager.add(component);
+        }
+        else {
             m_log.log(LogService.LOG_INFO, "Ignoring configuration update because factory
instance was already configured: " + name);
         }
     }

Copied: incubator/ace/trunk/ace-gateway-log-store/src/test/java/org/apache/ace/gateway/log/store/impl/GatewayLogStoreTest.java
(from r1161449, incubator/ace/trunk/ace-gateway-log-store/src/test/java/org/apache/ace/gateway/log/store/impl/GatewayLogStoreTester.java)
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-gateway-log-store/src/test/java/org/apache/ace/gateway/log/store/impl/GatewayLogStoreTest.java?p2=incubator/ace/trunk/ace-gateway-log-store/src/test/java/org/apache/ace/gateway/log/store/impl/GatewayLogStoreTest.java&p1=incubator/ace/trunk/ace-gateway-log-store/src/test/java/org/apache/ace/gateway/log/store/impl/GatewayLogStoreTester.java&r1=1161449&r2=1162742&rev=1162742&view=diff
==============================================================================
--- incubator/ace/trunk/ace-gateway-log-store/src/test/java/org/apache/ace/gateway/log/store/impl/GatewayLogStoreTester.java
(original)
+++ incubator/ace/trunk/ace-gateway-log-store/src/test/java/org/apache/ace/gateway/log/store/impl/GatewayLogStoreTest.java
Mon Aug 29 11:17:58 2011
@@ -36,7 +36,7 @@ import org.testng.annotations.AfterMetho
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-public class GatewayLogStoreTester {
+public class GatewayLogStoreTest {
     private LogStoreImpl m_logStore;
     private File m_dir = null;
 



Mime
View raw message