incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1549567 [1/5] - in /sling/trunk/contrib/extensions/replication: ./ src/main/java/org/apache/sling/replication/agent/ src/main/java/org/apache/sling/replication/agent/impl/ src/main/java/org/apache/sling/replication/communication/ src/main/...
Date Mon, 09 Dec 2013 13:37:50 GMT
Author: bdelacretaz
Date: Mon Dec  9 13:37:48 2013
New Revision: 1549567

URL: http://svn.apache.org/r1549567
Log:
Apply SLING-3265.2.patch, contributed by Tommaso Teofili, thanks! Such a large patch is unusual, ok here as it takes into account a number of issues raised during the donation review

Added:
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentsManager.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentQueueResource.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationHeader.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRule.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/impl/DefaultReplicationRuleEngine.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageReadingException.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/DefaultReplicationPackageBuilderProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/VoidReplicationPackage.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationQueueServlet.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/TransportAuthenticationContext.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/TransportAuthenticationException.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/TransportAuthenticationProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/TransportAuthenticationProviderFactory.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopTransportAuthenticationProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopTransportAuthenticationProviderFactory.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryTransportAuthenticationProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryTransportAuthenticationProviderFactory.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsTransportAuthenticationProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsTransportAuthenticationProviderFactory.java
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config.author/
    sling/trunk/contrib/extensions/replication/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/src/main/resources/SLING-CONTENT/libs/sling/replication/config.author/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish.json
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config.publish/
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config.publish/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reversehttp.json
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config.publish/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reverserepo.json
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResourceTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactoryTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/ErrorAwareQueueDistributionStrategyTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/PriorityPathQueueDistributionStrategyTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/SingleQueueDistributionStrategyTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRuleTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/DefaultReplicationRuleEngineTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRuleTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/VoidReplicationPackageTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/NopTransportAuthenticationProviderTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsTransportAuthenticationProviderTest.java
Removed:
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentsManagerImpl.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentImpl.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/ReplicationPackageBuilderProviderImpl.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/VoidReplicationPackage.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationContext.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationException.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandler.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandlerFactory.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandlerProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/DefaultAuthenticationHandlerManager.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandler.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandlerFactory.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryAuthenticationHandler.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryAuthenticationHandlerFactory.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandler.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandlerFactory.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentImplTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandlerTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandlerTest.java
Modified:
    sling/trunk/contrib/extensions/replication/pom.xml
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/AgentConfigurationException.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentsManager.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResource.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentJobConsumer.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResource.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactory.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationActionType.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationResponse.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEvent.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEventFactory.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/impl/DefaultReplicationEventFactory.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/ReplicationQueue.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/ReplicationQueueDistributionStrategy.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/ReplicationQueueException.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/ReplicationQueueItemState.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/ReplicationQueueProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/AbstractReplicationQueueProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/ErrorAwareQueueDistributionStrategy.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/PriorityPathDistributionStrategy.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/SingleQueueDistributionStrategy.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingReplicationQueue.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingReplicationQueueProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingUtils.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/simple/ScheduledReplicationQueueProcessor.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/simple/SimpleReplicationQueue.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/simple/SimpleReplicationQueueProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/ReplicationRule.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/ReplicationRuleEngine.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackage.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuilder.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuilderProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/AbstractReplicationPackageBuilder.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/ReplicationPackageAdapterFactory.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackage.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPollServlet.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPostServlet.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationServlet.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationReceiverServlet.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/ReplicationTransportException.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/TransportHandler.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/HttpTransportHandler.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/PollingTransportHandler.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/RepositoryTransportHandler.java
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish-reverse.json
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish.json
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reversehttp.json
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reverserepo.json
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProviderTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingReplicationQueueTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingUtilsTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/simple/SimpleReplicationQueueTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilderTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/HttpTransportHandlerTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/PollingTransportHandlerTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/RepositoryTransportHandlerTest.java

Modified: sling/trunk/contrib/extensions/replication/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/pom.xml?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/pom.xml (original)
+++ sling/trunk/contrib/extensions/replication/pom.xml Mon Dec  9 13:37:48 2013
@@ -25,7 +25,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>18</version>
+        <version>19-SNAPSHOT</version>
         <relativePath>../../../parent/pom.xml</relativePath>
     </parent>
 
@@ -68,7 +68,7 @@
               <configuration>
                 <instructions>
                   <Bundle-SymbolicName>org.apache.sling.replication</Bundle-SymbolicName>
-                  <Sling-Initial-Content>SLING-CONTENT/libs/sling/replication/agents;path:=/apps/system/config;overwrite:=true</Sling-Initial-Content>
+                  <Sling-Initial-Content>SLING-CONTENT/libs/sling/replication;path:=/apps/system;overwrite:=true</Sling-Initial-Content>
                   <Export-Package>
                     org.apache.sling.replication.agent,
                     org.apache.sling.replication.transport.authentication,
@@ -77,12 +77,12 @@
                     org.apache.sling.replication.event,
                     org.apache.sling.replication.queue,
                     org.apache.sling.replication.rule,
-                    org.apache.sling.replication.serialization,
+                    org.apache.sling.replication.serialization
                   </Export-Package>
                 </instructions>
               </configuration>
             </plugin>
-	        <plugin>
+            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-javadoc-plugin</artifactId>
             </plugin>

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/AgentConfigurationException.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/AgentConfigurationException.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/AgentConfigurationException.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/AgentConfigurationException.java Mon Dec  9 13:37:48 2013
@@ -19,7 +19,7 @@
 package org.apache.sling.replication.agent;
 
 /**
- * represents error happened during agent configuration
+ * Represents errors happened during {@link ReplicationAgent} configuration
  */
 @SuppressWarnings("serial")
 public class AgentConfigurationException extends Exception {

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java Mon Dec  9 13:37:48 2013
@@ -25,19 +25,58 @@ import org.apache.sling.replication.queu
 import org.apache.sling.replication.serialization.ReplicationPackage;
 
 /**
- * A replication agent
+ * A replication agent is responsible for delivering content to another instance
  */
 public interface ReplicationAgent {
 
+    /**
+     * get agent name
+     *
+     * @return the agent name as a <code>String</code>
+     */
     String getName();
 
+    /**
+     * get the agent queue with the given name
+     *
+     * @param name a queue name as a <code>String</code>
+     * @return a {@link ReplicationQueue} with the given name bound to this agent, if it exists, <code>null</code> otherwise
+     * @throws ReplicationQueueException
+     */
     ReplicationQueue getQueue(String name) throws ReplicationQueueException;
 
+    /**
+     * get the rules defined for this {@link ReplicationAgent}
+     *
+     * @return an <code>Array</code> of <code>String</code>s for this agent's rules
+     */
+    String[] getRules();
+
+    /**
+     * execute a {@link ReplicationRequest} against this agent waiting for a {@link ReplicationResponse}
+     *
+     * @param replicationRequest the replication request
+     * @return a {@link ReplicationResponse}
+     * @throws AgentReplicationException
+     */
     ReplicationResponse execute(ReplicationRequest replicationRequest)
-                    throws AgentReplicationException;
+            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;
 
+    /**
+     * process the replication of a certain item
+     *
+     * @param item a {@link ReplicationPackage} to process
+     * @return <code>true</code> if process was successful, <code>false</code> otherwise
+     * @throws AgentReplicationException
+     */
     boolean process(ReplicationPackage item) throws AgentReplicationException;
 
 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java Mon Dec  9 13:37:48 2013
@@ -30,7 +30,7 @@ public class ReplicationAgentConfigurati
 
     public static final String TRANSPORT = "TransportHandler.target";
 
-    public static final String AUTHENTICATION_FACTORY = "AuthenticationHandlerFactory.target";
+    public static final String TRANSPORT_AUTHENTICATION_FACTORY = "TransportAuthenticationProviderFactory.target";
 
     public static final String QUEUEPROVIDER = "ReplicationQueueProvider.target";
 
@@ -44,6 +44,10 @@ public class ReplicationAgentConfigurati
 
     public static final String DISTRIBUTION = "ReplicationQueueDistributionStrategy.target";
 
+    public static final String RULES = "rules";
+
+    public static final String ENABLED = "enabled";
+
     private final String name;
 
     private final String endpoint;
@@ -58,17 +62,20 @@ public class ReplicationAgentConfigurati
 
     private final String[] authenticationProperties;
 
+    private final String[] rules;
+
     public ReplicationAgentConfiguration(Dictionary<?, ?> dictionary) {
         this.name = PropertiesUtil.toString(dictionary.get(NAME), "");
         this.endpoint = PropertiesUtil.toString(dictionary.get(ENDPOINT), "");
         this.targetAuthenticationHandlerFactory = PropertiesUtil.toString(
-                        dictionary.get(AUTHENTICATION_FACTORY), "");
+                        dictionary.get(TRANSPORT_AUTHENTICATION_FACTORY), "");
         this.targetReplicationBuilder = PropertiesUtil.toString(dictionary.get(PACKAGING), "");
         this.targetReplicationQueueProvider = PropertiesUtil.toString(
                         dictionary.get(QUEUEPROVIDER), "");
         this.targetTransportHandler = PropertiesUtil.toString(dictionary.get(TRANSPORT), "");
         String[] ap = PropertiesUtil.toStringArray(dictionary.get(AUTHENTICATION_PROPERTIES));
         this.authenticationProperties = ap != null ? ap : new String[0];
+        this.rules = PropertiesUtil.toStringArray(dictionary.get(RULES), new String[0]);
     }
 
     public String[] getAuthenticationProperties() {
@@ -106,7 +113,8 @@ public class ReplicationAgentConfigurati
                         + targetReplicationBuilder + "\", \"targetReplicationQueueProvider\":\""
                         + targetReplicationQueueProvider + "\", \"targetAuthenticationHandlerFactory\":\""
                         + targetAuthenticationHandlerFactory + "\", \"authenticationProperties\":\""
-                        + Arrays.toString(authenticationProperties) + "\"}";
+                        + Arrays.toString(authenticationProperties) + "\", \"rules\":\""
+                        + Arrays.toString(rules) + "\"}";
     }
 
 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java Mon Dec  9 13:37:48 2013
@@ -21,14 +21,29 @@ package org.apache.sling.replication.age
 import java.util.Map;
 
 /**
- * Facade class for dealing with {@link ReplicationAgent}'s {@link ReplicationConfiguration}s
+ * Facade class for dealing with {@link ReplicationAgent}s' {@link ReplicationAgentConfiguration}s
  */
 public interface ReplicationAgentConfigurationManager {
 
+    /**
+     * retrieve a {@link ReplicationAgentConfiguration} for a given {@link ReplicationAgent}
+     *
+     * @param replicationAgent a {@link ReplicationAgent}
+     * @return a {@link ReplicationAgentConfiguration} for the given agent
+     * @throws AgentConfigurationException
+     */
     ReplicationAgentConfiguration getConfiguration(ReplicationAgent replicationAgent)
-                    throws AgentConfigurationException;
+            throws AgentConfigurationException;
 
+    /**
+     * updates the {@link ReplicationAgentConfiguration} of a certain {@link ReplicationAgent}
+     *
+     * @param agent      a {@link ReplicationAgent}
+     * @param properties a {@link Map} of properties used to update the configuration
+     * @return the updated {@link ReplicationAgentConfiguration} for the given agent
+     * @throws AgentConfigurationException
+     */
     ReplicationAgentConfiguration updateConfiguration(ReplicationAgent agent,
-                    Map<String, Object> properties) throws AgentConfigurationException;
+                                                      Map<String, Object> properties) throws AgentConfigurationException;
 
 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentsManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentsManager.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentsManager.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentsManager.java Mon Dec  9 13:37:48 2013
@@ -18,8 +18,8 @@
  */
 package org.apache.sling.replication.agent;
 
+import java.util.Collection;
 import java.util.SortedSet;
-
 import org.apache.sling.replication.communication.ReplicationActionType;
 
 /**
@@ -27,6 +27,19 @@ import org.apache.sling.replication.comm
  */
 public interface ReplicationAgentsManager {
 
+    /**
+     * get agents which can handle the given action on the given paths
+     *
+     * @param action a {@link ReplicationActionType}
+     * @param paths  the paths such agents should be able to handle
+     * @return a {@link SortedSet} of {@link ReplicationAgent}s
+     */
     SortedSet<ReplicationAgent> getAgentsFor(ReplicationActionType action, String... paths);
 
+    /**
+     * get all the agents registered and active in the system
+     *
+     * @return a <code>Collection</code> of {@link ReplicationAgent}s
+     */
+    Collection<ReplicationAgent> getAllAvailableAgents();
 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java Mon Dec  9 13:37:48 2013
@@ -50,10 +50,13 @@ public class DefaultReplicationAgentConf
     public ReplicationAgentConfiguration getConfiguration(ReplicationAgent replicationAgent)
                     throws AgentConfigurationException {
         if (log.isInfoEnabled()) {
-            log.info("retrieving configuration for agent ", replicationAgent);
+            log.info("retrieving configuration for agent {}", replicationAgent);
         }
         try {
             Configuration configuration = getOsgiConfiguration(replicationAgent);
+            if (log.isInfoEnabled()) {
+                log.info("configuration for agent {} found {}", replicationAgent, configuration);
+            }
             return new ReplicationAgentConfiguration(configuration.getProperties());
 
         } catch (Exception e) {
@@ -65,8 +68,8 @@ public class DefaultReplicationAgentConf
     }
 
     private Configuration getOsgiConfiguration(ReplicationAgent replicationAgent) throws Exception {
-        String filter = new StringBuilder("(name=").append(replicationAgent.getName()).append(")")
-                        .toString();
+
+        String filter = "(name=" + replicationAgent.getName() + ")";
         Configuration[] configurations = configAdmin.listConfigurations(filter);
         if (configurations == null) {
           throw new Exception("no configuration found");
@@ -92,7 +95,11 @@ public class DefaultReplicationAgentConf
             @SuppressWarnings("unchecked")
             Dictionary<String, Object> configurationProperties = configuration.getProperties();
             for (Map.Entry<String, Object> entry : updateProperties.entrySet()) {
-                configurationProperties.put(entry.getKey(), entry.getValue());
+                String key = entry.getKey();
+                if (key.startsWith("X-replication-")) {
+                    key = key.substring(0, 14);
+                }
+                configurationProperties.put(key, entry.getValue());
             }
             configuration.update(configurationProperties);
             return new ReplicationAgentConfiguration(configuration.getProperties());

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentsManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentsManager.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentsManager.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentsManager.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,94 @@
+/*
+ * 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.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.References;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.agent.ReplicationAgentsManager;
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default implementation of {@link ReplicationAgentsManager}
+ */
+@Component
+@References({
+        @Reference(name = "replicationAgent",
+                referenceInterface = ReplicationAgent.class,
+                cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
+                policy = ReferencePolicy.DYNAMIC,
+                bind = "bindReplicationAgent",
+                unbind = "unbindReplicationAgent")
+})
+@Service(value = ReplicationAgentsManager.class)
+public class DefaultReplicationAgentsManager implements ReplicationAgentsManager {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final SortedSet<ReplicationAgent> replicationAgents = new TreeSet<ReplicationAgent>(new ReplicationAgentComparator());
+
+    public SortedSet<ReplicationAgent> getAgentsFor(ReplicationActionType action, String... paths) {
+        // TODO : implement the filtering based on rules here
+        return Collections.unmodifiableSortedSet(replicationAgents);
+    }
+
+    public Collection<ReplicationAgent> getAllAvailableAgents() {
+        return Collections.unmodifiableCollection(replicationAgents);
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        replicationAgents.clear();
+    }
+
+    protected void bindReplicationAgent(final ReplicationAgent replicationAgent,
+                                        Map<String, Object> properties) {
+        synchronized (replicationAgents) {
+            replicationAgents.add(replicationAgent);
+        }
+        log.debug("Registering replication agent {} ", replicationAgent);
+    }
+
+    protected void unbindReplicationAgent(final ReplicationAgent replicationAgent,
+                                          Map<String, Object> properties) {
+        synchronized (replicationAgents) {
+            replicationAgents.remove(replicationAgent);
+        }
+        log.debug("Unregistering replication agent {} ", replicationAgent);
+    }
+
+    private final class ReplicationAgentComparator implements Comparator<ReplicationAgent> {
+        public int compare(ReplicationAgent o1, ReplicationAgent o2) {
+            return o1.getName().compareTo(o2.getName());
+        }
+    }
+}

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResource.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResource.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResource.java Mon Dec  9 13:37:48 2013
@@ -25,27 +25,29 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
 
 /**
- * a {@Resource} for a {@link ReplicationAgentConfiguration}
+ * a {@link org.apache.sling.api.resource.Resource} for a {@link ReplicationAgentConfiguration}
  */
 public class ReplicationAgentConfigurationResource extends AbstractResource {
 
     public static final String RESOURCE_TYPE = "sling/replication/agent/configuration";
 
-    private ReplicationAgentConfiguration replicationAgentConfiguration;
 
-    private ResourceResolver resourceResolver;
+    private final ReplicationAgentConfiguration replicationAgentConfiguration;
+
+    private final ResourceResolver resourceResolver;
 
     public ReplicationAgentConfigurationResource(
                     ReplicationAgentConfiguration replicationAgentConfiguration,
                     ResourceResolver resourceResolver) {
+        if (replicationAgentConfiguration == null) {
+            throw new RuntimeException("cannot create a configuration resource with a null configuration");
+        }
         this.replicationAgentConfiguration = replicationAgentConfiguration;
         this.resourceResolver = resourceResolver;
     }
 
     public String getPath() {
-        return new StringBuilder(ReplicationAgentResource.BASE_PATH).append('/')
-                        .append(replicationAgentConfiguration.getName()).append("/configuration")
-                        .toString();
+        return ReplicationAgentResource.BASE_PATH + '/' + replicationAgentConfiguration.getName() + "/configuration";
     }
 
     public String getResourceType() {
@@ -58,8 +60,7 @@ public class ReplicationAgentConfigurati
 
     public ResourceMetadata getResourceMetadata() {
         ResourceMetadata metadata = new ResourceMetadata();
-        metadata.setResolutionPath(new StringBuilder(ReplicationAgentResource.BASE_PATH)
-                        .append('/').append(replicationAgentConfiguration.getName()).toString());
+        metadata.setResolutionPath(ReplicationAgentResource.BASE_PATH + '/' + replicationAgentConfiguration.getName());
         return metadata;
     }
 

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentJobConsumer.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentJobConsumer.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentJobConsumer.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentJobConsumer.java Mon Dec  9 13:37:48 2013
@@ -30,15 +30,15 @@ import org.apache.sling.replication.seri
 import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
 
 /**
- * {@JobConsumer} for {@link ReplicationAgent}s using {@link org.apache.sling.replication.queue.impl.jobhandling.JobHandlingReplicationQueue}
+ * {@link JobConsumer} for {@link ReplicationAgent}s using {@link org.apache.sling.replication.queue.impl.jobhandling.JobHandlingReplicationQueue}
  */
 public class ReplicationAgentJobConsumer implements JobConsumer {
 
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private ReplicationAgent agent;
+    private final ReplicationAgent agent;
 
-    private ReplicationPackageBuilder packageBuilder;
+    private final ReplicationPackageBuilder packageBuilder;
 
     public ReplicationAgentJobConsumer(ReplicationAgent agent,
                     ReplicationPackageBuilder packageBuilder) {

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentQueueResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentQueueResource.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentQueueResource.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentQueueResource.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,75 @@
+/*
+ * 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 org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.replication.queue.ReplicationQueue;
+
+/**
+ * A {@link org.apache.sling.api.resource.Resource} for {@link ReplicationQueue}s
+ */
+public class ReplicationAgentQueueResource extends AbstractResource {
+
+    public static final String RESOURCE_TYPE = "sling/replication/agent/queue";
+
+    private final ReplicationQueue queue;
+
+    private final ResourceResolver resourceResolver;
+
+    public ReplicationAgentQueueResource(
+            ReplicationQueue queue,
+            ResourceResolver resourceResolver) {
+        this.queue = queue;
+        this.resourceResolver = resourceResolver;
+    }
+
+    public String getPath() {
+        return ReplicationAgentResource.BASE_PATH + '/' + queue.getName() + "/queue";
+    }
+
+    public String getResourceType() {
+        return RESOURCE_TYPE;
+    }
+
+    public String getResourceSuperType() {
+        return null;
+    }
+
+    public ResourceMetadata getResourceMetadata() {
+        ResourceMetadata metadata = new ResourceMetadata();
+        metadata.setResolutionPath(ReplicationAgentResource.BASE_PATH + '/' + queue.getName());
+        return metadata;
+    }
+
+    public ResourceResolver getResourceResolver() {
+        return resourceResolver;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+        if (ReplicationQueue.class == type) {
+            return (AdapterType) queue;
+        } else {
+            return super.adaptTo(type);
+        }
+    }
+}
\ No newline at end of file

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResource.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResource.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResource.java Mon Dec  9 13:37:48 2013
@@ -25,7 +25,7 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.replication.agent.ReplicationAgent;
 
 /**
- * a {@link ReplicationAgent} {@link org.apache.sling.api.resource.Resource}
+ * a {@link ReplicationAgent} {@link org.apache.sling.api.resource.Resource}
  */
 public class ReplicationAgentResource extends AbstractResource {
 
@@ -39,13 +39,15 @@ public class ReplicationAgentResource ex
 
     public ReplicationAgentResource(ReplicationAgent replicationAgent,
                     ResourceResolver resourceResolver) {
+        if (replicationAgent == null) {
+            throw new RuntimeException("cannot create an agent resource with a null agent");
+        }
         this.replicationAgent = replicationAgent;
         this.resourceResolver = resourceResolver;
     }
 
     public String getPath() {
-        return new StringBuilder(BASE_PATH).append('/').append(replicationAgent.getName())
-                        .toString();
+        return BASE_PATH + '/' + replicationAgent.getName();
     }
 
     public String getResourceType() {

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProvider.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProvider.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProvider.java Mon Dec  9 13:37:48 2013
@@ -19,9 +19,7 @@
 package org.apache.sling.replication.agent.impl;
 
 import java.util.Iterator;
-
 import javax.servlet.http.HttpServletRequest;
-
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -30,6 +28,11 @@ import org.apache.felix.scr.annotations.
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
+
+import org.apache.sling.replication.agent.AgentConfigurationException;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
+import org.apache.sling.replication.agent.ReplicationAgentConfigurationManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
@@ -51,6 +54,8 @@ public class ReplicationAgentResourcePro
 
     private static final String CONFIGURATION_PATH = "/configuration";
 
+    private static final String QUEUE_PATH = "/queue";
+
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     private BundleContext context;
@@ -67,7 +72,7 @@ public class ReplicationAgentResourcePro
 
     @Deprecated
     public Resource getResource(ResourceResolver resourceResolver, HttpServletRequest request,
-                    String path) {
+                                String path) {
         return getResource(resourceResolver, path);
     }
 
@@ -80,26 +85,43 @@ public class ReplicationAgentResourcePro
                 log.info("resolving configuration for agent {}", agentPath);
             }
             ReplicationAgent replicationAgent = getAgentAtPath(agentPath);
-            ServiceReference configurationManagerServiceReference = context
-                            .getServiceReference(ReplicationAgentConfigurationManager.class
-                                            .getName());
-            if (configurationManagerServiceReference != null) {
-                ReplicationAgentConfigurationManager agentConfigurationManager = (ReplicationAgentConfigurationManager) context
-                                .getService(configurationManagerServiceReference);
-                ReplicationAgentConfiguration configuration;
-                try {
-                    configuration = agentConfigurationManager
-                                    .getConfiguration(replicationAgent);
-                    resource = new ReplicationAgentConfigurationResource(configuration,
-                                    resourceResolver);
-                } catch (AgentConfigurationException e) {
+            if (replicationAgent != null) {
+                ServiceReference configurationManagerServiceReference = context
+                        .getServiceReference(ReplicationAgentConfigurationManager.class
+                                .getName());
+                if (configurationManagerServiceReference != null) {
+                    ReplicationAgentConfigurationManager agentConfigurationManager = (ReplicationAgentConfigurationManager) context
+                            .getService(configurationManagerServiceReference);
+                    ReplicationAgentConfiguration configuration;
+                    try {
+                        configuration = agentConfigurationManager
+                                .getConfiguration(replicationAgent);
+                        resource = new ReplicationAgentConfigurationResource(configuration,
+                                resourceResolver);
+                    } catch (AgentConfigurationException e) {
+                        if (log.isWarnEnabled()) {
+                            log.warn("could not find a configuration", e);
+                        }
+                    }
+                } else {
                     if (log.isWarnEnabled()) {
-                        log.warn("could not find a configuration", e);
+                        log.warn("could not find a configuration manager service");
                     }
                 }
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn("could not find a configuration manager service");
+            }
+        } else if (path.endsWith(QUEUE_PATH)) {
+            String agentPath = path.substring(0, path.lastIndexOf(QUEUE_PATH));
+            if (log.isInfoEnabled()) {
+                log.info("resolving queue for agent {}", agentPath);
+            }
+            ReplicationAgent replicationAgent = getAgentAtPath(agentPath);
+            if (replicationAgent != null) {
+                try {
+                    resource = new ReplicationAgentQueueResource(replicationAgent.getQueue(null), resourceResolver);
+                } catch (Exception e) {
+                    if (log.isWarnEnabled()) {
+                        log.warn("could not find a queue for agent {}", replicationAgent.getName());
+                    }
                 }
             }
         } else {
@@ -108,7 +130,7 @@ public class ReplicationAgentResourcePro
             }
             ReplicationAgent replicationAgent = getAgentAtPath(path);
             resource = replicationAgent != null ? new ReplicationAgentResource(replicationAgent,
-                            resourceResolver) : null;
+                    resourceResolver) : null;
         }
         if (log.isInfoEnabled()) {
             log.info("resource found: {}", resource != null ? resource.getPath() : "none");
@@ -125,11 +147,11 @@ public class ReplicationAgentResourcePro
         ServiceReference[] replicationAgentReferences;
         try {
             replicationAgentReferences = context.getServiceReferences(
-                            ReplicationAgent.class.getName(),
-                            new StringBuilder("(name=").append(agentName).append(")").toString());
+                    ReplicationAgent.class.getName(),
+                    "(name=" + agentName + ")");
             if (replicationAgentReferences != null && replicationAgentReferences.length == 1) {
                 replicationAgent = (ReplicationAgent) context
-                                .getService(replicationAgentReferences[0]);
+                        .getService(replicationAgentReferences[0]);
                 if (log.isDebugEnabled()) {
                     log.debug("replication agent found: {}", replicationAgent);
                 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactory.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactory.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactory.java Mon Dec  9 13:37:48 2013
@@ -22,7 +22,6 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Random;
-
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
@@ -32,6 +31,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.ReferencePolicy;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.event.jobs.consumer.JobConsumer;
+import org.apache.sling.replication.agent.AgentConfigurationException;
 import org.apache.sling.replication.agent.ReplicationAgent;
 import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
 import org.apache.sling.replication.queue.ReplicationQueueDistributionStrategy;
@@ -39,12 +39,13 @@ import org.apache.sling.replication.queu
 import org.apache.sling.replication.queue.impl.SingleQueueDistributionStrategy;
 import org.apache.sling.replication.queue.impl.jobhandling.JobHandlingReplicationQueue;
 import org.apache.sling.replication.queue.impl.jobhandling.JobHandlingReplicationQueueProvider;
+import org.apache.sling.replication.rule.ReplicationRuleEngine;
 import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
 import org.apache.sling.replication.serialization.impl.vlt.FileVaultReplicationPackageBuilder;
 import org.apache.sling.replication.transport.TransportHandler;
-import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
-import org.apache.sling.replication.transport.authentication.AuthenticationHandlerFactory;
-import org.apache.sling.replication.transport.authentication.impl.UserCredentialsAuthenticationHandlerFactory;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationProvider;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationProviderFactory;
+import org.apache.sling.replication.transport.authentication.impl.UserCredentialsTransportAuthenticationProviderFactory;
 import org.apache.sling.replication.transport.impl.HttpTransportHandler;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -54,13 +55,13 @@ 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 = ReplicationAgentServiceFactory.SERVICE_PID, 
-    configurationFactory = true, 
-    specVersion = "1.1", 
-    policy = ConfigurationPolicy.REQUIRE
+@Component(metatype = true,
+        label = "Replication Agents Factory",
+        description = "OSGi configuration based ReplicationAgent service factory",
+        name = ReplicationAgentServiceFactory.SERVICE_PID,
+        configurationFactory = true,
+        specVersion = "1.1",
+        policy = ConfigurationPolicy.REQUIRE
 )
 public class ReplicationAgentServiceFactory {
 
@@ -70,7 +71,7 @@ public class ReplicationAgentServiceFact
 
     private static final String TRANSPORT = ReplicationAgentConfiguration.TRANSPORT;
 
-    private static final String AUTHENTICATION_FACTORY = ReplicationAgentConfiguration.AUTHENTICATION_FACTORY;
+    private static final String TRANSPORT_AUTHENTICATION_FACTORY = ReplicationAgentConfiguration.TRANSPORT_AUTHENTICATION_FACTORY;
 
     private static final String QUEUEPROVIDER = ReplicationAgentConfiguration.QUEUEPROVIDER;
 
@@ -80,18 +81,21 @@ public class ReplicationAgentServiceFact
 
     private static final String DEFAULT_TRANSPORT = "(name=" + HttpTransportHandler.NAME + ")";
 
-    private static final String DEFAULT_AUTHENTICATION_FACTORY = "(name=" + UserCredentialsAuthenticationHandlerFactory.TYPE + ")";
+    private static final String DEFAULT_AUTHENTICATION_FACTORY = "(name=" + UserCredentialsTransportAuthenticationProviderFactory.TYPE + ")";
 
     private static final String DEFAULT_ENDPOINT = "http://localhost:4503/system/replication/receive";
 
     private static final String DEFAULT_PACKAGING = "(name="
-                    + FileVaultReplicationPackageBuilder.NAME + ")";
+            + FileVaultReplicationPackageBuilder.NAME + ")";
 
     private static final String DEFAULT_QUEUEPROVIDER = "(name="
-                    + JobHandlingReplicationQueueProvider.NAME + ")";
+            + JobHandlingReplicationQueueProvider.NAME + ")";
 
     private static final String DEFAULT_DISTRIBUTION = "(name="
-                    + SingleQueueDistributionStrategy.NAME + ")";
+            + SingleQueueDistributionStrategy.NAME + ")";
+
+    @Property(boolValue = true)
+    private static final String ENABLED = ReplicationAgentConfiguration.ENABLED;
 
     @Property
     private static final String NAME = ReplicationAgentConfiguration.NAME;
@@ -102,6 +106,9 @@ public class ReplicationAgentServiceFact
     @Property
     private static final String AUTHENTICATION_PROPERTIES = ReplicationAgentConfiguration.AUTHENTICATION_PROPERTIES;
 
+    @Property
+    private static final String RULES = ReplicationAgentConfiguration.RULES;
+
     @Property(name = TRANSPORT, value = DEFAULT_TRANSPORT)
     @Reference(name = "TransportHandler", target = DEFAULT_TRANSPORT, policy = ReferencePolicy.DYNAMIC)
     private TransportHandler transportHandler;
@@ -114,85 +121,111 @@ public class ReplicationAgentServiceFact
     @Reference(name = "ReplicationQueueProvider", target = DEFAULT_QUEUEPROVIDER, policy = ReferencePolicy.DYNAMIC)
     private ReplicationQueueProvider queueProvider;
 
-    @Property(name = AUTHENTICATION_FACTORY, value = DEFAULT_AUTHENTICATION_FACTORY)
-    @Reference(name = "AuthenticationHandlerFactory", target = DEFAULT_AUTHENTICATION_FACTORY, policy = ReferencePolicy.DYNAMIC)
-    private AuthenticationHandlerFactory authenticationHandlerFactory;
+    @Property(name = TRANSPORT_AUTHENTICATION_FACTORY, value = DEFAULT_AUTHENTICATION_FACTORY)
+    @Reference(name = "TransportAuthenticationProviderFactory", target = DEFAULT_AUTHENTICATION_FACTORY, policy = ReferencePolicy.DYNAMIC)
+    private TransportAuthenticationProviderFactory transportAuthenticationProviderFactory;
 
     @Property(name = DISTRIBUTION, value = DEFAULT_DISTRIBUTION)
     @Reference(name = "ReplicationQueueDistributionStrategy", target = DEFAULT_DISTRIBUTION, policy = ReferencePolicy.DYNAMIC)
     private ReplicationQueueDistributionStrategy queueDistributionStrategy;
-    
+
     private ServiceRegistration agentReg;
 
     private ServiceRegistration jobReg;
 
+    @Reference
+    private ReplicationRuleEngine replicationRuleEngine;
+
     @Activate
     public void activate(BundleContext context, Map<String, ?> config) throws Exception {
+
         // inject configuration
         Dictionary<String, Object> props = new Hashtable<String, Object>();
 
-        String name = PropertiesUtil
-                        .toString(config.get(NAME), String.valueOf(new Random().nextInt(1000)));
-        props.put(NAME, name);
+        boolean enabled = PropertiesUtil.toBoolean(config.get(ENABLED), true);
+        if (enabled) {
+            props.put(ENABLED, enabled);
 
-        String endpoint = PropertiesUtil.toString(config.get(ENDPOINT), DEFAULT_ENDPOINT);
-        props.put(ENDPOINT, endpoint);
+            String name = PropertiesUtil
+                    .toString(config.get(NAME), String.valueOf(new Random().nextInt(1000)));
+            props.put(NAME, name);
 
-        String transport = PropertiesUtil.toString(config.get(TRANSPORT), DEFAULT_TRANSPORT);
-        props.put(TRANSPORT, transport);
+            String endpoint = PropertiesUtil.toString(config.get(ENDPOINT), DEFAULT_ENDPOINT);
+            props.put(ENDPOINT, endpoint);
 
-        String packaging = PropertiesUtil.toString(config.get(PACKAGING), DEFAULT_PACKAGING);
-        props.put(PACKAGING, packaging);
+            String transport = PropertiesUtil.toString(config.get(TRANSPORT), DEFAULT_TRANSPORT);
+            props.put(TRANSPORT, transport);
 
-        String queue = PropertiesUtil.toString(config.get(QUEUEPROVIDER), DEFAULT_QUEUEPROVIDER);
-        props.put(QUEUEPROVIDER, queue);
+            String packaging = PropertiesUtil.toString(config.get(PACKAGING), DEFAULT_PACKAGING);
+            props.put(PACKAGING, packaging);
 
-        String distribution = PropertiesUtil.toString(config.get(DISTRIBUTION), DEFAULT_DISTRIBUTION);
-        props.put(DISTRIBUTION, distribution);
+            String queue = PropertiesUtil.toString(config.get(QUEUEPROVIDER), DEFAULT_QUEUEPROVIDER);
+            props.put(QUEUEPROVIDER, queue);
 
-        Map<String, String> authenticationProperties = PropertiesUtil.toMap(config.get(AUTHENTICATION_PROPERTIES), new String[0]);
-        props.put(AUTHENTICATION_PROPERTIES, authenticationProperties);
+            String distribution = PropertiesUtil.toString(config.get(DISTRIBUTION), DEFAULT_DISTRIBUTION);
+            props.put(DISTRIBUTION, distribution);
 
-        String af = PropertiesUtil.toString(config.get(AUTHENTICATION_FACTORY), DEFAULT_AUTHENTICATION_FACTORY);
-        props.put(AUTHENTICATION_FACTORY, af);
+            Map<String, String> authenticationProperties = PropertiesUtil.toMap(config.get(AUTHENTICATION_PROPERTIES), new String[0]);
+            props.put(AUTHENTICATION_PROPERTIES, authenticationProperties);
 
-        AuthenticationHandler<?, ?> authenticationHandler = authenticationHandlerFactory.createAuthenticationHandler(authenticationProperties);
-        
-        if (!transportHandler.supportsAuthenticationHandler(authenticationHandler)) {
-            throw new Exception("authentication handler " + authenticationHandler
-                            + " not supported by transport handler " + transportHandler);
-        }
-        
+            String[] rules = PropertiesUtil.toStringArray(config.get(RULES), new String[0]);
+            props.put(RULES, rules);
 
-        if (log.isInfoEnabled()) {
-            log.info("bound services for {} :  {} - {} - {} - {} - {}", new Object[] { name,
-                    transportHandler, endpoint, packageBuilder, queueProvider, authenticationHandler });
-        }
+            String af = PropertiesUtil.toString(config.get(TRANSPORT_AUTHENTICATION_FACTORY), DEFAULT_AUTHENTICATION_FACTORY);
+            props.put(TRANSPORT_AUTHENTICATION_FACTORY, af);
+
+            // check configuration is valid
+            if (name == null || transportHandler == null || endpoint == null || packageBuilder == null || queueProvider == null || transportAuthenticationProviderFactory == null || queueDistributionStrategy == null) {
+                throw new AgentConfigurationException("configuration for this agent is not valid");
+            }
 
-        ReplicationAgent agent = new SimpleReplicationAgentImpl(name, endpoint, transportHandler, packageBuilder, queueProvider, authenticationHandler, queueDistributionStrategy);
+            TransportAuthenticationProvider<?, ?> transportAuthenticationProvider = transportAuthenticationProviderFactory.createAuthenticationProvider(authenticationProperties);
 
-        // register agent service
-        agentReg = context.registerService(ReplicationAgent.class.getName(), agent, props);
+            if (!transportHandler.supportsAuthenticationProvider(transportAuthenticationProvider)) {
+                throw new Exception("authentication handler " + transportAuthenticationProvider
+                        + " not supported by transport handler " + transportHandler);
+            }
 
-        // eventually register job consumer for sling job handling based queues
-        if (DEFAULT_QUEUEPROVIDER.equals(queue)){
-            Dictionary<String, Object> jobProps = new Hashtable<String, Object>();
-            String topic = new StringBuilder(JobHandlingReplicationQueue.REPLICATION_QUEUE_TOPIC).append('/')
-                            .append(name).toString();
-            String childTopic = topic+"/*";
-            jobProps.put(JobConsumer.PROPERTY_TOPICS, new String[]{topic, childTopic});
-            jobReg = context.registerService(JobConsumer.class.getName(), new ReplicationAgentJobConsumer(agent, packageBuilder), jobProps);
+            if (log.isInfoEnabled()) {
+                log.info("bound services for {} :  {} - {} - {} - {} - {} - {}", new Object[]{name,
+                        transportHandler, transportAuthenticationProvider, endpoint, packageBuilder, queueProvider, queueDistributionStrategy});
+            }
+
+            ReplicationAgent agent = new SimpleReplicationAgent(name, endpoint, rules, transportHandler, packageBuilder, queueProvider, transportAuthenticationProvider, queueDistributionStrategy);
+
+            // register agent service
+            agentReg = context.registerService(ReplicationAgent.class.getName(), agent, props);
+
+            // apply rules if any
+            if (rules.length > 0) {
+                replicationRuleEngine.applyRules(agent, rules);
+            }
+
+            // eventually register job consumer for sling job handling based queues
+            if (DEFAULT_QUEUEPROVIDER.equals(queue)) {
+                Dictionary<String, Object> jobProps = new Hashtable<String, Object>();
+                String topic = JobHandlingReplicationQueue.REPLICATION_QUEUE_TOPIC + '/' + name;
+                String childTopic = topic + "/*";
+                jobProps.put(JobConsumer.PROPERTY_TOPICS, new String[]{topic, childTopic});
+                jobReg = context.registerService(JobConsumer.class.getName(), new ReplicationAgentJobConsumer(agent, packageBuilder), jobProps);
+            }
         }
     }
 
     @Deactivate
     private void deactivate() {
-        if (agentReg != null) {
-            agentReg.unregister();
+        ReplicationAgent replicationAgent = (ReplicationAgent) agentReg.getReference();
+        String[] rules = replicationAgent.getRules();
+        if (rules != null) {
+            replicationRuleEngine.unapplyRules(replicationAgent, rules);
         }
 
         if (jobReg != null) {
             jobReg.unregister();
         }
+
+        if (agentReg != null) {
+            agentReg.unregister();
+        }
     }
 }

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,161 @@
+/*
+ * 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 org.apache.sling.replication.agent.AgentReplicationException;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.communication.ReplicationEndpoint;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.communication.ReplicationResponse;
+import org.apache.sling.replication.queue.ReplicationQueue;
+import org.apache.sling.replication.queue.ReplicationQueueDistributionStrategy;
+import org.apache.sling.replication.queue.ReplicationQueueException;
+import org.apache.sling.replication.queue.ReplicationQueueItemState;
+import org.apache.sling.replication.queue.ReplicationQueueProvider;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
+import org.apache.sling.replication.serialization.ReplicationPackageBuildingException;
+import org.apache.sling.replication.transport.ReplicationTransportException;
+import org.apache.sling.replication.transport.TransportHandler;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Basic implementation of a {@link ReplicationAgent}
+ */
+public class SimpleReplicationAgent implements ReplicationAgent {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final ReplicationPackageBuilder packageBuilder;
+
+    private final ReplicationQueueProvider queueProvider;
+
+    private final TransportHandler transportHandler;
+
+    private final TransportAuthenticationProvider<?, ?> transportAuthenticationProvider;
+
+    private final ReplicationQueueDistributionStrategy queueDistributionStrategy;
+
+    private final String name;
+
+    private final String endpoint;
+
+    private final String[] rules;
+
+    public SimpleReplicationAgent(String name, String endpoint, String[] rules,
+                                  TransportHandler transportHandler, ReplicationPackageBuilder packageBuilder,
+                                  ReplicationQueueProvider queueProvider,
+                                  TransportAuthenticationProvider<?, ?> transportAuthenticationProvider,
+                                  ReplicationQueueDistributionStrategy queueDistributionHandler) {
+        this.name = name;
+        this.endpoint = endpoint;
+        this.rules = rules;
+        this.transportHandler = transportHandler;
+        this.packageBuilder = packageBuilder;
+        this.queueProvider = queueProvider;
+        this.transportAuthenticationProvider = transportAuthenticationProvider;
+        this.queueDistributionStrategy = queueDistributionHandler;
+    }
+
+    public ReplicationResponse execute(ReplicationRequest replicationRequest)
+            throws AgentReplicationException {
+
+        // create package from request
+        ReplicationPackage replicationPackage;
+        try {
+            replicationPackage = packageBuilder.createPackage(replicationRequest);
+        } catch (ReplicationPackageBuildingException e) {
+            throw new AgentReplicationException(e);
+        }
+
+        ReplicationResponse replicationResponse = new ReplicationResponse();
+
+        // send the replication package to the queue distribution handler
+        try {
+            ReplicationQueueItemState state = queueDistributionStrategy.add(replicationPackage,
+                    this, queueProvider);
+            if (state != null) {
+                replicationResponse.setStatus(state.getItemState().toString());
+                replicationResponse.setSuccessful(state.isSuccessful());
+            } else {
+                replicationResponse.setStatus(ReplicationQueueItemState.ItemState.ERROR.toString());
+            }
+        } catch (Exception e) {
+            if (log.isErrorEnabled()) {
+                log.error("an error happened during queue processing", e);
+            }
+            replicationResponse.setSuccessful(false);
+        }
+
+        return replicationResponse;
+    }
+
+    public void send(ReplicationRequest replicationRequest) throws AgentReplicationException {
+        // create package from request
+        ReplicationPackage replicationPackage;
+        try {
+            replicationPackage = packageBuilder.createPackage(replicationRequest);
+        } catch (ReplicationPackageBuildingException e) {
+            throw new AgentReplicationException(e);
+        }
+        try {
+            queueDistributionStrategy.offer(replicationPackage, this, queueProvider);
+        } catch (ReplicationQueueException e) {
+            throw new AgentReplicationException(e);
+        }
+    }
+
+    public boolean process(ReplicationPackage item) throws AgentReplicationException {
+        try {
+            if (transportHandler != null) {
+                transportHandler.transport(item, new ReplicationEndpoint(endpoint),
+                        transportAuthenticationProvider);
+                return true;
+            } else {
+                if (log.isWarnEnabled()) {
+                    log.warn("could not process an item as a transport handler is not bound to agent {}",
+                            name);
+                }
+                return false;
+            }
+        } catch (ReplicationTransportException e) {
+            throw new AgentReplicationException(e);
+        }
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public ReplicationQueue getQueue(String name) throws ReplicationQueueException {
+        ReplicationQueue queue;
+        if (name != null && name.length() > 0) {
+            queue = queueProvider.getQueue(this, name);
+        } else {
+            queue = queueProvider.getDefaultQueue(this);
+        }
+        return queue;
+    }
+
+    public String[] getRules() {
+        return rules;
+    }
+}

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationActionType.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationActionType.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationActionType.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationActionType.java Mon Dec  9 13:37:48 2013
@@ -25,14 +25,14 @@ package org.apache.sling.replication.com
 public enum ReplicationActionType {
 
     /**
-     * Content is activated
+     * Content is added
      */
-    ACTIVATE("Activate"),
+    ADD("Add"),
 
     /**
-     * Content is deactivated
+     * Content is deleted
      */
-    DEACTIVATE("Deactivate");
+    DELETE("Delete");
 
     /**
      * internal human readable name

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationHeader.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationHeader.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationHeader.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationHeader.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,41 @@
+/*
+ * 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.communication;
+
+/**
+ * HTTP headers {@link Enum} for replication
+ */
+public enum ReplicationHeader {
+
+    TYPE("X-replication-type"),
+    ACTION("X-replication-action"),
+    PATH("X-replication-path"),
+    QUEUE("X-replication-queue");
+
+    private final String name;
+
+    ReplicationHeader(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return name;
+    }
+}

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationResponse.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationResponse.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationResponse.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/communication/ReplicationResponse.java Mon Dec  9 13:37:48 2013
@@ -22,23 +22,23 @@ package org.apache.sling.replication.com
  * A replication response
  */
 public class ReplicationResponse {
-    private boolean successfull;
+    private boolean successful;
 
     private String status;
 
-    public boolean isSuccessfull() {
-        return successfull;
+    public boolean isSuccessful() {
+        return successful;
     }
 
-    public void setSuccessfull(boolean successfull) {
-        this.successfull = successfull;
+    public void setSuccessful(boolean successful) {
+        this.successful = successful;
     }
 
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder();
         sb.append("{\"success\":");
-        sb.append(successfull);
+        sb.append(successful);
         sb.append(", \"status\":\"");
         sb.append(status);
         sb.append("\"}");

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEvent.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEvent.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEvent.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEvent.java Mon Dec  9 13:37:48 2013
@@ -28,7 +28,11 @@ public class ReplicationEvent extends Ev
 
     public static final String EVENT_TOPIC = "org/apache/sling/replication/event";
 
-    public ReplicationEvent(ReplicationEventType type, Dictionary properties) {
-        super(new StringBuilder(EVENT_TOPIC).append(type.toString()).toString(), properties);
+    public ReplicationEvent(ReplicationEventType type, Dictionary<?, ?> properties) {
+        super(getTopic(type), properties);
+    }
+
+    public static String getTopic(ReplicationEventType type) {
+        return EVENT_TOPIC + '/' + type.toString();
     }
 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEventFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEventFactory.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEventFactory.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEventFactory.java Mon Dec  9 13:37:48 2013
@@ -30,5 +30,5 @@ public interface ReplicationEventFactory
      * @param replicationEventType the type of event to be generated
      * @param properties a dictionary of properties to be attached to the event
      */
-    void generateEvent(ReplicationEventType replicationEventType, Dictionary properties);
+    void generateEvent(ReplicationEventType replicationEventType, Dictionary<?, ?> properties);
 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/impl/DefaultReplicationEventFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/impl/DefaultReplicationEventFactory.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/impl/DefaultReplicationEventFactory.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/impl/DefaultReplicationEventFactory.java Mon Dec  9 13:37:48 2013
@@ -27,6 +27,9 @@ import org.apache.sling.replication.even
 import org.apache.sling.replication.event.ReplicationEventType;
 import org.osgi.service.event.EventAdmin;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * {@link ReplicationEventFactory} OSGi service
  */
@@ -34,15 +37,17 @@ import org.osgi.service.event.EventAdmin
 @Service(value = ReplicationEventFactory.class)
 public class DefaultReplicationEventFactory implements ReplicationEventFactory {
 
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
     @Reference
     private EventAdmin eventAdmin;
 
-    public void postEvent(ReplicationEvent event) {
-        eventAdmin.postEvent(event);
-    }
-
-    public void generateEvent(ReplicationEventType replicationEventType, Dictionary properties) {
-        postEvent(new ReplicationEvent(replicationEventType, properties));
+    public void generateEvent(ReplicationEventType replicationEventType, Dictionary<?, ?> properties) {
+        ReplicationEvent replicationEvent = new ReplicationEvent(replicationEventType, properties);
+        eventAdmin.postEvent(replicationEvent);
+        if (log.isDebugEnabled()) {
+            log.debug("replication event posted {}", replicationEvent);
+        }
     }
 
 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/ReplicationQueue.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/ReplicationQueue.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/ReplicationQueue.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/ReplicationQueue.java Mon Dec  9 13:37:48 2013
@@ -27,6 +27,12 @@ import org.apache.sling.replication.seri
 public interface ReplicationQueue {
 
     /**
+     * get this queue name
+     * @return queue name as a <code>String</code>
+     */
+    String getName();
+
+    /**
      * add a replication package to this queue
      *
      * @param replicationPackage
@@ -52,30 +58,27 @@ public interface ReplicationQueue {
      * get the agent this queue is used for
      *
      * @return a replication agent
-     * @throws ReplicationQueueException
      */
-    ReplicationAgent getAgent() throws ReplicationQueueException;
+    ReplicationAgent getAgent();
 
     /**
      * get the first item (FIFO wise, the next to be processed) into the queue
      *
      * @return the first replication package into the queue
-     * @throws ReplicationQueueException
      */
-    ReplicationPackage getHead() throws ReplicationQueueException;
+    ReplicationPackage getHead();
 
     /**
      * remove the first package into the queue from it
      *
      * @throws ReplicationQueueException
      */
-    void removeHead() throws ReplicationQueueException;
+    void removeHead();
 
     /**
      * check if the queue is empty
      *
      * @return <code>true</code> if the queue is empty, <code>false</code> otherwise
-     * @throws ReplicationQueueException
      */
-    boolean isEmpty() throws ReplicationQueueException;
+    boolean isEmpty();
 }



Mime
View raw message