1 22 package org.jboss.resource.adapter.jms; 23 24 import java.util.Iterator ; 25 import java.util.Map ; 26 27 import javax.resource.ResourceException ; 28 import javax.resource.spi.ActivationSpec ; 29 import javax.resource.spi.BootstrapContext ; 30 import javax.resource.spi.ResourceAdapter ; 31 import javax.resource.spi.ResourceAdapterInternalException ; 32 import javax.resource.spi.XATerminator ; 33 import javax.resource.spi.endpoint.MessageEndpointFactory ; 34 import javax.resource.spi.work.WorkManager ; 35 import javax.transaction.xa.XAResource ; 36 37 import org.jboss.logging.Logger; 38 import org.jboss.resource.adapter.jms.inflow.JmsActivation; 39 import org.jboss.resource.adapter.jms.inflow.JmsActivationSpec; 40 41 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 42 43 49 public class JmsResourceAdapter implements ResourceAdapter 50 { 51 52 private static final Logger log = Logger.getLogger(JmsResourceAdapter.class); 53 54 55 private BootstrapContext ctx; 56 57 58 private ConcurrentReaderHashMap activations = new ConcurrentReaderHashMap(); 59 60 65 public WorkManager getWorkManager() 66 { 67 return ctx.getWorkManager(); 68 } 69 70 public XATerminator getTerminator() 71 { 72 return ctx.getXATerminator(); 73 } 74 public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) throws ResourceException 75 { 76 JmsActivation activation = new JmsActivation(this, endpointFactory, (JmsActivationSpec) spec); 77 activations.put(spec, activation); 78 activation.start(); 79 } 80 81 public void endpointDeactivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) 82 { 83 JmsActivation activation = (JmsActivation) activations.remove(spec); 84 if (activation != null) 85 activation.stop(); 86 } 87 88 public XAResource [] getXAResources(ActivationSpec [] specs) throws ResourceException 89 { 90 return null; 92 } 93 94 public void start(BootstrapContext ctx) throws ResourceAdapterInternalException 95 { 96 this.ctx = ctx; 97 } 98 99 public void stop() 100 { 101 for (Iterator i = activations.entrySet().iterator(); i.hasNext();) 102 { 103 Map.Entry entry = (Map.Entry ) i.next(); 104 try 105 { 106 JmsActivation activation = (JmsActivation) entry.getValue(); 107 if (activation != null) 108 activation.stop(); 109 } 110 catch (Exception ignored) 111 { 112 log.debug("Ignored", ignored); 113 } 114 i.remove(); 115 } 116 } 117 } 118 | Popular Tags |