beehive-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eddie O'Neil" <ekon...@gmail.com>
Subject ejbcontrol changes? -- svn 407080
Date Tue, 16 May 2006 22:07:36 GMT
Chad--

  Hey; was taking a look at this change and had a question / comment.
It appears that the new code uses an exception to handle control flow
rather than attempting to avoid the exception.  The
"NoSuchMethodException" could be avoided if the methods on a class
were searched manually rather than using the "getMethod(String,
Class...)" method signature.  In cases where this fails and an
exception is throw, the performance of EJB control invocations will
drop dramatically.

  Could this change this to search a Class for a method with a
matching signature?

Eddie


---------- Forwarded message ----------
From: cschoett@apache.org <cschoett@apache.org>
Date: May 16, 2006 3:13 PM
Subject: svn commit: r407080 - in /beehive/trunk/system-controls:
src/ejb/org/apache/beehive/controls/system/ejb/
test/ejb/src/controls/org/apache/beehive/test/controls/system/controls/
test/ejb/src/tests/org/apache/beehive/test/controls/system/test/
To: commits@beehive.apache.org


Author: cschoett
Date: Tue May 16 14:13:15 2006
New Revision: 407080

URL: http://svn.apache.org/viewcvs?rev=407080&view=rev
Log:
Updated ejb system control to allow a user to specify an ejb control
method override in the control interface.
Necessary to allow a user to set a method interceptor on an ejb control method.
Also updated ejb system control test suite to include a new test case
for this usage.

Added:
    beehive/trunk/system-controls/test/ejb/src/controls/org/apache/beehive/test/controls/system/controls/MethodOverrideSessionEJBControl.java
  (with props)
    beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestMethodOverrideSessionEjbControl.java
  (with props)
Modified:
    beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EJBControlImpl.java
    beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EntityEJBControlImpl.java

Modified: beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EJBControlImpl.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EJBControlImpl.java?rev=407080&r1=407079&r2=407080&view=diff
==============================================================================
--- beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EJBControlImpl.java
(original)
+++ beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EJBControlImpl.java
Tue May 16 14:13:15 2006
@@ -84,7 +84,7 @@
             _jndiName = JNDI_APPSCOPED_PREFIX +
EJBInfo.getEJBRefName(context.getControlInterface());

             // todo: works this way in geronimo, determine which is correct!
-            // _jndiName =
EJBInfo.getEJBRefName(context.getControlInterface());
+//            _jndiName = EJBInfo.getEJBRefName(context.getControlInterface());
         }

         // Obtain the JCX interface and identify the home/remote
@@ -107,6 +107,32 @@
         return m.getDeclaringClass().isAssignableFrom(_homeInterface);
     }

+    /**
+     * Return true if the method is from the ControlBean.
+     * @param m Method to check.
+     */
+    protected boolean isControlBeanMethod(Method m) {
+        return
m.getDeclaringClass().isAssignableFrom(context.getControlBean().getClass());
+    }
+
+    // todo: finish this method
+    protected Method mapControlBeanMethodToEJB(Method m) throws
NoSuchMethodException {
+        try {
+            return _homeInterface.getMethod(m.getName(),
m.getParameterTypes());
+        }
+        catch (NoSuchMethodException e) {
+            // not an error, check remote and bean interface
+        }
+
+        if (_beanInstance == null) {
+            _beanInstance = resolveBeanInstance();
+            if (_beanInstance == null) {
+                throw new ControlException("Unable to resolve bean instance");
+            }
+        }
+        return _beanInstance.getClass().getMethod(m.getName(),
m.getParameterTypes());
+    }
+
     protected static boolean isCreateMethod(Method m) {
         return methodThrows(m, CreateException.class);
     }
@@ -293,6 +319,10 @@
      */
     public Object invoke(Method m, Object[] args) throws Throwable {
         Object retval = null;
+
+        if (isControlBeanMethod(m)) {
+            m = mapControlBeanMethodToEJB(m);
+        }

         if (isHomeMethod(m)) {
             try {

Modified: beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EntityEJBControlImpl.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EntityEJBControlImpl.java?rev=407080&r1=407079&r2=407080&view=diff
==============================================================================
--- beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EntityEJBControlImpl.java
(original)
+++ beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EntityEJBControlImpl.java
Tue May 16 14:13:15 2006
@@ -128,6 +128,10 @@
             invokeException = t;
         }

+        if (isControlBeanMethod(m)) {
+            m = mapControlBeanMethodToEJB(m);
+        }
+
         if (isMultiSelectorMethod(m)) {
             releaseBeanInstance(false);


Added: beehive/trunk/system-controls/test/ejb/src/controls/org/apache/beehive/test/controls/system/controls/MethodOverrideSessionEJBControl.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/test/ejb/src/controls/org/apache/beehive/test/controls/system/controls/MethodOverrideSessionEJBControl.java?rev=407080&view=auto
==============================================================================
--- beehive/trunk/system-controls/test/ejb/src/controls/org/apache/beehive/test/controls/system/controls/MethodOverrideSessionEJBControl.java
(added)
+++ beehive/trunk/system-controls/test/ejb/src/controls/org/apache/beehive/test/controls/system/controls/MethodOverrideSessionEJBControl.java
Tue May 16 14:13:15 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2006 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.test.controls.system.controls;
+
+import org.apache.beehive.controls.api.bean.ControlExtension;
+import org.apache.beehive.controls.system.ejb.EJBControl;
+import org.apache.beehive.controls.system.ejb.SessionEJBControl;
+import org.apache.beehive.test.controls.system.ejb.session.SimpleSessionHome;
+import org.apache.beehive.test.controls.system.ejb.session.SimpleSessionRemote;
+
+/**
+ * This test EJB-Control uses a EJBHome jndi value and specifies the
jndi context with the
+ * JNDIContextEnv annotation.
+ */
+@ControlExtension
+@EJBControl.EJBHome(jndiName="SimpleSessionRemote")
+@EJBControl.JNDIContextEnv(contextFactory="org.openejb.client.RemoteInitialContextFactory",
+                           providerURL="localhost:4201",
principal="system", credentials="manager")
+public interface MethodOverrideSessionEJBControl extends
SessionEJBControl, SimpleSessionHome, SimpleSessionRemote
+{
+    // override of EJB method
+    public String sayHello();
+
+    // override of EJB method
+    public String echo(String echoString);
+}

Propchange: beehive/trunk/system-controls/test/ejb/src/controls/org/apache/beehive/test/controls/system/controls/MethodOverrideSessionEJBControl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestMethodOverrideSessionEjbControl.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestMethodOverrideSessionEjbControl.java?rev=407080&view=auto
==============================================================================
--- beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestMethodOverrideSessionEjbControl.java
(added)
+++ beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestMethodOverrideSessionEjbControl.java
Tue May 16 14:13:15 2006
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2006 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.test.controls.system.test;
+
+import org.apache.cactus.ServletTestCase;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.context.ControlContainerContext;
+import org.apache.beehive.controls.api.context.ControlThreadContext;
+import org.apache.beehive.test.controls.system.controls.MethodOverrideSessionEJBControl;
+import org.apache.beehive.test.controls.system.ejb.session.SimpleSessionHome;
+
+/**
+ * Test the ability to override a EJB method in the EJB control
interface.  Sometimes
+ * necessary when method level annotations need to be added at the
method level.  Expected
+ * behavior is that the EJB method is still invoked after any
necessary annotation processing
+ * has been completed.
+ */
+public class TestMethodOverrideSessionEjbControl extends ServletTestCase
+{
+    @Control
+    private MethodOverrideSessionEJBControl _ejbControl;
+
+    private ControlContainerContext _controlContext = null;
+
+    /**
+     * Setup the test.
+     * @throws Exception
+     */
+    public void setUp() throws Exception {
+        _controlContext = ControlThreadContext.getContext();
+        if (_controlContext == null) {
+            _controlContext = TestContextInitializer.initContext(this);
+        } else {
+            TestMethodOverrideSessionEjbControlClientInitializer.initialize(_controlContext,
this);
+        }
+    }
+
+    /**
+     * Tear down the test.
+     * @throws Exception
+     */
+    public void tearDown() throws Exception {
+        _controlContext.endContext();
+        super.tearDown();
+    }
+
+    /**
+     * Test overridden method which has no parameters.
+     * @throws Exception
+     */
+    public void testEjbControlHello() throws Exception {
+        String result = _ejbControl.sayHello();
+        assertEquals("Hello!", result);
+    }
+
+    /**
+     * Test overridden method with parameters.
+     * @throws Exception
+     */
+    public void testEjbControlEcho() throws Exception {
+        String result = _ejbControl.echo("Hi there");
+        assertEquals("Hi there", result);
+    }
+
+    /**
+     * Test the getEJBHomeInstance EJB control api.
+     * @throws Exception
+     */
+    public void testGetHome() throws Exception {
+        SimpleSessionHome home =
(SimpleSessionHome)_ejbControl.getEJBHomeInstance();
+        assertNotNull(home);
+    }
+
+    /**
+     * Test the hasEJBBeanInstance EJB control api.
+     * @throws Exception
+     */
+    public void testHasBeanInstance() throws Exception {
+        _ejbControl.sayHello();
+        assertTrue(_ejbControl.hasEJBBeanInstance());
+    }
+
+    /**
+     * Test the getEJBBeanInstance EJB control api.
+     * @throws Exception
+     */
+    public void testGetBeanInstance() throws Exception {
+        _ejbControl.sayHello();
+        Object bean = _ejbControl.getEJBBeanInstance();
+        assertNotNull(bean);
+    }
+
+    /**
+     * Test the getEJBException EJB control api.
+     * @throws Exception
+     */
+    public void testGetEjbException() throws Exception {
+        Throwable t = _ejbControl.getEJBException();
+        assertNull(t);
+    }
+}

Propchange: beehive/trunk/system-controls/test/ejb/src/tests/org/apache/beehive/test/controls/system/test/TestMethodOverrideSessionEjbControl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Mime
View raw message