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 2014/07/09 09:04:41 UTC

svn commit: r1609026 - in /sling/trunk/installer/core: ./ src/main/java/org/apache/sling/installer/api/jmx/ src/main/java/org/apache/sling/installer/core/impl/

Author: chetanm
Date: Wed Jul  9 07:04:41 2014
New Revision: 1609026

URL: http://svn.apache.org/r1609026
Log:
SLING-3736 - Expose OSGi Installer state via JMX

Added:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/jmx/
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/jmx/InstallerMBean.java   (with props)
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallerMBeanImpl.java   (with props)
Modified:
    sling/trunk/installer/core/pom.xml
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java

Modified: sling/trunk/installer/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/pom.xml?rev=1609026&r1=1609025&r2=1609026&view=diff
==============================================================================
--- sling/trunk/installer/core/pom.xml (original)
+++ sling/trunk/installer/core/pom.xml Wed Jul  9 07:04:41 2014
@@ -61,7 +61,8 @@
                             org.apache.sling.installer.api;version=3.1.0,
                             org.apache.sling.installer.api.info;version=1.0.0,
                             org.apache.sling.installer.api.event;version=1.0.0,
-                            org.apache.sling.installer.api.tasks;version=1.3.0
+                            org.apache.sling.installer.api.tasks;version=1.3.0,
+                            org.apache.sling.installer.api.jmx;version=1.0.0
                         </Export-Package>
 				     <!-- 
 				        As we make use of optional features from 4.3 if they

Added: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/jmx/InstallerMBean.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/jmx/InstallerMBean.java?rev=1609026&view=auto
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/jmx/InstallerMBean.java (added)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/jmx/InstallerMBean.java Wed Jul  9 07:04:41 2014
@@ -0,0 +1,44 @@
+/*
+ * 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.installer.api.jmx;
+
+public interface InstallerMBean {
+
+    /**
+     * Count of Active resource groups. These resource groups are currently
+     * in processing.
+     */
+    int getActiveResourceCount();
+
+    /**
+     * Count of Installed resource groups. These resources groups are processed.
+     */
+    int getInstalledResourceCount();
+
+    /**
+     * Indicates that whether the installer is currently active
+     */
+    boolean isActive();
+
+    /**
+     * Determines the time since when the installer is in suspended state
+     */
+    long getSuspendedSince();
+}

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/jmx/InstallerMBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java?rev=1609026&r1=1609025&r2=1609026&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java Wed Jul  9 07:04:41 2014
@@ -23,9 +23,14 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
 
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
 import org.apache.sling.installer.api.OsgiInstaller;
 import org.apache.sling.installer.api.ResourceChangeListener;
+import org.apache.sling.installer.api.event.InstallationListener;
 import org.apache.sling.installer.api.info.InfoProvider;
+import org.apache.sling.installer.api.jmx.InstallerMBean;
 import org.apache.sling.installer.api.tasks.InstallTaskFactory;
 import org.apache.sling.installer.api.tasks.ResourceTransformer;
 import org.apache.sling.installer.api.tasks.RetryHandler;
@@ -73,6 +78,8 @@ public class Activator implements Bundle
                 RetryHandler.class.getName()
         };
         osgiControllerServiceReg = context.registerService(serviceInterfaces, osgiControllerService, props);
+
+        registerJmxBean(context);
     }
 
     /**
@@ -100,6 +107,20 @@ public class Activator implements Bundle
         this.services.clear();
     }
 
+    private void registerJmxBean(BundleContext context) throws MalformedObjectNameException {
+        Hashtable<String, String> jmxProps = new Hashtable<String, String>();
+        jmxProps.put("type", "Installer");
+        jmxProps.put("name", "Sling OSGi Installer");
+
+        final Hashtable<String, Object> mbeanProps = new Hashtable<String, Object>();
+        mbeanProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Installer Controller Service");
+        mbeanProps.put(Constants.SERVICE_VENDOR, VENDOR);
+        mbeanProps.put("jmx.objectname", new ObjectName("org.apache.sling.installer", jmxProps));
+        ServiceRegistration mbeanReg = context.registerService(new String[] {InstallerMBean.class.getName(),
+                InstallationListener.class.getName()}, new InstallerMBeanImpl(osgiControllerService), mbeanProps);
+        registrations.add(mbeanReg);
+    }
+
     /**
      * Register internal services.
      */

Added: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallerMBeanImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallerMBeanImpl.java?rev=1609026&view=auto
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallerMBeanImpl.java (added)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallerMBeanImpl.java Wed Jul  9 07:04:41 2014
@@ -0,0 +1,67 @@
+/*
+ * 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.installer.core.impl;
+
+import org.apache.sling.installer.api.event.InstallationEvent;
+import org.apache.sling.installer.api.event.InstallationListener;
+import org.apache.sling.installer.api.info.InfoProvider;
+import org.apache.sling.installer.api.jmx.InstallerMBean;
+
+public class InstallerMBeanImpl implements InstallationListener, InstallerMBean {
+    private final InfoProvider infoProvider;
+    private volatile boolean active;
+    private volatile long lastEventTime;
+
+    public InstallerMBeanImpl(InfoProvider infoProvider) {
+        this.infoProvider = infoProvider;
+    }
+
+    //~---------------------------------------< InstallationListener >
+
+    public void onEvent(InstallationEvent event) {
+        switch (event.getType()) {
+            case STARTED:
+                active = true;
+                break;
+            case SUSPENDED:
+                active = false;
+                break;
+        }
+        lastEventTime = System.currentTimeMillis();
+    }
+
+    //~----------------------------------------< InstallerMBean >
+
+    public int getActiveResourceCount() {
+        return infoProvider.getInstallationState().getActiveResources().size();
+    }
+
+    public int getInstalledResourceCount() {
+        return infoProvider.getInstallationState().getInstalledResources().size();
+    }
+
+    public boolean isActive() {
+        return active;
+    }
+
+    public long getSuspendedSince() {
+        return active ? -1 : lastEventTime;
+    }
+}

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallerMBeanImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native