ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1447249 - in /ace/trunk/org.apache.ace.log.task: bnd.bnd src/org/apache/ace/server/log/task/Activator.java src/org/apache/ace/server/log/task/LogSyncTask.java test/org/apache/ace/server/log/task/LogTaskTest.java
Date Mon, 18 Feb 2013 13:30:31 GMT
Author: marrs
Date: Mon Feb 18 13:30:30 2013
New Revision: 1447249

URL: http://svn.apache.org/r1447249
Log:
ACE-325 Added a feature to set what the log task should do: push, pull or both.

Modified:
    ace/trunk/org.apache.ace.log.task/bnd.bnd
    ace/trunk/org.apache.ace.log.task/src/org/apache/ace/server/log/task/Activator.java
    ace/trunk/org.apache.ace.log.task/src/org/apache/ace/server/log/task/LogSyncTask.java
    ace/trunk/org.apache.ace.log.task/test/org/apache/ace/server/log/task/LogTaskTest.java

Modified: ace/trunk/org.apache.ace.log.task/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log.task/bnd.bnd?rev=1447249&r1=1447248&r2=1447249&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.log.task/bnd.bnd (original)
+++ ace/trunk/org.apache.ace.log.task/bnd.bnd Mon Feb 18 13:30:30 2013
@@ -7,4 +7,6 @@
 	org.apache.ace.connectionfactory;version=latest,\
 	org.apache.ace.log;version=latest,\
 	org.apache.ace.server.log.store.api;version=latest
-Bundle-Version: 1.0.0
\ No newline at end of file
+Bundle-Version: 1.0.0
+Private-Package: org.apache.ace.server.log.task
+Bundle-Activator: org.apache.ace.server.log.task.Activator
\ No newline at end of file

Modified: ace/trunk/org.apache.ace.log.task/src/org/apache/ace/server/log/task/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log.task/src/org/apache/ace/server/log/task/Activator.java?rev=1447249&r1=1447248&r2=1447249&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.log.task/src/org/apache/ace/server/log/task/Activator.java (original)
+++ ace/trunk/org.apache.ace.log.task/src/org/apache/ace/server/log/task/Activator.java Mon
Feb 18 13:30:30 2013
@@ -27,6 +27,7 @@ import org.apache.ace.connectionfactory.
 import org.apache.ace.discovery.Discovery;
 import org.apache.ace.log.LogSync;
 import org.apache.ace.server.log.store.LogStore;
+import org.apache.ace.server.log.task.LogSyncTask.Mode;
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
@@ -37,13 +38,11 @@ import org.osgi.service.cm.ManagedServic
 import org.osgi.service.log.LogService;
 
 public class Activator extends DependencyActivatorBase implements ManagedServiceFactory {
-
     private static final String KEY_LOG_NAME = "name";
+    private static final String KEY_MODE = "mode";
     
     private final Map<String, Component> m_instances = new HashMap<String, Component>();
-    
     private volatile DependencyManager m_manager;
-    private volatile LogService m_log;
 
     @Override
     public void init(BundleContext context, DependencyManager manager) throws Exception {
@@ -53,64 +52,63 @@ public class Activator extends Dependenc
         manager.add(createComponent()
             .setInterface(ManagedServiceFactory.class.getName(), props)
             .setImplementation(this)
-            .add(createServiceDependency().setService(LogService.class).setRequired(false))
-            );
+        );
     }
 
     @Override
     public void destroy(BundleContext context, DependencyManager manager) throws Exception
{
     }
 
-    public void deleted(String pid) {
-        Component service = m_instances.remove(pid);
-        if (service != null) {
-            m_manager.remove(service);
-        }
-    }
-
     public String getName() {
         return "Log Sync Task Factory";
     }
 
-    @SuppressWarnings("unchecked")
     public synchronized void updated(String pid, Dictionary dict) throws ConfigurationException
{
         String name = (String) dict.get(KEY_LOG_NAME);
         if ((name == null) || "".equals(name)) {
             throw new ConfigurationException(KEY_LOG_NAME, "Log name has to be specified.");
         }
+        Mode mode = Mode.PUSH;
+        String modeValue = (String) dict.get(KEY_MODE);
+        if ("pull".equals(modeValue)) {
+        	mode = Mode.PULL;
+        }
+        else if ("pushpull".equals(modeValue)) {
+        	mode = Mode.PUSHPULL;
+        }
 
-        Component comp;
-        boolean created = false;
-
+        Component oldComponent, newComponent;
+        
+        Properties props = new Properties();
+        props.put(KEY_LOG_NAME, name);
+        props.put("taskName", LogSyncTask.class.getName());
+        props.put("description", "Syncs log (name=" + name + ", mode=" + mode.toString()
+ ") with a server.");
+        String filter = "(&(" + Constants.OBJECTCLASS + "=" + LogStore.class.getName()
+ ")(name=" + name + "))";
+        LogSyncTask service = new LogSyncTask(name, name, mode);
+        newComponent = m_manager.createComponent()
+    		.setInterface(new String[] { Runnable.class.getName(), LogSync.class.getName() }, props)
+    		.setImplementation(service)
+    		.add(createServiceDependency().setService(ConnectionFactory.class).setRequired(true))
+    		.add(createServiceDependency().setService(LogStore.class, filter).setRequired(true))
+    		.add(createServiceDependency().setService(Discovery.class).setRequired(true))
+    		.add(createServiceDependency().setService(LogService.class).setRequired(false));
+        
         synchronized (m_instances) {
-            comp = m_instances.get(pid);
-            if (comp != null) {
-                m_log.log(LogService.LOG_INFO, "Ignoring configuration update because factory
instance was already configured: " + name);
-            } else {
-                Properties props = new Properties();
-                props.put(KEY_LOG_NAME, name);
-                props.put("taskName", LogSyncTask.class.getName());
-                props.put("description", "Syncs log (name=" + name + ") with a server.");
-                
-                String filter = "(&(" + Constants.OBJECTCLASS + "=" + LogStore.class.getName()
+ ")(name=" + name + "))";
-
-                LogSyncTask service = new LogSyncTask(name, name);
-
-                comp = m_manager.createComponent()
-                                .setInterface(new String[] { Runnable.class.getName(), LogSync.class.getName()
}, props)
-                                .setImplementation(service)
-                                .add(createServiceDependency().setService(ConnectionFactory.class).setRequired(true))
-                                .add(createServiceDependency().setService(LogStore.class,
filter).setRequired(true))
-                                .add(createServiceDependency().setService(Discovery.class).setRequired(true))
-                                .add(createServiceDependency().setService(LogService.class).setRequired(false));
-                m_instances.put(pid, comp);
-
-                created = true;
-            }
+            oldComponent = m_instances.put(pid, newComponent);
         }
-        
-        if (created && (comp != null)) {
-            m_manager.add(comp);
+        if (oldComponent != null) {
+        	m_manager.remove(oldComponent);
         }
+        m_manager.add(newComponent);
     }
-}
\ No newline at end of file
+
+	public void deleted(String pid) {
+		Component component;
+		synchronized (m_instances) {
+			component = m_instances.remove(pid);
+		}
+	    if (component != null) {
+	        m_manager.remove(component);
+	    }
+	}
+}

Modified: ace/trunk/org.apache.ace.log.task/src/org/apache/ace/server/log/task/LogSyncTask.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log.task/src/org/apache/ace/server/log/task/LogSyncTask.java?rev=1447249&r1=1447248&r2=1447249&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.log.task/src/org/apache/ace/server/log/task/LogSyncTask.java
(original)
+++ ace/trunk/org.apache.ace.log.task/src/org/apache/ace/server/log/task/LogSyncTask.java
Mon Feb 18 13:30:30 2013
@@ -48,7 +48,7 @@ public class LogSyncTask implements Runn
     private static final String COMMAND_SEND = "send";
     private static final String COMMAND_RECEIVE = "receive";
 
-    private static final String TARGETID_KEY = "gwid";
+    private static final String TARGETID_KEY = "tid";
     private static final String FILTER_KEY = "filter";
     private static final String LOGID_KEY = "logid";
     private static final String RANGE_KEY = "range";
@@ -61,21 +61,35 @@ public class LogSyncTask implements Runn
     
     private final String m_endpoint;
     private final String m_name;
+	private final Mode m_mode;
 
-    public LogSyncTask(String endpoint, String name) {
+    public static enum Mode { PUSH, PULL, PUSHPULL };
+    
+    public LogSyncTask(String endpoint, String name, Mode mode) {
         m_endpoint = endpoint;
         m_name = name;
+		m_mode = mode;
     }
 
     public void run() {
         try {
-            push();
+        	switch (m_mode) {
+	        	case PULL:
+	        		pull();
+	        		break;
+	        	case PUSH:
+	        		push();
+	        		break;
+	        	case PUSHPULL:
+	        		pushpull();
+	        		break;
+        	}
         }
         catch (MalformedURLException e) {
-            m_log.log(LogService.LOG_ERROR, "Unable to (fully) synchronize log (name=" +
m_name + ") with remote");
+            m_log.log(LogService.LOG_ERROR, "Unable to (" + m_mode.toString() + ") synchronize
log (name=" + m_name + ") with remote");
         }
         catch (IOException e) {
-            m_log.log(LogService.LOG_ERROR, "Unable to (fully) synchronize log (name=" +
m_name + ") with remote", e);
+            m_log.log(LogService.LOG_ERROR, "Unable to (" + m_mode.toString() + ") synchronize
log (name=" + m_name + ") with remote", e);
         }
     }
 

Modified: ace/trunk/org.apache.ace.log.task/test/org/apache/ace/server/log/task/LogTaskTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log.task/test/org/apache/ace/server/log/task/LogTaskTest.java?rev=1447249&r1=1447248&r2=1447249&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.log.task/test/org/apache/ace/server/log/task/LogTaskTest.java
(original)
+++ ace/trunk/org.apache.ace.log.task/test/org/apache/ace/server/log/task/LogTaskTest.java
Mon Feb 18 13:30:30 2013
@@ -36,7 +36,7 @@ public class LogTaskTest {
         public List<LogDescriptor> m_calledWith = new ArrayList<LogDescriptor>();
 
         public MockLogSyncTask(String endpoint, String name) {
-            super(endpoint, name);
+            super(endpoint, name, LogSyncTask.Mode.PUSH);
         }
 
         @Override



Mime
View raw message