Source Code Cross Referenced for JBossTestClusteredServices.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » 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 JBoss 4.2.1 » testsuite » org.jboss.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test;
023:
024:        import java.net.URL;
025:        import java.util.ArrayList;
026:        import java.util.Hashtable;
027:
028:        import javax.management.ObjectName;
029:        import javax.naming.InitialContext;
030:
031:        import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
032:
033:        /**
034:         * Derived implementation of JBossTestServices for cluster testing.
035:         *
036:         * @author <a href="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
037:         * @author Scott.Stark@jboss.org
038:         * @version $Revision: 57211 $
039:         * @see org.jboss.test.JBossTestServices
040:         */
041:        public class JBossTestClusteredServices extends JBossTestServices {
042:            protected ArrayList adaptors = null;
043:            protected ArrayList servers = null;
044:            protected ArrayList namingURLs = null;
045:            protected ArrayList namingURLsHA = null;
046:            protected ArrayList httpURLs = null;
047:
048:            // Constructors --------------------------------------------------
049:
050:            public JBossTestClusteredServices(String className) {
051:                super (className);
052:            }
053:
054:            int getServerCount() {
055:                return servers.size();
056:            }
057:
058:            RMIAdaptor[] getAdaptors() throws Exception {
059:                init();
060:                RMIAdaptor[] tmp = new RMIAdaptor[adaptors.size()];
061:                adaptors.toArray(tmp);
062:                return tmp;
063:            }
064:
065:            RMIAdaptor getAdaptor(int index) throws Exception {
066:                init();
067:                RMIAdaptor adaptor = (RMIAdaptor) adaptors.get(index);
068:                return adaptor;
069:            }
070:
071:            String[] getServers() throws Exception {
072:                init();
073:                String[] tmp = new String[servers.size()];
074:                servers.toArray(tmp);
075:                return tmp;
076:            }
077:
078:            String getServer(int index) throws Exception {
079:                init();
080:                String server = (String) servers.get(index);
081:                return server;
082:            }
083:
084:            /** Get the JNDI provider urls for the cluster nodes
085:             * @return
086:             * @throws Exception
087:             */
088:            String[] getNamingURLs() throws Exception {
089:                init();
090:                String[] tmp = new String[namingURLs.size()];
091:                namingURLs.toArray(tmp);
092:                return tmp;
093:            }
094:
095:            String getNamingURL(int index) throws Exception {
096:                init();
097:                String server = (String) namingURLs.get(index);
098:                return server;
099:            }
100:
101:            /** Get the JNDI provider urls for the cluster nodes
102:             * @return
103:             * @throws Exception
104:             */
105:            String[] getHANamingURLs() throws Exception {
106:                init();
107:                String[] tmp = new String[namingURLsHA.size()];
108:                namingURLsHA.toArray(tmp);
109:                return tmp;
110:            }
111:
112:            String getHANamingURL(int index) throws Exception {
113:                init();
114:                String server = (String) namingURLsHA.get(index);
115:                return server;
116:            }
117:
118:            /** Get the default web container urls for the cluster nodes
119:             * @return
120:             * @throws Exception
121:             */
122:            String[] getHttpURLs() throws Exception {
123:                init();
124:                String[] tmp = new String[httpURLs.size()];
125:                httpURLs.toArray(tmp);
126:                return tmp;
127:            }
128:
129:            String getHttpURL(int index) throws Exception {
130:                init();
131:                String server = (String) httpURLs.get(index);
132:                return server;
133:            }
134:
135:            /**
136:             * Deploy a package on the given server with the main deployer. The supplied 
137:             * name is interpreted as a url, or as a filename in jbosstest.deploy.lib or 
138:             * ../lib.
139:             *
140:             * @param server         server on which the package should be deployed
141:             * @param name           filename/url of package to deploy.
142:             * @exception Exception  Description of Exception
143:             */
144:            public void deploy(RMIAdaptor server, String name) throws Exception {
145:                if (Boolean.getBoolean("jbosstest.nodeploy") == true) {
146:                    log.debug("Skipping deployment of: " + name);
147:                    return;
148:                }
149:
150:                URL deployURL = getDeployURL(name);
151:                log.debug("Deploying " + name + ", url=" + deployURL + " to "
152:                        + server);
153:                invoke(server, getDeployerName(), "deploy",
154:                        new Object[] { deployURL },
155:                        new String[] { "java.net.URL" });
156:            }
157:
158:            public void redeploy(RMIAdaptor server, String name)
159:                    throws Exception {
160:                if (Boolean.getBoolean("jbosstest.nodeploy") == true) {
161:                    log.debug("Skipping redeployment of: " + name);
162:                    return;
163:                }
164:
165:                URL deployURL = getDeployURL(name);
166:                log.debug("Deploying " + name + ", url=" + deployURL);
167:                invoke(server, getDeployerName(), "redeploy",
168:                        new Object[] { deployURL },
169:                        new String[] { "java.net.URL" });
170:            }
171:
172:            /**
173:             * Undeploy a package from the given server with the main deployer. 
174:             * The supplied name is interpreted as a url, or as a filename in 
175:             * jbosstest.deploy.lib or ../lib.
176:             *
177:             * @param server         server on which the package should be deployed
178:             * @param name           filename/url of package to undeploy.
179:             * @exception Exception  Description of Exception
180:             */
181:            public void undeploy(RMIAdaptor server, String name)
182:                    throws Exception {
183:                if (Boolean.getBoolean("jbosstest.nodeploy") == true)
184:                    return;
185:                URL deployURL = getDeployURL(name);
186:                log.debug("Undeploying " + name + ", url=" + deployURL);
187:                Object[] args = { deployURL };
188:                String[] sig = { "java.net.URL" };
189:                invoke(server, getDeployerName(), "undeploy", args, sig);
190:            }
191:
192:            /**
193:             * Override to invoke the operation on all servers
194:             *
195:             * @param name
196:             * @param method
197:             * @param args
198:             * @param sig
199:             * @return
200:             * @throws Exception
201:             */
202:            protected Object invoke(ObjectName name, String method,
203:                    Object[] args, String[] sig) throws Exception {
204:                RMIAdaptor[] adaptors = getAdaptors();
205:
206:                Object result = null;
207:                for (int i = 0; i < adaptors.length; i++) {
208:                    RMIAdaptor adaptor = adaptors[i];
209:                    log.debug("Using RMIAdaptor: " + adaptor);
210:                    result = invoke(adaptor, name, method, args, sig);
211:                }
212:
213:                return result;
214:
215:            }
216:
217:            public void init() throws Exception {
218:                if (initialContext == null) {
219:                    initialContext = new InitialContext();
220:                }
221:                if (adaptors == null) {
222:                    adaptors = new ArrayList();
223:                    servers = new ArrayList();
224:                    namingURLs = new ArrayList();
225:                    namingURLsHA = new ArrayList();
226:                    httpURLs = new ArrayList();
227:                    String adaptorName = System
228:                            .getProperty("jbosstest.server.name");
229:                    if (adaptorName == null)
230:                        adaptorName = "jmx/invoker/RMIAdaptor";
231:
232:                    Hashtable env = new Hashtable();
233:                    env.put("java.naming.factory.initial",
234:                            "org.jnp.interfaces.NamingContextFactory");
235:                    env.put("java.naming.factory.url.pkgs",
236:                            "org.jnp.interfaces");
237:
238:                    // Look for jbosstest.cluster.nodeN properties for the server names
239:                    String node = "jbosstest.cluster.node";
240:                    int count = 0;
241:                    while (count < 10) {
242:                        String prop = node + count;
243:                        String host = System.getProperty(prop);
244:                        count++;
245:                        if (host == null)
246:                            break;
247:                        log.info(prop + " = " + host);
248:                        servers.add(host);
249:                        // See if there is a jbosstest.cluster.nodeN.jndi.url
250:                        String urlProp = prop + ".jndi.url";
251:                        String urlDefault = "jnp://" + host + ":1099";
252:                        String urlValue = System.getProperty(urlProp,
253:                                urlDefault);
254:                        log.debug("JNDI Url for node=" + count + " is:"
255:                                + urlValue);
256:                        namingURLs.add(urlValue);
257:                        env.put("java.naming.provider.url", urlValue);
258:                        // Lookup the adaptor
259:                        InitialContext tmpCtx = new InitialContext(env);
260:                        RMIAdaptor adaptor = (RMIAdaptor) tmpCtx
261:                                .lookup(adaptorName);
262:                        adaptors.add(adaptor);
263:
264:                        // See if there is a jbosstest.cluster.nodeN.hajndi.url
265:                        urlProp = prop + ".hajndi.url";
266:                        urlDefault = "jnp://" + host + ":1100";
267:                        urlValue = System.getProperty(urlProp, urlDefault);
268:                        log.debug("HA-JNDI Url for node=" + count + " is:"
269:                                + urlValue);
270:                        namingURLsHA.add(urlValue);
271:
272:                        // See if there is a jbosstest.cluster.nodeN.http.url
273:                        urlProp = prop + ".http.url";
274:                        urlDefault = "http://" + host + ":8080";
275:                        urlValue = System.getProperty(urlProp, urlDefault);
276:                        log.debug("Http Url for node=" + count + " is:"
277:                                + urlValue);
278:                        httpURLs.add(urlValue);
279:                    }
280:
281:                    if (adaptors.size() == 0)
282:                        throw new IllegalStateException(
283:                                "No jbosstest.cluster.node values found");
284:                }
285:            }
286:
287:            /**
288:             * This method gives overriding testcases to set the cluster servernames
289:             */
290:            public void setServerNames(String[] snames) {
291:                if (snames == null)
292:                    return;
293:                for (int i = 0; i < snames.length; i++) {
294:                    servers.add(snames[i]);
295:                }
296:            }
297:
298:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.