KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > umo > manager > DefaultWorkListener


1 /*
2  * $Id: DefaultWorkListener.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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 org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15
16 import javax.resource.spi.work.WorkEvent JavaDoc;
17 import javax.resource.spi.work.WorkListener JavaDoc;
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: 3798 $
24  */

25 public class DefaultWorkListener implements WorkListener JavaDoc
26 {
27
28     /**
29      * logger used by this class
30      */

31     protected transient Log logger = LogFactory.getLog(getClass());
32
33     public void workAccepted(WorkEvent JavaDoc event)
34     {
35         handleWorkException(event, "workAccepted");
36     }
37
38     public void workRejected(WorkEvent JavaDoc event)
39     {
40         handleWorkException(event, "workRejected");
41     }
42
43     public void workStarted(WorkEvent JavaDoc event)
44     {
45         handleWorkException(event, "workStarted");
46     }
47
48     public void workCompleted(WorkEvent JavaDoc event)
49     {
50         handleWorkException(event, "workCompleted");
51     }
52
53     protected void handleWorkException(WorkEvent JavaDoc event, String JavaDoc type)
54     {
55         Throwable JavaDoc 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 }
76
Popular Tags