1 22 package org.objectweb.petals.component.common; 23 24 import java.util.logging.Level ; 25 import java.util.logging.Logger ; 26 27 import javax.jbi.JBIException; 28 import javax.jbi.component.Component; 29 import javax.jbi.component.ComponentContext; 30 import javax.jbi.component.ComponentLifeCycle; 31 import javax.jbi.component.ServiceUnitManager; 32 import javax.jbi.messaging.DeliveryChannel; 33 import javax.jbi.messaging.MessageExchange; 34 import javax.jbi.servicedesc.ServiceEndpoint; 35 import javax.management.ObjectName ; 36 37 import org.objectweb.petals.component.common.listener.AbstractInternalMEProcessor; 38 import org.objectweb.petals.component.common.listener.MessageExchangeListener; 39 import org.objectweb.petals.component.common.serviceunitmanager.manager.PetalsServiceUnitManager; 40 import org.objectweb.petals.component.common.util.ComponentLogger; 41 42 import org.w3c.dom.Document ; 43 import org.w3c.dom.DocumentFragment ; 44 45 52 public abstract class PetalsComponent implements Component, ComponentLifeCycle { 53 54 57 protected String componentName; 58 59 62 protected DeliveryChannel channel; 63 64 67 private ComponentContext context; 68 69 72 private MessageExchangeListener listener; 73 74 77 protected Logger logger; 78 79 82 protected PetalsServiceUnitManager serviceUnitManager; 83 84 87 public PetalsComponent() { 88 this.serviceUnitManager = createServiceUnitManager(); 89 } 90 91 96 public ObjectName getExtensionMBeanName() { 97 return null; 98 } 99 100 105 public void init(ComponentContext ctx) throws JBIException { 106 this.context = ctx; 107 Logger log = context.getLogger("", null); 108 logger = new ComponentLogger(log, log.getName(), log 109 .getResourceBundleName(), componentName); 110 channel = ctx.getDeliveryChannel(); 111 logger.log(Level.INFO, componentName + "init"); 112 } 113 114 119 public void shutDown() throws JBIException { 120 logger.log(Level.INFO, componentName + " shutdown"); 121 listener = null; 122 } 123 124 129 public void start() throws JBIException { 130 logger.log(Level.INFO, componentName + " start"); 131 AbstractInternalMEProcessor processor = createMessageExchangeProcessor(); 132 listener = createMessageExchangeListener(processor); 133 listener.listen(); 134 } 135 136 protected abstract AbstractInternalMEProcessor createMessageExchangeProcessor(); 137 138 145 protected MessageExchangeListener createMessageExchangeListener( 146 AbstractInternalMEProcessor processor) { 147 return new MessageExchangeListener(channel, processor, 148 MessageExchangeListener.IgnoredStatus.DONE_AND_ERROR_IGNORED, 0, 149 context.getComponentName()); 150 } 151 152 157 public void stop() throws JBIException { 158 logger.log(Level.INFO, componentName + " stop"); 159 this.listener.terminate(); 160 } 161 162 167 protected PetalsServiceUnitManager createServiceUnitManager() { 168 return new PetalsServiceUnitManager(); 169 } 170 171 176 public ComponentLifeCycle getLifeCycle() { 177 return this; 178 } 179 180 185 public Document getServiceDescription(ServiceEndpoint endpoint) { 186 return serviceUnitManager.getServiceDescription(endpoint); 187 } 188 189 194 public ServiceUnitManager getServiceUnitManager() { 195 return serviceUnitManager; 196 } 197 198 204 public boolean isExchangeWithConsumerOkay(ServiceEndpoint endpoint, 205 MessageExchange exchange) { 206 return true; 207 } 208 209 215 public boolean isExchangeWithProviderOkay(ServiceEndpoint endpoint, 216 MessageExchange exchange) { 217 return true; 218 } 219 220 225 public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) { 226 return null; 227 } 228 229 234 public String getComponentName() { 235 return componentName; 236 } 237 238 243 public void setComponentName(String componentName) { 244 this.componentName = componentName; 245 } 246 247 } 248 | Popular Tags |