KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cluster > web > CacheHelperServletContextListener


1 package org.jboss.test.cluster.web;
2
3 import javax.management.MBeanServer JavaDoc;
4 import javax.servlet.ServletContextEvent JavaDoc;
5 import javax.servlet.ServletContextListener JavaDoc;
6
7 import org.jboss.mx.util.MBeanServerLocator;
8
9 public class CacheHelperServletContextListener implements ServletContextListener JavaDoc
10 {
11    private MBeanServer JavaDoc server;
12    private CacheHelper helper;
13
14    public void contextInitialized(ServletContextEvent JavaDoc 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 JavaDoc e)
25          {
26             throw new RuntimeException JavaDoc(e);
27          }
28       }
29    }
30    
31    public void contextDestroyed(ServletContextEvent JavaDoc 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 JavaDoc e)
42       {
43          throw new RuntimeException JavaDoc(e);
44       }
45    }
46
47 }
48
Popular Tags