tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlmonte...@apache.org
Subject svn commit: r1528259 - in /tomee/tomee/trunk: container/openejb-core/src/main/java/org/apache/openejb/monitoring/ container/openejb-core/src/main/java/org/apache/openejb/resource/ server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/
Date Tue, 01 Oct 2013 22:59:35 GMT
Author: jlmonteiro
Date: Tue Oct  1 22:59:35 2013
New Revision: 1528259

URL: http://svn.apache.org/r1528259
Log:
Adding REST resources to JMX

Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/monitoring/LocalMBeanServer.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java
    tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/monitoring/LocalMBeanServer.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/monitoring/LocalMBeanServer.java?rev=1528259&r1=1528258&r2=1528259&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/monitoring/LocalMBeanServer.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/monitoring/LocalMBeanServer.java
Tue Oct  1 22:59:35 2013
@@ -98,6 +98,15 @@ public class LocalMBeanServer implements
         return registerSilently(new DynamicMBeanWrapper(object), name);
     }
 
+    public static void unregisterSilently(final ObjectName name) {
+        try {
+            get().unregisterMBean(name);
+
+        } catch (Exception e) {
+            LOGGER.error("Cannot unregister MBean " + name, e);
+        }
+    }
+
     public static TabularData tabularData(String typeName, String typeDescription, String[]
names, Object[] values) {
         if (names.length == 0) {
             return null;

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java?rev=1528259&r1=1528258&r2=1528259&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java
Tue Oct  1 22:59:35 2013
@@ -28,6 +28,7 @@ import org.apache.openejb.api.internal.I
 import org.apache.openejb.api.jmx.Description;
 import org.apache.openejb.api.jmx.MBean;
 import org.apache.openejb.api.jmx.ManagedAttribute;
+import org.apache.openejb.api.jmx.ManagedOperation;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.monitoring.ObjectNameBuilder;
@@ -105,7 +106,9 @@ public class GeronimoTransactionManagerF
         final GeronimoTransactionManager geronimoTransactionManager = new GeronimoTransactionManager(defaultTransactionTimeoutSeconds,
xidFactory, txLog);
         final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management")
                 .set("j2eeType", "TransactionManager");
-        LocalMBeanServer.registerDynamicWrapperSilently(new TransactionManagerMBean(geronimoTransactionManager),
jmxName.build());
+        LocalMBeanServer.registerDynamicWrapperSilently(
+                new TransactionManagerMBean(geronimoTransactionManager, defaultTransactionTimeout,
txLog),
+                jmxName.build());
 
         return geronimoTransactionManager;
     }
@@ -122,9 +125,13 @@ public class GeronimoTransactionManagerF
     public static final class TransactionManagerMBean {
 
         private final GeronimoTransactionManager transactionManager;
+        private final Duration defaultTransactionTimeout;
+        private final TransactionLog txLog;
 
-        public TransactionManagerMBean(final GeronimoTransactionManager transactionManager)
{
+        public TransactionManagerMBean(final GeronimoTransactionManager transactionManager,
final Duration defaultTransactionTimeout, final TransactionLog txLog) {
             this.transactionManager = transactionManager;
+            this.defaultTransactionTimeout = defaultTransactionTimeout;
+            this.txLog = txLog;
         }
 
         @ManagedAttribute
@@ -132,18 +139,30 @@ public class GeronimoTransactionManagerF
         public long getActive() {
             return transactionManager.getActiveCount();
         }
+
         @ManagedAttribute
         @Description("Number of committed transactions")
         public long getCommits() {
             return transactionManager.getTotalCommits();
         }
+
         @ManagedAttribute
         @Description("Number of rolled back transactions")
         public long getRollbacks() {
             return transactionManager.getTotalRollbacks();
         }
 
+        @ManagedOperation
+        @Description("Reset statistics counters")
+        public void resetStatistics() {
+            transactionManager.resetStatistics();
+        }
 
+        @ManagedAttribute
+        @Description("Display the default transaction timeout")
+        public String getDefaultTransactionTimeout() {
+            return defaultTransactionTimeout.toString();
+        }
 
     }
 

Modified: tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java?rev=1528259&r1=1528258&r2=1528259&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
(original)
+++ tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
Tue Oct  1 22:59:35 2013
@@ -35,10 +35,16 @@ import org.apache.cxf.transport.http.HTT
 import org.apache.cxf.transport.servlet.BaseUrlHelper;
 import org.apache.openejb.BeanContext;
 import org.apache.openejb.Injection;
+import org.apache.openejb.api.internal.Internal;
+import org.apache.openejb.api.jmx.Description;
+import org.apache.openejb.api.jmx.MBean;
+import org.apache.openejb.api.jmx.ManagedAttribute;
 import org.apache.openejb.assembler.classic.ServiceInfo;
 import org.apache.openejb.assembler.classic.util.ServiceConfiguration;
 import org.apache.openejb.assembler.classic.util.ServiceInfos;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.monitoring.LocalMBeanServer;
+import org.apache.openejb.monitoring.ObjectNameBuilder;
 import org.apache.openejb.rest.ThreadLocalContextManager;
 import org.apache.openejb.server.cxf.transport.util.CxfUtil;
 import org.apache.openejb.server.httpd.HttpRequest;
@@ -51,6 +57,8 @@ import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.proxy.ProxyEJB;
 import org.apache.webbeans.config.WebBeansContext;
 
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
 import javax.naming.Context;
 import javax.servlet.ServletException;
 import javax.servlet.ServletOutputStream;
@@ -94,6 +102,7 @@ public class CxfRsHttpListener implement
     private Server server;
     private String context = "";
     private Collection<Pattern> staticResourcesList = new CopyOnWriteArrayList<Pattern>();
+    private List<ObjectName> jmxNames = new ArrayList<ObjectName>();
 
     static {
         STATIC_CONTENT_TYPES = new HashMap<String, String>();
@@ -294,6 +303,12 @@ public class CxfRsHttpListener implement
     }
 
     public void undeploy() {
+        // unregister all MBeans
+        for (final ObjectName objectName : jmxNames) {
+            LocalMBeanServer.unregisterSilently(objectName);
+        }
+
+
         final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader());
         try {
@@ -433,7 +448,23 @@ public class CxfRsHttpListener implement
         LOGGER.info("REST Application: " + Logs.forceLength(prefix, addressSize, true) +
" -> " + application.getClass().getName());
 
         Collections.sort(resourcesToLog);
+
         for (Logs.LogResourceEndpointInfo resource : resourcesToLog) {
+
+            // Init and register MBeans
+            final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management")
+                    .set("J2EEServer", "openejb")
+                    .set("name", resource.classname)
+                    .set("j2eeType", "REST-" + resource.type);
+
+            ObjectName jmxObjectName = jmxName.build();
+            LocalMBeanServer.registerDynamicWrapperSilently(
+                    new RestServiceMBean(resource),
+                    jmxObjectName);
+
+            jmxNames.add(jmxObjectName);
+            //
+
             LOGGER.info("     Service URI: "
                     + Logs.forceLength(resource.address, addressSize, true) + " -> "
                     + Logs.forceLength(resource.type, 4, false) + " "
@@ -591,4 +622,60 @@ public class CxfRsHttpListener implement
             return clazz.newInstance();
         }
     }
+
+    @MBean
+    @Internal
+    @Description("REST service information")
+    public class RestServiceMBean {
+
+        private String type;
+        private String address;
+        private String classname;
+        private TabularData operations;
+
+        public RestServiceMBean(final Logs.LogResourceEndpointInfo jmxName) {
+            this.type = jmxName.type;
+            this.address = jmxName.address;
+            this.classname = jmxName.classname;
+
+            final String[] names = new String[operations.size()];
+            final String[] values = new String[operations.size()];
+            int idx = 0;
+            for (Logs.LogOperationEndpointInfo operation : jmxName.operations) {
+                names[idx] = Logs.forceLength(operation.http, jmxName.methodSize, false)
+ " "
+                        + Logs.forceLength(operation.address, operation.address.length(),
true);
+                values[idx] = Logs.forceLength(operation.method, jmxName.methodStrSize, true);
+                idx++;
+            }
+            LocalMBeanServer.tabularData(
+                    "Operations",
+                    "Operations for this endpoint",
+                    names, values
+            );
+        }
+
+        @ManagedAttribute
+        @Description("The type of the REST service")
+        public String getType() {
+            return type;
+        }
+
+        @ManagedAttribute
+        @Description("The REST service address")
+        public String getAddress() {
+            return address;
+        }
+
+        @ManagedAttribute
+        @Description("The REST service class name")
+        public String getClassname() {
+            return classname;
+        }
+
+        @ManagedAttribute
+        @Description("All available methods")
+        public TabularData getOperations() {
+            return operations;
+        }
+    }
 }



Mime
View raw message