View Javadoc
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.work;
8   
9   import javax.resource.spi.work.WorkEvent;
10  import javax.resource.spi.work.WorkListener;
11  
12  import org.apache.commons.logging.Log;
13  import org.apache.commons.logging.LogFactory;
14  
15  /**
16   * Default exception Handler used when executing work in the work manager
17   */
18  public class DefaultWorkListener implements WorkListener
19  {
20  
21      /**
22       * logger used by this class
23       */
24      protected transient Log logger = LogFactory.getLog(getClass());
25  
26      public void workAccepted(WorkEvent event)
27      {
28          handleWorkException(event, "workAccepted");
29      }
30  
31      public void workRejected(WorkEvent event)
32      {
33          handleWorkException(event, "workRejected");
34      }
35  
36      public void workStarted(WorkEvent event)
37      {
38          handleWorkException(event, "workStarted");
39      }
40  
41      public void workCompleted(WorkEvent event)
42      {
43          handleWorkException(event, "workCompleted");
44      }
45  
46      protected void handleWorkException(WorkEvent event, String type)
47      {
48          Throwable e;
49  
50          if (event != null && event.getException() != null)
51          {
52              e = event.getException();
53          }
54          else
55          {
56              return;
57          }
58  
59          if (event.getException().getCause() != null)
60          {
61              e = event.getException().getCause();
62          }
63  
64          logger.error("Work caused exception on '" + type + "'. Work being executed was: "
65                       + event.getWork().toString());
66          logger.error(e);
67      }
68  }