Modified: 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=1629162&r1=1629161&r2=1629162&view=diff ============================================================================== --- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactory.java (original) +++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentFactory.java Fri Oct 3 09:33:20 2014 @@ -18,21 +18,14 @@ */ 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 java.util.*; + +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.agent.ReplicationComponent; +import org.apache.sling.replication.agent.ReplicationComponentFactory; +import org.apache.sling.replication.agent.ReplicationComponentProvider; import org.apache.sling.replication.event.ReplicationEventFactory; import org.apache.sling.replication.packaging.ReplicationPackageExporter; import org.apache.sling.replication.packaging.ReplicationPackageImporter; @@ -40,6 +33,7 @@ import org.apache.sling.replication.queu 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.transport.authentication.TransportAuthenticationProvider; import org.apache.sling.settings.SlingSettingsService; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -52,26 +46,18 @@ import org.slf4j.LoggerFactory; */ @Component(metatype = true, label = "Simple Replication Agents Factory", - description = "OSGi configuration based ReplicationAgent service factory", - name = SimpleReplicationAgentFactory.SERVICE_PID, + description = "OSGi configuration factory for agents", 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 class SimpleReplicationAgentFactory implements ReplicationComponentProvider { + public static final String QUEUEPROVIDER_TARGET = "queueProvider.target"; - public static final String QUEUEPROVIDER_TARGET = "ReplicationQueueProvider.target"; - - public static final String QUEUE_DISTRIBUTION_TARGET = "ReplicationQueueDistributionStrategy.target"; + public static final String QUEUE_DISTRIBUTION_TARGET = "queueDistributionStrategy.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 + ")"; @@ -82,35 +68,32 @@ public class SimpleReplicationAgentFacto @Property(label = "Name") public static final String NAME = "name"; - @Property(label = "Triggers") - public static final String TRIGGERS = "triggers"; - @Property(boolValue = true, label = "Replicate using aggregated paths") public static final String USE_AGGREGATE_PATHS = "useAggregatePaths"; @Property(boolValue = false, label = "Replicate using aggregated paths") public static final String IS_PASSIVE = "isPassive"; - @Property(label = "Target ReplicationPackageExporter", name = PACKAGE_EXPORTER_TARGET) - @Reference(name = "ReplicationPackageExporter", policy = ReferencePolicy.DYNAMIC) - private volatile ReplicationPackageExporter packageExporter; - - @Property(label = "Target ReplicationPackageImporter", name = PACKAGE_IMPORTER_TARGET) - @Reference(name = "ReplicationPackageImporter", policy = ReferencePolicy.DYNAMIC) - private volatile ReplicationPackageImporter packageImporter; + + @Property(label = "Package Exporter", cardinality = 100) + public static final String PACKAGE_EXPORTER = "packageExporter"; + + @Property(label = "Package Importer", cardinality = 100) + public static final String PACKAGE_IMPORTER = "packageImporter"; @Property(label = "Target ReplicationQueueProvider", name = QUEUEPROVIDER_TARGET, value = DEFAULT_QUEUEPROVIDER) - @Reference(name = "ReplicationQueueProvider", target = DEFAULT_QUEUEPROVIDER, policy = ReferencePolicy.DYNAMIC) + @Reference(name = "queueProvider", target = DEFAULT_QUEUEPROVIDER) private volatile ReplicationQueueProvider queueProvider; @Property(label = "Target QueueDistributionStrategy", name = QUEUE_DISTRIBUTION_TARGET, value = DEFAULT_DISTRIBUTION) - @Reference(name = "ReplicationQueueDistributionStrategy", target = DEFAULT_DISTRIBUTION, policy = ReferencePolicy.DYNAMIC) + @Reference(name = "queueDistributionStrategy", target = DEFAULT_DISTRIBUTION) private volatile ReplicationQueueDistributionStrategy queueDistributionStrategy; - @Property(label = "Runmodes") - private static final String RUNMODES = "runModes"; + @Property(label = "Target TransportAuthenticationProvider", name = "transportAuthenticationProvider.target") + @Reference(name = "transportAuthenticationProvider", policy = ReferencePolicy.DYNAMIC, + cardinality = ReferenceCardinality.OPTIONAL_UNARY) + private volatile TransportAuthenticationProvider transportAuthenticationProvider; - private ServiceRegistration agentReg; @Reference private ReplicationEventFactory replicationEventFactory; @@ -118,8 +101,20 @@ public class SimpleReplicationAgentFacto @Reference private SlingSettingsService settingsService; + @Reference + private ReplicationComponentFactory componentFactory; + + + + private ServiceRegistration componentReg; + private BundleContext savedContext; + private Map<String, Object> savedConfig; + @Activate - public void activate(BundleContext context, Map<String, ?> config) throws Exception { + public void activate(BundleContext context, Map<String, Object> config) { + + savedContext = context; + savedConfig = config; // inject configuration Dictionary<String, Object> props = new Hashtable<String, Object>(); @@ -129,9 +124,6 @@ public class SimpleReplicationAgentFacto 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); @@ -143,61 +135,81 @@ public class SimpleReplicationAgentFacto String distribution = PropertiesUtil.toString(config.get(QUEUE_DISTRIBUTION_TARGET), DEFAULT_DISTRIBUTION); props.put(QUEUE_DISTRIBUTION_TARGET, distribution); - String[] triggers = PropertiesUtil.toStringArray(config.get(TRIGGERS), new String[0]); - props.put(TRIGGERS, triggers); + if (componentReg == null) { + Map<String, Object> properties = new HashMap<String, Object>(); + properties.putAll(config); + properties.put("type", "simple"); + ReplicationAgent agent = componentFactory.createComponent(ReplicationAgent.class, properties, this); - boolean useAggregatePaths = PropertiesUtil.toBoolean(config.get(USE_AGGREGATE_PATHS), true); - props.put(USE_AGGREGATE_PATHS, useAggregatePaths); + log.debug("activated agent {}", agent != null ? agent.getName() : null); - boolean isPassive = PropertiesUtil.toBoolean(config.get(IS_PASSIVE), false); - props.put(IS_PASSIVE, isPassive); + if (agent != null) { + props.put(NAME, agent.getName()); - // 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"); - } - - log.info("bound services for {} : {} - {} - {} - {} - {} - {}", new Object[]{name, - packageImporter, packageExporter, queueProvider, queueDistributionStrategy}); + // register agent service + componentReg = context.registerService(ReplicationAgent.class.getName(), agent, props); - SimpleReplicationAgent agent = new SimpleReplicationAgent(name, useAggregatePaths, isPassive, - packageImporter, packageExporter, queueProvider, queueDistributionStrategy, replicationEventFactory, - null); // TODO : enable triggers again - - // 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; + if (agent instanceof ReplicationComponent) { + ((ReplicationComponent) agent).enable(); } } } + } - 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(); + if (componentReg != null) { + ServiceReference reference = componentReg.getReference(); + Object service = context.getService(reference); + if (service instanceof ReplicationComponent) { + ((ReplicationComponent) service).disable(); + } + + componentReg.unregister(); + componentReg = null; + } + + } + + + public <ComponentType> ComponentType getComponent(Class<ComponentType> type, String componentName) { + if (type.isAssignableFrom(ReplicationQueueProvider.class)) { + return (ComponentType) queueProvider; + + } + else if (type.isAssignableFrom(ReplicationQueueDistributionStrategy.class)) { + return (ComponentType) queueDistributionStrategy; } + else if (type.isAssignableFrom(TransportAuthenticationProvider.class)) { + return (ComponentType) transportAuthenticationProvider; + } + return null; + } + + + private void refresh() { + if (savedContext != null && savedConfig != null) { + if (componentReg == null) { + activate(savedContext, savedConfig); + } + else if (componentReg != null) { + deactivate(savedContext); + activate(savedContext, savedConfig); + } + } + } + + private void bindTransportAuthenticationProvider(TransportAuthenticationProvider transportAuthenticationProvider) { + this.transportAuthenticationProvider = transportAuthenticationProvider; + refresh(); + } + private void unbindTransportAuthenticationProvider(TransportAuthenticationProvider transportAuthenticationProvider) { + this.transportAuthenticationProvider = null; + refresh(); } }
Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/packaging/ReplicationPackage.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/packaging/ReplicationPackage.java?rev=1629162&r1=1629161&r2=1629162&view=diff ============================================================================== --- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/packaging/ReplicationPackage.java (original) +++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/packaging/ReplicationPackage.java Fri Oct 3 09:33:20 2014 @@ -71,9 +71,8 @@ public interface ReplicationPackage exte */ long getLength(); - /** - * releases resources associated with this object + * releases resources associated with this package */ void close(); Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiServicePropertiesResourceProvider.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiServicePropertiesResourceProvider.java?rev=1629162&r1=1629161&r2=1629162&view=diff ============================================================================== --- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiServicePropertiesResourceProvider.java (original) +++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiServicePropertiesResourceProvider.java Fri Oct 3 09:33:20 2014 @@ -103,6 +103,10 @@ public class OsgiServicePropertiesResour Object service = context.getService(serviceReference); + if (service == null) { + return null; + } + services.put(serviceName, service); serviceProperties.put(serviceName, properties); 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=1629162&r1=1629161&r2=1629162&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 Fri Oct 3 09:33:20 2014 @@ -39,7 +39,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * base abstract implementation of a {@link ReplicationPackageBuilder} + * base abstract implementation of a JCR based {@link ReplicationPackageBuilder} */ public abstract class AbstractReplicationPackageBuilder implements ReplicationPackageBuilder { Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationTriggerServlet.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationTriggerServlet.java?rev=1629162&r1=1629161&r2=1629162&view=diff ============================================================================== --- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationTriggerServlet.java (original) +++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationTriggerServlet.java Fri Oct 3 09:33:20 2014 @@ -81,6 +81,7 @@ public class ReplicationTriggerServlet e // needed to allow e.g. the JavaScript EventSource API to make a call from author to this server and listen for the events // TODO : check if this is needed or not (other than for browser communication) + // TODO : allowed origins should be explicitly configured response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin")); response.setHeader("Access-Control-Allow-Credentials", "true"); Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsTransportAuthenticationProviderFactory.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsTransportAuthenticationProviderFactory.java?rev=1629162&r1=1629161&r2=1629162&view=diff ============================================================================== --- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsTransportAuthenticationProviderFactory.java (original) +++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsTransportAuthenticationProviderFactory.java Fri Oct 3 09:33:20 2014 @@ -52,10 +52,8 @@ public class UserCredentialsTransportAut public void activate(Map<String, Object> config) { transportAuthenticationProvider = new UserCredentialsTransportAuthenticationProvider(config); - } - public Object authenticate(Object authenticable, TransportAuthenticationContext context) throws TransportAuthenticationException { return transportAuthenticationProvider.authenticate(authenticable, context); Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/RequestUtils.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/RequestUtils.java?rev=1629162&r1=1629161&r2=1629162&view=diff ============================================================================== --- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/RequestUtils.java (original) +++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/RequestUtils.java Fri Oct 3 09:33:20 2014 @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.sling.replication.transport.impl; import javax.servlet.http.HttpServletRequest; @@ -34,12 +33,9 @@ public class RequestUtils { String action = request.getParameter(ReplicationParameter.ACTION.toString()); String[] paths = request.getParameterValues(ReplicationParameter.PATH.toString()); - ReplicationRequest replicationRequest = new ReplicationRequest(System.currentTimeMillis(), + return new ReplicationRequest(System.currentTimeMillis(), ReplicationActionType.fromName(action), paths); - - return replicationRequest; - } public static URI appendReplicationRequest(URI uri, ReplicationRequest replicationRequest) throws URISyntaxException { Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/ChainReplicateReplicationTrigger.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/ChainReplicateReplicationTrigger.java?rev=1629162&r1=1629161&r2=1629162&view=diff ============================================================================== --- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/ChainReplicateReplicationTrigger.java (original) +++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/ChainReplicateReplicationTrigger.java Fri Oct 3 09:33:20 2014 @@ -24,6 +24,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.sling.commons.osgi.PropertiesUtil; +import org.apache.sling.replication.agent.ReplicationComponent; import org.apache.sling.replication.communication.ReplicationActionType; import org.apache.sling.replication.communication.ReplicationRequest; import org.apache.sling.replication.event.ReplicationEvent; @@ -41,7 +42,7 @@ import org.slf4j.LoggerFactory; /** * {@link org.apache.sling.replication.trigger.ReplicationTrigger} for chain replication upon a certain {@link org.apache.sling.replication.event.ReplicationEventType} */ -public class ChainReplicateReplicationTrigger implements ReplicationTrigger { +public class ChainReplicateReplicationTrigger implements ReplicationTrigger, ReplicationComponent { public static final String TYPE = "replicateEvent"; public static final String PATH = "path"; @@ -63,14 +64,7 @@ public class ChainReplicateReplicationTr this.pathPrefix = pathPrefix; } - protected void deactivate() { - for (Map.Entry<String, ServiceRegistration> entry : registrations.entrySet()) { - if (entry.getValue() != null) { - entry.getValue().unregister(); - } - } - registrations.clear(); - } + public void register(String handlerId, ReplicationTriggerRequestHandler requestHandler) { // register an event handler on replication package install (on a certain path) which triggers the chain replication of that same package @@ -98,6 +92,18 @@ public class ChainReplicateReplicationTr } } + public void enable() { + } + + public void disable() { + for (Map.Entry<String, ServiceRegistration> entry : registrations.entrySet()) { + if (entry.getValue() != null) { + entry.getValue().unregister(); + } + } + registrations.clear(); + } + private class TriggerAgentEventListener implements EventHandler { Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/ResourceEventReplicationTrigger.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/ResourceEventReplicationTrigger.java?rev=1629162&r1=1629161&r2=1629162&view=diff ============================================================================== --- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/ResourceEventReplicationTrigger.java (original) +++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/ResourceEventReplicationTrigger.java Fri Oct 3 09:33:20 2014 @@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentHa import org.apache.sling.api.SlingConstants; import org.apache.sling.commons.osgi.PropertiesUtil; +import org.apache.sling.replication.agent.ReplicationComponent; import org.apache.sling.replication.communication.ReplicationActionType; import org.apache.sling.replication.communication.ReplicationRequest; import org.apache.sling.replication.trigger.ReplicationTrigger; @@ -40,7 +41,7 @@ import org.slf4j.LoggerFactory; /** * {@link org.apache.sling.replication.trigger.ReplicationTrigger} for triggering a specific agent upon node / properties being changed under a certain path */ -public class ResourceEventReplicationTrigger implements ReplicationTrigger { +public class ResourceEventReplicationTrigger implements ReplicationTrigger, ReplicationComponent { public static final String TYPE = "resourceEvent"; public static final String PATH = "path"; @@ -68,7 +69,11 @@ public class ResourceEventReplicationTri this.path = path; } - protected void deactivate() { + public void enable() { + + } + + public void disable() { for (Map.Entry<String, ServiceRegistration> entry : registrations.entrySet()) { if (entry.getValue() != null) { entry.getValue().unregister(); @@ -114,9 +119,9 @@ public class ResourceEventReplicationTri ReplicationActionType.DELETE : ReplicationActionType.ADD; log.info("triggering replication from event {}", event); - Object eventProperty = event.getProperty("path"); - if (eventProperty != null) { - String replicatingPath = String.valueOf(eventProperty); + Object pathProperty = event.getProperty("path"); + if (pathProperty != null) { + String replicatingPath = String.valueOf(pathProperty); requestHandler.handle(new ReplicationRequest(System.currentTimeMillis(), action, replicatingPath)); } } 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=1629162&r1=1629161&r2=1629162&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 Fri Oct 3 09:33:20 2014 @@ -125,8 +125,10 @@ public class SimpleReplicationAgentTest ReplicationPackageExporter packageExporter = mock(ReplicationPackageExporter.class); ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class); ReplicationQueueDistributionStrategy distributionHandler = mock(ReplicationQueueDistributionStrategy.class); + ReplicationEventFactory replicationEventFactory = mock(ReplicationEventFactory.class); + SimpleReplicationAgent agent = new SimpleReplicationAgent(name, true, - false, packageImporter, packageExporter, queueProvider, distributionHandler, null, null); + false, packageImporter, packageExporter, queueProvider, distributionHandler, replicationEventFactory, null); ReplicationQueue queue = mock(ReplicationQueue.class); when(queueProvider.getDefaultQueue(agent.getName())).thenReturn(queue); assertNotNull(agent.getQueue(null)); @@ -139,8 +141,10 @@ public class SimpleReplicationAgentTest ReplicationPackageExporter packageExporter = mock(ReplicationPackageExporter.class); ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class); ReplicationQueueDistributionStrategy distributionHandler = mock(ReplicationQueueDistributionStrategy.class); + ReplicationEventFactory replicationEventFactory = mock(ReplicationEventFactory.class); + SimpleReplicationAgent agent = new SimpleReplicationAgent(name, true, - false, packageImporter, packageExporter, queueProvider, distributionHandler, null, null); + false, packageImporter, packageExporter, queueProvider, distributionHandler, replicationEventFactory, null); ReplicationQueue queue = mock(ReplicationQueue.class); when(queueProvider.getQueue(agent.getName(), "priority")).thenReturn(queue); assertNotNull(agent.getQueue("priority")); @@ -153,8 +157,10 @@ public class SimpleReplicationAgentTest ReplicationPackageExporter packageExporter = mock(ReplicationPackageExporter.class); ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class); ReplicationQueueDistributionStrategy distributionHandler = mock(ReplicationQueueDistributionStrategy.class); + ReplicationEventFactory replicationEventFactory = mock(ReplicationEventFactory.class); + SimpleReplicationAgent agent = new SimpleReplicationAgent(name, true, - false, packageImporter, packageExporter, queueProvider, distributionHandler, null, null); + false, packageImporter, packageExporter, queueProvider, distributionHandler, replicationEventFactory, null); ReplicationQueue queue = mock(ReplicationQueue.class); when(queueProvider.getQueue(agent.getName(), "priority")).thenReturn(queue); assertNull(agent.getQueue("weird")); Added: sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-content-event.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-content-event.json?rev=1629162&view=auto ============================================================================== --- sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-content-event.json (added) +++ sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-content-event.json Fri Oct 3 09:33:20 2014 @@ -0,0 +1,13 @@ +{ + "jcr:primaryType": "sling:OsgiConfig", + "name": "test-content-event", + + "componentType": "trigger", + + "properties": [ + "type=resourceEvent", + "path=/content" + + ] + +} \ No newline at end of file Added: sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-remote-event.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-remote-event.json?rev=1629162&view=auto ============================================================================== --- sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-remote-event.json (added) +++ sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-remote-event.json Fri Oct 3 09:33:20 2014 @@ -0,0 +1,15 @@ +{ + "jcr:primaryType": "sling:OsgiConfig", + "name": "test-remote-event", + + "componentType": "trigger", + + "properties": [ + "type=remoteEvent", + "endpoint=http://localhost:4503/libs/sling/replication/services/triggers/content-changed.event", + + "authenticationProvider/type=service", + "authenticationProvider/name=publishAdmin" + ] + +} \ No newline at end of file Added: sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-replicate-event.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-replicate-event.json?rev=1629162&view=auto ============================================================================== --- sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-replicate-event.json (added) +++ sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-replicate-event.json Fri Oct 3 09:33:20 2014 @@ -0,0 +1,12 @@ +{ + "jcr:primaryType": "sling:OsgiConfig", + "name": "test-replicate-event", + + "componentType": "trigger", + + "properties": [ + "type=replicateEvent" + + ] + +} \ No newline at end of file Added: sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-scheduled-event.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-scheduled-event.json?rev=1629162&view=auto ============================================================================== --- sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-scheduled-event.json (added) +++ sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-test-scheduled-event.json Fri Oct 3 09:33:20 2014 @@ -0,0 +1,12 @@ + { + "jcr:primaryType": "sling:OsgiConfig", + "name": "test-scheduled-event", + + "componentType": "trigger", + + "properties": [ + "type=scheduledEvent", + "action=poll", + "seconds=30" + ] +} \ No newline at end of file Modified: sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.CoordinatingReplicationAgentFactory-pubsync.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.CoordinatingReplicationAgentFactory-pubsync.json?rev=1629162&r1=1629161&r2=1629162&view=diff ============================================================================== --- sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.CoordinatingReplicationAgentFactory-pubsync.json (original) +++ sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.CoordinatingReplicationAgentFactory-pubsync.json Fri Oct 3 09:33:20 2014 @@ -1,25 +1,21 @@ { "jcr:primaryType": "sling:OsgiConfig", "name": "pubsync", - "type": "coordinating", - "enabled" : false, "packageExporter": [ "authenticationProvider/type=service", - "authenticationProvider/name=publishAdmin", "packageBuilder/type=vlt", "packageBuilder/servicename=replicationService", - "endpoints[0]=http://localhost:4503/libs/sling/replication/services/exporters/reverse", - "endpoints[1]=http://localhost:4504/libs/sling/replication/services/exporters/reverse", - "endpoints[2]=http://localhost:4505/libs/sling/replication/services/exporters/reverse", + "endpoints[0]=http://localhost:4503/libs/sling/replication/services/exporters/reverse-pubsync", + "endpoints[1]=http://localhost:4504/libs/sling/replication/services/exporters/reverse-pubsync", + "endpoints[2]=http://localhost:4505/libs/sling/replication/services/exporters/reverse-pubsync", "endpoints.strategy=All" ], "packageImporter": [ "authenticationProvider/type=service", - "authenticationProvider/name=publishAdmin", "packageBuilder/type=vlt", "packageBuilder/servicename=replicationService", @@ -30,13 +26,9 @@ "endpoints.strategy=All" ], - "queueProvider": [ - "type=service", - "name=sjh" - ], + "queueProvider.target" : "(name=sjh)", + + "queueDistributionStrategy.target": "(name=error)", - "queueDistributionStrategy": [ - "type=service", - "name=error" - ] + "transportAuthenticationProvider.target" : "(name=publishAdmin)" } \ No newline at end of file Added: sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-remote-event.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-remote-event.json?rev=1629162&view=auto ============================================================================== --- sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-remote-event.json (added) +++ sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-remote-event.json Fri Oct 3 09:33:20 2014 @@ -0,0 +1,16 @@ +{ + "jcr:primaryType": "sling:OsgiConfig", + "name": "remote-event", + + "componentType": "trigger", + + "properties": [ + "type=remoteEvent", + "endpoint=http://localhost:4503/libs/sling/replication/services/triggers/content-changed.event", + + "authenticationProvider/type=service" + ], + + "transportAuthenticationProvider.target" : "(name=publishAdmin)" + +} \ No newline at end of file Added: sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish-reverse.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish-reverse.json?rev=1629162&view=auto ============================================================================== --- sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish-reverse.json (added) +++ sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish-reverse.json Fri Oct 3 09:33:20 2014 @@ -0,0 +1,43 @@ +{ + "jcr:primaryType": "sling:OsgiConfig", + "name": "publish-reverse", + + "enabled" : true, + + "packageExporter": [ + "type=remote", + "endpoints[0]=http://localhost:4503/libs/sling/replication/services/exporters/reverse", + + "authenticationProvider/type=service", + + "packageBuilder/type=vlt", + "packageBuilder/servicename=replicationService" + ], + + "packageImporter": [ + "type=local", + "packageBuilder/type=vlt", + "packageBuilder/servicename=replicationService" + ], + + "trigger0": [ + "type=scheduledEvent", + "action=poll", + "seconds=30" + ], + + "trigger1": [ + "type=remoteEvent", + "endpoint=http://localhost:4503/libs/sling/replication/services/triggers/content-changed.event", + + "authenticationProvider/type=service" + ], + + + "queueProvider.target" : "(name=sjh)", + + "queueDistributionStrategy.target": "(name=error)", + + "transportAuthenticationProvider.target" : "(name=publishAdmin)" + +} \ No newline at end of file Added: sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish.json?rev=1629162&view=auto ============================================================================== --- sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish.json (added) +++ sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.author/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-publish.json Fri Oct 3 09:33:20 2014 @@ -0,0 +1,26 @@ +{ + "jcr:primaryType": "sling:OsgiConfig", + "name": "publish", + + "packageExporter": [ + "type=local", + "packageBuilder/type=vlt", + "packageBuilder/servicename=replicationService" + ], + + "packageImporter": [ + "type=remote", + "endpoints[0]=http://localhost:4503/libs/sling/replication/services/importers/default", + + "authenticationProvider/type=service", + + "packageBuilder/type=vlt", + "packageBuilder/servicename=replicationService" + ], + + "queueProvider.target" : "(name=sjh)", + + "queueDistributionStrategy.target": "(name=error)", + + "transportAuthenticationProvider.target" : "(name=publishAdmin)" +} \ No newline at end of file Added: sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-content-changed.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-content-changed.json?rev=1629162&view=auto ============================================================================== --- sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-content-changed.json (added) +++ sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.GenericReplicationComponentFactory-trigger-content-changed.json Fri Oct 3 09:33:20 2014 @@ -0,0 +1,12 @@ +{ + "jcr:primaryType": "sling:OsgiConfig", + "name": "content-changed", + + "componentType": "trigger", + + "properties": [ + "type=resourceEvent", + "path=/content/usergenerated" + ] + +} \ No newline at end of file Added: sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-cache-flush.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-cache-flush.json?rev=1629162&view=auto ============================================================================== --- sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-cache-flush.json (added) +++ sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-cache-flush.json Fri Oct 3 09:33:20 2014 @@ -0,0 +1,19 @@ +{ + "jcr:primaryType": "sling:OsgiConfig", + "name": "cache-flush", + + "packageExporter": [ + "type=service", + "name=void" + ], + + "packageImporter": [ + "type=service", + "name=cache-flush" + ], + + + "queueProvider.target" : "(name=sjh)", + + "queueDistributionStrategy": "(name=error)" +} Added: sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-reverse.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-reverse.json?rev=1629162&view=auto ============================================================================== --- sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-reverse.json (added) +++ sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install.publish/org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory-reverse.json Fri Oct 3 09:33:20 2014 @@ -0,0 +1,28 @@ +{ + "jcr:primaryType": "sling:OsgiConfig", + "name": "reverse", + + "isPassive": true, + + "packageExporter": [ + "type=local", + "packageBuilder/type=vlt", + "packageBuilder/servicename=replicationService" + ], + + "packageImporter": [ + "type=local", + "packageBuilder/type=vlt", + "packageBuilder/servicename=replicationService" + ], + + + "queueProvider.target" : "(name=sjh)", + + "queueDistributionStrategy": "(name=error)", + + "trigger0": [ + "type=resourceEvent", + "path=/content/usergenerated" + ] +} Modified: sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install/resources/settings/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-simpleAgents.json URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install/resources/settings/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-simpleAgents.json?rev=1629162&r1=1629161&r2=1629162&view=diff ============================================================================== --- sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install/resources/settings/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-simpleAgents.json (original) +++ sling/trunk/contrib/extensions/replication/sample/src/main/resources/SLING-CONTENT/libs/sling/replication/install/resources/settings/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-simpleAgents.json Fri Oct 3 09:33:20 2014 @@ -2,7 +2,7 @@ "jcr:primaryType": "sling:OsgiConfig", "name": "simpleAgents", "provider.roots": [ "/libs/sling/replication/settings/agents" ], - "serviceType": "org.apache.sling.replication.agent.impl.CompactSimpleReplicationAgentFactory", + "serviceType": "org.apache.sling.replication.agent.impl.SimpleReplicationAgentFactory", "providerType": "osgiConfig", "groupPrefix": "agents",