KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > server > J2EEServer


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  * --------------------------------------------------------------------------
21  * $Id: J2EEServer.java,v 1.22 2004/11/23 09:29:29 danesa Exp $
22  * --------------------------------------------------------------------------
23  */

24 package org.objectweb.jonas.server;
25
26 // Java imports
27
import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import javax.management.JMException JavaDoc;
31 import javax.management.MBeanServer JavaDoc;
32 import javax.management.MBeanServerNotification JavaDoc;
33 import javax.management.Notification JavaDoc;
34 import javax.management.NotificationFilter JavaDoc;
35 import javax.management.NotificationListener JavaDoc;
36 import javax.management.ObjectName JavaDoc;
37
38 import org.objectweb.jonas.common.Log;
39 import org.objectweb.jonas.container.EJBService;
40 import org.objectweb.jonas.ear.EarService;
41 import org.objectweb.jonas.jmx.JmxService;
42 import org.objectweb.jonas.management.AttributeAddNotification;
43 import org.objectweb.jonas.management.AttributeRemoveNotification;
44 import org.objectweb.jonas.management.ListenerJavaBean;
45 import org.objectweb.jonas.management.ReconfigException;
46 import org.objectweb.jonas.management.j2eemanagement.J2EEManagedObject;
47 import org.objectweb.jonas.resource.ResourceService;
48 import org.objectweb.jonas.service.ServiceManager;
49 import org.objectweb.jonas.web.JWebContainerService;
50 import org.objectweb.jonas_timer.TimerEvent;
51 import org.objectweb.jonas_timer.TimerEventListener;
52 import org.objectweb.jonas_timer.TimerManager;
53 import org.objectweb.util.monolog.api.BasicLevel;
54 import org.objectweb.util.monolog.api.Logger;
55
56 /**
57  * MBean class for Server management.
58  * Two classes are used to provide all management services : J2EEServer and J2EEServerMBean.
59  * This class provide the notification's process when add or remove resources.
60  * @author Guillaume Riviere
61  * @author Michel Bruno
62  * <br>contributors Adriana Danes, Michel-Ange Anton
63  *
64  */

65 public class J2EEServer extends J2EEManagedObject implements TimerEventListener, NotificationListener JavaDoc {
66     /**
67      * object to manage
68      */

69     private Server server = null;
70     private String JavaDoc serverName = null;
71     private String JavaDoc serverVersion = null;
72     private String JavaDoc serverVendor = null;
73     private String JavaDoc protocols = null;
74     private ArrayList JavaDoc deployedObjects = null;
75     private ArrayList JavaDoc resources = null;
76     private ArrayList JavaDoc javaVMs = null;
77     /**
78      * monitoring objects
79      */

80     private boolean activated = true;
81
82     private int sizeTableMeasures = 120;
83     private int range = 10;
84     private Long JavaDoc[] tableMeasures;
85     private long maxtotalmemory;
86     private TimerEvent mytimer = null;
87
88     /**
89      * Management logger
90      */

91     private static Logger mgtLogger = Log.getLogger(Log.JONAS_MANAGEMENT_PREFIX);
92     /**
93      * Management logger
94      */

95     private static Logger evtLogger = Log.getLogger(Log.JONAS_MANAGEMENT_EVENT_PREFIX);
96
97     /**
98      * Notifications variables
99      */

100     // sequence number needed when sending notifications
101
private long sequenceNumber = 0;
102
103     /**Support JMX notification
104     /*-- temporary solution allowing to support one listener (the ManagementListener MBean)
105      */

106     private ListenerJavaBean myListener = null;
107
108     // Services used to deploy J2EE modules and applications
109
/**
110      * EJB Container service
111      */

112     private EJBService ejbService = null;
113     /**
114      * EAR service
115      */

116     private EarService earService = null;
117     /**
118      * Resource service
119      */

120     private ResourceService rarService = null;
121     /**
122      * War service
123      */

124     private JWebContainerService warService = null;
125     
126     private MBeanServer JavaDoc jmxServer = null;
127
128     /**
129      * MBean constructor
130      * @param objectName object name of the managed object
131      * @param server Server object
132      * @param serverName server name
133      * @param serverVersion JOnAS version
134      * @param serverVendor is JOnAS
135      * @param protocols protocols supported
136      */

137     public J2EEServer(String JavaDoc objectName, Server server, String JavaDoc serverName, String JavaDoc serverVersion
138         , String JavaDoc serverVendor, String JavaDoc protocols) {
139         super(objectName);
140         this.server = server;
141         this.serverName = serverName;
142         this.serverVersion = serverVersion;
143         this.serverVendor = serverVendor;
144         this.protocols = protocols;
145         initTable();
146         deployedObjects = new ArrayList JavaDoc();
147         resources = new ArrayList JavaDoc();
148         javaVMs = new ArrayList JavaDoc();
149         //Launch Timer
150
mytimer = TimerManager.getInstance().addTimerMs(this, range * 1000, new Integer JavaDoc(1), true);
151         // Get services references
152
// In case one of these services is not running, a ServiceException is thrown
153
// No exception treatement is provided, only keep reference null
154
try {
155             ejbService = (EJBService) ServiceManager.getInstance().getEjbService();
156         } catch (Exception JavaDoc e) {
157         }
158         try {
159             earService = (EarService) ServiceManager.getInstance().getEarService();
160         } catch (Exception JavaDoc e) {
161         }
162         try {
163             rarService = (ResourceService) ServiceManager.getInstance().getRarService();
164         } catch (Exception JavaDoc e) {
165         }
166         try {
167             warService = (JWebContainerService) ServiceManager.getInstance().getWebContainerService();
168         } catch (Exception JavaDoc e) {
169         }
170         try {
171             JmxService jmxService = (JmxService) ServiceManager.getInstance().getJmxService();
172             jmxServer = jmxService.getJmxServer();
173         } catch (Exception JavaDoc e) {
174         }
175         // Add myself as listner to MBeanServerNotifications. Use for this the MBeanServerDelegate ObjectName as
176
// argument in the addNotificationListener method (see JMX API for more info).
177
// Use null NotificationFilter and null handback object.
178
try {
179             ObjectName JavaDoc delegate = new ObjectName JavaDoc("JMImplementation:type=MBeanServerDelegate");
180             jmxServer.addNotificationListener(delegate, this, null, null);
181         } catch (JMException JavaDoc me) {
182             // MalformedObjectNameException should not occur if the JMX implementation is correct
183
// InstanceNotFoundException should not occur as we use MBeanServerDelegate ObjectName
184
throw new ReconfigException("ReconfigManager can't listen to MBeanServerNotifications because of exception: " + me.toString());
185         }
186     }
187
188     /**
189      * Server name
190      * @return String JOnAS server name
191      */

192     public String JavaDoc getServerName() {
193         return serverName;
194     }
195
196     /**
197      * Server version
198      * @return String JOnAS server version
199      */

200     public String JavaDoc getServerVersion() {
201         return serverVersion;
202     }
203
204     /**
205      * Server vendor
206      * @return String JOnAS server version
207      */

208     public String JavaDoc getServerVendor() {
209         return serverVendor;
210     }
211
212     /**
213          * Return the list of MBean names corresponding to the deployed J2EEModules and J2EEApplications
214      * @return java.util.ArrayList list of the deployed objects' MBean names
215      */

216     public List JavaDoc getDeployedObjects() {
217         return deployedObjects;
218     }
219
220     /**
221      * Add an object name to the <code>deployedObjects</code> list.
222      * @param objectName Object name corresponding to a J2EEDeployedObject MBean
223      */

224     public void addDeployedObject(String JavaDoc objectName) {
225         deployedObjects.add(objectName);
226     }
227
228     /**
229      * Remove an object name to the <code>deployedObjects</code> list.
230      * @param objectName Object name corresponding to a J2EEDeployedObject MBean
231      */

232     public void removeDeployedObject(String JavaDoc objectName) {
233         deployedObjects.remove(objectName);
234     }
235
236     /**
237      * Return the list of MBean names corresponding to the resources available on this server
238      * @return java.util.ArrayList list of the resources' MBean names
239      */

240     public List JavaDoc getResources() {
241         return resources;
242     }
243
244     /**
245          * Return the list of MBean names corresponding to the JVMs on which this server has running threads
246      * @return java.util.ArrayList list of the JVMs' MBean names
247      */

248     public List JavaDoc getJavaVMs() {
249         return javaVMs;
250     }
251
252     /**
253      * Add an object name to the <code>javaVMs</code> list.
254      * @param objectName Object name correspondig to a JVM MBean
255      */

256     public void addJavaVM(String JavaDoc objectName) {
257         javaVMs.add(objectName);
258     }
259
260     /**
261      * Protocols supported by this Server
262      * @return String protocols supported
263      */

264     public String JavaDoc getProtocols() {
265         return protocols;
266     }
267
268     /**
269      * Stop server (with stopping the JVM)
270      */

271     public void stop()
272         throws Exception JavaDoc {
273         server.stop();
274     }
275
276     /**
277      * run the garbage collector
278      */

279     public void runGC() {
280         Runtime.getRuntime().gc();
281     }
282
283     /**
284      * get jvm used memory
285      * @return Long - current used memory
286      */

287     public long getCurrentUsedMemory() {
288         return usedMemory();
289     }
290
291     /**
292      * get jvm total memory
293      * @return Long - current total memory
294      */

295     public long getCurrentTotalMemory() {
296         return totalMemory();
297     }
298
299     /**
300      * set range
301      * @param range range for free memory measurement
302      */

303     public void setRange(int range) {
304         if (this.range != range) {
305             synchronized (this) {
306                 if (range < 10) {
307                     throw new IllegalArgumentException JavaDoc("range could not be < 10");
308                 }
309                 this.range = range;
310                 // reset table values
311
initTable();
312                 /// change range
313
mytimer.change(this.range * 1000, new Integer JavaDoc(1));
314             }
315         }
316     }
317
318     /**
319      * get range
320      * @return Integer - range
321      */

322     public int getRange() {
323         return range;
324     }
325
326     /**
327      * Set the size of the table of measures
328      * @param sizeMeasuresTable Number of measures
329      */

330     public void setSizeTableMeasures(int sizeMeasuresTable) {
331         if (sizeMeasuresTable != this.sizeTableMeasures) {
332             synchronized (this) {
333                 if (sizeMeasuresTable <= 1) {
334                     throw new IllegalArgumentException JavaDoc("number of measures could not be <= 1");
335                 }
336                 this.sizeTableMeasures = sizeMeasuresTable;
337                 initTable();
338             }
339         }
340     }
341
342     /**
343      * Get the size of the table of measures
344      * @return Number of measures
345      */

346     public int getSizeTableMeasures() {
347         return sizeTableMeasures;
348     }
349
350     /**
351      * get the table of value
352      * @return Long[] measures table
353      */

354     public Long JavaDoc[] getTableMeasures() {
355         return tableMeasures;
356     }
357
358     // ===============================================================
359
// TimerEventListener implementation
360
// ===============================================================
361
/**
362      * The measures timeout has expired
363      * Do not synchronize this method to avoid deadlocks!
364      * @param arg Object
365      */

366     public void timeoutExpired(Object JavaDoc arg) {
367         int argvalue = ((Integer JavaDoc) arg).intValue();
368         switch (argvalue) {
369             case 1:
370
371                 //timeout expired
372
long uvalue = usedMemory();
373                 long tmvalue = totalMemory();
374
375                 // put the max total memory
376
if (tmvalue > maxtotalmemory) {
377                     maxtotalmemory = tmvalue;
378                 }
379                 for (int i = 0; i < tableMeasures.length; i++) {
380                     if (i != tableMeasures.length - 1) {
381                         tableMeasures[i] = tableMeasures[i + 1];
382                     } else {
383                         tableMeasures[i] = new Long JavaDoc(uvalue);
384                     }
385                 }
386                 break;
387             default:
388
389                 //timeoutExpired do nothing;
390
break;
391         }
392     }
393
394     /**
395      * set monitoring activation
396      * @param pActivated true is activated
397      */

398     public void setActivated(boolean pActivated) {
399         if (pActivated) {
400             if (!activated) {
401                 synchronized (this) {
402                     activated = true;
403                     initTable();
404                 }
405                 // launch timer
406
mytimer = TimerManager.getInstance().addTimerMs(this, range * 1000, (Object JavaDoc) new Integer JavaDoc(1), true);
407             }
408         } else {
409             if (activated) {
410                 synchronized (this) {
411                     activated = false;
412                     initTable();
413                     // stop timer
414
mytimer.stop();
415                     mytimer.unset();
416                 }
417             }
418         }
419     }
420
421     /**
422      * get monitoring activation
423      * @return Boolean is activated
424      */

425
426     public boolean isActivated() {
427         return activated;
428     }
429
430     /**
431      * private function for monitoring
432      * @return long used memory
433      */

434
435     private long usedMemory() {
436         long result = -1;
437         while (result < 0) {
438             result = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
439         }
440
441         return result / 1000;
442     }
443
444     /**
445      * private function for monitoring
446      * @return long total memory
447      */

448
449     private long totalMemory() {
450         return Runtime.getRuntime().totalMemory() / 1000;
451     }
452
453     /**
454      * private init table
455      */

456
457     private void initTable() {
458         tableMeasures = new Long JavaDoc[sizeTableMeasures];
459         // init max totalmemory
460
maxtotalmemory = totalMemory();
461         for (int i = 0; i < tableMeasures.length; i++) {
462             tableMeasures[i] = new Long JavaDoc(0);
463         }
464         // init the first value
465
tableMeasures[tableMeasures.length - 1] = new Long JavaDoc(usedMemory());
466     }
467
468     /**
469      * Deploy a stand-alone J2EE module packaged in a JAR file
470      * @param fileName the file name of the JAR to be be deployed.
471      * @return The ObjectName of the MBean associated to the deployed module
472      * @throws Exception Management operation could not be executed or failed
473      */

474     public String JavaDoc deployJar(String JavaDoc fileName) throws Exception JavaDoc {
475         if (ejbService != null) {
476             return ejbService.createContainer(fileName);
477         } else {
478             throw new Exception JavaDoc("EJB Container service not started");
479         }
480     }
481
482     /**
483      * Test if the specified filename is already deployed or not.
484      * @param fileName the name of the jar file.
485      * @return true if the jar is deployed, otherwise false.
486      * @throws Exception Management operation could not be executed
487      */

488     public Boolean JavaDoc isJarDeployed(String JavaDoc fileName) throws Exception JavaDoc {
489         if (ejbService != null) {
490             return ejbService.isJarDeployed(fileName);
491         } else {
492             throw new Exception JavaDoc("EJB Container service not started");
493         }
494     }
495
496     /**
497      * Uneploy a stand-alone J2EE module packaged in a JAR file
498      * @param fileName the file name of the JAR to be be undeployed.
499      * @throws Exception Management operation could not be executed or failed
500      */

501     public void unDeployJar(String JavaDoc fileName) throws Exception JavaDoc {
502         if (ejbService != null) {
503             ejbService.removeContainer(fileName);
504         } else {
505             throw new Exception JavaDoc("EJB Container service not started");
506         }
507     }
508
509     /**
510      * Test if the specified filename is already deployed or not.
511      * @param fileName the name of the war file.
512      * @return true if the war is deployed, otherwise false.
513      * @throws Exception Management operation could not be executed
514      */

515     public Boolean JavaDoc isWarDeployed(String JavaDoc fileName) throws Exception JavaDoc {
516         if (warService != null) {
517             return new Boolean JavaDoc(warService.isWarLoaded(fileName));
518         } else {
519             throw new Exception JavaDoc("WEB Container service not started");
520         }
521     }
522
523     /**
524      * Deploy a stand-alone J2EE module packaged in a WAR file
525      * @param fileName the file name of the WAR to be be deployed.
526      * @return The ObjectName of the MBean associated to the deployed module
527      * @throws Exception Management operation could not be executed or failed
528      */

529     public void deployWar(String JavaDoc fileName) throws Exception JavaDoc {
530         if (warService != null) {
531             warService.registerWarMBean(fileName);
532         } else {
533             throw new Exception JavaDoc("Web Container service not started");
534         }
535     }
536
537
538     /**
539      * Uneploy a stand-alone J2EE module packaged in a WAR file
540      * @param fileName the file name of the WAR to be be undeployed.
541      * @throws Exception Management operation could not be executed or failed
542      */

543     public void unDeployWar(String JavaDoc fileName) throws Exception JavaDoc {
544         if (warService != null) {
545             warService.unRegisterWarMBean(fileName);
546         } else {
547             throw new Exception JavaDoc("Web Container service not started");
548         }
549     }
550     /**
551      * Deploy a J2EE application packaged in a EAR file
552      * @param fileName the file name of the EAR to be be deployed.
553      * @return The ObjectName of the MBean associated to the deployed J2EE Application
554      * @throws Exception Management operation could not be executed or failed
555      */

556     public String JavaDoc deployEar(String JavaDoc fileName) throws Exception JavaDoc {
557         if (earService != null) {
558             return earService.deployEar(fileName);
559         } else {
560             throw new Exception JavaDoc("EAR Container service not started");
561         }
562     }
563
564     /**
565      * Test if the specified filename is already deployed or not. This
566      * method is defined in the EarService interface.
567      * @param fileName the name of the ear file.
568      * @return true if the ear is deployed, else false.
569      * @throws Exception Management operation could not be executed or failed
570      */

571     public Boolean JavaDoc isEarDeployed(String JavaDoc fileName) throws Exception JavaDoc {
572         if (earService != null) {
573             return earService.isEarDeployed(fileName);
574         } else {
575             throw new Exception JavaDoc("EAR Container service not started");
576         }
577     }
578
579     /**
580      * undeploy a J2EE application packaged in a EAR file
581      * @param fileName the file name of the EAR to be be undeployed.
582      * @throws Exception Management operation could not be executed or failed
583      */

584     public void unDeployEar(String JavaDoc fileName) throws Exception JavaDoc {
585         if (earService != null) {
586             earService.unDeployEar(fileName);
587         } else {
588             throw new Exception JavaDoc("EAR Container service not started");
589         }
590     }
591
592     /**
593      * Deploy a J2EE application packaged in a RAR file
594      * @param fileName the file name of the RAR to be be deployed.
595      * @return The ObjectName of the MBean associated to the deployed J2EE Application
596      * @throws Exception Management operation could not be executed or failed
597      */

598     public String JavaDoc deployRar(String JavaDoc fileName) throws Exception JavaDoc {
599         if (rarService != null) {
600             return rarService.deployRar(fileName);
601         } else {
602             throw new Exception JavaDoc("Resource service not started");
603         }
604     }
605
606     /**
607      * Test if the specified filename is already deployed or not.
608      * @param fileName the name of the rar file.
609      * @return true if the rar is deployed, else false.
610      * @throws Exception Management operation could not be executed or failed
611      */

612     public Boolean JavaDoc isRarDeployed(String JavaDoc fileName) throws Exception JavaDoc {
613         if (rarService != null) {
614             return rarService.isRarDeployed(fileName);
615         } else {
616             throw new Exception JavaDoc("Resource service not started");
617         }
618     }
619
620     /**
621      * undeploy a J2EE application packaged in a RAR file
622      * @param fileName the file name of the RAR to be be undeployed.
623      * @throws Exception Management operation could not be executed or failed
624      */

625     public void unDeployRar(String JavaDoc fileName) throws Exception JavaDoc {
626         if (rarService != null) {
627             rarService.unDeployRar(fileName);
628         } else {
629             throw new Exception JavaDoc("Resource service not started");
630         }
631     }
632
633     /**
634      * Add an object name to the <code>resources</code> list.
635      * @param pObjectName Object name correspondig to a J2EEResource MBean
636      */

637     public void addResource(String JavaDoc pObjectName) {
638         synchronized (resources) {
639             if (resources.contains(pObjectName)) {
640                 if (mgtLogger.isLoggable(BasicLevel.DEBUG)) {
641                     mgtLogger.log(BasicLevel.DEBUG
642                         , "The object name: " + pObjectName + " is already in the resources list");
643                 }
644             } else {
645                 // Add
646
resources.add(pObjectName);
647                 // Send the notification
648
AttributeAddNotification notification = new AttributeAddNotification(getObjectName()
649                     , sequenceNumber++, System.currentTimeMillis(), "", "resource"
650                     , pObjectName.toString());
651                 sendNotification(notification);
652                 if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
653                     evtLogger.log(BasicLevel.DEBUG
654                         , "AttributeAddNotification emitted: resource added to the J2EEServer: "
655                         + pObjectName.toString());
656                 }
657             }
658         }
659     }
660
661     /**
662      * Remove an object name from the <code>resources</code> list.
663      * @param pObjectName Object name correspondig to a J2EEResource MBean
664      * @return Object name to the removed J2EEResource MBean
665      */

666     public String JavaDoc removeResource(String JavaDoc pObjectName) {
667         String JavaDoc sRet = null;
668         synchronized (resources) {
669             int index = resources.indexOf(pObjectName);
670             if (index > -1) {
671                 // Remove
672
sRet = (String JavaDoc) resources.remove(index);
673                 // Send the notification
674
AttributeRemoveNotification notification = new AttributeRemoveNotification(
675                     getObjectName(), sequenceNumber++, System.currentTimeMillis(), "", "resource"
676                     , pObjectName.toString());
677                 sendNotification(notification);
678                 if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
679                     evtLogger.log(BasicLevel.DEBUG
680                         , "AttributeRemoveNotification emitted: resource removed from the J2EEServer: "
681                         + pObjectName.toString());
682                 }
683             }
684         }
685         return sRet;
686     }
687
688     /**
689      * Send a notification to the listener.
690      * @param notification The notification to send
691      */

692     public void sendNotification(Notification JavaDoc notification) {
693         // if registered listener(s)
694
if (myListener != null) {
695             NotificationListener JavaDoc listener = myListener.getListener();
696             Object JavaDoc handback = myListener.getHandback();
697             listener.handleNotification(notification, handback);
698             if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
699                 evtLogger.log(BasicLevel.DEBUG, "Notification sent");
700             }
701         }
702     }
703
704     /**
705      * Add a new listener.
706      * @param listner Listener to notify
707      * @param filter Notification filter
708      * @param handback ??
709      * @throws java.lang.IllegalArgumentException
710      */

711     public void addNotificationListener(NotificationListener JavaDoc listner, NotificationFilter JavaDoc filter
712         , java.lang.Object JavaDoc handback)
713         throws java.lang.IllegalArgumentException JavaDoc {
714         // Create new listener
715
ListenerJavaBean lmb = new ListenerJavaBean(listner, filter, handback);
716         myListener = lmb;
717         if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
718             evtLogger.log(BasicLevel.DEBUG
719                 , "Listener added for J2EEServer MBean: " + getObjectName().toString());
720             if (handback != null) {
721                 evtLogger.log(BasicLevel.DEBUG, " - with handback: " + handback.toString());
722             }
723         }
724     }
725     /**
726      * Treat the notifications emitted by the JMX server.
727      * This method determines the type of the notification and calls the specific treatement.
728      * @param notification received notification
729      * @param handback received handback object
730      */

731     public void handleNotification(Notification JavaDoc notification, java.lang.Object JavaDoc handback) {
732         if (notification instanceof MBeanServerNotification JavaDoc) {
733             // This notification is sent by the jmx server.
734
//
735
// ObjectName of the MBean that caused the notification
736
ObjectName JavaDoc causeObjectName = ((MBeanServerNotification JavaDoc) notification).getMBeanName();
737             String JavaDoc causeJ2eeType = causeObjectName.getKeyProperty("j2eeType");
738             if (causeJ2eeType != null) {
739                 // The MBean that caused the notification is a J2EEManagedObject
740
// Check for server name being the current server name
741
String JavaDoc serverName = causeObjectName.getKeyProperty("J2EEServer");
742                 if (serverName != null) {
743                     if (!serverName.equals(getServerName())) {
744                         return;
745                     }
746                 } else {
747                     return;
748                 }
749                 // Check for J2EEResource MBeans
750
boolean j2eeResource = false;
751                 if (causeJ2eeType.equals("JavaMailResource")
752                     || causeJ2eeType.equals("JNDIResource")
753                     || causeJ2eeType.equals("JDBCResource")
754                     || causeJ2eeType.equals("JMSResource")
755                     || causeJ2eeType.equals("JTAResource")
756                     || causeJ2eeType.equals("JCAResource")
757                     || causeJ2eeType.equals("RMIIIOPResource")
758                     || causeJ2eeType.equals("URLResource")) {
759                     j2eeResource = true;
760                 }
761                 if (j2eeResource) {
762                     String JavaDoc notificationType = notification.getType();
763                     handleResourceNotification(causeObjectName, notificationType);
764                 }
765                 // Check for J2EEDeployedObjects
766
boolean j2eeDeployed = false;
767                 if (causeJ2eeType.equals("J2EEApplication")
768                     || causeJ2eeType.equals("AppClientModule")
769                     || causeJ2eeType.equals("EJBModule")
770                     || causeJ2eeType.equals("WebModule")
771                     || causeJ2eeType.equals("ResourceAdapterModule")) {
772                     j2eeDeployed = true;
773                 }
774                 if (j2eeDeployed) {
775                     String JavaDoc notificationType = notification.getType();
776                     handleDeployedNotification(causeObjectName, notificationType);
777                 }
778             }
779         }
780     }
781     /**
782      * Treat the registration/unregistration of J2EEResources.
783      * @param resourceObjectName object name of the J2EEResource MBean that caused the notification
784      * @param notificationType may be a REGISTRATION_NOTIFICATION or an UNREGISTRATION_NOTIFICATION
785      */

786     private void handleResourceNotification(ObjectName JavaDoc resourceObjectName, String JavaDoc notificationType) {
787         if (notificationType.equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
788             addResource(resourceObjectName.toString());
789             if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
790                 evtLogger.log(BasicLevel.DEBUG, "Resource " + resourceObjectName.toString() + " added to J2EEServer " + getServerName());
791             }
792         } else if (notificationType.equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
793             removeResource(resourceObjectName.toString());
794             if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
795                 evtLogger.log(BasicLevel.DEBUG, "Resource " + resourceObjectName.toString() + " removed from J2EEServer " + getServerName());
796             }
797         }
798     }
799     /**
800      * Treat the registration/unregistration of J2EEDeployedObjects.
801      * @param deployedObjectName object name of the J2EEDeployedObject MBean that caused the notification
802      * @param notificationType may be a REGISTRATION_NOTIFICATION or an UNREGISTRATION_NOTIFICATION
803      */

804     private void handleDeployedNotification(ObjectName JavaDoc deployedObjectName, String JavaDoc notificationType) {
805         if (notificationType.equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
806             addDeployedObject(deployedObjectName.toString());
807             if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
808                 evtLogger.log(BasicLevel.DEBUG, "J2EEDeployedObject " + deployedObjectName.toString() + " added to J2EEServer " + getServerName());
809             }
810         } else if (notificationType.equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
811             removeDeployedObject(deployedObjectName.toString());
812             if (evtLogger.isLoggable(BasicLevel.DEBUG)) {
813                 evtLogger.log(BasicLevel.DEBUG, "J2EEDeployedObject " + deployedObjectName.toString() + " removed from J2EEServer " + getServerName());
814             }
815         }
816     }
817 }
818
Popular Tags