geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound ManagedConnectionFactoryWrapperTest.java ConnectionManagerTest.java
Date Tue, 09 Mar 2004 18:02:03 GMT
djencks     2004/03/09 10:02:03

  Modified:    modules/connector/src/java/org/apache/geronimo/connector
                        AdminObjectWrapper.java
               modules/connector/src/java/org/apache/geronimo/connector/deployment
                        AbstractRARConfigBuilder.java
                        RAR_1_0ConfigBuilder.java RAR_1_5ConfigBuilder.java
               modules/connector/src/java/org/apache/geronimo/connector/outbound
                        ConnectionManagerDeployment.java
                        ConnectionManagerFactory.java
                        ManagedConnectionFactoryWrapper.java
               modules/connector/src/test/org/apache/geronimo/connector/outbound
                        ConnectionManagerTest.java
  Added:       modules/connector/src/java/org/apache/geronimo/connector/outbound
                        CFMethodInterceptor.java
               modules/connector/src/test/org/apache/geronimo/connector/outbound
                        ManagedConnectionFactoryWrapperTest.java
  Removed:     modules/connector/src/java/org/apache/geronimo/connector/outbound
                        ProxyConnectionManager.java
  Log:
  introduce proxies to connection factories
  
  Revision  Changes    Path
  1.3       +19 -8     incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/AdminObjectWrapper.java
  
  Index: AdminObjectWrapper.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/AdminObjectWrapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AdminObjectWrapper.java	25 Feb 2004 09:57:09 -0000	1.2
  +++ AdminObjectWrapper.java	9 Mar 2004 18:02:02 -0000	1.3
  @@ -17,11 +17,9 @@
   
   package org.apache.geronimo.connector;
   
  +import org.apache.geronimo.gbean.DynamicGBeanDelegate;
   import org.apache.geronimo.gbean.GBeanInfo;
   import org.apache.geronimo.gbean.GBeanInfoFactory;
  -import org.apache.geronimo.gbean.GConstructorInfo;
  -import org.apache.geronimo.gbean.GAttributeInfo;
  -import org.apache.geronimo.gbean.DynamicGBeanDelegate;
   
   /**
    *
  @@ -37,34 +35,47 @@
   
       private final DynamicGBeanDelegate delegate;
       private final Object adminObject;
  +    private final String name;
   
       //for use as endpoint
       public AdminObjectWrapper() {
           adminObjectClass = null;
           adminObject = null;
           delegate = null;
  +        name = null;
       }
   
  -    public AdminObjectWrapper(Class adminObjectClass) throws IllegalAccessException, InstantiationException
{
  +    public AdminObjectWrapper(Class adminObjectClass, String name) throws IllegalAccessException,
InstantiationException {
           this.adminObjectClass = adminObjectClass;
           adminObject = adminObjectClass.newInstance();
           delegate = new DynamicGBeanDelegate();
           delegate.addAll(adminObject);
  +        this.name = name;
       }
   
       public Class getAdminObjectClass() {
           return adminObjectClass;
       }
   
  +    public Object getProxy() {
  +        return adminObject;
  +    }
  +
  +    public Object getId() {
  +        return name;
  +    }
  +
       static {
           GBeanInfoFactory infoFactory = new GBeanInfoFactory(AdminObjectWrapper.class.getName());
  -        infoFactory.addAttribute(new GAttributeInfo("AdminObjectClass", true));
  -        infoFactory.setConstructor(new GConstructorInfo(new String[] {"AdminObjectClass"},
  -                new Class[] {Class.class}));
  +        infoFactory.addAttribute("AdminObjectClass", true);
  +        infoFactory.addAttribute("Name", true);
  +        infoFactory.setConstructor(new String[] {"AdminObjectClass", "Name"},
  +                new Class[] {Class.class, String.class});
           GBEAN_INFO = infoFactory.getBeanInfo();
       }
   
       public static GBeanInfo getGBeanInfo() {
           return GBEAN_INFO;
       }
  +
   }
  
  
  
  1.7       +1 -3      incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/AbstractRARConfigBuilder.java
  
  Index: AbstractRARConfigBuilder.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/AbstractRARConfigBuilder.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractRARConfigBuilder.java	1 Mar 2004 20:50:07 -0000	1.6
  +++ AbstractRARConfigBuilder.java	9 Mar 2004 18:02:02 -0000	1.7
  @@ -66,10 +66,8 @@
   
       public final static String BASE_RESOURCE_ADAPTER_NAME = "geronimo.management:J2eeType=ResourceAdapter,name=";
       protected final static String BASE_CONNECTION_MANAGER_FACTORY_NAME = "geronimo.management:J2eeType=ConnectionManager,name=";
  -    protected static final String BASE_MANAGED_CONNECTION_FACTORY_NAME = "geronimo.management:J2eeType=ManagedConnectionFactory,name=";
       protected static final String BASE_REALM_BRIDGE_NAME = "geronimo.security:service=RealmBridge,name=";
       private static final String BASE_PASSWORD_CREDENTIAL_LOGIN_MODULE_NAME = "geronimo.security:service=Realm,type=PasswordCredential,name=";
  -    protected static final String BASE_ADMIN_OBJECT_NAME = "geronimo.management:service=AdminObject,name=";
   
       protected final Repository repository;
       protected final Kernel kernel;
  
  
  
  1.4       +10 -8     incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilder.java
  
  Index: RAR_1_0ConfigBuilder.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RAR_1_0ConfigBuilder.java	28 Feb 2004 10:08:47 -0000	1.3
  +++ RAR_1_0ConfigBuilder.java	9 Mar 2004 18:02:02 -0000	1.4
  @@ -55,6 +55,7 @@
   import org.apache.geronimo.xbeans.j2ee.connector_1_0.ConfigPropertyType;
   import org.apache.geronimo.xbeans.j2ee.connector_1_0.ConnectorDocument;
   import org.apache.geronimo.xbeans.j2ee.connector_1_0.ResourceadapterType;
  +import org.apache.geronimo.naming.jmx.JMXReferenceFactory;
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlObject;
   import org.apache.xmlbeans.XmlOptions;
  @@ -120,7 +121,6 @@
                       connectionManagerFactoryGBean.setAttribute("UseTransactionCaching",
Boolean.valueOf(connectionManagerFactory.getUseTransactionCaching()));
                       connectionManagerFactoryGBean.setAttribute("UseConnectionRequestInfo",
Boolean.valueOf(connectionManagerFactory.getUseConnectionRequestInfo()));
                       connectionManagerFactoryGBean.setAttribute("UseSubject", Boolean.valueOf(connectionManagerFactory.getUseSubject()));
  -                    connectionManagerFactoryGBean.setReferencePatterns("Kernel", Collections.singleton(Kernel.KERNEL));
                       connectionManagerFactoryGBean.setReferencePatterns("ConnectionTracker",
Collections.singleton(connectionTrackerNamePattern));
                       if (connectionManagerFactory.getRealmBridge() != null) {
                           connectionManagerFactoryGBean.setReferencePatterns("RealmBridge",
Collections.singleton(ObjectName.getInstance(BASE_REALM_BRIDGE_NAME + connectionManagerFactory.getRealmBridge())));
  @@ -136,6 +136,12 @@
                   }
                   context.addGBean(connectionManagerFactoryObjectName, connectionManagerFactoryGBean);
                   //ManagedConnectionFactory
  +                ObjectName managedConnectionFactoryObjectName = null;
  +                try {
  +                    managedConnectionFactoryObjectName = ObjectName.getInstance(JMXReferenceFactory.BASE_MANAGED_CONNECTION_FACTORY_NAME
+ gerConnectionfactoryInstance.getName());
  +                } catch (MalformedObjectNameException e) {
  +                    throw new DeploymentException("Could not construct ManagedConnectionFactory
object name", e);
  +                }
                   GBeanInfoFactory managedConnectionFactoryInfoFactory = new GBeanInfoFactory(ManagedConnectionFactoryWrapper.class.getName(),
ManagedConnectionFactoryWrapper.getGBeanInfo());
                   GBeanMBean managedConnectionFactoryGBean = setUpDynamicGBean(managedConnectionFactoryInfoFactory,
resourceAdapter.getConfigPropertyArray(), gerConnectionfactoryInstance.getConfigPropertySettingArray());
                   try {
  @@ -152,14 +158,10 @@
                           managedConnectionFactoryGBean.setReferencePatterns("ManagedConnectionFactoryListener",
Collections.singleton(ObjectName.getInstance(BASE_PASSWORD_CREDENTIAL_LOGIN_MODULE_NAME +
geronimoConnectionDefinition.getName())));
                       }
                       */
  +                    managedConnectionFactoryGBean.setReferencePatterns("Kernel", Collections.singleton(Kernel.KERNEL));
  +                    managedConnectionFactoryGBean.setAttribute("SelfName", managedConnectionFactoryObjectName);
                   } catch (Exception e) {
                       throw new DeploymentException(e);
  -                }
  -                ObjectName managedConnectionFactoryObjectName = null;
  -                try {
  -                    managedConnectionFactoryObjectName = ObjectName.getInstance(BASE_MANAGED_CONNECTION_FACTORY_NAME
+ gerConnectionfactoryInstance.getName());
  -                } catch (MalformedObjectNameException e) {
  -                    throw new DeploymentException("Could not construct ManagedConnectionFactory
object name", e);
                   }
                   context.addGBean(managedConnectionFactoryObjectName, managedConnectionFactoryGBean);
   
  
  
  
  1.4       +12 -10    incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/RAR_1_5ConfigBuilder.java
  
  Index: RAR_1_5ConfigBuilder.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/RAR_1_5ConfigBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RAR_1_5ConfigBuilder.java	28 Feb 2004 10:08:47 -0000	1.3
  +++ RAR_1_5ConfigBuilder.java	9 Mar 2004 18:02:02 -0000	1.4
  @@ -64,6 +64,7 @@
   import org.apache.geronimo.xbeans.j2ee.ConnectorDocument;
   import org.apache.geronimo.xbeans.j2ee.ConnectorType;
   import org.apache.geronimo.xbeans.j2ee.ResourceadapterType;
  +import org.apache.geronimo.naming.jmx.JMXReferenceFactory;
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlObject;
   import org.apache.xmlbeans.XmlOptions;
  @@ -167,7 +168,6 @@
                       connectionManagerFactoryGBean.setAttribute("UseTransactionCaching",
Boolean.valueOf(connectionManagerFactory.getUseTransactionCaching()));
                       connectionManagerFactoryGBean.setAttribute("UseConnectionRequestInfo",
Boolean.valueOf(connectionManagerFactory.getUseConnectionRequestInfo()));
                       connectionManagerFactoryGBean.setAttribute("UseSubject", Boolean.valueOf(connectionManagerFactory.getUseSubject()));
  -                    connectionManagerFactoryGBean.setReferencePatterns("Kernel", Collections.singleton(Kernel.KERNEL));
                       connectionManagerFactoryGBean.setReferencePatterns("ConnectionTracker",
Collections.singleton(connectionTrackerNamePattern));
                       if (connectionManagerFactory.getRealmBridge() != null) {
                           connectionManagerFactoryGBean.setReferencePatterns("RealmBridge",
Collections.singleton(ObjectName.getInstance(BASE_REALM_BRIDGE_NAME + connectionManagerFactory.getRealmBridge())));
  @@ -184,6 +184,12 @@
                   context.addGBean(connectionManagerFactoryObjectName, connectionManagerFactoryGBean);
                   //ManagedConnectionFactory
   
  +                ObjectName managedConnectionFactoryObjectName = null;
  +                try {
  +                    managedConnectionFactoryObjectName = ObjectName.getInstance(JMXReferenceFactory.BASE_MANAGED_CONNECTION_FACTORY_NAME
+ connectionfactoryInstance.getName());
  +                } catch (MalformedObjectNameException e) {
  +                    throw new DeploymentException("Could not construct ManagedConnectionFactory
object name", e);
  +                }
                   GBeanInfoFactory managedConnectionFactoryInfoFactory = new GBeanInfoFactory(ManagedConnectionFactoryWrapper.class.getName(),
ManagedConnectionFactoryWrapper.getGBeanInfo());
                   GBeanMBean managedConnectionFactoryGBean = setUpDynamicGBean(managedConnectionFactoryInfoFactory,
connectionDefinition.getConfigPropertyArray(), connectionfactoryInstance.getConfigPropertySettingArray());
                   try {
  @@ -203,15 +209,11 @@
                           managedConnectionFactoryGBean.setReferencePatterns("ManagedConnectionFactoryListener",
Collections.singleton(ObjectName.getInstance(BASE_PASSWORD_CREDENTIAL_LOGIN_MODULE_NAME +
geronimoConnectionDefinition.getName())));
                       }
                       */
  -                } catch (Exception e) {
  +                    managedConnectionFactoryGBean.setReferencePatterns("Kernel", Collections.singleton(Kernel.KERNEL));
  +                    managedConnectionFactoryGBean.setAttribute("SelfName", managedConnectionFactoryObjectName);
  +                  } catch (Exception e) {
                       throw new DeploymentException(e);
                   }
  -                ObjectName managedConnectionFactoryObjectName = null;
  -                try {
  -                    managedConnectionFactoryObjectName = ObjectName.getInstance(BASE_MANAGED_CONNECTION_FACTORY_NAME
+ connectionfactoryInstance.getName());
  -                } catch (MalformedObjectNameException e) {
  -                    throw new DeploymentException("Could not construct ManagedConnectionFactory
object name", e);
  -                }
                   context.addGBean(managedConnectionFactoryObjectName, managedConnectionFactoryGBean);
               }
   
  @@ -232,7 +234,7 @@
                   GBeanMBean adminObjectGBean = setUpDynamicGBean(adminObjectInfoFactory,
adminobject.getConfigPropertyArray(), gerAdminobjectInstance.getConfigPropertySettingArray());
                   ObjectName adminObjectObjectName = null;
                   try {
  -                    adminObjectObjectName = ObjectName.getInstance(BASE_ADMIN_OBJECT_NAME
+ gerAdminobjectInstance.getAdminobjectName());
  +                    adminObjectObjectName = ObjectName.getInstance(JMXReferenceFactory.BASE_ADMIN_OBJECT_NAME
+ gerAdminobjectInstance.getAdminobjectName());
                   } catch (MalformedObjectNameException e) {
                       throw new DeploymentException("Could not construct ManagedConnectionFactory
object name", e);
                   }
  
  
  
  1.5       +61 -65    incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerDeployment.java
  
  Index: ConnectionManagerDeployment.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerDeployment.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConnectionManagerDeployment.java	25 Feb 2004 09:57:10 -0000	1.4
  +++ ConnectionManagerDeployment.java	9 Mar 2004 18:02:03 -0000	1.5
  @@ -17,11 +17,13 @@
   
   package org.apache.geronimo.connector.outbound;
   
  -import javax.management.MBeanServer;
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
   import javax.resource.ResourceException;
   import javax.resource.spi.ManagedConnectionFactory;
  +import javax.resource.spi.ConnectionManager;
  +import javax.resource.spi.LazyAssociatableConnectionManager;
  +import javax.resource.spi.ConnectionRequestInfo;
   
   import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
   import org.apache.geronimo.gbean.GAttributeInfo;
  @@ -30,8 +32,8 @@
   import org.apache.geronimo.gbean.GBeanInfo;
   import org.apache.geronimo.gbean.GBeanInfoFactory;
   import org.apache.geronimo.gbean.GConstructorInfo;
  -import org.apache.geronimo.gbean.GReferenceInfo;
   import org.apache.geronimo.gbean.GOperationInfo;
  +import org.apache.geronimo.gbean.GReferenceInfo;
   import org.apache.geronimo.kernel.KernelMBean;
   import org.apache.geronimo.security.bridge.RealmBridge;
   
  @@ -42,19 +44,10 @@
    *
    * @version $Revision$ $Date$
    * */
  -public class ConnectionManagerDeployment implements ConnectionManagerFactory, GBean {
  +public class ConnectionManagerDeployment implements ConnectionManagerFactory, GBean, ConnectionManager,
LazyAssociatableConnectionManager {
   
       public static final GBeanInfo GBEAN_INFO;
   
  -    private final static String MBEAN_SERVER_DELEGATE =
  -            "JMImplementation:type=MBeanServerDelegate";
  -
  -    /**
  -     * The original Serializable ProxyConnectionManager that provides the
  -     * ConnectionManager implementation.
  -     */
  -    private ProxyConnectionManager cm;
  -
       //connection manager configuration choices
       private boolean useConnectionRequestInfo;
       private boolean useSubject;
  @@ -70,23 +63,22 @@
       //dependencies
       private RealmBridge realmBridge;
       private ConnectionTracker connectionTracker;
  -    private KernelMBean kernel;
  +
  +    private ConnectionInterceptor stack;
   
       //default constructor for use as endpoint
       public ConnectionManagerDeployment() {
       }
   
       public ConnectionManagerDeployment(boolean useConnectionRequestInfo,
  -            boolean useSubject,
  -            boolean useTransactionCaching,
  -            boolean useLocalTransactions,
  -            boolean useTransactions,
  -            int maxSize,
  -            int blockingTimeout,
  -            String name,
  -            RealmBridge realmBridge,
  -            ConnectionTracker connectionTracker,
  -            KernelMBean kernel) {
  +                                       boolean useSubject,
  +                                       boolean useTransactionCaching,
  +                                       boolean useLocalTransactions,
  +                                       boolean useTransactions,
  +                                       int maxSize,
  +                                       int blockingTimeout,
  +                                       RealmBridge realmBridge,
  +                                       ConnectionTracker connectionTracker) {
           this.useConnectionRequestInfo = useConnectionRequestInfo;
           this.useLocalTransactions = useLocalTransactions;
           this.useSubject = useSubject;
  @@ -95,37 +87,14 @@
           this.maxSize = maxSize;
           this.blockingTimeout = blockingTimeout;
           this.realmBridge = realmBridge;
  -        this.name = name;
           this.connectionTracker = connectionTracker;
  -        this.kernel = kernel;
       }
   
       public void setGBeanContext(GBeanContext context) {
       }
   
       public void doStart() {
  -        MBeanServer mbeanServer = null;
  -        if (kernel != null) {
  -            mbeanServer = kernel.getMBeanServer();
  -        } else {
  -            throw new IllegalStateException("Neither kernel nor context is set, but you're
trying to start");
  -        }
  -
  -        String agentID;
  -        try {
  -            ObjectName name = ObjectName.getInstance(MBEAN_SERVER_DELEGATE);
  -            agentID = (String) mbeanServer.getAttribute(name, "MBeanServerId");
  -        } catch (Exception e) {
  -            throw new RuntimeException("Problem getting agentID from MBeanServerDelegate",
e);
  -        }
  -
  -        ObjectName connectionManagerName = null;
  -        try {
  -            connectionManagerName = ObjectName.getInstance("geronimo.management:j2eeType=ConnectionManager,name="
+ name);
  -        } catch (MalformedObjectNameException e) {
  -            throw new RuntimeException("could not construct an object name for ConnectionManagerDeployment
mbean", e);
  -        }
  -        setUpConnectionManager(agentID, connectionManagerName);
  +        setUpConnectionManager();
   
       }
   
  @@ -141,7 +110,7 @@
        * LocalXAResourceInsertionInterceptor or XAResourceInsertionInterceptor (useTransactions
(&localTransactions))
        * MCFConnectionInterceptor
        */
  -    private void setUpConnectionManager(String agentID, ObjectName connectionManagerName)
{
  +    private void setUpConnectionManager() {
           //check for consistency between attributes
           if (realmBridge == null) {
               assert useSubject == false: "To use Subject in pooling, you need a SecurityDomain";
  @@ -188,26 +157,21 @@
                       connectionTracker,
                       realmBridge);
           }
  -
  -        cm = new ProxyConnectionManager(agentID, connectionManagerName, stack);
  +        this.stack = stack;
       }
   
       public void doStop() {
  -        cm = null;
           realmBridge = null;
           connectionTracker = null;
  +        stack = null;
       }
   
       public void doFail() {
       }
   
  -    public ConnectionInterceptor getStack() {
  -        return cm.getStack();
  -    }
  -
   
       public Object createConnectionFactory(ManagedConnectionFactory mcf) throws ResourceException
{
  -        return mcf.createConnectionFactory(cm);
  +        return mcf.createConnectionFactory(this);
       }
   
       public int getBlockingTimeout() {
  @@ -293,12 +257,46 @@
           this.useTransactionCaching = useTransactionCaching;
       }
   
  -    public KernelMBean getKernel() {
  -        return kernel;
  +    /**
  +     * in: mcf != null, is a deployed mcf
  +     * out: useable connection object.
  +     * @param managedConnectionFactory
  +     * @param connectionRequestInfo
  +     * @return
  +     * @throws ResourceException
  +     */
  +    public Object allocateConnection(
  +            ManagedConnectionFactory managedConnectionFactory,
  +            ConnectionRequestInfo connectionRequestInfo)
  +            throws ResourceException {
  +        ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory,
connectionRequestInfo);
  +        ConnectionInfo ci = new ConnectionInfo(mci);
  +        stack.getConnection(ci);
  +        return ci.getConnectionHandle();
  +    }
  +
  +    /**
  +     * in: non-null connection object, from non-null mcf.
  +     * connection object is not associated with a managed connection
  +     * out: supplied connection object is assiciated with a non-null ManagedConnection
from mcf.
  +     * @param connection
  +     * @param managedConnectionFactory
  +     * @param connectionRequestInfo
  +     * @throws ResourceException
  +     */
  +    public void associateConnection(
  +            Object connection,
  +            ManagedConnectionFactory managedConnectionFactory,
  +            ConnectionRequestInfo connectionRequestInfo)
  +            throws ResourceException {
  +        ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory,
connectionRequestInfo);
  +        ConnectionInfo ci = new ConnectionInfo(mci);
  +        ci.setConnectionHandle(connection);
  +        stack.getConnection(ci);
       }
   
  -    public void setKernel(KernelMBean kernel) {
  -        this.kernel = kernel;
  +    ConnectionInterceptor getStack() {
  +        return stack;
       }
   
       static {
  @@ -313,18 +311,16 @@
           infoFactory.addAttribute(new GAttributeInfo("UseConnectionRequestInfo", true));
           infoFactory.addAttribute(new GAttributeInfo("UseSubject", true));
   
  -        infoFactory.addOperation(new GOperationInfo("getStack"));
           infoFactory.addOperation(new GOperationInfo("createConnectionFactory", new String[]{ManagedConnectionFactory.class.getName()}));
   
           infoFactory.addReference(new GReferenceInfo("ConnectionTracker", ConnectionTracker.class.getName()));
           infoFactory.addReference(new GReferenceInfo("RealmBridge", RealmBridge.class.getName()));
  -        infoFactory.addReference(new GReferenceInfo("Kernel", KernelMBean.class.getName()));
   
           infoFactory.setConstructor(new GConstructorInfo(
                   new String[]{"UseConnectionRequestInfo", "UseSubject", "UseTransactionCaching",
"UseLocalTransactions", "UseTransactions",
  -                             "MaxSize", "BlockingTimeout", "Name", "RealmBridge", "ConnectionTracker",
"Kernel"},
  +                             "MaxSize", "BlockingTimeout", "RealmBridge", "ConnectionTracker"},
                   new Class[]{Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE,
  -                            Integer.TYPE, Integer.TYPE, String.class, RealmBridge.class,
ConnectionTracker.class, KernelMBean.class}));
  +                            Integer.TYPE, Integer.TYPE, RealmBridge.class, ConnectionTracker.class}));
           GBEAN_INFO = infoFactory.getBeanInfo();
       }
   
  
  
  
  1.3       +3 -1      incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerFactory.java
  
  Index: ConnectionManagerFactory.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConnectionManagerFactory.java	25 Feb 2004 09:57:10 -0000	1.2
  +++ ConnectionManagerFactory.java	9 Mar 2004 18:02:03 -0000	1.3
  @@ -29,4 +29,6 @@
   
       Object createConnectionFactory(ManagedConnectionFactory mcf) throws ResourceException;
   
  +    String getName();
  +
   }
  
  
  
  1.5       +55 -23    incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapper.java
  
  Index: ManagedConnectionFactoryWrapper.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ManagedConnectionFactoryWrapper.java	25 Feb 2004 09:57:10 -0000	1.4
  +++ ManagedConnectionFactoryWrapper.java	9 Mar 2004 18:02:03 -0000	1.5
  @@ -19,23 +19,25 @@
   
   import javax.naming.NamingException;
   import javax.resource.spi.ManagedConnectionFactory;
  +import javax.management.ObjectName;
   
  +import net.sf.cglib.proxy.Callback;
  +import net.sf.cglib.proxy.Enhancer;
  +import net.sf.cglib.proxy.MethodInterceptor;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.connector.ResourceAdapterWrapper;
   import org.apache.geronimo.connector.outbound.security.ManagedConnectionFactoryListener;
   import org.apache.geronimo.gbean.DynamicGBean;
   import org.apache.geronimo.gbean.DynamicGBeanDelegate;
  -import org.apache.geronimo.gbean.GAttributeInfo;
   import org.apache.geronimo.gbean.GBean;
   import org.apache.geronimo.gbean.GBeanContext;
   import org.apache.geronimo.gbean.GBeanInfo;
   import org.apache.geronimo.gbean.GBeanInfoFactory;
   import org.apache.geronimo.gbean.GConstructorInfo;
  -import org.apache.geronimo.gbean.GReferenceInfo;
  -import org.apache.geronimo.gbean.GOperationInfo;
   import org.apache.geronimo.gbean.WaitingException;
   import org.apache.geronimo.naming.geronimo.GeronimoContextManager;
  +import org.apache.geronimo.kernel.KernelMBean;
   
   /**
    *
  @@ -69,6 +71,10 @@
   
   
       private boolean registered = false;
  +    private Object proxy;
  +    private CFMethodInterceptor interceptor;
  +    private KernelMBean kernel;
  +    private ObjectName selfName;
   
       //default constructor for enhancement proxy endpoint
       public ManagedConnectionFactoryWrapper() {
  @@ -88,7 +94,9 @@
               String globalJNDIName,
               ResourceAdapterWrapper resourceAdapterWrapper,
               ConnectionManagerFactory connectionManagerFactory,
  -            ManagedConnectionFactoryListener managedConnectionFactoryListener) throws InstantiationException,
IllegalAccessException {
  +            ManagedConnectionFactoryListener managedConnectionFactoryListener,
  +            KernelMBean kernel,
  +            ObjectName selfName) throws InstantiationException, IllegalAccessException
{
           this.managedConnectionFactoryClass = managedConnectionFactoryClass;
           this.connectionFactoryInterface = connectionFactoryInterface;
           this.connectionFactoryImplClass = connectionFactoryImplClass;
  @@ -104,6 +112,8 @@
           delegate = new DynamicGBeanDelegate();
           delegate.addAll(managedConnectionFactory);
           this.managedConnectionFactoryListener = managedConnectionFactoryListener;
  +        this.kernel = kernel;
  +        this.selfName = selfName;
       }
   
       public Class getManagedConnectionFactoryClass() {
  @@ -130,11 +140,11 @@
           return globalJNDIName;
       }
   
  -
  +    /*
       public Object getConnectionFactory() {
           return connectionFactory;
       }
  -
  +     */
   
       public ResourceAdapterWrapper getResourceAdapterWrapper() {
           return resourceAdapterWrapper;
  @@ -169,15 +179,27 @@
   
           //create a new ConnectionFactory
           connectionFactory = connectionManagerFactory.createConnectionFactory(managedConnectionFactory);
  +        //build a proxy that can be turned off
  +        if (proxy == null) {
  +            Enhancer enhancer = new Enhancer();
  +            enhancer.setSuperclass(connectionFactoryInterface);
  +            enhancer.setCallbackType(MethodInterceptor.class);
  +            enhancer.setUseFactory(false);//????
  +            interceptor = new CFMethodInterceptor(kernel.getKernelName(), selfName);
  +            enhancer.setCallbacks(new Callback[] {interceptor});
  +            proxy = enhancer.create(new Class[0], new Object[0]);
  +        }
  +        interceptor.setConnectionFactory(connectionFactory);
           //If a globalJNDIName is supplied, bind it.
           if (globalJNDIName != null) {
  -            GeronimoContextManager.bind(globalJNDIName, connectionFactory);
  +            GeronimoContextManager.bind(globalJNDIName, proxy);
               log.debug("Bound connection factory into global 'ger:' context at " + globalJNDIName);
           }
   
       }
   
       public void doStop() throws WaitingException {
  +        interceptor.setConnectionFactory(null);
           //tear down login if present
           if (managedConnectionFactoryListener != null) {
               managedConnectionFactoryListener.setManagedConnectionFactory(null);
  @@ -209,28 +231,38 @@
           return null;
       }
   
  +    public Object getProxy() {
  +        return proxy;
  +    }
  +
  +    public Object getMethodInterceptor() {
  +        return interceptor;
  +    }
   
       static {
           GBeanInfoFactory infoFactory = new GBeanInfoFactory(ManagedConnectionFactoryWrapper.class.getName());
   
  -        infoFactory.addAttribute(new GAttributeInfo("ManagedConnectionFactoryClass", true));
  -        infoFactory.addAttribute(new GAttributeInfo("ConnectionFactoryInterface", true));
  -        infoFactory.addAttribute(new GAttributeInfo("ConnectionFactoryImplClass", true));
  -        infoFactory.addAttribute(new GAttributeInfo("ConnectionInterface", true));
  -        infoFactory.addAttribute(new GAttributeInfo("ConnectionImplClass", true));
  -
  -        infoFactory.addAttribute(new GAttributeInfo("GlobalJNDIName", true));
  -
  -        infoFactory.addOperation(new GOperationInfo("getConnectionFactory"));
  -
  -        infoFactory.addReference(new GReferenceInfo("ResourceAdapterWrapper", ResourceAdapterWrapper.class.getName()));
  -        infoFactory.addReference(new GReferenceInfo("ConnectionManagerFactory", ConnectionManagerFactory.class.getName()));
  -        infoFactory.addReference(new GReferenceInfo("ManagedConnectionFactoryListener",
ManagedConnectionFactoryListener.class.getName()));
  +        infoFactory.addAttribute("ManagedConnectionFactoryClass", true);
  +        infoFactory.addAttribute("ConnectionFactoryInterface", true);
  +        infoFactory.addAttribute("ConnectionFactoryImplClass", true);
  +        infoFactory.addAttribute("ConnectionInterface", true);
  +        infoFactory.addAttribute("ConnectionImplClass", true);
  +        infoFactory.addAttribute("SelfName", true);
  +
  +        infoFactory.addAttribute("GlobalJNDIName", true);
  +
  +        infoFactory.addOperation("getProxy");
  +        infoFactory.addOperation("getMethodInterceptor");
  +
  +        infoFactory.addReference("ResourceAdapterWrapper", ResourceAdapterWrapper.class);
  +        infoFactory.addReference("ConnectionManagerFactory", ConnectionManagerFactory.class);
  +        infoFactory.addReference("ManagedConnectionFactoryListener", ManagedConnectionFactoryListener.class);
  +        infoFactory.addReference("Kernel", KernelMBean.class);
           infoFactory.setConstructor(new GConstructorInfo(
                   new String[]{"ManagedConnectionFactoryClass", "ConnectionFactoryInterface",
"ConnectionFactoryImplClass", "ConnectionInterface", "ConnectionImplClass",
  -                             "GlobalJNDIName", "ResourceAdapterWrapper", "ConnectionManagerFactory",
"ManagedConnectionFactoryListener"},
  +                             "GlobalJNDIName", "ResourceAdapterWrapper", "ConnectionManagerFactory",
"ManagedConnectionFactoryListener", "Kernel", "SelfName"},
                   new Class[]{Class.class, Class.class, Class.class, Class.class, Class.class,
  -                            String.class, ResourceAdapterWrapper.class, ConnectionManagerFactory.class,
ManagedConnectionFactoryListener.class}));
  +                            String.class, ResourceAdapterWrapper.class, ConnectionManagerFactory.class,
ManagedConnectionFactoryListener.class, KernelMBean.class, ObjectName.class}));
   
           GBEAN_INFO = infoFactory.getBeanInfo();
       }
  
  
  
  1.1                  incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/CFMethodInterceptor.java
  
  Index: CFMethodInterceptor.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.connector.outbound;
  
  import java.lang.reflect.Method;
  import java.io.Serializable;
  import java.io.ObjectStreamException;
  import java.io.InvalidObjectException;
  
  import javax.management.ObjectName;
  
  import net.sf.cglib.proxy.MethodInterceptor;
  import net.sf.cglib.proxy.MethodProxy;
  import org.apache.geronimo.kernel.Kernel;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/03/09 18:02:02 $
   *
   * */
  public class CFMethodInterceptor implements MethodInterceptor, Serializable {
  
      private final String kernelName;
      private final ObjectName managedConnectionFactoryWrapperName;
  
      private transient Object internalProxy;
  
      public CFMethodInterceptor(String kernelName, ObjectName managedConnectionFactoryWrapperName)
{
          this.kernelName = kernelName;
          this.managedConnectionFactoryWrapperName = managedConnectionFactoryWrapperName;
      }
  
      public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy)
throws Throwable {
          if (internalProxy == null) {
              throw new IllegalStateException("Proxy is not connected");
          }
          return methodProxy.invoke(internalProxy, objects);
      }
  
      public void setConnectionFactory(Object connectionFactory) {
          internalProxy = connectionFactory;
      }
  
      private Object readResolve() throws ObjectStreamException {
          Kernel kernel = Kernel.getKernel(kernelName);
          try {
              return kernel.invoke(managedConnectionFactoryWrapperName, "getMethodInterceptor");
          } catch (Exception e) {
              throw (InvalidObjectException)new InvalidObjectException("could not get method
interceptor from ManagedConnectionFactoryWrapper").initCause(e);
          }
      }
  
  }
  
  
  
  1.5       +3 -4      incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTest.java
  
  Index: ConnectionManagerTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConnectionManagerTest.java	25 Feb 2004 09:57:13 -0000	1.4
  +++ ConnectionManagerTest.java	9 Mar 2004 18:02:03 -0000	1.5
  @@ -83,10 +83,9 @@
                   useTransactions,
                   maxSize,
                   blockingTimeout,
  -                name,
  +                //name,
                   realmBridge,
  -                connectionTrackingCoordinator,
  -                kernel);
  +                connectionTrackingCoordinator);
           connectionManagerDeployment.doStart();
           connectionFactory = (MockConnectionFactory) connectionManagerDeployment.createConnectionFactory(mockManagedConnectionFactory);
           defaultComponentContext = new DefaultComponentContext();
  
  
  
  1.1                  incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapperTest.java
  
  Index: ManagedConnectionFactoryWrapperTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.connector.outbound;
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.util.Collections;
  import java.util.Hashtable;
  
  import javax.management.ObjectName;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.resource.cci.Connection;
  import javax.resource.cci.ConnectionFactory;
  
  import junit.framework.TestCase;
  import org.apache.geronimo.connector.mock.MockConnection;
  import org.apache.geronimo.connector.mock.MockConnectionFactory;
  import org.apache.geronimo.connector.mock.MockManagedConnectionFactory;
  import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
  import org.apache.geronimo.gbean.jmx.GBeanMBean;
  import org.apache.geronimo.kernel.Kernel;
  import org.apache.geronimo.naming.deployment.RefAdapter;
  import org.apache.geronimo.naming.java.ComponentContextBuilder;
  import org.apache.geronimo.naming.java.ReadOnlyContext;
  import org.apache.geronimo.naming.jmx.JMXReferenceFactory;
  import org.apache.xmlbeans.XmlObject;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/03/09 18:02:03 $
   *
   * */
  public class ManagedConnectionFactoryWrapperTest extends TestCase {
  
      private Kernel kernel;
      private ObjectName selfName;
      private ObjectName ctcName;
      private ObjectName cmfName;
      private static final String GLOBAL_NAME = "GLOBAL_NAME";
      private static final String KERNEL_NAME = "testKernel";
      private static final String TARGET_NAME = "testCFName";
  
      public void testProxy() throws Exception {
          Object proxy = kernel.invoke(selfName, "getProxy");
          assertNotNull(proxy);
          assertTrue(proxy instanceof ConnectionFactory);
          Connection connection = ((ConnectionFactory) proxy).getConnection();
          assertNotNull(connection);
          kernel.stopGBean(selfName);
          try {
              ((ConnectionFactory) proxy).getConnection();
              fail();
          } catch (IllegalStateException ise) {
          }
          kernel.startGBean(selfName);
          ((ConnectionFactory) proxy).getConnection();
      }
  
      public void testSerialization() throws Exception {
          ConnectionFactory proxy = (ConnectionFactory)kernel.invoke(selfName, "getProxy");
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ObjectOutputStream oos = new ObjectOutputStream(baos);
          oos.writeObject(proxy);
          oos.flush();
          byte[] bytes = baos.toByteArray();
          oos.close();
          ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
          Object proxy2 = ois.readObject();
          assertNotNull(proxy2);
          assertTrue(proxy instanceof ConnectionFactory);
          Connection connection = proxy.getConnection();
          assertNotNull(connection);
          kernel.stopGBean(selfName);
          ObjectInputStream ois2 = new ObjectInputStream(new ByteArrayInputStream(bytes));
          ConnectionFactory proxy3 = (ConnectionFactory)ois2.readObject();
          try {
              proxy3.getConnection();
              fail();
          } catch (IllegalStateException ise) {
          }
          kernel.startGBean(selfName);
          proxy3.getConnection();
  
      }
  
      public void testGlobalLookup() throws Exception {
          Hashtable env = new Hashtable();
          env.put("java.naming.factory.initial", "com.sun.jndi.rmi.registry.RegistryContextFactory");
          env.put("java.naming.factory.url.pkgs", "org.apache.geronimo.naming");
          env.put("java.naming.provider.url", "rmi://localhost:1099");
  
          Context ctx = new InitialContext(env);
          ConnectionFactory cf = (ConnectionFactory)ctx.lookup("geronimo:" + GLOBAL_NAME);
          assertNotNull(cf);
          kernel.stopGBean(selfName);
          try {
              ctx.lookup("geronimo:" + GLOBAL_NAME);
              fail();
          } catch (NamingException ne) {
          }
          kernel.startGBean(selfName);
          ConnectionFactory cf2 = (ConnectionFactory)ctx.lookup("geronimo:" + GLOBAL_NAME);
          assertNotNull(cf2);
      }
  
      public void testLocalLookup() throws Exception {
          JMXReferenceFactory referenceFactory = new JMXReferenceFactory();
          ComponentContextBuilder builder = new ComponentContextBuilder(referenceFactory);
          builder.addResourceRef("resourceref", ConnectionFactory.class, new RefAdapter()
{
              public XmlObject getXmlObject() {
                  return null;
              }
  
              public void setXmlObject(XmlObject xmlObject) {
              }
  
              public String getRefName() {
                  return "resourceref";
              }
  
              public void setRefName(String name) {
              }
  
              public String getServerName() {
                  return null;
              }
  
              public void setServerName(String serverName) {
              }
  
              public String getKernelName() {
                  return KERNEL_NAME;
              }
  
              public void setKernelName(String kernelName) {
              }
  
              public String getTargetName() {
                  return TARGET_NAME;
              }
  
              public void setTargetName(String targetName) {
              }
  
              public String getExternalUri() {
                  return null;
              }
  
              public void setExternalUri(String externalURI) {
              }
  
          });
          ReadOnlyContext roc = builder.getContext();
          Object o = roc.lookup("env/resourceref");
          assertNotNull(o);
          assertTrue(o instanceof ConnectionFactory);
      }
  
      protected void setUp() throws Exception {
          kernel = new Kernel(KERNEL_NAME, "test.domain");
          kernel.boot();
          GBeanMBean ctc = new GBeanMBean(ConnectionTrackingCoordinator.getGBeanInfo());
          ctcName = ObjectName.getInstance("test:role=ConnectionTrackingCoordinator");
          kernel.loadGBean(ctcName, ctc);
          GBeanMBean cmf = new GBeanMBean(ConnectionManagerDeployment.getGBeanInfo());
          cmf.setAttribute("UseConnectionRequestInfo", Boolean.FALSE);
          cmf.setAttribute("UseSubject", Boolean.FALSE);
          cmf.setAttribute("UseTransactionCaching", Boolean.FALSE);
          cmf.setAttribute("UseLocalTransactions", Boolean.FALSE);
          cmf.setAttribute("UseTransactions", Boolean.FALSE);
          cmf.setAttribute("MaxSize", new Integer(10));
          cmf.setAttribute("BlockingTimeout", new Integer(5000));
          cmf.setReferencePatterns("ConnectionTracker", Collections.singleton(ctcName));
          cmfName = ObjectName.getInstance("test:role=ConnectionManagerFactory");
          kernel.loadGBean(cmfName, cmf);
  
          selfName = ObjectName.getInstance(JMXReferenceFactory.BASE_MANAGED_CONNECTION_FACTORY_NAME
+ TARGET_NAME);
  
          GBeanMBean mcfw = new GBeanMBean(ManagedConnectionFactoryWrapper.getGBeanInfo());
          mcfw.setAttribute("ManagedConnectionFactoryClass", MockManagedConnectionFactory.class);
          mcfw.setAttribute("ConnectionFactoryInterface", ConnectionFactory.class);
          mcfw.setAttribute("ConnectionFactoryImplClass", MockConnectionFactory.class);
          mcfw.setAttribute("ConnectionInterface", Connection.class);
          mcfw.setAttribute("ConnectionImplClass", MockConnection.class);
          mcfw.setAttribute("GlobalJNDIName", GLOBAL_NAME);
          //"ResourceAdapterWrapper",
          mcfw.setReferencePatterns("ConnectionManagerFactory", Collections.singleton(cmfName));
          //"ManagedConnectionFactoryListener",
          mcfw.setReferencePatterns("Kernel", Collections.singleton(Kernel.KERNEL));
          mcfw.setAttribute("SelfName", selfName);
          kernel.loadGBean(selfName, mcfw);
  
          kernel.startGBean(ctcName);
          kernel.startGBean(cmfName);
          kernel.startGBean(selfName);
      }
  
      protected void tearDown() throws Exception {
          kernel.stopGBean(selfName);
          kernel.shutdown();
      }
  }
  
  
  

Mime
View raw message