PageRenderTime 39ms CodeModel.GetById 26ms app.highlight 12ms 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 */
 22package org.jboss.as.test.smoke.deployment.rar;
 23
 24import java.io.PrintWriter;
 25
 26import java.util.ArrayList;
 27import java.util.List;
 28import java.util.logging.Logger;
 29
 30import javax.resource.NotSupportedException;
 31import javax.resource.ResourceException;
 32import javax.resource.spi.ConnectionEvent;
 33import javax.resource.spi.ConnectionEventListener;
 34import javax.resource.spi.ConnectionRequestInfo;
 35import javax.resource.spi.LocalTransaction;
 36import javax.resource.spi.ManagedConnection;
 37import javax.resource.spi.ManagedConnectionMetaData;
 38
 39import javax.security.auth.Subject;
 40import javax.transaction.xa.XAResource;
 41
 42/**
 43 * MultipleManagedConnection1
 44 *
 45 * @version $Revision: $
 46 */
 47public class MultipleManagedConnection1 implements ManagedConnection
 48{
 49
 50   /** The logger */
 51   private static Logger log = Logger.getLogger("MultipleManagedConnection1");
 52
 53   /** The logwriter */
 54   private PrintWriter logwriter;
 55
 56   /** ManagedConnectionFactory */
 57   private MultipleManagedConnectionFactory1 mcf;
 58
 59   /** Listeners */
 60   private List<ConnectionEventListener> listeners;
 61
 62   /** Connection */
 63   private Object connection;
 64
 65   /**
 66    * Default constructor
 67    * @param mcf mcf
 68    */
 69   public MultipleManagedConnection1(MultipleManagedConnectionFactory1 mcf)
 70   {
 71      this.mcf = mcf;
 72      this.logwriter = null;
 73      this.listeners = new ArrayList<ConnectionEventListener>(1);
 74      this.connection = null;
 75   }
 76
 77   /**
 78    * Creates a new connection handle for the underlying physical connection
 79    * represented by the ManagedConnection instance.
 80    *
 81    * @param subject Security context as JAAS subject
 82    * @param cxRequestInfo ConnectionRequestInfo instance
 83    * @return generic Object instance representing the connection handle.
 84    * @throws ResourceException generic exception if operation fails
 85    */
 86   public Object getConnection(Subject subject,
 87      ConnectionRequestInfo cxRequestInfo) throws ResourceException
 88   {
 89      log.finest("getConnection()");
 90      connection = new MultipleConnection1Impl(this, mcf);
 91      return connection;
 92   }
 93
 94   /**
 95    * Used by the container to change the association of an
 96    * application-level connection handle with a ManagedConneciton instance.
 97    *
 98    * @param connection Application-level connection handle
 99    * @throws ResourceException generic exception if operation fails
100    */
101   public void associateConnection(Object connection) throws ResourceException
102   {
103      log.finest("associateConnection()");
104   }
105
106   /**
107    * Application server calls this method to force any cleanup on the ManagedConnection instance.
108    *
109    * @throws ResourceException generic exception if operation fails
110    */
111   public void cleanup() throws ResourceException
112
113   {
114      log.finest("cleanup()");
115   }
116
117   /**
118    * Destroys the physical connection to the underlying resource manager.
119    *
120    * @throws ResourceException generic exception if operation fails
121    */
122   public void destroy() throws ResourceException
123   {
124      log.finest("destroy()");
125   }
126
127   /**
128    * Adds a connection event listener to the ManagedConnection instance.
129    *
130    * @param listener A new ConnectionEventListener to be registered
131    */
132   public void addConnectionEventListener(ConnectionEventListener listener)
133   {
134      log.finest("addConnectionEventListener()");
135      if (listener == null)
136         throw new IllegalArgumentException("Listener is null");
137      listeners.add(listener);
138   }
139
140   /**
141    * Removes an already registered connection event listener from the ManagedConnection instance.
142    *
143    * @param listener already registered connection event listener to be removed
144    */
145   public void removeConnectionEventListener(ConnectionEventListener listener)
146   {
147      log.finest("removeConnectionEventListener()");
148      if (listener == null)
149         throw new IllegalArgumentException("Listener is null");
150      listeners.remove(listener);
151   }
152
153   /**
154    * Close handle
155    *
156    * @param handle The handle
157    */
158   public void closeHandle(MultipleConnection1 handle)
159   {
160      ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
161      event.setConnectionHandle(handle);
162      for (ConnectionEventListener cel : listeners)
163      {
164         cel.connectionClosed(event);
165      }
166
167   }
168
169   /**
170    * Gets the log writer for this ManagedConnection instance.
171    *
172    * @return Character ourput stream associated with this Managed-Connection instance
173    * @throws ResourceException generic exception if operation fails
174    */
175   public PrintWriter getLogWriter() throws ResourceException
176   {
177      log.finest("getLogWriter()");
178      return logwriter;
179   }
180
181   /**
182    * Sets the log writer for this ManagedConnection instance.
183    *
184    * @param out Character Output stream to be associated
185    * @throws ResourceException  generic exception if operation fails
186    */
187   public void setLogWriter(PrintWriter out) throws ResourceException
188   {
189      log.finest("setLogWriter()");
190      logwriter = out;
191   }
192
193   /**
194    * Returns an <code>javax.resource.spi.LocalTransaction</code> instance.
195    *
196    * @return LocalTransaction instance
197    * @throws ResourceException generic exception if operation fails
198    */
199   public LocalTransaction getLocalTransaction() throws ResourceException
200   {
201      throw new NotSupportedException("LocalTransaction not supported");
202   }
203
204   /**
205    * Returns an <code>javax.transaction.xa.XAresource</code> instance.
206    *
207    * @return XAResource instance
208    * @throws ResourceException generic exception if operation fails
209    */
210   public XAResource getXAResource() throws ResourceException
211   {
212      throw new NotSupportedException("GetXAResource not supported not supported");
213   }
214
215   /**
216    * Gets the metadata information for this connection's underlying EIS resource manager instance.
217    *
218    * @return ManagedConnectionMetaData instance
219    * @throws ResourceException generic exception if operation fails
220    */
221   public ManagedConnectionMetaData getMetaData() throws ResourceException
222   {
223      log.finest("getMetaData()");
224      return new MultipleManagedConnectionMetaData();
225   }
226
227
228}