1 45 package org.exolab.jms.net.connector; 46 47 import java.util.ArrayList ; 48 import java.util.Collections ; 49 import java.util.Iterator ; 50 import java.util.List ; 51 52 53 59 public class TestAcceptorEventListener 60 implements ManagedConnectionAcceptorListener { 61 62 65 private List _connections = Collections.synchronizedList(new ArrayList ()); 66 67 70 private List _errors = new ArrayList (); 71 72 76 private InvocationHandler _handler = null; 77 78 79 82 public TestAcceptorEventListener() { 83 this(null); 84 } 85 86 92 public TestAcceptorEventListener(InvocationHandler handler) { 93 _handler = handler; 94 } 95 96 102 public void accepted(ManagedConnectionAcceptor acceptor, 103 ManagedConnection connection) { 104 if (_handler != null) { 105 try { 106 connection.setInvocationHandler(_handler); 107 _connections.add(connection); 108 } catch (ResourceException exception) { 109 _errors.add(exception); 110 try { 111 connection.destroy(); 112 } catch (ResourceException ignore) { 113 } 115 } 116 } else { 117 _connections.add(connection); 118 } 119 } 120 121 127 public void error(ManagedConnectionAcceptor acceptor, 128 Throwable throwable) { 129 _errors.add(throwable); 130 try { 131 acceptor.close(); 132 } catch (ResourceException ignore) { 133 } 134 } 135 136 141 public List getConnections() { 142 return _connections; 143 } 144 145 151 public ManagedConnection getConnection() { 152 ManagedConnection result = null; 153 synchronized (_connections) { 154 if (!_connections.isEmpty()) { 155 result = (ManagedConnection) _connections.get(0); 156 } 157 } 158 return result; 159 } 160 161 167 public List getErrors() { 168 return _errors; 169 } 170 171 176 public void destroy() throws ResourceException { 177 Iterator iterator = _connections.iterator(); 178 while (iterator.hasNext()) { 179 ManagedConnection connection = (ManagedConnection) iterator.next(); 180 connection.destroy(); 181 } 182 } 183 184 } 185 | Popular Tags |