View Javadoc

1   /*
2    * $Id: DefaultWorkListener.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.umo.manager;
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   * @author <a href="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
23   * @version $Revision: 7976 $
24   */
25  public class DefaultWorkListener implements WorkListener
26  {
27  
28      /**
29       * logger used by this class
30       */
31      protected transient Log logger = LogFactory.getLog(getClass());
32  
33      public void workAccepted(WorkEvent event)
34      {
35          handleWorkException(event, "workAccepted");
36      }
37  
38      public void workRejected(WorkEvent event)
39      {
40          handleWorkException(event, "workRejected");
41      }
42  
43      public void workStarted(WorkEvent event)
44      {
45          handleWorkException(event, "workStarted");
46      }
47  
48      public void workCompleted(WorkEvent event)
49      {
50          handleWorkException(event, "workCompleted");
51      }
52  
53      protected void handleWorkException(WorkEvent event, String type)
54      {
55          Throwable e;
56  
57          if (event != null && event.getException() != null)
58          {
59              e = event.getException();
60          }
61          else
62          {
63              return;
64          }
65  
66          if (event.getException().getCause() != null)
67          {
68              e = event.getException().getCause();
69          }
70  
71          logger.error("Work caused exception on '" + type + "'. Work being executed was: "
72                       + event.getWork().toString());
73          logger.error(e);
74      }
75  }