1 22 package org.jboss.ejb3.test.jca.inflow; 23 24 import java.util.Iterator ; 25 import java.util.Map ; 26 27 import javax.management.MBeanServer ; 28 import javax.management.ObjectName ; 29 import javax.resource.ResourceException ; 30 import javax.resource.spi.ActivationSpec ; 31 import javax.resource.spi.BootstrapContext ; 32 import javax.resource.spi.ResourceAdapter ; 33 import javax.resource.spi.ResourceAdapterInternalException ; 34 import javax.resource.spi.endpoint.MessageEndpoint ; 35 import javax.resource.spi.endpoint.MessageEndpointFactory ; 36 import javax.transaction.xa.XAResource ; 37 38 import org.jboss.mx.util.MBeanServerLocator; 39 import org.jboss.mx.util.ObjectNameFactory; 40 41 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 42 43 49 public class TestResourceAdapter implements ResourceAdapter , TestResourceAdapterMBean 50 { 51 public static final ObjectName mbean = ObjectNameFactory.create("jboss.test:test=TestResourceAdapter"); 52 53 BootstrapContext ctx; 54 55 ConcurrentReaderHashMap endpoints = new ConcurrentReaderHashMap(); 56 57 public TestResourceAdapterInflowResults testInflow() throws Exception 58 { 59 TestResourceAdapterInflow test = new TestResourceAdapterInflow(this); 60 return test.run(); 61 } 62 63 public TestResourceAdapterWorkManagerResults testWorkManager() throws Exception 64 { 65 TestResourceAdapterWorkManager test = new TestResourceAdapterWorkManager(this); 66 return test.run(); 67 } 68 69 public TestResourceAdapterTimerResults testTimer() throws Exception 70 { 71 TestResourceAdapterTimer test = new TestResourceAdapterTimer(this); 72 return test.run(); 73 } 74 75 public TestResourceAdapterTxInflowResults testTxInflow() throws Exception 76 { 77 TestResourceAdapterTxInflow test = new TestResourceAdapterTxInflow(this); 78 return test.run(); 79 } 80 81 public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) throws ResourceException 82 { 83 MessageEndpoint endpoint = endpointFactory.createEndpoint(null); 84 endpoints.put(spec, endpoint); 85 } 86 87 public void endpointDeactivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) 88 { 89 MessageEndpoint endpoint = (MessageEndpoint ) endpoints.remove(spec); 90 if (endpoint != null) 91 endpoint.release(); 92 } 93 94 public XAResource [] getXAResources(ActivationSpec [] specs) throws ResourceException 95 { 96 return null; 98 } 99 100 public void start(BootstrapContext ctx) throws ResourceAdapterInternalException 101 { 102 this.ctx = ctx; 103 104 try 105 { 106 MBeanServer server = MBeanServerLocator.locateJBoss(); 107 server.registerMBean(this, mbean); 108 } 109 catch (Exception e) 110 { 111 throw new ResourceAdapterInternalException (e); 112 } 113 } 114 115 public void stop() 116 { 117 try 118 { 119 MBeanServer server = MBeanServerLocator.locateJBoss(); 120 server.unregisterMBean(mbean); 121 122 for (Iterator i = endpoints.entrySet().iterator(); i.hasNext();) 123 { 124 Map.Entry entry = (Map.Entry ) i.next(); 125 MessageEndpoint endpoint = (MessageEndpoint ) entry.getValue(); 126 if (endpoint != null) 127 { 128 endpoint.release(); 129 i.remove(); 130 } 131 } 132 } 133 catch (Exception ignored) 134 { 135 } 136 } 137 138 MessageEndpoint getEndpoint(String name) throws Exception 139 { 140 for (Iterator i = endpoints.entrySet().iterator(); i.hasNext();) 141 { 142 Map.Entry entry = (Map.Entry ) i.next(); 143 TestActivationSpec spec = (TestActivationSpec) entry.getKey(); 144 if (name.equals(spec.getName())) 145 return (MessageEndpoint ) entry.getValue(); 146 } 147 throw new Exception ("MessageEndpoint not found for name: " + name); 148 } 149 } 150 | Popular Tags |