You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2011/09/06 14:00:45 UTC

svn commit: r1165620 - in /incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log: Activator.java LogConfigurator.java LogSyncConfigurator.java task/LogSyncTask.java

Author: marrs
Date: Tue Sep  6 12:00:45 2011
New Revision: 1165620

URL: http://svn.apache.org/viewvc?rev=1165620&view=rev
Log:
ACE-170 ACE-173 Refactored the log and sync task.

Added:
    incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogConfigurator.java   (with props)
    incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogSyncConfigurator.java   (with props)
Modified:
    incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/Activator.java
    incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/task/LogSyncTask.java

Modified: incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/Activator.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/Activator.java?rev=1165620&r1=1165619&r2=1165620&view=diff
==============================================================================
--- incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/Activator.java (original)
+++ incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/Activator.java Tue Sep  6 12:00:45 2011
@@ -18,100 +18,34 @@
  */
 package org.apache.ace.gateway.log;
 
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Map;
 import java.util.Properties;
 
-import org.apache.ace.discovery.Discovery;
-import org.apache.ace.gateway.log.store.LogStore;
-import org.apache.ace.gateway.log.task.LogSyncTask;
-import org.apache.ace.identification.Identification;
-import org.apache.ace.log.Log;
-import org.apache.ace.scheduler.constants.SchedulerConstants;
-import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedServiceFactory;
 import org.osgi.service.log.LogService;
 
-public class Activator extends DependencyActivatorBase implements ManagedServiceFactory {
-
-    private static final String LOG_NAME = "name";
-
-    private DependencyManager m_manager;
-    private final Map m_logInstances = new HashMap(); // String -> Service
-    private final Map m_syncInstances = new HashMap(); // String -> Service
-    private volatile LogService m_log;
-
+public class Activator extends DependencyActivatorBase {
     public void init(BundleContext context, DependencyManager manager) throws Exception {
-        m_manager = manager;
-        Properties props = new Properties();
+        Properties props;
+
+        props = new Properties();
         props.put(Constants.SERVICE_PID, "org.apache.ace.gateway.log.factory");
         manager.add(createComponent()
             .setInterface(ManagedServiceFactory.class.getName(), props)
-            .setImplementation(this)
+            .setImplementation(LogConfigurator.class)
             .add(createServiceDependency().setService(LogService.class).setRequired(false)));
-    }
-
-    public void destroy(BundleContext context, DependencyManager manager) throws Exception {
-    }
-
-    public synchronized void deleted(String pid) {
-        Component log = (Component) m_logInstances.remove(pid);
-        if (log != null) {
-            m_manager.remove(log);
-        }
-        Component sync = (Component) m_syncInstances.remove(pid);
-        if (sync != null) {
-            m_manager.remove(sync);
-        }
-    }
 
-    public String getName() {
-        return "Log Factory";
+        props = new Properties();
+        props.put(Constants.SERVICE_PID, "org.apache.ace.gateway.log.sync.factory");
+        manager.add(createComponent()
+            .setInterface(ManagedServiceFactory.class.getName(), props)
+            .setImplementation(LogSyncConfigurator.class)
+            .add(createServiceDependency().setService(LogService.class).setRequired(false)));
     }
 
-    public synchronized void updated(String pid, Dictionary dict) throws ConfigurationException {
-        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_logInstances.get(pid);
-        if (service == null) {
-            // publish log service
-            Properties props = new Properties();
-            props.put(LOG_NAME, name);
-            Component log = m_manager.createComponent()
-                .setInterface(Log.class.getName(), props)
-                .setImplementation(LogImpl.class)
-                .add(createServiceDependency().setService(LogStore.class, "(&("+Constants.OBJECTCLASS+"="+LogStore.class.getName()+")(name=" + name + "))").setRequired(true))
-                .add(createServiceDependency().setService(LogService.class).setRequired(false));
-
-            // publish log sync task service
-            Dictionary properties = new Properties();
-            properties.put(SchedulerConstants.SCHEDULER_DESCRIPTION_KEY, "Task that synchronizes log store with id=" + name + " on the gateway and server");
-            properties.put(SchedulerConstants.SCHEDULER_NAME_KEY, name);
-            properties.put(SchedulerConstants.SCHEDULER_RECIPE, "2000");
-            Component sync = m_manager.createComponent()
-                .setInterface(Runnable.class.getName(), properties)
-                .setImplementation(new LogSyncTask(name))
-                .add(createServiceDependency().setService(LogStore.class, "(&("+Constants.OBJECTCLASS+"="+LogStore.class.getName()+")(name=" + name + "))").setRequired(true))
-                .add(createServiceDependency().setService(Discovery.class).setRequired(true))
-                .add(createServiceDependency().setService(Identification.class).setRequired(true))
-                .add(createServiceDependency().setService(LogService.class).setRequired(false));
-
-            m_logInstances.put(pid, log);
-            m_syncInstances.put(pid, sync);
-            m_manager.add(log);
-            m_manager.add(sync);
-        }
-        else {
-            m_log.log(LogService.LOG_INFO, "Ignoring configuration update because factory instance was lready configured: " + name);
-        }
+    public void destroy(BundleContext context, DependencyManager manager) throws Exception {
     }
-}
\ No newline at end of file
+}

Added: incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogConfigurator.java?rev=1165620&view=auto
==============================================================================
--- incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogConfigurator.java (added)
+++ incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogConfigurator.java Tue Sep  6 12:00:45 2011
@@ -0,0 +1,62 @@
+package org.apache.ace.gateway.log;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.ace.gateway.log.store.LogStore;
+import org.apache.ace.log.Log;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+import org.osgi.service.log.LogService;
+
+public class LogConfigurator implements ManagedServiceFactory {
+    private static final String LOG_NAME = "name";
+
+    private DependencyManager m_manager;
+    private final Map /*<String, Component>*/ m_logInstances = new HashMap();
+    private volatile LogService m_log;
+    
+    public String getName() {
+        return "Log Factory";
+    }
+
+    public synchronized void deleted(String pid) {
+        Component log = (Component) m_logInstances.remove(pid);
+        if (log != null) {
+            m_manager.remove(log);
+        }
+    }
+
+    public synchronized void updated(String pid, Dictionary dict) throws ConfigurationException {
+        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_logInstances.get(pid);
+        if (service == null) {
+            // publish log service
+            Properties props = new Properties();
+            props.put(LOG_NAME, name);
+            String filterString;
+            filterString = "(&("+Constants.OBJECTCLASS+"="+LogStore.class.getName()+")(name=" + name + "))";
+
+            Component log = m_manager.createComponent()
+                .setInterface(Log.class.getName(), props)
+                .setImplementation(LogImpl.class)
+                .add(m_manager.createServiceDependency().setService(LogStore.class, filterString).setRequired(true))
+                .add(m_manager.createServiceDependency().setService(LogService.class).setRequired(false));
+
+            m_logInstances.put(pid, log);
+            m_manager.add(log);
+        }
+        else {
+            m_log.log(LogService.LOG_INFO, "Ignoring configuration update because factory instance was already configured: " + name);
+        }
+    }
+}

Propchange: incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogConfigurator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogSyncConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogSyncConfigurator.java?rev=1165620&view=auto
==============================================================================
--- incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogSyncConfigurator.java (added)
+++ incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogSyncConfigurator.java Tue Sep  6 12:00:45 2011
@@ -0,0 +1,92 @@
+package org.apache.ace.gateway.log;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.ace.discovery.Discovery;
+import org.apache.ace.gateway.log.store.LogStore;
+import org.apache.ace.gateway.log.task.LogSyncTask;
+import org.apache.ace.identification.Identification;
+import org.apache.ace.scheduler.constants.SchedulerConstants;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+import org.osgi.service.log.LogService;
+
+public class LogSyncConfigurator implements ManagedServiceFactory {
+    private static final String MA_NAME = "ma";
+    private static final String LOG_NAME = "name";
+
+    private DependencyManager m_manager;
+    private final Map /*<String, Component>*/ m_syncInstances = new HashMap();
+    private volatile LogService m_log;
+    
+    public String getName() {
+        return "Log Sync Factory";
+    }
+
+    public synchronized void deleted(String pid) {
+        Component sync = (Component) m_syncInstances.remove(pid);
+        if (sync != null) {
+            m_manager.remove(sync);
+        }
+    }
+
+    public synchronized void updated(String pid, Dictionary dict) throws ConfigurationException {
+        String name = (String) dict.get(LOG_NAME);
+        String ma = (String) dict.get(MA_NAME);
+        if ((name == null) || "".equals(name)) {
+            throw new ConfigurationException(LOG_NAME, "Log name has to be specified.");
+        }
+
+        Component service = (Component) m_syncInstances.get(pid);
+        if (service == null) {
+            // publish log sync task service
+            Dictionary properties = new Properties();
+            String filterString;
+            String filterForDiscovery;
+            String filterForIdentification;
+            String schedulerName;
+            String description;
+            if (ma == null) {
+                filterString = "(&("+Constants.OBJECTCLASS+"="+LogStore.class.getName()+")(name=" + name + "))";
+                filterForDiscovery = "(&("+Constants.OBJECTCLASS+"="+Discovery.class.getName()+")(!(ma=*)))";
+                filterForIdentification = "(&("+Constants.OBJECTCLASS+"="+Identification.class.getName()+")(!(ma=*)))";
+                schedulerName = name;
+                description = "Task that synchronizes log store with id=" + name + " on the gateway and server";
+            }
+            else {
+                // if there is more than one management agent ("ma" is specified) then still it's very well possible that there's only
+                // one log, so either bind to this one global log (assuming ma is not specified for it) or a ma-specific log (ma is
+                // specified)
+                filterString = "(&("+Constants.OBJECTCLASS+"="+LogStore.class.getName()+")(name=" + name + ")(|(ma=" + ma + ")(!(ma=*))))";
+                filterForDiscovery = "(&("+Constants.OBJECTCLASS+"="+Discovery.class.getName()+")(ma=" + ma + "))";
+                filterForIdentification = "(&("+Constants.OBJECTCLASS+"="+Identification.class.getName()+")(ma=" + ma + "))";
+                schedulerName = "ma=" + ma + ";name=" + name;
+                description = "Task that synchronizes log store with id=" + name + " and ma=" + ma + " on the gateway and server";
+                properties.put(MA_NAME, ma);
+            }
+
+            properties.put(SchedulerConstants.SCHEDULER_NAME_KEY, schedulerName);
+            properties.put(SchedulerConstants.SCHEDULER_DESCRIPTION_KEY, description);
+            properties.put(SchedulerConstants.SCHEDULER_RECIPE, "2000");
+            Component sync = m_manager.createComponent()
+                .setInterface(Runnable.class.getName(), properties)
+                .setImplementation(new LogSyncTask(name))
+                .add(m_manager.createServiceDependency().setService(LogStore.class, filterString).setRequired(true))
+                .add(m_manager.createServiceDependency().setService(Discovery.class, filterForDiscovery).setRequired(true))
+                .add(m_manager.createServiceDependency().setService(Identification.class, filterForIdentification).setRequired(true))
+                .add(m_manager.createServiceDependency().setService(LogService.class).setRequired(false));
+
+            m_syncInstances.put(pid, sync);
+            m_manager.add(sync);
+        }
+        else {
+            m_log.log(LogService.LOG_INFO, "Ignoring configuration update because factory instance was already configured: " + name);
+        }
+    }
+}

Propchange: incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/LogSyncConfigurator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/task/LogSyncTask.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/task/LogSyncTask.java?rev=1165620&r1=1165619&r2=1165620&view=diff
==============================================================================
--- incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/task/LogSyncTask.java (original)
+++ incubator/ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/task/LogSyncTask.java Tue Sep  6 12:00:45 2011
@@ -75,8 +75,7 @@ public class LogSyncTask implements Runn
 
         Connection sendConnection = null;
         try {
-            sendConnection = new Connection(new URL(host, m_endpoint + "/"
-                    + COMMAND_SEND));
+            sendConnection = new Connection(new URL(host, m_endpoint + "/" + COMMAND_SEND));
             long[] logIDs = m_LogStore.getLogIDs();
             for (int i = 0; i < logIDs.length; i++) {
                 Connection queryConnection = new Connection(new URL(host,