Source Code Cross Referenced for StopServer.java in  » EJB-Server-geronimo » deploy-tool » org » apache » geronimo » deployment » cli » 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 » EJB Server geronimo » deploy tool » org.apache.geronimo.deployment.cli 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.deployment.cli;
017:
018:        import java.io.IOException;
019:        import java.net.MalformedURLException;
020:        import java.util.HashMap;
021:        import java.util.Map;
022:
023:        import javax.management.MBeanServerConnection;
024:        import javax.management.remote.JMXConnector;
025:        import javax.management.remote.JMXConnectorFactory;
026:        import javax.management.remote.JMXServiceURL;
027:
028:        import org.apache.geronimo.gbean.GBeanInfo;
029:        import org.apache.geronimo.gbean.GBeanInfoBuilder;
030:        import org.apache.geronimo.kernel.Kernel;
031:        import org.apache.geronimo.kernel.util.Main;
032:        import org.apache.geronimo.system.jmx.KernelDelegate;
033:
034:        /**
035:         * @version $Rev: 535507 $ $Date: 2007-05-05 04:22:39 -0700 (Sat, 05 May 2007) $
036:         */
037:        public class StopServer implements  Main {
038:
039:            public static final String RMI_NAMING_CONFG_ID = "org/apache/geronimo/RMINaming";
040:
041:            public static final String DEFAULT_PORT = "1099"; // 1099 is used by java.rmi.registry.Registry
042:
043:            String port;
044:
045:            String user;
046:
047:            String password;
048:
049:            private String[] args;
050:
051:            public static void main(String[] args) throws Exception {
052:                StopServer cmd = new StopServer();
053:                cmd.execute(args);
054:            }
055:
056:            public int execute(Object opaque) {
057:                if (!(opaque instanceof  String[])) {
058:                    throw new IllegalArgumentException("Argument type is ["
059:                            + opaque.getClass() + "]; expected ["
060:                            + String[].class + "]");
061:                }
062:                this .args = (String[]) opaque;
063:
064:                int i = 0;
065:                while (i < args.length && args[i].startsWith("--")) {
066:                    if (setParam(i++)) {
067:                        i++;
068:                    }
069:                }
070:
071:                if (i < args.length) {
072:                    // There was an argument error somewhere.
073:                    printUsage();
074:                }
075:
076:                try {
077:                    if (port != null) {
078:                        Integer.parseInt(port);
079:                    }
080:                } catch (NumberFormatException e) {
081:                    System.out.println("Invalid port number specified.");
082:                    return 1;
083:                }
084:
085:                try {
086:                    InputPrompt prompt = new InputPrompt(System.in, System.out);
087:                    if (user == null) {
088:                        user = prompt.getInput("Username: ");
089:                    }
090:                    if (password == null) {
091:                        password = prompt.getPassword("Password: ");
092:                    }
093:                } catch (IOException e) {
094:                    System.out.println("Unable to prompt for login.");
095:                    return 1;
096:                }
097:
098:                try {
099:                    if (port == null) {
100:                        port = DEFAULT_PORT;
101:                    }
102:                    System.out
103:                            .print("Locating server on port " + port + "... ");
104:                    Kernel kernel = null;
105:                    try {
106:                        kernel = getRunningKernel();
107:                    } catch (IOException e) {
108:                        System.out
109:                                .println("\nCould not communicate with the server.  The server may not be running or the port number may be incorrect.");
110:                    }
111:                    if (kernel != null) {
112:                        System.out.println("Server found.");
113:                        System.out.println("Server shutdown started");
114:                        kernel.shutdown();
115:                        System.out.println("Server shutdown completed");
116:                    }
117:                } catch (Exception e) {
118:                    e.printStackTrace();
119:                    return 1;
120:                }
121:                return 0;
122:            }
123:
124:            private boolean argumentHasValue(int i) {
125:                return i + 1 < args.length && !args[i + 1].startsWith("--");
126:            }
127:
128:            private boolean setParam(int i) {
129:                if (argumentHasValue(i)) {
130:                    if (args[i].equals("--user")) {
131:                        user = args[++i];
132:                    } else if (args[i].equals("--password")) {
133:                        password = args[++i];
134:                    } else if (args[i].equals("--port")) {
135:                        port = args[++i];
136:                    } else {
137:                        printUsage();
138:                    }
139:                    return true;
140:                } else {
141:                    printUsage();
142:                }
143:                return false;
144:            }
145:
146:            public Kernel getRunningKernel() throws IOException {
147:                Map map = new HashMap();
148:                map.put("jmx.remote.credentials",
149:                        new String[] { user, password });
150:                Kernel kernel = null;
151:                try {
152:                    JMXServiceURL address = new JMXServiceURL(
153:                            "service:jmx:rmi:///jndi/rmi://localhost" + ":"
154:                                    + port + "/JMXConnector");
155:                    JMXConnector jmxConnector = JMXConnectorFactory.connect(
156:                            address, map);
157:                    MBeanServerConnection mbServerConnection = jmxConnector
158:                            .getMBeanServerConnection();
159:                    kernel = new KernelDelegate(mbServerConnection);
160:                } catch (MalformedURLException e) {
161:                    e.printStackTrace();
162:                }
163:                return kernel;
164:            }
165:
166:            public void printUsage() {
167:                System.out.println();
168:                System.out.println("Command-line shutdown syntax:");
169:                System.out.println("    shutdown [options]");
170:                System.out.println();
171:                System.out.println("The available options are:");
172:                System.out.println("    --user");
173:                System.out.println("    --password");
174:                System.out.println("    --port");
175:                System.exit(1);
176:            }
177:
178:            public static final GBeanInfo GBEAN_INFO;
179:
180:            static {
181:                GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
182:                        StopServer.class, "StopServer");
183:
184:                infoBuilder.addInterface(Main.class);
185:
186:                infoBuilder.setConstructor(new String[0]);
187:
188:                GBEAN_INFO = infoBuilder.getBeanInfo();
189:            }
190:
191:            public static GBeanInfo getGBeanInfo() {
192:                return GBEAN_INFO;
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.