1 22 package org.jboss.ejb3; 23 24 import javax.management.MBeanServer ; 25 import javax.management.MBeanServerConnection ; 26 27 import org.jboss.kernel.Kernel; 28 import org.jboss.logging.Logger; 29 30 34 public class KernelAbstractionFactory 35 { 36 private static final Logger log = Logger.getLogger(KernelAbstractionFactory.class); 37 38 private static ClientKernelAbstraction clientKernelAbstraction = null; 39 private static KernelAbstraction kernelAbstraction = null; 40 private static Kernel kernel = null; 41 42 public static KernelAbstraction getInstance() throws Exception 43 { 44 if (kernelAbstraction == null) 45 { 46 MBeanServer mbeanServer = (MBeanServer )getMBeanServer(); 47 if (kernel != null) 48 kernelAbstraction = new MCKernelAbstraction(kernel, mbeanServer); 49 else 50 { 51 kernelAbstraction = new JmxKernelAbstraction(mbeanServer); 52 } 53 } 54 55 return kernelAbstraction; 56 } 57 58 public static ClientKernelAbstraction getClientInstance() throws Exception 59 { 60 if (clientKernelAbstraction == null) 61 { 62 if (kernel != null) 63 { 64 clientKernelAbstraction = new MCClientKernelAbstraction(kernel); 65 } 66 else 67 { 68 MBeanServerConnection mbeanServer = (MBeanServerConnection )getMBeanServer(); 69 clientKernelAbstraction = new JmxClientKernelAbstraction(mbeanServer); 70 } 71 } 72 73 return clientKernelAbstraction; 74 } 75 76 public static void setKernel(Kernel k) 77 { 78 kernel = k; 79 kernelAbstraction = null; 80 clientKernelAbstraction = null; 81 } 82 83 protected static MBeanServerConnection getMBeanServer() throws Exception 84 { 85 MBeanServerConnection mbeanServer; 86 87 try 88 { 89 mbeanServer = org.jboss.mx.util.MBeanServerLocator.locateJBoss(); 90 } 91 catch (IllegalStateException e) 92 { 93 String adaptorName = System.getProperty("jbosstest.server.name", "jmx/invoker/RMIAdaptor"); 94 mbeanServer = (MBeanServerConnection )InitialContextFactory.getInitialContext().lookup(adaptorName); 95 } 96 97 return mbeanServer; 98 } 99 } 100 101 | Popular Tags |