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


0001:        /**
0002:         * JOnAS: Java(TM) Open Application Server
0003:         * Copyright (C) 2006 Bull S.A.
0004:         * Contact: jonas-team@objectweb.org
0005:         *
0006:         * This library is free software; you can redistribute it and/or
0007:         * modify it under the terms of the GNU Lesser General Public
0008:         * License as published by the Free Software Foundation; either
0009:         * version 2.1 of the License, or any later version.
0010:         *
0011:         * This library is distributed in the hope that it will be useful,
0012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014:         * Lesser General Public License for more details.
0015:         *
0016:         * You should have received a copy of the GNU Lesser General Public
0017:         * License along with this library; if not, write to the Free Software
0018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
0019:         * USA
0020:         *
0021:         * --------------------------------------------------------------------------
0022:         * $Id: ServerProxy.java 10045 2007-03-02 12:42:35Z danesa $
0023:         * --------------------------------------------------------------------------
0024:         */package org.objectweb.jonas.management.monitoring;
0025:
0026:        import java.io.ByteArrayOutputStream;
0027:        import java.io.File;
0028:        import java.io.FileInputStream;
0029:        import java.io.IOException;
0030:        import java.util.Collection;
0031:        import java.util.Hashtable;
0032:        import java.util.Iterator;
0033:        import java.util.Set;
0034:
0035:        import javax.management.Attribute;
0036:        import javax.management.AttributeList;
0037:        import javax.management.InstanceNotFoundException;
0038:        import javax.management.MBeanException;
0039:        import javax.management.MBeanServer;
0040:        import javax.management.ObjectName;
0041:        import javax.management.ReflectionException;
0042:        import javax.management.RuntimeOperationsException;
0043:
0044:        import org.objectweb.jonas.common.JProp;
0045:        import org.objectweb.jonas.jmx.CatalinaObjectName;
0046:        import org.objectweb.jonas.jmx.J2eeObjectName;
0047:        import org.objectweb.jonas.jmx.JonasObjectName;
0048:        import org.objectweb.jonas.jmx.JoramObjectName;
0049:        import org.objectweb.jonas.jmx.ManagementException;
0050:        import org.objectweb.util.monolog.api.BasicLevel;
0051:
0052:        /**
0053:         * A ServerProxy proxy MBean represents a server in the domain on the master side.
0054:         * Implements state transition diagram.
0055:         * @author Adriana Danes
0056:         */
0057:        public class ServerProxy extends JMXProxy implements  ServerProxyMBean {
0058:            /**
0059:             * J2EEServer ObjectName corresponding to the represented server
0060:             */
0061:            private String j2eeObjectName;
0062:
0063:            /**
0064:             * Default value for maxcheck
0065:             */
0066:            private static final int MAXCHECK_DEFAULT = 5;
0067:
0068:            /**
0069:             * Number of retries when detecting a broken connection
0070:             */
0071:            private int maxcheck = MAXCHECK_DEFAULT;
0072:
0073:            /**
0074:             * number of checks in UNREACHABLE case in the case of a server with discovery
0075:             */
0076:            private int nbcheck = 0;
0077:            /**
0078:             * This variable, set to false when the ServerProxy is created, passes to true
0079:             * if a discovery notification arrives concerning the server represented by this
0080:             * proxy
0081:             */
0082:            private boolean hasDiscovery = false;
0083:
0084:            /**
0085:             * Ref to the ClusterDaemon that can monitor the Server
0086:             * null if no ClusterDaemon declared or found.
0087:             */
0088:            private ClusterDaemonProxy clusterdaemon = null;
0089:
0090:            /**
0091:             * MBeanServer
0092:             */
0093:            private MBeanServer mbeanServer = null;
0094:
0095:            /**
0096:             * Constructor used when a server is discovered
0097:             * @param serverName the name of the managed server
0098:             * @param dm the domain monitor which treated the discovery notification
0099:             */
0100:            public ServerProxy(DomainMonitor dm, String serverName) {
0101:                super (dm, serverName, null);
0102:                logger.log(BasicLevel.DEBUG, name);
0103:            }
0104:
0105:            /**
0106:             * Constructor used for a new domain.xml entry or for
0107:             * a server added to the domain by a management application.
0108:             * Also used when creating the ServerProxy for the local server.
0109:             * @param dm current domain monitor
0110:             * @param serverName the name of the managed server
0111:             * @param urls Collection of urls to cinnect to the server
0112:             * @param cdp possible clusterdaemon
0113:             */
0114:            public ServerProxy(DomainMonitor dm, String serverName,
0115:                    Collection urls, ClusterDaemonProxy cdp) {
0116:                super (dm, serverName, urls);
0117:                clusterdaemon = cdp;
0118:                logger.log(BasicLevel.DEBUG, name);
0119:            }
0120:
0121:            /**
0122:             * Notification from discovery: RUNNING
0123:             * @param urls for connection
0124:             */
0125:            public void notifyStarting(Collection urls) {
0126:                logger.log(BasicLevel.DEBUG, name);
0127:                switch (state) {
0128:                case RUNNING:
0129:                    logger.log(BasicLevel.DEBUG, "Already running");
0130:                    break;
0131:                case FAILED:
0132:                    if (connect(urls)) {
0133:                        state = RUNNING;
0134:                        getMonitoringInfo();
0135:                    }
0136:                    break;
0137:                case UNKNOWN:
0138:                    logger.log(BasicLevel.WARN, "Running now with discovery");
0139:                case INITIAL:
0140:                case UNREACHABLE:
0141:                case STOPPED:
0142:                case STARTING:
0143:                    if (connect(urls)) {
0144:                        state = RUNNING;
0145:                        getMonitoringInfo();
0146:                    } else {
0147:                        state = FAILED;
0148:                    }
0149:                    break;
0150:                }
0151:                hasDiscovery = true;
0152:            }
0153:
0154:            /**
0155:             * Notification from discovery: STOPPING
0156:             */
0157:            public void notifyStopping() {
0158:                logger.log(BasicLevel.DEBUG, name);
0159:                switch (state) {
0160:                case STOPPED:
0161:                    logger.log(BasicLevel.DEBUG, "Already stopped");
0162:                    break;
0163:                case UNKNOWN:
0164:                    logger.log(BasicLevel.WARN, "Running now with discovery");
0165:                case FAILED:
0166:                case UNREACHABLE:
0167:                case RUNNING:
0168:                case STOPPING:
0169:                    state = STOPPED;
0170:                    disconnect();
0171:                    break;
0172:                }
0173:                // Set indicator to false in order to reset general info in case
0174:                // the server restarts
0175:                setInfoSet(false);
0176:                hasDiscovery = true;
0177:            }
0178:
0179:            /**
0180:             * Check the MBean server connection and possibly change state in UNREACHABLE
0181:             * or FAILED.
0182:             * @param readall read all monitoring info if server RUNNING
0183:             */
0184:            public void checkit(boolean readall) {
0185:                logger.log(BasicLevel.DEBUG, name);
0186:
0187:                switch (state) {
0188:                case RUNNING:
0189:                    if (!checkConnection()) {
0190:                        state = UNREACHABLE;
0191:                        disconnect();
0192:                        setInfoSet(false);
0193:                        nbcheck = 0;
0194:                    }
0195:                    break;
0196:                case FAILED:
0197:                    if (checkConnection()) {
0198:                        serverStarted();
0199:                    }
0200:                    break;
0201:                case INITIAL:
0202:                    if (checkConnection()) {
0203:                        serverStarted();
0204:                    } else {
0205:                        state = UNREACHABLE;
0206:                    }
0207:                    break;
0208:                case UNREACHABLE:
0209:                    if (checkConnection()) {
0210:                        serverStarted();
0211:                    } else {
0212:                        if (hasDiscovery) {
0213:                            // Increment and test nbcheck only if server with
0214:                            // discovery
0215:                            if (nbcheck++ >= maxcheck) {
0216:                                state = FAILED;
0217:                            }
0218:                        }
0219:                    }
0220:                    break;
0221:                case STOPPING:
0222:                    // let stopit set the state
0223:                    break;
0224:                case STARTING:
0225:                    if (checkConnection()) {
0226:                        serverStarted();
0227:                    } else {
0228:                        if (nbcheck++ >= maxcheck) {
0229:                            state = UNREACHABLE;
0230:                        }
0231:                    }
0232:                    break;
0233:                case STOPPED:
0234:                    break;
0235:                }
0236:                if (readall && state == RUNNING) {
0237:                    // Update some information about the server
0238:                    getMonitoringInfo();
0239:                }
0240:            }
0241:
0242:            /**
0243:             * This method is called by checkit() when the represented server is not
0244:             * in RUNNING state but its connection works. This is good, it means
0245:             * that the server is RUNNING.
0246:             */
0247:            void serverStarted() {
0248:                state = RUNNING;
0249:                dm.notifyServerProxyRunning(this );
0250:            }
0251:
0252:            /**
0253:             * @return The J2EEServer ObjectName corresponding to the represented server
0254:             */
0255:            public String getJ2eeObjectName() {
0256:                if (j2eeObjectName == null) {
0257:                    j2eeObjectName = J2eeObjectName.J2EEServer(getDomain(),
0258:                            name).toString();
0259:                }
0260:                return j2eeObjectName;
0261:            }
0262:
0263:            /**
0264:             * @return The name corresponding to the represented server
0265:             */
0266:            public String getServerName() {
0267:                return name;
0268:            }
0269:
0270:            /**
0271:             * @return The name of the associated cluster daemon, if any, null otherwise
0272:             */
0273:            public String getClusterDaemonName() {
0274:                if (clusterdaemon == null) {
0275:                    return null;
0276:                }
0277:                return clusterdaemon.getName();
0278:            }
0279:
0280:            /**
0281:             * Start the Server
0282:             * discovery notification concerning the represented server
0283:             */
0284:            public void startit() {
0285:                logger.log(BasicLevel.DEBUG, name);
0286:                if (clusterdaemon == null) {
0287:                    logger.log(BasicLevel.ERROR,
0288:                            "No ClusterDaemon associated to " + name);
0289:                    return;
0290:                }
0291:                if (state != RUNNING) {
0292:                    state = STARTING;
0293:                    clusterdaemon.startServer(name, null);
0294:                    nbcheck = 0;
0295:                }
0296:                checkit(true);
0297:            }
0298:
0299:            /**
0300:             * Stop the server via the ClusterDaemon
0301:             */
0302:            public void stopit() {
0303:                logger.log(BasicLevel.DEBUG, name);
0304:                if (clusterdaemon == null) {
0305:                    logger.log(BasicLevel.ERROR,
0306:                            "No ClusterDaemon associated to " + name);
0307:                    return;
0308:                }
0309:                if (state != STOPPED) {
0310:                    state = STOPPING;
0311:                    if (clusterdaemon.stopServer(name, null)) {
0312:                        state = STOPPED;
0313:                    }
0314:                }
0315:            }
0316:
0317:            /**
0318:             * Deploy a filename on the represented (remote) server
0319:             * @param fileName the name of the file containig the module/application
0320:             * to deploy
0321:             */
0322:            public void deployModule(String fileName) {
0323:
0324:                logger.log(BasicLevel.DEBUG, fileName);
0325:
0326:                // Build a DeployAction and register it in DomainMonitor
0327:                DeployAction act = new DeployAction(this , fileName,
0328:                        DeployAction.DEPLOY);
0329:                if (dm == null) {
0330:                    logger.log(BasicLevel.ERROR,
0331:                            "Operation reserved to the master");
0332:                    return;
0333:                }
0334:                if (!dm.registerDeployAction(act)) {
0335:                    logger.log(BasicLevel.WARN,
0336:                            "Operation already running for " + fileName);
0337:                    return;
0338:                }
0339:
0340:                // Check connection
0341:                if (!checkConnection()) {
0342:                    logger.log(BasicLevel.WARN, "Cannot deploy: Server " + name
0343:                            + " not running");
0344:                    act.setError("server not running");
0345:                    return;
0346:                }
0347:
0348:                // operation depends on the type of the file
0349:                String opName = null;
0350:                if (fileName.endsWith(".jar")) {
0351:                    opName = "deployJar";
0352:                } else if (fileName.endsWith(".war")) {
0353:                    opName = "deployWar";
0354:                } else if (fileName.endsWith(".rar")) {
0355:                    opName = "deployRar";
0356:                } else if (fileName.endsWith(".ear")) {
0357:                    opName = "deployEar";
0358:                } else {
0359:                    logger.log(BasicLevel.ERROR,
0360:                            "Cannot deploy this type of file: " + fileName);
0361:                    act.setError("Bad file type : " + fileName);
0362:                    return;
0363:                }
0364:
0365:                String[] params = { fileName };
0366:                String[] signature = { "java.lang.String" };
0367:                try {
0368:                    connection.invoke(serverOn, opName, params, signature);
0369:                } catch (InstanceNotFoundException e) {
0370:                    logger.log(BasicLevel.ERROR, "Cannot deploy file: "
0371:                            + fileName + " :", e);
0372:                    act.setError("Remote J2EEServer not registered");
0373:                    return;
0374:                } catch (MBeanException e) {
0375:                    logger.log(BasicLevel.ERROR, "Cannot deploy file: "
0376:                            + fileName + " :", e);
0377:                    Exception t = e.getTargetException();
0378:                    String errmess = t.getMessage();
0379:                    Throwable c = t.getCause();
0380:                    if (c != null) {
0381:                        errmess += " - " + c.getMessage();
0382:                    }
0383:                    act.setError(errmess);
0384:                    return;
0385:                } catch (ReflectionException e) {
0386:                    logger.log(BasicLevel.ERROR, "Cannot deploy file: "
0387:                            + fileName + " :", e);
0388:                    act.setError(e.getCause().getMessage());
0389:                    return;
0390:                } catch (IOException e) {
0391:                    logger.log(BasicLevel.ERROR, "Cannot deploy file: "
0392:                            + fileName + " :", e);
0393:                    act.setError(e.getMessage());
0394:                    return;
0395:                } catch (RuntimeOperationsException e) {
0396:                    logger.log(BasicLevel.ERROR, "Cannot deploy file: "
0397:                            + fileName + " :", e);
0398:                    Exception t = e.getTargetException();
0399:                    String errmess = t.getMessage();
0400:                    Throwable c = t.getCause();
0401:                    if (c != null) {
0402:                        errmess += " - " + c.getMessage();
0403:                    }
0404:                    act.setError(errmess);
0405:                    return;
0406:                } catch (Exception e) {
0407:                    logger.log(BasicLevel.ERROR, "Unexpected exception: " + e);
0408:                    act.setError(e.getMessage());
0409:                    return;
0410:                }
0411:                act.setOK();
0412:            }
0413:
0414:            /**
0415:             * Undeploy a module on the remote server
0416:             * @param fileName Name of the file containing module (or app) to undeploy
0417:             */
0418:            public void undeployModule(String fileName) {
0419:
0420:                logger.log(BasicLevel.DEBUG, fileName);
0421:
0422:                // Build a DeployAction and register it in DomainMonitor
0423:                DeployAction act = new DeployAction(this , fileName,
0424:                        DeployAction.UNDEPLOY);
0425:                if (dm == null) {
0426:                    logger.log(BasicLevel.ERROR,
0427:                            "Operation reserved to the master");
0428:                    return;
0429:                }
0430:                if (!dm.registerDeployAction(act)) {
0431:                    logger.log(BasicLevel.WARN,
0432:                            "Operation already running for " + fileName);
0433:                    return;
0434:                }
0435:
0436:                // Check connection
0437:                if (!checkConnection()) {
0438:                    logger.log(BasicLevel.WARN, "Cannot undeploy: Server "
0439:                            + name + " not running");
0440:                    act.setError("server not running");
0441:                    return;
0442:                }
0443:
0444:                // operation depends on the type of the file
0445:                String opName = null;
0446:                if (fileName.endsWith(".jar")) {
0447:                    opName = "unDeployJar";
0448:                } else if (fileName.endsWith(".war")) {
0449:                    opName = "unDeployWar";
0450:                } else if (fileName.endsWith(".rar")) {
0451:                    opName = "unDeployRar";
0452:                } else if (fileName.endsWith(".ear")) {
0453:                    opName = "unDeployEar";
0454:                } else {
0455:                    logger.log(BasicLevel.ERROR,
0456:                            "Cannot undeploy this type of file: " + fileName);
0457:                    act.setError("Bad file type : " + fileName);
0458:                    return;
0459:                }
0460:
0461:                String[] params = { fileName };
0462:                String[] signature = { "java.lang.String" };
0463:                try {
0464:                    connection.invoke(serverOn, opName, params, signature);
0465:                } catch (InstanceNotFoundException e) {
0466:                    logger.log(BasicLevel.ERROR, "Cannot undeploy file: "
0467:                            + fileName + " :", e);
0468:                    act.setError("Remote J2EEServer not registered");
0469:                    return;
0470:                } catch (MBeanException e) {
0471:                    logger.log(BasicLevel.ERROR, "Cannot undeploy file: "
0472:                            + fileName + " :", e);
0473:                    Exception t = e.getTargetException();
0474:                    String errmess = t.getMessage();
0475:                    Throwable c = t.getCause();
0476:                    if (c != null) {
0477:                        errmess += " - " + c.getMessage();
0478:                    }
0479:                    act.setError(errmess);
0480:                    return;
0481:                } catch (ReflectionException e) {
0482:                    logger.log(BasicLevel.ERROR, "Cannot undeploy file: "
0483:                            + fileName + " :", e);
0484:                    act.setError(e.getCause().getMessage());
0485:                    return;
0486:                } catch (IOException e) {
0487:                    logger.log(BasicLevel.ERROR, "Cannot undeploy file: "
0488:                            + fileName + " :", e);
0489:                    act.setError(e.getMessage());
0490:                    return;
0491:                }
0492:                act.setOK();
0493:            }
0494:
0495:            /**
0496:             * used for upload in file transfer
0497:             */
0498:            private static final int BUFFER_SIZE = 1024;
0499:
0500:            /**
0501:             * Upload a file on remote server for deployment
0502:             * @param fileName file to upload. One among .war,.jar,.ear,.rar
0503:             * @param replaceExisting if true, replace the existing file if any
0504:             * @throws IOException
0505:             */
0506:            public void uploadFile(String fileName, boolean replaceExisting) {
0507:
0508:                logger.log(BasicLevel.DEBUG, fileName);
0509:
0510:                // Build a DeployAction and register it in DomainMonitor
0511:                DeployAction act = new DeployAction(this , fileName,
0512:                        DeployAction.UPLOAD);
0513:                if (dm == null) {
0514:                    logger.log(BasicLevel.ERROR,
0515:                            "Operation reserved to the master");
0516:                    return;
0517:                }
0518:                if (!dm.registerDeployAction(act)) {
0519:                    logger.log(BasicLevel.WARN,
0520:                            "Operation already running for " + fileName);
0521:                    return;
0522:                }
0523:
0524:                // Check connection
0525:                if (!checkConnection()) {
0526:                    logger.log(BasicLevel.WARN, "Cannot upload file: Server "
0527:                            + name + " not running");
0528:                    act.setError("server not running");
0529:                    return;
0530:                }
0531:
0532:                File file = null;
0533:                // first try the file name as it is
0534:                try {
0535:                    file = new File(fileName).getCanonicalFile();
0536:                } catch (IOException e) {
0537:                    logger.log(BasicLevel.ERROR, "Cannot upload file "
0538:                            + fileName, e);
0539:                    act.setError(e.getMessage());
0540:                    return;
0541:                }
0542:                String deployName = file.getName();
0543:                if (!file.exists()) {
0544:                    // if the file was not found try looking for it under JONAS_BASE
0545:                    String dir = getFolderDir(fileName);
0546:                    if (dir == null) {
0547:                        act.setError("Directory not found");
0548:                        return;
0549:                    }
0550:                    file = new File(dir, fileName);
0551:                    deployName = fileName;
0552:                }
0553:                if (file == null || !file.exists()) {
0554:                    act.setError("File not found");
0555:                    return;
0556:                }
0557:
0558:                try {
0559:                    FileInputStream inputStream = new FileInputStream(file);
0560:                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
0561:                    byte[] buf = new byte[BUFFER_SIZE];
0562:                    // Read bytes
0563:                    int len;
0564:                    while ((len = inputStream.read(buf)) > 0) {
0565:                        baos.write(buf, 0, len);
0566:                    }
0567:                    byte[] bytesOfFile = baos.toByteArray();
0568:
0569:                    Object[] opParams = new Object[] { bytesOfFile, deployName,
0570:                            Boolean.valueOf(replaceExisting) };
0571:                    String[] opSignature = new String[] { "[B",
0572:                            "java.lang.String", "boolean" };
0573:                    connection.invoke(serverOn, "sendFile", opParams,
0574:                            opSignature);
0575:                } catch (InstanceNotFoundException e) {
0576:                    logger.log(BasicLevel.ERROR, "Cannot upload file: "
0577:                            + fileName + " :", e);
0578:                    act.setError("Remote J2EEServer not registered");
0579:                    return;
0580:                } catch (MBeanException e) {
0581:                    logger.log(BasicLevel.ERROR, "Cannot upload file: "
0582:                            + fileName + " :", e);
0583:                    Exception t = e.getTargetException();
0584:                    String errmess = t.getMessage();
0585:                    Throwable c = t.getCause();
0586:                    if (c != null) {
0587:                        errmess += " - " + c.getMessage();
0588:                    }
0589:                    act.setError(errmess);
0590:                    return;
0591:                } catch (ReflectionException e) {
0592:                    logger.log(BasicLevel.ERROR, "Cannot upload file: "
0593:                            + fileName + " :", e);
0594:                    act.setError(e.getCause().getMessage());
0595:                    return;
0596:                } catch (IOException e) {
0597:                    logger.log(BasicLevel.ERROR, "Cannot upload file: "
0598:                            + fileName + " :", e);
0599:                    act.setError(e.getMessage());
0600:                    return;
0601:                }
0602:                act.setOK();
0603:            }
0604:
0605:            /**
0606:             * Upload a file on remote server and deploy it.
0607:             * @param fileName file to upload. One among .war,.jar,.ear,.rar
0608:             * @param replaceExisting if true, replace the existing file if any
0609:             */
0610:            public void uploadDeployModule(String fileName,
0611:                    boolean replaceExisting) {
0612:
0613:                logger.log(BasicLevel.DEBUG, fileName);
0614:
0615:                // This must be considered as 1 single action, so we cannot just
0616:                // call the 2 methods like that :
0617:                //   uploadFile(filename, replaceExisting);
0618:                //   deployModule(filename);
0619:
0620:                // Build a DeployAction and register it in DomainMonitor
0621:                DeployAction act = new DeployAction(this , fileName,
0622:                        DeployAction.UPLOADDEPLOY);
0623:                if (dm == null) {
0624:                    logger.log(BasicLevel.ERROR,
0625:                            "Operation reserved to the master");
0626:                    return;
0627:                }
0628:                if (!dm.registerDeployAction(act)) {
0629:                    logger.log(BasicLevel.WARN,
0630:                            "Operation already running for " + fileName);
0631:                    return;
0632:                }
0633:
0634:                // Check connection
0635:                if (!checkConnection()) {
0636:                    logger.log(BasicLevel.WARN, "Cannot upload file: Server "
0637:                            + name + " not running");
0638:                    act.setError("server not running");
0639:                    return;
0640:                }
0641:
0642:                File file = null;
0643:                // first try the file name as it is
0644:                try {
0645:                    file = new File(fileName).getCanonicalFile();
0646:                } catch (IOException e) {
0647:                    logger.log(BasicLevel.ERROR, "Cannot upload file "
0648:                            + fileName, e);
0649:                    act.setError(e.getMessage());
0650:                    return;
0651:                }
0652:                String deployName = file.getName();
0653:                if (!file.exists()) {
0654:                    // if the file was not found try looking for it under JONAS_BASE
0655:                    String dir = getFolderDir(fileName);
0656:                    if (dir == null) {
0657:                        act.setError("Directory not found");
0658:                        return;
0659:                    }
0660:                    file = new File(dir, fileName);
0661:                    deployName = fileName;
0662:                }
0663:                if (file == null || !file.exists()) {
0664:                    act.setError("File not found");
0665:                    return;
0666:                }
0667:
0668:                try {
0669:                    FileInputStream inputStream = new FileInputStream(file);
0670:                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
0671:                    byte[] buf = new byte[BUFFER_SIZE];
0672:                    // Read bytes
0673:                    int len;
0674:                    while ((len = inputStream.read(buf)) > 0) {
0675:                        baos.write(buf, 0, len);
0676:                    }
0677:                    byte[] bytesOfFile = baos.toByteArray();
0678:
0679:                    Object[] opParams = new Object[] { bytesOfFile, deployName,
0680:                            Boolean.valueOf(replaceExisting) };
0681:                    String[] opSignature = new String[] { "[B",
0682:                            "java.lang.String", "boolean" };
0683:                    connection.invoke(serverOn, "sendFile", opParams,
0684:                            opSignature);
0685:                } catch (InstanceNotFoundException e) {
0686:                    logger.log(BasicLevel.ERROR, "Cannot upload file: "
0687:                            + fileName + " :", e);
0688:                    act.setError("Remote J2EEServer not registered");
0689:                    return;
0690:                } catch (MBeanException e) {
0691:                    logger.log(BasicLevel.ERROR, "Cannot upload file: "
0692:                            + fileName + " :", e);
0693:                    Exception t = e.getTargetException();
0694:                    String errmess = t.getMessage();
0695:                    Throwable c = t.getCause();
0696:                    if (c != null) {
0697:                        errmess += " - " + c.getMessage();
0698:                    }
0699:                    act.setError(errmess);
0700:                    return;
0701:                } catch (ReflectionException e) {
0702:                    logger.log(BasicLevel.ERROR, "Cannot upload file: "
0703:                            + fileName + " :", e);
0704:                    act.setError(e.getCause().getMessage());
0705:                    return;
0706:                } catch (IOException e) {
0707:                    logger.log(BasicLevel.ERROR, "Cannot upload file: "
0708:                            + fileName + " :", e);
0709:                    act.setError(e.getMessage());
0710:                    return;
0711:                }
0712:                // Set intermediate state: DEPLOYING
0713:                act.setDeploying();
0714:
0715:                // operation depends on the type of the file
0716:                String opName = null;
0717:                if (fileName.endsWith(".jar")) {
0718:                    opName = "deployJar";
0719:                } else if (fileName.endsWith(".war")) {
0720:                    opName = "deployWar";
0721:                } else if (fileName.endsWith(".rar")) {
0722:                    opName = "deployRar";
0723:                } else if (fileName.endsWith(".ear")) {
0724:                    opName = "deployEar";
0725:                } else {
0726:                    logger.log(BasicLevel.ERROR,
0727:                            "Cannot deploy this type of file: " + fileName);
0728:                    return;
0729:                }
0730:
0731:                String[] params = { fileName };
0732:                String[] signature = { "java.lang.String" };
0733:                try {
0734:                    connection.invoke(serverOn, opName, params, signature);
0735:                } catch (InstanceNotFoundException e) {
0736:                    logger.log(BasicLevel.ERROR, "Cannot deploy file: "
0737:                            + fileName + " :", e);
0738:                    act.setError("Remote J2EEServer not registered");
0739:                    return;
0740:                } catch (MBeanException e) {
0741:                    logger.log(BasicLevel.ERROR, "Cannot deploy file: "
0742:                            + fileName + " :", e);
0743:                    Exception t = e.getTargetException();
0744:                    String errmess = t.getMessage();
0745:                    Throwable c = t.getCause();
0746:                    if (c != null) {
0747:                        errmess += " - " + c.getMessage();
0748:                    }
0749:                    act.setError(errmess);
0750:                    return;
0751:                } catch (ReflectionException e) {
0752:                    logger.log(BasicLevel.ERROR, "Cannot deploy file: "
0753:                            + fileName + " :", e);
0754:                    act.setError(e.getCause().getMessage());
0755:                    return;
0756:                } catch (IOException e) {
0757:                    logger.log(BasicLevel.ERROR, "Cannot deploy file: "
0758:                            + fileName + " :", e);
0759:                    act.setError(e.getMessage());
0760:                    return;
0761:                }
0762:                act.setOK();
0763:            }
0764:
0765:            /**
0766:             * Returns the directory that a file would be found in.
0767:             *
0768:             * @param fileName the file to find the directory for.
0769:             * @return The directory of the given file.
0770:             */
0771:            private String getFolderDir(String fileName) {
0772:                String jBase = JProp.getJonasBase();
0773:                // based on extension
0774:                String dir = null;
0775:                // EJB
0776:                if (fileName.toLowerCase().endsWith(".jar")) {
0777:                    dir = jBase + File.separator + "ejbjars";
0778:                } else if (fileName.toLowerCase().endsWith(".war")) {
0779:                    // War file
0780:                    dir = jBase + File.separator + "webapps";
0781:                } else if (fileName.toLowerCase().endsWith(".ear")) {
0782:                    // ear file
0783:                    dir = jBase + File.separator + "apps";
0784:                } else if (fileName.toLowerCase().endsWith(".rar")) {
0785:                    // rar file
0786:                    dir = jBase + File.separator + "rars";
0787:                } else {
0788:                    // invalid type
0789:                    logger.log(BasicLevel.ERROR, "Invalid extension for "
0790:                            + fileName);
0791:                }
0792:                return dir;
0793:            }
0794:
0795:            /**
0796:             * @return maxcheck value
0797:             */
0798:            public int getMaxcheck() {
0799:                return maxcheck;
0800:            }
0801:
0802:            /**
0803:             * @param maxcheck maxcheck value
0804:             */
0805:            public void setMaxcheck(int maxcheck) {
0806:                this .maxcheck = maxcheck;
0807:            }
0808:
0809:            // ------------------- Monitoring support -------------------//
0810:            // MBean ObjectNames used for monitoring the represented server
0811:            // these names depend on the domain name and the server name
0812:            private ObjectName jvmOn = null;
0813:
0814:            // General information about the server
0815:            /**
0816:             * Name of the host as given by InetAddress.getLoaclHost().
0817:             * (node attribute from JVM MBean)
0818:             */
0819:            private String hostName = null;
0820:            /**
0821:             * JOnAS version
0822:             */
0823:            private String jonasVersion = null;
0824:            /**
0825:             * JVM vendor
0826:             */
0827:            private String javaVendor = null;
0828:            /**
0829:             * JVM version
0830:             */
0831:            private String javaVersion = null;
0832:            // Info about memory usage
0833:            /**
0834:             * Heap size - free memory
0835:             */
0836:            private Long currentUsedMemory = new Long(-1);
0837:            /**
0838:             * Allocated heap size
0839:             */
0840:            private Long currentTotalMemory = new Long(-1);
0841:            private int allThreadsCount;
0842:            private String protocols = null;
0843:            // infos jdk5
0844:            private String loadCPU = null;
0845:            // Tomcat
0846:            private boolean tomcat;
0847:            private int maxThreadsByConnectorTomcat = 0;
0848:            private int currentThreadCountByConnectorTomcat = 0;
0849:            private int currentThreadBusyByConnectorTomcat = 0;
0850:            private long bytesReceivedByConnectorTomcat = 0;
0851:            private long bytesSentByConnectorTomcat = 0;
0852:            private int errorCountByConnectorTomcat = 0;
0853:            private long processingTimeByConnectorTomcat = 0;
0854:            private int requestCountByConnectorTomcat = 0;
0855:            //Tx
0856:            private boolean transaction;
0857:            private int totalBegunTransactions;
0858:            private int totalCommittedTransactions;
0859:            private int totalCurrentTransactions;
0860:            private int totalExpiredTransactions;
0861:            private int totalRolledbackTransactions;
0862:            // Worker Pool
0863:            private boolean workers;
0864:            private int currentWorkerPoolSize;
0865:            private int maxWorkerPoolSize;
0866:            private int minWorkerPoolSize;
0867:            // JCA
0868:            private boolean jcaConnection;
0869:            private int connectionFailuresJCAConnection = 0;
0870:            private int connectionLeaksJCAConnection = 0;
0871:            private int currentBusyJCAConnection = 0;
0872:            private int currentOpenedJCAConnection = 0;
0873:            private int rejectedOpenJCAConnection = 0;
0874:            private int servedOpenJCAConnection = 0;
0875:            private int waiterCountJCAConnection = 0;
0876:            private long waitingTimeJCAConnection = 0;
0877:            //private int currentInTxJCAConnection;
0878:            //private int currentWaitersJCAConnection;
0879:            //private int poolMaxWaitersJCAConnection;
0880:            //private int poolMaxOpentimeJCAConnection;
0881:            //private int physicalConnectionOpenedCountJCAConnection;
0882:            //private int rejectedFullJCAConnection;
0883:            //private int rejectedOtherJCAConnection;
0884:            //private int rejectedTimeoutJCAConnection;
0885:            // JDBCResource
0886:            private boolean jdbcDatasource;
0887:            private int connectionFailuresJDBCResource;
0888:            private int connectionLeaksJDBCResource;
0889:            private int currentBusyJDBCResource;
0890:            private int currentOpenedJDBCResource;
0891:            private int rejectedOpenJDBCResource;
0892:            private int servedOpenJDBCResource;
0893:            private int waiterCountJDBCResource;
0894:            private long waitingTimeJDBCResource;
0895:
0896:            // JMS
0897:            private boolean jmsJoram;
0898:            private int jmsQueuesNbMsgsReceiveSinceCreation;
0899:            private int jmsQueuesNbMsgsSendToDMQSinceCreation;
0900:            private int jmsQueuesNbMsgsDeliverSinceCreation;
0901:            private int jmsTopicsNbMsgsReceiveSinceCreation;
0902:            private int jmsTopicsNbMsgsSendToDMQSinceCreation;
0903:            private int jmsTopicsNbMsgsDeliverSinceCreation;
0904:            // EJB
0905:            private int currentNumberOfEntityBean;
0906:            private int currentNumberOfEJB;
0907:            private int currentNumberOfMDB;
0908:            private int currentNumberOfSBF;
0909:            private int currentNumberOfSBL;
0910:            /**
0911:             * Indicates if general info on representes server are set or not set
0912:             */
0913:            private boolean infoSet;
0914:
0915:            /**
0916:             * @return true if the general info are set, false otherwise
0917:             */
0918:            public boolean isInfoSet() {
0919:                return infoSet;
0920:            }
0921:
0922:            /**
0923:             * Set the indicator value to <code>true</code> after execting the getInfo() method,
0924:             * and to <code>false</code> when detecting that server become unreacheable or stopping.
0925:             * @param infoSet indicator value to set
0926:             */
0927:            public void setInfoSet(boolean infoSet) {
0928:                this .infoSet = infoSet;
0929:            }
0930:
0931:            /**
0932:             * Get general information that charaterizes the managed server and set this info into
0933:             * attributes that won't change during the server life (JOnAS version, JVM version, etc;)
0934:             */
0935:            private void getInfo() {
0936:                logger.log(BasicLevel.DEBUG, name);
0937:                if (!checkConnection()) {
0938:                    logger.log(BasicLevel.INFO, "Cannot set info for " + name);
0939:                    logger.log(BasicLevel.INFO, "Connection is not set yet");
0940:                    return;
0941:                }
0942:                String domain = getDomain();
0943:                /**
0944:                 * ObjectName of the JSR77 JVM MBean
0945:                 * <domain>:j2eeType=JVM,name=<server>,J2EEServer=<server>
0946:                 */
0947:                jvmOn = J2eeObjectName.JVM(domain, name, name);
0948:
0949:                String attr = "";
0950:                try {
0951:                    if (serverOn != null && connection.isRegistered(serverOn)) {
0952:                        attr = "serverVersion";
0953:                        jonasVersion = (String) connection.getAttribute(
0954:                                serverOn, attr);
0955:                    }
0956:                    if (jvmOn != null && connection.isRegistered(jvmOn)) {
0957:                        String[] attributes = new String[] { "javaVersion",
0958:                                "javaVendor", "node" };
0959:                        AttributeList al = (AttributeList) connection
0960:                                .getAttributes(jvmOn, attributes);
0961:                        for (int i = 0; i < al.size(); i++) {
0962:                            Attribute at = (Attribute) al.get(i);
0963:                            String name = at.getName();
0964:                            if ("javaVersion".equals(name)) {
0965:                                javaVersion = (String) at.getValue();
0966:                            } else if ("javaVendor".equals(name)) {
0967:                                javaVendor = (String) at.getValue();
0968:                            } else if ("node".equals(name)) {
0969:                                hostName = (String) at.getValue();
0970:                            }
0971:                        }
0972:                    }
0973:                } catch (Exception e) {
0974:                    logger.log(BasicLevel.WARN,
0975:                            "Error while getting attribute " + attr);
0976:                    logger.log(BasicLevel.WARN, "serverObjectName=" + serverOn);
0977:                    logger.log(BasicLevel.WARN, "jvmObjectName=" + jvmOn);
0978:                    throw new ManagementException(
0979:                            "Error while getting attribute " + attr + " from "
0980:                                    + name, e);
0981:                }
0982:                setInfoSet(true);
0983:            }
0984:
0985:            /**
0986:             * Update non static information for this node.
0987:             */
0988:            public void getMonitoringInfo() {
0989:                logger.log(BasicLevel.DEBUG, name);
0990:                if (!isInfoSet()) {
0991:                    getInfo();
0992:                }
0993:                // Get general monitoring info
0994:                ObjectName on = null;
0995:                try {
0996:                    // Threads usage given by the JVM MBean
0997:                    if (jvmOn != null && connection.isRegistered(jvmOn)) {
0998:                        on = jvmOn;
0999:                        allThreadsCount = ((Integer) connection.getAttribute(
1000:                                on, "allThreadsCount")).intValue();
1001:                    }
1002:                    // JDK5 - TODO
1003:
1004:                    // J2EEServer provided info on memory managemenet and on protocols
1005:                    if (serverOn != null && connection.isRegistered(serverOn)) {
1006:                        on = serverOn;
1007:                        String[] attributes = new String[] {
1008:                                "currentUsedMemory", "currentTotalMemory",
1009:                                "protocols" };
1010:                        AttributeList al = (AttributeList) connection
1011:                                .getAttributes(on, attributes);
1012:                        for (int i = 0; i < al.size(); i++) {
1013:                            Attribute at = (Attribute) al.get(i);
1014:                            String name = at.getName();
1015:                            if ("currentUsedMemory".equals(name)) {
1016:                                currentUsedMemory = (Long) at.getValue();
1017:                            } else if ("currentTotalMemory".equals(name)) {
1018:                                currentTotalMemory = (Long) at.getValue();
1019:                            } else if ("protocols".equals(name)) {
1020:                                protocols = (String) at.getValue();
1021:                            }
1022:                        }
1023:                    }
1024:                } catch (Exception e) {
1025:                    logger.log(BasicLevel.WARN, "Error while monitoting MBean "
1026:                            + on + ", " + e);
1027:                }
1028:
1029:                // Get satistics provided by Cataline MBeans
1030:                getMonitoringInfoTomcat();
1031:
1032:                // Get satistics provided JOnAS WORKER POOL MBeans
1033:                getMonitoringInfoWorkers();
1034:
1035:                // Get satistics on transactions provided by JTAResource MBean
1036:                getMonitoringInfoTransaction();
1037:
1038:                // Get satistics on JCA connection factories
1039:                getMonitoringInfoJCAConnection();
1040:
1041:                // Get satistics on DataSources
1042:                getMonitoringInfoJDBCResource();
1043:
1044:                // Get statistics on EJBS
1045:                getMonitoringInfoEJBs();
1046:
1047:                // Get Joram Jms Statistics
1048:                getMonitoringInfoJmsJoram();
1049:            }
1050:
1051:            /**
1052:             * Get Joram Jms Statistics
1053:             */
1054:            private void getMonitoringInfoJmsJoram() {
1055:                jmsJoram = false;
1056:                ObjectName on = null;
1057:                try {
1058:                    // Check if the remote server has registered the JORAM RAR module MBean:
1059:                    // <domainName>:j2eeType=ResourceAdapterModule,name=joram_for_jonas_ra,J2EEServer=<serverName>
1060:                    on = J2eeObjectName.getResourceAdapterModules(getDomain(),
1061:                            name);
1062:                    Iterator it = connection.queryNames(on, null).iterator();
1063:                    while (it.hasNext()) {
1064:                        on = (ObjectName) it.next();
1065:                        String name = on.getKeyProperty("name");
1066:                        if (name.equals(JoramObjectName.getJORAM_RAR_NAME())) {
1067:                            jmsJoram = true;
1068:                        }
1069:                    }
1070:                    if (jmsJoram) {
1071:                        Hashtable statistic = null;
1072:                        jmsQueuesNbMsgsReceiveSinceCreation = 0;
1073:                        jmsQueuesNbMsgsSendToDMQSinceCreation = 0;
1074:                        jmsQueuesNbMsgsDeliverSinceCreation = 0;
1075:                        jmsTopicsNbMsgsReceiveSinceCreation = 0;
1076:                        jmsTopicsNbMsgsSendToDMQSinceCreation = 0;
1077:                        jmsTopicsNbMsgsDeliverSinceCreation = 0;
1078:                        on = JoramObjectName.joramQueues();
1079:                        Set onSet = connection.queryNames(on, null);
1080:                        for (it = onSet.iterator(); it.hasNext();) {
1081:                            on = (ObjectName) it.next();
1082:                            statistic = (Hashtable) connection.getAttribute(on,
1083:                                    "Statistic");
1084:                            jmsQueuesNbMsgsReceiveSinceCreation += ((Long) statistic
1085:                                    .get("nbMsgsReceiveSinceCreation"))
1086:                                    .doubleValue();
1087:                            jmsQueuesNbMsgsSendToDMQSinceCreation += ((Long) statistic
1088:                                    .get("nbMsgsSendToDMQSinceCreation"))
1089:                                    .doubleValue();
1090:                            jmsQueuesNbMsgsDeliverSinceCreation += ((Long) statistic
1091:                                    .get("nbMsgsDeliverSinceCreation"))
1092:                                    .doubleValue();
1093:                        }
1094:                        on = JoramObjectName.joramTopics();
1095:                        onSet = connection.queryNames(on, null);
1096:                        for (it = onSet.iterator(); it.hasNext();) {
1097:                            on = (ObjectName) it.next();
1098:                            statistic = (Hashtable) connection.getAttribute(on,
1099:                                    "Statistic");
1100:                            jmsTopicsNbMsgsReceiveSinceCreation += ((Long) statistic
1101:                                    .get("nbMsgsReceiveSinceCreation"))
1102:                                    .doubleValue();
1103:                            jmsTopicsNbMsgsSendToDMQSinceCreation += ((Long) statistic
1104:                                    .get("nbMsgsSendToDMQSinceCreation"))
1105:                                    .doubleValue();
1106:                            jmsTopicsNbMsgsDeliverSinceCreation += ((Long) statistic
1107:                                    .get("nbMsgsDeliverSinceCreation"))
1108:                                    .doubleValue();
1109:                        }
1110:
1111:                    }
1112:                } catch (Exception e) {
1113:                    logger.log(BasicLevel.WARN, "Error while monitoring MBean "
1114:                            + on + ", " + e);
1115:                }
1116:            }
1117:
1118:            /**
1119:             * Update satistics information provided by Cataline MBeans for this node.
1120:             */
1121:            private void getMonitoringInfoTomcat() {
1122:                ObjectName on = null;
1123:                try {
1124:                    // Catalina MBeans provided info
1125:                    // thread uage provided by <domain>:type=ThreadPool,name=connectorName
1126:                    ObjectName ons = CatalinaObjectName
1127:                            .catalinaThreadPools(getDomain());
1128:                    tomcat = false;
1129:                    maxThreadsByConnectorTomcat = 0;
1130:                    currentThreadCountByConnectorTomcat = 0;
1131:                    currentThreadBusyByConnectorTomcat = 0;
1132:                    for (Iterator it = connection.queryNames(ons, null)
1133:                            .iterator(); it.hasNext();) {
1134:                        tomcat = true;
1135:                        on = (ObjectName) it.next();
1136:                        String[] attributes = new String[] { "maxThreads",
1137:                                "currentThreadCount", "currentThreadsBusy"
1138:                        // "minSpareThreads", "maxSpareThreads"
1139:                        };
1140:                        AttributeList al = (AttributeList) connection
1141:                                .getAttributes(on, attributes);
1142:                        for (int i = 0; i < al.size(); i++) {
1143:                            Attribute at = (Attribute) al.get(i);
1144:                            String name = at.getName();
1145:                            if ("maxThreads".equals(name)) {
1146:                                maxThreadsByConnectorTomcat = maxThreadsByConnectorTomcat
1147:                                        + ((Integer) at.getValue()).intValue();
1148:                            } else if ("currentThreadCount".equals(name)) {
1149:                                currentThreadCountByConnectorTomcat = currentThreadCountByConnectorTomcat
1150:                                        + ((Integer) at.getValue()).intValue();
1151:                            } else if ("currentThreadsBusy".equals(name)) {
1152:                                int value = ((Integer) at.getValue())
1153:                                        .intValue();
1154:                                currentThreadBusyByConnectorTomcat += value;
1155:                            }
1156:                        }
1157:                    }
1158:                    // request processing statistics provided by
1159:                    // <domain>:type=GlobalRequestProcessor,name=connectorName
1160:                    ons = CatalinaObjectName
1161:                            .catalinaGlobalRequestProcessors(getDomain());
1162:                    bytesReceivedByConnectorTomcat = 0;
1163:                    bytesSentByConnectorTomcat = 0;
1164:                    errorCountByConnectorTomcat = 0;
1165:                    processingTimeByConnectorTomcat = 0;
1166:                    requestCountByConnectorTomcat = 0;
1167:                    for (Iterator it = connection.queryNames(ons, null)
1168:                            .iterator(); it.hasNext();) {
1169:                        tomcat = true;
1170:                        on = (ObjectName) it.next();
1171:                        String[] attributes = new String[] { "bytesReceived",
1172:                                "bytesSent", "errorCount", "maxTime",
1173:                                "processingTime", "requestCount" };
1174:                        AttributeList al = (AttributeList) connection
1175:                                .getAttributes(on, attributes);
1176:                        for (int i = 0; i < al.size(); i++) {
1177:                            Attribute at = (Attribute) al.get(i);
1178:                            String name = at.getName();
1179:                            if ("bytesReceived".equals(name)) {
1180:                                bytesReceivedByConnectorTomcat += ((Long) at
1181:                                        .getValue()).longValue();
1182:                            } else if ("bytesSent".equals(name)) {
1183:                                bytesSentByConnectorTomcat += ((Long) at
1184:                                        .getValue()).longValue();
1185:                            } else if ("errorCount".equals(name)) {
1186:                                errorCountByConnectorTomcat += ((Integer) at
1187:                                        .getValue()).intValue();
1188:                            } else if ("processingTime".equals(name)) {
1189:                                processingTimeByConnectorTomcat += ((Long) at
1190:                                        .getValue()).longValue();
1191:                            } else if ("requestCount".equals(name)) {
1192:                                requestCountByConnectorTomcat += ((Integer) at
1193:                                        .getValue()).intValue();
1194:                            }
1195:                        }
1196:                    }
1197:                } catch (Exception e) {
1198:                    logger.log(BasicLevel.WARN, "Error while monitoring MBean "
1199:                            + on);
1200:                }
1201:            }
1202:
1203:            /**
1204:             * Update transaction statistics using JTA MBean
1205:             */
1206:            private void getMonitoringInfoTransaction() {
1207:                // transaction processing statistics provided by JTA MBean:
1208:                // <domain>:j2eeType=JTAResource,name=JTAResource,J2EEServer=<server>
1209:                ObjectName jtaOn = J2eeObjectName.JTAResource(getDomain(),
1210:                        name, null);
1211:                transaction = false;
1212:                try {
1213:                    if (jtaOn != null && connection.isRegistered(jtaOn)) {
1214:                        transaction = true;
1215:                        String[] attributes = new String[] {
1216:                                "totalBegunTransactions",
1217:                                "totalCommittedTransactions",
1218:                                "totalCurrentTransactions",
1219:                                "totalExpiredTransactions",
1220:                                "totalRolledbackTransactions" };
1221:                        AttributeList al = (AttributeList) connection
1222:                                .getAttributes(jtaOn, attributes);
1223:                        for (int i = 0; i < al.size(); i++) {
1224:                            Attribute at = (Attribute) al.get(i);
1225:                            String name = at.getName();
1226:                            if ("totalBegunTransactions".equals(name)) {
1227:                                totalBegunTransactions = ((Integer) at
1228:                                        .getValue()).intValue();
1229:                            } else if ("totalCommittedTransactions"
1230:                                    .equals(name)) {
1231:                                totalCommittedTransactions = ((Integer) at
1232:                                        .getValue()).intValue();
1233:                            } else if ("totalCurrentTransactions".equals(name)) {
1234:                                totalCurrentTransactions = ((Integer) at
1235:                                        .getValue()).intValue();
1236:                            } else if ("totalRolledbackTransactions"
1237:                                    .equals(name)) {
1238:                                totalRolledbackTransactions = ((Integer) at
1239:                                        .getValue()).intValue();
1240:                            }
1241:                        }
1242:                    }
1243:                } catch (Exception e) {
1244:                    logger.log(BasicLevel.WARN, "Error while monitoring MBean "
1245:                            + jtaOn);
1246:                }
1247:            }
1248:
1249:            /**
1250:             * Update JOnAS Worker pool thread statistics
1251:             */
1252:            private void getMonitoringInfoWorkers() {
1253:                // JOnAS Worker pool thread statistics are provided by workmanager MBean:
1254:                // <domain>:type=workmanager/*,name=.. TO BE Added*/
1255:                ObjectName wpoolOn = JonasObjectName.workManager();
1256:                workers = false;
1257:                try {
1258:                    if (wpoolOn != null && connection.isRegistered(wpoolOn)) {
1259:                        workers = true;
1260:                        String[] attributes = new String[] { "currentPoolSize",
1261:                                "maxPoolSize", "minPoolSize" };
1262:                        AttributeList al = (AttributeList) connection
1263:                                .getAttributes(wpoolOn, attributes);
1264:                        for (int i = 0; i < al.size(); i++) {
1265:                            Attribute at = (Attribute) al.get(i);
1266:                            String name = at.getName();
1267:                            if ("currentPoolSize".equals(name)) {
1268:                                currentWorkerPoolSize = ((Integer) at
1269:                                        .getValue()).intValue();
1270:                            } else if ("maxPoolSize".equals(name)) {
1271:                                maxWorkerPoolSize = ((Integer) at.getValue())
1272:                                        .intValue();
1273:                            } else if ("minPoolSize".equals(name)) {
1274:                                minWorkerPoolSize = ((Integer) at.getValue())
1275:                                        .intValue();
1276:                            }
1277:                        }
1278:                    }
1279:                } catch (Exception e) {
1280:                    logger.log(BasicLevel.WARN, "Error while monitoring MBean "
1281:                            + wpoolOn);
1282:                }
1283:            }
1284:
1285:            /**
1286:             * Update statistics related to the JDBCDataSources.
1287:             * The ***JDBCResource attributes represent the sum of the corresponding attributes
1288:             * in all the JDBCDataSource MBeans of a given managed server
1289:             */
1290:            private void getMonitoringInfoJDBCResource() {
1291:                // JDBCDataSources MBeans are identified by
1292:                // <domain>:j2eeType=JDBCDataSource,name=<datasource-name>
1293:                ObjectName jdbcDatasourcesOn = J2eeObjectName
1294:                        .getJDBCDataSources(getDomain(), name);
1295:                ObjectName jdbcDatasourceOn = null;
1296:                jdbcDatasource = false;
1297:                try {
1298:                    Set jdbcDatasourceOns = connection.queryNames(
1299:                            jdbcDatasourcesOn, null);
1300:                    if (jdbcDatasourceOns.isEmpty()) {
1301:                        return;
1302:                    }
1303:                    String[] attributes = new String[] { "connectionFailures",
1304:                            "connectionLeaks", "currentBusy", "currentOpened",
1305:                            "rejectedOpen", "servedOpen", "waiterCount",
1306:                            "waitingTime" };
1307:                    jdbcDatasource = true;
1308:                    connectionFailuresJDBCResource = 0;
1309:                    connectionLeaksJDBCResource = 0;
1310:                    currentBusyJDBCResource = 0;
1311:                    currentOpenedJDBCResource = 0;
1312:                    rejectedOpenJDBCResource = 0;
1313:                    servedOpenJDBCResource = 0;
1314:                    waiterCountJDBCResource = 0;
1315:                    waitingTimeJDBCResource = 0;
1316:                    for (Iterator it = jdbcDatasourceOns.iterator(); it
1317:                            .hasNext();) {
1318:                        jdbcDatasourceOn = (ObjectName) it.next();
1319:                        AttributeList al = (AttributeList) connection
1320:                                .getAttributes(jdbcDatasourceOn, attributes);
1321:                        for (int i = 0; i < al.size(); i++) {
1322:                            Attribute at = (Attribute) al.get(i);
1323:                            String name = at.getName();
1324:                            if ("connectionFailures".equals(name)) {
1325:                                connectionFailuresJDBCResource += ((Integer) at
1326:                                        .getValue()).intValue();
1327:                            } else if ("connectionLeaks".equals(name)) {
1328:                                connectionLeaksJDBCResource += ((Integer) at
1329:                                        .getValue()).intValue();
1330:                            } else if ("currentBusy".equals(name)) {
1331:                                currentBusyJDBCResource += ((Integer) at
1332:                                        .getValue()).intValue();
1333:                            } else if ("currentOpened".equals(name)) {
1334:                                currentOpenedJDBCResource += ((Integer) at
1335:                                        .getValue()).intValue();
1336:                            } else if ("rejectedOpen".equals(name)) {
1337:                                rejectedOpenJDBCResource += ((Integer) at
1338:                                        .getValue()).intValue();
1339:                            } else if ("servedOpen".equals(name)) {
1340:                                servedOpenJDBCResource += ((Integer) at
1341:                                        .getValue()).intValue();
1342:                            } else if ("waiterCount".equals(name)) {
1343:                                waiterCountJDBCResource += ((Integer) at
1344:                                        .getValue()).intValue();
1345:                            } else if ("waitingTime".equals(name)) {
1346:                                waitingTimeJDBCResource += ((Long) at
1347:                                        .getValue()).intValue();
1348:                            }
1349:                        }
1350:                    }
1351:                } catch (Exception e) {
1352:                    logger.log(BasicLevel.WARN, "Error while monitoring MBean "
1353:                            + jdbcDatasourceOn);
1354:                }
1355:            }
1356:
1357:            /**
1358:             * Update statistics related to the JCAConnection resources.
1359:             * The ***JCA attributes represent the sum of the corresponding attributes
1360:             * in all the JCAConnectionFactory MBeans of a given managed server
1361:             */
1362:            private void getMonitoringInfoJCAConnection() {
1363:                // JCAConnectionFactory MBeans are identified by
1364:                // <domain>:j2eeType=JCAConnectionFactory,name=<jca-connection-name>
1365:                ObjectName jcaFactoriesOn = J2eeObjectName
1366:                        .getJCAConnectionFactories(getDomain(), name);
1367:                ObjectName jcaFactoryOn = null;
1368:                jcaConnection = false;
1369:                try {
1370:                    Set jcaFactoryOns = connection.queryNames(jcaFactoriesOn,
1371:                            null);
1372:                    if (jcaFactoryOns.isEmpty()) {
1373:                        return;
1374:                    }
1375:                    String[] attributes = new String[] { "connectionFailures",
1376:                            "connectionLeaks", "currentBusy", "currentOpened",
1377:                            "rejectedOpen", "servedOpen", "waiterCount",
1378:                            "waitingTime" };
1379:                    jcaConnection = true;
1380:                    connectionFailuresJCAConnection = 0;
1381:                    connectionLeaksJCAConnection = 0;
1382:                    currentBusyJCAConnection = 0;
1383:                    currentOpenedJCAConnection = 0;
1384:                    rejectedOpenJCAConnection = 0;
1385:                    servedOpenJCAConnection = 0;
1386:                    waiterCountJCAConnection = 0;
1387:                    waitingTimeJCAConnection = 0;
1388:                    for (Iterator it = jcaFactoryOns.iterator(); it.hasNext();) {
1389:                        jcaFactoryOn = (ObjectName) it.next();
1390:                        AttributeList al = (AttributeList) connection
1391:                                .getAttributes(jcaFactoryOn, attributes);
1392:                        for (int i = 0; i < al.size(); i++) {
1393:                            Attribute at = (Attribute) al.get(i);
1394:                            String name = at.getName();
1395:                            if ("connectionFailures".equals(name)) {
1396:                                connectionFailuresJCAConnection += ((Integer) at
1397:                                        .getValue()).intValue();
1398:                            } else if ("connectionLeaks".equals(name)) {
1399:                                connectionLeaksJCAConnection += ((Integer) at
1400:                                        .getValue()).intValue();
1401:                            } else if ("currentBusy".equals(name)) {
1402:                                currentBusyJCAConnection += ((Integer) at
1403:                                        .getValue()).intValue();
1404:                            } else if ("currentOpened".equals(name)) {
1405:                                currentOpenedJCAConnection += ((Integer) at
1406:                                        .getValue()).intValue();
1407:                            } else if ("rejectedOpen".equals(name)) {
1408:                                rejectedOpenJCAConnection += ((Integer) at
1409:                                        .getValue()).intValue();
1410:                            } else if ("servedOpen".equals(name)) {
1411:                                servedOpenJCAConnection += ((Integer) at
1412:                                        .getValue()).intValue();
1413:                            } else if ("waiterCount".equals(name)) {
1414:                                waiterCountJCAConnection += ((Integer) at
1415:                                        .getValue()).intValue();
1416:                            } else if ("waitingTime".equals(name)) {
1417:                                waitingTimeJCAConnection += ((Long) at
1418:                                        .getValue()).intValue();
1419:                            }
1420:                        }
1421:                    }
1422:                } catch (Exception e) {
1423:                    logger.log(BasicLevel.WARN, "Error while monitoring MBean "
1424:                            + jcaFactoryOn + ", " + e);
1425:                }
1426:            }
1427:
1428:            private void getMonitoringInfoEJBs() {
1429:                ObjectName entityBeansOn = J2eeObjectName
1430:                        .getEntityBeans(getDomain());
1431:                ObjectName on = null;
1432:                try {
1433:                    on = J2eeObjectName.getEntityBeans(getDomain());
1434:                    Set ons = connection.queryNames(on, null);
1435:                    currentNumberOfEntityBean = ons.size();
1436:                    on = J2eeObjectName.getStatefulSessionBeans(getDomain());
1437:                    ons = connection.queryNames(on, null);
1438:                    currentNumberOfSBF = ons.size();
1439:                    on = J2eeObjectName.getStatelessSessionBeans(getDomain());
1440:                    ons = connection.queryNames(on, null);
1441:                    currentNumberOfSBL = ons.size();
1442:                    on = J2eeObjectName.getMessageDrivenBeans(getDomain());
1443:                    ons = connection.queryNames(on, null);
1444:                    currentNumberOfMDB = ons.size();
1445:                    currentNumberOfEJB = currentNumberOfEntityBean
1446:                            + currentNumberOfSBF + currentNumberOfSBL
1447:                            + currentNumberOfMDB;
1448:                } catch (Exception e) {
1449:                    logger.log(BasicLevel.WARN, "Error while monitoring MBean "
1450:                            + on + ", " + e);
1451:                }
1452:            }
1453:
1454:            public int getAllThreadsCount() {
1455:                return allThreadsCount;
1456:            }
1457:
1458:            public long getBytesReceivedByConnectorTomcat() {
1459:                return bytesReceivedByConnectorTomcat;
1460:            }
1461:
1462:            public long getBytesSentByConnectorTomcat() {
1463:                return bytesSentByConnectorTomcat;
1464:            }
1465:
1466:            public int getConnectionFailuresJCAConnection() {
1467:                return connectionFailuresJCAConnection;
1468:            }
1469:
1470:            public int getConnectionLeaksJCAConnection() {
1471:                return connectionLeaksJCAConnection;
1472:            }
1473:
1474:            public int getCurrentBusyJCAConnection() {
1475:                return currentBusyJCAConnection;
1476:            }
1477:
1478:            public int getCurrentNumberOfEntityBean() {
1479:                return currentNumberOfEntityBean;
1480:            }
1481:
1482:            public int getCurrentNumberOfEJB() {
1483:                return currentNumberOfEJB;
1484:            }
1485:
1486:            public int getCurrentNumberOfMDB() {
1487:                return currentNumberOfMDB;
1488:            }
1489:
1490:            public int getCurrentNumberOfSBF() {
1491:                return currentNumberOfSBF;
1492:            }
1493:
1494:            public int getCurrentNumberOfSBL() {
1495:                return currentNumberOfSBL;
1496:            }
1497:
1498:            public int getCurrentOpenedJCAConnection() {
1499:                return currentOpenedJCAConnection;
1500:            }
1501:
1502:            public int getCurrentThreadBusyByConnectorTomcat() {
1503:                return currentThreadBusyByConnectorTomcat;
1504:            }
1505:
1506:            public int getCurrentThreadCountByConnectorTomcat() {
1507:                return currentThreadCountByConnectorTomcat;
1508:            }
1509:
1510:            public Long getCurrentTotalMemory() {
1511:                return currentTotalMemory;
1512:            }
1513:
1514:            public Long getCurrentUsedMemory() {
1515:                return currentUsedMemory;
1516:            }
1517:
1518:            public int getCurrentWorkerPoolSize() {
1519:                return currentWorkerPoolSize;
1520:            }
1521:
1522:            public int getErrorCountByConnectorTomcat() {
1523:                return errorCountByConnectorTomcat;
1524:            }
1525:
1526:            public String getHostName() {
1527:                return hostName;
1528:            }
1529:
1530:            public String getJavaVendor() {
1531:                return javaVendor;
1532:            }
1533:
1534:            public String getJavaVersion() {
1535:                return javaVersion;
1536:            }
1537:
1538:            public int getJmsQueuesNbMsgsDeliverSinceCreation() {
1539:                return jmsQueuesNbMsgsDeliverSinceCreation;
1540:            }
1541:
1542:            public int getJmsQueuesNbMsgsReceiveSinceCreation() {
1543:                return jmsQueuesNbMsgsReceiveSinceCreation;
1544:            }
1545:
1546:            public int getJmsQueuesNbMsgsSendToDMQSinceCreation() {
1547:                return jmsQueuesNbMsgsSendToDMQSinceCreation;
1548:            }
1549:
1550:            public int getJmsTopicsNbMsgsDeliverSinceCreation() {
1551:                return jmsTopicsNbMsgsDeliverSinceCreation;
1552:            }
1553:
1554:            public int getJmsTopicsNbMsgsReceiveSinceCreation() {
1555:                return jmsTopicsNbMsgsReceiveSinceCreation;
1556:            }
1557:
1558:            public int getJmsTopicsNbMsgsSendToDMQSinceCreation() {
1559:                return jmsTopicsNbMsgsSendToDMQSinceCreation;
1560:            }
1561:
1562:            public String getJOnASVersion() {
1563:                return jonasVersion;
1564:            }
1565:
1566:            public String getLoadCPU() {
1567:                return loadCPU;
1568:            }
1569:
1570:            public int getMaxThreadsByConnectorTomcat() {
1571:                return maxThreadsByConnectorTomcat;
1572:            }
1573:
1574:            public int getMaxWorkerPoolSize() {
1575:                return maxWorkerPoolSize;
1576:            }
1577:
1578:            public MBeanServer getMbeanServer() {
1579:                return mbeanServer;
1580:            }
1581:
1582:            public int getMinWorkerPoolSize() {
1583:                return minWorkerPoolSize;
1584:            }
1585:
1586:            public long getProcessingTimeByConnectorTomcat() {
1587:                return processingTimeByConnectorTomcat;
1588:            }
1589:
1590:            public String getProtocols() {
1591:                return protocols;
1592:            }
1593:
1594:            public int getRequestCountByConnectorTomcat() {
1595:                return requestCountByConnectorTomcat;
1596:            }
1597:
1598:            public int getTotalBegunTransactions() {
1599:                return totalBegunTransactions;
1600:            }
1601:
1602:            public int getTotalCommittedTransactions() {
1603:                return totalCommittedTransactions;
1604:            }
1605:
1606:            public int getTotalCurrentTransactions() {
1607:                return totalCurrentTransactions;
1608:            }
1609:
1610:            public int getTotalExpiredTransactions() {
1611:                return totalExpiredTransactions;
1612:            }
1613:
1614:            public int getTotalRolledbackTransactions() {
1615:                return totalRolledbackTransactions;
1616:            }
1617:
1618:            public int getWaiterCountJCAConnection() {
1619:                return waiterCountJCAConnection;
1620:            }
1621:
1622:            public long getWaitingTimeJCAConnection() {
1623:                return waitingTimeJCAConnection;
1624:            }
1625:
1626:            public boolean getTomcat() {
1627:                return tomcat;
1628:            }
1629:
1630:            public boolean getTransaction() {
1631:                return transaction;
1632:            }
1633:
1634:            public boolean getWorkers() {
1635:                return workers;
1636:            }
1637:
1638:            public int getConnectionFailuresJDBCResource() {
1639:                return connectionFailuresJDBCResource;
1640:            }
1641:
1642:            public int getConnectionLeaksJDBCResource() {
1643:                return connectionLeaksJDBCResource;
1644:            }
1645:
1646:            public int getCurrentBusyJDBCResource() {
1647:                return currentBusyJDBCResource;
1648:            }
1649:
1650:            public int getCurrentOpenedJDBCResource() {
1651:                return currentOpenedJDBCResource;
1652:            }
1653:
1654:            public int getRejectedOpenJDBCResource() {
1655:                return rejectedOpenJDBCResource;
1656:            }
1657:
1658:            public int getServedOpenJDBCResource() {
1659:                return servedOpenJDBCResource;
1660:            }
1661:
1662:            public int getWaiterCountJDBCResource() {
1663:                return waiterCountJDBCResource;
1664:            }
1665:
1666:            public long getWaitingTimeJDBCResource() {
1667:                return waitingTimeJDBCResource;
1668:            }
1669:
1670:            public int getServedOpenJCAConnection() {
1671:                return servedOpenJCAConnection;
1672:            }
1673:
1674:            public int getRejectedOpenJCAConnection() {
1675:                return rejectedOpenJCAConnection;
1676:            }
1677:
1678:            public boolean getJcaConnection() {
1679:                return jcaConnection;
1680:            }
1681:
1682:            public boolean getJdbcDatasource() {
1683:                return jdbcDatasource;
1684:            }
1685:
1686:            public boolean getJmsJoram() {
1687:                return jmsJoram;
1688:            }
1689:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.