1 12 13 package org.ejtools.jmx.browser.model; 14 15 16 17 import java.beans.beancontext.BeanContextServiceAvailableEvent ; 18 19 import java.beans.beancontext.BeanContextServiceRevokedEvent ; 20 21 import java.beans.beancontext.BeanContextServices ; 22 23 24 25 import javax.management.ObjectInstance ; 26 27 28 29 import org.apache.log4j.Logger; 30 31 import org.ejtools.jmx.browser.model.service.CacheService; 32 33 34 35 36 37 74 75 public class Domain extends Node 76 77 { 78 79 80 81 private static Logger logger = Logger.getLogger(Domain.class); 82 83 84 85 86 87 88 89 public Domain() 90 91 { 92 93 super(); 94 95 } 96 97 98 99 100 101 110 111 public int getSize() 112 113 { 114 115 return this.size(); 116 117 } 118 119 120 121 122 123 132 133 public void serviceAvailable(BeanContextServiceAvailableEvent bcsae) 134 135 { 136 137 if (CacheService.class.equals(bcsae.getServiceClass())) 138 139 { 140 141 BeanContextServices context = (BeanContextServices ) getBeanContext(); 142 143 if (context != null) 144 145 { 146 147 this.useServices(context); 148 149 } 150 151 } 152 153 super.serviceAvailable(bcsae); 154 155 } 156 157 158 159 160 161 162 163 172 173 public void serviceRevoked(BeanContextServiceRevokedEvent bcsre) 174 175 { 176 177 if (CacheService.class.equals(bcsre.getServiceClass())) 178 179 { 180 181 BeanContextServices context = (BeanContextServices ) getBeanContext(); 182 183 if (context != null) 184 185 { 186 187 this.releaseServices(context); 188 189 } 190 191 } 192 193 super.serviceRevoked(bcsre); 194 195 } 196 197 198 199 200 201 210 211 public void setReference(ObjectInstance resource) 212 213 { 214 215 this.name = resource.getObjectName().getDomain(); 216 217 } 218 219 220 221 222 223 224 225 protected void initializeBeanContextResources() 226 227 { 228 229 super.initializeBeanContextResources(); 230 231 BeanContextServices context = (BeanContextServices ) getBeanContext(); 232 233 this.useServices(context); 234 235 } 236 237 238 239 240 241 242 243 protected void releaseBeanContextResources() 244 245 { 246 247 BeanContextServices context = (BeanContextServices ) getBeanContext(); 248 249 this.releaseServices(context); 250 251 super.releaseBeanContextResources(); 252 253 } 254 255 256 257 258 259 268 269 protected void releaseServices(BeanContextServices context) 270 271 { 272 273 logger.debug("In releaseServices..."); 274 275 if (context.hasService(CacheService.class)) 276 277 { 278 279 281 try 282 283 { 284 285 CacheService service = (CacheService) context.getService(this, this, CacheService.class, this, this); 286 287 service.remove(CacheService.DOMAIN_TYPE, this.name); 288 289 context.releaseService(this, this, CacheService.class); 290 291 } 292 293 catch (Exception e) 294 295 { 296 297 logger.error("Error during utilisation of service CacheService for " + this.name, e); 298 299 } 300 301 } 302 303 } 304 305 306 307 308 309 318 319 protected void useServices(BeanContextServices context) 320 321 { 322 323 if (context.hasService(CacheService.class)) 324 325 { 326 327 329 try 330 331 { 332 333 CacheService service = (CacheService) context.getService(this, this, CacheService.class, this, this); 334 335 service.add(CacheService.DOMAIN_TYPE, this.name, this); 336 337 context.releaseService(this, this, CacheService.class); 338 339 } 340 341 catch (Exception e) 342 343 { 344 345 logger.error("Error during utilisation of service CacheService for " + this.name, e); 346 347 } 348 349 } 350 351 } 352 353 } 354 355 | Popular Tags |