KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > model > Resource


1 /*
2
3  * EJTools, the Enterprise Java Tools
4
5  *
6
7  * Distributable under LGPL license.
8
9  * See terms of license at www.gnu.org.
10
11  */

12
13 package org.ejtools.jmx.browser.model;
14
15
16
17 import java.awt.Component JavaDoc;
18
19 import java.beans.beancontext.BeanContextServiceAvailableEvent JavaDoc;
20
21 import java.beans.beancontext.BeanContextServiceRevokedEvent JavaDoc;
22
23 import java.beans.beancontext.BeanContextServices JavaDoc;
24
25 import java.io.PrintWriter JavaDoc;
26
27 import java.io.StringWriter JavaDoc;
28
29 import java.util.Hashtable JavaDoc;
30
31 import java.util.Iterator JavaDoc;
32
33
34
35 import javax.management.Attribute JavaDoc;
36
37 import javax.management.AttributeList JavaDoc;
38
39 import javax.management.MBeanInfo JavaDoc;
40
41 import javax.management.MBeanNotificationInfo JavaDoc;
42
43 import javax.management.ObjectInstance JavaDoc;
44
45 import javax.management.ObjectName JavaDoc;
46
47
48
49 import org.apache.log4j.Logger;
50
51 import org.ejtools.adwt.service.ConsoleService;
52
53 import org.ejtools.graph.service.GraphConsumer;
54
55 import org.ejtools.graph.service.GraphConsumerMediator;
56
57 import org.ejtools.graph.service.GraphProducer;
58
59 import org.ejtools.graph.service.GraphService;
60
61 import org.ejtools.jmx.MBeanAccessor;
62
63 import org.ejtools.jmx.browser.model.service.CacheService;
64
65 import org.ejtools.jmx.browser.model.service.ConnectionService;
66
67 import org.ejtools.jmx.browser.model.service.NotificationService;
68
69 import org.ejtools.jmx.browser.ui.MBeanCustomizer;
70
71 import org.ejtools.util.ClassTools;
72
73
74
75 /**
76
77  * Description of the Class
78
79  *
80
81  * @author letiemble
82
83  * @version $Revision: 1.6 $
84
85  * @created 13 d?cembre 2001
86
87  * @todo Javadoc to complete
88
89  * @javabean:class displayName="JMX ManagedObject"
90
91  * shortDescription="JMX ManagedObject"
92
93  * @javabean:icons color16="/toolbarButtonGraphics/development/Bean16.gif"
94
95  * @javabean:property name="name"
96
97  * class="java.lang.String"
98
99  * displayName="Name"
100
101  * shortDescription="ManagedObject name"
102
103  * @javabean:property name="className"
104
105  * class="java.lang.String"
106
107  * displayName="Class Name"
108
109  * shortDescription="Class Name"
110
111  * @javabean:property name="domain"
112
113  * class="java.lang.String"
114
115  * displayName="Domain"
116
117  * shortDescription="Domain name"
118
119  * @javabean:property name="description"
120
121  * class="java.lang.String"
122
123  * displayName="Description"
124
125  * shortDescription="Description"
126
127  * @javabean:property name="registeredForNotifications"
128
129  * class="boolean"
130
131  * displayName="Registered for Notifications"
132
133  * shortDescription="Registered for Notifications"
134
135  * expert="true"
136
137  * @javabean:property name="broadcaster"
138
139  * class="boolean"
140
141  * displayName="Broadcaster of Notifications"
142
143  * shortDescription="Broadcaster of Notifications"
144
145  * expert="true"
146
147  */

148
149 public class Resource extends Node implements MBeanAccessor, GraphConsumerMediator
150
151 {
152
153    /** Description of the Field */
154
155    protected String JavaDoc canonicalName;
156
157    /** Description of the Field */
158
159    protected String JavaDoc description;
160
161    /** Description of the Field */
162
163    protected String JavaDoc domain;
164
165    /** Description of the Field */
166
167    protected transient Hashtable JavaDoc graphProducers = new Hashtable JavaDoc();
168
169    /** Description of the Field */
170
171    protected transient MBeanInfo JavaDoc info;
172
173    /** Description of the Field */
174
175    protected transient ObjectInstance JavaDoc objectInstance;
176
177    /** Description of the Field */
178
179    protected transient ObjectName JavaDoc objectName;
180
181    /** Description of the Field */
182
183    private static Logger logger = Logger.getLogger(Resource.class);
184
185
186
187
188
189    /** Constructor for the ManagedObject object */
190
191    public Resource()
192
193    {
194
195       super();
196
197    }
198
199
200
201
202
203    /** Description of the Method */
204
205    public void clear()
206
207    {
208
209       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
210
211       this.releaseServices(context);
212
213
214
215       super.clear();
216
217    }
218
219
220
221
222
223    /**
224
225     * Getter for the attribute attribute
226
227     *
228
229     * @param attribute Description of the Parameter
230
231     * @return The attribute value
232
233     * @exception Exception Description of the Exception
234
235     */

236
237    public Object JavaDoc getAttribute(String JavaDoc attribute)
238
239       throws Exception JavaDoc
240
241    {
242
243       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
244
245       Object JavaDoc result = null;
246
247
248
249       if (context.hasService(ConnectionService.class))
250
251       {
252
253          try
254
255          {
256
257             ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this);
258
259             result = service.getMBeanServer().getAttribute(objectName, attribute);
260
261             context.releaseService(this, this, ConnectionService.class);
262
263          }
264
265          catch (Exception JavaDoc e)
266
267          {
268
269             logger.error("Error while getting attribute", e);
270
271             throw e;
272
273          }
274
275       }
276
277       return result;
278
279    }
280
281
282
283
284
285    /**
286
287     * @param as Description of the Parameter
288
289     * @return The attributes value
290
291     * @exception Exception Description of the Exception
292
293     */

294
295    public AttributeList JavaDoc getAttributes(String JavaDoc[] as)
296
297       throws Exception JavaDoc
298
299    {
300
301       return null;
302
303    }
304
305
306
307
308
309    /**
310
311     * Gets the canonicalName attribute of the ManagedObject object
312
313     *
314
315     * @return The canonicalName value
316
317     */

318
319    public String JavaDoc getCanonicalName()
320
321    {
322
323       return this.canonicalName;
324
325    }
326
327
328
329
330
331    /**
332
333     * Gets the component attribute of the ManagedObject object
334
335     *
336
337     * @return The component value
338
339     * @author laurent
340
341     * @created 23 mars 2002
342
343     */

344
345    public Component JavaDoc getComponent()
346
347    {
348
349       if (c == null)
350
351       {
352
353          c = new MBeanCustomizer(this);
354
355       }
356
357       return (Component JavaDoc) c;
358
359    }
360
361
362
363
364
365    /**
366
367     * Gets the description attribute of the ManagedObject object
368
369     *
370
371     * @return The description value
372
373     */

374
375    public String JavaDoc getDescription()
376
377    {
378
379       return this.description;
380
381    }
382
383
384
385
386
387    /**
388
389     * Gets the domain attribute of the ManagedObject object
390
391     *
392
393     * @return The domain value
394
395     */

396
397    public String JavaDoc getDomain()
398
399    {
400
401       return this.domain;
402
403    }
404
405
406
407
408
409    /**
410
411     * Gets the graphConsumers attribute of the ManagedObject object
412
413     *
414
415     * @return The graphConsumers value
416
417     */

418
419    public GraphConsumer[] getGraphConsumers()
420
421    {
422
423       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
424
425       GraphConsumer[] result = new GraphConsumer[0];
426
427
428
429       if (context.hasService(GraphService.class))
430
431       {
432
433          try
434
435          {
436
437             GraphService service = (GraphService) context.getService(this, this, GraphService.class, this, this);
438
439             result = service.getGraphConsumers();
440
441             context.releaseService(this, this, GraphService.class);
442
443          }
444
445          catch (Exception JavaDoc e)
446
447          {
448
449             logger.error("Error while using GraphService", e);
450
451          }
452
453       }
454
455       return result;
456
457    }
458
459
460
461
462
463    /**
464
465     * Gets the graphProducers attribute of the Resource object
466
467     *
468
469     * @return The graphProducers value
470
471     */

472
473    public Hashtable JavaDoc getGraphProducers()
474
475    {
476
477       return this.graphProducers;
478
479    }
480
481
482
483
484
485    /**
486
487     * Gets the mBeanInfo attribute of the ManagedObject object
488
489     *
490
491     * @return The mBeanInfo value
492
493     */

494
495    public MBeanInfo JavaDoc getMBeanInfo()
496
497    {
498
499       if (this.info == null)
500
501       {
502
503          BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
504
505          if (context.hasService(ConnectionService.class))
506
507          {
508
509             try
510
511             {
512
513                ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this);
514
515                this.info = service.getMBeanServer().getMBeanInfo(this.objectName);
516
517                if (this.info == null)
518
519                {
520
521                   logger.warn("MBeanInfo for " + this.objectName + " is null");
522
523                }
524
525                context.releaseService(this, this, ConnectionService.class);
526
527             }
528
529             catch (Exception JavaDoc e)
530
531             {
532
533                logger.error("Error during utilisation of service ConnectionService", e);
534
535             }
536
537          }
538
539       }
540
541       return this.info;
542
543    }
544
545
546
547
548
549    /**
550
551     * Gets the instance attribute of the ManagedObject object
552
553     *
554
555     * @return The instance value
556
557     * @exception Exception Description of the Exception
558
559     */

560
561    public ObjectInstance JavaDoc getObjectInstance()
562
563       throws Exception JavaDoc
564
565    {
566
567       return this.objectInstance;
568
569    }
570
571
572
573
574
575    /**
576
577     * Gets the objectName attribute of the ManagedObject object
578
579     *
580
581     * @return The objectName value
582
583     */

584
585    public ObjectName JavaDoc getObjectName()
586
587    {
588
589       return this.objectName;
590
591    }
592
593
594
595
596
597    /**
598
599     * Description of the Method
600
601     *
602
603     * @param action Description of the Parameter
604
605     * @param params Description of the Parameter
606
607     * @param signatures Description of the Parameter
608
609     * @return Description of the Return Value
610
611     * @exception Exception Description of the Exception
612
613     */

614
615    public Object JavaDoc invoke(String JavaDoc action, Object JavaDoc[] params, String JavaDoc[] signatures)
616
617       throws Exception JavaDoc
618
619    {
620
621       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
622
623       Object JavaDoc result = null;
624
625
626
627       if (context.hasService(ConnectionService.class))
628
629       {
630
631          try
632
633          {
634
635             this.log("Invoking " + action + "...");
636
637
638
639             ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this);
640
641             result = service.getMBeanServer().invoke(objectName, action, params, signatures);
642
643             context.releaseService(this, this, ConnectionService.class);
644
645
646
647             this.log("Result :");
648
649             this.log("" + result);
650
651          }
652
653          catch (Exception JavaDoc e)
654
655          {
656
657             this.log(e);
658
659             logger.error("Error while invoking method", e);
660
661             throw e;
662
663          }
664
665       }
666
667       this.log("");
668
669       return result;
670
671    }
672
673
674
675
676
677    /**
678
679     * Gets the broadcaster attribute of the ManagedObject object
680
681     *
682
683     * @return The broadcaster value
684
685     * @exception Exception Description of the Exception
686
687     */

688
689    public boolean isBroadcaster()
690
691       throws Exception JavaDoc
692
693    {
694
695       // Test if the MBean send notification
696

697       MBeanNotificationInfo JavaDoc[] ni = this.getMBeanInfo().getNotifications();
698
699
700
701       if (ni != null)
702
703       {
704
705          return (ni.length > 0);
706
707       }
708
709       return false;
710
711    }
712
713
714
715
716
717    /**
718
719     * @param s Description of the Parameter
720
721     * @return The instanceOf value
722
723     * @exception Exception Description of the Exception
724
725     */

726
727    public boolean isInstanceOf(String JavaDoc s)
728
729       throws Exception JavaDoc
730
731    {
732
733       return false;
734
735    }
736
737
738
739
740
741    /**
742
743     * Gets the registered attribute of the ManagedObject object
744
745     *
746
747     * @return The registered value
748
749     * @exception Exception Description of the Exception
750
751     */

752
753    public boolean isRegistered()
754
755       throws Exception JavaDoc
756
757    {
758
759       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
760
761       boolean result = false;
762
763
764
765       if (context.hasService(ConnectionService.class))
766
767       {
768
769          try
770
771          {
772
773             ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this);
774
775             result = service.getMBeanServer().isRegistered(this.objectName);
776
777             context.releaseService(this, this, ConnectionService.class);
778
779          }
780
781          catch (Exception JavaDoc e)
782
783          {
784
785             logger.error("Error while testing registration", e);
786
787             throw e;
788
789          }
790
791       }
792
793       return result;
794
795    }
796
797
798
799
800
801    /**
802
803     * Gets the registeredForNotifications attribute of the ManagedObject object
804
805     *
806
807     * @return The registeredForNotifications value
808
809     * @exception Exception Description of the Exception
810
811     */

812
813    public boolean isRegisteredForNotifications()
814
815       throws Exception JavaDoc
816
817    {
818
819       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
820
821       boolean result = false;
822
823
824
825       if (context.hasService(NotificationService.class))
826
827       {
828
829          try
830
831          {
832
833             NotificationService service = (NotificationService) context.getService(this, this, NotificationService.class, this, this);
834
835             result = service.hasObjectName(objectName);
836
837             context.releaseService(this, this, NotificationService.class);
838
839          }
840
841          catch (Exception JavaDoc e)
842
843          {
844
845             logger.error("Error while using NotificationService", e);
846
847             throw e;
848
849          }
850
851       }
852
853       return result;
854
855    }
856
857
858
859
860
861    /**
862
863     * Description of the Method
864
865     *
866
867     * @param text Description of the Parameter
868
869     */

870
871    public void log(String JavaDoc text)
872
873    {
874
875       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
876
877
878
879       if (context.hasService(ConsoleService.class))
880
881       {
882
883          try
884
885          {
886
887             ConsoleService service = (ConsoleService) context.getService(this, this, ConsoleService.class, this, this);
888
889             service.append(text);
890
891             context.releaseService(this, this, ConsoleService.class);
892
893          }
894
895          catch (Exception JavaDoc e)
896
897          {
898
899             logger.error("Error while logging", e);
900
901          }
902
903       }
904
905    }
906
907
908
909
910
911    /**
912
913     * Description of the Method
914
915     *
916
917     * @param t Description of the Parameter
918
919     */

920
921    public void log(Throwable JavaDoc t)
922
923    {
924
925       StringWriter JavaDoc w = new StringWriter JavaDoc();
926
927       PrintWriter JavaDoc pw = new PrintWriter JavaDoc(w);
928
929       t.printStackTrace(pw);
930
931       pw.close();
932
933       this.log("Exception occured :");
934
935       this.log(w.toString());
936
937    }
938
939
940
941
942
943    /**
944
945     * Description of the Method
946
947     *
948
949     * @param attribute Description of the Parameter
950
951     * @param consumer Description of the Parameter
952
953     */

954
955    public void registerForGraph(GraphConsumer consumer, String JavaDoc attribute)
956
957    {
958
959       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
960
961
962
963       if (context.hasService(GraphService.class))
964
965       {
966
967          try
968
969          {
970
971             GraphService service = (GraphService) context.getService(this, this, GraphService.class, this, this);
972
973             final String JavaDoc attrName = attribute;
974
975             GraphProducer producer = (GraphProducer) this.graphProducers.get(attribute);
976
977             if (producer == null)
978
979             {
980
981                producer =
982
983                   new GraphProducer()
984
985                   {
986
987                      /**
988
989                       * @return The graphProducerId value
990
991                       */

992
993                      public String JavaDoc getGraphProducerId()
994
995                      {
996
997                         return Resource.this.getCanonicalName() + " : " + attrName;
998
999                      }
1000
1001
1002
1003
1004
1005                     /**
1006
1007                      * @return Description of the Return Value
1008
1009                      */

1010
1011                     public double produce()
1012
1013                     {
1014
1015                        try
1016
1017                        {
1018
1019                           Object JavaDoc o = getAttribute(attrName);
1020
1021                           return ClassTools.getValue(o);
1022
1023                        }
1024
1025                        catch (Exception JavaDoc e)
1026
1027                        {
1028
1029                           logger.warn("Cannot produce a numerical value for " + this.getGraphProducerId());
1030
1031                        }
1032
1033                        return 0;
1034
1035                     }
1036
1037                  };
1038
1039               this.graphProducers.put(attribute, producer);
1040
1041            }
1042
1043            service.addGraphProducer(consumer, producer);
1044
1045            context.releaseService(this, this, GraphService.class);
1046
1047         }
1048
1049         catch (Exception JavaDoc e)
1050
1051         {
1052
1053            logger.error("Error while using GraphService", e);
1054
1055         }
1056
1057      }
1058
1059   }
1060
1061
1062
1063
1064
1065
1066
1067   /**
1068
1069    * Description of the Method
1070
1071    *
1072
1073    * @exception Exception Description of the Exception
1074
1075    */

1076
1077   public void registerForNotifications()
1078
1079      throws Exception JavaDoc
1080
1081   {
1082
1083      BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
1084
1085
1086
1087      if (this.isBroadcaster() && !this.isRegisteredForNotifications())
1088
1089      {
1090
1091         if (context.hasService(NotificationService.class))
1092
1093         {
1094
1095            try
1096
1097            {
1098
1099               NotificationService service = (NotificationService) context.getService(this, this, NotificationService.class, this, this);
1100
1101               service.addObjectName(objectName);
1102
1103               context.releaseService(this, this, NotificationService.class);
1104
1105               logger.debug("ManagedObject " + objectName + " added for broadcasting");
1106
1107            }
1108
1109            catch (Exception JavaDoc e)
1110
1111            {
1112
1113               logger.error("Error while using NotificationService", e);
1114
1115               throw e;
1116
1117            }
1118
1119         }
1120
1121      }
1122
1123   }
1124
1125
1126
1127
1128
1129   /**
1130
1131    * Description of the Method
1132
1133    *
1134
1135    * @param bcsae Description of the Parameter
1136
1137    */

1138
1139   public void serviceAvailable(BeanContextServiceAvailableEvent JavaDoc bcsae)
1140
1141   {
1142
1143      if (CacheService.class.equals(bcsae.getServiceClass()))
1144
1145      {
1146
1147         BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
1148
1149         if (context != null)
1150
1151         {
1152
1153            this.useServices(context);
1154
1155         }
1156
1157      }
1158
1159      super.serviceAvailable(bcsae);
1160
1161   }
1162
1163
1164
1165
1166
1167
1168
1169   /**
1170
1171    * Description of the Method
1172
1173    *
1174
1175    * @param bcsre Description of the Parameter
1176
1177    */

1178
1179   public void serviceRevoked(BeanContextServiceRevokedEvent JavaDoc bcsre)
1180
1181   {
1182
1183      if (NotificationService.class.equals(bcsre.getServiceClass()))
1184
1185      {
1186
1187         try
1188
1189         {
1190
1191            this.unregisterForNotifications();
1192
1193         }
1194
1195         catch (Exception JavaDoc e)
1196
1197         {
1198
1199         }
1200
1201      }
1202
1203      if (CacheService.class.equals(bcsre.getServiceClass()))
1204
1205      {
1206
1207         BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
1208
1209         if (context != null)
1210
1211         {
1212
1213            this.releaseServices(context);
1214
1215         }
1216
1217      }
1218
1219      super.serviceRevoked(bcsre);
1220
1221   }
1222
1223
1224
1225
1226
1227   /**
1228
1229    * Getter for the attribute attribute
1230
1231    *
1232
1233    * @param attribute The new attribute value
1234
1235    * @exception Exception Description of the Exception
1236
1237    */

1238
1239   public void setAttribute(Attribute JavaDoc attribute)
1240
1241      throws Exception JavaDoc
1242
1243   {
1244
1245      BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
1246
1247
1248
1249      if (context.hasService(ConnectionService.class))
1250
1251      {
1252
1253         try
1254
1255         {
1256
1257            ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this);
1258
1259            logger.debug("setAttribute(" + objectName + "," + attribute + ")");
1260
1261            service.getMBeanServer().setAttribute(objectName, attribute);
1262
1263            context.releaseService(this, this, ConnectionService.class);
1264
1265         }
1266
1267         catch (Exception JavaDoc e)
1268
1269         {
1270
1271            logger.error("Error while setting attribute", e);
1272
1273            throw e;
1274
1275         }
1276
1277      }
1278
1279   }
1280
1281
1282
1283
1284
1285   /**
1286
1287    * Sets the attributes attribute of the ManagedObject object
1288
1289    *
1290
1291    * @param list The new attributes value
1292
1293    * @return Description of the Return Value
1294
1295    * @exception Exception Description of the Exception
1296
1297    */

1298
1299   public AttributeList JavaDoc setAttributes(AttributeList JavaDoc list)
1300
1301      throws Exception JavaDoc
1302
1303   {
1304
1305      BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
1306
1307      AttributeList JavaDoc result = null;
1308
1309
1310
1311      if (context.hasService(ConnectionService.class))
1312
1313      {
1314
1315         try
1316
1317         {
1318
1319            this.unregisterForNotifications();
1320
1321
1322
1323            ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this);
1324
1325            result = service.getMBeanServer().setAttributes(this.objectName, list);
1326
1327            context.releaseService(this, this, ConnectionService.class);
1328
1329         }
1330
1331         catch (Exception JavaDoc e)
1332
1333         {
1334
1335            logger.error("Error while setting attributes", e);
1336
1337            throw e;
1338
1339         }
1340
1341      }
1342
1343      return result;
1344
1345   }
1346
1347
1348
1349
1350
1351
1352
1353   /**
1354
1355    * Sets the reference attribute of the ManagedObject object
1356
1357    *
1358
1359    * @param instance The new reference value
1360
1361    * @exception Exception Description of the Exception
1362
1363    */

1364
1365   public void setReference(ObjectInstance JavaDoc instance)
1366
1367      throws Exception JavaDoc
1368
1369   {
1370
1371      this.objectInstance = instance;
1372
1373      this.objectName = this.objectInstance.getObjectName();
1374
1375      this.name = this.objectName.getCanonicalName();
1376
1377      this.canonicalName = this.objectName.getCanonicalName();
1378
1379      this.className = this.objectInstance.getClassName();
1380
1381      this.domain = this.objectName.getDomain();
1382
1383   }
1384
1385
1386
1387
1388
1389   /** Description of the Method */
1390
1391   public void unregisterForGraph()
1392
1393   {
1394
1395      BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
1396
1397
1398
1399      if (context.hasService(GraphService.class))
1400
1401      {
1402
1403         try
1404
1405         {
1406
1407            GraphService service = (GraphService) context.getService(this, this, GraphService.class, this, this);
1408
1409            for (Iterator JavaDoc iterator = this.graphProducers.keySet().iterator(); iterator.hasNext(); )
1410
1411            {
1412
1413               String JavaDoc attribute = (String JavaDoc) iterator.next();
1414
1415               GraphProducer producer = (GraphProducer) this.graphProducers.get(attribute);
1416
1417               service.removeGraphProducer(producer);
1418
1419            }
1420
1421            context.releaseService(this, this, GraphService.class);
1422
1423         }
1424
1425         catch (Exception JavaDoc e)
1426
1427         {
1428
1429            logger.error("Error while using GraphService", e);
1430
1431         }
1432
1433      }
1434
1435   }
1436
1437
1438
1439
1440
1441   /**
1442
1443    * Description of the Method
1444
1445    *
1446
1447    * @exception Exception Description of the Exception
1448
1449    */

1450
1451   public void unregisterForNotifications()
1452
1453      throws Exception JavaDoc
1454
1455   {
1456
1457      BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
1458
1459
1460
1461      if (this.isRegisteredForNotifications())
1462
1463      {
1464
1465         if (context.hasService(NotificationService.class))
1466
1467         {
1468
1469            try
1470
1471            {
1472
1473               NotificationService service = (NotificationService) context.getService(this, this, NotificationService.class, this, this);
1474
1475               service.removeObjectName(this.objectName);
1476
1477               logger.debug("ManagedObject " + objectName + " removed for broadcasting");
1478
1479            }
1480
1481            catch (Exception JavaDoc e)
1482
1483            {
1484
1485               logger.error("Error while using NotificationService", e);
1486
1487               throw e;
1488
1489            }
1490
1491            finally
1492
1493            {
1494
1495               context.releaseService(this, this, NotificationService.class);
1496
1497            }
1498
1499         }
1500
1501      }
1502
1503   }
1504
1505
1506
1507
1508
1509   /**
1510
1511    * Description of the Method
1512
1513    *
1514
1515    * @exception Exception Description of the Exception
1516
1517    */

1518
1519   public void unregisterMBean()
1520
1521      throws Exception JavaDoc
1522
1523   {
1524
1525      BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
1526
1527
1528
1529      if (context.hasService(ConnectionService.class))
1530
1531      {
1532
1533         try
1534
1535         {
1536
1537            ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this);
1538
1539            service.getMBeanServer().unregisterMBean(this.objectName);
1540
1541            context.releaseService(this, this, ConnectionService.class);
1542
1543         }
1544
1545         catch (Exception JavaDoc e)
1546
1547         {
1548
1549            logger.error("Error while unregistering", e);
1550
1551            throw e;
1552
1553         }
1554
1555      }
1556
1557   }
1558
1559
1560
1561
1562
1563   /** Description of the Method */
1564
1565   protected void initializeBeanContextResources()
1566
1567   {
1568
1569      super.initializeBeanContextResources();
1570
1571
1572
1573      BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
1574
1575      this.useServices(context);
1576
1577   }
1578
1579
1580
1581
1582
1583
1584
1585   /** Description of the Method */
1586
1587   protected void releaseBeanContextResources()
1588
1589   {
1590
1591      super.releaseBeanContextResources();
1592
1593
1594
1595      BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
1596
1597      this.releaseServices(context);
1598
1599   }
1600
1601
1602
1603
1604
1605   /**
1606
1607    * Description of the Method
1608
1609    *
1610
1611    * @param context Description of the Parameter
1612
1613    */

1614
1615   protected void releaseServices(BeanContextServices JavaDoc context)
1616
1617   {
1618
1619      if (context.hasService(CacheService.class))
1620
1621      {
1622
1623
1624
1625// logger.debug("Using service CacheService...");
1626

1627         try
1628
1629         {
1630
1631            this.unregisterForNotifications();
1632
1633            this.unregisterForGraph();
1634
1635
1636
1637            CacheService service = (CacheService) context.getService(this, this, CacheService.class, this, this);
1638
1639            service.remove(CacheService.RESOURCE_TYPE, this.getCanonicalName());
1640
1641            context.releaseService(this, this, CacheService.class);
1642
1643         }
1644
1645         catch (Exception JavaDoc e)
1646
1647         {
1648
1649            logger.error("Error during utilisation of service CacheService", e);
1650
1651         }
1652
1653      }
1654
1655   }
1656
1657
1658
1659
1660
1661   /**
1662
1663    * Description of the Method
1664
1665    *
1666
1667    * @param context Description of the Parameter
1668
1669    */

1670
1671   protected void useServices(BeanContextServices JavaDoc context)
1672
1673   {
1674
1675      if (context.hasService(CacheService.class))
1676
1677      {
1678
1679// logger.debug("Using service CacheService...");
1680

1681         try
1682
1683         {
1684
1685            CacheService service = (CacheService) context.getService(this, this, CacheService.class, this, this);
1686
1687            service.add(CacheService.RESOURCE_TYPE, this.getCanonicalName(), this);
1688
1689            context.releaseService(this, this, CacheService.class);
1690
1691         }
1692
1693         catch (Exception JavaDoc e)
1694
1695         {
1696
1697            logger.error("Error during utilisation of service CacheService", e);
1698
1699         }
1700
1701      }
1702
1703   }
1704
1705}
1706
1707
Popular Tags