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


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 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:         * $Id: J2EEServer.java 9642 2006-09-29 14:01:14Z danesa $
022:         * --------------------------------------------------------------------------
023:         */package org.objectweb.jonas.server;
024:
025:        // Java imports
026:        import java.util.ArrayList;
027:        import java.util.List;
028:
029:        import javax.management.JMException;
030:        import javax.management.MBeanServer;
031:        import javax.management.MBeanServerNotification;
032:        import javax.management.Notification;
033:        import javax.management.NotificationFilter;
034:        import javax.management.NotificationListener;
035:        import javax.management.ObjectName;
036:
037:        import org.objectweb.jonas.common.Log;
038:        import org.objectweb.jonas.container.EJBService;
039:        import org.objectweb.jonas.ear.EarService;
040:        import org.objectweb.jonas.jmx.JmxService;
041:        import org.objectweb.jonas.management.AttributeAddNotification;
042:        import org.objectweb.jonas.management.AttributeRemoveNotification;
043:        import org.objectweb.jonas.management.ListenerJavaBean;
044:        import org.objectweb.jonas.management.ReconfigException;
045:        import org.objectweb.jonas.management.j2eemanagement.J2EEManagedObject;
046:        import org.objectweb.jonas.resource.ResourceService;
047:        import org.objectweb.jonas.service.ServiceManager;
048:        import org.objectweb.jonas.web.JWebContainerService;
049:        import org.objectweb.jonas_timer.TimerEvent;
050:        import org.objectweb.jonas_timer.TimerEventListener;
051:        import org.objectweb.jonas_timer.TimerManager;
052:        import org.objectweb.util.monolog.api.BasicLevel;
053:        import org.objectweb.util.monolog.api.Logger;
054:
055:        /**
056:         * MBean class for Server management.
057:         * Two classes are used to provide all management services : J2EEServer and J2EEServerMBean.
058:         * This class provide the notification's process when add or remove resources.
059:         * @author Guillaume Riviere
060:         * @author Michel Bruno
061:         * <br>contributors Adriana Danes, Michel-Ange Anton
062:         *
063:         */
064:        public class J2EEServer extends J2EEManagedObject implements 
065:                TimerEventListener, NotificationListener {
066:            /**
067:             * object to manage
068:             */
069:            private Server server = null;
070:            private String serverName = null;
071:            private String serverVersion = null;
072:            private String serverVendor = null;
073:            private String protocols = null;
074:            private ArrayList deployedObjects = null;
075:            private ArrayList resources = null;
076:            private ArrayList javaVMs = null;
077:            private String versions = null;
078:            private String jonasBase = null;
079:            /**
080:             * monitoring objects
081:             */
082:            private boolean activated = true;
083:
084:            private int sizeTableMeasures = 120;
085:            private int range = 10;
086:            private Long[] tableMeasures;
087:            private long maxtotalmemory;
088:            private TimerEvent mytimer = null;
089:
090:            /**
091:             * Management logger
092:             */
093:            private static Logger mgtLogger = Log
094:                    .getLogger(Log.JONAS_MANAGEMENT_PREFIX);
095:            /**
096:             * Management logger
097:             */
098:            private static Logger evtLogger = Log
099:                    .getLogger(Log.JONAS_MANAGEMENT_EVENT_PREFIX);
100:
101:            /**
102:             * Notifications variables
103:             */
104:            // sequence number needed when sending notifications
105:            private long sequenceNumber = 0;
106:
107:            /**Support JMX notification
108:            /*-- temporary solution allowing to support one listener (the ManagementListener MBean)
109:             */
110:            private ListenerJavaBean myListener = null;
111:
112:            // Services used to deploy J2EE modules and applications
113:            /**
114:             * EJB Container service
115:             */
116:            private EJBService ejbService = null;
117:            /**
118:             * EAR service
119:             */
120:            private EarService earService = null;
121:            /**
122:             * Resource service
123:             */
124:            private ResourceService rarService = null;
125:            /**
126:             * War service
127:             */
128:            private JWebContainerService warService = null;
129:
130:            private MBeanServer jmxServer = null;
131:
132:            /**
133:             * MBean constructor
134:             * @param objectName object name of the managed object
135:             * @param server Server object
136:             * @param serverName server name
137:             * @param serverVersion JOnAS version
138:             * @param serverVendor is JOnAS
139:             * @param protocols protocols supported
140:             */
141:            public J2EEServer(String objectName, Server server,
142:                    String serverName, String serverVersion,
143:                    String serverVendor, String protocols, String versions) {
144:                super (objectName);
145:                this .server = server;
146:                this .serverName = serverName;
147:                this .serverVersion = serverVersion;
148:                this .serverVendor = serverVendor;
149:                this .protocols = protocols;
150:                this .versions = versions;
151:                initTable();
152:                deployedObjects = new ArrayList();
153:                resources = new ArrayList();
154:                javaVMs = new ArrayList();
155:                //Launch Timer
156:                mytimer = TimerManager.getInstance().addTimerMs(this ,
157:                        range * 1000, new Integer(1), true);
158:                // Get services references
159:                // In case one of these services is not running, a ServiceException is thrown
160:                // No exception treatement is provided, only keep reference null
161:                try {
162:                    ejbService = (EJBService) ServiceManager.getInstance()
163:                            .getEjbService();
164:                } catch (Exception e) {
165:                }
166:                try {
167:                    earService = (EarService) ServiceManager.getInstance()
168:                            .getEarService();
169:                } catch (Exception e) {
170:                }
171:                try {
172:                    rarService = (ResourceService) ServiceManager.getInstance()
173:                            .getRarService();
174:                } catch (Exception e) {
175:                }
176:                try {
177:                    warService = (JWebContainerService) ServiceManager
178:                            .getInstance().getWebContainerService();
179:                } catch (Exception e) {
180:                }
181:                try {
182:                    JmxService jmxService = (JmxService) ServiceManager
183:                            .getInstance().getJmxService();
184:                    jmxServer = jmxService.getJmxServer();
185:                } catch (Exception e) {
186:                }
187:                // Add myself as listner to  MBeanServerNotifications. Use for this the MBeanServerDelegate ObjectName as
188:                // argument in the addNotificationListener method (see JMX API for more info).
189:                // Use null NotificationFilter and null handback object.
190:                try {
191:                    ObjectName delegate = new ObjectName(
192:                            "JMImplementation:type=MBeanServerDelegate");
193:                    jmxServer.addNotificationListener(delegate, this , null,
194:                            null);
195:                } catch (JMException me) {
196:                    // MalformedObjectNameException should not occur if the JMX implementation is correct
197:                    // InstanceNotFoundException should not occur as we use MBeanServerDelegate ObjectName
198:                    throw new ReconfigException(
199:                            "ReconfigManager can't listen to MBeanServerNotifications because of exception: "
200:                                    + me.toString());
201:                }
202:            }
203:
204:            /**
205:             * Server name
206:             * @return String JOnAS server name
207:             */
208:            public String getServerName() {
209:                return serverName;
210:            }
211:
212:            /**
213:             * Server version
214:             * @return String JOnAS server version
215:             */
216:            public String getServerVersion() {
217:                return serverVersion;
218:            }
219:
220:            /**
221:             * Server vendor
222:             * @return String JOnAS server version
223:             */
224:            public String getServerVendor() {
225:                return serverVendor;
226:            }
227:
228:            /**
229:             * Return the list of MBean names corresponding to the deployed J2EEModules and J2EEApplications
230:             * @return java.util.ArrayList list of the deployed objects' MBean names
231:             */
232:            public List getDeployedObjects() {
233:                return deployedObjects;
234:            }
235:
236:            /**
237:             * Add an object name to the <code>deployedObjects</code> list.
238:             * @param objectName Object name corresponding to a J2EEDeployedObject MBean
239:             */
240:            public void addDeployedObject(String objectName) {
241:                deployedObjects.add(objectName);
242:            }
243:
244:            /**
245:             * Remove an object name to the <code>deployedObjects</code> list.
246:             * @param objectName Object name corresponding to a J2EEDeployedObject MBean
247:             */
248:            public void removeDeployedObject(String objectName) {
249:                deployedObjects.remove(objectName);
250:            }
251:
252:            /**
253:             * Return the list of MBean names corresponding to the resources available on this server
254:             * @return java.util.ArrayList list of the resources' MBean names
255:             */
256:            public List getResources() {
257:                return resources;
258:            }
259:
260:            /**
261:             * Return the list of MBean names corresponding to the JVMs on which this server has running threads
262:             * @return java.util.ArrayList list of the JVMs' MBean names
263:             */
264:            public List getJavaVMs() {
265:                return javaVMs;
266:            }
267:
268:            /**
269:             * Add an object name to the <code>javaVMs</code> list.
270:             * @param objectName Object name correspondig to a JVM MBean
271:             */
272:            public void addJavaVM(String objectName) {
273:                javaVMs.add(objectName);
274:            }
275:
276:            /**
277:             * Protocols supported by this Server
278:             * @return String protocols supported
279:             */
280:            public String getProtocols() {
281:                return protocols;
282:            }
283:
284:            /**
285:             * Stop server (with stopping the JVM)
286:             */
287:            public void stop() throws Exception {
288:                server.stop();
289:            }
290:
291:            /**
292:             * run the garbage collector
293:             */
294:            public void runGC() {
295:                Runtime.getRuntime().gc();
296:            }
297:
298:            /**
299:             * get jvm used memory
300:             * @return Long - current used memory
301:             */
302:            public long getCurrentUsedMemory() {
303:                return usedMemory();
304:            }
305:
306:            /**
307:             * get jvm total memory
308:             * @return Long - current total memory
309:             */
310:            public long getCurrentTotalMemory() {
311:                return totalMemory();
312:            }
313:
314:            /**
315:             * set range
316:             * @param range range for free memory measurement
317:             */
318:            public void setRange(int range) {
319:                if (this .range != range) {
320:                    synchronized (this ) {
321:                        if (range < 10) {
322:                            throw new IllegalArgumentException(
323:                                    "range could not be < 10");
324:                        }
325:                        this .range = range;
326:                        // reset table values
327:                        initTable();
328:                        /// change range
329:                        mytimer.change(this .range * 1000, new Integer(1));
330:                    }
331:                }
332:            }
333:
334:            /**
335:             * get range
336:             * @return Integer - range
337:             */
338:            public int getRange() {
339:                return range;
340:            }
341:
342:            /**
343:             * Set the size of the table of measures
344:             * @param sizeMeasuresTable Number of measures
345:             */
346:            public void setSizeTableMeasures(int sizeMeasuresTable) {
347:                if (sizeMeasuresTable != this .sizeTableMeasures) {
348:                    synchronized (this ) {
349:                        if (sizeMeasuresTable <= 1) {
350:                            throw new IllegalArgumentException(
351:                                    "number of measures could not be <= 1");
352:                        }
353:                        this .sizeTableMeasures = sizeMeasuresTable;
354:                        initTable();
355:                    }
356:                }
357:            }
358:
359:            /**
360:             * Get the size of the table of measures
361:             * @return Number of measures
362:             */
363:            public int getSizeTableMeasures() {
364:                return sizeTableMeasures;
365:            }
366:
367:            /**
368:             * get the table of value
369:             * @return Long[] measures table
370:             */
371:            public Long[] getTableMeasures() {
372:                return tableMeasures;
373:            }
374:
375:            // ===============================================================
376:            // TimerEventListener implementation
377:            // ===============================================================
378:            /**
379:             * The measures timeout has expired
380:             * Do not synchronize this method to avoid deadlocks!
381:             * @param arg Object
382:             */
383:            public void timeoutExpired(Object arg) {
384:                int argvalue = ((Integer) arg).intValue();
385:                switch (argvalue) {
386:                case 1:
387:
388:                    //timeout expired
389:                    long uvalue = usedMemory();
390:                    long tmvalue = totalMemory();
391:
392:                    // put the max total memory
393:                    if (tmvalue > maxtotalmemory) {
394:                        maxtotalmemory = tmvalue;
395:                    }
396:                    for (int i = 0; i < tableMeasures.length; i++) {
397:                        if (i != tableMeasures.length - 1) {
398:                            tableMeasures[i] = tableMeasures[i + 1];
399:                        } else {
400:                            tableMeasures[i] = new Long(uvalue);
401:                        }
402:                    }
403:                    break;
404:                default:
405:
406:                    //timeoutExpired do nothing;
407:                    break;
408:                }
409:            }
410:
411:            /**
412:             * set monitoring activation
413:             * @param pActivated true is activated
414:             */
415:            public void setActivated(boolean pActivated) {
416:                if (pActivated) {
417:                    if (!activated) {
418:                        synchronized (this ) {
419:                            activated = true;
420:                            initTable();
421:                        }
422:                        // launch timer
423:                        mytimer = TimerManager.getInstance().addTimerMs(this ,
424:                                range * 1000, (Object) new Integer(1), true);
425:                    }
426:                } else {
427:                    if (activated) {
428:                        synchronized (this ) {
429:                            activated = false;
430:                            initTable();
431:                            // stop timer
432:                            mytimer.stop();
433:                            mytimer.unset();
434:                        }
435:                    }
436:                }
437:            }
438:
439:            /**
440:             * get monitoring activation
441:             * @return Boolean is activated
442:             */
443:
444:            public boolean isActivated() {
445:                return activated;
446:            }
447:
448:            /**
449:             * private function for monitoring
450:             * @return long  used memory
451:             */
452:
453:            private long usedMemory() {
454:                long result = -1;
455:                while (result < 0) {
456:                    result = Runtime.getRuntime().totalMemory()
457:                            - Runtime.getRuntime().freeMemory();
458:                }
459:
460:                return result / 1000;
461:            }
462:
463:            /**
464:             * private function for monitoring
465:             * @return long  total memory
466:             */
467:
468:            private long totalMemory() {
469:                return Runtime.getRuntime().totalMemory() / 1000;
470:            }
471:
472:            /**
473:             * private init table
474:             */
475:
476:            private void initTable() {
477:                tableMeasures = new Long[sizeTableMeasures];
478:                // init max totalmemory
479:                maxtotalmemory = totalMemory();
480:                for (int i = 0; i < tableMeasures.length; i++) {
481:                    tableMeasures[i] = new Long(0);
482:                }
483:                // init the first value
484:                tableMeasures[tableMeasures.length - 1] = new Long(usedMemory());
485:            }
486:
487:            /**
488:             * Deploy a stand-alone J2EE module packaged in a JAR file
489:             * @param fileName the file name of the JAR to be be deployed.
490:             * @return The ObjectName of the MBean associated to the deployed module
491:             * @throws Exception Management operation could not be executed or failed
492:             */
493:            public String deployJar(String fileName) throws Exception {
494:                if (ejbService != null) {
495:                    return ejbService.createContainer(fileName);
496:                } else {
497:                    throw new Exception("Service ejb not started on "
498:                            + serverName);
499:                }
500:            }
501:
502:            /**
503:             * Test if the specified filename is already deployed or not.
504:             * @param fileName the name of the jar file.
505:             * @return true if the jar is deployed, otherwise false.
506:             * @throws Exception Management operation could not be executed
507:             */
508:            public Boolean isJarDeployed(String fileName) throws Exception {
509:                if (ejbService != null) {
510:                    return ejbService.isJarDeployed(fileName);
511:                } else {
512:                    throw new Exception("Service ejb not started on "
513:                            + serverName);
514:                }
515:            }
516:
517:            /**
518:             * Uneploy a stand-alone J2EE module packaged in a JAR file
519:             * @param fileName the file name of the JAR to be be undeployed.
520:             * @throws Exception Management operation could not be executed or failed
521:             */
522:            public void unDeployJar(String fileName) throws Exception {
523:                if (ejbService != null) {
524:                    ejbService.removeContainer(fileName);
525:                } else {
526:                    throw new Exception("Service ejb not started on "
527:                            + serverName);
528:                }
529:            }
530:
531:            /**
532:             * Test if the specified filename is already deployed or not.
533:             * @param fileName the name of the war file.
534:             * @return true if the war is deployed, otherwise false.
535:             * @throws Exception Management operation could not be executed
536:             */
537:            public Boolean isWarDeployed(String fileName) throws Exception {
538:                if (warService != null) {
539:                    return new Boolean(warService.isWarLoaded(fileName));
540:                } else {
541:                    throw new Exception("Service web not started on "
542:                            + serverName);
543:                }
544:            }
545:
546:            /**
547:             * Deploy a stand-alone J2EE module packaged in a WAR file
548:             * @param fileName the file name of the WAR to be be deployed.
549:             * @return The ObjectName of the MBean associated to the deployed module
550:             * @throws Exception Management operation could not be executed or failed
551:             */
552:            public void deployWar(String fileName) throws Exception {
553:                if (warService != null) {
554:                    warService.registerWarMBean(fileName);
555:                } else {
556:                    throw new Exception("Service web not started on "
557:                            + serverName);
558:                }
559:            }
560:
561:            /**
562:             * Uneploy a stand-alone J2EE module packaged in a WAR file
563:             * @param fileName the file name of the WAR to be be undeployed.
564:             * @throws Exception Management operation could not be executed or failed
565:             */
566:            public void unDeployWar(String fileName) throws Exception {
567:                if (warService != null) {
568:                    warService.unRegisterWarMBean(fileName);
569:                } else {
570:                    throw new Exception("Service web not started on "
571:                            + serverName);
572:                }
573:            }
574:
575:            /**
576:             * Deploy a J2EE application packaged in a EAR file
577:             * @param fileName the file name of the EAR to be be deployed.
578:             * @return The ObjectName of the MBean associated to the deployed J2EE Application
579:             * @throws Exception Management operation could not be executed or failed
580:             */
581:            public String deployEar(String fileName) throws Exception {
582:                if (earService != null) {
583:                    return earService.deployEar(fileName);
584:                } else {
585:                    throw new Exception("Service ear not started on "
586:                            + serverName);
587:                }
588:            }
589:
590:            /**
591:             * Test if the specified filename is already deployed or not. This
592:             * method is defined in the EarService interface.
593:             * @param fileName the name of the ear file.
594:             * @return true if the ear is deployed, else false.
595:             * @throws Exception Management operation could not be executed or failed
596:             */
597:            public Boolean isEarDeployed(String fileName) throws Exception {
598:                if (earService != null) {
599:                    return earService.isEarDeployed(fileName);
600:                } else {
601:                    throw new Exception("Service ear not started on "
602:                            + serverName);
603:                }
604:            }
605:
606:            /**
607:             * undeploy a J2EE application packaged in a EAR file
608:             * @param fileName the file name of the EAR to be be undeployed.
609:             * @throws Exception Management operation could not be executed or failed
610:             */
611:            public void unDeployEar(String fileName) throws Exception {
612:                if (earService != null) {
613:                    earService.unDeployEar(fileName);
614:                } else {
615:                    throw new Exception("Service ear not started on "
616:                            + serverName);
617:                }
618:            }
619:
620:            /**
621:             * Deploy a J2EE application packaged in a RAR file
622:             * @param fileName the file name of the RAR to be be deployed.
623:             * @return The ObjectName of the MBean associated to the deployed J2EE Application
624:             * @throws Exception Management operation could not be executed or failed
625:             */
626:            public String deployRar(String fileName) throws Exception {
627:                if (rarService != null) {
628:                    return rarService.deployRar(fileName);
629:                } else {
630:                    throw new Exception("Service resource not started on "
631:                            + serverName);
632:                }
633:            }
634:
635:            /**
636:             * Test if the specified filename is already deployed or not.
637:             * @param fileName the name of the rar file.
638:             * @return true if the rar is deployed, else false.
639:             * @throws Exception Management operation could not be executed or failed
640:             */
641:            public Boolean isRarDeployed(String fileName) throws Exception {
642:                if (rarService != null) {
643:                    return rarService.isRarDeployed(fileName);
644:                } else {
645:                    throw new Exception("Service resource not started on "
646:                            + serverName);
647:                }
648:            }
649:
650:            /**
651:             * undeploy a J2EE application packaged in a RAR file
652:             * @param fileName the file name of the RAR to be be undeployed.
653:             * @throws Exception Management operation could not be executed or failed
654:             */
655:            public void unDeployRar(String fileName) throws Exception {
656:                if (rarService != null) {
657:                    rarService.unDeployRar(fileName);
658:                } else {
659:                    throw new Exception("Service resource not started on "
660:                            + serverName);
661:                }
662:            }
663:
664:            /**
665:             * Add an object name to the <code>resources</code> list.
666:             * @param pObjectName Object name correspondig to a J2EEResource MBean
667:             */
668:            public void addResource(String pObjectName) {
669:                synchronized (resources) {
670:                    if (resources.contains(pObjectName)) {
671:                        if (mgtLogger.isLoggable(BasicLevel.DEBUG)) {
672:                            mgtLogger.log(BasicLevel.DEBUG, "The object name: "
673:                                    + pObjectName
674:                                    + " is already in the resources list");
675:                        }
676:                    } else {
677:                        // Add
678:                        resources.add(pObjectName);
679:                        // Send the notification
680:                        AttributeAddNotification notification = new AttributeAddNotification(
681:                                getObjectName(), sequenceNumber++, System
682:                                        .currentTimeMillis(), "", "resource",
683:                                pObjectName.toString());
684:                        sendNotification(notification);
685:                        if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
686:                            evtLogger.log(BasicLevel.DEBUG,
687:                                    "AttributeAddNotification emitted: resource added to the J2EEServer: "
688:                                            + pObjectName.toString());
689:                        }
690:                    }
691:                }
692:            }
693:
694:            /**
695:             * Remove an object name from the <code>resources</code> list.
696:             * @param pObjectName Object name correspondig to a J2EEResource MBean
697:             * @return Object name to the removed J2EEResource MBean
698:             */
699:            public String removeResource(String pObjectName) {
700:                String sRet = null;
701:                synchronized (resources) {
702:                    int index = resources.indexOf(pObjectName);
703:                    if (index > -1) {
704:                        // Remove
705:                        sRet = (String) resources.remove(index);
706:                        // Send the notification
707:                        AttributeRemoveNotification notification = new AttributeRemoveNotification(
708:                                getObjectName(), sequenceNumber++, System
709:                                        .currentTimeMillis(), "", "resource",
710:                                pObjectName.toString());
711:                        sendNotification(notification);
712:                        if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
713:                            evtLogger.log(BasicLevel.DEBUG,
714:                                    "AttributeRemoveNotification emitted: resource removed from the J2EEServer: "
715:                                            + pObjectName.toString());
716:                        }
717:                    }
718:                }
719:                return sRet;
720:            }
721:
722:            /**
723:             * Send a notification to the listener.
724:             * @param notification The notification to send
725:             */
726:            public void sendNotification(Notification notification) {
727:                // if registered listener(s)
728:                if (myListener != null) {
729:                    NotificationListener listener = myListener.getListener();
730:                    Object handback = myListener.getHandback();
731:                    listener.handleNotification(notification, handback);
732:                    if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
733:                        evtLogger.log(BasicLevel.DEBUG, "Notification sent");
734:                    }
735:                }
736:            }
737:
738:            /**
739:             * Add a new listener.
740:             * @param listner Listener to notify
741:             * @param filter Notification filter
742:             * @param handback ??
743:             * @throws java.lang.IllegalArgumentException
744:             */
745:            public void addNotificationListener(NotificationListener listner,
746:                    NotificationFilter filter, java.lang.Object handback)
747:                    throws java.lang.IllegalArgumentException {
748:                // Create new listener
749:                ListenerJavaBean lmb = new ListenerJavaBean(listner, filter,
750:                        handback);
751:                myListener = lmb;
752:                if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
753:                    evtLogger.log(BasicLevel.DEBUG,
754:                            "Listener added for J2EEServer MBean: "
755:                                    + getObjectName().toString());
756:                    if (handback != null) {
757:                        evtLogger.log(BasicLevel.DEBUG, " - with handback: "
758:                                + handback.toString());
759:                    }
760:                }
761:            }
762:
763:            /**
764:             * Treat the notifications emitted by the JMX server.
765:             * This method determines the type of the notification and calls the specific treatement.
766:             * @param notification received notification
767:             * @param handback received handback object
768:             */
769:            public void handleNotification(Notification notification,
770:                    java.lang.Object handback) {
771:                if (notification instanceof  MBeanServerNotification) {
772:                    // This notification is sent by the jmx server.
773:                    //
774:                    // ObjectName of the MBean that caused the notification
775:                    ObjectName causeObjectName = ((MBeanServerNotification) notification)
776:                            .getMBeanName();
777:                    String causeJ2eeType = causeObjectName
778:                            .getKeyProperty("j2eeType");
779:                    if (causeJ2eeType != null) {
780:                        // The MBean that caused the notification is a J2EEManagedObject
781:                        // Check for server name being the current server name
782:                        String serverName = causeObjectName
783:                                .getKeyProperty("J2EEServer");
784:                        if (serverName != null) {
785:                            if (!serverName.equals(getServerName())) {
786:                                return;
787:                            }
788:                        } else {
789:                            return;
790:                        }
791:                        // Check for J2EEResource MBeans
792:                        boolean j2eeResource = false;
793:                        if (causeJ2eeType.equals("JavaMailResource")
794:                                || causeJ2eeType.equals("JNDIResource")
795:                                || causeJ2eeType.equals("JDBCResource")
796:                                || causeJ2eeType.equals("JMSResource")
797:                                || causeJ2eeType.equals("JTAResource")
798:                                || causeJ2eeType.equals("JCAResource")
799:                                || causeJ2eeType.equals("RMIIIOPResource")
800:                                || causeJ2eeType.equals("URLResource")) {
801:                            j2eeResource = true;
802:                        }
803:                        if (j2eeResource) {
804:                            String notificationType = notification.getType();
805:                            handleResourceNotification(causeObjectName,
806:                                    notificationType);
807:                        }
808:                        // Check for J2EEDeployedObjects
809:                        boolean j2eeDeployed = false;
810:                        if (causeJ2eeType.equals("J2EEApplication")
811:                                || causeJ2eeType.equals("AppClientModule")
812:                                || causeJ2eeType.equals("EJBModule")
813:                                || causeJ2eeType.equals("WebModule")
814:                                || causeJ2eeType
815:                                        .equals("ResourceAdapterModule")) {
816:                            j2eeDeployed = true;
817:                        }
818:                        if (j2eeDeployed) {
819:                            String notificationType = notification.getType();
820:                            handleDeployedNotification(causeObjectName,
821:                                    notificationType);
822:                        }
823:                    }
824:                }
825:            }
826:
827:            /**
828:             * Treat the registration/unregistration of J2EEResources.
829:             * @param resourceObjectName object name of the J2EEResource MBean that caused the notification
830:             * @param notificationType may be a REGISTRATION_NOTIFICATION or an UNREGISTRATION_NOTIFICATION
831:             */
832:            private void handleResourceNotification(
833:                    ObjectName resourceObjectName, String notificationType) {
834:                if (notificationType
835:                        .equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
836:                    addResource(resourceObjectName.toString());
837:                    if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
838:                        evtLogger.log(BasicLevel.DEBUG, "Resource "
839:                                + resourceObjectName.toString()
840:                                + " added to J2EEServer " + getServerName());
841:                    }
842:                } else if (notificationType
843:                        .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
844:                    removeResource(resourceObjectName.toString());
845:                    if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
846:                        evtLogger
847:                                .log(BasicLevel.DEBUG, "Resource "
848:                                        + resourceObjectName.toString()
849:                                        + " removed from J2EEServer "
850:                                        + getServerName());
851:                    }
852:                }
853:            }
854:
855:            /**
856:             * Treat the registration/unregistration of J2EEDeployedObjects.
857:             * @param deployedObjectName object name of the J2EEDeployedObject MBean that caused the notification
858:             * @param notificationType may be a REGISTRATION_NOTIFICATION or an UNREGISTRATION_NOTIFICATION
859:             */
860:            private void handleDeployedNotification(
861:                    ObjectName deployedObjectName, String notificationType) {
862:                if (notificationType
863:                        .equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
864:                    addDeployedObject(deployedObjectName.toString());
865:                    if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
866:                        evtLogger.log(BasicLevel.DEBUG, "J2EEDeployedObject "
867:                                + deployedObjectName.toString()
868:                                + " added to J2EEServer " + getServerName());
869:                    }
870:                } else if (notificationType
871:                        .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
872:                    removeDeployedObject(deployedObjectName.toString());
873:                    if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
874:                        evtLogger
875:                                .log(BasicLevel.DEBUG, "J2EEDeployedObject "
876:                                        + deployedObjectName.toString()
877:                                        + " removed from J2EEServer "
878:                                        + getServerName());
879:                    }
880:                }
881:            }
882:
883:            /**
884:             * @return Returns the versions.
885:             */
886:            public String getVersions() {
887:                return versions;
888:            }
889:
890:            public String getJonasBase() {
891:                return jonasBase;
892:            }
893:
894:            public void setJonasBase(String jonasBase) {
895:                this.jonasBase = jonasBase;
896:            }
897:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.