PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/testsuite/integration/smoke/src/test/java/org/jboss/as/test/smoke/deployment/rar/MultipleManagedConnection1.java

#
Java | 228 lines | 95 code | 27 blank | 106 comment | 5 complexity | e9cc34c85a93a6113715d4d3c9d102a8 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat Middleware LLC, and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.test.smoke.deployment.rar;
  23. import java.io.PrintWriter;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import java.util.logging.Logger;
  27. import javax.resource.NotSupportedException;
  28. import javax.resource.ResourceException;
  29. import javax.resource.spi.ConnectionEvent;
  30. import javax.resource.spi.ConnectionEventListener;
  31. import javax.resource.spi.ConnectionRequestInfo;
  32. import javax.resource.spi.LocalTransaction;
  33. import javax.resource.spi.ManagedConnection;
  34. import javax.resource.spi.ManagedConnectionMetaData;
  35. import javax.security.auth.Subject;
  36. import javax.transaction.xa.XAResource;
  37. /**
  38. * MultipleManagedConnection1
  39. *
  40. * @version $Revision: $
  41. */
  42. public class MultipleManagedConnection1 implements ManagedConnection
  43. {
  44. /** The logger */
  45. private static Logger log = Logger.getLogger("MultipleManagedConnection1");
  46. /** The logwriter */
  47. private PrintWriter logwriter;
  48. /** ManagedConnectionFactory */
  49. private MultipleManagedConnectionFactory1 mcf;
  50. /** Listeners */
  51. private List<ConnectionEventListener> listeners;
  52. /** Connection */
  53. private Object connection;
  54. /**
  55. * Default constructor
  56. * @param mcf mcf
  57. */
  58. public MultipleManagedConnection1(MultipleManagedConnectionFactory1 mcf)
  59. {
  60. this.mcf = mcf;
  61. this.logwriter = null;
  62. this.listeners = new ArrayList<ConnectionEventListener>(1);
  63. this.connection = null;
  64. }
  65. /**
  66. * Creates a new connection handle for the underlying physical connection
  67. * represented by the ManagedConnection instance.
  68. *
  69. * @param subject Security context as JAAS subject
  70. * @param cxRequestInfo ConnectionRequestInfo instance
  71. * @return generic Object instance representing the connection handle.
  72. * @throws ResourceException generic exception if operation fails
  73. */
  74. public Object getConnection(Subject subject,
  75. ConnectionRequestInfo cxRequestInfo) throws ResourceException
  76. {
  77. log.finest("getConnection()");
  78. connection = new MultipleConnection1Impl(this, mcf);
  79. return connection;
  80. }
  81. /**
  82. * Used by the container to change the association of an
  83. * application-level connection handle with a ManagedConneciton instance.
  84. *
  85. * @param connection Application-level connection handle
  86. * @throws ResourceException generic exception if operation fails
  87. */
  88. public void associateConnection(Object connection) throws ResourceException
  89. {
  90. log.finest("associateConnection()");
  91. }
  92. /**
  93. * Application server calls this method to force any cleanup on the ManagedConnection instance.
  94. *
  95. * @throws ResourceException generic exception if operation fails
  96. */
  97. public void cleanup() throws ResourceException
  98. {
  99. log.finest("cleanup()");
  100. }
  101. /**
  102. * Destroys the physical connection to the underlying resource manager.
  103. *
  104. * @throws ResourceException generic exception if operation fails
  105. */
  106. public void destroy() throws ResourceException
  107. {
  108. log.finest("destroy()");
  109. }
  110. /**
  111. * Adds a connection event listener to the ManagedConnection instance.
  112. *
  113. * @param listener A new ConnectionEventListener to be registered
  114. */
  115. public void addConnectionEventListener(ConnectionEventListener listener)
  116. {
  117. log.finest("addConnectionEventListener()");
  118. if (listener == null)
  119. throw new IllegalArgumentException("Listener is null");
  120. listeners.add(listener);
  121. }
  122. /**
  123. * Removes an already registered connection event listener from the ManagedConnection instance.
  124. *
  125. * @param listener already registered connection event listener to be removed
  126. */
  127. public void removeConnectionEventListener(ConnectionEventListener listener)
  128. {
  129. log.finest("removeConnectionEventListener()");
  130. if (listener == null)
  131. throw new IllegalArgumentException("Listener is null");
  132. listeners.remove(listener);
  133. }
  134. /**
  135. * Close handle
  136. *
  137. * @param handle The handle
  138. */
  139. public void closeHandle(MultipleConnection1 handle)
  140. {
  141. ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
  142. event.setConnectionHandle(handle);
  143. for (ConnectionEventListener cel : listeners)
  144. {
  145. cel.connectionClosed(event);
  146. }
  147. }
  148. /**
  149. * Gets the log writer for this ManagedConnection instance.
  150. *
  151. * @return Character ourput stream associated with this Managed-Connection instance
  152. * @throws ResourceException generic exception if operation fails
  153. */
  154. public PrintWriter getLogWriter() throws ResourceException
  155. {
  156. log.finest("getLogWriter()");
  157. return logwriter;
  158. }
  159. /**
  160. * Sets the log writer for this ManagedConnection instance.
  161. *
  162. * @param out Character Output stream to be associated
  163. * @throws ResourceException generic exception if operation fails
  164. */
  165. public void setLogWriter(PrintWriter out) throws ResourceException
  166. {
  167. log.finest("setLogWriter()");
  168. logwriter = out;
  169. }
  170. /**
  171. * Returns an <code>javax.resource.spi.LocalTransaction</code> instance.
  172. *
  173. * @return LocalTransaction instance
  174. * @throws ResourceException generic exception if operation fails
  175. */
  176. public LocalTransaction getLocalTransaction() throws ResourceException
  177. {
  178. throw new NotSupportedException("LocalTransaction not supported");
  179. }
  180. /**
  181. * Returns an <code>javax.transaction.xa.XAresource</code> instance.
  182. *
  183. * @return XAResource instance
  184. * @throws ResourceException generic exception if operation fails
  185. */
  186. public XAResource getXAResource() throws ResourceException
  187. {
  188. throw new NotSupportedException("GetXAResource not supported not supported");
  189. }
  190. /**
  191. * Gets the metadata information for this connection's underlying EIS resource manager instance.
  192. *
  193. * @return ManagedConnectionMetaData instance
  194. * @throws ResourceException generic exception if operation fails
  195. */
  196. public ManagedConnectionMetaData getMetaData() throws ResourceException
  197. {
  198. log.finest("getMetaData()");
  199. return new MultipleManagedConnectionMetaData();
  200. }
  201. }