You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by to...@apache.org on 2014/10/14 15:52:02 UTC

svn commit: r1631762 - in /sling/trunk/contrib/extensions/replication: core/src/main/java/org/apache/sling/replication/agent/impl/ core/src/main/java/org/apache/sling/replication/packaging/impl/exporter/ core/src/main/java/org/apache/sling/replication/...

Author: tommaso
Date: Tue Oct 14 13:52:02 2014
New Revision: 1631762

URL: http://svn.apache.org/r1631762
Log:
SLING-3993 - added an abstract jcr event trigger to avoid loops with two implementations(current and another persisting and replicating the event itself)

Added:
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/AbstractJcrEventTrigger.java   (with props)
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTrigger.java   (with props)
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/util/
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/util/ReplicationJcrUtils.java   (with props)
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/util/RequestUtils.java   (with props)
Removed:
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/RequestUtils.java
Modified:
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationComponentFactory.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/packaging/impl/exporter/RemoteReplicationPackageExporter.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentServlet.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationPackageExporterServlet.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationPackageImporterServlet.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationTriggerServlet.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/AdvancedHttpReplicationTransportHandler.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/SimpleHttpReplicationTransportHandler.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/JcrEventReplicationTrigger.java
    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
    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

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationComponentFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationComponentFactory.java?rev=1631762&r1=1631761&r2=1631762&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationComponentFactory.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationComponentFactory.java Tue Oct 14 13:52:02 2014
@@ -51,6 +51,7 @@ import org.apache.sling.replication.tran
 import org.apache.sling.replication.trigger.ReplicationTrigger;
 import org.apache.sling.replication.trigger.impl.ChainReplicateReplicationTrigger;
 import org.apache.sling.replication.trigger.impl.JcrEventReplicationTrigger;
+import org.apache.sling.replication.trigger.impl.PersistingJcrEventReplicationTrigger;
 import org.apache.sling.replication.trigger.impl.RemoteEventReplicationTrigger;
 import org.apache.sling.replication.trigger.impl.ResourceEventReplicationTrigger;
 import org.apache.sling.replication.trigger.impl.ScheduledReplicationTrigger;
@@ -269,6 +270,8 @@ public class DefaultReplicationComponent
             return new ChainReplicateReplicationTrigger(properties, bundleContext);
         } else if (JcrEventReplicationTrigger.TYPE.equals(factory)) {
             return new JcrEventReplicationTrigger(properties, repository);
+        } else if (PersistingJcrEventReplicationTrigger.TYPE.equals(factory)) {
+            return new PersistingJcrEventReplicationTrigger(properties, repository);
         }
 
         return null;

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/packaging/impl/exporter/RemoteReplicationPackageExporter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/packaging/impl/exporter/RemoteReplicationPackageExporter.java?rev=1631762&r1=1631761&r2=1631762&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/packaging/impl/exporter/RemoteReplicationPackageExporter.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/packaging/impl/exporter/RemoteReplicationPackageExporter.java Tue Oct 14 13:52:02 2014
@@ -48,7 +48,6 @@ public class RemoteReplicationPackageExp
                                             int pollItems) {
         this.packageBuilder = packageBuilder;
 
-
         List<ReplicationTransportHandler> transportHandlers = new ArrayList<ReplicationTransportHandler>();
 
         for (String endpoint : endpoints) {

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java?rev=1631762&r1=1631761&r2=1631762&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java Tue Oct 14 13:52:02 2014
@@ -42,7 +42,7 @@ import org.apache.sling.replication.seri
 import org.apache.sling.replication.serialization.ReplicationPackageBuildingException;
 import org.apache.sling.replication.serialization.ReplicationPackageReadingException;
 import org.apache.sling.replication.serialization.impl.AbstractReplicationPackageBuilder;
-import org.apache.sling.replication.trigger.impl.JcrEventReplicationTrigger;
+import org.apache.sling.replication.util.ReplicationJcrUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -116,7 +116,7 @@ public class FileVaultReplicationPackage
     @Override
     protected Session getSession() throws RepositoryException {
         Session session = repository.loginService(subServiceName, null);
-        session.getWorkspace().getObservationManager().setUserData(JcrEventReplicationTrigger.DO_NOT_REPLICATE);
+        ReplicationJcrUtils.setDoNotReplicate(session);
         return session;
     }
 
@@ -182,7 +182,10 @@ public class FileVaultReplicationPackage
             File file = new File(replicationPackage.getId());
             if (file.exists()) {
                 VaultPackage pkg = packaging.getPackageManager().open(file);
-                pkg.extract(session, new ImportOptions());
+                ImportOptions opts = new ImportOptions();
+                // TODO : make it possible to expose the VLT ImportMode / ACLHandling in a generic way (from the ReplicationRequest?)
+//                opts.setImportMode(ImportMode.MERGE);
+                pkg.extract(session, opts);
                 return true;
             }
         } catch (Exception e) {

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentServlet.java?rev=1631762&r1=1631761&r2=1631762&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentServlet.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentServlet.java Tue Oct 14 13:52:02 2014
@@ -38,7 +38,7 @@ import org.apache.sling.replication.comm
 import org.apache.sling.replication.communication.ReplicationResponse;
 import org.apache.sling.replication.queue.ReplicationQueueItemState.ItemState;
 import org.apache.sling.replication.resources.ReplicationConstants;
-import org.apache.sling.replication.transport.impl.RequestUtils;
+import org.apache.sling.replication.util.RequestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationPackageExporterServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationPackageExporterServlet.java?rev=1631762&r1=1631761&r2=1631762&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationPackageExporterServlet.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationPackageExporterServlet.java Tue Oct 14 13:52:02 2014
@@ -37,7 +37,7 @@ import org.apache.sling.replication.comm
 import org.apache.sling.replication.packaging.ReplicationPackage;
 import org.apache.sling.replication.packaging.ReplicationPackageExporter;
 import org.apache.sling.replication.resources.ReplicationConstants;
-import org.apache.sling.replication.transport.impl.RequestUtils;
+import org.apache.sling.replication.util.RequestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationPackageImporterServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationPackageImporterServlet.java?rev=1631762&r1=1631761&r2=1631762&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationPackageImporterServlet.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationPackageImporterServlet.java Tue Oct 14 13:52:02 2014
@@ -68,6 +68,7 @@ public class ReplicationPackageImporterS
             if (replicationPackage != null) {
                 success = replicationPackageImporter.importPackage(replicationPackage);
             } else {
+                // TODO : this should not just cause a warning as it means package was not imported correctly
                 log.warn("cannot read a replication package from the given stream");
             }
         } catch (final Exception e) {

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=1631762&r1=1631761&r2=1631762&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 Tue Oct 14 13:52:02 2014
@@ -80,10 +80,8 @@ public class ReplicationTriggerServlet e
         response.setHeader("Connection", "keep-alive");
 
         // 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");
+//        response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin")); // allowed origins should be explicitly configured
+//        response.setHeader("Access-Control-Allow-Credentials", "true");
 
         final PrintWriter writer = response.getWriter();
 

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/AdvancedHttpReplicationTransportHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/AdvancedHttpReplicationTransportHandler.java?rev=1631762&r1=1631761&r2=1631762&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/AdvancedHttpReplicationTransportHandler.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/AdvancedHttpReplicationTransportHandler.java Tue Oct 14 13:52:02 2014
@@ -87,7 +87,6 @@ public class AdvancedHttpReplicationTran
                 new Object[]{replicationPackage.getId(),
                         replicationEndpoint.getUri(), transportAuthenticationProvider});
 
-
         try {
             Executor executor = Executor.newInstance();
             TransportAuthenticationContext context = new TransportAuthenticationContext();

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/SimpleHttpReplicationTransportHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/SimpleHttpReplicationTransportHandler.java?rev=1631762&r1=1631761&r2=1631762&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/SimpleHttpReplicationTransportHandler.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/transport/impl/SimpleHttpReplicationTransportHandler.java Tue Oct 14 13:52:02 2014
@@ -41,6 +41,7 @@ import org.apache.sling.replication.tran
 import org.apache.sling.replication.transport.ReplicationTransportHandler;
 import org.apache.sling.replication.transport.authentication.TransportAuthenticationContext;
 import org.apache.sling.replication.transport.authentication.TransportAuthenticationProvider;
+import org.apache.sling.replication.util.RequestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Added: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/AbstractJcrEventTrigger.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/AbstractJcrEventTrigger.java?rev=1631762&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/AbstractJcrEventTrigger.java (added)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/AbstractJcrEventTrigger.java Tue Oct 14 13:52:02 2014
@@ -0,0 +1,127 @@
+/*
+ * 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.trigger.impl;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
+import java.util.Map;
+
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.trigger.ReplicationTrigger;
+import org.apache.sling.replication.trigger.ReplicationTriggerRequestHandler;
+import org.apache.sling.replication.util.ReplicationJcrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract implementation of a {@link org.apache.sling.replication.trigger.ReplicationTrigger} that listens for 'safe'
+ * events and triggers a {@link org.apache.sling.replication.communication.ReplicationRequest} from that.
+ */
+public abstract class AbstractJcrEventTrigger implements ReplicationTrigger, EventListener {
+
+    protected static final String PATH = "path";
+    protected static final String SERVICENAME = "servicename";
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private final String path;
+    private final String serviceUser;
+    private ReplicationTriggerRequestHandler requestHandler;
+
+    protected final SlingRepository repository;
+    protected Session session;
+
+    public AbstractJcrEventTrigger(SlingRepository repository, String path, String serviceUser) {
+        this.repository = repository;
+        this.path = path;
+        this.serviceUser = serviceUser;
+    }
+
+    public AbstractJcrEventTrigger(Map<String, Object> properties, SlingRepository repository) {
+        this(repository, PropertiesUtil.toString(properties.get(PATH), null), PropertiesUtil.toString(properties.get(SERVICENAME), null));
+    }
+
+    public void register(String handlerId, ReplicationTriggerRequestHandler requestHandler) {
+        try {
+            session = getSession();
+            session.getWorkspace().getObservationManager().addEventListener(
+                    this, getEventTypes(), path, true, null, null, false);
+            this.requestHandler = requestHandler;
+        } catch (RepositoryException e) {
+            log.error("unable to register session", e);
+        }
+    }
+
+    public void unregister(String handlerId) {
+        if (session != null) {
+            session.logout();
+        }
+    }
+
+    public void onEvent(EventIterator eventIterator) {
+        while (eventIterator.hasNext()) {
+            Event event = eventIterator.nextEvent();
+            try {
+                if (ReplicationJcrUtils.isSafe(event)) {
+                    ReplicationRequest request = processEvent(event);
+                    if (request != null) {
+                        requestHandler.handle(request);
+                    }
+                }
+            } catch (RepositoryException e) {
+                log.error("Error while handling event {}", event, e);
+            }
+        }
+    }
+
+    /**
+     * process the received event and generates a replication request
+     *
+     * @param event an {@link javax.jcr.observation.Event} to be processed
+     * @return the {@link org.apache.sling.replication.communication.ReplicationRequest} originated by processing the event,
+     * or <code>null</code> if no request could be generated
+     * @throws RepositoryException
+     */
+    protected abstract ReplicationRequest processEvent(Event event) throws RepositoryException;
+
+    /**
+     * get the binary int event types to be handled by this JCR event listener
+     *
+     * @return a <code>int</code> as generated by e.g. <code>Event.NODE_ADDED | Event.NODE_MOVED</code>
+     */
+    protected int getEventTypes() {
+        return Event.NODE_ADDED | Event.NODE_MOVED | Event.NODE_REMOVED | Event.PROPERTY_CHANGED |
+                Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED;
+    }
+
+    /**
+     * return a newly initiated JCR session to register the {@link javax.jcr.observation.EventListener}
+     *
+     * @return a {@link javax.jcr.Session}
+     * @throws RepositoryException
+     */
+    protected Session getSession() throws RepositoryException {
+        return repository.loginService(serviceUser, null);
+    }
+
+}

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

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/JcrEventReplicationTrigger.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/JcrEventReplicationTrigger.java?rev=1631762&r1=1631761&r2=1631762&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/JcrEventReplicationTrigger.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/JcrEventReplicationTrigger.java Tue Oct 14 13:52:02 2014
@@ -19,97 +19,44 @@
 package org.apache.sling.replication.trigger.impl;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 import javax.jcr.observation.Event;
-import javax.jcr.observation.EventIterator;
-import javax.jcr.observation.EventListener;
 import java.util.Map;
 
-import org.apache.jackrabbit.api.observation.JackrabbitEvent;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.replication.communication.ReplicationActionType;
 import org.apache.sling.replication.communication.ReplicationRequest;
 import org.apache.sling.replication.trigger.ReplicationTrigger;
-import org.apache.sling.replication.trigger.ReplicationTriggerRequestHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * A JCR observation based {@link org.apache.sling.replication.trigger.ReplicationTrigger}.
- * It filters events having {@link javax.jcr.observation.ObservationManager#setUserData(String)} set to
- * {@link #DO_NOT_REPLICATE}
  */
-public class JcrEventReplicationTrigger implements ReplicationTrigger {
-
-    public static final String DO_NOT_REPLICATE = "do.not.replicate";
+public class JcrEventReplicationTrigger extends AbstractJcrEventTrigger implements ReplicationTrigger {
 
     public static final String TYPE = "jcrEvent";
 
     private final Logger log = LoggerFactory.getLogger(this.getClass());
 
-    private final SlingRepository repository;
-    private final String path;
-
-    private Session adminSession;
-
-    public JcrEventReplicationTrigger(SlingRepository repository, String path) {
-        this.repository = repository;
-        this.path = path;
+    public JcrEventReplicationTrigger(SlingRepository repository, String path, String serviceName) {
+        super(repository, path, serviceName);
     }
 
     public JcrEventReplicationTrigger(Map<String, Object> properties, SlingRepository repository) {
-        this(repository, PropertiesUtil.toString(properties.get("path"), null));
+        this(repository, PropertiesUtil.toString(properties.get(PATH), null), PropertiesUtil.toString(properties.get(SERVICENAME), null));
     }
 
-    public void register(String handlerId, ReplicationTriggerRequestHandler requestHandler) {
-        log.info("activating ExampleObservation");
-        try {
-            adminSession = repository.loginService("replicationService", null);
-            adminSession.getWorkspace().getObservationManager().addEventListener(
-                    new JcrEventReplicationTriggerHandler(requestHandler), Event.NODE_ADDED | Event.NODE_MOVED | Event.NODE_REMOVED | Event.PROPERTY_CHANGED |
-                            Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED, path, true, null, null, false);
-        } catch (RepositoryException e) {
-            log.error("unable to register session", e);
+    @Override
+    protected ReplicationRequest processEvent(Event event) throws RepositoryException {
+        log.info("triggering replication from jcr event {}", event);
+        ReplicationRequest replicationRequest = null;
+        Object pathProperty = event.getPath();
+        if (pathProperty != null) {
+            String replicatingPath = String.valueOf(pathProperty);
+            replicationRequest = new ReplicationRequest(System.currentTimeMillis(), Event.NODE_REMOVED ==
+                    event.getType() ? ReplicationActionType.DELETE : ReplicationActionType.ADD, replicatingPath);
         }
+        return replicationRequest;
     }
-
-    public void unregister(String handlerId) {
-        if (adminSession != null) {
-            adminSession.logout();
-        }
-    }
-
-    private class JcrEventReplicationTriggerHandler implements EventListener {
-        private final ReplicationTriggerRequestHandler requestHandler;
-
-        public JcrEventReplicationTriggerHandler(ReplicationTriggerRequestHandler requestHandler) {
-            this.requestHandler = requestHandler;
-        }
-
-        public void onEvent(EventIterator eventIterator) {
-            try {
-                while (eventIterator.hasNext()) {
-                    Event event = eventIterator.nextEvent();
-                    if (event instanceof JackrabbitEvent && !((JackrabbitEvent)event).isExternal()) {
-                        String userData = event.getUserData();
-                        log.debug("event userData is {}", userData);
-                        if (!DO_NOT_REPLICATE.equals(userData)) {
-                            log.info("triggering replication from jcr event {}", event);
-
-                            Object pathProperty = event.getPath();
-                            if (pathProperty != null) {
-                                String replicatingPath = String.valueOf(pathProperty);
-                                requestHandler.handle(new ReplicationRequest(System.currentTimeMillis(), Event.NODE_MOVED ==
-                                        event.getType() ? ReplicationActionType.DELETE : ReplicationActionType.ADD, replicatingPath));
-                            }
-                        }
-                    }
-                }
-            } catch (RepositoryException e) {
-                log.error("Error while treating events", e);
-            }
-        }
-
-    }
-}
+}
\ No newline at end of file

Added: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTrigger.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTrigger.java?rev=1631762&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTrigger.java (added)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTrigger.java Tue Oct 14 13:52:02 2014
@@ -0,0 +1,91 @@
+/*
+ * 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.trigger.impl;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.observation.Event;
+import javax.jcr.security.Privilege;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.trigger.ReplicationTrigger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link org.apache.sling.replication.trigger.ReplicationTrigger} that listens for certain events and persists them
+ * under a specific path in the repo
+ */
+public class PersistingJcrEventReplicationTrigger extends AbstractJcrEventTrigger implements ReplicationTrigger {
+
+    private static final String NUGGETS_PATH_PROPERTY = "nuggets.path";
+    private static final String DEFAULT_NUGGETS_PATH = "/var/nuggets";
+
+    public static final String TYPE = "persistedJcrEvent";
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final String nuggetsPath;
+
+    public PersistingJcrEventReplicationTrigger(SlingRepository repository, String path, String servicename, String nuggetsPath) {
+        super(repository, path, servicename);
+        this.nuggetsPath = nuggetsPath;
+    }
+
+    public PersistingJcrEventReplicationTrigger(Map<String, Object> properties, SlingRepository repository) {
+        super(properties, repository);
+        this.nuggetsPath = PropertiesUtil.toString(properties.get(NUGGETS_PATH_PROPERTY), DEFAULT_NUGGETS_PATH);
+    }
+
+    @Override
+    protected ReplicationRequest processEvent(Event event) throws RepositoryException {
+        log.debug("processing event {}", event);
+
+        ReplicationRequest replicationRequest = null;
+
+        if (session.hasPermission(nuggetsPath, Privilege.JCR_ADD_CHILD_NODES)) {
+            log.debug("persisting event under {}", nuggetsPath);
+            Node nuggetsNode = session.getNode(nuggetsPath);
+            String path = nuggetsNode.addNode(event.getIdentifier()).getPath();
+            nuggetsNode.setProperty("path", event.getPath());
+            nuggetsNode.setProperty("date", event.getDate());
+            nuggetsNode.setProperty("type", event.getType());
+            nuggetsNode.setProperty("userData", event.getUserData());
+            nuggetsNode.setProperty("userID", event.getUserID());
+
+            Set<Map.Entry> set = event.getInfo().entrySet();
+            for (Map.Entry entry : set) {
+                nuggetsNode.setProperty("info." + entry.getKey(), String.valueOf(entry.getValue()));
+            }
+            session.save();
+            log.debug("event persisted at {}", path);
+            replicationRequest = new ReplicationRequest(System.currentTimeMillis(), ReplicationActionType.ADD, path);
+        } else {
+            log.warn("not enough privileges to persist the event {} under {}", event, nuggetsPath);
+        }
+
+        return replicationRequest;
+    }
+
+}

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

Added: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/util/ReplicationJcrUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/util/ReplicationJcrUtils.java?rev=1631762&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/util/ReplicationJcrUtils.java (added)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/util/ReplicationJcrUtils.java Tue Oct 14 13:52:02 2014
@@ -0,0 +1,63 @@
+/*
+ * 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.util;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.observation.Event;
+
+import org.apache.jackrabbit.api.observation.JackrabbitEvent;
+
+/**
+ * Utility class for JCR related replication operations.
+ */
+public class ReplicationJcrUtils {
+
+    public static final String DO_NOT_REPLICATE = "do.not.replicate";
+
+    /**
+     * checks a generated JCR event was not created by a JCR session having set the 'userData' to {@link #DO_NOT_REPLICATE}.
+     *
+     * @param jcrEvent an {@link javax.jcr.observation.Event}
+     * @return <code>false</code> if the event was generated by a {@link javax.jcr.Session} having its
+     * {@link javax.jcr.observation.ObservationManager#setUserData(String)} set to {@link #DO_NOT_REPLICATE}
+     * @throws javax.jcr.RepositoryException if retrieving 'userData' fails
+     */
+    public static boolean isSafe(Event jcrEvent) throws RepositoryException {
+        boolean safe = false;
+        if (jcrEvent instanceof JackrabbitEvent && !((JackrabbitEvent) jcrEvent).isExternal()) {
+            String userData = jcrEvent.getUserData();
+            if (!DO_NOT_REPLICATE.equals(userData)) {
+                safe = true;
+            }
+        }
+        return safe;
+
+    }
+
+    /**
+     * set {@link #DO_NOT_REPLICATE} on the given {@link Session}'s {@link javax.jcr.observation.ObservationManager#setUserData(String)}
+     *
+     * @param session a {@link javax.jcr.Session}
+     * @throws RepositoryException if retrieving the {@link javax.jcr.observation.ObservationManager} fails
+     */
+    public static void setDoNotReplicate(Session session) throws RepositoryException {
+        session.getWorkspace().getObservationManager().setUserData(ReplicationJcrUtils.DO_NOT_REPLICATE);
+    }
+}

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

Added: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/util/RequestUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/util/RequestUtils.java?rev=1631762&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/util/RequestUtils.java (added)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/util/RequestUtils.java Tue Oct 14 13:52:02 2014
@@ -0,0 +1,53 @@
+/*
+ * 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.util;
+
+import javax.servlet.http.HttpServletRequest;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationParameter;
+import org.apache.sling.replication.communication.ReplicationRequest;
+
+/**
+ * Utility class for HTTP / Replication request related operations.
+ */
+public class RequestUtils {
+
+    public static ReplicationRequest fromServletRequest(HttpServletRequest request) {
+        String action = request.getParameter(ReplicationParameter.ACTION.toString());
+        String[] paths = request.getParameterValues(ReplicationParameter.PATH.toString());
+
+        return new ReplicationRequest(System.currentTimeMillis(),
+                ReplicationActionType.fromName(action),
+                paths);
+    }
+
+    public static URI appendReplicationRequest(URI uri, ReplicationRequest replicationRequest) throws URISyntaxException {
+        URIBuilder uriBuilder = new URIBuilder(uri);
+        uriBuilder.addParameter(ReplicationParameter.ACTION.toString(), replicationRequest.getAction().getName());
+        for (String path : replicationRequest.getPaths()) {
+            uriBuilder.addParameter(ReplicationParameter.PATH.toString(), path);
+        }
+        return uriBuilder.build();
+    }
+
+}

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

Modified: 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=1631762&r1=1631761&r2=1631762&view=diff
==============================================================================
--- 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 (original)
+++ 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 Tue Oct 14 13:52:02 2014
@@ -6,7 +6,8 @@
 
     "properties": [
         "type=jcrEvent",
-        "path=/content/usergenerated"
+        "path=/content/usergenerated",
+        "servicename=replicationService"
     ]
 
 }
\ No newline at end of file

Modified: 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=1631762&r1=1631761&r2=1631762&view=diff
==============================================================================
--- 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 (original)
+++ 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 Tue Oct 14 13:52:02 2014
@@ -23,6 +23,7 @@
 
     "trigger0": [
         "type=jcrEvent",
-        "path=/content/usergenerated"
+        "path=/content/usergenerated",
+        "servicename=replicationService"
     ]
 }