KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > admin > business > MBeanTriggerImpl


1 /*
2  * SimpleCacheAdmin
3  *
4  * Business Implementation
5  *
6  */

7
8 package org.enhydra.admin.business;
9
10 import org.enhydra.admin.spec.business.*;
11 import javax.management.*;
12 import java.util.*;
13
14 public class MBeanTriggerImpl implements MBeanTrigger {
15         
16         private MBeanServer mBeanServer = null;
17             
18     public String JavaDoc refreshCache(){
19                     String JavaDoc message = "Caches are successfully refreshed!";
20                     try {
21                    ObjectName onameEnhydra = new ObjectName("EnhydraApplications:type=DatabaseManager,*");
22                    Set enhydraMBeans= getMBeanServer().queryNames(onameEnhydra,null);
23                    Object JavaDoc[] oi=enhydraMBeans.toArray();
24                    
25                    for (int i=0;i<oi.length;i++){
26                         getMBeanServer().invoke((ObjectName)oi[i], "Refresh_Cache", null, null);
27                    }
28             } catch (Exception JavaDoc ex){
29                 ex.printStackTrace();
30                 message = "Encountered some problems during cache refreshing!";
31             }
32             return message;
33     }
34     
35     public String JavaDoc refreshStatistic(){
36                     String JavaDoc message = "Cache statistics are successfully refreshed!";
37                     try {
38                    ObjectName onameEnhydra = new ObjectName("EnhydraApplications:type=DatabaseManager,*");
39                    Set enhydraMBeans= getMBeanServer().queryNames(onameEnhydra,null);
40                    Object JavaDoc[] oi=enhydraMBeans.toArray();
41                    
42                    for (int i=0;i<oi.length;i++){
43                         getMBeanServer().invoke((ObjectName)oi[i], "Refresh_Statistics", null, null);
44                    }
45             } catch (Exception JavaDoc ex){
46                 ex.printStackTrace();
47                 message = "Encountered some problems during cache statistic refreshing!";
48             }
49             return message;
50     }
51     
52     public String JavaDoc enableCache(){
53                     String JavaDoc message = "Caches are successfully enabled!";
54                     try {
55                    ObjectName onameEnhydra = new ObjectName("EnhydraApplications:type=DatabaseManager,*");
56                    Set enhydraMBeans= getMBeanServer().queryNames(onameEnhydra,null);
57                    Object JavaDoc[] oi=enhydraMBeans.toArray();
58                    
59                    for (int i=0;i<oi.length;i++){
60                         getMBeanServer().invoke((ObjectName)oi[i], "Enable_Cache", null, null);
61                    }
62             } catch (Exception JavaDoc ex){
63                 ex.printStackTrace();
64                 message = "Encountered some problems during cache enabling!";
65             }
66             return message;
67     }
68     
69     public String JavaDoc disableCache(){
70                     String JavaDoc message = "Caches are successfully disabled!";
71                     try {
72                    ObjectName onameEnhydra = new ObjectName("EnhydraApplications:type=DatabaseManager,*");
73                    Set enhydraMBeans= getMBeanServer().queryNames(onameEnhydra,null);
74                    Object JavaDoc[] oi=enhydraMBeans.toArray();
75                    
76                    for (int i=0;i<oi.length;i++){
77                         getMBeanServer().invoke((ObjectName)oi[i], "Disable_Cache", null, null);
78                    }
79             } catch (Exception JavaDoc ex){
80                 ex.printStackTrace();
81                 message = "Encountered some problems during cache disabling!";
82             }
83             return message;
84     }
85     
86     public String JavaDoc toggleCache(){
87                     String JavaDoc message = "Caches are successfully toggled!";
88                     try {
89                    ObjectName onameEnhydra = new ObjectName("EnhydraApplications:type=DatabaseManager,*");
90                    Set enhydraMBeans= getMBeanServer().queryNames(onameEnhydra,null);
91                    Object JavaDoc[] oi=enhydraMBeans.toArray();
92                    
93                    for (int i=0;i<oi.length;i++){
94                         getMBeanServer().invoke((ObjectName)oi[i], "Toggle_EnableOrDisable_Cache", null, null);
95                    }
96             } catch (Exception JavaDoc ex){
97                 ex.printStackTrace();
98                 message = "Encountered some problems during cache toggling!";
99             }
100             return message;
101     }
102     
103     private MBeanServer getMBeanServer(){
104              if (mBeanServer == null){
105                  try {
106                       ArrayList server = MBeanServerFactory.findMBeanServer(null);
107                       if (server == null) {
108                         return null;
109                       }
110                       else {
111                         mBeanServer = (MBeanServer) server.get(0);
112                       }
113                    } catch (Exception JavaDoc e) {
114                       e.printStackTrace();
115                    }
116                }
117                return mBeanServer;
118         }
119
120
121 }
122
Popular Tags