01: /*
02: * Created on January 13, 2004
03: *
04: * WorkImpl.java is used to test JCA 1.5
05: * as implemented by JOnAS. This class implements the Work Interface
06: *
07: */
08: package ersatz.resourceadapter;
09:
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 implements Work {
25: private String workType;
26: private MessageEndpointFactory factory = null;
27: private String message;
28: private MessageEndpoint ep = null;
29: String cName = "WorkImpl";
30:
31: // constructor #1
32: public WorkImpl(String w) {
33: workType = w;
34: }
35:
36: // constructor #2
37: public WorkImpl(MessageEndpointFactory factory, String message)
38: throws Exception {
39: Utility.log(cName + ".constructor factory=" + factory
40: + " message=" + message);
41: this .factory = factory;
42: this .message = message;
43: workType = "Message Delivery";
44: if (factory == null)
45: throw new Exception("MessageEndpointFactory==null");
46: }
47:
48: public void release() {
49: Utility.log(cName + ".release workType=" + workType);
50: }
51:
52: public void run() {
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
61: + ".run factory.CreateEndpoint created. ep="
62: + ep);
63:
64: mli = (ersatz.resourceadapter.MsgListenerInterface) ep;
65: if (ep != null) {
66: /* tmp *///mli.offMessage(message);
67: /* tmp *///Utility.log(cName+".run onMessage successful.");
68: mli.onMessage(message);
69: Utility.log(cName + ".run onMessage successful.");
70: } else {
71: Utility.log(cName + ".run error: endpoint=" + ep);
72: }
73: } catch (UnavailableException ue) {
74: Utility.log(cName + ".run error: UnavailableException");
75: ue.printStackTrace();
76: } catch (Exception e) {
77: Utility.log(cName + ".run error: Exception e=" + e);
78: e.printStackTrace();
79: } catch (Throwable t) {
80: Utility.log(cName + ".run error: Throwable t=" + t);
81: t.printStackTrace();
82: }
83: }
84: if (ep != null) {
85: ep.release();
86: }
87:
88: }
89:
90: public String getWorkType() {
91: return workType;
92: }
93: }
|