Author: julien(a)jboss.com
Date: 2007-03-15 21:53:48 -0400 (Thu, 15 Mar 2007)
New Revision: 6706
Added:
trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOServiceModelMBean.java
trunk/jems/src/main/org/jboss/portal/test/
trunk/jems/src/main/org/jboss/portal/test/jems/
trunk/jems/src/main/org/jboss/portal/test/jems/POJOService.java
trunk/jems/src/resources/
trunk/jems/src/resources/pojo-service-sar/
trunk/jems/src/resources/pojo-service-sar/META-INF/
trunk/jems/src/resources/pojo-service-sar/META-INF/jboss-service.xml
Removed:
trunk/jems/src/main/org/jboss/portal/jems/as/system/JBossService.java
Modified:
trunk/common/src/main/org/jboss/portal/common/mx/JavaBeanModelMBeanBuilder.java
trunk/jems/build.xml
Log:
- added an alternative model mbean implementation which takes care of managing the JBoss
service state and behavior in order to make services POJO instead of having to extends the
AbstractJBossService class
Modified: trunk/common/src/main/org/jboss/portal/common/mx/JavaBeanModelMBeanBuilder.java
===================================================================
---
trunk/common/src/main/org/jboss/portal/common/mx/JavaBeanModelMBeanBuilder.java 2007-03-16
00:12:26 UTC (rev 6705)
+++
trunk/common/src/main/org/jboss/portal/common/mx/JavaBeanModelMBeanBuilder.java 2007-03-16
01:53:48 UTC (rev 6706)
@@ -232,11 +232,11 @@
// Finally add the metadata
mmais.add(mmai);
-
- //
- className = from.getName();
}
+ //
+ className = from.getName();
+
// Methods->Operations
mmois = new ArrayList();
for (Iterator i = beanMethods.iterator(); i.hasNext();)
Modified: trunk/jems/build.xml
===================================================================
--- trunk/jems/build.xml 2007-03-16 00:12:26 UTC (rev 6705)
+++ trunk/jems/build.xml 2007-03-16 01:53:48 UTC (rev 6706)
@@ -168,6 +168,12 @@
</fileset>
</jar>
+ <jar jarfile="${build.lib}/pojo-service.sar">
+ <fileset dir="${build.classes}"/>
+ <fileset dir="${build.resources}/pojo-service-sar"/>
+ <fileset dir="${jboss.portal-common.root}/lib"
includes="portal-common-lib.jar"/>
+ </jar>
+
</target>
<!-- ================================================================== -->
Deleted: trunk/jems/src/main/org/jboss/portal/jems/as/system/JBossService.java
===================================================================
--- trunk/jems/src/main/org/jboss/portal/jems/as/system/JBossService.java 2007-03-16
00:12:26 UTC (rev 6705)
+++ trunk/jems/src/main/org/jboss/portal/jems/as/system/JBossService.java 2007-03-16
01:53:48 UTC (rev 6706)
@@ -1,35 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt 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.portal.jems.as.system;
-
-public interface JBossService
-{
-
- public void create() throws Exception;
-
- public void start() throws Exception;
-
- public void stop();
-
- public void destroy();
-}
Added: trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOServiceModelMBean.java
===================================================================
--- trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOServiceModelMBean.java
(rev 0)
+++
trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOServiceModelMBean.java 2007-03-16
01:53:48 UTC (rev 6706)
@@ -0,0 +1,395 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt 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.portal.jems.as.system;
+
+import org.jboss.mx.modelmbean.ModelMBeanInvoker;
+import org.jboss.mx.server.InvocationContext;
+import org.jboss.mx.server.Invocation;
+import org.jboss.mx.interceptor.AbstractInterceptor;
+import org.jboss.portal.common.mx.JavaBeanModelMBeanBuilder;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.system.ServiceMBeanSupport;
+import org.apache.log4j.Logger;
+import org.w3c.dom.Element;
+
+import javax.management.modelmbean.ModelMBeanInfo;
+import javax.management.modelmbean.InvalidTargetObjectTypeException;
+import javax.management.modelmbean.ModelMBeanInfoSupport;
+import javax.management.modelmbean.ModelMBeanOperationInfo;
+import javax.management.modelmbean.ModelMBeanAttributeInfo;
+import javax.management.modelmbean.ModelMBeanConstructorInfo;
+import javax.management.modelmbean.ModelMBeanNotificationInfo;
+import javax.management.MBeanException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public class POJOServiceModelMBean extends ModelMBeanInvoker
+{
+
+// Attributes ----------------------------------------------------
+
+ private static final Logger log = Logger.getLogger(POJOServiceModelMBean.class);
+
+ // Constructors --------------------------------------------------
+
+ private boolean createExists;
+ private boolean startExists;
+ private boolean stopExists;
+ private boolean destroyExists;
+ private boolean getStateExists;
+ private boolean getStateStringExists;
+
+ private final ServiceMBeanSupport support = new ServiceMBeanSupport()
+ {
+ protected void createService() throws Exception
+ {
+ execute("create");
+ }
+ protected void startService() throws Exception
+ {
+ execute("start");
+ }
+ protected void stopService() throws Exception
+ {
+ execute("stop");
+ }
+ protected void destroyService() throws Exception
+ {
+ execute("destroy");
+ }
+ private void execute(String lifecycle) throws Exception
+ {
+ Method m = null;
+ try
+ {
+ m = getResource().getClass().getMethod(lifecycle, new Class[0]);
+ }
+ catch (NoSuchMethodException ignore)
+ {
+ }
+
+ //
+ if (m != null)
+ {
+ try
+ {
+ m.invoke(getResource(), new Object[0]);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new Error(e);
+ }
+ catch (InvocationTargetException e)
+ {
+ Throwable t = e.getTargetException();
+ if (t instanceof Exception)
+ {
+ throw (Exception)t;
+ }
+ else if (t instanceof Error)
+ {
+ throw (Error)t;
+ }
+ else
+ {
+ throw new Error(t);
+ }
+ }
+ }
+ }
+ };
+
+ public POJOServiceModelMBean(Object resource, Element config, String version) throws
MBeanException
+ {
+ try
+ {
+ setManagedResource(resource, "ObjectReference");
+
+ // Build
+ ModelMBeanInfo info = JavaBeanModelMBeanBuilder.build(resource.getClass(),
Object.class);
+
+ //
+ List mmois = Tools.toList(info.getOperations());
+ List mmais = Tools.toList(info.getAttributes());
+
+ //
+ for (int i = 0;i < mmois.size();i++)
+ {
+ ModelMBeanOperationInfo mmoi = (ModelMBeanOperationInfo)mmois.get(i);
+ if (mmoi.getSignature().length == 0)
+ {
+ if (mmoi.getName().equals("create"))
+ {
+ createExists = true;
+ }
+ else if (mmoi.getName().equals("start"))
+ {
+ startExists = true;
+ }
+ else if (mmoi.getName().equals("stop"))
+ {
+ stopExists = true;
+ }
+ else if (mmoi.getName().equals("destroy"))
+ {
+ destroyExists = true;
+ }
+ else if (mmoi.getName().equals("getState"))
+ {
+ getStateExists = true;
+ }
+ else if (mmoi.getName().equals("getStateString"))
+ {
+ getStateStringExists = true;
+ }
+ }
+ }
+
+ //
+ if (!createExists)
+ {
+ mmois.add(templateInfo.getOperation("create"));
+ }
+ if (!startExists)
+ {
+ mmois.add(templateInfo.getOperation("start"));
+ }
+ if (!stopExists)
+ {
+ mmois.add(templateInfo.getOperation("stop"));
+ }
+ if (!destroyExists)
+ {
+ mmois.add(templateInfo.getOperation("destroy"));
+ }
+ if (!getStateExists)
+ {
+ mmois.add(templateInfo.getOperation("getState"));
+ mmais.add(templateInfo.getAttribute("State"));
+ }
+ if (!getStateStringExists)
+ {
+ mmois.add(templateInfo.getOperation("getStateString"));
+ mmais.add(templateInfo.getAttribute("StateString"));
+ }
+
+ //
+ info = new ModelMBeanInfoSupport(
+ info.getClassName(),
+ info.getDescription(),
+ (ModelMBeanAttributeInfo[])mmais.toArray(new
ModelMBeanAttributeInfo[mmais.size()]),
+ (ModelMBeanConstructorInfo[])info.getConstructors(),
+ (ModelMBeanOperationInfo[])mmois.toArray(new
ModelMBeanOperationInfo[mmois.size()]),
+ (ModelMBeanNotificationInfo[])info.getNotifications());
+
+ //
+ setModelMBeanInfo(info);
+ }
+ catch (InstanceNotFoundException e)
+ {
+ throw new MBeanException(e);
+ }
+ catch (InvalidTargetObjectTypeException e)
+ {
+ throw new MBeanException(e, "Unsupported resource type: " +
resourceType);
+ }
+ catch (Exception e)
+ {
+ throw new MBeanException(e);
+ }
+ }
+
+ // ModelMBean implementation -------------------------------------
+
+ public boolean isSupportedResourceType(Object resource, String resourceType)
+ {
+ return "ObjectReference".equals(resourceType);
+ }
+
+ public MBeanInfo getMBeanInfo()
+ {
+ return info;
+ }
+
+ //
+
+
+ protected void initDispatchers()
+ {
+ super.initDispatchers();
+
+ //
+ for (Iterator i = attributeContextMap.values().iterator();i.hasNext();)
+ {
+ InvocationContext ctx = (InvocationContext)i.next();
+ if ("State".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return new Integer(support.getState());
+ }
+ });
+ }
+ else if ("StateString".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return support.getStateString();
+ }
+ });
+ }
+ }
+
+ //
+ for (Iterator i = operationContextMap.values().iterator();i.hasNext();)
+ {
+ InvocationContext ctx = (InvocationContext)i.next();
+ if ("create".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ support.create();
+ return null;
+ }
+ });
+ }
+ else if ("start".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ support.start();
+ return null;
+ }
+ });
+ }
+ else if ("stop".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ support.stop();
+ return null;
+ }
+ });
+ }
+ else if ("destroy".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ support.destroy();
+ return null;
+ }
+ });
+ }
+ else if ("getState".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return new Integer(support.getState());
+ }
+ });
+ }
+ else if ("getStateString".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return support.getStateString();
+ }
+ });
+ }
+ }
+ }
+
+ static
+ {
+ try
+ {
+ templateInfo = JavaBeanModelMBeanBuilder.build(Template.class, Object.class);
+ }
+ catch (Exception e)
+ {
+ throw new Error(e);
+ }
+ }
+
+ /** . */
+ private static ModelMBeanInfo templateInfo;
+
+ private static class Template
+ {
+ public int getState()
+ {
+ throw new UnsupportedOperationException();
+ }
+ public String getStateString()
+ {
+ throw new UnsupportedOperationException();
+ }
+ public void create()
+ {
+ throw new UnsupportedOperationException();
+ }
+ public void start()
+ {
+ throw new UnsupportedOperationException();
+ }
+ public void stop()
+ {
+ throw new UnsupportedOperationException();
+ }
+ public void destroy()
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+}
Added: trunk/jems/src/main/org/jboss/portal/test/jems/POJOService.java
===================================================================
--- trunk/jems/src/main/org/jboss/portal/test/jems/POJOService.java
(rev 0)
+++ trunk/jems/src/main/org/jboss/portal/test/jems/POJOService.java 2007-03-16 01:53:48
UTC (rev 6706)
@@ -0,0 +1,50 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt 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.portal.test.jems;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class POJOService
+{
+ public void create()
+ {
+ System.out.println("create callback");
+ }
+
+ public void start()
+ {
+ System.out.println("start callback");
+ }
+
+ public void stop()
+ {
+ System.out.println("stop callback");
+ }
+
+ public void destroy()
+ {
+ System.out.println("destroy callback");
+ }
+}
Added: trunk/jems/src/resources/pojo-service-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/jems/src/resources/pojo-service-sar/META-INF/jboss-service.xml
(rev 0)
+++ trunk/jems/src/resources/pojo-service-sar/META-INF/jboss-service.xml 2007-03-16
01:53:48 UTC (rev 6706)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2006, Red Hat Middleware, LLC, and individual ~
+ ~ contributors as indicated by the @authors tag. See the ~
+ ~ copyright.txt 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<server>
+
+ <!-- -->
+ <mbean
+ code="org.jboss.portal.test.jems.POJOService"
+ name="portal.test:service=POJO"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.POJOServiceModelMBean">
+ <xmbean/>
+ </mbean>
+</server>