1 package org.jboss.test.cluster.web; 2 3 import javax.management.MBeanServer ; 4 import javax.servlet.ServletContextEvent ; 5 import javax.servlet.ServletContextListener ; 6 7 import org.jboss.mx.util.MBeanServerLocator; 8 9 public class CacheHelperServletContextListener implements ServletContextListener 10 { 11 private MBeanServer server; 12 private CacheHelper helper; 13 14 public void contextInitialized(ServletContextEvent arg0) 15 { 16 server = MBeanServerLocator.locateJBoss(); 17 if (!server.isRegistered(CacheHelper.OBJECT_NAME)) 18 { 19 helper = new CacheHelper(server); 20 try 21 { 22 server.registerMBean(helper, CacheHelper.OBJECT_NAME); 23 } 24 catch (Exception e) 25 { 26 throw new RuntimeException (e); 27 } 28 } 29 } 30 31 public void contextDestroyed(ServletContextEvent arg0) 32 { 33 try 34 { 35 if (helper != null && !helper.getLeaveInstalledAfterShutdown() 36 && (server.isRegistered(CacheHelper.OBJECT_NAME))) 37 { 38 server.unregisterMBean(CacheHelper.OBJECT_NAME); 39 } 40 } 41 catch (Exception e) 42 { 43 throw new RuntimeException (e); 44 } 45 } 46 47 } 48 | Popular Tags |