You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ch...@apache.org on 2015/12/17 11:05:42 UTC

svn commit: r1720502 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/ main/java/org/apache/sling/jcr/resource/internal/helper/jcr/ test/java/org/apache/sling/jcr/resource/internal/

Author: chetanm
Date: Thu Dec 17 10:05:42 2015
New Revision: 1720502

URL: http://svn.apache.org/viewvc?rev=1720502&view=rev
Log:
SLING-5384 - Expose BackgroundObserverMBean as part of OakResourceListener setup

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/OakResourceListenerTest.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java?rev=1720502&r1=1720501&r2=1720502&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/OakResourceListener.java Thu Dec 17 10:05:42 2015
@@ -42,6 +42,7 @@ import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.oak.plugins.observation.NodeObserver;
 import org.apache.jackrabbit.oak.spi.commit.BackgroundObserver;
+import org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.Observer;
 import org.apache.sling.api.SlingConstants;
@@ -69,6 +70,8 @@ public class OakResourceListener extends
 
     private final ServiceRegistration serviceRegistration;
 
+    private final ServiceRegistration mbeanRegistration;
+
     /** Helper object. */
     final ObservationListenerSupport support;
 
@@ -87,11 +90,11 @@ public class OakResourceListener extends
         this.pathMapper = pathMapper;
         this.mountPrefix = (mountPrefix == null || mountPrefix.length() == 0 || mountPrefix.equals("/") ? null : mountPrefix);
 
-        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        final Hashtable<String, Object> props = new Hashtable<String, Object>();
         props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
         props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling JCR Observation Listener for Oak");
 
-        final Observer observer = new BackgroundObserver(this, executor, observationQueueLength) {
+        final BackgroundObserver observer = new BackgroundObserver(this, executor, observationQueueLength) {
             @Override
             protected void added(int queueSize) {
                 if (queueSize == observationQueueLength) {
@@ -101,6 +104,13 @@ public class OakResourceListener extends
             }
         };
         serviceRegistration = bundleContext.registerService(Observer.class.getName(), observer, props);
+
+        final Dictionary<String, Object> mbeanProps = new Hashtable<String, Object>(props);
+        String objectName = String.format("org.apache.sling:type=%s,name=SlingResourceListener",
+                BackgroundObserverMBean.TYPE);
+        mbeanProps.put("jmx.objectname", objectName);
+
+        mbeanRegistration = bundleContext.registerService(BackgroundObserverMBean.class.getName(), observer.getMBean(), mbeanProps);
     }
 
     /**
@@ -108,6 +118,7 @@ public class OakResourceListener extends
      */
     @Override
     public void close() throws IOException {
+        mbeanRegistration.unregister();
         serviceRegistration.unregister();
         this.support.dispose();
     }

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=1720502&r1=1720501&r2=1720502&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java Thu Dec 17 10:05:42 2015
@@ -76,7 +76,9 @@ import org.osgi.service.component.Compon
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@Component(immediate = true)
+@Component(immediate = true, metatype = true,
+        label = "Apache Sling JCR Resource Provider Factory",
+        description = "This provider adds  JCR resources to the resource tree")
 @Service(value = ResourceProvider.class)
 @Properties({ @Property(name = ResourceProvider.PROPERTY_NAME, value = "JCR"),
         @Property(name = ResourceProvider.PROPERTY_ROOT, value = "/"),

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/OakResourceListenerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/OakResourceListenerTest.java?rev=1720502&r1=1720501&r2=1720502&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/OakResourceListenerTest.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/OakResourceListenerTest.java Thu Dec 17 10:05:42 2015
@@ -17,9 +17,11 @@
 package org.apache.sling.jcr.resource.internal;
 
 import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerObserver;
+import static org.junit.Assert.assertNotNull;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyMap;
 import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -33,6 +35,7 @@ import javax.jcr.Session;
 import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.jcr.Jcr;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
+import org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean;
 import org.apache.jackrabbit.oak.spi.commit.Observer;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -96,7 +99,7 @@ public class OakResourceListenerTest ext
         when(bundleContext.createFilter(any(String.class))).thenReturn(null);
         when(bundleContext.getServiceReference(any(String.class))).thenReturn(null);
         when(bundleContext.getService(null)).thenReturn(mockEA);
-        when(bundleContext.registerService(any(String.class), any(Object.class), any(Dictionary.class)))
+        when(bundleContext.registerService(eq(Observer.class.getName()), any(Object.class), any(Dictionary.class)))
                 .thenAnswer(new Answer<ServiceRegistration>() {
                     public ServiceRegistration answer(InvocationOnMock invocation) throws Throwable {
                         Object[] arguments = invocation.getArguments();
@@ -104,6 +107,16 @@ public class OakResourceListenerTest ext
                         return mock(ServiceRegistration.class);
                     }
                 });
+
+        when(bundleContext.registerService(eq(BackgroundObserverMBean.class.getName()), any(Object.class), any
+                (Dictionary.class)))
+                .thenAnswer(new Answer<ServiceRegistration>() {
+                    public ServiceRegistration answer(InvocationOnMock invocation) throws Throwable {
+                        Object[] arguments = invocation.getArguments();
+                        assertNotNull(((Dictionary)arguments[2]).get("jmx.objectname"));
+                        return mock(ServiceRegistration.class);
+                    }
+                });
 
         listener = new SynchronousOakResourceListener(
                 this.slingRepository, bundleContext, resolver, tracker, executor);