You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ie...@apache.org on 2016/07/27 12:10:14 UTC

svn commit: r1754255 [4/5] - in /sling/trunk/contrib: commons/mom/ commons/mom/api/ commons/mom/api/src/ commons/mom/api/src/main/ commons/mom/api/src/main/java/ commons/mom/api/src/main/java/org/ commons/mom/api/src/main/java/org/apache/ commons/mom/a...

Added: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/java/org/apache/sling/jobs/it/TestSuiteLauncherIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/java/org/apache/sling/jobs/it/TestSuiteLauncherIT.java?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/java/org/apache/sling/jobs/it/TestSuiteLauncherIT.java (added)
+++ sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/java/org/apache/sling/jobs/it/TestSuiteLauncherIT.java Wed Jul 27 12:10:12 2016
@@ -0,0 +1,87 @@
+package org.apache.sling.jobs.it;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.sling.crankstart.junit.CrankstartSetup;
+import org.junit.ClassRule;
+import org.junit.rules.ExternalResource;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Basic tests of the launcher, verify that we 
+ *  can start the Felix HTTP service and a few
+ *  other things. 
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses(CheckRootIT.class)
+public class TestSuiteLauncherIT {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(TestSuiteLauncherIT.class);
+    private static final long classSetup = System.currentTimeMillis();
+    private static final long MAX_BACKOFF = 5000;
+    private static final long INITIAL_BACKOFF = 100;
+
+    @ClassRule
+    public final static CrankstartSetup crankstartSetup = new CrankstartSetup().withModelResources(Models.DEFAULT_MODELS);
+
+
+    @ClassRule
+    public final static ExternalResource R = new ExternalResource() {
+        @Override
+        protected void before() throws Throwable {
+            LOGGER.info("Waiting for Crankstart to start");
+            while(crankstartSetup.getTotalBundles() == 0) {
+                Thread.sleep(100);
+            }
+            if (crankstartSetup.getBundlesFailed() > 0) {
+                LOGGER.error("Bundles failed to start {} ",crankstartSetup.getBundlesFailed());
+                fail();
+            }
+            LOGGER.info("Crankstart to started {} bundles ", crankstartSetup.getBundlesStarted());
+            DefaultHttpClient client = new DefaultHttpClient();
+            final HttpUriRequest get = new HttpGet(crankstartSetup.getBaseUrl());
+            HttpResponse response = null;
+            long backoff = INITIAL_BACKOFF;
+            boolean noresponse = false;
+            long ttl = System.currentTimeMillis()+60000;
+            // try for no more than 60s
+            while(System.currentTimeMillis() < ttl) {
+                try {
+                    response = client.execute(get);
+                    if (noresponse) {
+                        backoff = INITIAL_BACKOFF;
+                        noresponse = false;
+                    }
+                    if (response.getStatusLine().getStatusCode() == 404) {
+                        LOGGER.info("Sever up and responding to http requests, startup complete");
+                        Thread.sleep(60000);
+                        return;
+                    }
+                    LOGGER.info("Server not respoding as expected to http requests, waiting {} ms", backoff);
+                    Thread.sleep(backoff);
+                    backoff = Math.min((long)(backoff*1.5), MAX_BACKOFF);
+                } catch (Exception ex) {
+                    noresponse = true;
+                    LOGGER.info("Server not respoding waiting {} ms {} ", backoff, ex.getClass());
+                    Thread.sleep(backoff);
+                    backoff = Math.min(backoff*2, MAX_BACKOFF);
+                } finally {
+                    Models.closeConnection(response);
+                }
+
+            }
+            fail("Unable to contact server");
+        }
+
+    };
+
+
+}
\ No newline at end of file

Propchange: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/java/org/apache/sling/jobs/it/TestSuiteLauncherIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/crankstart-model.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/crankstart-model.txt?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/crankstart-model.txt (added)
+++ sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/crankstart-model.txt Wed Jul 27 12:10:12 2016
@@ -0,0 +1,46 @@
+#
+#  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.
+#
+
+# Test the crankstart launcher by setting up an HTTP
+# server with a few servlets that require specific OSGi configurations
+[feature name=:crankstart]
+
+[variables]
+  felix.framework.version=5.0.0
+  slf4j.version = 1.7.6
+  http.port = 8080
+  osgi.storage.path = CRANKSTART/felix
+  osgi.start.level = 42
+  osgi-core-packages=org.osgi.dto; version=1.0.0, org.osgi.framework; version=1.8.0, org.osgi.framework.dto; version=1.8.0, org.osgi.framework.hooks.bundle; version=1.1.0, org.osgi.framework.hooks.resolver; version=1.0.0, org.osgi.framework.hooks.service; version=1.1.0, org.osgi.framework.hooks.weaving; version=1.1.0, org.osgi.framework.launch; version=1.2.0, org.osgi.framework.namespace; version=1.1.0, org.osgi.framework.startlevel; version=1.0.0, org.osgi.framework.startlevel.dto; version=1.0.0, org.osgi.framework.wiring; version=1.2.0, org.osgi.framework.wiring.dto; version=1.2.0, org.osgi.resource; version=1.0.0, org.osgi.resource.dto; version=1.0.0, org.osgi.service.packageadmin; version=1.2.0, org.osgi.service.resolver; version=1.0.0, org.osgi.service.startlevel; version=1.1.0, org.osgi.service.url; version=1.0.0
+  osgi-compendium-services=org.osgi.util.tracker; version=1.5.1
+  jre-1.8=javax.accessibility;uses:="javax.swing.text";version="0.0.0.1_008_JavaSE", javax.activity;version="0.0.0.1_008_JavaSE", javax.annotation.processing;uses:="javax.tools,javax.lang.model,javax.lang.model.element,javax.lang.model.util";version="0.0.0.1_008_JavaSE", javax.annotation;version="0.0.0.1_008_JavaSE", javax.crypto.interfaces;uses:="javax.crypto.spec,javax.crypto";version="0.0.0.1_008_JavaSE", javax.crypto.spec;uses:="javax.crypto";version="0.0.0.1_008_JavaSE", javax.crypto;uses:="javax.crypto.spec";version="0.0.0.1_008_JavaSE", javax.imageio.event;uses:="javax.imageio";version="0.0.0.1_008_JavaSE", javax.imageio.metadata;uses:="org.w3c.dom,javax.imageio";version="0.0.0.1_008_JavaSE", javax.imageio.plugins.bmp;uses:="javax.imageio";version="0.0.0.1_008_JavaSE", javax.imageio.plugins.jpeg;uses:="javax.imageio";version="0.0.0.1_008_JavaSE", javax.imageio.spi;uses:="javax.imageio.stream,javax.imageio,javax.imageio.metadata";version="0.0.0.1_008_JavaSE", javax.imageio.str
 eam;uses:="javax.imageio";version="0.0.0.1_008_JavaSE", javax.imageio;uses:="javax.imageio.metadata,javax.imageio.stream,javax.imageio.spi,javax.imageio.event";version="0.0.0.1_008_JavaSE", javax.lang.model.element;uses:="javax.lang.model.type,javax.lang.model";version="0.0.0.1_008_JavaSE", javax.lang.model.type;uses:="javax.lang.model.element,javax.lang.model";version="0.0.0.1_008_JavaSE", javax.lang.model.util;uses:="javax.lang.model,javax.lang.model.element,javax.annotation.processing,javax.lang.model.type";version="0.0.0.1_008_JavaSE", javax.lang.model;version="0.0.0.1_008_JavaSE", javax.management.loading;uses:="javax.management";version="0.0.0.1_008_JavaSE", javax.management.modelmbean;uses:="javax.management,javax.management.loading";version="0.0.0.1_008_JavaSE", javax.management.monitor;uses:="javax.management";version="0.0.0.1_008_JavaSE", javax.management.openmbean;uses:="javax.management";version="0.0.0.1_008_JavaSE", javax.management.relation;uses:="javax.management";ver
 sion="0.0.0.1_008_JavaSE", javax.management.remote.rmi;uses:="javax.management.remote,javax.security.auth,javax.management,javax.management.loading,javax.naming,javax.rmi.ssl,org.omg.CORBA,org.omg.CORBA_2_3.portable,org.omg.CORBA.portable,javax.rmi.CORBA,javax.rmi";version="0.0.0.1_008_JavaSE", javax.management.remote;uses:="javax.security.auth,javax.management";version="0.0.0.1_008_JavaSE", javax.management.timer;uses:="javax.management";version="0.0.0.1_008_JavaSE", javax.management;uses:="javax.management.loading,javax.management.openmbean";version="0.0.0.1_008_JavaSE", javax.naming.directory;uses:="javax.naming";version="0.0.0.1_008_JavaSE", javax.naming.event;uses:="javax.naming,javax.naming.directory";version="0.0.0.1_008_JavaSE", javax.naming.ldap;uses:="javax.naming,javax.naming.directory,javax.net.ssl,javax.naming.event";version="0.0.0.1_008_JavaSE", javax.naming.spi;uses:="javax.naming,javax.naming.directory";version="0.0.0.1_008_JavaSE", javax.naming;uses:="javax.naming.s
 pi";version="0.0.0.1_008_JavaSE", javax.net.ssl;uses:="javax.security.cert,javax.security.auth.x500,javax.net";version="0.0.0.1_008_JavaSE", javax.net;version="0.0.0.1_008_JavaSE", javax.print.attribute.standard;uses:="javax.print.attribute";version="0.0.0.1_008_JavaSE", javax.print.attribute;version="0.0.0.1_008_JavaSE", javax.print.event;uses:="javax.print,javax.print.attribute";version="0.0.0.1_008_JavaSE", javax.print;uses:="javax.print.attribute,javax.print.event,javax.print.attribute.standard";version="0.0.0.1_008_JavaSE", javax.rmi.CORBA;uses:="org.omg.CORBA,org.omg.CORBA_2_3.portable,org.omg.CORBA.portable,org.omg.SendingContext";version="0.0.0.1_008_JavaSE", javax.rmi.ssl;uses:="javax.net,javax.net.ssl";version="0.0.0.1_008_JavaSE", javax.rmi;uses:="org.omg.CORBA,javax.rmi.CORBA";version="0.0.0.1_008_JavaSE", javax.script;version="0.0.0.1_008_JavaSE", javax.security.auth.callback;version="0.0.0.1_008_JavaSE", javax.security.auth.kerberos;uses:="javax.security.auth,javax.cry
 pto";version="0.0.0.1_008_JavaSE", javax.security.auth.login;uses:="javax.security.auth,javax.security.auth.callback";version="0.0.0.1_008_JavaSE", javax.security.auth.spi;uses:="javax.security.auth.callback,javax.security.auth.login,javax.security.auth";version="0.0.0.1_008_JavaSE", javax.security.auth.x500;uses:="javax.security.auth";version="0.0.0.1_008_JavaSE", javax.security.auth;version="0.0.0.1_008_JavaSE", javax.security.cert;version="0.0.0.1_008_JavaSE", javax.security.sasl;uses:="javax.security.auth.callback";version="0.0.0.1_008_JavaSE", javax.sound.midi.spi;uses:="javax.sound.midi";version="0.0.0.1_008_JavaSE", javax.sound.midi;uses:="javax.sound.midi.spi";version="0.0.0.1_008_JavaSE", javax.sound.sampled.spi;uses:="javax.sound.sampled";version="0.0.0.1_008_JavaSE", javax.sound.sampled;uses:="javax.sound.sampled.spi";version="0.0.0.1_008_JavaSE", javax.sql.rowset.serial;uses:="javax.sql.rowset";version="0.0.0.1_008_JavaSE", javax.sql.rowset.spi;uses:="javax.sql,javax.nam
 ing,javax.sql.rowset";version="0.0.0.1_008_JavaSE", javax.sql.rowset;uses:="javax.sql,javax.sql.rowset.serial,javax.sql.rowset.spi";version="0.0.0.1_008_JavaSE", javax.sql;uses:="javax.transaction.xa";version="0.0.0.1_008_JavaSE", javax.swing.border;uses:="javax.swing";version="0.0.0.1_008_JavaSE", javax.swing.colorchooser;uses:="javax.swing,javax.swing.border,javax.swing.event,javax.swing.text";version="0.0.0.1_008_JavaSE", javax.swing.event;uses:="javax.swing,javax.swing.text,javax.swing.table,javax.swing.tree,javax.swing.undo";version="0.0.0.1_008_JavaSE", javax.swing.filechooser;uses:="javax.swing";version="0.0.0.1_008_JavaSE", javax.swing.plaf.basic;uses:="javax.swing.border,javax.swing,javax.swing.plaf,javax.swing.text,javax.swing.event,javax.swing.colorchooser,javax.accessibility,javax.swing.filechooser,javax.swing.text.html,javax.sound.sampled,javax.swing.table,javax.swing.plaf.synth,javax.swing.tree";version="0.0.0.1_008_JavaSE", javax.swing.plaf.metal;uses:="javax.swing.pl
 af,javax.swing,javax.swing.border,javax.swing.text,javax.swing.plaf.basic,javax.swing.filechooser,javax.swing.event,javax.swing.tree";version="0.0.0.1_008_JavaSE", javax.swing.plaf.multi;uses:="javax.accessibility,javax.swing,javax.swing.plaf,javax.swing.filechooser,javax.swing.text,javax.swing.tree";version="0.0.0.1_008_JavaSE", javax.swing.plaf.nimbus;uses:="javax.swing,javax.swing.plaf,javax.swing.border,javax.swing.plaf.synth";version="0.0.0.1_008_JavaSE", javax.swing.plaf.synth;uses:="javax.swing,javax.swing.plaf,javax.swing.text,javax.swing.border,javax.swing.plaf.basic,javax.swing.colorchooser,javax.swing.event,javax.xml.parsers,org.xml.sax,org.xml.sax.helpers,javax.swing.table,javax.swing.tree";version="0.0.0.1_008_JavaSE", javax.swing.plaf;uses:="javax.swing,javax.swing.border,javax.accessibility,javax.swing.filechooser,javax.swing.text,javax.swing.tree";version="0.0.0.1_008_JavaSE", javax.swing.table;uses:="javax.swing.event,javax.swing.plaf,javax.swing.border,javax.swing,
 javax.accessibility";version="0.0.0.1_008_JavaSE", javax.swing.text.html.parser;uses:="javax.swing.text,javax.swing.text.html";version="0.0.0.1_008_JavaSE", javax.swing.text.html;uses:="javax.swing.event,javax.swing.text,javax.accessibility,javax.swing,javax.swing.plaf,javax.swing.border,javax.swing.undo";version="0.0.0.1_008_JavaSE", javax.swing.text.rtf;uses:="javax.swing.text";version="0.0.0.1_008_JavaSE", javax.swing.text;uses:="javax.swing.event,javax.swing.tree,javax.swing.undo,javax.swing,javax.swing.plaf,javax.swing.plaf.basic,javax.print,javax.print.attribute,javax.accessibility,javax.swing.text.html";version="0.0.0.1_008_JavaSE", javax.swing.tree;uses:="javax.swing.event,javax.swing,javax.swing.border,javax.swing.plaf,javax.swing.plaf.basic";version="0.0.0.1_008_JavaSE", javax.swing.undo;uses:="javax.swing,javax.swing.event";version="0.0.0.1_008_JavaSE", javax.swing;uses:="javax.swing.event,javax.accessibility,javax.swing.text,javax.swing.plaf,javax.swing.border,javax.swin
 g.tree,javax.swing.table,javax.swing.colorchooser,javax.swing.plaf.basic,javax.swing.text.html,javax.swing.filechooser,javax.print,javax.print.attribute,javax.swing.plaf.metal";version="0.0.0.1_008_JavaSE", javax.tools;uses:="javax.lang.model.element,javax.annotation.processing,javax.lang.model";version="0.0.0.1_008_JavaSE", org.ietf.jgss;version="0.0.0.1_008_JavaSE", org.omg.CORBA.DynAnyPackage;uses:="org.omg.CORBA";version="0.0.0.1_008_JavaSE", org.omg.CORBA.ORBPackage;uses:="org.omg.CORBA";version="0.0.0.1_008_JavaSE", org.omg.CORBA.TypeCodePackage;uses:="org.omg.CORBA";version="0.0.0.1_008_JavaSE", org.omg.CORBA.portable;uses:="org.omg.CORBA,org.omg.CORBA_2_3.portable";version="0.0.0.1_008_JavaSE", org.omg.CORBA;uses:="org.omg.CORBA.portable,org.omg.CORBA.DynAnyPackage,org.omg.CORBA.ORBPackage,org.omg.CORBA_2_3.portable,org.omg.CORBA.TypeCodePackage";version="0.0.0.1_008_JavaSE", org.omg.CORBA_2_3.portable;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE"
 , org.omg.CORBA_2_3;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.CosNaming.NamingContextExtPackage;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", =.omg.CosNaming.NamingContextPackage;uses:="org.omg.CORBA,org.omg.CORBA.portable,org.omg.CosNaming";version="0.0.0.1_008_JavaSE", org.omg.CosNaming;uses:="org.omg.CORBA.portable,org.omg.CORBA,org.omg.PortableServer,org.omg.CosNaming.NamingContextPackage,org.omg.CosNaming.NamingContextExtPackage";version="0.0.0.1_008_JavaSE", org.omg.Dynamic;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.DynamicAny.DynAnyFactoryPackage;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.DynamicAny.DynAnyPackage;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.DynamicAny;uses:="org.omg.CORBA,org.omg.CORBA.portable,org.omg.DynamicAny.DynAnyFactoryPackage,org.omg.DynamicAny.DynAnyPackage";version
 ="0.0.0.1_008_JavaSE", org.omg.IOP.CodecFactoryPackage;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.IOP.CodecPackage;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.IOP;uses:="org.omg.CORBA,org.omg.CORBA.portable,org.omg.IOP.CodecFactoryPackage,org.omg.IOP.CodecPackage";version="0.0.0.1_008_JavaSE", org.omg.Messaging;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.PortableInterceptor.ORBInitInfoPackage;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.PortableInterceptor;uses:="org.omg.CORBA,org.omg.CORBA.portable,org.omg.IOP,org.omg.PortableInterceptor.ORBInitInfoPackage,org.omg.CORBA_2_3.portable,org.omg.Dynamic";version="0.0.0.1_008_JavaSE", org.omg.PortableServer.CurrentPackage;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.PortableServer.POAManagerPackage;uses:="org.omg.CORBA,org.omg.CORBA.portable";vers
 ion="0.0.0.1_008_JavaSE", org.omg.PortableServer.POAPackage;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.PortableServer.ServantLocatorPackage;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.PortableServer.portable;uses:="org.omg.CORBA,org.omg.PortableServer";version="0.0.0.1_008_JavaSE", org.omg.PortableServer;uses:="org.omg.CORBA,org.omg.CORBA.portable,org.omg.PortableServer.CurrentPackage,org.omg.PortableServer.POAManagerPackage,org.omg.PortableServer.POAPackage,org.omg.PortableServer.portable,org.omg.CORBA_2_3,org.omg.PortableServer.ServantLocatorPackage";version="0.0.0.1_008_JavaSE", org.omg.SendingContext;uses:="org.omg.CORBA,org.omg.CORBA.portable";version="0.0.0.1_008_JavaSE", org.omg.stub.java.rmi;uses:="javax.rmi.CORBA";version="0.0.0.1_008_JavaSE"
+  system-customise= javax.xml.namespace, javax.xml.parsers, javax.xml.xpath, javax.xml.transform, javax.transaction, javax.transaction.xa, javax.xml.transform.dom, javax.xml.transform.stream, org.xml.sax, org.w3c.dom
+
+
+[settings]
+  org.osgi.service.http.port = ${http.port}
+  org.osgi.framework.storage = ${osgi.storage.path}
+  org.osgi.framework.startlevel.beginning = ${osgi.start.level}
+  org.osgi.framework.system.packages=${osgi-core-packages}, ${osgi-compendium-services}, ${jre-1.8}, ${system-customise}
+
+  
+[artifacts]
+  org.apache.felix/org.apache.felix.framework/${felix.framework.version}
+  org.slf4j/slf4j-api/${slf4j.version}
+  org.slf4j/slf4j-simple/${slf4j.version}

Propchange: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/crankstart-model.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/crankstart-model.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/base.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/base.txt?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/base.txt (added)
+++ sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/base.txt Wed Jul 27 12:10:12 2016
@@ -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.
+#
+# This is a feature description
+#
+# A feature consists of variables and run mode dependent artifacts.
+#
+
+# Test our Sling extension commands, that add a bundle via the Sling installer
+# (which requires commons.json and jcr-wrapper)
+[feature name=crankstart.test.base]
+
+[variables]
+  felix.http.jetty.version=2.2.0
+
+[artifacts]
+  # artifacts that are usually provided by the Sling launchpad
+  org.apache.sling/org.apache.sling.launchpad.api/1.1.0
+  org.apache.felix/org.apache.felix.http.jetty/${felix.http.jetty.version}
+  org.apache.felix/org.apache.felix.eventadmin/1.3.2
+  org.apache.felix/org.apache.felix.scr/1.8.2
+  org.apache.felix/org.apache.felix.metatype/1.0.10
+  org.apache.sling/org.apache.sling.commons.osgi/2.2.0
+  org.apache.sling/org.apache.sling.commons.log/2.1.2
+  org.apache.felix/org.apache.felix.configadmin/1.6.0
+  org.apache.felix/org.apache.felix.webconsole/3.1.6

Propchange: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/base.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/base.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/crankstart-test-support.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/crankstart-test-support.txt?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/crankstart-test-support.txt (added)
+++ sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/crankstart-test-support.txt Wed Jul 27 12:10:12 2016
@@ -0,0 +1,29 @@
+#
+#  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.
+#
+
+[feature name=crankstart.test.support]
+
+[artifacts]
+  org.apache.sling/org.apache.sling.jcr.jcr-wrapper/2.0.0
+  org.apache.sling/org.apache.sling.commons.json/2.0.6
+  org.apache.sling/org.apache.sling.junit.core/1.0.10
+  org.apache.sling/org.apache.sling.commons.mime/2.1.8
+  org.apache.sling/org.apache.sling.settings/1.3.6
+
+

Propchange: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/crankstart-test-support.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/crankstart-test-support.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/jobs-runtime.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/jobs-runtime.txt?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/jobs-runtime.txt (added)
+++ sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/jobs-runtime.txt Wed Jul 27 12:10:12 2016
@@ -0,0 +1,42 @@
+#
+#  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.
+#
+# Load this bundle to run tests, it built with mvn clean install after each test.
+
+[feature name=sling.extensions.jobs]
+
+[artifacts]
+  com.google.code.gson/gson/2.2.4
+  org.apache.geronimo.specs/geronimo-j2ee-management_1.1_spec/1.0.1
+  org.apache.geronimo.specs/geronimo-jms_1.1_spec/1.1.1
+  org.ow2.asm/asm/4.1
+  com.google.guava/guava/16.0.1
+  org.apache.commons/commons-pool2/2.4.2
+  org.apache.sling/org.apache.sling.mom/0.0.1-SNAPSHOT
+  org.apache.sling/org.apache.sling.jobs/0.0.1-SNAPSHOT
+  org.apache.sling/org.apache.sling.jms/0.0.1-SNAPSHOT
+  org.apache.sling/org.apache.sling.jobs-it-services/0.0.1-SNAPSHOT
+
+[configurations]
+  # Configure a queue to listen to the queue used in the IT Services components.
+  # In general a queue should only be activated on an instance if the
+  # instance is configured with consumers for that queue.
+  # If consumers are not present, then the queue will dequeue and force a retry
+  # of each item it can process untill the retry limit is reached.
+  org.apache.sling.jobs.impl.JobQueueConsumerFactory
+  queue-name="org/apache/sling/jobs/it/services"

Propchange: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/jobs-runtime.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/provisioning-model/jobs-runtime.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/sling-launchpad.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/sling-launchpad.txt?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/sling-launchpad.txt (added)
+++ sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/sling-launchpad.txt Wed Jul 27 12:10:12 2016
@@ -0,0 +1,65 @@
+#
+#  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.
+#
+
+# Start the Sling Launchpad including whatever is required to
+# run the Sling integration tests.
+#
+# Currently all those 529 tests pass if started with
+#  java  -Xmx1G  -XX:MaxPermSize=256m \
+#   -Dsling.run.modes=:standalone,jackrabbit -Dsling.home=CRANKSTART \
+#   -jar target/org.apache.sling.crankstart.launcher-1.9.9-SNAPSHOT.jar \
+#   src/test/resources/crankstart-model.txt \
+#   src/test/resources/sling-launchpad.txt
+ 
+[feature name=sling.launchpad]
+
+[settings]
+  org.apache.sling.commons.log.julenabled=true
+  
+[artifacts]
+  # karaf bunde provides Sling Launchpad startup services
+  org.apache.sling/org.apache.sling.launchpad.karaf/0.1.1-SNAPSHOT
+  
+  # artifacts that are usually provided by the Sling launchpad
+   org.apache.sling/org.apache.sling.launchpad.api/1.1.0
+  
+  # The launchpad itself
+  org.apache.sling/org.apache.sling.launchpad/8/txt/slingfeature
+  
+  # Sling integration tests support
+  # TODO problem with the test-service bundles with 2 run modes
+  # org.apache.sling/org.apache.sling.launchpad.test-bundles/0.0.1-SNAPSHOT/txt
+  
+# TODO remove those once nested test-bundles model works
+[artifacts startLevel=2]
+  org.apache.sling/org.apache.sling.servlets.compat/1.0.3-SNAPSHOT
+  org.apache.sling/org.apache.sling.junit.core/1.0.11-SNAPSHOT
+  org.apache.sling/org.apache.sling.junit.remote/1.0.11-SNAPSHOT
+  org.apache.sling/org.apache.sling.junit.scriptable/1.0.11-SNAPSHOT
+  org.apache.sling/org.apache.sling.launchpad.test-fragment/2.0.9-SNAPSHOT
+  org.apache.sling/org.apache.sling.launchpad.test-services-war/2.0.8/war
+  org.apache.sling/org.apache.sling.launchpad.test-services/2.0.9-SNAPSHOT
+    
+[configurations]
+  integrationTestsConfig
+    message="This test config should be loaded at startup"
+
+  org.apache.sling.servlets.resolver.SlingServletResolver
+    # Set the servlet resolver's cache size to zero for testing
+    servletresolver.cacheSize=I"0"

Propchange: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/sling-launchpad.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/commons/mom/examples/jobs/it/src/test/resources/sling-launchpad.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/contrib/commons/mom/jms/.gitignore
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/jms/.gitignore?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/jms/.gitignore (added)
+++ sling/trunk/contrib/commons/mom/jms/.gitignore Wed Jul 27 12:10:12 2016
@@ -0,0 +1 @@
+activemq-data

Added: sling/trunk/contrib/commons/mom/jms/README.md
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/jms/README.md?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/jms/README.md (added)
+++ sling/trunk/contrib/commons/mom/jms/README.md Wed Jul 27 12:10:12 2016
@@ -0,0 +1,79 @@
+# Message Oriented Middleware API implementation using Active MQ.
+
+This bundle implements the MoM API using Active MQ. It supports both Pub/Sub and Queue patterns and will run out of the
+box, embedded or connected to a dedicated cluster.
+
+## Out of the Box.
+
+As the name suggests, no configuration is required, the components will start, create an ActiveMQ instance embedded inside
+the OSGi container and run. On restart, normal or after a crash, provided the working directory is not changed or modified, 
+the ActiveMQ embedded server will restart and resume operations. In the event the JVM crashes, ActiveMQ will perform recovery
+ by replaying its journal. The embedded server uses KahaDB to store data on local disk.
+ 
+## Embedded with custom configuration.
+
+AMQ can be run embedded with custom configuration to allow a cluster of Sling instances for form a multi master AMQ cluster with each 
+Sling instance embedding its own AMQ broker. This is achieved via OSGi configuration. (ToDo: Config + Doc)
+
+## External AMQ Broker cluster.
+
+The bundle can be run to use an external AMQ Broker cluster, maintained and setup separately from the Sling cluster. To do this, modify the
+Broker URL via OSGi configuration.
+
+# Implementation details.
+
+## AMQ ConnectionFactory.
+
+Running AMQ inside OSGi is very simple. All that is required is the AMQ dependencies, and instancing an AQM PooledConnectionFactory with a
+default localhost url. vm://localhost:61616. The PooledConnectionFactory will trigger the creation of an AMQ Broker if one is not present
+and AMQ will run normally. This service implements an internal service API org.apache.sling.jms.ConnectionFactoryService, which enables 
+consumers to get a JMS ConnectionFactory.
+
+## MoM API implementation
+
+The MoM API implementation uses the ConnectionFactory service to get a JMS connection. It opens JMS sessions using that connection factory
+and implements the methods in the API. JMS Support both Pub/Sub and Queue patterns in the MoM API without much additional work. 
+The JMS sessions are single threaded, so care is taken not to share between threads or cause throughput issues with synchronization.
+
+The Map of Map messages in the MoM API are serialised to Json using the Gson library and transmitted as Text messages. JMS Headers are currently
+not used other than to identify the JSON encoding of the text payload.
+
+The delivery of messages on Topics and Queues is entirely managed by AMQ with no additional code. The retry semantics of the QueueReader API
+is achieved by dispatching JMS messages from within a JMS MessageListener onMessage method, and throwing an IllegalArgumentException to JMS
+when a message needs to be re-queued. How retries work and the backoff algorithm used for messages that need to be retried is managed 
+by ActiveMQ configuration which supports many scenarios for retrying messages.
+
+## Delivery Retry for Queued messages
+
+The semantics of the MoM API is that a consumer may throw an exception when its QueueReader.onMessage method is called. That indicates that the 
+message could not be consumed at this time and should be retried. There are several ways that this can be achieved in general, and some 
+AMQ specific ways. By default JMS ensures delivery order. Hence a message on the queue that is not dequeued, will block other messages on the queue 
+until it is dequeued. AMQ deals with this by allowing a deployyer to configure queues to retry at the broker rather than attempting to redeliver in 
+order to the same JMS consumer. The configuration is not default and has to be provided by configuring the AMQ broker.
+
+    <broker xmlns="http://activemq.apache.org/schema/core"    schedulerSupport="true" >
+        .... 
+        <plugins>
+            <redeliveryPlugin fallbackToDeadLetter="true" sendToDlqIfMaxRetriesExceeded="true">
+                <redeliveryPolicyMap>
+                    <redeliveryPolicyMap>
+                        <redeliveryPolicyEntries>
+                            <!-- a destination specific policy -->
+                            <redeliveryPolicy queue="SpecialQueue" maximumRedeliveries="4" redeliveryDelay="10000" />
+                        </redeliveryPolicyEntries>
+                        <!-- the fallback policy for all other destinations -->
+                        <defaultEntry>
+                            <redeliveryPolicy maximumRedeliveries="4" initialRedeliveryDelay="5000" redeliveryDelay="10000" />
+                        </defaultEntry>
+                    </redeliveryPolicyMap>
+                </redeliveryPolicyMap>
+            </redeliveryPlugin>
+        </plugins>
+        
+This can also be achieved in code, by dequeing all messages regardless of failiure or not. Those generate an exception on dequeued get requeued. If the size of the 
+queue is so large as to significantly impact processing due to delays in processing the queue, then an alternative approach is to requeue to a special retry queue, ensuring
+that retries get a higher level of priority. This may not be necessary, as retries happen due to unavailability, and if the queue is long, then resources will be
+available, so no retry. If the queue is short, then the re-queue time is minimal. The approach is quite simular to the approach used in AMQ 5.7 and later, although
+it will work with any JMS provider.
+
+The code base is currently configured to use and explicit dequeue and requeue approach that does not depend on features of the JMS provider.
\ No newline at end of file

Propchange: sling/trunk/contrib/commons/mom/jms/README.md
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/commons/mom/jms/README.md
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/contrib/commons/mom/jms/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/jms/pom.xml?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/jms/pom.xml (added)
+++ sling/trunk/contrib/commons/mom/jms/pom.xml Wed Jul 27 12:10:12 2016
@@ -0,0 +1,237 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>26</version>
+        <relativePath />
+    </parent>
+
+    <artifactId>org.apache.sling.jms</artifactId>
+    <packaging>bundle</packaging>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <name>Apache Sling MoM Implementation using JMS with AMQ</name>
+    <description>
+        Provides a JMS Connection provider that works OOTB in a cluster or uses a pre-existing AMQ endpoint depending on the configuration.
+    </description>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/commons/mom/jms</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/commons/mom/jms</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/jms</url>
+    </scm>
+
+    <properties>
+        <site.jira.version.id>12315369</site.jira.version.id>
+        <sling.java.version>7</sling.java.version>
+        <exam.version>4.4.0</exam.version>
+        <url.version>2.4.5</url.version>
+        <bundle.build.dir>${basedir}/target</bundle.build.dir>
+        <bundle.file.name>${bundle.build.dir}/${project.build.finalName}.jar</bundle.file.name>
+        <min.port>37000</min.port>
+        <max.port>37999</max.port>
+    </properties>
+
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Embed-Dependency>
+                            activemq-broker,
+                            activemq-client,
+                            activemq-pool,
+                            activemq-protobuf,
+                            activemq-kahadb-store,
+                            activemq-jms-pool,
+                            hawtbuf</Embed-Dependency>
+                        <Import-Package>
+                            org.apache.activemq.jaas*;resolution:=optional,
+                            org.apache.commons.net.ftp*;resolution:=optional,
+                            org.apache.geronimo.transaction*;resolution:=optional,
+                            org.fusesource.hawtbuf*;resolution:=optional,
+                            org.apache.commons.pool2*;resolution:=optional,
+                            javax.jmdns*;resolution:=optional,
+                            !org.apache.maven*,
+                            *
+
+                        </Import-Package>
+                        <!--
+                        <Import-Package>com.thoughtworks.xstream*;resolution:=optional,
+                            org.apache.activeio*;resolution:=optional,
+                            org.apache.commons.pool*;resolution:=optional,
+                            org.apache.derby*;resolution:=optional,
+                            org.apache.tools.ant*;resolution:=optional,
+                            org.apache.maven*;resolution:=optional,
+                            org.apache.xbean*;resolution:=optional,
+                            '=org.apache.xbean.spring.context.v2;resolution:=optional',
+                            org.apache.xpath*;resolution:=optional,
+                            org.codehaus.jam*;resolution:=optional,
+                            org.springframework*;resolution:=optional,
+                            org.springframework.beans.factory.xml;resolution:=optional,
+                            org.w3c.dom.traversal*;resolution:=optional,
+                            org.apache.commons.net*;resolution:=optional,
+                            org.apache.kahadb*;resolution:=optional,
+                            org.apache.activemq.ra*;resolution:=optional,
+                            org.apache.geronimo.transaction.manager*;resolution:=optional,
+                            *
+                        </Import-Package>
+                        -->
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <exclude>activemq-data/**</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <reporting>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <configuration>
+                    <excludePackageNames>
+                    </excludePackageNames>
+                </configuration>
+            </plugin>
+        </plugins>
+    </reporting>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.mom</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <!-- ActiveMQ -->
+        <!-- The released OSGi bindle contains a bleuprint config with an invalid import that cant be satisfied without a custom
+         bundle, hence these will be embeded. -->
+        <dependency>
+            <groupId>org.apache.activemq</groupId>
+            <artifactId>activemq-broker</artifactId>
+            <version>5.13.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.activemq</groupId>
+            <artifactId>activemq-client</artifactId>
+            <version>5.13.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.activemq</groupId>
+            <artifactId>activemq-pool</artifactId>
+            <version>5.13.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.activemq</groupId>
+            <artifactId>activemq-jms-pool</artifactId>
+            <version>5.13.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.activemq</groupId>
+            <artifactId>activemq-kahadb-store</artifactId>
+            <version>5.13.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.activemq.protobuf</groupId>
+            <artifactId>activemq-protobuf</artifactId>
+            <version>1.1</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.fusesource.hawtbuf</groupId>
+            <artifactId>hawtbuf</artifactId>
+            <version>1.11</version>
+            <scope>provided</scope>
+        </dependency>
+
+
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>2.2.4</version>
+            <scope>provided</scope>
+        </dependency>
+
+
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <version>6.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.api</artifactId>
+            <version>2.4.0</version>
+            <scope>provided</scope>
+        </dependency>
+      <!-- Testing -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <version>1.10.19</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

Propchange: sling/trunk/contrib/commons/mom/jms/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/commons/mom/jms/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/amq/ActiveMQConnectionFactoryService.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/amq/ActiveMQConnectionFactoryService.java?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/amq/ActiveMQConnectionFactoryService.java (added)
+++ sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/amq/ActiveMQConnectionFactoryService.java Wed Jul 27 12:10:12 2016
@@ -0,0 +1,106 @@
+/*
+ * 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.amq;
+
+import org.apache.activemq.pool.PooledConnectionFactory;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.jms.ConnectionFactoryService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+
+import javax.jms.ConnectionFactory;
+
+/**
+ * Creates a ConnectionFactoryService that makes a pooled  JMS ConnectionFactory available to consumers. The implementation
+ * of JMS is provided by ActiveMQ in this instances. If the component is left un-configured it will connection to vm://localhost:6161.
+ * If no server is present at that address, the component will create a standalone ActiveMQ broker on startup. Without additional
+ * configuration that AMQ Broker will operate standalone. With configuration it is possible to configure the broker to become
+ * a member of a multi master AMQ Broker network. Alternatively if a dedicated AMQ Broker is required the jms.brokerUrl configuration
+ * setting should be adjusted to point to that broker.
+ *
+ * This component works OOTB and in Unit tests with no further action.
+ *
+ * The jms.brokerUrl allows configuration of the broker in any way that ActiveMQ allows, including xbean and broker.
+ *
+ *
+ * Available URI patterns.
+ *
+ * xbean:org/apache/sling/amq/activemq.xml will result in the Broker searching for org/apache/sling/amq/activemq.xml in
+ * the classpath and using that to configure the Borker, see http://activemq.apache.org/xml-configuration.html for details
+ * of the format. See that location for an example of the default configuration.
+ *
+ *
+ *
+ * broker:tcp://localhost:61616 will create a broker on localhost port 61616 using the URI configuration format.
+ * See http://activemq.apache.org/broker-configuration-uri.html and http://activemq.apache.org/broker-uri.html for
+ * details of the format.
+ *
+ * properties:/foo/bar.properties uses a properties file as per http://activemq.apache.org/broker-properties-uri.html
+ *
+ */
+@Component(immediate = true, metatype = true)
+@Service(value=ConnectionFactoryService.class)
+public class ActiveMQConnectionFactoryService implements ConnectionFactoryService {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ActiveMQConnectionFactoryService.class);
+    private PooledConnectionFactory pooledConnectionFactory;
+
+    // Where the broker is configured out of the box, the shutdown hook must be disabled.
+    // so that the deactivate method can perform the shutdown.
+    // This assumes that OSGi does shutdown properly.
+
+    public static final String DEFAULT_BROKER_URI = "vm://localhost:61616?broker.useShutdownHook=false";
+    @Property(value = DEFAULT_BROKER_URI)
+    public static final String BROKER_URI = "jms.brokerUri";
+
+
+
+
+    @Activate
+    public void activate(Map<String, Object> props) {
+
+        String brokerURL = (String) props.get(BROKER_URI);
+
+        pooledConnectionFactory = new PooledConnectionFactory(brokerURL);
+        pooledConnectionFactory.start();
+    }
+
+
+    @Deactivate
+    public void deactivate(Map<String, Object> props) {
+
+        LOGGER.info("Stopping ActiveMQ Pooled connection factory");
+        pooledConnectionFactory.stop();
+        pooledConnectionFactory = null;
+    }
+
+
+
+    @Override
+    public ConnectionFactory getConnectionFactory() {
+        return pooledConnectionFactory;
+    }
+
+}
\ No newline at end of file

Propchange: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/amq/ActiveMQConnectionFactoryService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/ConnectionFactoryService.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/ConnectionFactoryService.java?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/ConnectionFactoryService.java (added)
+++ sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/ConnectionFactoryService.java Wed Jul 27 12:10:12 2016
@@ -0,0 +1,36 @@
+/*
+ * 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.jms;
+
+import javax.jms.ConnectionFactory;
+
+/**
+ * Created by ieb on 30/03/2016.
+ * Implementations of this service provide JMS Connection factories. In general implementations should work OOTB with no
+ * further configuration and provide an efficient JMS Connection Factory that allows sessions to be created with minimal
+ * overhead.
+ */
+public interface ConnectionFactoryService {
+    /**
+     *
+     * Get a connection factory.
+     * @return the connection factory.
+     */
+    ConnectionFactory getConnectionFactory();
+}

Propchange: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/ConnectionFactoryService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSMessageTypes.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSMessageTypes.java?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSMessageTypes.java (added)
+++ sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSMessageTypes.java Wed Jul 27 12:10:12 2016
@@ -0,0 +1,29 @@
+/*
+ * 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.jms;
+
+/**
+ * Created by ieb on 04/04/2016.
+ */
+public enum JMSMessageTypes {
+    /**
+     * A text message containing json.
+     */
+    JSON
+}

Propchange: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSMessageTypes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSQueueManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSQueueManager.java?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSQueueManager.java (added)
+++ sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSQueueManager.java Wed Jul 27 12:10:12 2016
@@ -0,0 +1,289 @@
+/*
+ * 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.jms;
+
+import org.apache.felix.scr.annotations.*;
+import org.apache.sling.mom.*;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nonnull;
+import javax.jms.*;
+import java.io.Closeable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Created by ieb on 30/03/2016.
+ * A JMS implementation of a QueueManager. It will allow callers to add messages to named queues, and consumers to read
+ * messages from named queues in order. The component uses a single connection to the JMS broker, but dedicated sessions
+ * for each send and for each Queue reader.
+ */
+@Component(immediate = true)
+@Service(value = QueueManager.class)
+public class JMSQueueManager implements QueueManager {
+
+
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(JMSQueueManager.class);
+    private static final String NRETRIES = "_nr";
+
+    @Reference
+    private ConnectionFactoryService connectionFactoryService;
+
+
+    /**
+     * Holds all QueueReader registrations.
+     */
+    @Reference(referenceInterface = QueueReader.class,
+            cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
+            policy = ReferencePolicy.DYNAMIC,
+            bind="addReader",
+            unbind="removeReader")
+    private final Map<ServiceReference<QueueReader>, QueueReaderHolder> registrations =
+            new ConcurrentHashMap<ServiceReference<QueueReader>, QueueReaderHolder>();
+
+    private Connection connection;
+
+    @Activate
+    public synchronized void activate(Map<String, Object> properties) throws JMSException {
+        connection = connectionFactoryService.getConnectionFactory().createConnection();
+        connection.start();
+    }
+
+    @Deactivate
+    public synchronized void deactivate(Map<String, Object> properties) throws JMSException {
+        for ( Map.Entry<ServiceReference<QueueReader>, QueueReaderHolder> e : registrations.entrySet()) {
+            e.getValue().close();
+        }
+        registrations.clear();
+        connection.stop();
+        connection.close();
+    }
+
+
+
+    /**
+     * Add a message to the queue. The message is added to the queue transactionally and auto acknowledged.
+     * @param name the name of the queue.
+     * @param message the message to post to the queue.
+     */
+    @Override
+    public void add(@Nonnull Types.QueueName name, @Nonnull Map<String, Object> message) {
+        Session session = null;
+        try {
+            session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+            message.put(NRETRIES, 0L); // set the number of retries to 0.
+            TextMessage textMessage = session.createTextMessage(Json.toJson(message));
+            textMessage.setJMSType(JMSMessageTypes.JSON.toString());
+            LOGGER.info("Sending to {} message {} ", name, textMessage);
+            session.createProducer(session.createQueue(name.toString())).send(textMessage);
+            session.commit();
+            session.close();
+        } catch (JMSException e) {
+            LOGGER.error("Unable to send message to queue "+name, e);
+            close(session);
+
+        }
+
+    }
+
+
+    /**
+     * quietly close the session.
+     * @param session
+     */
+    private void close(Session session) {
+        if(session != null) {
+            try {
+                session.close();
+            } catch (JMSException e) {
+                LOGGER.warn("Unable to close session ",e);
+            }
+        }
+    }
+
+
+    // Register Readers using OSGi Whiteboard pattern
+    public synchronized  void addReader(ServiceReference<QueueReader> serviceRef) {
+        if (registrations.containsKey(serviceRef)) {
+            LOGGER.error("Registration for service reference is already present {}",serviceRef);
+            return;
+        }
+        QueueReaderHolder queueReaderHolder = new QueueReaderHolder(connection, serviceRef.getBundle().getBundleContext().getService(serviceRef), getServiceProperties(serviceRef));
+        registrations.put(serviceRef, queueReaderHolder);
+    }
+
+    private Map<String, Object> getServiceProperties(ServiceReference<QueueReader> serviceRef) {
+        Map<String, Object> m = new HashMap<String, Object>();
+        for ( String k : serviceRef.getPropertyKeys()) {
+            m.put(k, serviceRef.getProperty(k));
+        }
+        return Collections.unmodifiableMap(m);
+    }
+
+    public synchronized void removeReader(ServiceReference<QueueReader> serviceRef) {
+        QueueReaderHolder queueReaderHolder = registrations.remove(serviceRef);
+        if ( queueReaderHolder != null) {
+            queueReaderHolder.close();
+        }
+    }
+
+    private static class QueueReaderHolder implements Closeable {
+        private final JMSQueueSession session;
+
+        public QueueReaderHolder(Connection connection, QueueReader queueReader, Map<String, Object> properties) {
+            try {
+                LOGGER.info("Creating Queue holder for {} ", queueReader.getClass());
+                String name = (String) properties.get(QueueReader.QUEUE_NAME_PROP);
+                checkNotNull(name, "A valid queue name as property " + QueueReader.QUEUE_NAME_PROP + " is required for QueueReader registration");
+                if (queueReader instanceof MessageFilter) {
+                    session = new JMSQueueSession(connection, queueReader, name, (MessageFilter) queueReader, true, 5);
+                } else {
+                    session = new JMSQueueSession(connection, queueReader, name, new MessageFilter() {
+                        @Override
+                        public boolean accept(Types.Name name, Map<String, Object> mapMessage) {
+                            return true;
+                        }
+
+                    }, true, 5);
+
+                }
+            } catch (JMSException e) {
+                throw new IllegalArgumentException("Unable to register QueueReader with JMS ",e);
+            }
+
+        }
+
+        public void close() {
+            session.close();
+        }
+    }
+
+    private static void checkNotNull(Object v, String message) {
+        if ( v == null) {
+            throw new IllegalArgumentException(message);
+        }
+    }
+
+
+    public static class JMSQueueSession implements Closeable, MessageListener {
+        private static final Logger LOGGER = LoggerFactory.getLogger(JMSQueueSession.class);
+        private final QueueReader queueReader;
+        private final String name;
+        private final MessageFilter messageFilter;
+        private final Session session;
+        private final MessageConsumer queueConsumer;
+        private final MessageProducer queueProducer;
+        private boolean retryByRequeue;
+        private int maxRetries;
+
+        public JMSQueueSession(Connection connection, QueueReader queueReader, String name,  MessageFilter messageFilter, boolean retryByRequeue, int maxRetries) throws JMSException {
+            this.queueReader = queueReader;
+            this.name = name;
+            this.messageFilter = messageFilter;
+            this.retryByRequeue = retryByRequeue;
+            this.maxRetries = maxRetries;
+            session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+            Queue queue = session.createQueue(name);
+            queueConsumer = session.createConsumer(queue);
+            queueProducer = session.createProducer(queue);
+            queueConsumer.setMessageListener(this);
+        }
+
+        @Override
+        public void close() {
+            if ( queueConsumer != null) {
+                try {
+                    queueConsumer.close();
+                } catch (JMSException e) {
+                    LOGGER.warn("Failed to close queue consumer on "+name,e);
+                }
+            }
+            if ( session != null) {
+                try {
+                    session.close();
+                } catch (JMSException e) {
+                    LOGGER.warn("Failed to close queue session on " + name, e);
+                }
+            }
+
+        }
+
+        @Override
+        public void onMessage(Message message) {
+            boolean committed = false;
+            TextMessage textMessage = null;
+            try {
+                try {
+                    LOGGER.info("Got from {} message {} ", name, message);
+                    Destination destination = message.getJMSDestination();
+                    if (destination instanceof Queue) {
+                        Queue queue = (Queue) destination;
+                        if ( JMSMessageTypes.JSON.equals(JMSMessageTypes.valueOf(message.getJMSType()))) {
+                            textMessage = (TextMessage) message;
+                            final Map<String, Object> mapMessage = Json.toMap(textMessage.getText());
+                            Types.QueueName queueName = Types.queueName(queue.getQueueName());
+                            if (queueName.equals(name) && messageFilter.accept(queueName, mapMessage)) {
+                                queueReader.onMessage(queueName, mapMessage);
+                                session.commit();
+                                // all ok.
+                                committed = true;
+                                return;
+                            }
+                        }
+                    }
+                } catch (RequeueMessageException e) {
+                    LOGGER.info("QueueReader requested requeue of message ", e);
+                    if (retryByRequeue && textMessage != null) {
+                        Map<String, Object> mapMessage = Json.toMap(textMessage.getText());
+                        if ((int)mapMessage.get(NRETRIES) < maxRetries) {
+                            mapMessage.put(NRETRIES, ((long) mapMessage.get(NRETRIES)) + 1);
+                            TextMessage retryMessage = session.createTextMessage(Json.toJson(mapMessage));
+                            retryMessage.setJMSType(JMSMessageTypes.JSON.toString());
+                            LOGGER.info("Retrying message Sending to {} message {} ", name, textMessage);
+                            queueProducer.send(retryMessage);
+                            session.commit();
+                            committed = true;
+                            return;
+                        }
+                    }
+                }
+            } catch (JMSException e) {
+                LOGGER.info("Receive failed leaving to provider to require if required. ", e);
+            } finally {
+                try {
+                    if (!committed) {
+                        session.rollback();
+                    }
+                } catch (JMSException e) {
+                    LOGGER.info("QueueReader rollback failed. ",e);
+                }
+            }
+            // If onMessage throws an exception JMS will put the message back onto the queue.
+            // the delay before it gets retried is a JMS server configuration.
+            throw new IllegalArgumentException("Unable to process message, requeue");
+        }
+
+    }
+
+}

Propchange: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSQueueManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSTopicManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSTopicManager.java?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSTopicManager.java (added)
+++ sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSTopicManager.java Wed Jul 27 12:10:12 2016
@@ -0,0 +1,248 @@
+/*
+ * 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.jms;
+
+import org.apache.felix.scr.annotations.*;
+import org.apache.sling.mom.*;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nonnull;
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Created by ieb on 30/03/2016.
+ * This class provides support for sending messages to topics over JMS and subscribing to topics. It uses the ConnectionFactoryService
+ * to interact with JMS. There is nothing in
+ */
+@Component(immediate = true)
+@Service(value = TopicManager.class)
+public class JMSTopicManager implements TopicManager {
+
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(JMSTopicManager.class);
+
+
+    /**
+     * Holds all QueueReader registrations.
+     */
+    @Reference(referenceInterface = Subscriber.class,
+            cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
+            policy = ReferencePolicy.DYNAMIC,
+            bind="addSubscriber",
+            unbind="removeSubscriber")
+    private final Map<ServiceReference<Subscriber>, SubscriberHolder> registrations =
+            new ConcurrentHashMap<ServiceReference<Subscriber>, SubscriberHolder>();
+
+    @Reference
+    private ConnectionFactoryService connectionFactoryService;
+    // A single connection is maintained open per instance of this component.
+    private Connection connection;
+    // A single session is used for listening to messages. Separate sessions are opened for sending to avoid synchronisation on sending operations.
+    private Session session;
+    private final Object lock = new Object();
+
+    @Activate
+    public synchronized  void activate(Map<String, Object> properties) throws JMSException {
+            connection = connectionFactoryService.getConnectionFactory().createConnection();
+            session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+            connection.start();
+    }
+
+    @Deactivate
+    public synchronized  void deactivate(Map<String, Object> properties) throws JMSException {
+        for ( Map.Entry<ServiceReference<Subscriber>, SubscriberHolder> e : registrations.entrySet()) {
+            e.getValue().close();
+        }
+        registrations.clear();
+        // don't close the session, there is a bug in JMS which means an already closed session wont go quietly
+        // and the hook that shutsdown an embedded connection still gets fired when OSGi shutsdown even with
+        // a flag to prevent it. connection.stop and close are clean.
+        connection.stop();
+        connection.close();
+    }
+
+
+    @Override
+    public void publish(Types.TopicName name, Types.CommandName commandName, Map<String, Object> message) {
+        Session session = null;
+        try {
+            // use a fresh session per message.
+            session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+            TextMessage textMessage = session.createTextMessage(Json.toJson(message));
+            textMessage.setJMSType(JMSMessageTypes.JSON.toString());
+            session.createProducer(session.createTopic(name.toString())).send(textMessage);
+            session.commit();
+            session.close();
+        } catch (JMSException e) {
+            LOGGER.error("Unable to send message to queue "+name, e);
+            if(session != null) {
+                try {
+                    session.close();
+                } catch (JMSException e1) {
+                    LOGGER.warn("Unable to close session ",e1);
+                }
+            }
+
+        }
+    }
+
+
+    // Register Subscribers using OSGi Whiteboard pattern
+    public synchronized  void addSubscriber(ServiceReference<Subscriber> serviceRef) {
+        if (registrations.containsKey(serviceRef)) {
+            LOGGER.error("Registration for service reference is already present {}",serviceRef);
+            return;
+        }
+        SubscriberHolder subscriberHolder = new SubscriberHolder(session, serviceRef.getBundle().getBundleContext().getService(serviceRef), getServiceProperties(serviceRef));
+        registrations.put(serviceRef, subscriberHolder);
+    }
+
+    private Map<String, Object> getServiceProperties(ServiceReference<Subscriber> serviceRef) {
+        Map<String, Object> m = new HashMap<String, Object>();
+        for ( String k : serviceRef.getPropertyKeys()) {
+            m.put(k, serviceRef.getProperty(k));
+        }
+        return Collections.unmodifiableMap(m);
+    }
+
+    public synchronized void removeSubscriber(ServiceReference<Subscriber> serviceRef) {
+        SubscriberHolder subscriberHolder = registrations.remove(serviceRef);
+        if (subscriberHolder != null) {
+            subscriberHolder.close();
+        }
+    }
+
+    private static class SubscriberHolder implements Closeable {
+
+
+        private final FilteredTopicSubscriber filteredTopicSubscriber;
+
+        public SubscriberHolder(Session session, Subscriber subscriber, Map<String, Object> properties) {
+            try {
+                LOGGER.info("Creating Subscriber holder for {} ", subscriber.getClass());
+                String[] topicNames = (String[]) properties.get(Subscriber.TOPIC_NAMES_PROP);
+
+                if ( topicNames == null || topicNames.length == 0) {
+                    throw new IllegalArgumentException("At least one valid topic name in property " + Subscriber.TOPIC_NAMES_PROP + " is required for Subscriber registration");
+                }
+                if ( subscriber instanceof MessageFilter) {
+                    filteredTopicSubscriber = new FilteredTopicSubscriber(session, subscriber, topicNames, (MessageFilter)subscriber);
+                } else {
+                    filteredTopicSubscriber = new FilteredTopicSubscriber(session, subscriber, topicNames, new MessageFilter() {
+
+
+                        @Override
+                        public boolean accept(Types.Name name, Map<String, Object> mapMessage) {
+                            return true;
+                        }
+                    });
+
+                }
+            } catch (JMSException e) {
+                throw new IllegalArgumentException("Unable to register QueueReader with JMS ",e);
+            }
+
+        }
+
+        public void close() {
+            try {
+                filteredTopicSubscriber.close();
+            } catch (IOException e) {
+                LOGGER.warn("Unable to close topic subscriber {} ", e);
+            }
+        }
+    }
+
+    /**
+     * This listens to topic messages, and applies the message filter prior to sending to the subscriber.
+     * Although JMS has its own filtering language, this is JMS specific and since we don't want to expose implementation
+     * details in the JOBs API either explicitly or out of band, the JMS specific filters cant be used. As a replacement the
+     * API provides the MessageFilter API.
+     */
+    private static final class FilteredTopicSubscriber implements Closeable, MessageListener {
+        private final Subscriber subscriber;
+        private final MessageFilter filter;
+        private final List<MessageConsumer> consumers = new ArrayList<MessageConsumer>();
+
+        public FilteredTopicSubscriber(@Nonnull Session session,
+                                       @Nonnull Subscriber subscriber,
+                                       @Nonnull String[] topicNames,
+                                       @Nonnull MessageFilter filter) throws JMSException {
+            this.subscriber = subscriber;
+            this.filter = filter;
+            for (String t : topicNames) {
+                MessageConsumer c = session.createConsumer(session.createTopic(t));
+                c.setMessageListener(this);
+                consumers.add(c);
+            }
+        }
+
+
+        @Override
+        public void onMessage(Message message) {
+            try {
+                LOGGER.info("Got message {} ", message);
+                Destination destination = message.getJMSDestination();
+                if (destination instanceof Topic) {
+                    Topic topic = (Topic) destination;
+                    String type = message.getJMSType();
+                    if (JMSMessageTypes.JSON.equals(JMSMessageTypes.valueOf(type))) {
+                        TextMessage textMessage = (TextMessage) message;
+                        Map<String, Object> mapMessage = Json.toMap(textMessage.getText());
+                        Types.TopicName topicName = Types.topicName(topic.getTopicName());
+                        if ( filter.accept(topicName, mapMessage) ) {
+                            subscriber.onMessage(topicName, mapMessage);
+                        }
+                    }
+                }
+            } catch (JMSException e) {
+                LOGGER.warn("Failed to deliver message ",e);
+            }
+        }
+
+        @Override
+        public void close() throws IOException {
+            for (MessageConsumer c : consumers) {
+                try {
+                    LOGGER.info("Closing consumer on dispose {} ",c);
+                    c.close();
+                } catch (JMSException e) {
+                    LOGGER.warn(e.getMessage(), e);
+                }
+            }
+        }
+    }
+
+
+
+}

Propchange: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/JMSTopicManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/Json.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/Json.java?rev=1754255&view=auto
==============================================================================
--- sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/Json.java (added)
+++ sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/Json.java Wed Jul 27 12:10:12 2016
@@ -0,0 +1,92 @@
+/*
+ * 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.jms;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by ieb on 31/03/2016.
+ */
+public class Json {
+
+    public static Map<String, Object> toMap(String text) {
+        JsonElement root = new JsonParser().parse(text);
+        return toMapValue(root);
+    }
+
+    private static <T> T toMapValue(JsonElement element) {
+        if (element.isJsonObject()) {
+            return (T) toMapValue(element.getAsJsonObject());
+        } else if (element.isJsonArray()) {
+            return (T) toMapValue(element.getAsJsonArray());
+        } else if (element.isJsonNull()) {
+            return null;
+        } else if (element.isJsonPrimitive()) {
+            return (T) toMapValue(element.getAsJsonPrimitive());
+        }
+        throw new IllegalArgumentException("Encountered JsonElement that is not an object, array, primitive or null: "+element);
+    }
+    private static <T> T toMapValue(JsonArray array) {
+        List<Object> list = new ArrayList<Object>();
+        for( JsonElement e : array) {
+            list.add(toMapValue(e));
+        }
+        return (T) list;
+    }
+
+    private static <T> T toMapValue(JsonObject obj) {
+        Map<String, Object> m = new HashMap<String, Object>();
+        for (Map.Entry<String, JsonElement> e : obj.entrySet()) {
+            m.put(e.getKey(), toMapValue(e.getValue()));
+        }
+        return (T) m;
+    }
+
+    private static <T> T toMapValue(JsonPrimitive p) {
+        if (p.isString()) {
+            return (T) p.getAsString();
+        } else if (p.isBoolean()) {
+            return (T) ((Boolean)p.getAsBoolean());
+        } else if (p.isNumber()) {
+            double d = p.getAsDouble();
+            if (Math.floor(d) == d) {
+                return (T)((Long)p.getAsLong());
+            }
+            return (T)((Double)d);
+        } else {
+            return null;
+        }
+    }
+
+    public static String toJson(Map<String, Object> message) {
+        return new Gson().toJson(message);
+    }
+
+
+}

Propchange: sling/trunk/contrib/commons/mom/jms/src/main/java/org/apache/sling/jms/Json.java
------------------------------------------------------------------------------
    svn:eol-style = native