1 22 package org.jboss.test.deployers.rar.mcf1; 23 24 import java.io.PrintWriter ; 25 import java.util.Iterator ; 26 27 import javax.resource.ResourceException ; 28 import javax.resource.spi.ConnectionEvent ; 29 import javax.resource.spi.ConnectionEventListener ; 30 import javax.resource.spi.ConnectionRequestInfo ; 31 import javax.resource.spi.LocalTransaction ; 32 import javax.resource.spi.ManagedConnection ; 33 import javax.resource.spi.ManagedConnectionMetaData ; 34 import javax.security.auth.Subject ; 35 import javax.transaction.xa.XAResource ; 36 37 import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArraySet; 38 import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean; 39 40 public class MCF1ManagedConnection implements ManagedConnection , LocalTransaction 41 { 42 private SynchronizedBoolean destroyed = new SynchronizedBoolean(false); 43 private CopyOnWriteArraySet connections = new CopyOnWriteArraySet(); 44 private CopyOnWriteArraySet listeners = new CopyOnWriteArraySet(); 45 47 public MCF1ManagedConnection(MCF1ManagedConnectionFactory mcf) 48 { 49 } 51 52 public void addConnectionEventListener(ConnectionEventListener listener) 53 { 54 checkDestroyed(); 55 listeners.add(listener); 56 } 57 58 public void associateConnection(Object connection) throws ResourceException 59 { 60 checkDestroyed(); 61 if (connection instanceof MCF1ConnectionImpl) 62 throw new ResourceException ("Wrong object"); 63 ((MCF1ConnectionImpl) connection).setManagedConnection(this); 64 connections.add(connection); 65 } 66 67 public void cleanup() throws ResourceException 68 { 69 for (Iterator i = connections.iterator(); i.hasNext();) 70 { 71 MCF1ConnectionImpl connection = (MCF1ConnectionImpl) i.next(); 72 connection.setManagedConnection(null); 73 } 74 connections.clear(); 75 } 76 77 public void destroy() throws ResourceException 78 { 79 destroyed.set(true); 80 cleanup(); 81 } 82 83 public Object getConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException 84 { 85 MCF1ConnectionImpl connection = new MCF1ConnectionImpl(); 86 connection.setManagedConnection(this); 87 return connection; 88 } 89 90 public LocalTransaction getLocalTransaction() throws ResourceException 91 { 92 return this; 93 } 94 95 public PrintWriter getLogWriter() throws ResourceException 96 { 97 return null; 98 } 99 100 public ManagedConnectionMetaData getMetaData() throws ResourceException 101 { 102 return null; 103 } 104 105 public XAResource getXAResource() throws ResourceException 106 { 107 return null; 108 } 109 110 public void removeConnectionEventListener(ConnectionEventListener listener) 111 { 112 listeners.remove(listener); 113 } 114 115 public void setLogWriter(PrintWriter out) throws ResourceException 116 { 117 } 118 119 public void begin() throws ResourceException 120 { 121 } 122 123 public void commit() throws ResourceException 124 { 125 } 126 127 public void rollback() throws ResourceException 128 { 129 } 130 131 protected void checkDestroyed() 132 { 133 if (destroyed.get()) 134 throw new IllegalStateException ("Destroyed"); 135 } 136 137 void closeHandle(MCF1ConnectionImpl connection) 138 { 139 if (destroyed.get()) 140 return; 141 142 connections.remove(connection); 143 144 ConnectionEvent ce = new ConnectionEvent (this, ConnectionEvent.CONNECTION_CLOSED); 145 ce.setConnectionHandle(connection); 146 for (Iterator i = listeners.iterator(); i.hasNext();) 147 { 148 ConnectionEventListener listener = (ConnectionEventListener ) i.next(); 149 listener.connectionClosed(ce); 150 } 151 } 152 } 153 | Popular Tags |