[jboss-cvs] JBossAS SVN: r83077 - in branches/JBPAPP_4_2_0_GA_CP/ejb3: src/main/org/jboss/ejb3/service and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 19 09:40:09 EST 2009


Author: wolfc
Date: 2009-01-19 09:40:08 -0500 (Mon, 19 Jan 2009)
New Revision: 83077

Added:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceXMBeanDelegate.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1224/
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1224/META-INF/
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1224/META-INF/defaulted-service-xmbean.xml
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1224/META-INF/jboss-service.xml
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/DefaultedServiceBean.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/DefaultedServiceRemote.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/unit/
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/unit/DefaultedMBeanUnitTestCase.java
Modified:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
Log:
JBPAPP-1224: better mimicking the behavior of ServiceCreator

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml	2009-01-19 14:29:51 UTC (rev 83076)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml	2009-01-19 14:40:08 UTC (rev 83077)
@@ -2123,6 +2123,13 @@
       <build-simple-jar name="jbpapp1186"/>
    </target>
 
+   <target name="jbpapp1224"
+      description="Builds a simple jar files."
+      depends="compile-classes">
+
+      <build-simple-jar name="jbpapp1224"/>
+   </target>
+
    <target name="jaxws"
       description="Builds a simple jar."
       depends="compile-classes">
@@ -3817,6 +3824,7 @@
    	ejbthree1504,
       jbpapp999,
       jbpapp1186,
+      jbpapp1224,
       jbas4489, epcpropagation, jaccpropagation, 
       aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, jaxws,
       pkg, securitydomain, enventry, externalpersistenceunit,

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2009-01-19 14:29:51 UTC (rev 83076)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2009-01-19 14:40:08 UTC (rev 83077)
@@ -21,11 +21,30 @@
  */
 package org.jboss.ejb3.service;
 
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+
+import javax.ejb.EJBException;
+import javax.ejb.Handle;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
+import javax.management.InstanceNotFoundException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+
 import org.jboss.annotation.ejb.Management;
 import org.jboss.annotation.ejb.Service;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.MethodInfo;
-import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.InvocationResponse;
 import org.jboss.aop.joinpoint.MethodInvocation;
@@ -46,31 +65,13 @@
 import org.jboss.injection.Injector;
 import org.jboss.logging.Logger;
 
-import javax.ejb.EJBException;
-import javax.ejb.Handle;
-import javax.ejb.Timer;
-import javax.ejb.TimerService;
-import javax.management.Attribute;
-import javax.management.AttributeList;
-import javax.management.AttributeNotFoundException;
-import javax.management.InstanceNotFoundException;
-import javax.management.InvalidAttributeValueException;
-import javax.management.MBeanException;
-import javax.management.MBeanInfo;
-import javax.management.MBeanRegistrationException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.ReflectionException;
-import java.lang.reflect.Method;
-import java.util.Hashtable;
-
 /**
  * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
  * @version $Revision$
  */
 public class ServiceContainer extends SessionContainer implements TimedObjectInvoker
 {
-   ServiceMBeanDelegate delegate;
+   DynamicMBean delegate;
    Object singleton;
    boolean injected;
    BeanContext beanContext;
@@ -548,7 +549,9 @@
                delegateObjectName = (objname == null || objname.equals("")) ?
                                new ObjectName(getObjectName().getCanonicalName() + ",type=ManagementInterface") : new ObjectName(service.objectName());
 
-               delegate = new ServiceMBeanDelegate(mbeanServer, this, service.xmbean(), delegateObjectName);
+               // we must install something that resembles a ModelMBean to make
+               // sure that attribute values and persistence is applied.
+               delegate = new ServiceXMBeanDelegate(this, service.xmbean());
 
                getDeployment().getKernelAbstraction().installMBean(delegateObjectName, getDependencyPolicy(), delegate);
             }

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceXMBeanDelegate.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceXMBeanDelegate.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/service/ServiceXMBeanDelegate.java	2009-01-19 14:40:08 UTC (rev 83077)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.service;
+
+import java.lang.reflect.Method;
+
+import javax.management.MBeanException;
+import javax.management.MBeanOperationInfo;
+import javax.management.NotCompliantMBeanException;
+
+import org.jboss.logging.Logger;
+import org.jboss.mx.interceptor.AbstractInterceptor;
+import org.jboss.mx.interceptor.Interceptor;
+import org.jboss.mx.interceptor.ReflectedDispatcher;
+import org.jboss.mx.modelmbean.XMBean;
+import org.jboss.mx.server.Invocation;
+import org.jboss.mx.server.InvocationContext;
+import org.jboss.mx.server.MethodMapper;
+
+/**
+ * A XMBean which dispatches to the ServiceContainer instead of to the target bean.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ServiceXMBeanDelegate extends XMBean
+{
+   private static final Logger log = Logger.getLogger(ServiceXMBeanDelegate.class);
+   
+   private ServiceContainer container;
+   
+   /**
+    * @param container
+    * @param resourceType
+    * @throws MBeanException
+    * @throws NotCompliantMBeanException
+    */
+   public ServiceXMBeanDelegate(ServiceContainer container, String resourceType) throws MBeanException, NotCompliantMBeanException
+   {
+      super(container.getSingleton(), resourceType);
+      
+      this.container = container;
+   }
+   
+   @Override
+   protected void initDispatchers()
+   {
+      super.initDispatchers();
+      
+      // map the Methods on the target resource for easy access
+      MethodMapper mmap = new MethodMapper(getResource().getClass());
+      
+      MBeanOperationInfo[] operations = info.getOperations();
+      
+      // Set the dispatchers for the operations
+      for (int i = 0; i < operations.length; ++i)
+      {
+         MBeanOperationInfo op = operations[i];
+         
+         // hack for backwards compatibility
+         // In the old return type was ignore, in the new it's not and
+         // specifying java.lang.Void is wrong.
+         if(op.getReturnType().equals("java.lang.Void"))
+         {
+            op = new MBeanOperationInfo(op.getName(), op.getDescription(), op.getSignature(), "void", op.getImpact());
+         }
+         
+         OperationKey opKey = new OperationKey(op.getName(), op.getSignature());
+         InvocationContext ctx = (InvocationContext) operationContextMap.get(opKey);
+
+         Interceptor dispatcher = ctx.getDispatcher();
+         
+         // Reconfigure if we have a Reflected dispatcher
+         if (dispatcher instanceof ReflectedDispatcher)
+         {
+            // Don't reset the dispatcher
+            //dispatcher = null;
+            Method m = mmap.lookupOperation(op);
+            if (m == null)
+            {
+               // TODO: ehr, I would say this is an error, but there seems to be
+               // something like late binding in the original code. Let's just issue a warning.
+               log.warn("operation " + op + " was not found, ignoring");
+               /*
+               // Look for an method on the model mbean
+               m = MethodMapper.lookupOperation(op, this);
+               if (m != null)
+               {
+                  // operation found on the 'this' invoker
+                  target = this;
+                  dispatcher = new ReflectedDispatcher(m, dynamicResource);
+               }
+               else
+               {
+                  // operation not found, use late binding
+                  // What is this late binding attempt and should there be a warning?
+                  dispatcher = new ReflectedDispatcher(dynamicResource);
+               }
+               */
+            }
+            else
+            {
+               // operation found on the resource
+               dispatcher = new ContainerDispatcher(m);
+            }
+            ctx.setDispatcher(dispatcher);
+         }
+      }
+   }
+   
+   private class ContainerDispatcher extends AbstractInterceptor
+   {
+      private Method method;
+      
+      protected ContainerDispatcher(Method method)
+      {
+         this.method = method;
+      }
+      
+      @Override
+      public Object invoke(Invocation invocation) throws Throwable
+      {
+         return container.localInvoke(method, invocation.getArgs());
+      }
+   }
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1224/META-INF/defaulted-service-xmbean.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1224/META-INF/defaulted-service-xmbean.xml	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1224/META-INF/defaulted-service-xmbean.xml	2009-01-19 14:40:08 UTC (rev 83077)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mbean PUBLIC "-//JBoss//DTD JBOSS XMBEAN 1.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_2.dtd">
+<mbean>
+  <description>TestService description</description>
+
+  <descriptors>
+    <persistence persistPolicy="OnUpdate"/>
+    <persistence-manager value="org.jboss.mx.persistence.DelegatingPersistenceManager"/>
+  </descriptors>
+
+  <class>org.jboss.ejb3.test.jpapp1224.DefaultedServiceBean</class>
+
+  <constructor>
+    <description>The default constructor</description>
+    <name>DefaultedServiceBean</name>
+  </constructor>
+
+  <attribute access="read-write" getMethod="getConfigParam" setMethod="setConfigParam">
+    <description>Description for configParam</description>
+    <name>ConfigParam</name>
+    <type>java.lang.String</type>
+    <descriptors>
+      <value value="${jboss.server.base.dir}/test"/>
+    </descriptors>
+  </attribute>
+  
+  <operation>
+   <description>Description for start</description>
+   <name>start</name>
+   <return-type>void</return-type>
+  </operation>
+  
+  <operation>
+   <description>Description for stop</description>
+   <name>stop</name>
+   <return-type>void</return-type>
+  </operation>
+  
+  <operation>
+   <description>Description for operationOne</description>
+   <name>operationOne</name>
+   <return-type>void</return-type>
+  </operation>
+  
+  <operation>
+   <description>Description for operationTwo</description>
+   <name>operationTwo</name>   
+   <parameter>
+	   <description>Description for parameter</description>
+	   <name>param1</name>
+	   <type>java.lang.String</type>
+   </parameter>
+   <return-type>java.lang.String</return-type>
+  </operation>
+</mbean>
\ No newline at end of file

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1224/META-INF/jboss-service.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1224/META-INF/jboss-service.xml	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1224/META-INF/jboss-service.xml	2009-01-19 14:40:08 UTC (rev 83077)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+  <mbean code="org.jboss.ejb3.test.jbpapp1224.DefaultedServiceBean"
+    name="jboss.ejb3:service=TestService"
+    xmbean-dd="META-INF/defaulted-service-xmbean.xml">
+  </mbean>
+</server>
\ No newline at end of file

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/DefaultedServiceBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/DefaultedServiceBean.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/DefaultedServiceBean.java	2009-01-19 14:40:08 UTC (rev 83077)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.jbpapp1224;
+
+import org.jboss.annotation.ejb.Service;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Service(xmbean="resource:META-INF/defaulted-service-xmbean.xml")
+public class DefaultedServiceBean implements DefaultedServiceRemote
+{
+   private static final Logger log = Logger.getLogger(DefaultedServiceBean.class);
+   
+   private String configParam;
+   
+   public String getConfigParam()
+   {
+      return configParam;
+   }
+   
+   public void setConfigParam(String configParam)
+   {
+      log.info("configParam = " + configParam);
+      this.configParam = configParam;
+   }
+   
+   public void start()
+   {
+      log.info("configParam = " + configParam);
+   }
+   
+   public void stop()
+   {
+      
+   }
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/DefaultedServiceRemote.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/DefaultedServiceRemote.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/DefaultedServiceRemote.java	2009-01-19 14:40:08 UTC (rev 83077)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.jbpapp1224;
+
+import javax.ejb.Remote;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Remote
+public interface DefaultedServiceRemote
+{
+   String getConfigParam();
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/unit/DefaultedMBeanUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/unit/DefaultedMBeanUnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1224/unit/DefaultedMBeanUnitTestCase.java	2009-01-19 14:40:08 UTC (rev 83077)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.jbpapp1224.unit;
+
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.jbpapp1224.DefaultedServiceRemote;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Make sure that default values specified for attributes are actually used.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DefaultedMBeanUnitTestCase extends JBossTestCase
+{
+   public DefaultedMBeanUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testJMX() throws Exception
+   {
+      ObjectName on = new ObjectName("jboss.j2ee:jar=jbpapp1224.jar,name=DefaultedServiceBean,service=EJB3,type=ManagementInterface");
+      String actual = (String) getServer().getAttribute(on, "ConfigParam");
+      assertEquals("${jboss.server.base.dir}/test", actual);
+   }
+   
+   public void testRemote() throws Exception
+   {
+      DefaultedServiceRemote bean = (DefaultedServiceRemote) getInitialContext().lookup("DefaultedServiceBean/remote");
+      String actual = bean.getConfigParam();
+      assertEquals("${jboss.server.base.dir}/test", actual);
+   }
+   
+   public void testServerFound() throws Exception
+   {
+      serverFound();
+   }
+   
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(DefaultedMBeanUnitTestCase.class, "jbpapp1224.jar");
+   }
+}




More information about the jboss-cvs-commits mailing list