tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1208575 - in /openejb/trunk/openejb/container/openejb-core/src: main/java/org/apache/openejb/assembler/classic/ main/java/org/apache/openejb/config/ main/java/org/apache/openejb/core/managed/ main/java/org/apache/openejb/core/mdb/ main/jav...
Date Wed, 30 Nov 2011 17:56:13 GMT
Author: rmannibucau
Date: Wed Nov 30 17:56:10 2011
New Revision: 1208575

URL: http://svn.apache.org/viewvc?rev=1208575&view=rev
Log:
adding LocalMBeanServer to be able to desactivate mbeans

Added:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/monitoring/LocalMBeanServer.java
Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/MBeanDeployer.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/HeapDump.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=1208575&r1=1208574&r2=1208575&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
Wed Nov 30 17:56:10 2011
@@ -22,9 +22,34 @@ import org.apache.geronimo.connector.wor
 import org.apache.geronimo.connector.work.TransactionContextHandler;
 import org.apache.geronimo.connector.work.WorkContextHandler;
 import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
-import org.apache.openejb.*;
-import org.apache.openejb.cdi.*;
-import org.apache.openejb.core.*;
+import org.apache.openejb.AppContext;
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.BeanType;
+import org.apache.openejb.ClassLoaderUtil;
+import org.apache.openejb.Container;
+import org.apache.openejb.DuplicateDeploymentIdException;
+import org.apache.openejb.Injection;
+import org.apache.openejb.JndiConstants;
+import org.apache.openejb.MethodContext;
+import org.apache.openejb.NoSuchApplicationException;
+import org.apache.openejb.OpenEJB;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.UndeployException;
+import org.apache.openejb.cdi.CdiAppContextsService;
+import org.apache.openejb.cdi.CdiBuilder;
+import org.apache.openejb.cdi.CdiResourceInjectionService;
+import org.apache.openejb.cdi.CdiScanner;
+import org.apache.openejb.cdi.CustomELAdapter;
+import org.apache.openejb.cdi.ManagedSecurityService;
+import org.apache.openejb.cdi.OpenEJBTransactionService;
+import org.apache.openejb.cdi.OptimizedLoaderService;
+import org.apache.openejb.core.ConnectorReference;
+import org.apache.openejb.core.CoreContainerSystem;
+import org.apache.openejb.core.CoreUserTransaction;
+import org.apache.openejb.core.JndiFactory;
+import org.apache.openejb.core.SimpleTransactionSynchronizationRegistry;
+import org.apache.openejb.core.TransactionSynchronizationRegistryWrapper;
+import org.apache.openejb.core.WebContext;
 import org.apache.openejb.core.ivm.naming.IvmContext;
 import org.apache.openejb.core.ivm.naming.IvmJndiFactory;
 import org.apache.openejb.core.security.SecurityContextHandler;
@@ -32,31 +57,60 @@ import org.apache.openejb.core.timer.Ejb
 import org.apache.openejb.core.timer.NullEjbTimerServiceImpl;
 import org.apache.openejb.core.timer.ScheduleData;
 import org.apache.openejb.core.timer.TimerStore;
-import org.apache.openejb.core.transaction.*;
+import org.apache.openejb.core.transaction.JtaTransactionPolicyFactory;
+import org.apache.openejb.core.transaction.SimpleBootstrapContext;
+import org.apache.openejb.core.transaction.SimpleWorkManager;
+import org.apache.openejb.core.transaction.TransactionPolicyFactory;
+import org.apache.openejb.core.transaction.TransactionType;
 import org.apache.openejb.javaagent.Agent;
 import org.apache.openejb.loader.Options;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.persistence.JtaEntityManagerRegistry;
 import org.apache.openejb.persistence.PersistenceClassLoaderHandler;
 import org.apache.openejb.resource.GeronimoConnectionManagerFactory;
 import org.apache.openejb.spi.ApplicationServer;
 import org.apache.openejb.spi.ContainerSystem;
 import org.apache.openejb.spi.SecurityService;
-import org.apache.openejb.util.*;
+import org.apache.openejb.util.AsmParameterNameLoader;
+import org.apache.openejb.util.ContextUtil;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.Messages;
+import org.apache.openejb.util.OpenEJBErrorHandler;
+import org.apache.openejb.util.References;
+import org.apache.openejb.util.SafeToolkit;
 import org.apache.openejb.util.proxy.ProxyFactory;
 import org.apache.openejb.util.proxy.ProxyManager;
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.spi.*;
+import org.apache.webbeans.spi.ContextsService;
+import org.apache.webbeans.spi.LoaderService;
+import org.apache.webbeans.spi.ResourceInjectionService;
+import org.apache.webbeans.spi.ScannerService;
+import org.apache.webbeans.spi.TransactionService;
 import org.apache.webbeans.spi.adaptor.ELAdaptor;
 import org.apache.xbean.finder.ResourceFinder;
 import org.apache.xbean.recipe.ObjectRecipe;
 import org.apache.xbean.recipe.Option;
 import org.apache.xbean.recipe.UnsetPropertiesRecipe;
 
-import javax.management.*;
-import javax.naming.*;
-import javax.persistence.EntityManagerFactory;
-import javax.resource.spi.*;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.XATerminator;
 import javax.resource.spi.work.WorkManager;
 import javax.transaction.TransactionManager;
 import javax.transaction.TransactionSynchronizationRegistry;
@@ -66,17 +120,26 @@ import java.io.File;
 import java.io.IOException;
 import java.lang.instrument.ClassFileTransformer;
 import java.lang.instrument.Instrumentation;
-import java.lang.management.ManagementFactory;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeMap;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.atomic.AtomicInteger;
-import java.lang.IllegalStateException;
 
 public class Assembler extends AssemblerTool implements org.apache.openejb.spi.Assembler,
JndiConstants {
 
@@ -1164,7 +1227,7 @@ public class Assembler extends Assembler
         }
 
         // mbeans
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer server = LocalMBeanServer.get();
         for (String objectName : appInfo.jmx) {
             try {
               ObjectName on = new ObjectName(objectName);

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java?rev=1208575&r1=1208574&r2=1208575&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
Wed Nov 30 17:56:10 2011
@@ -2,6 +2,7 @@ package org.apache.openejb.assembler.cla
 
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.monitoring.DynamicMBeanWrapper;
+import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.monitoring.ObjectNameBuilder;
 import org.apache.openejb.persistence.PersistenceUnitInfoImpl;
 import org.apache.openejb.util.LogCategory;
@@ -84,7 +85,7 @@ public class ReloadableEntityManagerFact
     }
 
     public void register() throws OpenEJBException {
-        final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        final MBeanServer server = LocalMBeanServer.get();
         try {
             server.registerMBean(mBeanify(), generateObjectName());
         } catch (Exception e) {
@@ -111,7 +112,7 @@ public class ReloadableEntityManagerFact
 
     public void unregister() throws OpenEJBException {
         if (objectName != null) {
-            final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+            final MBeanServer server = LocalMBeanServer.get();
             try {
                 server.unregisterMBean(objectName);
             } catch (Exception e) {
@@ -131,7 +132,7 @@ public class ReloadableEntityManagerFact
         try {
             delegate = PersistenceBuilder.createEmf(classLoader, entityManagerFactoryCallable);
         } catch (Exception e) {
-            LOGGER.error("can't replace EntityManagerFactory " + delegate);
+            LOGGER.error("can't replace EntityManagerFactory " + delegate, e);
         }
     }
 

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/MBeanDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/MBeanDeployer.java?rev=1208575&r1=1208574&r2=1208575&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/MBeanDeployer.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/MBeanDeployer.java
Wed Nov 30 17:56:10 2011
@@ -34,6 +34,7 @@ import org.apache.openejb.OpenEJB;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.monitoring.DynamicMBeanWrapper;
+import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.monitoring.ObjectNameBuilder;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
@@ -44,7 +45,7 @@ import org.apache.xbean.finder.ClassFind
  */
 public class MBeanDeployer implements DynamicDeployer {
     private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG,
MBeanDeployer.class);
-    private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+    private static final MBeanServer server = LocalMBeanServer.get();
 
     private static final String OPENEJB_MBEAN_CLASSES_PROPERTY = "openejb.user.mbeans.list";
     private static final String OPENEJB_MBEAN_CLASSES_SPLIT = ",";

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java?rev=1208575&r1=1208574&r2=1208575&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
Wed Nov 30 17:56:10 2011
@@ -41,6 +41,7 @@ import org.apache.openejb.core.transacti
 import org.apache.openejb.core.transaction.TransactionPolicy;
 import org.apache.openejb.core.transaction.TransactionPolicy.TransactionSynchronization;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.monitoring.ManagedMBean;
 import org.apache.openejb.monitoring.ObjectNameBuilder;
 import org.apache.openejb.monitoring.StatsInterceptor;
@@ -238,7 +239,7 @@ public class ManagedContainer implements
     public synchronized void undeploy(final BeanContext bean) throws OpenEJBException {
         Data data = (Data) bean.getContainerData();
 
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer server = LocalMBeanServer.get();
         for (ObjectName objectName : data.jmxNames) {
             try {
                 server.unregisterMBean(objectName);
@@ -270,7 +271,7 @@ public class ManagedContainer implements
         StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
         beanContext.addSystemInterceptor(stats);
 
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer server = LocalMBeanServer.get();
 
         ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
         jmxName.set("J2EEServer", "openejb");

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java?rev=1208575&r1=1208574&r2=1208575&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java
Wed Nov 30 17:56:10 2011
@@ -23,6 +23,7 @@ import org.apache.openejb.ApplicationExc
 import org.apache.openejb.ContainerType;
 import org.apache.openejb.RpcContainer;
 import org.apache.openejb.InterfaceType;
+import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.monitoring.StatsInterceptor;
 import org.apache.openejb.monitoring.ObjectNameBuilder;
 import org.apache.openejb.monitoring.ManagedMBean;
@@ -154,7 +155,7 @@ public class MdbContainer implements Rpc
         StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
         beanContext.addSystemInterceptor(stats);
 
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer server = LocalMBeanServer.get();
 
         ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
         jmxName.set("J2EEServer", "openejb");

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java?rev=1208575&r1=1208574&r2=1208575&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java
Wed Nov 30 17:56:10 2011
@@ -16,32 +16,6 @@
  */
 package org.apache.openejb.core.singleton;
 
-import java.lang.management.ManagementFactory;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.FutureTask;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import javax.ejb.EJBContext;
-import javax.ejb.NoSuchEJBException;
-import javax.ejb.SessionBean;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.xml.ws.WebServiceContext;
-
 import org.apache.openejb.ApplicationException;
 import org.apache.openejb.BeanContext;
 import org.apache.openejb.BeanType;
@@ -56,6 +30,7 @@ import org.apache.openejb.core.transacti
 import org.apache.openejb.core.transaction.TransactionPolicy;
 import org.apache.openejb.core.transaction.TransactionType;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.monitoring.ManagedMBean;
 import org.apache.openejb.monitoring.ObjectNameBuilder;
 import org.apache.openejb.monitoring.StatsInterceptor;
@@ -64,6 +39,30 @@ import org.apache.openejb.spi.SecuritySe
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 
+import javax.ejb.EJBContext;
+import javax.ejb.NoSuchEJBException;
+import javax.ejb.SessionBean;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.xml.ws.WebServiceContext;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
 public class SingletonInstanceManager {
     private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources");
 
@@ -294,7 +293,7 @@ public class SingletonInstanceManager {
         StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
         beanContext.addSystemInterceptor(stats);
 
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer server = LocalMBeanServer.get();
 
         ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
         jmxName.set("J2EEServer", "openejb");
@@ -327,7 +326,7 @@ public class SingletonInstanceManager {
         Data data = (Data) beanContext.getContainerData();
         if (data == null) return;
 
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer server = LocalMBeanServer.get();
         for (ObjectName objectName : data.jmxNames) {
             try {
                 server.unregisterMBean(objectName);

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java?rev=1208575&r1=1208574&r2=1208575&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
Wed Nov 30 17:56:10 2011
@@ -42,6 +42,7 @@ import org.apache.openejb.core.transacti
 import org.apache.openejb.core.transaction.TransactionPolicy;
 import org.apache.openejb.core.transaction.TransactionPolicy.TransactionSynchronization;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.monitoring.ManagedMBean;
 import org.apache.openejb.monitoring.ObjectNameBuilder;
 import org.apache.openejb.monitoring.StatsInterceptor;
@@ -255,7 +256,7 @@ public class StatefulContainer implement
     public synchronized void undeploy(final BeanContext beanContext) throws OpenEJBException
{
         Data data = (Data) beanContext.getContainerData();
 
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer server = LocalMBeanServer.get();
         for (ObjectName objectName : data.jmxNames) {
             try {
                 server.unregisterMBean(objectName);
@@ -287,7 +288,7 @@ public class StatefulContainer implement
         StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
         beanContext.addSystemInterceptor(stats);
 
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer server = LocalMBeanServer.get();
 
         ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
         jmxName.set("J2EEServer", "openejb");

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java?rev=1208575&r1=1208574&r2=1208575&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
Wed Nov 30 17:56:10 2011
@@ -27,6 +27,7 @@ import org.apache.openejb.core.intercept
 import org.apache.openejb.core.interceptor.InterceptorStack;
 import org.apache.openejb.core.timer.TimerServiceWrapper;
 import org.apache.openejb.loader.Options;
+import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.monitoring.ManagedMBean;
 import org.apache.openejb.monitoring.ObjectNameBuilder;
 import org.apache.openejb.monitoring.StatsInterceptor;
@@ -328,7 +329,7 @@ public class StatelessInstanceManager {
         StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
         beanContext.addSystemInterceptor(stats);
 
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer server = LocalMBeanServer.get();
 
         ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
         jmxName.set("J2EEServer", "openejb");
@@ -388,7 +389,7 @@ public class StatelessInstanceManager {
         Data data = (Data) beanContext.getContainerData();
         if (data == null) return;
 
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        MBeanServer server = LocalMBeanServer.get();
         for (ObjectName objectName : data.jmxNames) {
             try {
                 server.unregisterMBean(objectName);

Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/monitoring/LocalMBeanServer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/monitoring/LocalMBeanServer.java?rev=1208575&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/monitoring/LocalMBeanServer.java
(added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/monitoring/LocalMBeanServer.java
Wed Nov 30 17:56:10 2011
@@ -0,0 +1,400 @@
+package org.apache.openejb.monitoring;
+
+import javax.management.*;
+import javax.management.loading.ClassLoaderRepository;
+import java.io.ObjectInputStream;
+import java.lang.management.ManagementFactory;
+import java.util.Set;
+
+/**
+ * @author rmannibucau
+ */
+public class LocalMBeanServer implements MBeanServer {
+    public static final String OPENEJB_JMX_ACTIVE = "openejb.jmx.active";
+
+    private static final LocalMBeanServer INSTANCE = new LocalMBeanServer();
+
+    private LocalMBeanServer() {
+        // no-op
+    }
+
+    public static MBeanServer get() {
+        return INSTANCE;
+    }
+
+    private static boolean isJMXActive() {
+        return "true".equalsIgnoreCase(System.getProperty(OPENEJB_JMX_ACTIVE, "true"));
+    }
+
+    private static MBeanServer s() {
+        if (isJMXActive()) {
+            return ManagementFactory.getPlatformMBeanServer();
+        }
+        return NoOpMBeanServer.INSTANCE;
+    }
+
+    @Override
+    public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException
{
+        return s().createMBean(className, name);
+    }
+
+    @Override
+    public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName)
throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException,
NotCompliantMBeanException, InstanceNotFoundException {
+        return s().createMBean(className, name, loaderName);
+    }
+
+    @Override
+    public ObjectInstance createMBean(String className, ObjectName name, Object[] params,
String[] signature) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException {
+        return s().createMBean(className, name, params, signature);
+    }
+
+    @Override
+    public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName,
Object[] params, String[] signature) throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException
{
+        return s().createMBean(className, name, loaderName, params, signature);
+    }
+
+    @Override
+    public ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException,
MBeanRegistrationException, NotCompliantMBeanException {
+        return s().registerMBean(object, name);
+    }
+
+    @Override
+    public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException
{
+        s().unregisterMBean(name);
+    }
+
+    @Override
+    public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException
{
+        return s().getObjectInstance(name);
+    }
+
+    @Override
+    public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
+        return queryMBeans(name, query);
+    }
+
+    @Override
+    public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
+        return s().queryNames(name, query);
+    }
+
+    @Override
+    public boolean isRegistered(ObjectName name) {
+        return s().isRegistered(name);
+    }
+
+    @Override
+    public Integer getMBeanCount() {
+        return s().getMBeanCount();
+    }
+
+    @Override
+    public Object getAttribute(ObjectName name, String attribute) throws MBeanException,
AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
+        return s().getAttribute(name, attribute);
+    }
+
+    @Override
+    public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException,
ReflectionException {
+        return s().getAttributes(name, attributes);
+    }
+
+    @Override
+    public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException,
AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
{
+        s().setAttribute(name, attribute);
+    }
+
+    @Override
+    public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws
InstanceNotFoundException, ReflectionException {
+        return s().setAttributes(name, attributes);
+    }
+
+    @Override
+    public Object invoke(ObjectName name, String operationName, Object[] params, String[]
signature) throws InstanceNotFoundException, MBeanException, ReflectionException {
+        return s().invoke(name, operationName, params, signature);
+    }
+
+    @Override
+    public String getDefaultDomain() {
+        return s().getDefaultDomain();
+    }
+
+    @Override
+    public String[] getDomains() {
+        return s().getDomains();
+    }
+
+    @Override
+    public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter
filter, Object handback) throws InstanceNotFoundException {
+        s().addNotificationListener(name, listener, filter, handback);
+    }
+
+    @Override
+    public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter
filter, Object handback) throws InstanceNotFoundException {
+        s().addNotificationListener(name, listener, filter, handback);
+    }
+
+    @Override
+    public void removeNotificationListener(ObjectName name, ObjectName listener) throws InstanceNotFoundException,
ListenerNotFoundException {
+        s().removeNotificationListener(name, listener);
+    }
+
+    @Override
+    public void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter
filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException {
+        s().removeNotificationListener(name, listener, filter, handback);
+    }
+
+    @Override
+    public void removeNotificationListener(ObjectName name, NotificationListener listener)
throws InstanceNotFoundException, ListenerNotFoundException {
+        s().removeNotificationListener(name, listener);
+    }
+
+    @Override
+    public void removeNotificationListener(ObjectName name, NotificationListener listener,
NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException
{
+        s().removeNotificationListener(name, listener, filter, handback);
+    }
+
+    @Override
+    public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException,
ReflectionException {
+        return s().getMBeanInfo(name);
+    }
+
+    @Override
+    public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException
{
+        return s().isInstanceOf(name, className);
+    }
+
+    @Override
+    public Object instantiate(String className) throws ReflectionException, MBeanException
{
+        return s().instantiate(className);
+    }
+
+    @Override
+    public Object instantiate(String className, ObjectName loaderName) throws ReflectionException,
MBeanException, InstanceNotFoundException {
+        return s().instantiate(className, loaderName);
+    }
+
+    @Override
+    public Object instantiate(String className, Object[] params, String[] signature) throws
ReflectionException, MBeanException {
+        return s().instantiate(className, params, signature);
+    }
+
+    @Override
+    public Object instantiate(String className, ObjectName loaderName, Object[] params, String[]
signature) throws ReflectionException, MBeanException, InstanceNotFoundException {
+        return s().instantiate(className, loaderName, params, signature);
+    }
+
+    @Override
+    public ObjectInputStream deserialize(ObjectName name, byte[] data) throws InstanceNotFoundException,
OperationsException {
+        return s().deserialize(name, data);
+    }
+
+    @Override
+    public ObjectInputStream deserialize(String className, byte[] data) throws OperationsException,
ReflectionException {
+        return s().deserialize(className, data);
+    }
+
+    @Override
+    public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[]
data) throws InstanceNotFoundException, OperationsException, ReflectionException {
+        return s().deserialize(className, loaderName, data);
+    }
+
+    @Override
+    public ClassLoader getClassLoaderFor(ObjectName mbeanName) throws InstanceNotFoundException
{
+        return s().getClassLoaderFor(mbeanName);
+    }
+
+    @Override
+    public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException
{
+        return s().getClassLoader(loaderName);
+    }
+
+    @Override
+    public ClassLoaderRepository getClassLoaderRepository() {
+        return s().getClassLoaderRepository();
+    }
+
+    private static class NoOpMBeanServer implements MBeanServer{
+        public static final MBeanServer INSTANCE = new NoOpMBeanServer();
+        private static final String[] DEFAULT_DOMAINS = new String[]{ "default-domain" };
+
+        @Override
+        public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException
{
+            return null;
+        }
+
+        @Override
+        public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName)
throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException,
NotCompliantMBeanException, InstanceNotFoundException {
+            return null;
+        }
+
+        @Override
+        public ObjectInstance createMBean(String className, ObjectName name, Object[] params,
String[] signature) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException {
+            return null;
+        }
+
+        @Override
+        public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName,
Object[] params, String[] signature) throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException
{
+            return null;
+        }
+
+        @Override
+        public ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException,
MBeanRegistrationException, NotCompliantMBeanException {
+            return null;
+        }
+
+        @Override
+        public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException
{
+            // no-op
+        }
+
+        @Override
+        public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException
{
+            return null;
+        }
+
+        @Override
+        public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
+            return null;
+        }
+
+        @Override
+        public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
+            return null;
+        }
+
+        @Override
+        public boolean isRegistered(ObjectName name) {
+            return false;
+        }
+
+        @Override
+        public Integer getMBeanCount() {
+            return 0;
+        }
+
+        @Override
+        public Object getAttribute(ObjectName name, String attribute) throws MBeanException,
AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
+            return null;
+        }
+
+        @Override
+        public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException,
ReflectionException {
+            return new AttributeList();
+        }
+
+        @Override
+        public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException,
AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
{
+            // no-op
+        }
+
+        @Override
+        public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws
InstanceNotFoundException, ReflectionException {
+            return new AttributeList();
+        }
+
+        @Override
+        public Object invoke(ObjectName name, String operationName, Object[] params, String[]
signature) throws InstanceNotFoundException, MBeanException, ReflectionException {
+            return null;
+        }
+
+        @Override
+        public String getDefaultDomain() {
+            return DEFAULT_DOMAINS[0];
+        }
+
+        @Override
+        public String[] getDomains() {
+            return DEFAULT_DOMAINS;
+        }
+
+        @Override
+        public void addNotificationListener(ObjectName name, NotificationListener listener,
NotificationFilter filter, Object handback) throws InstanceNotFoundException {
+            // no-op
+        }
+
+        @Override
+        public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter
filter, Object handback) throws InstanceNotFoundException {
+            // no-op
+        }
+
+        @Override
+        public void removeNotificationListener(ObjectName name, ObjectName listener) throws
InstanceNotFoundException, ListenerNotFoundException {
+            // no-op
+        }
+
+        @Override
+        public void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter
filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException {
+            // no-op
+        }
+
+        @Override
+        public void removeNotificationListener(ObjectName name, NotificationListener listener)
throws InstanceNotFoundException, ListenerNotFoundException {
+            // no-op
+        }
+
+        @Override
+        public void removeNotificationListener(ObjectName name, NotificationListener listener,
NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException
{
+            // no-op
+        }
+
+        @Override
+        public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException,
IntrospectionException, ReflectionException {
+            return null;
+        }
+
+        @Override
+        public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException
{
+            return false;
+        }
+
+        @Override
+        public Object instantiate(String className) throws ReflectionException, MBeanException
{
+            return null;
+        }
+
+        @Override
+        public Object instantiate(String className, ObjectName loaderName) throws ReflectionException,
MBeanException, InstanceNotFoundException {
+            return null;
+        }
+
+        @Override
+        public Object instantiate(String className, Object[] params, String[] signature)
throws ReflectionException, MBeanException {
+            return null;
+        }
+
+        @Override
+        public Object instantiate(String className, ObjectName loaderName, Object[] params,
String[] signature) throws ReflectionException, MBeanException, InstanceNotFoundException
{
+            return null;
+        }
+
+        @Override
+        public ObjectInputStream deserialize(ObjectName name, byte[] data) throws InstanceNotFoundException,
OperationsException {
+            return null;
+        }
+
+        @Override
+        public ObjectInputStream deserialize(String className, byte[] data) throws OperationsException,
ReflectionException {
+            return null;
+        }
+
+        @Override
+        public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[]
data) throws InstanceNotFoundException, OperationsException, ReflectionException {
+            return null;
+        }
+
+        @Override
+        public ClassLoader getClassLoaderFor(ObjectName mbeanName) throws InstanceNotFoundException
{
+            return null;
+        }
+
+        @Override
+        public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException
{
+            return null;
+        }
+
+        @Override
+        public ClassLoaderRepository getClassLoaderRepository() {
+            return null;
+        }
+    }
+}

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/HeapDump.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/HeapDump.java?rev=1208575&r1=1208574&r2=1208575&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/HeapDump.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/HeapDump.java
Wed Nov 30 17:56:10 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.openejb.util;
 
+import org.apache.openejb.monitoring.LocalMBeanServer;
+
 import javax.management.MBeanServer;
 import java.lang.management.ManagementFactory;
 import java.lang.reflect.InvocationTargetException;
@@ -50,7 +52,7 @@ public class HeapDump {
         // use JMX to find hot spot mbean
         Object hotspotMBean = null;
         try {
-            MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+            MBeanServer server = LocalMBeanServer.get();
             hotspotMBean = ManagementFactory.newPlatformMXBeanProxy(server,
                     "com.sun.management:type=HotSpotDiagnostic",
                     clazz);

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java?rev=1208575&r1=1208574&r2=1208575&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java
Wed Nov 30 17:56:10 2011
@@ -31,6 +31,7 @@ import org.apache.openejb.jee.WebApp;
 import org.apache.openejb.jee.jpa.unit.Persistence;
 import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.monitoring.LocalMBeanServer;
 
 import javax.naming.NamingException;
 import java.io.IOException;
@@ -51,6 +52,7 @@ public class AutoConfigPersistenceUnitsT
     private List<ResourceInfo> resources;
 
     protected void setUp() throws Exception {
+        System.setProperty(LocalMBeanServer.OPENEJB_JMX_ACTIVE, "false");
         config = new ConfigurationFactory();
         assembler = new Assembler();
 
@@ -62,6 +64,10 @@ public class AutoConfigPersistenceUnitsT
         resources = configuration.facilities.resources;
     }
 
+    @Override public void tearDown() {
+        System.getProperties().remove(LocalMBeanServer.OPENEJB_JMX_ACTIVE);
+    }
+
     /**
      * Existing data source "Orange", jta managed
      * Existing data source "OrangeUnmanaged", not jta managed



Mime
View raw message