1 22 23 package org.objectweb.petals.component.common.su; 24 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import java.util.logging.Logger ; 28 29 import javax.jbi.component.ComponentContext; 30 import javax.jbi.management.DeploymentException; 31 32 import org.objectweb.petals.component.common.PEtALSComponentSDKException; 33 import org.objectweb.petals.component.common.bc.AbstractBindingComponent; 34 import org.objectweb.petals.component.common.bc.ExternalListenerManager; 35 import org.objectweb.petals.tools.jbicommon.descriptor.Consumes; 36 37 44 public class BindingComponentServiceUnitManager extends 45 SimpleServiceUnitManager { 46 47 private AbstractBindingComponent bindingComponent; 48 49 public BindingComponentServiceUnitManager(ComponentContext context, 50 Logger logger, AbstractBindingComponent bindingComponent) { 51 super(bindingComponent, context, logger); 52 this.bindingComponent = bindingComponent; 53 } 54 55 private List <String > getServiceUnitAddresses(final String serviceUnitName) { 56 return new ArrayList <String >(getServiceUnitDatas().get(serviceUnitName) 57 .getAddressToConsumes().keySet()); 58 } 59 60 @Override 61 public void start(final String serviceUnitName) throws DeploymentException { 62 super.start(serviceUnitName); 63 for (String address : getServiceUnitAddresses(serviceUnitName)) { 64 try { 65 Consumes consumes = getConsumesFromAddress(address); 66 if (consumes == null) { 67 throw new DeploymentException( 68 "The Consumes node of the JBI.XML descriptor file is null."); 69 } 70 getExternalListenerManager().startListening(address, 71 consumes.getExtensions()); 72 } catch (PEtALSComponentSDKException e) { 73 String msg = "Failed to start listening to address : " 74 + address; 75 getLogger().severe(msg); 76 throw new DeploymentException(msg, e); 77 } 78 } 79 } 80 81 private ExternalListenerManager getExternalListenerManager() 82 throws DeploymentException { 83 ExternalListenerManager externalListenerManager = bindingComponent 84 .getInitializer().getExternalListenerManager(); 85 if (externalListenerManager == null) { 86 throw new DeploymentException( 87 "No external Listener manager provided. " 88 + "So consumes node not allowed"); 89 } 90 return externalListenerManager; 91 } 92 93 @Override 94 public void stop(final String serviceUnitName) throws DeploymentException { 95 for (String address : getServiceUnitAddresses(serviceUnitName)) { 96 try { 97 getExternalListenerManager().stopListening(address); 98 } catch (PEtALSComponentSDKException e) { 99 String msg = "Failed to start listening to address : " 100 + address; 101 getLogger().severe(msg); 102 throw new DeploymentException(msg, e); 103 } 104 } 105 super.stop(serviceUnitName); 106 } 107 108 } 109 | Popular Tags |