KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ersatz > resourceadapter > WorkImpl


1 /*
2  * Created on January 13, 2004
3  *
4  * WorkImpl.java is used to test JCA 1.5
5  * as implemented by JOnAS. This class implements the Work Interface
6  *
7  */

8 package ersatz.resourceadapter;
9
10 import javax.resource.spi.work.Work;
11 import javax.resource.spi.endpoint.MessageEndpointFactory;
12 import javax.resource.spi.endpoint.MessageEndpoint;
13 import javax.resource.spi.UnavailableException;
14 import javax.resource.ResourceException;
15
16 /**
17  * @author Bob Kruse
18  *
19  * JCA1.5 Work class
20  *
21  * used to test the J2EE Connector as implemented by JOnAS.
22  *
23  */

24 public class WorkImpl
25         implements Work
26 {
27     private String workType;
28     private MessageEndpointFactory factory = null;
29     private String message;
30     private MessageEndpoint ep = null;
31     String cName = "WorkImpl";
32     
33     // constructor #1
34
public WorkImpl(String w) {
35         workType=w;
36     }
37     // constructor #2
38
public WorkImpl(MessageEndpointFactory factory, String message)
39             throws Exception
40     {
41         Utility.log(cName+".constructor factory="+factory+" message="+message);
42         this.factory=factory;
43         this.message=message;
44         workType="Message Delivery";
45         if (factory==null) throw new Exception("MessageEndpointFactory==null");
46     }
47     public void release()
48     {
49         Utility.log(cName+".release workType="+workType);
50     }
51     public void run()
52     {
53         ersatz.resourceadapter.MsgListenerInterface mli = null;
54         Utility.log(cName+".run workType="+workType) ;
55         if (workType.equals("Message Delivery")) {
56             try {
57                 // create endpoint ---cannot handle XA
58
// deliver message
59
ep = factory.createEndpoint(null);
60                 Utility.log(cName+".run factory.CreateEndpoint created. ep="+ep);
61                 
62                 mli = (ersatz.resourceadapter.MsgListenerInterface)ep;
63                 if (ep != null) {
64 /* tmp */ //mli.offMessage(message);
65
/* tmp */ //Utility.log(cName+".run onMessage successful.");
66
mli.onMessage(message);
67                     Utility.log(cName+".run onMessage successful.");
68                 } else {
69                     Utility.log(cName+".run error: endpoint="+ep);
70                 }
71             } catch (UnavailableException ue) {
72                 Utility.log(cName+".run error: UnavailableException");
73                 ue.printStackTrace();
74             } catch (Exception e) {
75                 Utility.log(cName+".run error: Exception e="+e);
76                 e.printStackTrace();
77             } catch (Throwable t) {
78                 Utility.log(cName+".run error: Throwable t="+t);
79                 t.printStackTrace();
80             }
81         }
82         if (ep!=null) {
83             ep.release();
84         }
85         
86     }
87     public String getWorkType()
88     {
89         return workType;
90     }
91 }
Popular Tags