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


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999-2004 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: J2EEDomain.java 9884 2006-12-04 09:54:38Z danesa $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.management.j2eemanagement;
025:
026:        import java.util.ArrayList;
027:        import java.util.Collection;
028:        import java.util.Iterator;
029:
030:        import javax.management.JMException;
031:        import javax.management.MBeanRegistration;
032:        import javax.management.MBeanServer;
033:        import javax.management.MBeanServerConnection;
034:        import javax.management.MalformedObjectNameException;
035:        import javax.management.ObjectName;
036:
037:        import org.objectweb.jonas.common.Log;
038:        import org.objectweb.jonas.jmx.J2eeObjectName;
039:        import org.objectweb.jonas.jmx.JonasObjectName;
040:        import org.objectweb.jonas.management.cluster.BaseCluster;
041:        import org.objectweb.jonas.management.monitoring.ClusterDaemonProxy;
042:        import org.objectweb.jonas.management.monitoring.DomainMonitor;
043:        import org.objectweb.jonas.management.monitoring.ServerProxy;
044:        import org.objectweb.jonas.server.J2EEServer;
045:
046:        import org.objectweb.util.monolog.api.BasicLevel;
047:        import org.objectweb.util.monolog.api.Logger;
048:
049:        /**
050:         * Implements a managed object which represents either a management domain or a cluster.
051:         * This J2EEManagedObject is accessed mainly by jonasAdmin.
052:         * The complete interface is described in the following xml file :
053:         * @See src/org/objectweb/jonas/server/mbeans-descriptors.xml
054:         * @author Adriana Danes
055:         * @author Vivek Lakshmanan
056:         */
057:        public class J2EEDomain extends J2EEManagedObject implements 
058:                MBeanRegistration {
059:
060:            /**
061:             * Management domain name
062:             */
063:            private String domainName = null;
064:
065:            /**
066:             * J2EE Management logger
067:             */
068:            private static Logger logger = Log
069:                    .getLogger("org.objectweb.jonas.management.j2eemanagement");
070:
071:            /**
072:             * Ref to the J2EEServer of this server
073:             */
074:            private J2EEServer myJ2eeServer;
075:
076:            /**
077:             * Ref to the local MBean server. Got it as a preRegister argument.
078:             */
079:            private MBeanServer mbeanServer;
080:
081:            /**
082:             * For slave servers, must keep here the connection
083:             * because there is no DomainMonitor.
084:             */
085:            private ServerProxy localServerProxy;
086:
087:            /**
088:             * The associated DomainMonitor, in case this is the master node.
089:             */
090:            private DomainMonitor domainMonitor = null;
091:
092:            private static J2EEDomain unique;
093:
094:            /**
095:             * MBean constructor
096:             * @param objectName object name of the managed object
097:             * @throws JMException ..
098:             */
099:            public J2EEDomain(String objectName) throws JMException {
100:                super (objectName, false, false, false);
101:                ObjectName myObjectName = ObjectName.getInstance(objectName);
102:                domainName = myObjectName.getKeyProperty("name");
103:                unique = this ;
104:            }
105:
106:            /**
107:             * Set this server as the master
108:             */
109:            public void setMaster() {
110:                try {
111:                    ObjectName dmOn = JonasObjectName.domainMonitor();
112:                    domainMonitor = new DomainMonitor(domainName);
113:                    if (mbeanServer != null) {
114:                        mbeanServer.registerMBean(domainMonitor, dmOn);
115:                    }
116:                } catch (Exception e) {
117:                    logger.log(BasicLevel.ERROR, "Cannot create DomainMonitor",
118:                            e);
119:                }
120:            }
121:
122:            /**
123:             * Singleton: Each server (master or slave) must have 1 unique J2EEDomain object.
124:             * @return the unique instance of the J2EEDomain
125:             */
126:            public static J2EEDomain getInstance() {
127:                return unique;
128:            }
129:
130:            /**
131:             * @param serverName Name of the server
132:             * @return the connection to the MBeanServer of this server
133:             */
134:            public MBeanServerConnection getConnection(String serverName) {
135:                ServerProxy sp = getServerProxy(serverName);
136:                if (sp != null) {
137:                    return sp.getConnection();
138:                } else {
139:                    logger.log(BasicLevel.ERROR, "Unknown server: "
140:                            + serverName);
141:                    return null;
142:                }
143:            }
144:
145:            /**
146:             * Return the MBeans OBJECT_NAMEs of the servers belonging to this domain
147:             * @return The list of object names corresponding to the servers associated with this domain
148:             */
149:            public String[] getServers() {
150:                logger.log(BasicLevel.DEBUG, "");
151:                String[] sb = null;
152:                if (domainMonitor != null) {
153:                    Collection col = domainMonitor.getServerList();
154:                    sb = new String[col.size()];
155:                    int i = 0;
156:                    for (Iterator it = col.iterator(); it.hasNext();) {
157:                        ServerProxy proxy = (ServerProxy) it.next();
158:                        sb[i++] = proxy.getJ2eeObjectName();
159:                    }
160:                } else {
161:                    // Slave: Only itself
162:                    sb = new String[1];
163:                    sb[0] = myJ2eeServer.getObjectName();
164:                }
165:                return sb;
166:            }
167:
168:            /**
169:             * Return the servers' name belonging domain
170:             * @return The list of names corresponding to the servers within this domain
171:             */
172:            public String[] getServerNames() {
173:                logger.log(BasicLevel.DEBUG, "");
174:                String[] names = null;
175:                if (domainMonitor != null) {
176:                    Collection col = domainMonitor.getServerList();
177:                    names = new String[col.size()];
178:                    int i = 0;
179:                    for (Iterator it = col.iterator(); it.hasNext();) {
180:                        ServerProxy proxy = (ServerProxy) it.next();
181:                        names[i++] = proxy.getName();
182:                    }
183:                } else {
184:                    // Slave: Only itself
185:                    names = new String[1];
186:                    names[0] = localServerProxy.getName();
187:                }
188:                return names;
189:            }
190:
191:            /**
192:             * @param clusterName name of a cluster in the domain
193:             * @return the list of server names corresponding to the servers within a cluster
194:             */
195:            public String[] getServerNames(String clusterName) {
196:                logger.log(BasicLevel.DEBUG, "");
197:                String[] names = null;
198:                BaseCluster cl = findCluster(clusterName);
199:                if (cl != null) {
200:                    int nbServers = cl.getNbMembers();
201:                    names = new String[nbServers];
202:                    if (nbServers == 0) {
203:                        return names;
204:                    }
205:                    Iterator sps = cl.getServerProxyList().iterator();
206:                    int i = 0;
207:                    while (sps.hasNext()) {
208:                        ServerProxy sp = (ServerProxy) sps.next();
209:                        names[i++] = sp.getServerName();
210:                    }
211:                }
212:                return names;
213:            }
214:
215:            /**
216:             * Return the MBeans OBJECT_NAMEs of the servers belonging to this domain
217:             * but only if they are running.
218:             * @return The list of object names corresponding to the servers associated with this domain
219:             */
220:            public String[] getStartedServers() {
221:                logger.log(BasicLevel.DEBUG, "");
222:                ArrayList sb = new ArrayList();
223:                if (domainMonitor != null) {
224:                    Collection col = domainMonitor.getServerList();
225:                    for (Iterator it = col.iterator(); it.hasNext();) {
226:                        ServerProxy proxy = (ServerProxy) it.next();
227:                        if (proxy.getServerState() == ServerProxy.RUNNING) {
228:                            sb.add(proxy.getJ2eeObjectName());
229:                        }
230:                    }
231:                } else {
232:                    // Slave: Only itself
233:                    sb.add(myJ2eeServer.getObjectName());
234:                }
235:                return (String[]) sb.toArray(new String[0]);
236:            }
237:
238:            public String[] getClusterDaemons() {
239:                logger.log(BasicLevel.DEBUG, "");
240:                String[] sb = null;
241:                if (domainMonitor != null) {
242:                    Collection col = domainMonitor.getClusterDaemonList();
243:                    sb = new String[col.size()];
244:                    int i = 0;
245:                    for (Iterator it = col.iterator(); it.hasNext();) {
246:                        ClusterDaemonProxy cdp = (ClusterDaemonProxy) it.next();
247:                        sb[i++] = cdp.getObjectName();
248:                    }
249:                } else {
250:                    logger.log(BasicLevel.ERROR,
251:                            "Operation allowed on master only");
252:                }
253:                return sb;
254:            }
255:
256:            /**
257:             * Return the MBeans OBJECT_NAMEs of the clusters in this domain
258:             * @return The list of object names corresponding to the clusters in this domain
259:             */
260:            public String[] getClusters() {
261:                logger.log(BasicLevel.DEBUG, "");
262:                String[] sb = null;
263:                if (domainMonitor != null) {
264:                    Collection col = domainMonitor.getTotalClusterList();
265:                    sb = new String[col.size()];
266:                    int i = 0;
267:                    for (Iterator it = col.iterator(); it.hasNext();) {
268:                        BaseCluster cl = (BaseCluster) it.next();
269:                        if (cl == null) {
270:                            logger.log(BasicLevel.ERROR, "null cl elt");
271:                        } else {
272:                            sb[i++] = cl.getObjectName();
273:                        }
274:                    }
275:                } else {
276:                    logger.log(BasicLevel.ERROR,
277:                            "Operation allowed on master only");
278:                }
279:                return sb;
280:            }
281:
282:            /**
283:             * Get the domainMonitor, or null if slave server.
284:             * @return the domainMonitor, for the master server.
285:             */
286:            public DomainMonitor getDomainMonitor() {
287:                return domainMonitor;
288:            }
289:
290:            /**
291:             * Create a logical cluster (by jonasAdmin)
292:             * @param name the cluster's name
293:             * @return the OBJECT_NAME corresponding to the created MBean
294:             */
295:            public String createCluster(String name) {
296:                logger.log(BasicLevel.DEBUG, "");
297:                if (domainMonitor != null) {
298:                    BaseCluster cl = domainMonitor.createLogicalCluster(name);
299:                    return cl.getObjectName();
300:                } else {
301:                    logger.log(BasicLevel.ERROR,
302:                            "Operation allowed on master only");
303:                    return null;
304:                }
305:            }
306:
307:            /**
308:             * Add the local J2EEServer to the 'servers' list.
309:             * This method is called by the Server.start() method execution.
310:             * @param j2eeserver J2EEServer object corresponding to the currently managed
311:             * server (the local server which can be a master or a slave)
312:             * @param urls Collection of JMX remote connector urls for this server
313:             */
314:            public void addLocalServer(J2EEServer j2eeserver, Collection urls) {
315:                logger.log(BasicLevel.DEBUG, "");
316:                myJ2eeServer = j2eeserver;
317:                String svname = j2eeserver.getServerName();
318:                if (domainMonitor != null) {
319:                    // Master case: must check if not already created.
320:                    localServerProxy = domainMonitor.addLocalServer(svname,
321:                            urls);
322:                    // Read domain.xml after having added the local server
323:                    domainMonitor.readDomainConfig();
324:                } else {
325:                    // Slave case: create it in any case.
326:                    // no cluster daemon (4th param)
327:                    localServerProxy = new ServerProxy(domainMonitor, svname,
328:                            urls, null);
329:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
330:                        logger.log(BasicLevel.DEBUG, "Adding server : "
331:                                + svname);
332:                    }
333:                    // give a name and register mbean
334:                    ObjectName on;
335:                    try {
336:                        on = JonasObjectName.serverProxy(svname);
337:                        localServerProxy.setObjectName(on.toString());
338:                    } catch (MalformedObjectNameException e) {
339:                        logger.log(BasicLevel.ERROR, "MalformedObjectName: "
340:                                + svname);
341:                    }
342:                }
343:            }
344:
345:            /**
346:             * Set the local server running and get its info
347:             * Cannot be done before because some MBeans must exist first.
348:             */
349:            public void setLocalServerRunning() {
350:                localServerProxy.getMonitoringInfo();
351:            }
352:
353:            /**
354:             * Get a Cluster by its name
355:             * @param name The name of the cluster
356:             * @return the Cluster or null if unknown by the domain.
357:             */
358:            public BaseCluster findCluster(String name) {
359:                logger.log(BasicLevel.DEBUG, "");
360:                if (domainMonitor == null) {
361:                    logger
362:                            .log(BasicLevel.WARN,
363:                                    "discovery service not started");
364:                    return null;
365:                }
366:                return domainMonitor.findCluster(name);
367:            }
368:
369:            /**
370:             * Get a Server by its name
371:             * @param name The name of the server
372:             * @return the Server or null if unknown by the domain.
373:             */
374:            public J2EEServer findServer(String name) {
375:                logger.log(BasicLevel.DEBUG, "");
376:                if (domainMonitor == null) {
377:                    logger
378:                            .log(BasicLevel.WARN,
379:                                    "discovery service not started");
380:                    return null;
381:                }
382:                return domainMonitor.findServer(name);
383:            }
384:
385:            /**
386:             * Get a Server by its name
387:             * @param name The name of the server
388:             * @return the ServerProxy or null if unknown by the domain.
389:             */
390:            public ServerProxy findServerProxy(String name) {
391:                logger.log(BasicLevel.DEBUG, "");
392:                if (domainMonitor == null) {
393:                    logger
394:                            .log(BasicLevel.WARN,
395:                                    "discovery service not started");
396:                    return null;
397:                }
398:                return domainMonitor.findServerProxy(name);
399:            }
400:
401:            /**
402:             * @param mbeanServer The MBean server in which the MBean will be registered.
403:             * @param name The object name of the MBean
404:             * @return The object name of the MBean
405:             */
406:            public ObjectName preRegister(MBeanServer mbeanServer,
407:                    ObjectName name) throws Exception {
408:                logger.log(BasicLevel.DEBUG, "");
409:                if (name == null) {
410:                    return J2eeObjectName.J2EEDomain(domainName);
411:                }
412:                this .mbeanServer = mbeanServer;
413:                String myName = getObjectName().toString();
414:                String argName = name.toString();
415:                if (myName.equals(argName)) {
416:                    return name;
417:                } else {
418:                    if (logger.isLoggable(BasicLevel.WARN)) {
419:                        logger.log(BasicLevel.WARN,
420:                                "Trying to register J2EEDomain MBean with the following name: "
421:                                        + argName
422:                                        + " when the expected name is: "
423:                                        + myName);
424:                    }
425:                    return ObjectName.getInstance(domainName);
426:                }
427:            }
428:
429:            /**
430:             * Add J2EEDomain MBean (myself) as listener to registration/unregistration notifications of
431:             * JOnAS management MBeans.
432:             * @param registrationDone Indicates whether or not the MBean has been successfully registered
433:             */
434:            public void postRegister(Boolean registrationDone) {
435:                logger.log(BasicLevel.DEBUG, "");
436:            }
437:
438:            /**
439:             * @see javax.management.MBeanRegistration#preDeregister()
440:             */
441:            public void preDeregister() throws Exception {
442:                logger.log(BasicLevel.DEBUG, "");
443:            }
444:
445:            /**
446:             * @see javax.management.MBeanRegistration#postDeregister()
447:             */
448:            public void postDeregister() {
449:                logger.log(BasicLevel.DEBUG, "");
450:            }
451:
452:            /**
453:             * Start a Remote JOnAS Server
454:             * MBean implementation for jonasAdmin
455:             * @param serverName Name of the jonas server
456:             */
457:            public void startServer(String serverName) {
458:                if (domainMonitor == null) {
459:                    logger.log(BasicLevel.ERROR,
460:                            "Operation only possible on master");
461:                    return;
462:                }
463:                ServerProxy proxy = domainMonitor.findServerProxy(serverName);
464:                proxy.startit();
465:            }
466:
467:            /**
468:             * Stop a Remote JOnAS Server
469:             * MBean implementation for jonasAdmin
470:             * @param serverName Name of the jonas server
471:             */
472:            public void stopServer(String serverName) {
473:                if (domainMonitor == null) {
474:                    logger.log(BasicLevel.ERROR,
475:                            "Operation only possible on master");
476:                    return;
477:                }
478:                ServerProxy proxy = domainMonitor.findServerProxy(serverName);
479:                proxy.stopit();
480:            }
481:
482:            /**
483:             * @return Returns the description.
484:             */
485:            public String getDescription() {
486:                if (domainMonitor != null) {
487:                    return domainMonitor.getDescription();
488:                } else {
489:                    return "Unknown";
490:                }
491:            }
492:
493:            /**
494:             * @return Returns the master.
495:             */
496:            public boolean isMaster() {
497:                return (domainMonitor != null);
498:            }
499:
500:            /**
501:             * Return the domain name
502:             * @return domain name or cluster name
503:             */
504:            public String getMyName() {
505:                return domainName;
506:            }
507:
508:            /**
509:             * Return connector server urls for a given JOnAS server
510:             * @param serverName the given JOnAS server name
511:             * @return connector server urls for a given JOnAS server
512:             */
513:            public String[] getConnectorServerURLs(String serverName) {
514:                ArrayList urlList = null;
515:                ServerProxy sp = getServerProxy(serverName);
516:                if (sp != null) {
517:                    urlList = sp.getUrls();
518:                }
519:                if (urlList == null) {
520:                    return null;
521:                }
522:                String[] ret = new String[urlList.size()];
523:                Iterator it = urlList.iterator();
524:                for (int i = 0; i < urlList.size(); i++) {
525:                    ret[i] = (String) it.next();
526:                }
527:                return ret;
528:            }
529:
530:            /**
531:             * Deploy a JAR file on a multiple management target composed of servers and/or clusters
532:             * @param target list of server and/or cluster names
533:             * @param fileName file to be deployed
534:             */
535:            public void deployJar(String[] target, String fileName) {
536:                for (int i = 0; i < target.length; i++) {
537:                    deployOnTarget(target[i], fileName);
538:                }
539:            }
540:
541:            /**
542:             * Deploy a EAR file on a multiple management target composed of servers and/or clusters
543:             * @param target list of server and/or cluster names
544:             * @param fileName file to be deployed
545:             */
546:            public void deployEar(String[] target, String fileName) {
547:                for (int i = 0; i < target.length; i++) {
548:                    deployOnTarget(target[i], fileName);
549:                }
550:            }
551:
552:            /**
553:             * Deploy a WAR file on a multiple management target composed of servers and/or clusters
554:             * @param target list of server and/or cluster names
555:             * @param fileName file to be deployed
556:             */
557:            public void deployWar(String[] target, String fileName) {
558:                for (int i = 0; i < target.length; i++) {
559:                    deployOnTarget(target[i], fileName);
560:                }
561:            }
562:
563:            /**
564:             * Deploy a RAR file on a multiple management target composed of servers and/or clusters
565:             * @param target list of server and/or cluster names
566:             * @param fileName file to be deployed
567:             */
568:            public void deployRar(String[] target, String fileName) {
569:                for (int i = 0; i < target.length; i++) {
570:                    deployOnTarget(target[i], fileName);
571:                }
572:            }
573:
574:            /**
575:             * Upload and deploy a JAR file on a multiple management target composed of servers and/or clusters
576:             * @param target list of server and/or cluster names
577:             * @param fileName file to be deployed
578:             * @param replaceExisting true if the uploaded file can replace a file with the same name in the jars directory
579:             */
580:            public void uploadDeployJar(String[] target, String fileName,
581:                    boolean replaceExisting) {
582:                for (int i = 0; i < target.length; i++) {
583:                    uploadDeployOnTarget(target[i], fileName, replaceExisting);
584:                }
585:            }
586:
587:            /**
588:             * Upload and deploy a WAR file on a multiple management target composed of servers and/or clusters
589:             * @param target list of server and/or cluster names
590:             * @param fileName file to be deployed
591:             * @param replaceExisting true if the uploaded file can replace a file with the same name in the wars directory
592:             */
593:            public void uploadDeployWar(String[] target, String fileName,
594:                    boolean replaceExisting) {
595:                for (int i = 0; i < target.length; i++) {
596:                    uploadDeployOnTarget(target[i], fileName, replaceExisting);
597:                }
598:            }
599:
600:            /**
601:             * Upload and deploy an EAR file on a multiple management target composed of servers and/or clusters
602:             * @param target list of server and/or cluster names
603:             * @param fileName file to be deployed
604:             * @param replaceExisting true if the uploaded file can replace a file with the same name in the apps directory
605:             */
606:            public void uploadDeployEar(String[] target, String fileName,
607:                    boolean replaceExisting) {
608:                for (int i = 0; i < target.length; i++) {
609:                    uploadDeployOnTarget(target[i], fileName, replaceExisting);
610:                }
611:            }
612:
613:            /**
614:             * Upload and deploy a RAR file on a multiple management target composed of servers and/or clusters
615:             * @param target list of server and/or cluster names
616:             * @param fileName file to be deployed
617:             * @param replaceExisting true if the uploaded file can replace a file with the same name in the rars directory
618:             */
619:            public void uploadDeployRar(String[] target, String fileName,
620:                    boolean replaceExisting) {
621:                for (int i = 0; i < target.length; i++) {
622:                    uploadDeployOnTarget(target[i], fileName, replaceExisting);
623:                }
624:            }
625:
626:            /**
627:             * Undeploy a JAR file of a multiple management target composed of servers and/or clusters
628:             * @param target list of server and/or cluster names
629:             * @param fileName file to be undeployed
630:             */
631:            public void unDeployJar(String[] target, String fileName) {
632:                for (int i = 0; i < target.length; i++) {
633:                    unDeployOnTarget(target[i], fileName);
634:                }
635:            }
636:
637:            /**
638:             * Undeploy a WAR file of a multiple management target composed of servers and/or clusters
639:             * @param target list of server and/or cluster names
640:             * @param fileName file to be undeployed
641:             */
642:            public void unDeployWar(String[] target, String fileName) {
643:                for (int i = 0; i < target.length; i++) {
644:                    unDeployOnTarget(target[i], fileName);
645:                }
646:            }
647:
648:            /**
649:             * Undeploy a EAR file of a multiple management target composed of servers and/or clusters
650:             * @param target list of server and/or cluster names
651:             * @param fileName file to be undeployed
652:             */
653:            public void unDeployEar(String[] target, String fileName) {
654:                for (int i = 0; i < target.length; i++) {
655:                    unDeployOnTarget(target[i], fileName);
656:                }
657:            }
658:
659:            /**
660:             * Undeploy a RAR file of a multiple management target composed of servers and/or clusters
661:             * @param target list of server and/or cluster names
662:             * @param fileName file to be undeployed
663:             */
664:            public void unDeployRar(String[] target, String fileName) {
665:                for (int i = 0; i < target.length; i++) {
666:                    unDeployOnTarget(target[i], fileName);
667:                }
668:            }
669:
670:            /**
671:             *
672:             * @param serverName name of the server to add
673:             * @param urls JMX remote connector urls
674:             * @param clusterName name of the cluster in which the server is to be
675:             * attached, if any. Null otherwise.
676:             * @param clusterDaemonName name of the cluster daemon if any. Null otherwise.
677:             * @throws JMException could not add the server to the domain
678:             */
679:            public void addServer(String serverName, String clusterName,
680:                    String clusterDaemonName, String[] urls) throws JMException {
681:                BaseCluster cl = findCluster(domainName);
682:                cl.addServer(serverName, urls, clusterDaemonName);
683:                if (clusterName != null) {
684:                    cl = findCluster(clusterName);
685:                    cl.addServer(serverName, urls, clusterDaemonName);
686:                }
687:            }
688:
689:            /**
690:             * Deploy a file on a management target which may be a server or a cluster
691:             * @param target server or cluster name
692:             * @param fileName file to be deployed
693:             */
694:            private void deployOnTarget(String target, String fileName) {
695:                ServerProxy sp = findServerProxy(target);
696:                if (sp != null) {
697:                    // The target is a known server in the domain
698:                    sp.deployModule(fileName);
699:                } else {
700:                    // maybe the target is a cluster
701:                    BaseCluster cl = findCluster(target);
702:                    if (cl != null) {
703:                        cl.deployModule(fileName);
704:                    } else {
705:                        logger.log(BasicLevel.ERROR,
706:                                "Can't get deploy on unknown target " + target);
707:                    }
708:                }
709:            }
710:
711:            /**
712:             * Deploy a file on a management target which may be a server or a cluster
713:             * @param target server or cluster name
714:             * @param fileName file to be deployed
715:             * @param replaceExisting true if the uploaded file can replace a file with the same name in the jars directory
716:             */
717:            private void uploadDeployOnTarget(String target, String fileName,
718:                    boolean replaceExisting) {
719:                ServerProxy sp = findServerProxy(target);
720:                if (sp != null) {
721:                    // The target is a known server in the domain
722:                    sp.uploadDeployModule(fileName, replaceExisting);
723:                } else {
724:                    // maybe the target is a cluster
725:                    BaseCluster cl = findCluster(target);
726:                    if (cl != null) {
727:                        cl.uploadDeployModule(fileName, replaceExisting);
728:                    } else {
729:                        logger.log(BasicLevel.ERROR,
730:                                "Can't get deploy on unknown target " + target);
731:                    }
732:                }
733:            }
734:
735:            /**
736:             * Undeploy a file of a management target which may be a server or a cluster
737:             * @param target server or cluster name
738:             * @param fileName file to be deployed
739:             */
740:            private void unDeployOnTarget(String target, String fileName) {
741:                ServerProxy sp = findServerProxy(target);
742:                if (sp != null) {
743:                    // The target is a known server in the domain
744:                    sp.undeployModule(fileName);
745:                } else {
746:                    // maybe the target is a cluster
747:                    BaseCluster cl = findCluster(target);
748:                    if (cl != null) {
749:                        cl.undeployModule(fileName);
750:                    } else {
751:                        logger.log(BasicLevel.ERROR,
752:                                "Can't get undeploy on unknown target "
753:                                        + target);
754:                    }
755:                }
756:            }
757:
758:            /**
759:             * Return the ServerProxy of a given server in the domain.
760:             * @param serverName the server who's ServerProxy is asked for
761:             * @return ServerProxy of the given server.
762:             */
763:            private ServerProxy getServerProxy(String serverName) {
764:                if (serverName.equals(myJ2eeServer.getServerName())) {
765:                    return localServerProxy;
766:                } else {
767:                    // Remote server: Only if we are in the master
768:                    if (domainMonitor == null) {
769:                        logger
770:                                .log(BasicLevel.ERROR,
771:                                        "Can't get ServerProxy of a remote server as this is not a master");
772:                        return null;
773:                    } else {
774:                        return domainMonitor.findServerProxy(serverName);
775:                    }
776:                }
777:            }
778:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.