Source Code Cross Referenced for ServerLifecycleListener.java in  » Sevlet-Container » tomcat-catalina » org » apache » catalina » mbeans » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Sevlet Container » tomcat catalina » org.apache.catalina.mbeans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 1999-2002,2004 The Apache Software Foundation.
0003:         * 
0004:         * Licensed under the Apache License, Version 2.0 (the "License");
0005:         * you may not use this file except in compliance with the License.
0006:         * You may obtain a copy of the License at
0007:         * 
0008:         *      http://www.apache.org/licenses/LICENSE-2.0
0009:         * 
0010:         * Unless required by applicable law or agreed to in writing, software
0011:         * distributed under the License is distributed on an "AS IS" BASIS,
0012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013:         * See the License for the specific language governing permissions and
0014:         * limitations under the License.
0015:         */
0016:
0017:        package org.apache.catalina.mbeans;
0018:
0019:        import java.beans.PropertyChangeEvent;
0020:        import java.beans.PropertyChangeListener;
0021:        import java.util.StringTokenizer;
0022:        import javax.management.MBeanException;
0023:
0024:        import org.apache.catalina.Connector;
0025:        import org.apache.catalina.Container;
0026:        import org.apache.catalina.ContainerEvent;
0027:        import org.apache.catalina.ContainerListener;
0028:        import org.apache.catalina.Context;
0029:        import org.apache.catalina.DefaultContext;
0030:        import org.apache.catalina.Engine;
0031:        import org.apache.catalina.Globals;
0032:        import org.apache.catalina.Host;
0033:        import org.apache.catalina.Lifecycle;
0034:        import org.apache.catalina.LifecycleEvent;
0035:        import org.apache.catalina.LifecycleListener;
0036:        import org.apache.catalina.Loader;
0037:        import org.apache.catalina.Logger;
0038:        import org.apache.catalina.Manager;
0039:        import org.apache.catalina.Realm;
0040:        import org.apache.catalina.Server;
0041:        import org.apache.catalina.ServerFactory;
0042:        import org.apache.catalina.Service;
0043:        import org.apache.catalina.core.StandardContext;
0044:        import org.apache.catalina.core.StandardEngine;
0045:        import org.apache.catalina.core.StandardHost;
0046:        import org.apache.catalina.core.StandardServer;
0047:        import org.apache.catalina.core.StandardService;
0048:        import org.apache.catalina.deploy.ContextEnvironment;
0049:        import org.apache.catalina.deploy.ContextResource;
0050:        import org.apache.catalina.deploy.ContextResourceLink;
0051:        import org.apache.catalina.deploy.NamingResources;
0052:        import org.apache.commons.logging.Log;
0053:        import org.apache.commons.logging.LogFactory;
0054:
0055:        /**
0056:         * Implementation of <code>LifecycleListener</code> that
0057:         * instantiates the set of MBeans associated with the components of a
0058:         * running instance of Catalina.
0059:         *
0060:         * @author Craig R. McClanahan
0061:         * @author Amy Roh
0062:         * @version $Revision: 1.13 $ $Date: 2004/02/27 14:58:45 $
0063:         */
0064:
0065:        public class ServerLifecycleListener implements  ContainerListener,
0066:                LifecycleListener, PropertyChangeListener {
0067:
0068:            private static Log log = LogFactory
0069:                    .getLog(ServerLifecycleListener.class);
0070:
0071:            // ------------------------------------------------------------- Properties
0072:
0073:            /**
0074:             * The debugging detail level for this component.
0075:             */
0076:            protected int debug = 0;
0077:
0078:            public int getDebug() {
0079:                return (this .debug);
0080:            }
0081:
0082:            public void setDebug(int debug) {
0083:                this .debug = debug;
0084:            }
0085:
0086:            /**
0087:             * Semicolon separated list of paths containing MBean desciptor resources.
0088:             */
0089:            protected String descriptors = null;
0090:
0091:            public String getDescriptors() {
0092:                return (this .descriptors);
0093:            }
0094:
0095:            public void setDescriptors(String descriptors) {
0096:                this .descriptors = descriptors;
0097:            }
0098:
0099:            /**
0100:             * MX4J adaptor name.
0101:             */
0102:            protected String adaptor = null;
0103:
0104:            public String getAdaptor() {
0105:                return (this .adaptor);
0106:            }
0107:
0108:            public void setAdaptor(String adaptor) {
0109:                this .adaptor = adaptor;
0110:            }
0111:
0112:            /**
0113:             * MX4J jrmp/iiop listen host
0114:             */
0115:            protected String adaptorHost = null;
0116:
0117:            public String getAdaptorHost() {
0118:                return (this .adaptorHost);
0119:            }
0120:
0121:            public void setAdaptorHost(String adaptorHost) {
0122:                this .adaptorHost = adaptorHost;
0123:            }
0124:
0125:            /**
0126:             * MX4J jrmp/iiop listen port
0127:             */
0128:            protected int adaptorPort = -1;
0129:
0130:            public int getAdaptorPort() {
0131:                return (this .adaptorPort);
0132:            }
0133:
0134:            public void setAdaptorPort(int adaptorPort) {
0135:                this .adaptorPort = adaptorPort;
0136:            }
0137:
0138:            // ---------------------------------------------- ContainerListener Methods
0139:
0140:            /**
0141:             * Handle a <code>ContainerEvent</code> from one of the Containers we are
0142:             * interested in.
0143:             *
0144:             * @param event The event that has occurred
0145:             */
0146:            public void containerEvent(ContainerEvent event) {
0147:
0148:                try {
0149:                    String type = event.getType();
0150:                    if (Container.ADD_CHILD_EVENT.equals(type)) {
0151:                        processContainerAddChild(event.getContainer(),
0152:                                (Container) event.getData());
0153:                    } else if (Container.REMOVE_CHILD_EVENT.equals(type)) {
0154:                        processContainerRemoveChild(event.getContainer(),
0155:                                (Container) event.getData());
0156:                    }
0157:                } catch (Exception e) {
0158:                    log.error("Exception processing event " + event, e);
0159:                }
0160:
0161:            }
0162:
0163:            // ---------------------------------------------- LifecycleListener Methods
0164:
0165:            /**
0166:             * Primary entry point for startup and shutdown events.
0167:             *
0168:             * @param event The event that has occurred
0169:             */
0170:            public void lifecycleEvent(LifecycleEvent event) {
0171:
0172:                Lifecycle lifecycle = event.getLifecycle();
0173:                if (Lifecycle.START_EVENT.equals(event.getType())) {
0174:
0175:                    if (lifecycle instanceof  Server) {
0176:
0177:                        // Loading additional MBean descriptors
0178:                        loadMBeanDescriptors();
0179:
0180:                        createMBeans();
0181:
0182:                        if (adaptor != null) {
0183:                            try {
0184:                                MBeanUtils.createRMIAdaptor(adaptor,
0185:                                        adaptorHost, adaptorPort);
0186:                            } catch (Exception e) {
0187:                                log.error("createAdaptor: Exception", e);
0188:                            }
0189:                        }
0190:
0191:                    }
0192:
0193:                    // We are embedded.
0194:                    if (lifecycle instanceof  Service) {
0195:                        try {
0196:                            MBeanFactory factory = new MBeanFactory();
0197:                            createMBeans(factory);
0198:                            loadMBeanDescriptors();
0199:                            createMBeans((Service) lifecycle);
0200:                        } catch (Exception ex) {
0201:                            log.error("Create mbean factory");
0202:                        }
0203:                    }
0204:
0205:                    /*
0206:                    // Ignore events from StandardContext objects to avoid
0207:                    // reregistering the context
0208:                    if (lifecycle instanceof StandardContext)
0209:                        return;
0210:                    createMBeans();
0211:                     */
0212:
0213:                } else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
0214:                    try {
0215:                        if (lifecycle instanceof  Server) {
0216:                            destroyMBeans((Server) lifecycle);
0217:                        }
0218:                        if (lifecycle instanceof  Service) {
0219:                            destroyMBeans((Service) lifecycle);
0220:                        }
0221:                    } catch (MBeanException t) {
0222:
0223:                        Exception e = t.getTargetException();
0224:                        if (e == null) {
0225:                            e = t;
0226:                        }
0227:                        log.error("destroyMBeans: MBeanException", e);
0228:
0229:                    } catch (Throwable t) {
0230:
0231:                        log.error("destroyMBeans: Throwable", t);
0232:
0233:                    }
0234:                    // FIXME: RMI adaptor should be stopped; however, this is
0235:                    // undocumented in MX4J, and reports exist in the MX4J bug DB that
0236:                    // this doesn't work
0237:
0238:                }
0239:
0240:                if ((Context.RELOAD_EVENT.equals(event.getType()))
0241:                        || (Lifecycle.START_EVENT.equals(event.getType()))) {
0242:
0243:                    // Give context a new handle to the MBean server if the
0244:                    // context has been reloaded since reloading causes the
0245:                    // context to lose its previous handle to the server
0246:                    if (lifecycle instanceof  StandardContext) {
0247:                        // If the context is privileged, give a reference to it
0248:                        // in a servlet context attribute
0249:                        StandardContext context = (StandardContext) lifecycle;
0250:                        if (context.getPrivileged()) {
0251:                            context.getServletContext().setAttribute(
0252:                                    Globals.MBEAN_REGISTRY_ATTR,
0253:                                    MBeanUtils.createRegistry());
0254:                            context.getServletContext().setAttribute(
0255:                                    Globals.MBEAN_SERVER_ATTR,
0256:                                    MBeanUtils.createServer());
0257:                        }
0258:                    }
0259:
0260:                }
0261:
0262:            }
0263:
0264:            // ----------------------------------------- PropertyChangeListener Methods
0265:
0266:            /**
0267:             * Handle a <code>PropertyChangeEvent</code> from one of the Containers
0268:             * we are interested in.
0269:             *
0270:             * @param event The event that has occurred
0271:             */
0272:            public void propertyChange(PropertyChangeEvent event) {
0273:
0274:                if (event.getSource() instanceof  Container) {
0275:                    try {
0276:                        processContainerPropertyChange((Container) event
0277:                                .getSource(), event.getPropertyName(), event
0278:                                .getOldValue(), event.getNewValue());
0279:                    } catch (Exception e) {
0280:                        log.error(
0281:                                "Exception handling Container property change",
0282:                                e);
0283:                    }
0284:                } else if (event.getSource() instanceof  DefaultContext) {
0285:                    try {
0286:                        processDefaultContextPropertyChange(
0287:                                (DefaultContext) event.getSource(), event
0288:                                        .getPropertyName(),
0289:                                event.getOldValue(), event.getNewValue());
0290:                    } catch (Exception e) {
0291:                        log
0292:                                .error(
0293:                                        "Exception handling DefaultContext property change",
0294:                                        e);
0295:                    }
0296:                } else if (event.getSource() instanceof  NamingResources) {
0297:                    try {
0298:                        processNamingResourcesPropertyChange(
0299:                                (NamingResources) event.getSource(), event
0300:                                        .getPropertyName(),
0301:                                event.getOldValue(), event.getNewValue());
0302:                    } catch (Exception e) {
0303:                        log
0304:                                .error(
0305:                                        "Exception handling NamingResources property change",
0306:                                        e);
0307:                    }
0308:                } else if (event.getSource() instanceof  Server) {
0309:                    try {
0310:                        processServerPropertyChange((Server) event.getSource(),
0311:                                event.getPropertyName(), event.getOldValue(),
0312:                                event.getNewValue());
0313:                    } catch (Exception e) {
0314:                        log
0315:                                .error(
0316:                                        "Exception handing Server property change",
0317:                                        e);
0318:                    }
0319:                } else if (event.getSource() instanceof  Service) {
0320:                    try {
0321:                        processServicePropertyChange((Service) event
0322:                                .getSource(), event.getPropertyName(), event
0323:                                .getOldValue(), event.getNewValue());
0324:                    } catch (Exception e) {
0325:                        log.error("Exception handing Service property change",
0326:                                e);
0327:                    }
0328:                }
0329:
0330:            }
0331:
0332:            // ------------------------------------------------------ Protected Methods
0333:
0334:            /**
0335:             * Load additional MBean descriptor resources.
0336:             */
0337:            protected void loadMBeanDescriptors() {
0338:
0339:                if (descriptors != null) {
0340:                    StringTokenizer tokenizer = new StringTokenizer(
0341:                            descriptors, ";");
0342:                    while (tokenizer.hasMoreTokens()) {
0343:                        String resource = tokenizer.nextToken();
0344:                        MBeanUtils.loadMBeanDescriptors(resource);
0345:                    }
0346:                }
0347:
0348:            }
0349:
0350:            /**
0351:             * Create the MBeans that correspond to every existing node of our tree.
0352:             */
0353:            protected void createMBeans() {
0354:
0355:                try {
0356:
0357:                    MBeanFactory factory = new MBeanFactory();
0358:                    createMBeans(factory);
0359:                    createMBeans(ServerFactory.getServer());
0360:
0361:                } catch (MBeanException t) {
0362:
0363:                    Exception e = t.getTargetException();
0364:                    if (e == null)
0365:                        e = t;
0366:                    log.error("createMBeans: MBeanException", e);
0367:
0368:                } catch (Throwable t) {
0369:
0370:                    log.error("createMBeans: Throwable", t);
0371:
0372:                }
0373:
0374:            }
0375:
0376:            /**
0377:             * Create the MBeans for the specified Connector and its nested components.
0378:             *
0379:             * @param connector Connector for which to create MBeans
0380:             *
0381:             * @exception Exception if an exception is thrown during MBean creation
0382:             */
0383:            protected void createMBeans(Connector connector) throws Exception {
0384:
0385:                // Create the MBean for the Connnector itself
0386:                //        if (log.isDebugEnabled())
0387:                //            log.debug("Creating MBean for Connector " + connector);
0388:                //        MBeanUtils.createMBean(connector);
0389:
0390:            }
0391:
0392:            /**
0393:             * Create the MBeans for the specified Context and its nested components.
0394:             *
0395:             * @param context Context for which to create MBeans
0396:             *
0397:             * @exception Exception if an exception is thrown during MBean creation
0398:             */
0399:            protected void createMBeans(Context context) throws Exception {
0400:
0401:                // Create the MBean for the Context itself
0402:                //        if (log.isDebugEnabled())
0403:                //            log.debug("Creating MBean for Context " + context);
0404:                //        MBeanUtils.createMBean(context);
0405:                context.addContainerListener(this );
0406:                if (context instanceof  StandardContext) {
0407:                    ((StandardContext) context).addPropertyChangeListener(this );
0408:                    ((StandardContext) context).addLifecycleListener(this );
0409:                }
0410:
0411:                // If the context is privileged, give a reference to it
0412:                // in a servlet context attribute
0413:                if (context.getPrivileged()) {
0414:                    context.getServletContext().setAttribute(
0415:                            Globals.MBEAN_REGISTRY_ATTR,
0416:                            MBeanUtils.createRegistry());
0417:                    context.getServletContext().setAttribute(
0418:                            Globals.MBEAN_SERVER_ATTR,
0419:                            MBeanUtils.createServer());
0420:                }
0421:
0422:                // Create the MBeans for the associated nested components
0423:                Loader cLoader = context.getLoader();
0424:                if (cLoader != null) {
0425:                    if (log.isDebugEnabled())
0426:                        log.debug("Creating MBean for Loader " + cLoader);
0427:                    //MBeanUtils.createMBean(cLoader);
0428:                }
0429:                Logger hLogger = context.getParent().getLogger();
0430:                Logger cLogger = context.getLogger();
0431:                if ((cLogger != null) && (cLogger != hLogger)) {
0432:                    if (log.isDebugEnabled())
0433:                        log.debug("Creating MBean for Logger " + cLogger);
0434:                    //MBeanUtils.createMBean(cLogger);
0435:                }
0436:                Manager cManager = context.getManager();
0437:                if (cManager != null) {
0438:                    if (log.isDebugEnabled())
0439:                        log.debug("Creating MBean for Manager " + cManager);
0440:                    //MBeanUtils.createMBean(cManager);
0441:                }
0442:                Realm hRealm = context.getParent().getRealm();
0443:                Realm cRealm = context.getRealm();
0444:                if ((cRealm != null) && (cRealm != hRealm)) {
0445:                    if (log.isDebugEnabled())
0446:                        log.debug("Creating MBean for Realm " + cRealm);
0447:                    //MBeanUtils.createMBean(cRealm);
0448:                }
0449:
0450:                // Create the MBeans for the NamingResources (if any)
0451:                NamingResources resources = context.getNamingResources();
0452:                createMBeans(resources);
0453:
0454:            }
0455:
0456:            /**
0457:             * Create the MBeans for the specified ContextEnvironment entry.
0458:             *
0459:             * @param environment ContextEnvironment for which to create MBeans
0460:             *
0461:             * @exception Exception if an exception is thrown during MBean creation
0462:             */
0463:            protected void createMBeans(ContextEnvironment environment)
0464:                    throws Exception {
0465:
0466:                // Create the MBean for the ContextEnvironment itself
0467:                if (log.isDebugEnabled()) {
0468:                    log.debug("Creating MBean for ContextEnvironment "
0469:                            + environment);
0470:                }
0471:                MBeanUtils.createMBean(environment);
0472:
0473:            }
0474:
0475:            /**
0476:             * Create the MBeans for the specified ContextResource entry.
0477:             *
0478:             * @param resource ContextResource for which to create MBeans
0479:             *
0480:             * @exception Exception if an exception is thrown during MBean creation
0481:             */
0482:            protected void createMBeans(ContextResource resource)
0483:                    throws Exception {
0484:
0485:                // Create the MBean for the ContextResource itself
0486:                if (log.isDebugEnabled()) {
0487:                    log.debug("Creating MBean for ContextResource " + resource);
0488:                }
0489:                MBeanUtils.createMBean(resource);
0490:
0491:            }
0492:
0493:            /**
0494:             * Create the MBeans for the specified ContextResourceLink entry.
0495:             *
0496:             * @param resourceLink ContextResourceLink for which to create MBeans
0497:             *
0498:             * @exception Exception if an exception is thrown during MBean creation
0499:             */
0500:            protected void createMBeans(ContextResourceLink resourceLink)
0501:                    throws Exception {
0502:
0503:                // Create the MBean for the ContextResourceLink itself
0504:                if (log.isDebugEnabled()) {
0505:                    log.debug("Creating MBean for ContextResourceLink "
0506:                            + resourceLink);
0507:                }
0508:                MBeanUtils.createMBean(resourceLink);
0509:
0510:            }
0511:
0512:            /**
0513:             * Create the MBeans for the specified DefaultContext and its nested components.
0514:             *
0515:             * @param dcontext DefaultContext for which to create MBeans
0516:             *
0517:             * @exception Exception if an exception is thrown during MBean creation
0518:             */
0519:            protected void createMBeans(DefaultContext dcontext)
0520:                    throws Exception {
0521:
0522:                // Create the MBean for the DefaultContext itself
0523:                if (log.isDebugEnabled())
0524:                    log.debug("Creating MBean for DefaultContext " + dcontext);
0525:                MBeanUtils.createMBean(dcontext);
0526:
0527:                dcontext.addPropertyChangeListener(this );
0528:
0529:                // Create the MBeans for the associated nested components
0530:                Loader dLoader = dcontext.getLoader();
0531:                if (dLoader != null) {
0532:                    if (log.isDebugEnabled())
0533:                        log.debug("Creating MBean for Loader " + dLoader);
0534:                    //MBeanUtils.createMBean(dLoader);
0535:                }
0536:
0537:                Manager dManager = dcontext.getManager();
0538:                if (dManager != null) {
0539:                    if (log.isDebugEnabled())
0540:                        log.debug("Creating MBean for Manager " + dManager);
0541:                    //MBeanUtils.createMBean(dManager);
0542:                }
0543:
0544:                // Create the MBeans for the NamingResources (if any)
0545:                NamingResources resources = dcontext.getNamingResources();
0546:                createMBeans(resources);
0547:
0548:            }
0549:
0550:            /**
0551:             * Create the MBeans for the specified Engine and its nested components.
0552:             *
0553:             * @param engine Engine for which to create MBeans
0554:             *
0555:             * @exception Exception if an exception is thrown during MBean creation
0556:             */
0557:            protected void createMBeans(Engine engine) throws Exception {
0558:
0559:                // Create the MBean for the Engine itself
0560:                if (log.isDebugEnabled()) {
0561:                    log.debug("Creating MBean for Engine " + engine);
0562:                }
0563:                //MBeanUtils.createMBean(engine);
0564:                engine.addContainerListener(this );
0565:                if (engine instanceof  StandardEngine) {
0566:                    ((StandardEngine) engine).addPropertyChangeListener(this );
0567:                }
0568:
0569:                // Create the MBeans for the associated nested components
0570:                Logger eLogger = engine.getLogger();
0571:                if (eLogger != null) {
0572:                    if (log.isDebugEnabled())
0573:                        log.debug("Creating MBean for Logger " + eLogger);
0574:                    //MBeanUtils.createMBean(eLogger);
0575:                }
0576:                Realm eRealm = engine.getRealm();
0577:                if (eRealm != null) {
0578:                    if (log.isDebugEnabled())
0579:                        log.debug("Creating MBean for Realm " + eRealm);
0580:                    //MBeanUtils.createMBean(eRealm);
0581:                }
0582:
0583:                // Create the MBeans for each child Host
0584:                Container hosts[] = engine.findChildren();
0585:                for (int j = 0; j < hosts.length; j++) {
0586:                    createMBeans((Host) hosts[j]);
0587:                }
0588:
0589:                // Create the MBeans for DefaultContext
0590:                DefaultContext dcontext = engine.getDefaultContext();
0591:                if (dcontext != null) {
0592:                    dcontext.setParent(engine);
0593:                    createMBeans(dcontext);
0594:                }
0595:
0596:            }
0597:
0598:            /**
0599:             * Create the MBeans for the specified Host and its nested components.
0600:             *
0601:             * @param host Host for which to create MBeans
0602:             *
0603:             * @exception Exception if an exception is thrown during MBean creation
0604:             */
0605:            protected void createMBeans(Host host) throws Exception {
0606:
0607:                // Create the MBean for the Host itself
0608:                if (log.isDebugEnabled()) {
0609:                    log.debug("Creating MBean for Host " + host);
0610:                }
0611:                //MBeanUtils.createMBean(host);
0612:                host.addContainerListener(this );
0613:                if (host instanceof  StandardHost) {
0614:                    ((StandardHost) host).addPropertyChangeListener(this );
0615:                }
0616:
0617:                // Create the MBeans for the associated nested components
0618:                Logger eLogger = host.getParent().getLogger();
0619:                Logger hLogger = host.getLogger();
0620:                if ((hLogger != null) && (hLogger != eLogger)) {
0621:                    if (log.isDebugEnabled())
0622:                        log.debug("Creating MBean for Logger " + hLogger);
0623:                    //MBeanUtils.createMBean(hLogger);
0624:                }
0625:                Realm eRealm = host.getParent().getRealm();
0626:                Realm hRealm = host.getRealm();
0627:                if ((hRealm != null) && (hRealm != eRealm)) {
0628:                    if (log.isDebugEnabled())
0629:                        log.debug("Creating MBean for Realm " + hRealm);
0630:                    //MBeanUtils.createMBean(hRealm);
0631:                }
0632:
0633:                // Create the MBeans for each child Context
0634:                Container contexts[] = host.findChildren();
0635:                for (int k = 0; k < contexts.length; k++) {
0636:                    createMBeans((Context) contexts[k]);
0637:                }
0638:
0639:                // Create the MBeans for DefaultContext
0640:                DefaultContext dcontext = host.getDefaultContext();
0641:                if (dcontext != null) {
0642:                    dcontext.setParent(host);
0643:                    createMBeans(dcontext);
0644:                }
0645:
0646:            }
0647:
0648:            /**
0649:             * Create the MBeans for MBeanFactory.
0650:             *
0651:             * @param factory MBeanFactory for which to create MBean
0652:             *
0653:             * @exception Exception if an exception is thrown during MBean creation
0654:             */
0655:            protected void createMBeans(MBeanFactory factory) throws Exception {
0656:
0657:                // Create the MBean for the MBeanFactory
0658:                if (log.isDebugEnabled())
0659:                    log.debug("Creating MBean for MBeanFactory " + factory);
0660:                MBeanUtils.createMBean(factory);
0661:
0662:            }
0663:
0664:            /**
0665:             * Create the MBeans for the specified NamingResources and its
0666:             * nested components.
0667:             *
0668:             * @param resources NamingResources for which to create MBeans
0669:             */
0670:            protected void createMBeans(NamingResources resources)
0671:                    throws Exception {
0672:
0673:                // Create the MBean for the NamingResources itself
0674:                if (log.isDebugEnabled()) {
0675:                    log
0676:                            .debug("Creating MBean for NamingResources "
0677:                                    + resources);
0678:                }
0679:                MBeanUtils.createMBean(resources);
0680:                resources.addPropertyChangeListener(this );
0681:
0682:                // Create the MBeans for each child environment entry
0683:                ContextEnvironment environments[] = resources
0684:                        .findEnvironments();
0685:                for (int i = 0; i < environments.length; i++) {
0686:                    createMBeans(environments[i]);
0687:                }
0688:
0689:                // Create the MBeans for each child resource entry
0690:                ContextResource cresources[] = resources.findResources();
0691:                for (int i = 0; i < cresources.length; i++) {
0692:                    createMBeans(cresources[i]);
0693:                }
0694:
0695:                // Create the MBeans for each child resource link entry
0696:                ContextResourceLink cresourcelinks[] = resources
0697:                        .findResourceLinks();
0698:                for (int i = 0; i < cresourcelinks.length; i++) {
0699:                    createMBeans(cresourcelinks[i]);
0700:                }
0701:
0702:            }
0703:
0704:            /**
0705:             * Create the MBeans for the specified Server and its nested components.
0706:             *
0707:             * @param server Server for which to create MBeans
0708:             *
0709:             * @exception Exception if an exception is thrown during MBean creation
0710:             */
0711:            protected void createMBeans(Server server) throws Exception {
0712:
0713:                // Create the MBean for the Server itself
0714:                if (log.isDebugEnabled())
0715:                    log.debug("Creating MBean for Server " + server);
0716:                //MBeanUtils.createMBean(server);
0717:                if (server instanceof  StandardServer) {
0718:                    ((StandardServer) server).addPropertyChangeListener(this );
0719:                }
0720:
0721:                // Create the MBeans for the global NamingResources (if any)
0722:                NamingResources resources = server.getGlobalNamingResources();
0723:                if (resources != null) {
0724:                    createMBeans(resources);
0725:                }
0726:
0727:                // Create the MBeans for each child Service
0728:                Service services[] = server.findServices();
0729:                for (int i = 0; i < services.length; i++) {
0730:                    // FIXME - Warp object hierarchy not currently supported
0731:                    if (services[i].getContainer().getClass().getName().equals(
0732:                            "org.apache.catalina.connector.warp.WarpEngine")) {
0733:                        if (log.isDebugEnabled()) {
0734:                            log.debug("Skipping MBean for Service "
0735:                                    + services[i]);
0736:                        }
0737:                        continue;
0738:                    }
0739:                    createMBeans(services[i]);
0740:                }
0741:
0742:            }
0743:
0744:            /**
0745:             * Create the MBeans for the specified Service and its nested components.
0746:             *
0747:             * @param service Service for which to create MBeans
0748:             *
0749:             * @exception Exception if an exception is thrown during MBean creation
0750:             */
0751:            protected void createMBeans(Service service) throws Exception {
0752:
0753:                // Create the MBean for the Service itself
0754:                if (log.isDebugEnabled())
0755:                    log.debug("Creating MBean for Service " + service);
0756:                //MBeanUtils.createMBean(service);
0757:                if (service instanceof  StandardService) {
0758:                    ((StandardService) service).addPropertyChangeListener(this );
0759:                }
0760:
0761:                // Create the MBeans for the corresponding Connectors
0762:                Connector connectors[] = service.findConnectors();
0763:                for (int j = 0; j < connectors.length; j++) {
0764:                    createMBeans(connectors[j]);
0765:                }
0766:
0767:                // Create the MBean for the associated Engine and friends
0768:                Engine engine = (Engine) service.getContainer();
0769:                if (engine != null) {
0770:                    createMBeans(engine);
0771:                }
0772:
0773:            }
0774:
0775:            /**
0776:             * Deregister the MBeans for the specified Connector and its nested
0777:             * components.
0778:             *
0779:             * @param connector Connector for which to deregister MBeans
0780:             *
0781:             * @exception Exception if an exception is thrown during MBean destruction
0782:             */
0783:            protected void destroyMBeans(Connector connector, Service service)
0784:                    throws Exception {
0785:
0786:                //        // deregister the MBean for the Connector itself
0787:                //        if (log.isDebugEnabled())
0788:                //            log.debug("Destroying MBean for Connector " + connector);
0789:                //        MBeanUtils.destroyMBean(connector, service);
0790:
0791:            }
0792:
0793:            /**
0794:             * Deregister the MBeans for the specified Context and its nested
0795:             * components.
0796:             *
0797:             * @param context Context for which to deregister MBeans
0798:             *
0799:             * @exception Exception if an exception is thrown during MBean destruction
0800:             */
0801:            protected void destroyMBeans(Context context) throws Exception {
0802:
0803:                // Deregister ourselves as a ContainerListener
0804:                context.removeContainerListener(this );
0805:
0806:                // Destroy the MBeans for the associated nested components
0807:                Realm hRealm = context.getParent().getRealm();
0808:                Realm cRealm = context.getRealm();
0809:                if ((cRealm != null) && (cRealm != hRealm)) {
0810:                    if (log.isDebugEnabled())
0811:                        log.debug("Destroying MBean for Realm " + cRealm);
0812:                    //MBeanUtils.destroyMBean(cRealm);
0813:                }
0814:                Manager cManager = context.getManager();
0815:                if (cManager != null) {
0816:                    if (log.isDebugEnabled())
0817:                        log.debug("Destroying MBean for Manager " + cManager);
0818:                    //MBeanUtils.destroyMBean(cManager);
0819:                }
0820:                Logger hLogger = context.getParent().getLogger();
0821:                Logger cLogger = context.getLogger();
0822:                if ((cLogger != null) && (cLogger != hLogger)) {
0823:                    if (log.isDebugEnabled())
0824:                        log.debug("Destroying MBean for Logger " + cLogger);
0825:                    //MBeanUtils.destroyMBean(cLogger);
0826:                }
0827:                Loader cLoader = context.getLoader();
0828:                if (cLoader != null) {
0829:                    if (log.isDebugEnabled())
0830:                        log.debug("Destroying MBean for Loader " + cLoader);
0831:                    //MBeanUtils.destroyMBean(cLoader);
0832:                }
0833:
0834:                // Destroy the MBeans for the NamingResources (if any)
0835:                NamingResources resources = context.getNamingResources();
0836:                if (resources != null) {
0837:                    destroyMBeans(resources);
0838:                }
0839:
0840:                // deregister the MBean for the Context itself
0841:                if (log.isDebugEnabled())
0842:                    log.debug("Destroying MBean for Context " + context);
0843:                //MBeanUtils.destroyMBean(context);
0844:                if (context instanceof  StandardContext) {
0845:                    ((StandardContext) context)
0846:                            .removePropertyChangeListener(this );
0847:                }
0848:
0849:            }
0850:
0851:            /**
0852:             * Deregister the MBeans for the specified ContextEnvironment entry.
0853:             *
0854:             * @param environment ContextEnvironment for which to destroy MBeans
0855:             *
0856:             * @exception Exception if an exception is thrown during MBean destruction
0857:             */
0858:            protected void destroyMBeans(ContextEnvironment environment)
0859:                    throws Exception {
0860:
0861:                // Destroy the MBean for the ContextEnvironment itself
0862:                if (log.isDebugEnabled()) {
0863:                    log.debug("Destroying MBean for ContextEnvironment "
0864:                            + environment);
0865:                }
0866:                MBeanUtils.destroyMBean(environment);
0867:
0868:            }
0869:
0870:            /**
0871:             * Deregister the MBeans for the specified ContextResource entry.
0872:             *
0873:             * @param resource ContextResource for which to destroy MBeans
0874:             *
0875:             * @exception Exception if an exception is thrown during MBean destruction
0876:             */
0877:            protected void destroyMBeans(ContextResource resource)
0878:                    throws Exception {
0879:
0880:                // Destroy the MBean for the ContextResource itself
0881:                if (log.isDebugEnabled()) {
0882:                    log.debug("Destroying MBean for ContextResource "
0883:                            + resource);
0884:                }
0885:                MBeanUtils.destroyMBean(resource);
0886:
0887:            }
0888:
0889:            /**
0890:             * Deregister the MBeans for the specified ContextResourceLink entry.
0891:             *
0892:             * @param resourceLink ContextResourceLink for which to destroy MBeans
0893:             *
0894:             * @exception Exception if an exception is thrown during MBean destruction
0895:             */
0896:            protected void destroyMBeans(ContextResourceLink resourceLink)
0897:                    throws Exception {
0898:
0899:                // Destroy the MBean for the ContextResourceLink itself
0900:                if (log.isDebugEnabled()) {
0901:                    log.debug("Destroying MBean for ContextResourceLink "
0902:                            + resourceLink);
0903:                }
0904:                MBeanUtils.destroyMBean(resourceLink);
0905:
0906:            }
0907:
0908:            /**
0909:             * Deregister the MBeans for the specified DefaultContext and its nested
0910:             * components.
0911:             *
0912:             * @param dcontext DefaultContext for which to deregister MBeans
0913:             *
0914:             * @exception Exception if an exception is thrown during MBean destruction
0915:             */
0916:            protected void destroyMBeans(DefaultContext dcontext)
0917:                    throws Exception {
0918:
0919:                Manager dManager = dcontext.getManager();
0920:                if (dManager != null) {
0921:                    if (log.isDebugEnabled())
0922:                        log.debug("Destroying MBean for Manager " + dManager);
0923:                    //MBeanUtils.destroyMBean(dManager);
0924:                }
0925:
0926:                Loader dLoader = dcontext.getLoader();
0927:                if (dLoader != null) {
0928:                    if (log.isDebugEnabled())
0929:                        log.debug("Destroying MBean for Loader " + dLoader);
0930:                    //MBeanUtils.destroyMBean(dLoader);
0931:                }
0932:
0933:                // Destroy the MBeans for the NamingResources (if any)
0934:                NamingResources resources = dcontext.getNamingResources();
0935:                if (resources != null) {
0936:                    destroyMBeans(resources);
0937:                }
0938:
0939:                // deregister the MBean for the DefaultContext itself
0940:                if (log.isDebugEnabled())
0941:                    log.debug("Destroying MBean for Context " + dcontext);
0942:                MBeanUtils.destroyMBean(dcontext);
0943:                dcontext.removePropertyChangeListener(this );
0944:
0945:            }
0946:
0947:            /**
0948:             * Deregister the MBeans for the specified Engine and its nested
0949:             * components.
0950:             *
0951:             * @param engine Engine for which to destroy MBeans
0952:             *
0953:             * @exception Exception if an exception is thrown during MBean destruction
0954:             */
0955:            protected void destroyMBeans(Engine engine) throws Exception {
0956:
0957:                // Deregister ourselves as a ContainerListener
0958:                engine.removeContainerListener(this );
0959:
0960:                // Deregister the MBeans for each child Host
0961:                Container hosts[] = engine.findChildren();
0962:                for (int k = 0; k < hosts.length; k++) {
0963:                    destroyMBeans((Host) hosts[k]);
0964:                }
0965:
0966:                // Deregister the MBeans for the associated nested components
0967:                Realm eRealm = engine.getRealm();
0968:                if (eRealm != null) {
0969:                    if (log.isDebugEnabled())
0970:                        log.debug("Destroying MBean for Realm " + eRealm);
0971:                    //MBeanUtils.destroyMBean(eRealm);
0972:                }
0973:                Logger eLogger = engine.getLogger();
0974:                if (eLogger != null) {
0975:                    if (log.isDebugEnabled())
0976:                        log.debug("Destroying MBean for Logger " + eLogger);
0977:                    //MBeanUtils.destroyMBean(eLogger);
0978:                }
0979:
0980:                // Deregister the MBean for the Engine itself
0981:                if (log.isDebugEnabled()) {
0982:                    log.debug("Destroying MBean for Engine " + engine);
0983:                }
0984:                //MBeanUtils.destroyMBean(engine);
0985:
0986:            }
0987:
0988:            /**
0989:             * Deregister the MBeans for the specified Host and its nested components.
0990:             *
0991:             * @param host Host for which to destroy MBeans
0992:             *
0993:             * @exception Exception if an exception is thrown during MBean destruction
0994:             */
0995:            protected void destroyMBeans(Host host) throws Exception {
0996:
0997:                // Deregister ourselves as a ContainerListener
0998:                host.removeContainerListener(this );
0999:
1000:                // Deregister the MBeans for each child Context
1001:                Container contexts[] = host.findChildren();
1002:                for (int k = 0; k < contexts.length; k++) {
1003:                    destroyMBeans((Context) contexts[k]);
1004:                }
1005:
1006:                // Deregister the MBeans for the associated nested components
1007:                Realm eRealm = host.getParent().getRealm();
1008:                Realm hRealm = host.getRealm();
1009:                if ((hRealm != null) && (hRealm != eRealm)) {
1010:                    if (log.isDebugEnabled())
1011:                        log.debug("Destroying MBean for Realm " + hRealm);
1012:                    //MBeanUtils.destroyMBean(hRealm);
1013:                }
1014:                Logger eLogger = host.getParent().getLogger();
1015:                Logger hLogger = host.getLogger();
1016:                if ((hLogger != null) && (hLogger != eLogger)) {
1017:                    if (log.isDebugEnabled())
1018:                        log.debug("Destroying MBean for Logger " + hLogger);
1019:                    //MBeanUtils.destroyMBean(hLogger);
1020:                }
1021:
1022:                // Deregister the MBean for the Host itself
1023:                if (log.isDebugEnabled()) {
1024:                    log.debug("Destroying MBean for Host " + host);
1025:                }
1026:                //MBeanUtils.destroyMBean(host);
1027:
1028:            }
1029:
1030:            /**
1031:             * Deregister the MBeans for the specified NamingResources and its
1032:             * nested components.
1033:             *
1034:             * @param resources NamingResources for which to destroy MBeans
1035:             *
1036:             * @exception Exception if an exception is thrown during MBean destruction
1037:             */
1038:            protected void destroyMBeans(NamingResources resources)
1039:                    throws Exception {
1040:
1041:                // Destroy the MBeans for each child resource entry
1042:                ContextResource cresources[] = resources.findResources();
1043:                for (int i = 0; i < cresources.length; i++) {
1044:                    destroyMBeans(cresources[i]);
1045:                }
1046:
1047:                // Destroy the MBeans for each child resource link entry
1048:                ContextResourceLink cresourcelinks[] = resources
1049:                        .findResourceLinks();
1050:                for (int i = 0; i < cresourcelinks.length; i++) {
1051:                    destroyMBeans(cresourcelinks[i]);
1052:                }
1053:
1054:                // Destroy the MBeans for each child environment entry
1055:                ContextEnvironment environments[] = resources
1056:                        .findEnvironments();
1057:                for (int i = 0; i < environments.length; i++) {
1058:                    destroyMBeans(environments[i]);
1059:                }
1060:
1061:                // Destroy the MBean for the NamingResources itself
1062:                if (log.isDebugEnabled()) {
1063:                    log.debug("Destroying MBean for NamingResources "
1064:                            + resources);
1065:                }
1066:                MBeanUtils.destroyMBean(resources);
1067:                resources.removePropertyChangeListener(this );
1068:
1069:            }
1070:
1071:            /**
1072:             * Deregister the MBeans for the specified Server and its related
1073:             * components.
1074:             *
1075:             * @param server Server for which to destroy MBeans
1076:             *
1077:             * @exception Exception if an exception is thrown during MBean destruction
1078:             */
1079:            protected void destroyMBeans(Server server) throws Exception {
1080:
1081:                // Destroy the MBeans for the global NamingResources (if any)
1082:                NamingResources resources = server.getGlobalNamingResources();
1083:                if (resources != null) {
1084:                    destroyMBeans(resources);
1085:                }
1086:
1087:                // Destroy the MBeans for each child Service
1088:                Service services[] = server.findServices();
1089:                for (int i = 0; i < services.length; i++) {
1090:                    // FIXME - Warp object hierarchy not currently supported
1091:                    if (services[i].getContainer().getClass().getName().equals(
1092:                            "org.apache.catalina.connector.warp.WarpEngine")) {
1093:                        if (log.isDebugEnabled()) {
1094:                            log.debug("Skipping MBean for Service "
1095:                                    + services[i]);
1096:                        }
1097:                        continue;
1098:                    }
1099:                    destroyMBeans(services[i]);
1100:                }
1101:
1102:                // Destroy the MBean for the Server itself
1103:                if (log.isDebugEnabled()) {
1104:                    log.debug("Destroying MBean for Server " + server);
1105:                }
1106:                //MBeanUtils.destroyMBean(server);
1107:                if (server instanceof  StandardServer) {
1108:                    ((StandardServer) server)
1109:                            .removePropertyChangeListener(this );
1110:                }
1111:
1112:            }
1113:
1114:            /**
1115:             * Deregister the MBeans for the specified Service and its nested
1116:             * components.
1117:             *
1118:             * @param service Service for which to destroy MBeans
1119:             *
1120:             * @exception Exception if an exception is thrown during MBean destruction
1121:             */
1122:            protected void destroyMBeans(Service service) throws Exception {
1123:
1124:                // Deregister the MBeans for the associated Engine
1125:                Engine engine = (Engine) service.getContainer();
1126:                if (engine != null) {
1127:                    //destroyMBeans(engine);
1128:                }
1129:
1130:                //        // Deregister the MBeans for the corresponding Connectors
1131:                //        Connector connectors[] = service.findConnectors();
1132:                //        for (int j = 0; j < connectors.length; j++) {
1133:                //            destroyMBeans(connectors[j], service);
1134:                //        }
1135:
1136:                // Deregister the MBean for the Service itself
1137:                if (log.isDebugEnabled()) {
1138:                    log.debug("Destroying MBean for Service " + service);
1139:                }
1140:                //MBeanUtils.destroyMBean(service);
1141:                if (service instanceof  StandardService) {
1142:                    ((StandardService) service)
1143:                            .removePropertyChangeListener(this );
1144:                }
1145:
1146:            }
1147:
1148:            /**
1149:             * Log a message.
1150:             *
1151:             * @param message The message to be logged
1152:             */
1153:            protected void log(String message) {
1154:
1155:                System.out.print("ServerLifecycleListener: ");
1156:                System.out.println(message);
1157:
1158:            }
1159:
1160:            /**
1161:             * Log a message and associated exception.
1162:             *
1163:             * @param message The message to be logged
1164:             * @param throwable The exception to be logged
1165:             */
1166:            protected void log(String message, Throwable throwable) {
1167:
1168:                log(message);
1169:                throwable.printStackTrace(System.out);
1170:
1171:            }
1172:
1173:            /**
1174:             * Process the addition of a new child Container to a parent Container.
1175:             *
1176:             * @param parent Parent container
1177:             * @param child Child container
1178:             */
1179:            protected void processContainerAddChild(Container parent,
1180:                    Container child) {
1181:
1182:                if (log.isDebugEnabled())
1183:                    log.debug("Process addChild[parent=" + parent + ",child="
1184:                            + child + "]");
1185:
1186:                try {
1187:                    if (child instanceof  Context) {
1188:                        createMBeans((Context) child);
1189:                    } else if (child instanceof  Engine) {
1190:                        createMBeans((Engine) child);
1191:                    } else if (child instanceof  Host) {
1192:                        createMBeans((Host) child);
1193:                    }
1194:                } catch (MBeanException t) {
1195:                    Exception e = t.getTargetException();
1196:                    if (e == null)
1197:                        e = t;
1198:                    log.error("processContainerAddChild: MBeanException", e);
1199:                } catch (Throwable t) {
1200:                    log.error("processContainerAddChild: Throwable", t);
1201:                }
1202:
1203:            }
1204:
1205:            /**
1206:             * Process a property change event on a Container.
1207:             *
1208:             * @param container The container on which this event occurred
1209:             * @param propertyName The name of the property that changed
1210:             * @param oldValue The previous value (may be <code>null</code>)
1211:             * @param newValue The new value (may be <code>null</code>)
1212:             *
1213:             * @exception Exception if an exception is thrown
1214:             */
1215:            protected void processContainerPropertyChange(Container container,
1216:                    String propertyName, Object oldValue, Object newValue)
1217:                    throws Exception {
1218:
1219:                if (log.isTraceEnabled()) {
1220:                    log.trace("propertyChange[container=" + container
1221:                            + ",propertyName=" + propertyName + ",oldValue="
1222:                            + oldValue + ",newValue=" + newValue + "]");
1223:                }
1224:                if ("defaultContext".equals(propertyName)) {
1225:                    if (oldValue != null) {
1226:                        if (log.isDebugEnabled()) {
1227:                            log.debug("Removing MBean for DefaultContext "
1228:                                    + oldValue);
1229:                        }
1230:                        destroyMBeans((DefaultContext) oldValue);
1231:                    }
1232:                    if (newValue != null) {
1233:                        if (log.isDebugEnabled()) {
1234:                            log.debug("Creating MBean for DefaultContext "
1235:                                    + newValue);
1236:                        }
1237:                        createMBeans((DefaultContext) newValue);
1238:                    }
1239:                } else if ("loader".equals(propertyName)) {
1240:                    if (oldValue != null) {
1241:                        if (log.isDebugEnabled()) {
1242:                            log.debug("Removing MBean for Loader " + oldValue);
1243:                        }
1244:                        MBeanUtils.destroyMBean((Loader) oldValue);
1245:                    }
1246:                    if (newValue != null) {
1247:                        if (log.isDebugEnabled()) {
1248:                            log.debug("Creating MBean for Loader " + newValue);
1249:                        }
1250:                        MBeanUtils.createMBean((Loader) newValue);
1251:                    }
1252:                } else if ("logger".equals(propertyName)) {
1253:                    if (oldValue != null) {
1254:                        if (log.isDebugEnabled()) {
1255:                            log.debug("Removing MBean for Logger " + oldValue);
1256:                        }
1257:                        // MBeanUtils.destroyMBean((Logger) oldValue);
1258:                    }
1259:                    if (newValue != null) {
1260:                        if (log.isDebugEnabled()) {
1261:                            log.debug("Creating MBean for Logger " + newValue);
1262:                        }
1263:                        //MBeanUtils.createMBean((Logger) newValue);
1264:                    }
1265:                } else if ("manager".equals(propertyName)) {
1266:                    if (oldValue != null) {
1267:                        if (log.isDebugEnabled()) {
1268:                            log.debug("Removing MBean for Manager " + oldValue);
1269:                        }
1270:                        //MBeanUtils.destroyMBean((Manager) oldValue);
1271:                    }
1272:                    if (newValue != null) {
1273:                        if (log.isDebugEnabled()) {
1274:                            log.debug("Creating MBean for Manager " + newValue);
1275:                        }
1276:                        //MBeanUtils.createMBean((Manager) newValue);
1277:                    }
1278:                } else if ("realm".equals(propertyName)) {
1279:                    if (oldValue != null) {
1280:                        if (log.isDebugEnabled()) {
1281:                            log.debug("Removing MBean for Realm " + oldValue);
1282:                        }
1283:                        MBeanUtils.destroyMBean((Realm) oldValue);
1284:                    }
1285:                    if (newValue != null) {
1286:                        if (log.isDebugEnabled()) {
1287:                            log.debug("Creating MBean for Realm " + newValue);
1288:                        }
1289:                        //MBeanUtils.createMBean((Realm) newValue);
1290:                    }
1291:                } else if ("service".equals(propertyName)) {
1292:                    if (oldValue != null) {
1293:                        destroyMBeans((Service) oldValue);
1294:                    }
1295:                    if (newValue != null) {
1296:                        createMBeans((Service) newValue);
1297:                    }
1298:                }
1299:
1300:            }
1301:
1302:            /**
1303:             * Process a property change event on a DefaultContext.
1304:             *
1305:             * @param defaultContext The DefaultContext on which this event occurred
1306:             * @param propertyName The name of the property that changed
1307:             * @param oldValue The previous value (may be <code>null</code>)
1308:             * @param newValue The new value (may be <code>null</code>)
1309:             *
1310:             * @exception Exception if an exception is thrown
1311:             */
1312:            protected void processDefaultContextPropertyChange(
1313:                    DefaultContext defaultContext, String propertyName,
1314:                    Object oldValue, Object newValue) throws Exception {
1315:
1316:                if (log.isTraceEnabled()) {
1317:                    log.trace("propertyChange[defaultContext=" + defaultContext
1318:                            + ",propertyName=" + propertyName + ",oldValue="
1319:                            + oldValue + ",newValue=" + newValue + "]");
1320:                }
1321:                if ("loader".equals(propertyName)) {
1322:                    if (oldValue != null) {
1323:                        if (log.isDebugEnabled()) {
1324:                            log.debug("Removing MBean for Loader " + oldValue);
1325:                        }
1326:                        MBeanUtils.destroyMBean((Loader) oldValue);
1327:                    }
1328:                    if (newValue != null) {
1329:                        if (log.isDebugEnabled()) {
1330:                            log.debug("Creating MBean for Loader " + newValue);
1331:                        }
1332:                        MBeanUtils.createMBean((Loader) newValue);
1333:                    }
1334:                } else if ("logger".equals(propertyName)) {
1335:                    if (oldValue != null) {
1336:                        if (log.isDebugEnabled()) {
1337:                            log.debug("Removing MBean for Logger " + oldValue);
1338:                        }
1339:                        //MBeanUtils.destroyMBean((Logger) oldValue);
1340:                    }
1341:                    if (newValue != null) {
1342:                        if (log.isDebugEnabled()) {
1343:                            log.debug("Creating MBean for Logger " + newValue);
1344:                        }
1345:                        //MBeanUtils.createMBean((Logger) newValue);
1346:                    }
1347:                } else if ("manager".equals(propertyName)) {
1348:                    if (oldValue != null) {
1349:                        if (log.isDebugEnabled()) {
1350:                            log.debug("Removing MBean for Manager " + oldValue);
1351:                        }
1352:                        MBeanUtils.destroyMBean((Manager) oldValue);
1353:                    }
1354:                    if (newValue != null) {
1355:                        if (log.isDebugEnabled()) {
1356:                            log.debug("Creating MBean for Manager " + newValue);
1357:                        }
1358:                        MBeanUtils.createMBean((Manager) newValue);
1359:                    }
1360:                } else if ("realm".equals(propertyName)) {
1361:                    if (oldValue != null) {
1362:                        //                if (log.isDebugEnabled()) {
1363:                        //                    log.debug("Removing MBean for Realm " + oldValue);
1364:                        //                }
1365:                        //                //MBeanUtils.destroyMBean((Realm) oldValue);
1366:                    }
1367:                    if (newValue != null) {
1368:                        //                if (log.isDebugEnabled()) {
1369:                        //                    log.debug("Creating MBean for Realm " + newValue);
1370:                        //                }
1371:                        //                //MBeanUtils.createMBean((Realm) newValue);
1372:                    }
1373:                } else if ("service".equals(propertyName)) {
1374:                    if (oldValue != null) {
1375:                        destroyMBeans((Service) oldValue);
1376:                    }
1377:                    if (newValue != null) {
1378:                        createMBeans((Service) newValue);
1379:                    }
1380:                }
1381:
1382:            }
1383:
1384:            /**
1385:             * Process the removal of a child Container from a parent Container.
1386:             *
1387:             * @param parent Parent container
1388:             * @param child Child container
1389:             */
1390:            protected void processContainerRemoveChild(Container parent,
1391:                    Container child) {
1392:
1393:                if (log.isDebugEnabled())
1394:                    log.debug("Process removeChild[parent=" + parent
1395:                            + ",child=" + child + "]");
1396:
1397:                try {
1398:                    if (child instanceof  Context) {
1399:                        Context context = (Context) child;
1400:                        if (context.getPrivileged()) {
1401:                            context.getServletContext().removeAttribute(
1402:                                    Globals.MBEAN_REGISTRY_ATTR);
1403:                            context.getServletContext().removeAttribute(
1404:                                    Globals.MBEAN_SERVER_ATTR);
1405:                        }
1406:                        if (log.isDebugEnabled())
1407:                            log
1408:                                    .debug("  Removing MBean for Context "
1409:                                            + context);
1410:                        destroyMBeans(context);
1411:                        if (context instanceof  StandardContext) {
1412:                            ((StandardContext) context)
1413:                                    .removePropertyChangeListener(this );
1414:                        }
1415:                    } else if (child instanceof  Host) {
1416:                        Host host = (Host) child;
1417:                        destroyMBeans(host);
1418:                        if (host instanceof  StandardHost) {
1419:                            ((StandardHost) host)
1420:                                    .removePropertyChangeListener(this );
1421:                        }
1422:                    }
1423:                } catch (MBeanException t) {
1424:                    Exception e = t.getTargetException();
1425:                    if (e == null)
1426:                        e = t;
1427:                    log.error("processContainerRemoveChild: MBeanException", e);
1428:                } catch (Throwable t) {
1429:                    log.error("processContainerRemoveChild: Throwable", t);
1430:                }
1431:
1432:            }
1433:
1434:            /**
1435:             * Process a property change event on a NamingResources.
1436:             *
1437:             * @param resources The global naming resources on which this
1438:             *  event occurred
1439:             * @param propertyName The name of the property that changed
1440:             * @param oldValue The previous value (may be <code>null</code>)
1441:             * @param newValue The new value (may be <code>null</code>)
1442:             *
1443:             * @exception Exception if an exception is thrown
1444:             */
1445:            protected void processNamingResourcesPropertyChange(
1446:                    NamingResources resources, String propertyName,
1447:                    Object oldValue, Object newValue) throws Exception {
1448:
1449:                if (log.isTraceEnabled()) {
1450:                    log.trace("propertyChange[namingResources=" + resources
1451:                            + ",propertyName=" + propertyName + ",oldValue="
1452:                            + oldValue + ",newValue=" + newValue + "]");
1453:                }
1454:
1455:                // FIXME - Add other resource types when supported by admin tool
1456:                if ("environment".equals(propertyName)) {
1457:                    if (oldValue != null) {
1458:                        destroyMBeans((ContextEnvironment) oldValue);
1459:                    }
1460:                    if (newValue != null) {
1461:                        createMBeans((ContextEnvironment) newValue);
1462:                    }
1463:                } else if ("resource".equals(propertyName)) {
1464:                    if (oldValue != null) {
1465:                        destroyMBeans((ContextResource) oldValue);
1466:                    }
1467:                    if (newValue != null) {
1468:                        createMBeans((ContextResource) newValue);
1469:                    }
1470:                } else if ("resourceLink".equals(propertyName)) {
1471:                    if (oldValue != null) {
1472:                        destroyMBeans((ContextResourceLink) oldValue);
1473:                    }
1474:                    if (newValue != null) {
1475:                        createMBeans((ContextResourceLink) newValue);
1476:                    }
1477:                }
1478:
1479:            }
1480:
1481:            /**
1482:             * Process a property change event on a Server.
1483:             *
1484:             * @param server The server on which this event occurred
1485:             * @param propertyName The name of the property that changed
1486:             * @param oldValue The previous value (may be <code>null</code>)
1487:             * @param newValue The new value (may be <code>null</code>)
1488:             *
1489:             * @exception Exception if an exception is thrown
1490:             */
1491:            protected void processServerPropertyChange(Server server,
1492:                    String propertyName, Object oldValue, Object newValue)
1493:                    throws Exception {
1494:
1495:                if (log.isTraceEnabled()) {
1496:                    log.trace("propertyChange[server=" + server
1497:                            + ",propertyName=" + propertyName + ",oldValue="
1498:                            + oldValue + ",newValue=" + newValue + "]");
1499:                }
1500:                if ("globalNamingResources".equals(propertyName)) {
1501:                    if (oldValue != null) {
1502:                        destroyMBeans((NamingResources) oldValue);
1503:                    }
1504:                    if (newValue != null) {
1505:                        createMBeans((NamingResources) newValue);
1506:                    }
1507:                } else if ("service".equals(propertyName)) {
1508:                    if (oldValue != null) {
1509:                        destroyMBeans((Service) oldValue);
1510:                    }
1511:                    if (newValue != null) {
1512:                        createMBeans((Service) newValue);
1513:                    }
1514:                }
1515:
1516:            }
1517:
1518:            /**
1519:             * Process a property change event on a Service.
1520:             *
1521:             * @param service The service on which this event occurred
1522:             * @param propertyName The name of the property that changed
1523:             * @param oldValue The previous value (may be <code>null</code>)
1524:             * @param newValue The new value (may be <code>null</code>)
1525:             *
1526:             * @exception Exception if an exception is thrown
1527:             */
1528:            protected void processServicePropertyChange(Service service,
1529:                    String propertyName, Object oldValue, Object newValue)
1530:                    throws Exception {
1531:
1532:                if (log.isTraceEnabled()) {
1533:                    log.trace("propertyChange[service=" + service
1534:                            + ",propertyName=" + propertyName + ",oldValue="
1535:                            + oldValue + ",newValue=" + newValue + "]");
1536:                }
1537:                if ("connector".equals(propertyName)) {
1538:                    if (oldValue != null) {
1539:                        destroyMBeans((Connector) oldValue, service);
1540:                    }
1541:                    if (newValue != null) {
1542:                        createMBeans((Connector) newValue);
1543:                    }
1544:                } else if ("container".equals(propertyName)) {
1545:                    if (oldValue != null) {
1546:                        destroyMBeans((Engine) oldValue);
1547:                    }
1548:                    if (newValue != null) {
1549:                        createMBeans((Engine) newValue);
1550:                    }
1551:                }
1552:
1553:            }
1554:
1555:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.