1 7 package org.ejtools.jmx.browser.web; 8 9 import java.beans.beancontext.BeanContextServicesSupport ; 10 import java.util.Collection ; 11 import java.util.Set ; 12 13 import javax.management.ObjectInstance ; 14 import javax.management.ObjectName ; 15 import javax.management.QueryExp ; 16 17 import org.ejtools.jmx.browser.mbean.View; 18 import org.ejtools.jmx.browser.model.Resource; 19 import org.ejtools.jmx.browser.model.Server; 20 import org.ejtools.jmx.browser.model.service.CacheService; 21 import org.ejtools.jmx.browser.model.service.CacheServiceProvider; 22 import org.ejtools.jmx.browser.model.service.ConnectionServiceProvider; 23 import org.ejtools.jmx.browser.model.service.CustomizationServiceProvider; 24 import org.ejtools.jmx.browser.model.service.NotificationServiceProvider; 25 26 27 35 public class JMXContainer extends BeanContextServicesSupport 36 { 37 38 protected CacheServiceProvider cacheProvider; 39 40 protected ConnectionServiceProvider connectionProvider; 41 42 protected CustomizationServiceProvider customizationProvider; 43 44 protected NotificationServiceProvider notificationProvider; 45 46 protected Server server; 47 48 49 50 public JMXContainer() 51 { 52 try 53 { 54 this.connectionProvider = new ConnectionServiceProvider(); 55 this.notificationProvider = new NotificationServiceProvider(); 56 this.cacheProvider = new CacheServiceProvider(); 57 this.customizationProvider = new CustomizationServiceProvider(); 58 this.server = new Server(); 59 60 this.add(this.cacheProvider); 61 this.add(this.connectionProvider); 62 this.add(this.notificationProvider); 63 this.add(this.customizationProvider); 64 this.add(this.server); 65 } 66 catch (Exception e) 67 { 68 e.printStackTrace(); 69 } 70 } 71 72 73 74 public void clearNotifications() 75 { 76 this.notificationProvider.clearAll(); 77 } 78 79 80 91 public ObjectInstance createMBean(java.lang.String className, ObjectName name, ObjectName loaderName, java.lang.Object [] params, java.lang.String [] signature) 92 throws Exception 93 { 94 return this.server.createMBean(className, name, loaderName, params, signature); 95 } 96 97 98 103 public int getCount() 104 { 105 return this.server.getCount(); 106 } 107 108 109 114 public String getDefaultDomain() 115 { 116 return this.server.getDefaultDomain(); 117 } 118 119 120 125 public Collection getNotifications() 126 { 127 return this.notificationProvider.listAll(); 128 } 129 130 131 136 public Collection getServer() 137 { 138 return this.server; 139 } 140 141 142 148 public View getView(int index) 149 { 150 return this.customizationProvider.getView(index); 151 } 152 153 154 159 public Collection getViews() 160 { 161 return this.customizationProvider.getViews(); 162 } 163 164 165 173 public Set query(ObjectName name, QueryExp exp) 174 throws Exception 175 { 176 return this.server.query(name, exp); 177 } 178 179 180 181 public void refresh() 182 { 183 this.server.refresh(); 184 } 185 186 187 193 public Object searchObjectName(String objectName) 194 { 195 Resource resource = (Resource) this.cacheProvider.get(CacheService.RESOURCE_TYPE, objectName); 196 try 197 { 198 if ((resource != null) && (resource.isRegistered())) 199 { 200 return resource; 201 } 202 } 203 catch (Exception e) 204 { 205 e.printStackTrace(); 206 } 207 return null; 208 } 209 210 218 public Object searchObjectName(String objectName, boolean refreshServer) 219 { 220 if (refreshServer){ 221 222 if (this.server.isConnected()) 223 { 224 this.server.disconnect(); 225 } 226 227 refresh(); 228 Resource resource = (Resource) this.cacheProvider.get(CacheService.RESOURCE_TYPE, objectName); 229 try 230 { 231 if ((resource != null) && (resource.isRegistered())) 232 { 233 return resource; 234 } 235 } 236 catch (Exception e) 237 { 238 e.printStackTrace(); 239 } 240 return null; 241 } else { 242 return searchObjectName(objectName); 243 } 244 } 245 } 246 | Popular Tags |