Enable JMX Bindings for Guice
-----------------------------

                 Key: SHINDIG-569
                 URL: https://issues.apache.org/jira/browse/SHINDIG-569
             Project: Shindig
          Issue Type: New Feature
            Reporter: Paul Lindner


I found that the JMX bindings for Guice really helped me track down problems 
getting my modules injected properly.

Here's a quick patch that enables this:

--- 
java/common/src/main/java/org/apache/shindig/common/servlet/GuiceServletContextListener.java
        (revision 691884)
+++ 
java/common/src/main/java/org/apache/shindig/common/servlet/GuiceServletContextListener.java
        (working copy)
@@ -18,8 +18,10 @@
  */
 package org.apache.shindig.common.servlet;
 
+import com.google.inject.Injector;
 import com.google.inject.Guice;
 import com.google.inject.Module;
+import com.google.inject.tools.jmx.Manager;
 
 import java.util.LinkedList;
 import java.util.List;
@@ -35,6 +37,7 @@
 public class GuiceServletContextListener implements ServletContextListener {
   public static final String INJECTOR_ATTRIBUTE = "guice-injector";
   public static final String MODULES_ATTRIBUTE = "guice-modules";
+  private boolean jmxInitialized = false;
 
   public void contextInitialized(ServletContextEvent event) {
     ServletContext context = event.getServletContext();
@@ -53,7 +56,17 @@
         }
       }
     }
-    context.setAttribute(INJECTOR_ATTRIBUTE, Guice.createInjector(modules));
+    Injector injector = Guice.createInjector(modules);
+    context.setAttribute(INJECTOR_ATTRIBUTE, injector);
+
+    try {
+      if (jmxInitialized == false) {
+        Manager.manage("ShindigGuiceContext", injector);
+        jmxInitialized = true;
+      }
+    } catch (Exception e) {
+      // Ignore errors
+    }
   }
 
   public void contextDestroyed(ServletContextEvent event) {



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to