Source Code Cross Referenced for DefaultHttpAdaptorServiceImpl.java in  » Inversion-of-Control » carbon » org » sape » carbon » services » jmx » server » mx4j » 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 » Inversion of Control » carbon » org.sape.carbon.services.jmx.server.mx4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the Sapient Public License
003:         * Version 1.0 (the "License"); you may not use this file except in compliance
004:         * with the License. You may obtain a copy of the License at
005:         * http://carbon.sf.net/License.html.
006:         *
007:         * Software distributed under the License is distributed on an "AS IS" basis,
008:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009:         * the specific language governing rights and limitations under the License.
010:         *
011:         * The Original Code is The Carbon Component Framework.
012:         *
013:         * The Initial Developer of the Original Code is Sapient Corporation
014:         *
015:         * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
016:         */
017:
018:        package org.sape.carbon.services.jmx.server.mx4j;
019:
020:        import java.io.IOException;
021:        import java.util.Iterator;
022:        import java.util.Set;
023:
024:        import javax.management.Attribute;
025:        import javax.management.MBeanServer;
026:        import javax.management.ObjectInstance;
027:        import javax.management.ObjectName;
028:
029:        import org.sape.carbon.core.component.Component;
030:        import org.sape.carbon.core.component.ComponentConfiguration;
031:        import org.sape.carbon.core.component.lifecycle.Configurable;
032:        import org.sape.carbon.core.component.lifecycle.Destroyable;
033:        import org.sape.carbon.core.component.lifecycle.Initializable;
034:        import org.sape.carbon.core.component.lifecycle.Startable;
035:        import org.sape.carbon.core.config.InvalidConfigurationException;
036:        import org.sape.carbon.services.jmx.server.MBeanServerService;
037:
038:        import mx4j.adaptor.http.HttpAdaptor;
039:        import org.apache.commons.logging.Log;
040:        import org.apache.commons.logging.LogFactory;
041:
042:        /**
043:         * This component implementation configures and sets up the MX4J HTTP adaptor
044:         * to create a web interface to JMX.
045:         *
046:         * Copyright 2002 Sapient
047:         * @since carbon 1.0
048:         * @author Greg Hinkle, June 2002
049:         * @version $Revision: 1.9 $($Author: dvoet $ / $Date: 2003/05/05 21:21:31 $)
050:         */
051:        public class DefaultHttpAdaptorServiceImpl implements  Configurable,
052:                Initializable, Startable, Destroyable, MBeanServerService {
053:
054:            /**
055:             * Provides a handle to Apache-commons logger
056:             */
057:            private Log log = LogFactory.getLog(this .getClass());
058:
059:            /** Holds the MBean Service being exposed. */
060:            private MBeanServer server;
061:
062:            /** Holds the HttpAdapter for the service. */
063:            private HttpAdaptor adaptor;
064:
065:            /** Holds the port of the adapter. */
066:            private int port;
067:
068:            /** holds the hostname for the adapter. */
069:            private String host;
070:
071:            /** Holds the port incrementals. */
072:            private int retries;
073:
074:            /**
075:             * Configure the component. This is preceded and followed by the suspend and
076:             * resume operations if they are available on the component.
077:             *
078:             * @param configuration <code>HttpAdaptorConfiguration</code>
079:             *        for this component
080:             */
081:            public void configure(ComponentConfiguration configuration) {
082:                try {
083:                    HttpAdaptorConfiguration config = (HttpAdaptorConfiguration) configuration;
084:
085:                    this .server = config.getMBeanServerService()
086:                            .getMBeanServer();
087:
088:                    this .port = config.getPort();
089:                    this .host = config.getHostname();
090:                    this .retries = config.getPortIncrementals();
091:
092:                    ObjectName adaptorName = new ObjectName(
093:                            "Server:name=HttpAdaptor");
094:                    this .adaptor = new HttpAdaptor();
095:                    this .adaptor.setPort(config.getPort());
096:                    this .adaptor.setHost(config.getHostname());
097:                    this .server.registerMBean(adaptor, adaptorName);
098:
099:                    ObjectName processorName = new ObjectName(
100:                            "Server:name=XSLTProcessor");
101:
102:                    this .server.createMBean("mx4j.adaptor.http.XSLTProcessor",
103:                            processorName, null);
104:
105:                    this .server.setAttribute(adaptorName, new Attribute(
106:                            "ProcessorName", processorName));
107:
108:                    this .server.invoke(processorName, "addMimeType",
109:                            new Object[] { ".pdf", "application/pdf" },
110:                            new String[] { "java.lang.String",
111:                                    "java.lang.String" });
112:                } catch (Exception e) {
113:                    throw new InvalidConfigurationException(this .getClass(),
114:                            configuration.getConfigurationName(), "",
115:                            "Couldn't configure MBeanServer.", e);
116:                }
117:            }
118:
119:            /**
120:             * Initialize the component. Called immediately after the Component's
121:             * constructor. On return, the container may start the component.
122:             *
123:             * @param thisComponent reference to the component
124:             */
125:            public void initialize(Component this Component) {
126:
127:                //this.server = MBeanServerFactory.createMBeanServer();
128:                //new MBeanServerImpl("HttpAdaptor");
129:
130:            }
131:
132:            /**
133:             * Start the component. On return, the container will begin fowarding
134:             * requests to the component. This may be an opportunity to dispatch
135:             * worker threads.
136:             *
137:             * @throws LifecycleException
138:             */
139:            public void start() {
140:
141:                //adaptor.start();
142:
143:                int retriesLeft = this .retries;
144:                int currentPort = this .port;
145:                boolean success = false;
146:                while ((retriesLeft > 0) && (success == false)) {
147:                    try {
148:                        this .adaptor.setPort(currentPort);
149:                        this .adaptor.start();
150:                        success = true;
151:                    } catch (IOException ioe) {
152:                        retriesLeft--;
153:                        currentPort++;
154:                    }
155:                }
156:                if (success) {
157:                    this .port = currentPort;
158:                    if (log.isDebugEnabled()) {
159:                        log
160:                                .debug("Able to start JMX Web Console listener on port ["
161:                                        + this .port + "]");
162:                    }
163:                } else {
164:                    if (log.isDebugEnabled()) {
165:                        log
166:                                .debug("Unable to start JMX Web Console listener on port ["
167:                                        + this .port
168:                                        + "] through ["
169:                                        + (this .port + this .retries) + "]");
170:                    }
171:                }
172:            }
173:
174:            /**
175:             * Stop the component. Prior to entry, the container will cease forwarding
176:             * requests for service to the component. This is an opportunity to cleanly
177:             * complete or abort any outstanding work. For example, a set of worker
178:             * threads could be killed off, or a queue set to drain.
179:             *
180:             * @throws LifecycleException
181:             */
182:            public void stop() {
183:                adaptor.stop();
184:            }
185:
186:            /**
187:             * Retreives the MBean Server.
188:             *
189:             * @return the MBean Server
190:             */
191:            public MBeanServer getMBeanServer() {
192:                return this .server;
193:            }
194:
195:            /**
196:             * Destroy the component. Called when the Component is already Stopped.
197:             *
198:             * @throws LifecycleException
199:             */
200:            public void destroy() {
201:                this .adaptor.stop();
202:                Set mbeanSet = this .server.queryMBeans(null, null);
203:                Iterator mbeanIterator = mbeanSet.iterator();
204:                while (mbeanIterator.hasNext()) {
205:                    ObjectInstance inst = (ObjectInstance) mbeanIterator.next();
206:                    try {
207:                        ObjectName objName = inst.getObjectName();
208:                        this .server.unregisterMBean(objName);
209:                        if (log.isTraceEnabled()) {
210:                            log.trace("Successfully deregistered object ["
211:                                    + inst.getObjectName() + "]");
212:                        }
213:                    } catch (Exception e) {
214:                        if (log.isTraceEnabled()) {
215:                            log.trace("Could not deregistered object ["
216:                                    + inst.getObjectName() + "]");
217:                        }
218:                    }
219:                }
220:
221:            }
222:
223:        }
ww__w._j__a__v__a2___s___._c___o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.