1 22 package org.jboss.resource.adapter.mail; 23 24 import javax.resource.spi.ResourceAdapter ; 25 import javax.resource.spi.BootstrapContext ; 26 import javax.resource.spi.ResourceAdapterInternalException ; 27 import javax.resource.spi.ActivationSpec ; 28 import javax.resource.spi.work.WorkManager ; 29 import javax.resource.spi.work.WorkException ; 30 import javax.resource.spi.endpoint.MessageEndpointFactory ; 31 import javax.resource.ResourceException ; 32 import javax.transaction.xa.XAResource ; 33 34 import org.jboss.resource.adapter.mail.inflow.MailActivation; 35 import org.jboss.resource.adapter.mail.inflow.MailActivationSpec; 36 import org.jboss.resource.adapter.mail.inflow.NewMsgsWorker; 37 import org.jboss.logging.Logger; 38 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 39 40 44 public class MailResourceAdapter 45 implements ResourceAdapter 46 { 47 private static Logger log = Logger.getLogger(MailResourceAdapter.class); 48 49 private BootstrapContext ctx; 50 51 private ConcurrentReaderHashMap activations = new ConcurrentReaderHashMap(); 52 53 private NewMsgsWorker newMsgsWorker; 54 55 60 public WorkManager getWorkManager() 61 { 62 return ctx.getWorkManager(); 63 } 64 65 public void start(BootstrapContext ctx) 67 throws ResourceAdapterInternalException 68 { 69 log.debug("start"); 70 this.ctx = ctx; 71 WorkManager mgr = ctx.getWorkManager(); 72 newMsgsWorker = new NewMsgsWorker(mgr); 73 try 74 { 75 mgr.scheduleWork(newMsgsWorker); 76 } 77 catch (WorkException e) 78 { 79 throw new ResourceAdapterInternalException (e); 80 } 81 } 82 83 public void stop() 84 { 85 log.debug("stop"); 86 newMsgsWorker.release(); 87 } 88 89 public void endpointActivation(MessageEndpointFactory endpointFactory, 90 ActivationSpec spec) 91 throws ResourceException 92 { 93 log.debug("endpointActivation, spec="+spec); 94 MailActivationSpec mailSpec = (MailActivationSpec) spec; 95 MailActivation activation = new MailActivation(this, endpointFactory, 96 mailSpec); 97 try 98 { 99 newMsgsWorker.watch(activation); 100 } 101 catch (InterruptedException e) 102 { 103 throw new ResourceException ("Failed to schedule new msg check", e); 104 } 105 activations.put(spec, activation); 106 } 107 108 public void endpointDeactivation(MessageEndpointFactory endpointFactory, 109 ActivationSpec spec) 110 { 111 log.debug("endpointDeactivation, spec="+spec); 112 MailActivation activation = (MailActivation) activations.remove(spec); 113 if (activation != null) 114 activation.release(); 115 } 116 117 public XAResource [] getXAResources(ActivationSpec [] specs) throws ResourceException 118 { 119 return new XAResource [0]; 120 } 121 123 } 124 | Popular Tags |