1 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 refreshCache(){ 19 String message = "Caches are successfully refreshed!"; 20 try { 21 ObjectName onameEnhydra = new ObjectName("EnhydraApplications:type=DatabaseManager,*"); 22 Set enhydraMBeans= getMBeanServer().queryNames(onameEnhydra,null); 23 Object [] 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 ex){ 29 ex.printStackTrace(); 30 message = "Encountered some problems during cache refreshing!"; 31 } 32 return message; 33 } 34 35 public String refreshStatistic(){ 36 String 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 [] 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 ex){ 46 ex.printStackTrace(); 47 message = "Encountered some problems during cache statistic refreshing!"; 48 } 49 return message; 50 } 51 52 public String enableCache(){ 53 String message = "Caches are successfully enabled!"; 54 try { 55 ObjectName onameEnhydra = new ObjectName("EnhydraApplications:type=DatabaseManager,*"); 56 Set enhydraMBeans= getMBeanServer().queryNames(onameEnhydra,null); 57 Object [] 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 ex){ 63 ex.printStackTrace(); 64 message = "Encountered some problems during cache enabling!"; 65 } 66 return message; 67 } 68 69 public String disableCache(){ 70 String message = "Caches are successfully disabled!"; 71 try { 72 ObjectName onameEnhydra = new ObjectName("EnhydraApplications:type=DatabaseManager,*"); 73 Set enhydraMBeans= getMBeanServer().queryNames(onameEnhydra,null); 74 Object [] 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 ex){ 80 ex.printStackTrace(); 81 message = "Encountered some problems during cache disabling!"; 82 } 83 return message; 84 } 85 86 public String toggleCache(){ 87 String message = "Caches are successfully toggled!"; 88 try { 89 ObjectName onameEnhydra = new ObjectName("EnhydraApplications:type=DatabaseManager,*"); 90 Set enhydraMBeans= getMBeanServer().queryNames(onameEnhydra,null); 91 Object [] 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 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 e) { 114 e.printStackTrace(); 115 } 116 } 117 return mBeanServer; 118 } 119 120 121 } 122 | Popular Tags |