Coverage Report - org.mule.processor.AsyncWorkListener
 
Classes in this File Line Coverage Branch Coverage Complexity
AsyncWorkListener
0%
0/21
0%
0/6
2
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.processor;
 8  
 
 9  
 import org.mule.api.MuleRuntimeException;
 10  
 import org.mule.api.processor.MessageProcessor;
 11  
 import org.mule.config.i18n.CoreMessages;
 12  
 
 13  
 import javax.resource.spi.work.WorkEvent;
 14  
 import javax.resource.spi.work.WorkListener;
 15  
 
 16  
 import org.apache.commons.logging.Log;
 17  
 import org.apache.commons.logging.LogFactory;
 18  
 
 19  
 public class AsyncWorkListener implements WorkListener
 20  
 {
 21  0
     protected Log logger = LogFactory.getLog(getClass());
 22  
     protected MessageProcessor target;
 23  
 
 24  
     public AsyncWorkListener(MessageProcessor target)
 25  0
     {
 26  0
         this.target = target;
 27  0
     }
 28  
 
 29  
     public void workAccepted(WorkEvent event)
 30  
     {
 31  0
         this.handleWorkException(event, "workAccepted");
 32  0
     }
 33  
 
 34  
     public void workRejected(WorkEvent event)
 35  
     {
 36  0
         this.handleWorkException(event, "workRejected");
 37  0
     }
 38  
 
 39  
     public void workStarted(WorkEvent event)
 40  
     {
 41  0
         this.handleWorkException(event, "workStarted");
 42  0
     }
 43  
 
 44  
     public void workCompleted(WorkEvent event)
 45  
     {
 46  0
         this.handleWorkException(event, "workCompleted");
 47  0
     }
 48  
 
 49  
     protected void handleWorkException(WorkEvent event, String type)
 50  
     {
 51  0
         if (event == null)
 52  
         {
 53  0
             return;
 54  
         }
 55  
 
 56  0
         Throwable e = event.getException();
 57  
 
 58  0
         if (e == null)
 59  
         {
 60  0
             return;
 61  
         }
 62  
 
 63  0
         if (e.getCause() != null)
 64  
         {
 65  0
             e = e.getCause();
 66  
         }
 67  
 
 68  0
         logger.error("Work caused exception on '" + type + "'. Work being executed was: "
 69  
                      + event.getWork().toString());
 70  0
         throw new MuleRuntimeException(CoreMessages.errorInvokingMessageProcessorAsynchronously(target), e);
 71  
     }
 72  
 
 73  
 }