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


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 2006 Bull S.A.S.
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 1any 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: ClusterDaemonTools.java 9305 2006-08-02 09:11:31Z pelletib $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.cluster.daemon;
025:
026:        import java.net.URI;
027:        import java.util.Properties;
028:
029:        import org.objectweb.jonas_clusterd.api.ClusterDaemonConfiguration;
030:        import org.objectweb.jonas_clusterd.api.ClusterDaemonConfigurationException;
031:        import org.objectweb.jonas_clusterd.lib.wrapper.ClusterDaemonConfigurationManagerWrapper;
032:
033:        import org.objectweb.carol.rmi.util.PortNumber;
034:        import org.objectweb.carol.util.configuration.CarolDefaultValues;
035:        import org.objectweb.carol.util.configuration.ConfigurationRepository;
036:        import org.objectweb.carol.util.configuration.ProtocolConfiguration;
037:
038:        /**
039:         *  Commons tools
040:         */
041:
042:        public class ClusterDaemonTools {
043:
044:            /**
045:             * Current cluster configuration (loaded)
046:             */
047:            private static ClusterDaemonConfiguration currentConfiguration = null;
048:
049:            /**
050:             *  constructor
051:             */
052:            private ClusterDaemonTools() {
053:
054:            }
055:
056:            /**
057:             * Build the JMX url connection
058:             * @param cdName cluster daemon name
059:             * @return JMX url
060:             * @throws ClusterDaemonException if an error occurs
061:             */
062:            public static String getJmxUrl(String cdName)
063:                    throws ClusterDaemonException {
064:
065:                // Determine protocols used by Carol and their configuration, only the current one is considered
066:                String serviceURL = null;
067:                try {
068:                    ProtocolConfiguration protocolConfiguration = ConfigurationRepository
069:                            .getCurrentConfiguration();
070:                    ConfigurationRepository
071:                            .setCurrentConfiguration(protocolConfiguration);
072:                    String carolProtocol = protocolConfiguration.getName();
073:                    String providerUrl = protocolConfiguration.getProviderURL();
074:                    URI carolURL = new URI(providerUrl);
075:                    String host = carolURL.getHost();
076:                    String port = String.valueOf(carolURL.getPort());
077:                    String scheme = carolURL.getScheme();
078:
079:                    if (scheme.equals("rmi") && carolProtocol.equals("jrmp")) {
080:                        // Treat RMI/JRMP cas
081:                        String myName = "jrmpconnector_" + cdName;
082:                        serviceURL = "service:jmx:rmi://" + host;
083:                        int jrmpExportedPort = 0;
084:                        // Add port number of exported objects if one is set by carol.
085:                        String propertyName = CarolDefaultValues.SERVER_JRMP_PORT;
086:                        Properties p = ConfigurationRepository.getProperties();
087:                        if (p != null) {
088:                            jrmpExportedPort = PortNumber.strToint(p
089:                                    .getProperty(propertyName, "0"),
090:                                    propertyName);
091:                        }
092:                        if (jrmpExportedPort > 0) {
093:                            serviceURL += ":" + jrmpExportedPort;
094:                        }
095:                        serviceURL += "/jndi/rmi://" + host + ":" + port + "/"
096:                                + myName;
097:                    } else if (scheme.equals("rmi")
098:                            && carolProtocol.equals("irmi")) {
099:                        // Treat RMI/IRMI cas
100:                        String myName = "irmiconnector_" + cdName;
101:                        serviceURL = "service:jmx:rmi://" + host;
102:                        int irmiExportedPort = 0;
103:                        // Add port number of exported objects if one is set by carol.
104:                        String propertyName = CarolDefaultValues.SERVER_IRMI_PORT;
105:                        Properties p = ConfigurationRepository.getProperties();
106:                        if (p != null) {
107:                            irmiExportedPort = PortNumber.strToint(p
108:                                    .getProperty(propertyName, "0"),
109:                                    propertyName);
110:                            // Add 1 to this port for IRMI as the JMX object will not
111:                            // use IRMI to bind but JRMP methods.
112:                            irmiExportedPort++;
113:                        }
114:                        if (irmiExportedPort > 1) {
115:                            serviceURL += ":" + irmiExportedPort;
116:                        }
117:                        serviceURL += "/jndi/rmi://" + host + ":" + port + "/"
118:                                + myName;
119:                    } else if (scheme.equals("jrmi")) {
120:                        // Treat JEREMIE case
121:                        String myName = "jeremieconnector_" + cdName;
122:                        serviceURL = "service:jmx:rmi://" + host;
123:                        int jeremieExportedPort = 0;
124:                        // Add port number of exported objects if one is set by carol.
125:                        String propertyName = CarolDefaultValues.SERVER_JEREMIE_PORT;
126:                        Properties p = ConfigurationRepository.getProperties();
127:                        if (p != null) {
128:                            jeremieExportedPort = PortNumber.strToint(p
129:                                    .getProperty(propertyName, "0"),
130:                                    propertyName);
131:                            // Add 1 to this port for jeremie as the JMX object will not
132:                            // use jeremie to bind but JRMP methods.
133:                            jeremieExportedPort++;
134:                        }
135:                        if (jeremieExportedPort > 1024) {
136:                            serviceURL += ":" + jeremieExportedPort;
137:                        }
138:                        serviceURL += "/jndi/jrmi://" + host + ":" + port + "/"
139:                                + myName;
140:
141:                    } else if (scheme.equals("cmi")) {
142:                        // Treat CMI case
143:                        String myName = "cmiconnector_" + cdName;
144:                        serviceURL = "service:jmx:rmi://" + host;
145:
146:                        int jrmpExportedPort = 0;
147:                        // Add port number of exported objects if one is set by carol.
148:                        String propertyName = CarolDefaultValues.SERVER_JRMP_PORT;
149:                        Properties p = ConfigurationRepository.getProperties();
150:                        if (p != null) {
151:                            jrmpExportedPort = PortNumber.strToint(p
152:                                    .getProperty(propertyName, "0"),
153:                                    propertyName);
154:                        }
155:                        if (jrmpExportedPort > 0) {
156:                            serviceURL += ":" + jrmpExportedPort;
157:                        }
158:                        serviceURL += "/jndi/cmi://" + host + ":" + port + "/"
159:                                + myName;
160:
161:                    } else if (scheme.equals("iiop")) {
162:                        // Treat RMI/IIOP case
163:                        String myName = "iiopconnector_" + cdName;
164:
165:                        serviceURL = "service:jmx:iiop://" + host
166:                                + "/jndi/iiop://" + host + ":" + port + "/"
167:                                + myName;
168:                    }
169:                } catch (Exception e) {
170:                    throw new ClusterDaemonException("Cannot get JMX URL", e);
171:                }
172:                return serviceURL;
173:
174:            }
175:
176:            /**
177:             * Build the Object Name
178:             * @return Object name
179:             * @throws ClusterDaemonException if an error occurs
180:             */
181:            public static String getObjectName() throws ClusterDaemonException {
182:
183:                // Determine protocols used by Carol and their configuration, only the current one is considered
184:                String objName = null;
185:                try {
186:                    ProtocolConfiguration protocolConfiguration = ConfigurationRepository
187:                            .getCurrentConfiguration();
188:                    ConfigurationRepository
189:                            .setCurrentConfiguration(protocolConfiguration);
190:                    String carolProtocol = protocolConfiguration.getName();
191:                    String providerUrl = protocolConfiguration.getProviderURL();
192:                    URI carolURL = new URI(providerUrl);
193:                    String scheme = carolURL.getScheme();
194:
195:                    if (scheme.equals("rmi") && carolProtocol.equals("jrmp")) {
196:                        // Treat RMI/JRMP cas
197:                        objName = "connectors:protocol=jrmp, name=cs_connector";
198:                    } else if (scheme.equals("rmi")
199:                            && carolProtocol.equals("irmi")) {
200:                        // Treat RMI/IRMI cas
201:                        objName = "connectors:protocol=irmi, name=cs_connector";
202:                    } else if (scheme.equals("jrmi")) {
203:                        // Treat JEREMIE case
204:                        objName = "connectors:protocol=jrmi, name=cs_connector";
205:                    } else if (scheme.equals("cmi")) {
206:                        // Treat CMI case
207:                        objName = "connectors:protocol=cmi, name=cs_connector";
208:
209:                    } else if (scheme.equals("iiop")) {
210:                        // Treat RMI/IIOP case
211:                        objName = "connectors:protocol=iiop, name=cs_connector";
212:                    }
213:                } catch (Exception e) {
214:                    throw new ClusterDaemonException("Cannot get ObjectName", e);
215:                }
216:                return objName;
217:
218:            }
219:
220:            /**
221:             * Load the cluster daemon configuration (clusterd.xml)
222:             * @param confFileName configuration file to used
223:             * @throws ClusterDaemonException if an error occurs
224:             */
225:            public static void loadClusterDaemonConfiguration(
226:                    String confFileName) throws ClusterDaemonException {
227:                ClassLoader currentLoader = Thread.currentThread()
228:                        .getContextClassLoader();
229:
230:                currentConfiguration = null;
231:                try {
232:                    currentConfiguration = ClusterDaemonConfigurationManagerWrapper
233:                            .getClusterDaemonConfiguration(confFileName,
234:                                    currentLoader);
235:                } catch (ClusterDaemonConfigurationException e) {
236:                    throw new ClusterDaemonException(e);
237:                }
238:
239:            }
240:
241:            /**
242:             * @return current configuration
243:             */
244:            public static ClusterDaemonConfiguration getCurrentConfiguration() {
245:                return currentConfiguration;
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.