Source Code Cross Referenced for JMXBeanLoader.java in  » Net » Coadunation_1.0.1 » com » rift » coad » lib » deployment » jmxbean » 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 » Net » Coadunation_1.0.1 » com.rift.coad.lib.deployment.jmxbean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * CoadunationLib: The coaduntion implementation library.
003:         * Copyright (C) 2006  Rift IT Contracting
004:         * 
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
018:         *
019:         * XMLConfigurationException.java
020:         *
021:         * JMXBeanLoader.java
022:         *
023:         * This object is responsible for loading the JMX Bean into memory from the 
024:         * deployment loader passed to it.
025:         */
026:
027:        package com.rift.coad.lib.deployment.jmxbean;
028:
029:        // import 
030:        import javax.management.ObjectName;
031:        import javax.management.MBeanServer;
032:        import java.util.Map;
033:        import java.util.HashMap;
034:        import java.util.Iterator;
035:        import java.util.List;
036:
037:        // logging import
038:        import org.apache.log4j.Logger;
039:
040:        // coad imports
041:        import com.rift.coad.lib.bean.BeanWrapper;
042:        import com.rift.coad.lib.bean.BeanRunnable;
043:        import com.rift.coad.lib.bean.BeanThread;
044:        import com.rift.coad.lib.security.ThreadsPermissionContainer;
045:        import com.rift.coad.lib.deployment.DeploymentLoader;
046:        import com.rift.coad.lib.deployment.JMXBeanInfo;
047:        import com.rift.coad.lib.deployment.DeploymentThreadInfo;
048:        import com.rift.coad.lib.thread.CoadunationThreadGroup;
049:        import com.rift.coad.lib.thread.BasicThread;
050:
051:        /**
052:         * The JMX Bean loader is responsibe for loading the beans contained in a 
053:         * Coadunation jar file.
054:         *
055:         * @author Brett Chaldecott
056:         */
057:        public class JMXBeanLoader extends BasicThread {
058:
059:            // the class log variable
060:            protected Logger log = Logger.getLogger(JMXBeanLoader.class
061:                    .getName());
062:
063:            // The classes memember variables
064:            private MBeanServer beanServer = null;
065:            private DeploymentLoader deploymentLoader = null;
066:            private ThreadsPermissionContainer permissions = null;
067:            private Map beans = null;
068:            private CoadunationThreadGroup threadGroup = null;
069:            private boolean successful = true;
070:            private Exception exception = null;
071:
072:            /** 
073:             * Creates a new instance of JMXBeanLoader loader.
074:             *
075:             * @param beanServer The reference to the bean server.
076:             * @param deploymentLoader The reference to the deployment loader.
077:             * @param permissions The threads permissions container.
078:             * @param threadGroup The reference to the thread group.
079:             * @exception JMXException
080:             * @exception Exception
081:             */
082:            public JMXBeanLoader(MBeanServer beanServer,
083:                    DeploymentLoader deploymentLoader,
084:                    ThreadsPermissionContainer permissions,
085:                    CoadunationThreadGroup threadGroup) throws JMXException,
086:                    Exception {
087:                this .beanServer = beanServer;
088:                this .deploymentLoader = deploymentLoader;
089:                this .permissions = permissions;
090:                this .threadGroup = threadGroup.createThreadGroup();
091:                beans = new HashMap();
092:
093:            }
094:
095:            /**
096:             * The finalize method for the jmx bean loader.
097:             */
098:            protected void finalize() {
099:                stopThreads();
100:            }
101:
102:            /**
103:             * The method that process the request
104:             */
105:            public void process() {
106:                try {
107:                    loadBeans();
108:                    registerBeans();
109:                } catch (Exception ex) {
110:                    log.error("Failed to load the JMX Beans because : "
111:                            + ex.getMessage(), ex);
112:                    successful = false;
113:                    exception = ex;
114:                }
115:            }
116:
117:            /**
118:             * Load the beans into memory.
119:             *
120:             * @exception JMXException
121:             */
122:            private void loadBeans() throws JMXException {
123:                try {
124:                    log.info("Load the JMX Beans for ["
125:                            + deploymentLoader.getFile().getPath() + "]");
126:                    Map beanList = deploymentLoader.getDeploymentInfo()
127:                            .getJmxBeans();
128:                    for (Iterator iter = beanList.keySet().iterator(); iter
129:                            .hasNext();) {
130:                        JMXBeanInfo jmxBeanInfo = (JMXBeanInfo) beanList
131:                                .get(iter.next());
132:                        BeanWrapper beanWrapper = new BeanWrapper(
133:                                deploymentLoader, jmxBeanInfo, permissions);
134:                        beans.put(jmxBeanInfo.getObjectName(), beanWrapper);
135:                        if (beanWrapper.getSubObject() instanceof  BeanRunnable) {
136:                            BeanThread beanThread = new BeanThread(
137:                                    (BeanRunnable) beanWrapper.getSubObject());
138:                            threadGroup.addThread(beanThread, jmxBeanInfo
139:                                    .getUsername());
140:                            beanThread.start();
141:                        }
142:
143:                        // loop through the bean thread information
144:                        List threadList = jmxBeanInfo.getThreadInfoList();
145:                        for (int index = 0; index < threadList.size(); index++) {
146:                            DeploymentThreadInfo threadInfo = (DeploymentThreadInfo) threadList
147:                                    .get(index);
148:                            threadGroup.startThreads(deploymentLoader
149:                                    .getClass(threadInfo.getClassName()),
150:                                    threadInfo.getUsername(), (int) threadInfo
151:                                            .getThreadNumber());
152:                        }
153:                    }
154:                } catch (Exception ex) {
155:                    stopThreads();
156:                    throw new JMXException("Failed to load the beans : "
157:                            + ex.getMessage(), ex);
158:                }
159:            }
160:
161:            /**
162:             * The operator method responsible for registering the beans with the JMX
163:             * bean server.
164:             *
165:             * @exception JMXException
166:             */
167:            private void registerBeans() throws JMXException {
168:                try {
169:                    if (log.isDebugEnabled()) {
170:                        log.debug("Register the Beans for ["
171:                                + deploymentLoader.getFile().getPath() + "]");
172:                    }
173:
174:                    for (Iterator iter = beans.keySet().iterator(); iter
175:                            .hasNext();) {
176:                        String objectName = (String) iter.next();
177:                        log.info("Register the jmx bean [" + objectName + "]");
178:                        BeanWrapper beanWrapper = (BeanWrapper) beans
179:                                .get(objectName);
180:                        beanServer.registerMBean(beanWrapper.getSubObject(),
181:                                new ObjectName(objectName));
182:                    }
183:                } catch (Exception ex) {
184:                    throw new JMXException("Failed to register the beans : "
185:                            + ex.getMessage(), ex);
186:                }
187:            }
188:
189:            /**
190:             * This method is called to un-register beans from the bean server.
191:             */
192:            public void unRegisterBeans() throws JMXException {
193:                try {
194:                    if (log.isDebugEnabled()) {
195:                        log.debug("Un-register the Beans for ["
196:                                + deploymentLoader.getFile().getPath() + "]");
197:                    }
198:
199:                    for (Iterator iter = beans.keySet().iterator(); iter
200:                            .hasNext();) {
201:                        String objectName = (String) iter.next();
202:                        log.info("Un-register the jmx bean [" + objectName
203:                                + "]");
204:                        beanServer.unregisterMBean(new ObjectName(objectName));
205:                    }
206:                } catch (Exception ex) {
207:                    throw new JMXException("Failed to un-register the beans : "
208:                            + ex.getMessage(), ex);
209:                }
210:            }
211:
212:            /**
213:             * This method stops the bean processing
214:             */
215:            public void stopThreads() {
216:                try {
217:                    if (threadGroup.isTerminated() == false) {
218:                        threadGroup.terminate();
219:                    }
220:                } catch (Exception ex) {
221:                    log.error("Failed to unload the beans ["
222:                            + deploymentLoader.getFile().getPath()
223:                            + "] because : " + ex.getMessage(), ex);
224:                }
225:            }
226:
227:            /**
228:             * This method returns the loaded beans.
229:             *
230:             * @return The list of loaded beans.
231:             */
232:            public Map getBeans() {
233:                return beans;
234:            }
235:
236:            /**
237:             * This method returns true if the loading was successfull and false
238:             * otherwise.
239:             */
240:            public boolean wasSucessfull() {
241:                return successful;
242:            }
243:
244:            /**
245:             * The exception that caused the problem
246:             */
247:            public Exception getException() {
248:                return exception;
249:            }
250:
251:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.