Coverage Report - org.mule.module.jca.JcaComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
JcaComponent
48%
10/21
N/A
1.357
JcaComponent$MuleJcaWorker
15%
3/20
0%
0/6
1.357
 
 1  
 /*
 2  
  * $Id: JcaComponent.java 11488 2008-03-24 14:38:49Z 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.module.jca;
 12  
 
 13  
 import org.mule.OptimizedRequestContext;
 14  
 import org.mule.RequestContext;
 15  
 import org.mule.api.MessagingException;
 16  
 import org.mule.api.MuleEvent;
 17  
 import org.mule.api.MuleException;
 18  
 import org.mule.api.MuleMessage;
 19  
 import org.mule.api.component.LifecycleAdapter;
 20  
 import org.mule.api.lifecycle.InitialisationException;
 21  
 import org.mule.api.model.EntryPointResolverSet;
 22  
 import org.mule.api.service.Service;
 23  
 import org.mule.component.AbstractJavaComponent;
 24  
 import org.mule.config.i18n.CoreMessages;
 25  
 import org.mule.config.i18n.Message;
 26  
 import org.mule.module.jca.i18n.JcaMessages;
 27  
 
 28  
 import javax.resource.spi.UnavailableException;
 29  
 import javax.resource.spi.endpoint.MessageEndpoint;
 30  
 import javax.resource.spi.endpoint.MessageEndpointFactory;
 31  
 import javax.resource.spi.work.Work;
 32  
 import javax.resource.spi.work.WorkEvent;
 33  
 import javax.resource.spi.work.WorkListener;
 34  
 import javax.resource.spi.work.WorkManager;
 35  
 
 36  0
 public class JcaComponent extends AbstractJavaComponent implements WorkListener
 37  
 {
 38  
     protected MessageEndpointFactory messageEndpointFactory;
 39  
     protected WorkManager workManager;
 40  
 
 41  
     public JcaComponent(MessageEndpointFactory messageEndpointFactory,
 42  
                         EntryPointResolverSet entryPointResolverSet,
 43  
                         Service service,
 44  
                         WorkManager workManager)
 45  18
     {
 46  18
         this.messageEndpointFactory = messageEndpointFactory;
 47  18
         this.entryPointResolverSet = entryPointResolverSet;
 48  18
         this.service = service;
 49  18
         this.workManager = workManager;
 50  18
     }
 51  
 
 52  
     /*
 53  
      * The service ins actually managed by the Application Server container,Since the
 54  
      * instance might be pooled by the server, we should use the
 55  
      * MessageEndPointFactory to delegate the request for creation to the container.
 56  
      * The container might create a Proxy object to intercept the actual method call
 57  
      * to implement transaction,security related functionalities
 58  
      */
 59  
     public Object getManagedInstance() throws UnavailableException, MuleException
 60  
     {
 61  0
         return messageEndpointFactory.createEndpoint(null);
 62  
     }
 63  
 
 64  
     public MuleMessage doOnCall(MuleEvent event)
 65  
     {
 66  
         try
 67  
         {
 68  2
             workManager.scheduleWork(new MuleJcaWorker(event), WorkManager.INDEFINITE, null, this);
 69  
         }
 70  0
         catch (Exception e)
 71  
         {
 72  0
             logger.error(CoreMessages.failedToInvoke("UMO Service: " + service.getName()));
 73  2
         }
 74  2
         return null;
 75  
     }
 76  
 
 77  
     public Class getObjectType()
 78  
     {
 79  0
         return MessageEndpoint.class;
 80  
     }
 81  
 
 82  
     // @Override
 83  
     protected LifecycleAdapter borrowComponentLifecycleAdaptor() throws Exception
 84  
     {
 85  
         // Template method unused because doOnCall and doOnEvent have been overridden
 86  0
         return null;
 87  
     }
 88  
 
 89  
     // @Override
 90  
     protected void returnComponentLifecycleAdaptor(LifecycleAdapter lifecycleAdapter)
 91  
     {
 92  
         // Template method unused because doOnCall and doOnEvent have been overridden
 93  0
     }
 94  
 
 95  
     // @Override
 96  
     protected void doInitialise() throws InitialisationException
 97  
     {
 98  
         // no-op no object-factory
 99  18
     }
 100  
 
 101  
     public class MuleJcaWorker implements Work
 102  
     {
 103  
 
 104  
         private MuleEvent event;
 105  
 
 106  
         MuleJcaWorker(MuleEvent event)
 107  2
         {
 108  2
             this.event = event;
 109  2
         }
 110  
 
 111  
         public void release()
 112  
         {
 113  
             // TODO Auto-generated method stub
 114  0
         }
 115  
 
 116  
         public void run()
 117  
         {
 118  
 
 119  0
             if (logger.isTraceEnabled())
 120  
             {
 121  0
                 logger.trace("MuleJcaWorker: async MuleEvent for Mule  JCA EndPoint " + service.getName());
 122  
             }
 123  
             try
 124  
             {
 125  
                 // Invoke method
 126  0
                 event = OptimizedRequestContext.criticalSetEvent(event);
 127  0
                 entryPointResolverSet.invoke(getManagedInstance(), RequestContext.getEventContext());
 128  
             }
 129  0
             catch (Exception e)
 130  
             {
 131  0
                 if (e instanceof UnavailableException)
 132  
                 {
 133  0
                     Message message = JcaMessages.cannotAllocateManagedInstance();
 134  0
                     logger.error(message);
 135  0
                     service.getExceptionListener().exceptionThrown(new MessagingException(message, e));
 136  0
                 }
 137  0
                 else if (e instanceof MessagingException)
 138  
                 {
 139  0
                     logger.error("Failed to execute  JCAEndPoint " + e.getMessage(), e);
 140  0
                     service.getExceptionListener().exceptionThrown(e);
 141  
                 }
 142  
                 else
 143  
                 {
 144  0
                     service.getExceptionListener().exceptionThrown(
 145  
                         new MessagingException(CoreMessages.eventProcessingFailedFor(service.getName()), e));
 146  
                 }
 147  0
             }
 148  0
         }
 149  
     }
 150  
 
 151  
     public void workAccepted(WorkEvent arg0)
 152  
     {
 153  
         // TODO Auto-generated method stub
 154  0
     }
 155  
 
 156  
     public void workCompleted(WorkEvent arg0)
 157  
     {
 158  
         // TODO Auto-generated method stub
 159  0
     }
 160  
 
 161  
     public void workRejected(WorkEvent arg0)
 162  
     {
 163  
         // TODO Auto-generated method stub
 164  0
     }
 165  
 
 166  
     public void workStarted(WorkEvent arg0)
 167  
     {
 168  
         // TODO Auto-generated method stub
 169  0
     }
 170  
 
 171  
 }