User: d_jencks
Date: 02/02/20 09:40:11
Modified: src/main/org/jboss/ejb Application.java Container.java
EJBDeployer.java EntityContainer.java
Log:
Made mbean depending on ejb work, with a test case
Revision Changes Path
1.28 +69 -28 jboss/src/main/org/jboss/ejb/Application.java
Index: Application.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/Application.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- Application.java 16 Feb 2002 06:34:31 -0000 1.27
+++ Application.java 20 Feb 2002 17:40:11 -0000 1.28
@@ -14,11 +14,13 @@
import java.util.Hashtable;
import javax.ejb.EJBLocalHome;
+import javax.management.MBeanServer;
import javax.management.ObjectName;
-
-import org.jboss.system.Service;
import org.jboss.management.j2ee.EJB;
import org.jboss.management.j2ee.EjbModule;
+import org.jboss.system.Service;
+import org.jboss.system.ServiceControllerMBean;
+import org.jboss.util.jmx.MBeanProxy;
import org.jboss.logging.Logger;
@@ -33,7 +35,7 @@
* @see EJBDeployer
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>
- * @version $Revision: 1.27 $
+ * @version $Revision: 1.28 $
*/
public class Application
implements Service
@@ -60,11 +62,25 @@
/** Module Object Name (JSr-77) **/
private String moduleName;
+
+ private final ServiceControllerMBean serviceController;
+
+ private final MBeanServer server;
// Static --------------------------------------------------------
// Public --------------------------------------------------------
+ //constructor with mbeanserver
+
+ public Application(final MBeanServer server)
+ {
+ this.server = server;
+ serviceController = (ServiceControllerMBean)
+ MBeanProxy.create(ServiceControllerMBean.class,
+ ServiceControllerMBean.OBJECT_NAME,
+ server);
+ }
/**
* Add a container to this application. This is called by the
* EJBDeployer.
@@ -202,8 +218,32 @@
}
// Service implementation ----------------------------------------
- public void create() throws Exception {}
- public void destroy(){}
+ public void create() throws Exception
+ {
+ boolean debug = log.isDebugEnabled();
+ log.debug( "Application.start(), begin" );
+ for (Iterator i = containers.values().iterator(); i.hasNext();)
+ {
+ Container con = (Container)i.next();
+ ObjectName jmxName= con.getJmxName();
+ server.registerMBean(con, jmxName);
+ serviceController.create(jmxName);
+ // Create JSR-77 EJB-Wrapper
+ log.debug( "Application.create(), create JSR-77 EJB-Component" );
+ ObjectName lEJB = EJB.create(
+ server,
+ getModuleName(),
+ con.getBeanMetaData()
+ );
+ if (debug) {
+ log.debug( "Application.start(), EJB: " + lEJB );
+ }
+ if( lEJB != null ) {
+ con.mEJBObjectName = lEJB.toString();
+ }
+ }
+ }
+
/**
* The mbean Service interface <code>start</code> method calls
* the start method on each contatiner, then the init method on each
@@ -216,33 +256,13 @@
{
boolean debug = log.isDebugEnabled();
- log.debug( "Application.start(), begin" );
- for (Iterator i = containers.values().iterator(); i.hasNext();)
- {
- Container con = (Container)i.next();
- con.create();
- }
for (Iterator i = containers.values().iterator(); i.hasNext();)
{
Container con = (Container)i.next();
if (debug) {
log.debug( "Application.start(), start container: " + con );
}
-
- con.start();
- // Create JSR-77 EJB-Wrapper
- log.debug( "Application.start(), create JSR-77 EJB-Component" );
- ObjectName lEJB = EJB.create(
- con.mbeanServer,
- getModuleName(),
- con.getBeanMetaData()
- );
- if (debug) {
- log.debug( "Application.start(), EJB: " + lEJB );
- }
- if( lEJB != null ) {
- con.mEJBObjectName = lEJB.toString();
- }
+ serviceController.start(con.getJmxName());
}
}
@@ -254,8 +274,21 @@
for (Iterator i = containers.values().iterator(); i.hasNext();)
{
Container con = (Container)i.next();
- con.stop();
+ try
+ {
+ serviceController.stop(con.getJmxName());
+ }
+ catch (Exception e)
+ {
+ //no log here, but this shouldn't happen.
+ //log.error("unexpected exception stopping Container: " +
con.getJmxName(), e);
+ } // end of try-catch
+
}
+ }
+
+ public void destroy()
+ {
for (Iterator i = containers.values().iterator(); i.hasNext();)
{
Container con = (Container)i.next();
@@ -263,7 +296,15 @@
if( con.mEJBObjectName != null ) {
EJB.destroy( con.mbeanServer, con.mEJBObjectName );
}
- con.destroy();
+ try
+ {
+ serviceController.destroy(con.getJmxName());
+ serviceController.remove(con.getJmxName());
+ }
+ catch (Exception e)
+ {
+ //log.error("unexpected exception destroying Container: " +
con.getJmxName(), e);
+ } // end of try-catch
}
}
1.77 +162 -77 jboss/src/main/org/jboss/ejb/Container.java
Index: Container.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/Container.java,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- Container.java 17 Feb 2002 03:06:45 -0000 1.76
+++ Container.java 20 Feb 2002 17:40:11 -0000 1.77
@@ -7,21 +7,25 @@
package org.jboss.ejb;
-import java.lang.reflect.Method;
-import java.rmi.MarshalledObject; // tmp
-import java.net.URL;
+
+
+
+
+import java.lang.reflect.Method;
import java.net.MalformedURLException;
+import java.net.URL;
+import java.rmi.MarshalledObject; // tmp
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import java.util.HashMap;
import java.util.Set;
-
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
@@ -32,34 +36,33 @@
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.naming.Context;
-import javax.naming.Name;
import javax.naming.InitialContext;
import javax.naming.LinkRef;
-import javax.naming.Reference;
+import javax.naming.Name;
+import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
-import javax.naming.StringRefAddr;
import javax.naming.RefAddr;
-import javax.naming.NameNotFoundException;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
import javax.transaction.Transaction; // tmp
import javax.transaction.TransactionManager;
-
import org.jboss.deployment.DeploymentException;
+import org.jboss.ejb.BeanLockManager;
+import org.jboss.ejb.plugins.local.BaseLocalContainerInvoker;
import org.jboss.invocation.Invocation;
import org.jboss.invocation.MarshalledInvocation;
-import org.jboss.ejb.BeanLockManager;
import org.jboss.logging.Logger;
+import org.jboss.metadata.ApplicationMetaData;
import org.jboss.metadata.BeanMetaData;
-import org.jboss.metadata.EnvEntryMetaData;
-import org.jboss.metadata.EjbRefMetaData;
import org.jboss.metadata.EjbLocalRefMetaData;
-import org.jboss.metadata.ResourceRefMetaData;
+import org.jboss.metadata.EjbRefMetaData;
+import org.jboss.metadata.EnvEntryMetaData;
import org.jboss.metadata.ResourceEnvRefMetaData;
-import org.jboss.metadata.ApplicationMetaData;
+import org.jboss.metadata.ResourceRefMetaData;
import org.jboss.naming.Util;
import org.jboss.security.AuthenticationManager;
import org.jboss.security.RealmMapping;
-
-import org.jboss.ejb.plugins.local.BaseLocalContainerInvoker;
+import org.jboss.util.jmx.ObjectNameFactory;
/**
* This is the base class for all EJB-containers in JBoss. A Container
@@ -79,7 +82,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>.
* @author <a href="[EMAIL PROTECTED]">Bill Burke</a>
-* @version $Revision: 1.76 $
+* @version $Revision: 1.77 $
** <p><b>Revisions:</b>
*
* <p><b>2001/07/26 bill burke:</b>
@@ -173,6 +176,9 @@
/** ObjectName of the JSR-77 EJB representation **/
protected String mEJBObjectName;
+ /** ObjectName of Container **/
+ private ObjectName jmxName;
+
/**
* The name of the Remote invoker dedicated to this container,
* the type is set through deployment
@@ -185,6 +191,13 @@
// We need the visibility on the MBeanServer for prototyping, it will be removed
in the future FIXME marcf
//protected MBeanServer mbeanServer;
public MBeanServer mbeanServer;
+
+ /**
+ * boolean <code>started</code> indicates if this container is currently started.
+ * if not, calls to non lifecycle methods will raise exceptions.
+ *
+ */
+ private boolean started = false;
// Public --------------------------------------------------------
@@ -401,6 +414,21 @@
return getBeanClass().newInstance();
}
+
+ public ObjectName getJmxName()
+ {
+ String jndiName = getBeanMetaData().getJndiName();
+ if (jndiName == null)
+ {
+ throw new IllegalStateException("cannot get Container object name unless
jndi name is set!");
+ } // end of if ()
+ if (jmxName == null)
+ {
+ jmxName =
ObjectNameFactory.create("jboss.j2ee:service=EJB,jndiName="+jndiName);
+ } // end of if ()
+ return jmxName;
+ }
+
/**
* The EJBDeployer calls this method. The EJBDeployer has set
* all the plugins and interceptors that this bean requires and now proceeds
@@ -445,10 +473,8 @@
*/
public void start() throws Exception
{
+ started = true;
localContainerInvoker.start();
- String jndiName = this.getBeanMetaData().getJndiName();
- ObjectName jmxName = new
ObjectName("jboss.j2ee:service=EJB,jndiName="+jndiName);
- mbeanServer.registerMBean(this, jmxName);
}
/**
@@ -458,16 +484,8 @@
*/
public void stop()
{
+ started = false;
localContainerInvoker.stop();
- try
- {
- String jndiName = this.getBeanMetaData().getJndiName();
- ObjectName jmxName = new
ObjectName("jboss.j2ee:service=EJB,jndiName="+jndiName);
- mbeanServer.unregisterMBean(jmxName);
- }
- catch(Exception e)
- {
- }
}
/**
@@ -545,29 +563,32 @@
public Object invoke(String ignored, Object[] params, String[] signature)
throws MBeanException, ReflectionException
{
- if (params != null && params.length == 1 && (params[0] instanceof Invocation)
== false) {
- log.error("Expected zero or single Invocation argument");
- new IllegalArgumentException("Expected zero or single Invocation
argument");
- }
+ if (params != null && params.length == 1 && (params[0] instanceof Invocation))
+ {
+ if (!started)
+ {
+ throw new IllegalStateException("container is not started, you cannot
invoke ejb methods on it");
+ } // end of if ()
+
- Object value = null;
- Invocation mi = (Invocation)params[0];
+ Object value = null;
+ Invocation mi = (Invocation)params[0];
- // Must have a valid Invocation to continue
- if (mi == null)
- {
- log.error("Method invocation object is null");
- throw new IllegalArgumentException("Method invocation object is null");
- }
+ // Must have a valid Invocation to continue
+ if (mi == null)
+ {
+ log.error("Method invocation object is null");
+ throw new IllegalArgumentException("Method invocation object is null");
+ }
- ClassLoader callerClassLoader =
Thread.currentThread().getContextClassLoader();
- boolean trace = log.isTraceEnabled();
- try
- {
- Thread.currentThread().setContextClassLoader(this.classLoader);
- switch (mi.getType())
+ ClassLoader callerClassLoader =
Thread.currentThread().getContextClassLoader();
+ boolean trace = log.isTraceEnabled();
+ try
{
- // Check against home, remote, localHome, local, getHome, getRemote,
getLocalHome, getLocal
+ Thread.currentThread().setContextClassLoader(this.classLoader);
+ switch (mi.getType())
+ {
+ // Check against home, remote, localHome, local, getHome, getRemote,
getLocalHome, getLocal
case Invocation.REMOTE:
if (mi instanceof MarshalledInvocation)
{
@@ -660,7 +681,7 @@
value = invokeHome(mi);
- break;
+ break;
case Invocation.LOCALHOME:
@@ -675,7 +696,7 @@
value = clazz;
}
- break;
+ break;
case Invocation.GETREMOTE:
@@ -686,34 +707,75 @@
value = clazz;
}
- break;
+ break;
case Invocation.GETLOCALHOME:
value = this.localHomeInterface;
- break;
+ break;
case Invocation.GETLOCAL:
value = this.localInterface;
- break;
+ break;
- ///throw new MBeanException(new IllegalArgumentException("Unknown
action: "));
+ ///throw new MBeanException(new IllegalArgumentException("Unknown
action: "));
+ }
+ }
+ catch (Exception e)
+ {
+ throw new MBeanException(e, "invoke failed");
}
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(callerClassLoader);
+ }
+
+ return value;
}
- catch (Exception e)
+ else if (params == null || params.length == 0)
{
- throw new MBeanException(e, "invoke failed");
- }
- finally
+ try
+ {
+ if ("create".equals(ignored) )
+ {
+ create();
+ } // end of if ()
+ else if ("start".equals(ignored))
+ {
+ start();
+ } // end of if ()
+ else if ("stop".equals(ignored))
+ {
+ stop();
+ } // end of if ()
+ else if ("destroy".equals(ignored))
+ {
+ destroy();
+ } // end of if ()
+ else
+ {
+ throw new IllegalArgumentException("unknown operation! " + ignored);
+ } // end of else
+ return null;
+ }
+ catch (Exception e)
+ {
+ log.error("Exception in service lifecyle operation: " + ignored, e);
+ throw new MBeanException(e, "Exception in service lifecyle operation: "
+ ignored);
+ } // end of try-catch
+
+
+ } // end of if ()
+ else
{
- Thread.currentThread().setContextClassLoader(callerClassLoader);
- }
+ log.error("Expected zero or single Invocation argument");
+ throw new IllegalArgumentException("Expected zero or single Invocation
argument");
+ } // end of else
- return value;
}
/**
@@ -727,29 +789,51 @@
* <li>'local' -> not implemented;</li>
* <li>'getHome' -> return EBJHome interface;</li>
* <li>'getRemote' -> return EJBObject interface</li>
+ * <li>'create' -> create service lifecycle operation</li>
+ * <li>'start' -> start service lifecycle operation</li>
+ * <li>'stop' -> stop service lifecycle operation</li>
+ * <li>'destroy' -> destroy service lifecycle operation</li>
* </ul>
*/
public MBeanInfo getMBeanInfo()
{
- MBeanParameterInfo miInfo = new MBeanParameterInfo("method",
Invocation.class.getName(), "Invocation data");
- MBeanConstructorInfo[] ctorInfo = null;
+ MBeanParameterInfo[] miInfoParams = new MBeanParameterInfo[] {new
MBeanParameterInfo("method", Invocation.class.getName(), "Invocation data")};
+ MBeanParameterInfo[] noParams = new MBeanParameterInfo[] {};
+ MBeanConstructorInfo[] ctorInfo = new MBeanConstructorInfo[] {};
+ MBeanAttributeInfo[] attrInfo = new MBeanAttributeInfo[] {};
MBeanOperationInfo[] opInfo = {
new MBeanOperationInfo("home", "Invoke an EJBHome interface method",
- new MBeanParameterInfo[] {miInfo},
+ miInfoParams,
"java.lang.Object", MBeanOperationInfo.ACTION_INFO),
new MBeanOperationInfo("remote", "Invoke an EJBObject interface method",
- new MBeanParameterInfo[] {miInfo},
+ miInfoParams,
"java.lang.Object", MBeanOperationInfo.ACTION_INFO),
new MBeanOperationInfo("getHome", "Get the EJBHome interface class",
- null,
+ noParams,
"java.lang.Class", MBeanOperationInfo.INFO),
new MBeanOperationInfo("getRemote", "Get the EJBObject interface class",
- null,
- "java.lang.Class", MBeanOperationInfo.INFO)
+ noParams,
+ "java.lang.Class", MBeanOperationInfo.INFO),
+ new MBeanOperationInfo("create", "create service lifecycle operation",
+ noParams,
+ "void", MBeanOperationInfo.ACTION),
+ new MBeanOperationInfo("start", "start service lifecycle operation",
+ noParams,
+ "void", MBeanOperationInfo.ACTION),
+ new MBeanOperationInfo("stop", "stop service lifecycle operation",
+ noParams,
+ "void", MBeanOperationInfo.ACTION),
+ new MBeanOperationInfo("destroy", "destroy service lifecycle operation",
+ noParams,
+ "void", MBeanOperationInfo.ACTION)
};
MBeanNotificationInfo[] notifyInfo = null;
- return new MBeanInfo(getClass().getName(), "EJB Container MBean",
- null, ctorInfo, opInfo, notifyInfo);
+ return new MBeanInfo(getClass().getName(),
+ "EJB Container MBean",
+ attrInfo,
+ ctorInfo,
+ opInfo,
+ notifyInfo);
}
// End DynamicMBean interface
@@ -854,12 +938,13 @@
{
// Internal link
log.debug("Binding "+refName+" to bean source: "+ref.getLink());
- if (getApplication().getContainer(ref.getLink()) == null)
- throw new DeploymentException ("Bean "+ref.getLink()+" not
found within this application.");
- /* Create a link from the ENC to the localJndiName where the
- which is the location of the local home
- */
- Util.bind(envCtx, refName, new LinkRef(localJndiName));
+ Container refContainer =
getApplication().getContainer(ref.getLink());
+ if (refContainer == null)
+ {
+ throw new DeploymentException ("Bean "+ref.getLink()+" not
found within this application.");
+ }
+
+ Util.bind(envCtx, ref.getName(), new
LinkRef(refContainer.getBeanMetaData().getLocalJndiName()));
}
else
{
1.10 +5 -5 jboss/src/main/org/jboss/ejb/EJBDeployer.java
Index: EJBDeployer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/EJBDeployer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- EJBDeployer.java 18 Feb 2002 02:58:57 -0000 1.9
+++ EJBDeployer.java 20 Feb 2002 17:40:11 -0000 1.10
@@ -74,7 +74,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>
-* @version $Revision: 1.9 $
+* @version $Revision: 1.10 $
*/
public class EJBDeployer
extends ServiceMBeanSupport
@@ -401,7 +401,7 @@
NDC.pop();
// Create application
- Application app = new Application();
+ Application app = new Application(server);
try
{
@@ -430,7 +430,7 @@
}
// Init application
- //app.create();
+ app.create();
// Start application
if (debug)
{
@@ -470,7 +470,7 @@
{
log.error("Could not deploy " + sdi.url, e);
app.stop();
- //app.destroy();
+ app.destroy();
throw new DeploymentException( "Could not deploy " + sdi.url, e );
}
@@ -504,7 +504,7 @@
// Undeploy application
log.info( "Undeploying:" + url );
app.stop();
- //app.destroy();
+ app.destroy();
/*
1.69 +21 -23 jboss/src/main/org/jboss/ejb/EntityContainer.java
Index: EntityContainer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/EntityContainer.java,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- EntityContainer.java 16 Feb 2002 07:21:50 -0000 1.68
+++ EntityContainer.java 20 Feb 2002 17:40:11 -0000 1.69
@@ -62,7 +62,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel OConnor</a>
* @author <a href="[EMAIL PROTECTED]">Bill Burke</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>
-* @version $Revision: 1.68 $
+* @version $Revision: 1.69 $
*
* <p><b>Revisions:</b>
*
@@ -941,29 +941,27 @@
{
MBeanParameterInfo miInfo = new MBeanParameterInfo("method",
Invocation.class.getName(), "Invocation data");
MBeanConstructorInfo[] ctorInfo = null;
- MBeanOperationInfo[] opInfo = {
- new MBeanOperationInfo("home", "Invoke an EJBHome interface method",
- new MBeanParameterInfo[] {miInfo},
- "java.lang.Object", MBeanOperationInfo.ACTION_INFO),
- new MBeanOperationInfo("remote", "Invoke an EJBObject interface method",
- new MBeanParameterInfo[] {miInfo},
- "java.lang.Object", MBeanOperationInfo.ACTION_INFO),
- new MBeanOperationInfo("getHome", "Get the EJBHome interface class",
- null,
- "java.lang.Class", MBeanOperationInfo.INFO),
- new MBeanOperationInfo("getRemote", "Get the EJBObject interface class",
- null,
- "java.lang.Class", MBeanOperationInfo.INFO),
+
+ MBeanParameterInfo[] miInfoParams = new MBeanParameterInfo[] {new
MBeanParameterInfo("method", Invocation.class.getName(), "Invocation data")};
+ MBeanParameterInfo[] noParams = new MBeanParameterInfo[] {};
+
+ MBeanInfo superInfo = super.getMBeanInfo();
+ int superOpInfoCount = superInfo.getOperations().length;
+ MBeanOperationInfo[] opInfo = new MBeanOperationInfo[superOpInfoCount +2];
+ System.arraycopy(superInfo.getOperations(), 0, opInfo, 0, superOpInfoCount);
+ opInfo[superOpInfoCount] =
new MBeanOperationInfo("getCacheSize", "Get the Container cache size.",
- null,
- "java.lang.Integer", MBeanOperationInfo.INFO),
+ noParams,
+ "java.lang.Integer", MBeanOperationInfo.INFO);
+ opInfo[superOpInfoCount + 1] =
new MBeanOperationInfo("flushCache", "Flush the Container cache.",
- null,
- "", MBeanOperationInfo.ACTION_INFO)
- };
- MBeanNotificationInfo[] notifyInfo = null;
- return new MBeanInfo(getClass().getName(), "EJB Container MBean",
- null, ctorInfo, opInfo, notifyInfo);
+ noParams,
+ "void", MBeanOperationInfo.ACTION);
+ return new MBeanInfo(getClass().getName(),
+ "EJB Entity Container MBean",
+ superInfo.getAttributes(),
+ superInfo.getConstructors(),
opInfo,
+ superInfo.getNotifications());
}
/**
@@ -994,7 +992,7 @@
return null;
}
- else return super.invoke("", params, signature);
+ else return super.invoke(actionName, params, signature);
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development