1 10 11 package org.mule.ra; 12 13 import org.mule.MuleException; 14 import org.mule.MuleManager; 15 import org.mule.config.i18n.Message; 16 import org.mule.config.i18n.Messages; 17 import org.mule.impl.MuleDescriptor; 18 import org.mule.impl.RequestContext; 19 import org.mule.impl.container.ContainerKeyPair; 20 import org.mule.impl.internal.notifications.ComponentNotification; 21 import org.mule.management.stats.ComponentStatistics; 22 import org.mule.umo.UMOComponent; 23 import org.mule.umo.UMODescriptor; 24 import org.mule.umo.UMOEvent; 25 import org.mule.umo.UMOException; 26 import org.mule.umo.UMOMessage; 27 import org.mule.umo.lifecycle.InitialisationException; 28 import org.mule.umo.lifecycle.RecoverableException; 29 import org.mule.umo.manager.ObjectNotFoundException; 30 import org.mule.umo.model.ModelException; 31 import org.mule.umo.model.UMOEntryPoint; 32 33 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean; 34 35 40 public class JcaComponent implements UMOComponent 41 { 42 45 private static final long serialVersionUID = -1510441245219710451L; 46 47 private transient final MuleDescriptor descriptor; 48 private transient UMOEntryPoint entryPoint; 49 private Object component; 50 private ComponentStatistics stats; 51 52 55 private final AtomicBoolean initialised = new AtomicBoolean(false); 56 57 60 private final AtomicBoolean started = new AtomicBoolean(false); 61 62 public JcaComponent(MuleDescriptor descriptor) 63 { 64 if (descriptor == null) 65 { 66 throw new IllegalArgumentException ("Descriptor cannot be null"); 67 } 68 69 this.descriptor = descriptor; 70 } 71 72 public UMODescriptor getDescriptor() 73 { 74 return descriptor; 75 } 76 77 public void dispatchEvent(UMOEvent event) throws UMOException 78 { 79 try 80 { 81 entryPoint.invoke(component, RequestContext.getEventContext()); 83 } 84 catch (Exception e) 85 { 86 throw new MuleException(new Message(Messages.FAILED_TO_INVOKE_X, "UMO Component: " 87 + descriptor.getName()), e); 88 } 89 } 90 91 99 public UMOMessage sendEvent(UMOEvent event) throws UMOException 100 { 101 throw new UnsupportedOperationException ("sendEvent()"); 102 } 103 104 public void pause() throws UMOException 105 { 106 } 108 109 public void resume() throws UMOException 110 { 111 } 113 114 public boolean isPaused() 115 { 116 return false; 117 } 118 119 public void start() throws UMOException 120 { 121 started.set(true); 122 } 123 124 public void stop() throws UMOException 125 { 126 started.set(false); 127 } 128 129 public void dispose() 130 { 131 ((MuleManager)MuleManager.getInstance()).getStatistics().remove(stats); 132 } 133 134 public synchronized void initialise() throws InitialisationException, RecoverableException 135 { 136 if (initialised.get()) 137 { 138 throw new InitialisationException(new Message(Messages.OBJECT_X_ALREADY_INITIALISED, 139 "Component '" + descriptor.getName() + "'"), this); 140 } 141 descriptor.initialise(); 142 try 143 { 144 entryPoint = MuleManager.getInstance().getModel().getEntryPointResolver().resolveEntryPoint( 145 descriptor); 146 } 147 catch (ModelException e) 148 { 149 throw new InitialisationException(e, this); 150 } 151 152 stats = new ComponentStatistics(descriptor.getName(), -1, -1); 154 155 stats.setEnabled(((MuleManager)MuleManager.getInstance()).getStatistics().isEnabled()); 156 ((MuleManager)MuleManager.getInstance()).getStatistics().add(stats); 157 stats.setOutboundRouterStat(getDescriptor().getOutboundRouter().getStatistics()); 158 stats.setInboundRouterStat(getDescriptor().getInboundRouter().getStatistics()); 159 160 component = descriptor.getImplementation(); 161 162 initialised.set(true); 163 MuleManager.getInstance().fireNotification( 164 new ComponentNotification(descriptor, ComponentNotification.COMPONENT_INITIALISED)); 165 } 166 167 protected Object getDelegateComponent() throws InitialisationException 168 { 169 Object impl = descriptor.getImplementation(); 170 Object component = null; 171 172 try 173 { 174 if (impl instanceof ContainerKeyPair) 175 { 176 component = MuleManager.getInstance().getContainerContext().getComponent(impl); 177 178 if (descriptor.isSingleton()) 179 { 180 descriptor.setImplementation(component); 181 } 182 } 183 else 184 { 185 component = impl; 186 } 187 } 188 catch (ObjectNotFoundException e) 189 { 190 throw new InitialisationException(e, this); 191 } 192 193 descriptor.fireInitialisationCallbacks(component); 195 return component; 196 } 197 198 public boolean isStarted() 199 { 200 return started.get(); 201 } 202 203 212 public Object getInstance() throws UMOException 213 { 214 return component; 215 } 216 } 217 | Popular Tags |