1 25 26 package org.objectweb.petals.jbi.management.service; 27 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 import javax.jbi.JBIException; 32 import javax.jbi.messaging.MessageExchange; 33 import javax.jbi.servicedesc.ServiceEndpoint; 34 import javax.management.ObjectName ; 35 36 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 37 import org.objectweb.fractal.fraclet.annotation.FractalComponent; 38 import org.objectweb.fractal.fraclet.annotation.Interface; 39 import org.objectweb.fractal.fraclet.annotation.LifeCycle; 40 import org.objectweb.fractal.fraclet.annotation.LifeCycleType; 41 import org.objectweb.fractal.fraclet.annotation.Monolog; 42 import org.objectweb.fractal.fraclet.annotation.Provides; 43 import org.objectweb.fractal.fraclet.annotation.Requires; 44 import org.objectweb.petals.PetalsException; 45 import org.objectweb.petals.jbi.component.lifecycle.ComponentLifeCycle; 46 import org.objectweb.petals.jbi.component.lifecycle.LifeCycleAbstract; 47 import org.objectweb.petals.util.LoggingUtil; 48 import org.objectweb.petals.util.ParameterCheckHelper; 49 import org.objectweb.util.monolog.api.Logger; 50 import org.w3c.dom.Document ; 51 52 58 @FractalComponent 59 @Provides(interfaces=@Interface(name="service",signature=org.objectweb.petals.jbi.management.service.AdminServiceMBean.class)) 60 public class AdminService implements AdminServiceMBean { 61 62 65 protected LoggingUtil log; 66 67 70 @Monolog(name="logger") 71 protected Logger logger; 72 73 76 @Requires(name="lifecyclemanager",signature=org.objectweb.petals.jbi.management.service.LifeCycleManagerService.class) 77 protected LifeCycleManagerService manager; 78 79 82 public AdminService() { 83 super(); 84 } 85 86 89 public ObjectName [] getBindingComponents() { 90 log.start(); 91 92 ObjectName [] names = new ObjectName [0]; 93 94 Map <ObjectName , ComponentLifeCycle> bindings = manager 95 .getBindingCompoLifeCycles(); 96 97 names = (ObjectName []) bindings.keySet().toArray(names); 98 99 return names; 100 } 101 102 105 public ObjectName getComponentByName(String name) { 106 log.call(); 107 ParameterCheckHelper.isNullParameterWithLog(name, 108 "name must not be null", log); 109 ParameterCheckHelper.isEmptyParameterWithLog(name, 110 "name must not be empty", log); 111 ObjectName on = null; 112 113 115 on = getBindingComponentByName(name); 116 117 if (on == null) { 118 120 on = getEngineComponentByName(name); 121 } 122 return on; 123 } 124 125 128 public ObjectName [] getEngineComponents() { 129 log.call(); 130 131 ObjectName [] names = new ObjectName [0]; 132 133 Map <ObjectName , ComponentLifeCycle> engines = manager 134 .getEngineCompoLifeCycles(); 135 136 names = (ObjectName []) engines.keySet().toArray(names); 137 138 return names; 139 } 140 141 145 public Document getServiceDescription(String componentName, 146 ServiceEndpoint endpoint) throws PetalsException { 147 log.call(); 148 Document doc = null; 149 ComponentLifeCycle componentLifeCycle = manager 150 .getComponentByName(componentName); 151 if (componentLifeCycle == null) { 152 log.error("No such component " + componentName 153 + " in the container"); 154 throw new PetalsException("No such component " + componentName 155 + " in the container"); 156 } 157 doc = componentLifeCycle.getComponent().getServiceDescription(endpoint); 158 return doc; 159 } 160 161 164 public String getSystemInfo() { 165 return "Petals JBI Container - version: " 166 + Package.getPackage("org.objectweb.petals") 167 .getImplementationVersion(); 168 } 169 170 173 public ObjectName getSystemService(String serviceName) { 174 log.call(); 175 ParameterCheckHelper.isNullParameterWithLog(serviceName, 176 "serviceName must not be null", log); 177 ParameterCheckHelper.isEmptyParameterWithLog(serviceName, 178 "serviceName must not be empty", log); 179 ObjectName result = null; 180 Map systemServices = manager.getSystemServices(); 181 182 synchronized (systemServices) { 183 for (Iterator iter = systemServices.values().iterator(); iter 184 .hasNext() 185 && result == null;) { 186 ComponentLifeCycle lifeCycle = (ComponentLifeCycle) iter.next(); 187 188 if (lifeCycle.getName().equals(serviceName)) { 189 result = lifeCycle.getMBeanName(); 190 } 191 } 192 } 193 return result; 194 } 195 196 199 public ObjectName [] getSystemServices() { 200 log.call(); 201 202 ObjectName [] names = new ObjectName [0]; 203 204 Map <ObjectName , LifeCycleAbstract> services = manager 205 .getSystemServices(); 206 207 names = (ObjectName []) services.keySet().toArray(names); 208 209 return names; 210 } 211 212 215 public boolean isBinding(String componentName) { 216 ParameterCheckHelper.isNullParameterWithLog(componentName, 217 "componentName must not be null", log); 218 ParameterCheckHelper.isEmptyParameterWithLog(componentName, 219 "componentName must not be empty", log); 220 boolean result = false; 221 result = manager.getBindingCompoLifeCycles().containsKey(componentName); 222 return result; 223 } 224 225 229 232 public boolean isEngine(String componentName) { 233 ParameterCheckHelper.isNullParameterWithLog(componentName, 234 "componentName must not be null", log); 235 ParameterCheckHelper.isEmptyParameterWithLog(componentName, 236 "componentName must not be empty", log); 237 boolean result = false; 238 result = manager.getEngineCompoLifeCycles().containsKey(componentName); 239 return result; 240 } 241 242 249 public boolean isExchangeWithConsumerOkayForComponent(String componentName, 250 ServiceEndpoint internalEndpoint, MessageExchange exchange) 251 throws JBIException { 252 log.call(); 253 ComponentLifeCycle componentLifeCycle = manager 254 .getComponentByName(componentName); 255 if (componentLifeCycle == null) { 256 log.error("No such component " + componentName 257 + " in the container"); 258 throw new JBIException("No such component " + componentName 259 + " in the container"); 260 } 261 return componentLifeCycle.getComponent().isExchangeWithConsumerOkay( 262 internalEndpoint, exchange); 263 } 264 265 272 public boolean isExchangeWithProviderOkayForComponent(String componentName, 273 ServiceEndpoint internalEndpoint, MessageExchange exchange) 274 throws JBIException { 275 log.call(); 276 ComponentLifeCycle componentLifeCycle = manager 277 .getComponentByName(componentName); 278 if (componentLifeCycle == null) { 279 log.error("No such component " + componentName 280 + " in the container"); 281 throw new JBIException("No such component " + componentName 282 + " in the container"); 283 } 284 return componentLifeCycle.getComponent().isExchangeWithProviderOkay( 285 internalEndpoint, exchange); 286 } 287 288 292 295 @LifeCycle(on=LifeCycleType.START) 296 public void start() throws IllegalLifeCycleException { 297 log = new LoggingUtil(logger); 298 } 299 300 306 protected ObjectName getBindingComponentByName(String name) { 307 log.call(); 308 309 ObjectName result = null; 310 311 Map bindings = manager.getBindingCompoLifeCycles(); 312 313 synchronized (bindings) { 314 for (Iterator iter = bindings.values().iterator(); iter.hasNext() 315 && result == null;) { 316 ComponentLifeCycle lifeCycle = (ComponentLifeCycle) iter.next(); 317 318 if (lifeCycle.getName().equals(name)) { 319 result = lifeCycle.getMBeanName(); 320 } 321 } 322 } 323 return result; 324 } 325 326 332 protected ObjectName getEngineComponentByName(String name) { 333 log.call(); 334 335 ObjectName result = null; 336 337 Map engines = manager.getEngineCompoLifeCycles(); 338 339 synchronized (engines) { 340 for (Iterator iter = engines.values().iterator(); iter.hasNext() 341 && result == null;) { 342 ComponentLifeCycle lifeCycle = (ComponentLifeCycle) iter.next(); 343 344 if (lifeCycle.getName().equals(name)) { 345 result = lifeCycle.getMBeanName(); 346 } 347 } 348 } 349 return result; 350 } 351 352 } 353 | Popular Tags |