sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1666644 - in /sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl: DefaultStartupHandler.java MBeanStartupListener.java
Date Sat, 14 Mar 2015 09:09:29 GMT
Author: cziegeler
Date: Sat Mar 14 09:09:28 2015
New Revision: 1666644

URL: http://svn.apache.org/r1666644
Log:
SLING-4503 : Provide a mechanism to notify a JMX Bean about startup progress

Added:
    sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/MBeanStartupListener.java
  (with props)
Modified:
    sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/DefaultStartupHandler.java

Modified: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/DefaultStartupHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/DefaultStartupHandler.java?rev=1666644&r1=1666643&r2=1666644&view=diff
==============================================================================
--- sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/DefaultStartupHandler.java
(original)
+++ sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/DefaultStartupHandler.java
Sat Mar 14 09:09:28 2015
@@ -92,6 +92,9 @@ public class DefaultStartupHandler
     /** Use incremental start level handling. */
     private final boolean useIncremental;
 
+    /** MBean startup listener. */
+    private final StartupListener mbeanStartupListener;
+
     /**
      * Constructor.
      * @param context Bundle context
@@ -104,6 +107,13 @@ public class DefaultStartupHandler
         this.startupMode = manager.getMode();
         this.targetStartLevel = manager.getTargetStartLevel();
 
+        StartupListener listener = null;
+        try {
+            listener = new MBeanStartupListener();
+        } catch ( final Exception ignore ) {
+            // ignore
+        }
+        this.mbeanStartupListener = listener;
         this.listenerTracker = new ServiceTracker<StartupListener, StartupListener>(context,
StartupListener.class,
                 new ServiceTrackerCustomizer<StartupListener, StartupListener>() {
 
@@ -291,6 +301,9 @@ public class DefaultStartupHandler
                 logger.log(Logger.LOG_ERROR, "Error calling StartupListener " + listener,
t);
             }
         }
+        if ( this.mbeanStartupListener != null ) {
+            this.mbeanStartupListener.startupFinished(this.startupMode);
+        }
 
         // stop the queue
         this.enqueue(false);
@@ -317,6 +330,9 @@ public class DefaultStartupHandler
                 logger.log(Logger.LOG_ERROR, "Error calling StartupListener " + listener,
t);
             }
         }
+        if ( this.mbeanStartupListener != null ) {
+            this.mbeanStartupListener.startupProgress(ratio);
+        }
     }
 
     /**

Added: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/MBeanStartupListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/MBeanStartupListener.java?rev=1666644&view=auto
==============================================================================
--- sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/MBeanStartupListener.java
(added)
+++ sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/MBeanStartupListener.java
Sat Mar 14 09:09:28 2015
@@ -0,0 +1,101 @@
+/*
+ * 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.launchpad.base.impl;
+
+import java.lang.management.ManagementFactory;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.sling.launchpad.api.StartupListener;
+import org.apache.sling.launchpad.api.StartupMode;
+
+/**
+ * The startup listener is listening for startup events.
+ *
+ * It notifies a JMX MBean when the startup is completed and about the
+ * progress.
+ */
+public class MBeanStartupListener
+    implements StartupListener {
+
+    /** The launcher mbean name. */
+    private static final String NAME_LAUNCHER = "org.apache.sling.launchpad:type=Launcher";
+
+    /** JMX Server. */
+    private final MBeanServer jmxServer;
+
+    /** Name of the launcher mbean. */
+    private final ObjectName launcherName;
+
+    /** Marker if the mbean is available. */
+    private boolean available;
+
+    /**
+     * Create a new MBean helper.
+     * @throws MalformedObjectNameException if the format of the object name does not correspond
to a valid ObjectName.
+     */
+    public MBeanStartupListener() throws MalformedObjectNameException {
+        this.launcherName = new ObjectName(NAME_LAUNCHER);
+        this.jmxServer = ManagementFactory.getPlatformMBeanServer();
+        // we check for the launcher mbean
+        try {
+            this.jmxServer.getMBeanInfo(launcherName);
+            available = true;
+        } catch (final Exception ignore) {
+            available = false;
+            // ignore
+        }
+    }
+
+    /**
+     * @see org.apache.sling.launchpad.api.StartupListener#inform(org.apache.sling.launchpad.api.StartupMode,
boolean)
+     */
+    @Override
+    public void inform(StartupMode mode, boolean finished) {
+        // nothing to do
+    }
+
+    /**
+     * @see org.apache.sling.launchpad.api.StartupListener#startupFinished(org.apache.sling.launchpad.api.StartupMode)
+     */
+    @Override
+    public void startupFinished(StartupMode mode) {
+        if ( this.available ) {
+            try {
+                this.jmxServer.invoke(launcherName, "startupFinished", null, null);
+            } catch (final Exception e) {
+                // we ignore this
+            }
+        }
+    }
+
+    /**
+     * @see org.apache.sling.launchpad.api.StartupListener#startupProgress(float)
+     */
+    @Override
+    public void startupProgress(float ratio) {
+        if ( this.available ) {
+            try {
+                this.jmxServer.invoke(launcherName, "startupProgress", new Object[]{ratio},
new String[]{Float.class.getName()});
+            } catch (final Exception e) {
+                // we ignore this
+            }
+        }
+    }
+}

Propchange: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/MBeanStartupListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/MBeanStartupListener.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/MBeanStartupListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message