geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: rev 53849 - in geronimo/trunk/modules/connector/src: java/org/apache/geronimo/connector java/org/apache/geronimo/connector/deployment test/org/apache/geronimo/connector
Date Wed, 06 Oct 2004 05:42:22 GMT
Author: djencks
Date: Tue Oct  5 22:42:21 2004
New Revision: 53849

Modified:
   geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/AdminObjectWrapper.java
   geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
   geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/AdminObjectWrapperTest.java
Log:
GERONIMO-362.  Admin object proxies expose their class, not interface

Modified: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/AdminObjectWrapper.java
==============================================================================
--- geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/AdminObjectWrapper.java
(original)
+++ geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/AdminObjectWrapper.java
Tue Oct  5 22:42:21 2004
@@ -36,35 +36,52 @@
  *
  * @version $Rev$ $Date$
  */
-public class AdminObjectWrapper implements DynamicGBean {
+public class AdminObjectWrapper implements GBeanLifecycle, DynamicGBean {
 
+    private final Class adminObjectInterface;
     private final Class adminObjectClass;
 
     private final DynamicGBeanDelegate delegate;
     private final Object adminObject;
+    private final Kernel kernel;
+    private final String objectName;
 
+    private ConnectorMethodInterceptor interceptor;
+    private Object proxy;
 
     /**
      * Default constructor required when a class is used as a GBean Endpoint.
      */
     public AdminObjectWrapper() {
+        adminObjectInterface = null;
         adminObjectClass = null;
         adminObject = null;
         delegate = null;
+        kernel = null;
+        objectName = null;
     }
 
     /**
      * Normal managed constructor.
      *
+     * @param adminObjectInterface Interface the proxy will implement.
      * @param adminObjectClass Class of admin object to be wrapped.
+     * @param kernel name is used so proxy can find correct kernel.
+     * @param objectName is used by proxy to find this gbean to reconnect to.
      * @throws IllegalAccessException
      * @throws InstantiationException
      */
-    public AdminObjectWrapper(final Class adminObjectClass) throws IllegalAccessException,
InstantiationException {
+    public AdminObjectWrapper(final Class adminObjectInterface,
+                              final Class adminObjectClass,
+                              final Kernel kernel,
+                              final String objectName) throws IllegalAccessException, InstantiationException
{
+        this.adminObjectInterface = adminObjectInterface;
         this.adminObjectClass = adminObjectClass;
         adminObject = adminObjectClass.newInstance();
         delegate = new DynamicGBeanDelegate();
         delegate.addAll(adminObject);
+        this.kernel = kernel;
+        this.objectName = objectName;
     }
 
     /**
@@ -80,10 +97,53 @@
      * @return proxy implementing adminObjectInterface.
      */
     public Object getProxy() {
-        return adminObject;
+        return proxy;
     }
 
+    /**
+     * Returns the MethodInterceptor the proxy communicates with when connected.
+     * @return MethodInterceptor the proxy calls.
+     */
+    public Object getMethodInterceptor() {
+        return interceptor;
+    }
+
+    /**
+     * GBean start method.
+     * @throws WaitingException
+     * @throws Exception
+     */
+    public void doStart() throws WaitingException, Exception {
+        if (proxy == null) {
+            //build proxy
+            Enhancer enhancer = new Enhancer();
+            enhancer.setSuperclass(adminObjectClass);
+            enhancer.setCallbackType(MethodInterceptor.class);
+            //TODO is this correct?
+            enhancer.setUseFactory(false);
+            interceptor = new ConnectorMethodInterceptor(kernel.getKernelName(), ObjectName.getInstance(objectName));
+            enhancer.setCallbacks(new Callback[]{interceptor});
+            proxy = enhancer.create(new Class[0], new Object[0]);
+        }
+        //connect proxy
+        interceptor.setInternalProxy(adminObject);
+    }
 
+    /**
+     * GBean stop method.
+     * @throws WaitingException
+     * @throws Exception
+     */
+    public void doStop() throws WaitingException, Exception {
+        //disconnect proxy
+        interceptor.setInternalProxy(null);
+    }
+
+    /**
+     * GBean fail method.
+     */
+    public void doFail() {
+    }
 
     //DynamicGBean implementation
 
@@ -124,12 +184,20 @@
 
     static {
         GBeanInfoFactory infoFactory = new GBeanInfoFactory(AdminObjectWrapper.class);
+        infoFactory.addAttribute("adminObjectInterface", Class.class, true);
         infoFactory.addAttribute("adminObjectClass", Class.class, true);
+        infoFactory.addAttribute("kernel", Kernel.class, false);
+        infoFactory.addAttribute("objectName", String.class, false);
 
         infoFactory.addOperation("getProxy");
+        infoFactory.addOperation("getMethodInterceptor");
 
 
-        infoFactory.setConstructor(new String[]{"adminObjectClass"});
+        infoFactory.setConstructor(new String[]{
+            "adminObjectInterface",
+            "adminObjectClass",
+            "kernel",
+            "objectName"});
 
         GBEAN_INFO = infoFactory.getBeanInfo();
     }

Modified: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
==============================================================================
--- geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
(original)
+++ geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
Tue Oct  5 22:42:21 2004
@@ -422,7 +422,7 @@
 
                 // set the standard properties
                 try {
-//                    adminObjectGBean.setAttribute("adminObjectInterface", cl.loadClass(adminObjectInterface));
+                    adminObjectGBean.setAttribute("adminObjectInterface", cl.loadClass(adminObjectInterface));
                     adminObjectGBean.setAttribute("adminObjectClass", cl.loadClass(adminObject.getAdminobjectClass().getStringValue()));
                 } catch (Exception e) {
                     throw new DeploymentException("Could not initialize AdminObject", e);

Modified: geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/AdminObjectWrapperTest.java
==============================================================================
--- geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/AdminObjectWrapperTest.java
(original)
+++ geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/AdminObjectWrapperTest.java
Tue Oct  5 22:42:21 2004
@@ -51,14 +51,13 @@
         MockAdminObject mockAdminObject = ((MockAdminObject) proxy).getSomething();
         assertNotNull(mockAdminObject);
         kernel.stopGBean(selfName);
-        //byebye nice properties:-)
-//        try {
-//            ((MockAdminObject) proxy).getSomething();
-//            fail();
-//        } catch (IllegalStateException ise) {
-//        }
-//        kernel.startGBean(selfName);
-//        ((MockAdminObject) proxy).getSomething();
+        try {
+            ((MockAdminObject) proxy).getSomething();
+            fail();
+        } catch (IllegalStateException ise) {
+        }
+        kernel.startGBean(selfName);
+        ((MockAdminObject) proxy).getSomething();
     }
 
     public void testSerialization() throws Exception {
@@ -78,11 +77,11 @@
         kernel.stopGBean(selfName);
         ObjectInputStream ois2 = new ObjectInputStream(new ByteArrayInputStream(bytes));
         MockAdminObject proxy3 = (MockAdminObject) ois2.readObject();
-//        try {
-//            proxy3.getSomething();
-//            fail();
-//        } catch (IllegalStateException ise) {
-//        }
+        try {
+            proxy3.getSomething();
+            fail();
+        } catch (IllegalStateException ise) {
+        }
         kernel.startGBean(selfName);
         proxy3.getSomething();
 
@@ -110,7 +109,7 @@
         selfName = refFactory.createAdminObjectObjectName(TARGET_NAME);
 
         GBeanMBean aow = new GBeanMBean(AdminObjectWrapper.getGBeanInfo());
-//        aow.setAttribute("adminObjectInterface", MockAdminObject.class);
+        aow.setAttribute("adminObjectInterface", MockAdminObject.class);
         aow.setAttribute("adminObjectClass", MockAdminObjectImpl.class);
         kernel.loadGBean(selfName, aow);
 

Mime
View raw message