sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1617269 - in /sling/trunk/contrib/extensions/replication/core/src: main/java/org/apache/sling/replication/agent/ main/java/org/apache/sling/replication/agent/impl/ main/java/org/apache/sling/replication/rule/impl/ main/java/org/apache/slin...
Date Mon, 11 Aug 2014 12:58:53 GMT
Author: tommaso
Date: Mon Aug 11 12:58:53 2014
New Revision: 1617269

URL: http://svn.apache.org/r1617269
Log:
SLING-3833 - applied Marius Petria's patch for cleaning up ReplicationAgent interface

Added:
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactory.java   (with props)
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/ReplicationTransportConstants.java   (with props)
    sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish-reverse.json
    sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish.json
    sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-cache-flush.json
    sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-reverse.json
    sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactoryTest.java   (with props)
Removed:
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/AgentConfigurationException.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactory.java
    sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish-reverse.json
    sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish.json
    sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-cache-flush.json
    sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reverse.json
    sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/resourceproviders/configs/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-httpTransportConfig.json
    sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java
    sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManagerTest.java
    sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactoryTest.java
Modified:
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRule.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ReplicateOnQueueEventRule.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRule.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/AbstractReplicationPackageBuilder.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/exporter/AgentReplicationPackageExporter.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackage.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentRootServlet.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/exporter/RemoteReplicationPackageExporter.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/importer/AdvancedRemoteReplicationPackageImporter.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/importer/RemoteReplicationPackageImporter.java
    sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/resourceproviders/configs/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-agentsConfig.json
    sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentTest.java

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java Mon Aug 11 12:58:53 2014
@@ -54,30 +54,4 @@ public interface ReplicationAgent {
      */
     ReplicationResponse execute(ReplicationRequest replicationRequest) throws AgentReplicationException;
 
-    /**
-     * Asynchronously sends a {@link ReplicationRequest} without waiting for any response
-     *
-     * @param replicationRequest the replication request
-     * @throws AgentReplicationException
-     */
-    void send(ReplicationRequest replicationRequest) throws AgentReplicationException;
-
-    /**
-     * removes a package from the top of the queue
-     * @param queueName
-     *          the name of a {@link ReplicationQueue} bound to this agent
-     * @return the <code>ReplicationPackage</code> popped from the underlying <code>ReplicationQueue</code>
-     * @throws ReplicationQueueException
-     */
-    ReplicationPackage removeHead(String queueName) throws ReplicationQueueException;
-
-    /**
-     * enables the current  {@link ReplicationAgent}
-     */
-    void enable();
-
-    /**
-     * disables the current  {@link ReplicationAgent}
-     */
-    void disable();
 }

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java Mon Aug 11 12:58:53 2014
@@ -87,21 +87,7 @@ public class SimpleReplicationAgent impl
         List<ReplicationPackage> replicationPackages;
         try {
             replicationPackages = buildPackages(replicationRequest);
-            return schedule(replicationPackages, false);
-
-        } catch (ReplicationPackageBuildingException e) {
-            log.error("Error building packages", e);
-            throw new AgentReplicationException(e);
-        }
-
-    }
-
-    public void send(ReplicationRequest replicationRequest) throws AgentReplicationException {
-        // create packages from request
-        List<ReplicationPackage> replicationPackages = null;
-        try {
-            replicationPackages = buildPackages(replicationRequest);
-            schedule(replicationPackages, true);
+            return schedule(replicationPackages);
 
         } catch (ReplicationPackageBuildingException e) {
             log.error("Error building packages", e);
@@ -135,12 +121,11 @@ public class SimpleReplicationAgent impl
         return replicationPackages;
     }
 
-    // offer option throws an exception at first error
-    private ReplicationResponse schedule(List<ReplicationPackage> replicationPackages, boolean offer) throws AgentReplicationException {
+    private ReplicationResponse schedule(List<ReplicationPackage> replicationPackages) {
         ReplicationResponse replicationResponse = new ReplicationResponse();
 
         for (ReplicationPackage replicationPackage : replicationPackages) {
-            ReplicationResponse currentReplicationResponse = schedule(replicationPackage, offer);
+            ReplicationResponse currentReplicationResponse = schedule(replicationPackage);
 
             replicationResponse.setSuccessful(currentReplicationResponse.isSuccessful());
             replicationResponse.setStatus(currentReplicationResponse.getStatus());
@@ -149,7 +134,7 @@ public class SimpleReplicationAgent impl
         return replicationResponse;
     }
 
-    private ReplicationResponse schedule(ReplicationPackage replicationPackage, boolean offer) throws AgentReplicationException {
+    private ReplicationResponse schedule(ReplicationPackage replicationPackage) {
         ReplicationResponse replicationResponse = new ReplicationResponse();
         log.info("scheduling replication of package {}", replicationPackage);
 
@@ -158,38 +143,26 @@ public class SimpleReplicationAgent impl
                 replicationPackage.getAction(),
                 replicationPackage.getType());
 
-        if (offer) {
-            try {
-                queueDistributionStrategy.offer(getName(), replicationQueueItem, queueProvider);
-                if (isPassive()) {
-                    generatePackageQueuedEvent(replicationQueueItem);
-                }
-            } catch (ReplicationQueueException e) {
-                replicationResponse.setSuccessful(false);
-                throw new AgentReplicationException(e);
+        // send the replication package to the queue distribution handler
+        try {
+            ReplicationQueueItemState state = queueDistributionStrategy.add(getName(), replicationQueueItem,
+                    queueProvider);
+            if (isPassive()) {
+                generatePackageQueuedEvent(replicationQueueItem);
             }
-        } else {
-            // send the replication package to the queue distribution handler
-            try {
-                ReplicationQueueItemState state = queueDistributionStrategy.add(getName(), replicationQueueItem,
-                        queueProvider);
-                if (isPassive()) {
-                    generatePackageQueuedEvent(replicationQueueItem);
-                }
-                if (state != null) {
-                    replicationResponse.setStatus(state.getItemState().toString());
-                    replicationResponse.setSuccessful(state.isSuccessful());
-                } else {
-                    replicationResponse.setStatus(ReplicationQueueItemState.ItemState.ERROR.toString());
-                    replicationResponse.setSuccessful(false);
-                }
-            } catch (Exception e) {
-                if (log.isErrorEnabled()) {
-                    log.error("an error happened during queue processing", e);
-                }
+            if (state != null) {
+                replicationResponse.setStatus(state.getItemState().toString());
+                replicationResponse.setSuccessful(state.isSuccessful());
+            } else {
+                replicationResponse.setStatus(ReplicationQueueItemState.ItemState.ERROR.toString());
                 replicationResponse.setSuccessful(false);
             }
+        } catch (Exception e) {
+            log.error("an error happened during queue processing", e);
+
+            replicationResponse.setSuccessful(false);
         }
+
         return replicationResponse;
     }
 
@@ -200,20 +173,6 @@ public class SimpleReplicationAgent impl
         replicationEventFactory.generateEvent(ReplicationEventType.PACKAGE_QUEUED, properties);
     }
 
-    public ReplicationPackage removeHead(String queueName) throws ReplicationQueueException {
-        ReplicationPackage replicationPackage = null;
-        if (isPassive()) {
-            ReplicationQueue queue = getQueue(queueName);
-            ReplicationQueueItem info = queue.getHead();
-            if (info != null) {
-                queue.removeHead();
-                replicationPackage = replicationPackageExporter.exportPackageById(info.getId());
-            }
-            return replicationPackage;
-        } else {
-            throw new ReplicationQueueException("cannot explicitly fetch items from not-passive agents");
-        }
-    }
 
     public String getName() {
         return name;

Added: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactory.java?rev=1617269&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactory.java (added)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactory.java Mon Aug 11 12:58:53 2014
@@ -0,0 +1,208 @@
+/*
+ * 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.apache.sling.replication.agent.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.event.ReplicationEventFactory;
+import org.apache.sling.replication.queue.ReplicationQueueDistributionStrategy;
+import org.apache.sling.replication.queue.ReplicationQueueProvider;
+import org.apache.sling.replication.queue.impl.SingleQueueDistributionStrategy;
+import org.apache.sling.replication.queue.impl.jobhandling.JobHandlingReplicationQueueProvider;
+import org.apache.sling.replication.rule.ReplicationRuleEngine;
+import org.apache.sling.replication.serialization.ReplicationPackageExporter;
+import org.apache.sling.replication.serialization.ReplicationPackageImporter;
+import org.apache.sling.settings.SlingSettingsService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An OSGi service factory for {@link ReplicationAgent}s
+ */
+@Component(metatype = true,
+        label = "Replication Agents Factory",
+        description = "OSGi configuration based ReplicationAgent service factory",
+        name = SimpleReplicationAgentFactory.SERVICE_PID,
+        configurationFactory = true,
+        specVersion = "1.1",
+        policy = ConfigurationPolicy.REQUIRE
+)
+public class SimpleReplicationAgentFactory {
+
+
+    public static final String PACKAGE_EXPORTER_TARGET = "ReplicationPackageExporter.target";
+
+    public static final String PACKAGE_IMPORTER_TARGET = "ReplicationPackageImporter.target";
+
+    public static final String QUEUEPROVIDER_TARGET = "ReplicationQueueProvider.target";
+
+    public static final String QUEUE_DISTRIBUTION_TARGET = "ReplicationQueueDistributionStrategy.target";
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    static final String SERVICE_PID = "org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory";
+
+    private static final String DEFAULT_QUEUEPROVIDER = "(name=" + JobHandlingReplicationQueueProvider.NAME + ")";
+
+    private static final String DEFAULT_DISTRIBUTION = "(name=" + SingleQueueDistributionStrategy.NAME + ")";
+
+    @Property(boolValue = true, label = "Enabled")
+    private static final String ENABLED = "enabled";
+
+    @Property(label = "Name")
+    private static final String NAME = "name";
+
+    @Property(label = "Rules")
+    private static final String RULES = "rules";
+
+    @Property(boolValue = true, label = "Replicate using aggregated paths")
+    private static final String USE_AGGREGATE_PATHS = "useAggregatePaths";
+
+    @Property(label = "Target ReplicationPackageExporter", name = PACKAGE_EXPORTER_TARGET)
+    @Reference(name = "ReplicationPackageExporter", policy = ReferencePolicy.DYNAMIC)
+    private ReplicationPackageExporter packageExporter;
+
+    @Property(label = "Target ReplicationPackageImporter", name = PACKAGE_IMPORTER_TARGET)
+    @Reference(name = "ReplicationPackageImporter", policy = ReferencePolicy.DYNAMIC)
+    private ReplicationPackageImporter packageImporter;
+
+    @Property(label = "Target ReplicationQueueProvider", name = QUEUEPROVIDER_TARGET, value = DEFAULT_QUEUEPROVIDER)
+    @Reference(name = "ReplicationQueueProvider", target = DEFAULT_QUEUEPROVIDER, policy = ReferencePolicy.DYNAMIC)
+    private volatile ReplicationQueueProvider queueProvider;
+
+    @Property(label = "Target QueueDistributionStrategy", name = QUEUE_DISTRIBUTION_TARGET, value = DEFAULT_DISTRIBUTION)
+    @Reference(name = "ReplicationQueueDistributionStrategy", target = DEFAULT_DISTRIBUTION, policy = ReferencePolicy.DYNAMIC)
+    private volatile ReplicationQueueDistributionStrategy queueDistributionStrategy;
+
+    @Property(label = "Runmodes")
+    private static final String RUNMODES = "runModes";
+
+    private ServiceRegistration agentReg;
+
+    @Reference
+    private ReplicationRuleEngine replicationRuleEngine;
+
+    @Reference
+    private ReplicationEventFactory replicationEventFactory;
+
+    @Reference
+    private SlingSettingsService settingsService;
+
+    @Activate
+    public void activate(BundleContext context, Map<String, ?> config) throws Exception {
+
+        // inject configuration
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+
+        boolean enabled = PropertiesUtil.toBoolean(config.get(ENABLED), true);
+
+        if (enabled) {
+            props.put(ENABLED, true);
+
+            String[] runModes = PropertiesUtil.toStringArray(config.get(RUNMODES), new String[0]);
+            props.put(RUNMODES, runModes);
+
+            String name = PropertiesUtil
+                    .toString(config.get(NAME), String.valueOf(new Random().nextInt(1000)));
+            props.put(NAME, name);
+
+
+            String queue = PropertiesUtil.toString(config.get(QUEUEPROVIDER_TARGET), "");
+            props.put(QUEUEPROVIDER_TARGET, queue);
+
+            String distribution = PropertiesUtil.toString(config.get(QUEUE_DISTRIBUTION_TARGET), "");
+            props.put(QUEUE_DISTRIBUTION_TARGET, distribution);
+
+            String[] rules = PropertiesUtil.toStringArray(config.get(RULES), new String[0]);
+            props.put(RULES, rules);
+
+
+            boolean useAggregatePaths = PropertiesUtil.toBoolean(config.get(USE_AGGREGATE_PATHS), true);
+            props.put(USE_AGGREGATE_PATHS, useAggregatePaths);
+
+            boolean isPassive = PropertiesUtil.toBoolean(config.get("isPassive"), false);
+            props.put(USE_AGGREGATE_PATHS, useAggregatePaths);
+
+            // check configuration is valid
+            if (name == null || packageExporter == null || packageImporter == null || queueProvider == null || queueDistributionStrategy == null) {
+                throw new Exception("configuration for this agent is not valid");
+            }
+
+
+            if (log.isInfoEnabled()) {
+                log.info("bound services for {} :  {} - {} - {} - {} - {} - {}", new Object[]{name,
+                        packageImporter, packageExporter, queueProvider, queueDistributionStrategy});
+            }
+
+            SimpleReplicationAgent agent = new SimpleReplicationAgent(name, rules, useAggregatePaths, isPassive,
+                    packageImporter, packageExporter, queueProvider, queueDistributionStrategy, replicationEventFactory, replicationRuleEngine);
+
+
+            // only enable if instance runmodes match configured ones
+            if (matchRunmodes(runModes)) {
+                // register agent service
+                agentReg = context.registerService(ReplicationAgent.class.getName(), agent, props);
+                agent.enable();
+            }
+        }
+    }
+
+    private boolean matchRunmodes(String[] configuredRunModes) {
+        boolean match = configuredRunModes == null || configuredRunModes.length == 0;
+        if (!match) {
+            Set<String> activeRunModes = settingsService.getRunModes();
+            for (String activeRunMode : activeRunModes) {
+                for (String configuredRunMode : configuredRunModes) {
+                    if (activeRunMode.equals(configuredRunMode)) {
+                        match = true;
+                        break;
+                    }
+                }
+            }
+        }
+        return match;
+    }
+
+    @Deactivate
+    private void deactivate(BundleContext context) {
+        if (agentReg != null) {
+            ServiceReference reference = agentReg.getReference();
+            SimpleReplicationAgent replicationAgent = (SimpleReplicationAgent) context.getService(reference);
+            replicationAgent.disable();
+            agentReg.unregister();
+        }
+
+    }
+}

Propchange: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRule.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRule.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRule.java Mon Aug 11 12:58:53 2014
@@ -81,22 +81,19 @@ public class ChainReplicateReplicationRu
             Dictionary<String, Object> properties = new Hashtable<String, Object>();
             properties.put(EventConstants.EVENT_TOPIC, ReplicationEvent.getTopic(ReplicationEventType.PACKAGE_INSTALLED));
             String path = ruleString.substring(ruleString.indexOf(':') + 1).trim();
-            if (log.isInfoEnabled()) {
-                log.info("agent {} will chain replication on path '{}'", agent.getName(), path);
-            }
+            log.info("agent {} will chain replication on path '{}'", agent.getName(), path);
+
 //            properties.put(EventConstants.EVENT_FILTER, "(path=" + path + "/*)");
             if (bundleContext != null) {
                 ServiceRegistration triggerPathEventRegistration = bundleContext.registerService(EventHandler.class.getName(), new TriggerAgentEventListener(agent, path), properties);
                 registrations.put(agent.getName() + ruleString, triggerPathEventRegistration);
             } else {
-                if (log.isErrorEnabled()) {
-                    log.error("cannot register trigger since bundle context is null");
-                }
+                log.error("cannot register trigger since bundle context is null");
+
             }
         } else {
-            if (log.isWarnEnabled()) {
-                log.warn("rule {} doesn't match signature: {}", ruleString, SIGNATURE);
-            }
+            log.warn("rule {} doesn't match signature: {}", ruleString, SIGNATURE);
+
         }
 
     }
@@ -112,9 +109,8 @@ public class ChainReplicateReplicationRu
                 serviceRegistration.unregister();
             }
         } else {
-            if (log.isWarnEnabled()) {
-                log.warn("rule {} doesn't match signature: {}", ruleString, SIGNATURE);
-            }
+            log.warn("rule {} doesn't match signature: {}", ruleString, SIGNATURE);
+
         }
     }
 
@@ -136,16 +132,14 @@ public class ChainReplicateReplicationRu
                 String[] paths = (String[]) pathProperty;
                 for (String p : paths) {
                     if (p.startsWith(path)) {
-                        if (log.isInfoEnabled()) {
-                            log.info("triggering chain replication from event {}", event);
-                        }
+                        log.info("triggering chain replication from event {}", event);
+
                         ReplicationActionType action = ReplicationActionType.valueOf(String.valueOf(actionProperty));
                         try {
-                            agent.send(new ReplicationRequest(System.currentTimeMillis(), action, paths));
+                            agent.execute(new ReplicationRequest(System.currentTimeMillis(), action, paths));
                         } catch (AgentReplicationException e) {
-                            if (log.isErrorEnabled()) {
-                                log.error("triggered replication resulted in an error {}", e);
-                            }
+                            log.error("triggered replication resulted in an error {}", e);
+
                         }
                         break;
                     }

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ReplicateOnQueueEventRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ReplicateOnQueueEventRule.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ReplicateOnQueueEventRule.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ReplicateOnQueueEventRule.java Mon Aug 11 12:58:53 2014
@@ -47,8 +47,6 @@ import org.apache.sling.commons.schedule
 import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.replication.agent.AgentReplicationException;
 import org.apache.sling.replication.agent.ReplicationAgent;
-import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
-import org.apache.sling.replication.agent.ReplicationAgentConfigurationManager;
 import org.apache.sling.replication.communication.ReplicationActionType;
 import org.apache.sling.replication.communication.ReplicationRequest;
 import org.apache.sling.replication.resources.ReplicationConstants;
@@ -74,8 +72,6 @@ public class ReplicateOnQueueEventRule i
 
     private static final Pattern signaturePattern = Pattern.compile(SIGNATURE_REGEX);
 
-    @Reference
-    private ReplicationAgentConfigurationManager replicationAgentConfigurationManager;
 
     @Reference
     private Scheduler scheduler;
@@ -106,17 +102,10 @@ public class ReplicateOnQueueEventRule i
             String path = matcher.group(5); // can be null
             try {
                 log.info("applying queue event replication rule");
-                // get configuration
-                ReplicationAgentConfiguration configuration = replicationAgentConfigurationManager.getConfiguration(agent.getName());
-
-                // get URI of the event queue
-                String targetTransport = configuration.getTargetTransportHandler();
-
-                log.info("found target transport {}", targetTransport);
 
                 ScheduleOptions options = scheduler.NOW();
                 options.name(agent.getName() + " " + ruleString);
-                scheduler.schedule(new EventBasedReplication(agent, actionType, path, targetTransport), options);
+                scheduler.schedule(new EventBasedReplication(agent, actionType, path, null), options);
 
             } catch (Exception e) {
                 log.error("{}", e);
@@ -171,7 +160,7 @@ public class ReplicateOnQueueEventRule i
     }
 
     private void asyncReplicate(ReplicationAgent agent, ReplicationActionType action, String path) throws AgentReplicationException {
-        agent.send(new ReplicationRequest(System.currentTimeMillis(), action, path));
+        agent.execute(new ReplicationRequest(System.currentTimeMillis(), action, path));
     }
 
     private class EventBasedReplication implements Runnable {

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRule.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRule.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRule.java Mon Aug 11 12:58:53 2014
@@ -92,15 +92,12 @@ public class ScheduleReplicateReplicatio
 
         public void run() {
             try {
-                if (log.isDebugEnabled()) {
-                    log.debug("agent {}: scheduling {} replication of {}", new Object[]{agent, action, path});
-                }
-                agent.send(new ReplicationRequest(System.currentTimeMillis(), action, path));
+                log.debug("agent {}: scheduling {} replication of {}", new Object[]{agent, action, path});
+
+                agent.execute(new ReplicationRequest(System.currentTimeMillis(), action, path));
             } catch (AgentReplicationException e) {
-                if (log.isErrorEnabled()) {
-                    log.error("failed scheduled replication {} on agent {} for path {}", new Object[]{
-                            action.name(), agent.getName(), path}, e);
-                }
+                log.error("failed scheduled replication {} on agent {} for path {}", new Object[]{
+                        action.name(), agent.getName(), path}, e);
             }
         }
     }

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java Mon Aug 11 12:58:53 2014
@@ -82,22 +82,19 @@ public class TriggerPathReplicationRule 
             properties.put(EventConstants.EVENT_TOPIC, new String[]{SlingConstants.TOPIC_RESOURCE_ADDED,
                     SlingConstants.TOPIC_RESOURCE_CHANGED, SlingConstants.TOPIC_RESOURCE_REMOVED});
             String path = ruleString.substring(ruleString.indexOf(':') + 1).trim();
-            if (log.isInfoEnabled()) {
-                log.info("trigger agent {} on path '{}'", agent.getName(), path);
-            }
+            log.info("trigger agent {} on path '{}'", agent.getName(), path);
+
             properties.put(EventConstants.EVENT_FILTER, "(path=" + path + "/*)");
             if (bundleContext != null) {
                 ServiceRegistration triggerPathEventRegistration = bundleContext.registerService(EventHandler.class.getName(), new TriggerAgentEventListener(agent), properties);
                 registrations.put(agent.getName() + ruleString, triggerPathEventRegistration);
             } else {
-                if (log.isErrorEnabled()) {
-                    log.error("cannot register trigger since bundle context is null");
-                }
+                log.error("cannot register trigger since bundle context is null");
+
             }
         } else {
-            if (log.isWarnEnabled()) {
-                log.warn("rule {} doesn't match signature: {}", ruleString, SIGNATURE);
-            }
+            log.warn("rule {} doesn't match signature: {}", ruleString, SIGNATURE);
+
         }
 
     }
@@ -113,9 +110,8 @@ public class TriggerPathReplicationRule 
                 serviceRegistration.unregister();
             }
         } else {
-            if (log.isWarnEnabled()) {
-                log.warn("rule {} doesn't match signature: {}", ruleString, SIGNATURE);
-            }
+            log.warn("rule {} doesn't match signature: {}", ruleString, SIGNATURE);
+
         }
     }
 
@@ -130,18 +126,15 @@ public class TriggerPathReplicationRule 
 
         public void handleEvent(Event event) {
             ReplicationActionType action = SlingConstants.TOPIC_RESOURCE_REMOVED.equals(event.getTopic()) ? ReplicationActionType.DELETE : ReplicationActionType.ADD;
-            if (log.isInfoEnabled()) {
-                log.info("triggering replication from event {}", event);
-            }
+            log.info("triggering replication from event {}", event);
+
             Object eventProperty = event.getProperty("path");
             if (eventProperty != null) {
                 String replicatingPath = String.valueOf(eventProperty);
                 try {
-                    agent.send(new ReplicationRequest(System.currentTimeMillis(), action, replicatingPath));
+                    agent.execute(new ReplicationRequest(System.currentTimeMillis(), action, replicatingPath));
                 } catch (AgentReplicationException e) {
-                    if (log.isErrorEnabled()) {
-                        log.error("triggered replication resulted in an error", e);
-                    }
+                    log.error("triggered replication resulted in an error", e);
                 }
             }
         }

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/AbstractReplicationPackageBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/AbstractReplicationPackageBuilder.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/AbstractReplicationPackageBuilder.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/AbstractReplicationPackageBuilder.java Mon Aug 11 12:58:53 2014
@@ -18,13 +18,13 @@
  */
 package org.apache.sling.replication.serialization.impl;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.nio.charset.Charset;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
+
 import org.apache.sling.replication.communication.ReplicationActionType;
 import org.apache.sling.replication.communication.ReplicationRequest;
 import org.apache.sling.replication.serialization.ReplicationPackage;
@@ -92,7 +92,6 @@ public abstract class AbstractReplicatio
         if (ReplicationActionType.DELETE.equals(actionType)) {
             return installDeletePackage(replicationPackage);
         }
-
         return installPackageInternal(replicationPackage);
 
     }
@@ -100,7 +99,7 @@ public abstract class AbstractReplicatio
     private boolean installDeletePackage(ReplicationPackage replicationPackage) throws ReplicationPackageReadingException {
         Session session = null;
         try {
-            if(replicationPackage != null){
+            if (replicationPackage != null) {
                 session = getSession();
                 for (String path : replicationPackage.getPaths()) {
                     if (session.itemExists(path)) {
@@ -125,12 +124,11 @@ public abstract class AbstractReplicatio
         ReplicationPackage replicationPackage = null;
         try {
             replicationPackage = VoidReplicationPackage.fromStream(new ByteArrayInputStream(id.getBytes("UTF-8")));
-        }
-        catch (IOException ex){
+        } catch (IOException ex) {
             // not a void package
         }
 
-        if(replicationPackage == null) {
+        if (replicationPackage == null) {
             replicationPackage = getPackageInternal(id);
         }
         return replicationPackage;

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/exporter/AgentReplicationPackageExporter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/exporter/AgentReplicationPackageExporter.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/exporter/AgentReplicationPackageExporter.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/exporter/AgentReplicationPackageExporter.java Mon Aug 11 12:58:53 2014
@@ -26,6 +26,8 @@ import org.apache.felix.scr.annotations.
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.replication.agent.ReplicationAgent;
 import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.queue.ReplicationQueue;
+import org.apache.sling.replication.queue.ReplicationQueueItem;
 import org.apache.sling.replication.serialization.ReplicationPackage;
 import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
 import org.apache.sling.replication.serialization.ReplicationPackageExporter;
@@ -69,11 +71,19 @@ public class AgentReplicationPackageExpo
                 log.info("getting item from queue {}", queueName);
             }
 
-            // get first item
-            ReplicationPackage headPackage = agent.removeHead(queueName);
-            result.add(headPackage);
+            ReplicationQueue queue = agent.getQueue(queueName);
+            ReplicationQueueItem info = queue.getHead();
+            ReplicationPackage replicationPackage = null;
+            if (info != null) {
+                queue.removeHead();
+                replicationPackage = replicationPackageBuilder.getPackage(info.getId());
+            }
+
+            result.add(replicationPackage);
         } catch (Exception ex) {
-            log.error("Error exporting package", ex);
+            if (log.isErrorEnabled()) {
+                log.error("Error exporting package", ex);
+            }
         }
 
         return result;

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackage.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackage.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackage.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackage.java Mon Aug 11 12:58:53 2014
@@ -26,6 +26,8 @@ import java.util.Arrays;
 import java.util.List;
 
 import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
+import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.jackrabbit.vault.fs.config.MetaInf;
 import org.apache.jackrabbit.vault.packaging.VaultPackage;
 import org.apache.sling.replication.communication.ReplicationActionType;
 import org.apache.sling.replication.serialization.ReplicationPackage;
@@ -47,10 +49,17 @@ public class FileVaultReplicationPackage
 
     public FileVaultReplicationPackage(VaultPackage pkg) {
         this.pkg = pkg;
-        List<PathFilterSet> filterSets = pkg.getMetaInf().getFilter().getFilterSets();
-        String[] paths = new String[filterSets.size()];
-        for (int i = 0; i < paths.length; i++) {
-            paths[i] = filterSets.get(i).getRoot();
+        MetaInf metaInf = pkg.getMetaInf();
+        String[] paths = new String[0];
+        if (metaInf != null) {
+            WorkspaceFilter filter = metaInf.getFilter();
+            if (filter != null) {
+                List<PathFilterSet> filterSets = filter.getFilterSets();
+                paths = new String[filterSets.size()];
+                for (int i = 0; i < paths.length; i++) {
+                    paths[i] = filterSets.get(i).getRoot();
+                }
+            }
         }
         this.paths = paths;
         this.id = pkg.getFile().getAbsolutePath();

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java Mon Aug 11 12:58:53 2014
@@ -111,9 +111,9 @@ public class FileVaultReplicationPackage
             opts.setMetaInf(inf);
             opts.setRootPath("/");
             File tmpFile = File.createTempFile("rp-vlt-create-" + System.nanoTime(), ".zip");
-            VaultPackage vaultPackage = packaging.getPackageManager().assemble(session, opts, tmpFile);
-
-            return new FileVaultReplicationPackage(vaultPackage);
+            packaging.getPackageManager().assemble(session, opts, tmpFile);
+            JcrPackage jcrPackage = packaging.getPackageManager(session).upload(tmpFile, false, true, null);
+            return new FileVaultReplicationPackage(jcrPackage.getPackage());
         } catch (Exception e) {
             throw new ReplicationPackageBuildingException(e);
         } finally {
@@ -139,7 +139,6 @@ public class FileVaultReplicationPackage
         if (log.isDebugEnabled()) {
             log.debug("reading a stream");
         }
-        Session session = null;
         ReplicationPackage pkg = null;
         try {
             File tmpFile = File.createTempFile("rp-vlt-read-" + System.nanoTime(), ".zip");
@@ -149,15 +148,19 @@ public class FileVaultReplicationPackage
 
             VaultPackage vaultPackage = packaging.getPackageManager().open(tmpFile);
 
-            pkg = new FileVaultReplicationPackage(vaultPackage);
+            if (vaultPackage != null) {
+                pkg = new FileVaultReplicationPackage(vaultPackage);
+            } else {
+                if (log.isWarnEnabled()) {
+                    log.warn("stream could not be read as a vlt package");
+                }
+            }
 
         } catch (Exception e) {
-            log.error("could not read / install the package", e);
-            throw new ReplicationPackageReadingException(e);
-        } finally {
-            if (session != null) {
-                session.logout();
+            if (log.isErrorEnabled()) {
+                log.error("could not read / install the package", e);
             }
+            throw new ReplicationPackageReadingException(e);
         }
         return pkg;
     }
@@ -171,9 +174,14 @@ public class FileVaultReplicationPackage
             if (file.exists()) {
                 VaultPackage pkg = packaging.getPackageManager().open(file);
                 replicationPackage = new FileVaultReplicationPackage(pkg);
+            } else {
+                VaultPackage pkg = packaging.getPackageManager(getSession()).open(PackageId.fromString(id)).getPackage();
+                replicationPackage = new FileVaultReplicationPackage(pkg);
             }
         } catch (Exception e) {
-            log.warn("could not find a package with id : {}", id);
+            if (log.isWarnEnabled()) {
+                log.warn("could not find a package with id : {}", id);
+            }
         }
         return replicationPackage;
     }
@@ -188,20 +196,28 @@ public class FileVaultReplicationPackage
 
     @Override
     public boolean installPackageInternal(ReplicationPackage replicationPackage) throws ReplicationPackageReadingException {
-        log.debug("reading a replication package stream");
-
+        if (log.isDebugEnabled()) {
+            log.debug("reading a replication package stream");
+        }
 
         Session session = null;
         try {
             session = getSession();
-            File file = new File(replicationPackage.getId());
-            if (file.exists()) {
-                VaultPackage pkg = packaging.getPackageManager().open(file);
-                pkg.extract(session, new ImportOptions());
-                return true;
+            if (session != null) {
+                final JcrPackage jcrPackage = packaging.getPackageManager(getSession())
+                        .open(PackageId.fromString(replicationPackage.getId()));
+                jcrPackage.install(new ImportOptions());
             }
+//            File file = new File(replicationPackage.getId());
+//            if (file.exists()) {
+//                VaultPackage pkg = packaging.getPackageManager().open(file);
+//                pkg.extract(session, new ImportOptions());
+//                return true;
+//            }
         } catch (Exception e) {
-            log.error("could not read / install the package", e);
+            if (log.isErrorEnabled()) {
+                log.error("could not read / install the package", e);
+            }
             throw new ReplicationPackageReadingException(e);
         } finally {
             if (session != null) {

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentRootServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentRootServlet.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentRootServlet.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentRootServlet.java Mon Aug 11 12:58:53 2014
@@ -76,7 +76,7 @@ public class ReplicationAgentRootServlet
         boolean failed = false;
         for (ReplicationAgent agent : agents) {
             try {
-                agent.send(replicationRequest);
+                agent.execute(replicationRequest);
             } catch (AgentReplicationException e) {
                 log.warn("agent {} failed", agent.getName(), e);
 

Added: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/ReplicationTransportConstants.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/ReplicationTransportConstants.java?rev=1617269&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/ReplicationTransportConstants.java (added)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/ReplicationTransportConstants.java Mon Aug 11 12:58:53 2014
@@ -0,0 +1,33 @@
+/*
+ * 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.apache.sling.replication.transport.impl;
+
+/**
+ * Replication transport constants
+ */
+public class ReplicationTransportConstants {
+
+    public static final String TRANSPORT_AUTHENTICATION_FACTORY = "TransportAuthenticationProviderFactory.target";
+
+    public static final String ENDPOINTS = "endpoints";
+
+    public static final String ENDPOINT_STRATEGY = "endpoints.strategy";
+
+    public static final String AUTHENTICATION_PROPERTIES = "authentication.properties";
+}

Propchange: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/ReplicationTransportConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/exporter/RemoteReplicationPackageExporter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/exporter/RemoteReplicationPackageExporter.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/exporter/RemoteReplicationPackageExporter.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/exporter/RemoteReplicationPackageExporter.java Mon Aug 11 12:58:53 2014
@@ -21,7 +21,6 @@ package org.apache.sling.replication.tra
 import org.apache.felix.scr.annotations.*;
 import org.apache.http.client.fluent.Executor;
 import org.apache.sling.commons.osgi.PropertiesUtil;
-import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
 import org.apache.sling.replication.communication.ReplicationEndpoint;
 import org.apache.sling.replication.communication.ReplicationRequest;
 import org.apache.sling.replication.serialization.*;
@@ -29,6 +28,7 @@ import org.apache.sling.replication.tran
 import org.apache.sling.replication.transport.authentication.TransportAuthenticationProvider;
 import org.apache.sling.replication.transport.authentication.TransportAuthenticationProviderFactory;
 import org.apache.sling.replication.transport.impl.MultipleEndpointReplicationTransportHandler;
+import org.apache.sling.replication.transport.impl.ReplicationTransportConstants;
 import org.apache.sling.replication.transport.impl.SimpleHttpReplicationTransportHandler;
 import org.apache.sling.replication.transport.impl.TransportEndpointStrategyType;
 import org.osgi.framework.BundleContext;
@@ -50,7 +50,7 @@ public class RemoteReplicationPackageExp
     @Property
     private static final String NAME = "name";
 
-    @Property(name = ReplicationAgentConfiguration.TRANSPORT_AUTHENTICATION_FACTORY)
+    @Property(name = ReplicationTransportConstants.TRANSPORT_AUTHENTICATION_FACTORY)
     @Reference(name = "TransportAuthenticationProviderFactory", policy = ReferencePolicy.DYNAMIC)
     private TransportAuthenticationProviderFactory transportAuthenticationProviderFactory;
 
@@ -71,7 +71,7 @@ public class RemoteReplicationPackageExp
             )},
             value = "One"
     )
-    private static final String ENDPOINT_STRATEGY = ReplicationAgentConfiguration.ENDPOINT_STRATEGY;
+    private static final String ENDPOINT_STRATEGY = ReplicationTransportConstants.ENDPOINT_STRATEGY;
 
     int pollItems;
     ReplicationTransportHandler transportHandler;
@@ -79,15 +79,15 @@ public class RemoteReplicationPackageExp
     @Activate
     protected void activate(BundleContext context, Map<String, ?> config) throws Exception {
 
-        Map<String, String> authenticationProperties = PropertiesUtil.toMap(config.get(ReplicationAgentConfiguration.AUTHENTICATION_PROPERTIES), new String[0]);
+        Map<String, String> authenticationProperties = PropertiesUtil.toMap(config.get(ReplicationTransportConstants.AUTHENTICATION_PROPERTIES), new String[0]);
 
         TransportAuthenticationProvider<Executor, Executor> transportAuthenticationProvider = (TransportAuthenticationProvider<Executor, Executor>) transportAuthenticationProviderFactory.createAuthenticationProvider(authenticationProperties);
 
-        String[] endpoints = PropertiesUtil.toStringArray(config.get(ReplicationAgentConfiguration.ENDPOINT), new String[0]);
+        String[] endpoints = PropertiesUtil.toStringArray(config.get(ReplicationTransportConstants.ENDPOINTS), new String[0]);
 
         pollItems = PropertiesUtil.toInteger(config.get(POLL_ITEMS), 1);
 
-        String endpointStrategyName = PropertiesUtil.toString(config.get(ReplicationAgentConfiguration.ENDPOINT_STRATEGY), "One");
+        String endpointStrategyName = PropertiesUtil.toString(config.get(ReplicationTransportConstants.ENDPOINT_STRATEGY), "One");
         TransportEndpointStrategyType transportEndpointStrategyType = TransportEndpointStrategyType.valueOf(endpointStrategyName);
 
         List<ReplicationTransportHandler> transportHandlers = new ArrayList<ReplicationTransportHandler>();

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/importer/AdvancedRemoteReplicationPackageImporter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/importer/AdvancedRemoteReplicationPackageImporter.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/importer/AdvancedRemoteReplicationPackageImporter.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/importer/AdvancedRemoteReplicationPackageImporter.java Mon Aug 11 12:58:53 2014
@@ -26,7 +26,6 @@ import java.util.Map;
 import org.apache.felix.scr.annotations.*;
 import org.apache.http.client.fluent.Executor;
 import org.apache.sling.commons.osgi.PropertiesUtil;
-import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
 import org.apache.sling.replication.communication.ReplicationEndpoint;
 import org.apache.sling.replication.event.ReplicationEventFactory;
 import org.apache.sling.replication.serialization.ReplicationPackage;
@@ -37,6 +36,7 @@ import org.apache.sling.replication.tran
 import org.apache.sling.replication.transport.authentication.TransportAuthenticationProviderFactory;
 import org.apache.sling.replication.transport.impl.AdvancedHttpReplicationTransportHandler;
 import org.apache.sling.replication.transport.impl.MultipleEndpointReplicationTransportHandler;
+import org.apache.sling.replication.transport.impl.ReplicationTransportConstants;
 import org.apache.sling.replication.transport.impl.TransportEndpointStrategyType;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
@@ -52,7 +52,7 @@ public class AdvancedRemoteReplicationPa
 
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    @Property(name = ReplicationAgentConfiguration.TRANSPORT_AUTHENTICATION_FACTORY)
+    @Property(name = ReplicationTransportConstants.TRANSPORT_AUTHENTICATION_FACTORY)
     @Reference(name = "TransportAuthenticationProviderFactory", policy = ReferencePolicy.DYNAMIC)
     private TransportAuthenticationProviderFactory transportAuthenticationProviderFactory;
 
@@ -65,7 +65,7 @@ public class AdvancedRemoteReplicationPa
             )},
             value = "One"
     )
-    private static final String ENDPOINT_STRATEGY = ReplicationAgentConfiguration.ENDPOINT_STRATEGY;
+    private static final String ENDPOINT_STRATEGY = ReplicationTransportConstants.ENDPOINT_STRATEGY;
 
     @Property(boolValue = false)
     private static final String USE_CUSTOM_HEADERS = "useCustomHeaders";
@@ -89,13 +89,12 @@ public class AdvancedRemoteReplicationPa
     @Activate
     protected void activate(BundleContext context, Map<String, ?> config) throws Exception {
 
-        Map<String, String> authenticationProperties = PropertiesUtil.toMap(config.get(ReplicationAgentConfiguration.AUTHENTICATION_PROPERTIES),
-                new String[0]);
+        Map<String, String> authenticationProperties = PropertiesUtil.toMap(config.get(ReplicationTransportConstants.AUTHENTICATION_PROPERTIES), new String[0]);
 
         TransportAuthenticationProvider<Executor, Executor> transportAuthenticationProvider = (TransportAuthenticationProvider<Executor, Executor>)
                 transportAuthenticationProviderFactory.createAuthenticationProvider(authenticationProperties);
-        String[] endpoints = PropertiesUtil.toStringArray(config.get(ReplicationAgentConfiguration.ENDPOINT), new String[0]);
-        String endpointStrategyName = PropertiesUtil.toString(config.get(ReplicationAgentConfiguration.ENDPOINT_STRATEGY),
+        String[] endpoints = PropertiesUtil.toStringArray(config.get(ReplicationTransportConstants.ENDPOINTS), new String[0]);
+        String endpointStrategyName = PropertiesUtil.toString(config.get(ReplicationTransportConstants.ENDPOINT_STRATEGY),
                 TransportEndpointStrategyType.One.name());
         TransportEndpointStrategyType transportEndpointStrategyType = TransportEndpointStrategyType.valueOf(endpointStrategyName);
 

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/importer/RemoteReplicationPackageImporter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/importer/RemoteReplicationPackageImporter.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/importer/RemoteReplicationPackageImporter.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/importer/RemoteReplicationPackageImporter.java Mon Aug 11 12:58:53 2014
@@ -26,7 +26,6 @@ import java.util.Map;
 import org.apache.felix.scr.annotations.*;
 import org.apache.http.client.fluent.Executor;
 import org.apache.sling.commons.osgi.PropertiesUtil;
-import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
 import org.apache.sling.replication.communication.ReplicationEndpoint;
 import org.apache.sling.replication.event.ReplicationEventFactory;
 import org.apache.sling.replication.serialization.ReplicationPackage;
@@ -36,6 +35,7 @@ import org.apache.sling.replication.tran
 import org.apache.sling.replication.transport.authentication.TransportAuthenticationProvider;
 import org.apache.sling.replication.transport.authentication.TransportAuthenticationProviderFactory;
 import org.apache.sling.replication.transport.impl.MultipleEndpointReplicationTransportHandler;
+import org.apache.sling.replication.transport.impl.ReplicationTransportConstants;
 import org.apache.sling.replication.transport.impl.SimpleHttpReplicationTransportHandler;
 import org.apache.sling.replication.transport.impl.TransportEndpointStrategyType;
 import org.osgi.framework.BundleContext;
@@ -51,7 +51,7 @@ public class RemoteReplicationPackageImp
 
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    @Property(name = ReplicationAgentConfiguration.TRANSPORT_AUTHENTICATION_FACTORY)
+    @Property(name = ReplicationTransportConstants.TRANSPORT_AUTHENTICATION_FACTORY)
     @Reference(name = "TransportAuthenticationProviderFactory", policy = ReferencePolicy.DYNAMIC)
     private TransportAuthenticationProviderFactory transportAuthenticationProviderFactory;
 
@@ -64,7 +64,7 @@ public class RemoteReplicationPackageImp
             )},
             value = "One"
     )
-    private static final String ENDPOINT_STRATEGY = ReplicationAgentConfiguration.ENDPOINT_STRATEGY;
+    private static final String ENDPOINT_STRATEGY = ReplicationTransportConstants.ENDPOINT_STRATEGY;
 
     @Reference
     private ReplicationEventFactory replicationEventFactory;
@@ -74,12 +74,12 @@ public class RemoteReplicationPackageImp
     @Activate
     protected void activate(BundleContext context, Map<String, ?> config) throws Exception {
 
-        Map<String, String> authenticationProperties = PropertiesUtil.toMap(config.get(ReplicationAgentConfiguration.AUTHENTICATION_PROPERTIES), new String[0]);
+        Map<String, String> authenticationProperties = PropertiesUtil.toMap(config.get(ReplicationTransportConstants.AUTHENTICATION_PROPERTIES), new String[0]);
 
         TransportAuthenticationProvider<Executor, Executor> transportAuthenticationProvider = (TransportAuthenticationProvider<Executor, Executor>)
                 transportAuthenticationProviderFactory.createAuthenticationProvider(authenticationProperties);
 
-        String[] endpoints = PropertiesUtil.toStringArray(config.get(ReplicationAgentConfiguration.ENDPOINT), new String[0]);
+        String[] endpoints = PropertiesUtil.toStringArray(config.get(ReplicationTransportConstants.ENDPOINTS), new String[0]);
 
         String endpointStrategyName = PropertiesUtil.toString(config.get(ENDPOINT_STRATEGY),
                 TransportEndpointStrategyType.One.name());

Added: sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish-reverse.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish-reverse.json?rev=1617269&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish-reverse.json (added)
+++ sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish-reverse.json Mon Aug 11 12:58:53 2014
@@ -0,0 +1,10 @@
+{
+    "jcr:primaryType" : "sling:OsgiConfig",
+    "name" : "publish-reverse",
+    "ReplicationPackageExporter.target" : "(name=publish)",
+    "ReplicationPackageImporter.target" : "(name=local)",
+    "ReplicationQueueProvider.target" : "(name=sjh)",
+    "ReplicationQueueDistributionStrategy.target" : "(name=error)",
+    "rules" : ["scheduled poll every 30 sec"],
+    "runModes" : ["author"]
+}

Added: sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish.json?rev=1617269&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish.json (added)
+++ sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish.json Mon Aug 11 12:58:53 2014
@@ -0,0 +1,9 @@
+{
+    "jcr:primaryType" : "sling:OsgiConfig",
+    "name" : "publish",
+    "ReplicationPackageExporter.target" : "(name=local)",
+    "ReplicationPackageImporter.target" : "(name=publish)",
+    "ReplicationQueueProvider.target" : "(name=sjh)",
+    "ReplicationQueueDistributionStrategy.target" : "(name=single)",
+    "runModes" : ["author"]
+}

Added: sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-cache-flush.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-cache-flush.json?rev=1617269&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-cache-flush.json (added)
+++ sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-cache-flush.json Mon Aug 11 12:58:53 2014
@@ -0,0 +1,11 @@
+{
+    "jcr:primaryType" : "sling:OsgiConfig",
+    "name" : "cache-flush",
+    "ReplicationPackageImporter.target" : "(name=cache-flush)",
+    "useAggregatePaths" : false,
+    "ReplicationPackageExporter.target" : "(name=void)",
+    "ReplicationQueueDistributionStrategy.target" : "(name=single)",
+    "rules" : ["trigger on path: /content/usergenerated"],
+    "enabled" : false,
+    "runModes" : ["publish"]
+}

Added: sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-reverse.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-reverse.json?rev=1617269&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-reverse.json (added)
+++ sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-reverse.json Mon Aug 11 12:58:53 2014
@@ -0,0 +1,11 @@
+{
+    "jcr:primaryType" : "sling:OsgiConfig",
+    "name" : "reverse",
+    "ReplicationPackageExporter.target" : "(name=local)",
+    "ReplicationPackageImporter.target" : "(name=local)",
+    "ReplicationQueueProvider.target" : "(name=sjh)",
+    "ReplicationQueueDistributionStrategy.target" : "(name=error)",
+    "rules" : ["trigger on path: /content/usergenerated"],
+    "runModes" : ["publish"],
+    "isPassive" : true
+}

Modified: sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/resourceproviders/configs/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-agentsConfig.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/resourceproviders/configs/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-agentsConfig.json?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/resourceproviders/configs/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-agentsConfig.json (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/resourceproviders/configs/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-agentsConfig.json Mon Aug 11 12:58:53 2014
@@ -2,7 +2,7 @@
     "jcr:primaryType" : "sling:OsgiConfig",
     "name" : "replicationAgentsConfig",
     "provider.roots" : [ "/libs/sling/replication/config/agents" ],
-    "serviceType" : "org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory",
+    "serviceType" : "org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory",
     "providerType" : "osgiConfig",
     "resourceProperties" : [
         "sling:resourceType=replication/config/agent",

Added: sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactoryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactoryTest.java?rev=1617269&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactoryTest.java (added)
+++ sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactoryTest.java Mon Aug 11 12:58:53 2014
@@ -0,0 +1,86 @@
+/*
+ * 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.apache.sling.replication.agent.impl;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.replication.queue.ReplicationQueueDistributionStrategy;
+import org.apache.sling.replication.queue.ReplicationQueueProvider;
+import org.apache.sling.replication.serialization.ReplicationPackageExporter;
+import org.apache.sling.replication.serialization.ReplicationPackageImporter;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Testcase for {@link SimpleReplicationAgentFactory}
+ */
+public class SimpleReplicationAgentFactoryTest {
+
+    @Test
+    public void testActivationWithAllServicesAndPropertiesBound() throws Exception {
+        SimpleReplicationAgentFactory serviceFactory = new SimpleReplicationAgentFactory();
+
+        Field packageImporterField = serviceFactory.getClass().getDeclaredField("packageImporter");
+        packageImporterField.setAccessible(true);
+        ReplicationPackageImporter packageImporter = mock(ReplicationPackageImporter.class);
+        packageImporterField.set(serviceFactory, packageImporter);
+
+
+        Field packageExporterField = serviceFactory.getClass().getDeclaredField("packageExporter");
+        packageExporterField.setAccessible(true);
+        ReplicationPackageExporter packageExporter = mock(ReplicationPackageExporter.class);
+        packageExporterField.set(serviceFactory, packageExporter);
+
+
+        Field distributionField = serviceFactory.getClass().getDeclaredField("queueDistributionStrategy");
+        distributionField.setAccessible(true);
+        ReplicationQueueDistributionStrategy distributionStrategy = mock(ReplicationQueueDistributionStrategy.class);
+        distributionField.set(serviceFactory, distributionStrategy);
+
+        Field queueField = serviceFactory.getClass().getDeclaredField("queueProvider");
+        queueField.setAccessible(true);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        queueField.set(serviceFactory, queueProvider);
+
+
+        Map<String, Object> dictionary = new HashMap<String, Object>();
+        dictionary.put("endpoint", "http://somewhere.com");
+        dictionary.put("name", "agent1");
+        BundleContext context = mock(BundleContext.class);
+        serviceFactory.activate(context, dictionary);
+    }
+
+    @Test
+    public void testActivationWithNoServicesBound() throws Exception {
+        try {
+            SimpleReplicationAgentFactory serviceFactory = new SimpleReplicationAgentFactory();
+            Map<String, Object> dictionary = new HashMap<String, Object>();
+            BundleContext context = mock(BundleContext.class);
+            serviceFactory.activate(context, dictionary);
+            fail("missing / incomplete configuration should trigger agent configuration exception");
+        } catch (Exception e) {
+            // expected
+        }
+    }
+}

Propchange: sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentTest.java?rev=1617269&r1=1617268&r2=1617269&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentTest.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentTest.java Mon Aug 11 12:58:53 2014
@@ -113,7 +113,7 @@ public class SimpleReplicationAgentTest 
         when(packageExporter.exportPackage(request)).thenReturn(Arrays.asList(new ReplicationPackage[] { replicationPackage } ));
         when(queueProvider.getDefaultQueue(agent.getName())).thenReturn(
                 new SimpleReplicationQueue(agent.getName(), "name"));
-        agent.send(request);
+        agent.execute(request);
     }
 
     @Test



Mime
View raw message