View Javadoc

1   /*
2    * $Id: DefaultWorkListener.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.work;
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  /**
20   * Default exception Handler used when executing work in the work manager
21   */
22  public class DefaultWorkListener implements WorkListener
23  {
24  
25      /**
26       * logger used by this class
27       */
28      protected transient Log logger = LogFactory.getLog(getClass());
29  
30      public void workAccepted(WorkEvent event)
31      {
32          handleWorkException(event, "workAccepted");
33      }
34  
35      public void workRejected(WorkEvent event)
36      {
37          handleWorkException(event, "workRejected");
38      }
39  
40      public void workStarted(WorkEvent event)
41      {
42          handleWorkException(event, "workStarted");
43      }
44  
45      public void workCompleted(WorkEvent event)
46      {
47          handleWorkException(event, "workCompleted");
48      }
49  
50      protected void handleWorkException(WorkEvent event, String type)
51      {
52          Throwable e;
53  
54          if (event != null && event.getException() != null)
55          {
56              e = event.getException();
57          }
58          else
59          {
60              return;
61          }
62  
63          if (event.getException().getCause() != null)
64          {
65              e = event.getException().getCause();
66          }
67  
68          logger.error("Work caused exception on '" + type + "'. Work being executed was: "
69                       + event.getWork().toString());
70          logger.error(e);
71      }
72  }