1 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 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 public WorkImpl(String w) { 35 workType=w; 36 } 37 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 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 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 |