Source Code Cross Referenced for ClusterDaemonServlet.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » j2eemanagement » servlets » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.j2eemanagement.servlets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 2006 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id:  $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.j2eemanagement.servlets;
025:
026:        //import java
027:        import java.io.IOException;
028:        import java.io.PrintWriter;
029:
030:        import javax.management.ObjectName;
031:        import javax.management.j2ee.Management;
032:        import javax.servlet.ServletConfig;
033:        import javax.servlet.ServletException;
034:        import javax.servlet.http.HttpServletRequest;
035:        import javax.servlet.http.HttpServletResponse;
036:
037:        /**
038:         * This servlet is an example which shows how to access the MEJB from a servlet.
039:         * @author JOnAS team
040:         * @author Adriana Danes
041:         */
042:        public class ClusterDaemonServlet extends J2eemanagementBaseServlet {
043:
044:            // ---------------------------------------------------------- Constants
045:            /** Parameter */
046:            static final String PARAM_DOMAIN = "domainName";
047:            /** Parameter */
048:            static final String PARAM_DAEMON = "daemonName";
049:            /** Parameter which gives the name of the server to be started by the daemon */
050:            static final String PARAM_SERVER = "serverName";
051:            /** Parameter */
052:            static final String PARAM_VIEW = "view";
053:            /** Parameter */
054:            static final String VIEW_INIT = "init";
055:
056:            // ---------------------------------------------------------- Public methods
057:
058:            /**
059:             * Initialize the servlet.
060:             * @param pConfig See HttpServlet
061:             * @throws ServletException Could not execute request
062:             */
063:            public void init(ServletConfig pConfig) throws ServletException {
064:                super .init(pConfig);
065:            }
066:
067:            // ---------------------------------------------------------- Protected
068:            // methods
069:
070:            /**
071:             * Response to the GET request.
072:             * @param pRequest See HttpServlet
073:             * @param pResponse See HttpServlet
074:             * @throws IOException An input or output error is detected when the servlet handles the request
075:             * @throws ServletException Could not execute request
076:             */
077:            protected void doGet(HttpServletRequest pRequest,
078:                    HttpServletResponse pResponse) throws IOException,
079:                    ServletException {
080:                dispatch(pRequest, pResponse);
081:            }
082:
083:            /**
084:             * Response to the POST request.
085:             * @param pRequest See HttpServlet
086:             * @param pResponse See HttpServlet
087:             * @throws IOException An input or output error is detected when the servlet handles the request
088:             * @throws ServletException Could not execute request
089:             */
090:            protected void doPost(HttpServletRequest pRequest,
091:                    HttpServletResponse pResponse) throws IOException,
092:                    ServletException {
093:                dispatch(pRequest, pResponse);
094:            }
095:
096:            /**
097:             * Dispatch the response.
098:             * @param pRequest Request
099:             * @param pResponse Response
100:             * @throws IOException An input or output error is detected when the servlet handles the request
101:             */
102:            protected void dispatch(HttpServletRequest pRequest,
103:                    HttpServletResponse pResponse) throws IOException {
104:
105:                pResponse.setContentType("text/html");
106:                PrintWriter out = pResponse.getWriter();
107:
108:                // Get parameters
109:                String sParamDomain = pRequest.getParameter(PARAM_DOMAIN);
110:                String sParamDaemon = pRequest.getParameter(PARAM_DAEMON);
111:                String sParamServer = pRequest.getParameter(PARAM_SERVER);
112:                String sParamView = pRequest.getParameter(PARAM_VIEW);
113:
114:                // Dispatching
115:                if ((sParamDomain == null) || (sParamDomain.length() == 0)) {
116:                    doViewError("Parameter <i>Domain name</i> not found",
117:                            pRequest, out);
118:                } else if ((sParamDaemon == null)
119:                        || (sParamDaemon.length() == 0)) {
120:                    doViewError("Parameter <i>Daemon name</i> not found",
121:                            pRequest, out);
122:                } else if ((sParamServer == null)
123:                        || (sParamServer.length() == 0)) {
124:                    doViewError("Parameter <i>Server name</i> not found",
125:                            pRequest, out);
126:                } else if ((sParamView == null) || (sParamView.length() == 0)
127:                        || VIEW_INIT.equals(sParamView)) {
128:                    doViewInit(pRequest, out);
129:                    doViewManagement(sParamDomain, sParamDaemon, sParamServer,
130:                            pRequest, out);
131:                } else {
132:                    doViewError("Unknown View", pRequest, out);
133:                }
134:
135:            }
136:
137:            /**
138:             * Do management opeartions in this view.
139:             * @param pDomainName Name of domain to access
140:             * @param pDaemonName Name of the deamon
141:             * @param pServerName Name of the server to be started by the daemon
142:             * @param pRequest Http request
143:             * @param pOut Printer
144:             */
145:            protected void doViewManagement(String pDomainName,
146:                    String pDaemonName, String pServerName,
147:                    HttpServletRequest pRequest, PrintWriter pOut) {
148:                Management mgmt = getMgmt();
149:
150:                // ------------------------------
151:                // Access to the J2EEDomain MBean
152:                // ------------------------------
153:                ObjectName onDomain = accessJ2EEDomain(pDomainName, mgmt, pOut);
154:                if (onDomain == null) {
155:                    return;
156:                }
157:
158:                startServer(onDomain, pDaemonName, pServerName, mgmt, pOut);
159:                pOut.println("<h2>Application is OK </h2>");
160:
161:                // Footer
162:                printNavigationFooter(pRequest, pOut);
163:            }
164:
165:            /**
166:             * Create J2EEDomain MBean's ObjectName and test if MBean registered
167:             * @param pDomainName the name provided by the user
168:             * @param mgmt MEJB
169:             * @param pOut output stream
170:             * @return true if management operation succeeded
171:             */
172:            private ObjectName accessJ2EEDomain(String pDomainName,
173:                    Management mgmt, PrintWriter pOut) {
174:                ObjectName onDomain = null;
175:                pOut.println("<h2>Access the J2EEDomain MBean</h2>");
176:                pOut.println("<ul>");
177:
178:                // Get the J2EEDomain MBean's ObjectName
179:                try {
180:                    String name = pDomainName + ":j2eeType=J2EEDomain,name="
181:                            + pDomainName;
182:                    onDomain = ObjectName.getInstance(name);
183:                    pOut.println("<li>J2EEDomain object name \""
184:                            + name.toString() + "\" created.</li>");
185:                } catch (Exception e) {
186:                    pOut
187:                            .println("<li>Cannot create object name for J2EEDomain managed object: "
188:                                    + e + "</li>");
189:                    pOut.println("</ul>");
190:                    return null;
191:                }
192:                // Check that the J2EEDomain MBean registered
193:                try {
194:                    boolean exists = mgmt.isRegistered(onDomain);
195:                    if (exists) {
196:                        pOut
197:                                .println("<li>Found this J2EEDomain MBean in the current MBean server</li>");
198:                        pOut.println("</ul><br/>");
199:                    } else {
200:                        pOut
201:                                .println("<li><b>Can't find this J2EEDomain MBean in the current MBean server</b></li>");
202:                        pOut.println("</ul>");
203:                        return null;
204:                    }
205:                } catch (Exception e) {
206:                    pOut.println("<li>Error when using this J2EEDomain MBean: "
207:                            + e + "</li>");
208:                    pOut.println("</ul>");
209:                    return null;
210:                }
211:                return onDomain;
212:            }
213:
214:            /**
215:             * Start a server in domain
216:             * @param pOnDomain J2EEDomain MBean ObjectName
217:             * @param pDaemonName daemon name - currently not used
218:             * @param pServerName server name
219:             * @param mgmt MEJB
220:             * @param pOut output stream
221:             */
222:            private void startServer(ObjectName pOnDomain, String pDaemonName,
223:                    String pServerName, Management mgmt, PrintWriter pOut) {
224:                pOut.println("<h2>Start the server " + pServerName + "</h2>");
225:                pOut.println("<ul>");
226:                try {
227:                    String[] signature = { "java.lang.String" };
228:                    String[] params = { pServerName };
229:                    mgmt.invoke(pOnDomain, "startServer", params, signature);
230:                    pOut
231:                            .println("<li>Server " + pServerName
232:                                    + " started.</li>");
233:                    pOut.println("</ul><br/>");
234:                } catch (Exception e) {
235:                    pOut
236:                            .println("<li>Cannot create cluster start the server</li>");
237:                    pOut.println("</ul>");
238:                }
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.