Coverage Report - org.mule.ra.JcaComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
JcaComponent
42%
14/33
N/A
1.667
JcaComponent$MuleJcaWorker
20%
3/15
0%
0/4
1.667
 
 1  
 /*
 2  
  * $Id: JcaComponent.java 10130 2007-12-22 17:07:56Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.ra;
 12  
 
 13  
 import org.mule.MuleException;
 14  
 import org.mule.MuleManager;
 15  
 import org.mule.config.i18n.CoreMessages;
 16  
 import org.mule.impl.MuleDescriptor;
 17  
 import org.mule.impl.OptimizedRequestContext;
 18  
 import org.mule.impl.RequestContext;
 19  
 import org.mule.impl.model.AbstractComponent;
 20  
 import org.mule.ra.i18n.JcaMessages;
 21  
 import org.mule.umo.ComponentException;
 22  
 import org.mule.umo.MessagingException;
 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.manager.ObjectNotFoundException;
 29  
 import org.mule.umo.manager.UMOWorkManager;
 30  
 import org.mule.umo.model.UMOEntryPoint;
 31  
 
 32  
 import javax.resource.spi.UnavailableException;
 33  
 import javax.resource.spi.endpoint.MessageEndpointFactory;
 34  
 import javax.resource.spi.work.Work;
 35  
 import javax.resource.spi.work.WorkEvent;
 36  
 import javax.resource.spi.work.WorkListener;
 37  
 import javax.resource.spi.work.WorkManager;
 38  
 
 39  
 /**
 40  
  * <code>JcaComponent</code> Is the type of component used in Mule when embedded
 41  
  * inside an app server using JCA. In the future we might want to use one of the
 42  
  * existing models.
 43  
  */
 44  0
 public class JcaComponent extends AbstractComponent implements WorkListener
 45  
 {
 46  
 
 47  
     /**
 48  
      * Serial version
 49  
      */
 50  
     private static final long serialVersionUID = -1510441245219710451L;
 51  
 
 52  
     private transient UMOEntryPoint entryPoint;
 53  
     protected UMOWorkManager workManager;
 54  
 
 55  
     public JcaComponent(MuleDescriptor descriptor, UMOWorkManager workManager)
 56  
     {
 57  
 
 58  16
         super(descriptor, MuleManager.getInstance().lookupModel(descriptor.getModelName()));
 59  16
         this.workManager = workManager;
 60  16
     }
 61  
 
 62  
     public UMODescriptor getDescriptor()
 63  
     {
 64  60
         return descriptor;
 65  
     }
 66  
 
 67  
     /**
 68  
      * This is the synchronous call method and not supported by components managed in
 69  
      * a JCA container
 70  
      * 
 71  
      * @param event
 72  
      * @return
 73  
      * @throws UMOException
 74  
      */
 75  
     public UMOMessage sendEvent(UMOEvent event) throws UMOException
 76  
     {
 77  2
         throw new UnsupportedOperationException("sendEvent()");
 78  
     }
 79  
 
 80  
     public boolean isPaused()
 81  
     {
 82  
         // JcaComponent is a wrapper for a hosted component implementation and
 83  
         // therefore cannot be paused by mule
 84  0
         return false;
 85  
     }
 86  
 
 87  
     protected void waitIfPaused(UMOEvent event) throws InterruptedException
 88  
     {
 89  
         // JcaComponent is a wrapper for a hosted component implementation and
 90  
         // therefore cannot be paused by mule
 91  2
     }
 92  
 
 93  
     protected void doPause() throws UMOException
 94  
     {
 95  2
         throw new ComponentException(JcaMessages.cannotPauseResumeJcaComponent(), null, this);
 96  
     }
 97  
 
 98  
     protected void doResume() throws UMOException
 99  
     {
 100  2
         throw new ComponentException(JcaMessages.cannotPauseResumeJcaComponent(), null, this);
 101  
     }
 102  
 
 103  
     public synchronized void doInitialise() throws InitialisationException
 104  
     {
 105  
         try
 106  
         {
 107  4
             entryPoint = MuleManager.getInstance()
 108  
                 .lookupModel(this.getDescriptor().getModelName())
 109  
                 .getEntryPointResolver()
 110  
                 .resolveEntryPoint(descriptor);
 111  
         }
 112  0
         catch (UMOException e)
 113  
         {
 114  0
             throw new InitialisationException(e, this);
 115  4
         }
 116  4
     }
 117  
 
 118  
     protected void doDispatch(UMOEvent event) throws UMOException
 119  
     {
 120  
         try
 121  
         {
 122  2
             workManager.scheduleWork(new MuleJcaWorker(event), WorkManager.INDEFINITE, null, this);
 123  
         }
 124  0
         catch (Exception e)
 125  
         {
 126  0
             throw new MuleException(CoreMessages.failedToInvoke("UMO Component: " + descriptor.getName()), e);
 127  2
         }
 128  2
     }
 129  
 
 130  
     /**
 131  
      * Implementation of template method which is never call because send() is
 132  
      * overwritten
 133  
      */
 134  
     protected UMOMessage doSend(UMOEvent event) throws UMOException
 135  
     {
 136  0
         return null;
 137  
     }
 138  
 
 139  
     /*
 140  
      * The component ins actually managed by the Application Server container,Since
 141  
      * the instance might be pooled by the server, we should use the
 142  
      * MessageEndPointFactory to delegate the request for creation to the container.
 143  
      * The container might create a Proxy object to intercept the actual method call
 144  
      * to implement transaction,security related functionalities
 145  
      */
 146  
     public Object getManagedInstance() throws UMOException
 147  
     {
 148  0
         Object managedInstance = null;
 149  
         try
 150  
         {
 151  
 
 152  0
             MessageEndpointFactory messageEndpointFactory = (MessageEndpointFactory) descriptor.getImplementation();
 153  0
             managedInstance = messageEndpointFactory.createEndpoint(null);
 154  
 
 155  
         }
 156  0
         catch (UnavailableException e)
 157  
         {
 158  
 
 159  0
             logger.error("Request Failed to allocate Managed Instance" + e.getMessage(), e);
 160  0
             throw new ObjectNotFoundException(this.getName(), e);
 161  0
         }
 162  
 
 163  0
         return managedInstance;
 164  
     }
 165  
 
 166  
     public class MuleJcaWorker implements Work
 167  
     {
 168  
 
 169  
         private UMOEvent event;
 170  
 
 171  
         MuleJcaWorker(UMOEvent event)
 172  2
         {
 173  2
             this.event = event;
 174  2
         }
 175  
 
 176  
         public void release()
 177  
         {
 178  
             // TODO Auto-generated method stub
 179  0
         }
 180  
 
 181  
         public void run()
 182  
         {
 183  
 
 184  0
             if (logger.isTraceEnabled())
 185  
             {
 186  0
                 logger.trace("MuleJcaWorker: async Event for Mule  JCA EndPoint " + descriptor.getName());
 187  
             }
 188  
             try
 189  
             {
 190  
                 // Invoke method
 191  0
                 event = OptimizedRequestContext.criticalSetEvent(event);
 192  0
                 entryPoint.invoke(getManagedInstance(), RequestContext.getEventContext());
 193  
             }
 194  0
             catch (Exception e)
 195  
             {
 196  0
                 if (e instanceof MessagingException)
 197  
                 {
 198  0
                     logger.error("Failed to execute  JCAEndPoint " + e.getMessage(), e);
 199  0
                     handleException(e);
 200  
                 }
 201  
                 else
 202  
                 {
 203  0
                     handleException(new MessagingException(CoreMessages.eventProcessingFailedFor(descriptor.getName()),
 204  
                         e));
 205  
                 }
 206  0
             }
 207  0
         }
 208  
     }
 209  
 
 210  
     public void workAccepted(WorkEvent arg0)
 211  
     {
 212  
         // TODO Auto-generated method stub
 213  0
     }
 214  
 
 215  
     public void workCompleted(WorkEvent arg0)
 216  
     {
 217  
         // TODO Auto-generated method stub
 218  0
     }
 219  
 
 220  
     public void workRejected(WorkEvent arg0)
 221  
     {
 222  
         // TODO Auto-generated method stub
 223  0
     }
 224  
 
 225  
     public void workStarted(WorkEvent arg0)
 226  
     {
 227  
         // TODO Auto-generated method stub
 228  0
     }
 229  
 }