User: schaefera
Date: 02/02/26 20:36:45
Modified: src/main/org/jboss/management/j2ee EJB.java EjbModule.java
J2EEApplication.java J2EEServer.java
JDBCDataSource.java JavaMail.java
Log:
Fixed a problem with dropping a standalone EJB module.
Applied patches from Scott McLaughlin:
- Fixes for EjbModule, EJB, J2EEserver, JDBCDataSource
- Adding JavaMail Resource and its MBean
Revision Changes Path
1.8 +3 -3 jboss/src/main/org/jboss/management/j2ee/EJB.java
Index: EJB.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/management/j2ee/EJB.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- EJB.java 13 Feb 2002 06:00:37 -0000 1.7
+++ EJB.java 27 Feb 2002 04:36:45 -0000 1.8
@@ -19,7 +19,7 @@
* {@link javax.management.j2ee.EJB EJB}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>.
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*
* <p><b>Revisions:</b>
*
@@ -67,7 +67,7 @@
).getObjectName();
}
catch( Exception e ) {
-//AS lLog.error( "Could not create JSR-77 EJB: " + pBeanMeta.getJndiName(),
e );
+ lLog.error( "Could not create JSR-77 EJB: " + pBeanMeta.getJndiName(), e );
return null;
}
}
@@ -79,7 +79,7 @@
pServer.unregisterMBean( new ObjectName( pEJBName ) );
}
catch( Exception e ) {
-//AS lLog.error( "Could not destory JSR-77 EJB: " + pEJBName, e );
+ lLog.error( "Could not destory JSR-77 EJB: " + pEJBName, e );
}
}
1.12 +88 -4 jboss/src/main/org/jboss/management/j2ee/EjbModule.java
Index: EjbModule.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/management/j2ee/EjbModule.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- EjbModule.java 13 Feb 2002 06:00:37 -0000 1.11
+++ EjbModule.java 27 Feb 2002 04:36:45 -0000 1.12
@@ -11,8 +11,11 @@
import java.util.ArrayList;
import java.util.List;
+import javax.management.AttributeChangeNotification;
import javax.management.MalformedObjectNameException;
import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.j2ee.EJB;
@@ -23,13 +26,14 @@
import java.security.InvalidParameterException;
import org.jboss.logging.Logger;
+import org.jboss.system.ServiceMBean;
/**
* Root class of the JBoss JSR-77 implementation of
* {@link javax.management.j2ee.EJBModule EJBModule}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>.
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*
* <p><b>Revisions:</b>
*
@@ -49,9 +53,21 @@
// Attributes ----------------------------------------------------
private List mEJBs = new ArrayList();
+ private long mStartTime = -1;
+ private int mState = ServiceMBean.STOPPED;
// Static --------------------------------------------------------
+ private static final String[] sTypes = new String[] {
+ "j2ee.object.created",
+ "j2ee.object.deleted",
+ "state.stopped",
+ "state.stopping",
+ "state.starting",
+ "state.running",
+ "state.failed"
+ };
+
public static ObjectName create( MBeanServer pServer, String pApplicationName,
String pName, URL pURL ) {
Logger lLog = Logger.getLogger( EjbModule.class );
String lDD = null;
@@ -74,7 +90,7 @@
lDD = J2EEDeployedObject.getDeploymentDescriptor( pURL,
J2EEDeployedObject.EJB );
}
catch( Exception e ) {
-//AS lLog.error( "Could not create JSR-77 EjbModule: " + pApplicationName,
e );
+ lLog.error( "Could not create JSR-77 EjbModule: " + pApplicationName, e );
return null;
}
try {
@@ -100,7 +116,7 @@
).getObjectName();
}
catch( Exception e ) {
-//AS lLog.error( "Could not create JSR-77 EjbModule: " + pApplicationName,
e );
+ lLog.error( "Could not create JSR-77 EjbModule: " + pApplicationName, e );
return null;
}
}
@@ -112,7 +128,7 @@
pServer.unregisterMBean( new ObjectName( pModuleName ) );
}
catch( Exception e ) {
-//AS lLog.error( "Could not destory JSR-77 EjbModule: " + pModuleName, e );
+ lLog.error( "Could not destory JSR-77 EjbModule: " + pModuleName, e );
}
}
@@ -177,6 +193,44 @@
}
}
+ // org.jboss.ServiceMBean overrides ------------------------------------
+
+ public void postRegister( Boolean pRegisterationDone ) {
+ super.postRegister( pRegisterationDone );
+ // If set then register for its events
+/*
+ try {
+ getServer().addNotificationListener( mService, new Listener(), null, null
);
+ }
+ catch( JMException jme ) {
+ //AS ToDo: later on we have to define what happens when service is null or
+ //AS ToDo: not found.
+ jme.printStackTrace();
+ }
+*/
+ sendNotification(
+ new Notification(
+ sTypes[ 0 ],
+ getName(),
+ 1,
+ System.currentTimeMillis(),
+ "EJB Module created"
+ )
+ );
+ }
+
+ public void preDeregister() {
+ sendNotification(
+ new Notification(
+ sTypes[ 1 ],
+ getName(),
+ 1,
+ System.currentTimeMillis(),
+ "EJB Module deleted"
+ )
+ );
+ }
+
// Object overrides ---------------------------------------------------
public String toString() {
@@ -192,4 +246,34 @@
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
+
+ private class Listener implements NotificationListener {
+
+ public void handleNotification( Notification pNotification, Object pHandback )
+ {
+ if( pNotification instanceof AttributeChangeNotification ) {
+ AttributeChangeNotification lChange = (AttributeChangeNotification)
pNotification;
+ if( "State".equals( lChange.getAttributeName() ) )
+ {
+ mState = ( (Integer) lChange.getNewValue() ).intValue();
+ if( mState == ServiceMBean.STARTED ) {
+ mStartTime = lChange.getTimeStamp();
+ } else {
+ mStartTime = -1;
+ }
+ // Now send the event to the JSR-77 listeners
+ sendNotification(
+ new Notification(
+ sTypes[ getState() + 2 ],
+ getName(),
+ 1,
+ System.currentTimeMillis(),
+ "State changed"
+ )
+ );
+ }
+ }
+ }
+
+ }
}
1.9 +16 -11 jboss/src/main/org/jboss/management/j2ee/J2EEApplication.java
Index: J2EEApplication.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/management/j2ee/J2EEApplication.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- J2EEApplication.java 13 Feb 2002 06:00:37 -0000 1.8
+++ J2EEApplication.java 27 Feb 2002 04:36:45 -0000 1.9
@@ -24,7 +24,7 @@
* {@link javax.management.j2ee.J2EEApplication J2EEApplication}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>.
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
*
* <p><b>Revisions:</b>
*
@@ -83,7 +83,7 @@
).getObjectName();
}
catch( Exception e ) {
-//AS lLog.error( "Could not create JSR-77 J2EEApplication: " + pName, e );
+ lLog.error( "Could not create JSR-77 J2EEApplication: " + pName, e );
return null;
}
}
@@ -91,19 +91,24 @@
public static void destroy( MBeanServer pServer, String pName ) {
Logger lLog = Logger.getLogger( J2EEApplication.class );
try {
- // Find the Object to be destroyed
- ObjectName lSearch = new ObjectName(
- J2EEManagedObject.getDomainName() + ":type=J2EEApplication,name=" +
pName + ",*"
- );
- ObjectName lApplication = (ObjectName) pServer.queryNames(
- lSearch,
- null
- ).iterator().next();
+ ObjectName lApplication;
+ if( pName.indexOf( "type=J2EEApplication" ) >= 0 ) {
+ lApplication = new ObjectName( pName );
+ } else {
+ // Find the Object to be destroyed
+ ObjectName lSearch = new ObjectName(
+ J2EEManagedObject.getDomainName() + ":type=J2EEApplication,name=" +
pName + ",*"
+ );
+ lApplication = (ObjectName) pServer.queryNames(
+ lSearch,
+ null
+ ).iterator().next();
+ }
// Now remove the J2EEApplication
pServer.unregisterMBean( lApplication );
}
catch( Exception e ) {
-//AS lLog.error( "Could not destroy JSR-77 J2EEApplication: " + pName, e );
+ lLog.error( "Could not destroy JSR-77 J2EEApplication: " + pName, e );
}
}
1.7 +9 -3 jboss/src/main/org/jboss/management/j2ee/J2EEServer.java
Index: J2EEServer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/management/j2ee/J2EEServer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- J2EEServer.java 10 Dec 2001 06:27:49 -0000 1.6
+++ J2EEServer.java 27 Feb 2002 04:36:45 -0000 1.7
@@ -19,7 +19,7 @@
* J2EEServer}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
*
* <p><b>Revisions:</b>
*
@@ -116,7 +116,10 @@
String lType = J2EEManagedObject.getType( pChild );
if(
"J2EEApplication".equals( lType ) ||
- "J2EEModule".equals( lType )
+ "J2EEModule".equals( lType ) ||
+ "EjbModule".equals( lType ) ||
+ "ConnectorModule".equals( lType ) ||
+ "WebModule".equals( lType )
) {
mDeployedObjects.add( pChild );
} else if( "Node".equals( lType ) ) {
@@ -140,7 +143,10 @@
String lType = J2EEManagedObject.getType( pChild );
if(
"J2EEApplication".equals( lType ) ||
- "J2EEModule".equals( lType )
+ "J2EEModule".equals( lType ) ||
+ "EjbModule".equals( lType ) ||
+ "ConnectorModule".equals( lType ) ||
+ "WebModule".equals( lType )
) {
mDeployedObjects.remove( pChild );
} else if( "Node".equals( lType ) ) {
1.8 +8 -7 jboss/src/main/org/jboss/management/j2ee/JDBCDataSource.java
Index: JDBCDataSource.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/management/j2ee/JDBCDataSource.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- JDBCDataSource.java 9 Feb 2002 16:21:33 -0000 1.7
+++ JDBCDataSource.java 27 Feb 2002 04:36:45 -0000 1.8
@@ -24,7 +24,7 @@
* {@link javax.management.j2ee.JDBCDataSource JDBCDataSource}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>.
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*
* <p><b>Revisions:</b>
*
@@ -63,7 +63,7 @@
};
public static ObjectName create( MBeanServer pServer, String pName, ObjectName
pService ) {
- Logger lLog = Logger.getLogger( JNDI.class );
+ Logger lLog = Logger.getLogger( JDBCDataSource.class );
ObjectName lServer = null;
try {
lServer = (ObjectName) pServer.queryNames(
@@ -124,7 +124,7 @@
}
public static void destroy( MBeanServer pServer, String pName ) {
- Logger lLog = Logger.getLogger( JNDI.class );
+ Logger lLog = Logger.getLogger( JDBCDataSource.class );
try {
// Find the Object to be destroyed
ObjectName lSearch = new ObjectName(
@@ -242,10 +242,11 @@
);
}
- public void preDeregister() {
- Logger log = getLog();
- if (log.isInfoEnabled())
- log.info( "JDBCDataSource.preDeregister(): " + getName() );
+ public void preDeregister() {
+ Logger lLog = getLog();
+ if( lLog.isInfoEnabled() ) {
+ lLog.info( "JDBCDataSource.preDeregister(): " + getName() );
+ }
sendNotification(
new Notification(
sTypes[ 1 ],
1.4 +207 -10 jboss/src/main/org/jboss/management/j2ee/JavaMail.java
Index: JavaMail.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/management/j2ee/JavaMail.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JavaMail.java 27 Nov 2001 06:15:26 -0000 1.3
+++ JavaMail.java 27 Feb 2002 04:36:45 -0000 1.4
@@ -6,15 +6,23 @@
*/
package org.jboss.management.j2ee;
+import javax.management.AttributeChangeNotification;
+import javax.management.JMException;
import javax.management.MalformedObjectNameException;
+import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationListener;
import javax.management.ObjectName;
+import org.jboss.logging.Logger;
+import org.jboss.system.ServiceMBean;
+
/**
* Root class of the JBoss JSR-77 implementation of
* {@link javax.management.j2ee.JavaMail JavaMail}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>.
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*
* <p><b>Revisions:</b>
*
@@ -25,12 +33,80 @@
**/
public class JavaMail
extends J2EEResource
- implements javax.management.j2ee.JavaMail
+ implements JavaMailMBean
{
- // -------------------------------------------------------------------------
- // Members
- // -------------------------------------------------------------------------
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private long mStartTime = -1;
+ private int mState = ServiceMBean.STOPPED;
+ private ObjectName mService;
+
+ // Static --------------------------------------------------------
+
+ private static final String[] sTypes = new String[] {
+ "j2ee.object.created",
+ "j2ee.object.deleted",
+ "state.stopped",
+ "state.stopping",
+ "state.starting",
+ "state.running",
+ "state.failed"
+ };
+ public static ObjectName create( MBeanServer pServer, String pName, ObjectName
pService ) {
+ Logger lLog = Logger.getLogger( JavaMail.class );
+ ObjectName lServer = null;
+ try {
+ lServer = (ObjectName) pServer.queryNames(
+ new ObjectName( J2EEManagedObject.getDomainName() +
":type=J2EEServer,*" ),
+ null
+ ).iterator().next();
+ }
+ catch( Exception e ) {
+ lLog.error( "Could not create JSR-77 Server", e );
+ return null;
+ }
+ try {
+ // Now create the JNDI Representant
+ return pServer.createMBean(
+ "org.jboss.management.j2ee.JavaMail",
+ null,
+ new Object[] {
+ pName,
+ lServer,
+ pService
+ },
+ new String[] {
+ String.class.getName(),
+ ObjectName.class.getName(),
+ ObjectName.class.getName()
+ }
+ ).getObjectName();
+ }
+ catch( Exception e ) {
+ lLog.error( "Could not create JSR-77 JavaMail Resouce", e );
+ return null;
+ }
+ }
+
+ public static void destroy( MBeanServer pServer, String pName ) {
+ Logger lLog = Logger.getLogger( JavaMail.class );
+ try {
+ // Find the Object to be destroyed
+ System.out.println("JavaMail Destroy : " +
J2EEManagedObject.getDomainName() + ":type=JavaMail,name=" + pName + ",*");
+ ObjectName lSearch = new ObjectName(
+ J2EEManagedObject.getDomainName() + ":type=JavaMail,name=" + pName +
",*"
+ );
+
+ pServer.unregisterMBean( lSearch );
+ }
+ catch( Exception e ) {
+ lLog.error( "Could not destroy JSR-77 JavaMail Resource", e );
+ }
+ }
+
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
@@ -40,21 +116,142 @@
*
* @throws InvalidParameterException If list of nodes or ports was null or empty
**/
- public JavaMail( String pName, ObjectName pServer )
+ public JavaMail( String pName, ObjectName pServer, ObjectName pService )
throws
MalformedObjectNameException,
InvalidParentException
{
super( "JavaMail", pName, pServer );
+ mService = pService;
}
- // -------------------------------------------------------------------------
- // Properties (Getters/Setters)
- // -------------------------------------------------------------------------
+ // org.jboss.ServiceMBean overrides ------------------------------------
+ public void postRegister( Boolean pRegisterationDone ) {
+ super.postRegister( pRegisterationDone );
+ // If set then register for its events
+ try {
+ getServer().addNotificationListener( mService, new Listener(), null, null
);
+ }
+ catch( JMException jme ) {
+ //AS ToDo: later on we have to define what happens when service is null or
+ //AS ToDo: not found.
+ jme.printStackTrace();
+ }
+ sendNotification(
+ new Notification(
+ sTypes[ 0 ],
+ getName(),
+ 1,
+ System.currentTimeMillis(),
+ "JavaMail Resource created"
+ )
+ );
+ }
+
+ public void preDeregister() {
+ sendNotification(
+ new Notification(
+ sTypes[ 1 ],
+ getName(),
+ 1,
+ System.currentTimeMillis(),
+ "JavaMail Resource deleted"
+ )
+ );
+ }
+
+ // javax.managment.j2ee.EventProvider implementation -------------
+
+ public String[] getTypes() {
+ return sTypes;
+ }
+
+ public String getType( int pIndex ) {
+ if( pIndex >= 0 && pIndex < sTypes.length ) {
+ return sTypes[ pIndex ];
+ } else {
+ return null;
+ }
+ }
+
+ // javax.management.j2ee.StateManageable implementation ----------
+
+ public long getStartTime() {
+ return mStartTime;
+ }
+
+ public int getState() {
+ return mState;
+ }
+
+ /**
+ * This method is only overwriten because to catch the exception
+ * which is not specified in {@link javax.management.j2ee.StateManageable
+ * StateManageable} interface.
+ **/
+ public void start()
+ {
+ try {
+ super.start();
+ }
+ catch( Exception e ) {
+ getLog().error( "start failed", e );
+ }
+ }
+
+ public void startRecursive() {
+ // No recursive start here
+ try {
+ start();
+ }
+ catch( Exception e ) {
+ getLog().error( "start failed", e );
+ }
+ }
+
+ // java.lang.Object overrides ------------------------------------
+
public String toString() {
- return "JavaMail [ " +
- "name: " + getName() +
+ return "JavaMail { " + super.toString() + " } [ " +
" ]";
}
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+ private class Listener implements NotificationListener {
+
+ public void handleNotification( Notification pNotification, Object pHandback )
+ {
+ if( pNotification instanceof AttributeChangeNotification ) {
+ AttributeChangeNotification lChange = (AttributeChangeNotification)
pNotification;
+ if( "State".equals( lChange.getAttributeName() ) )
+ {
+ mState = ( (Integer) lChange.getNewValue() ).intValue();
+ if( mState == ServiceMBean.STARTED ) {
+ mStartTime = lChange.getTimeStamp();
+ } else {
+ mStartTime = -1;
+ }
+ // Now send the event to the JSR-77 listeners
+ sendNotification(
+ new Notification(
+ sTypes[ getState() + 2 ],
+ getName(),
+ 1,
+ System.currentTimeMillis(),
+ "State changed"
+ )
+ );
+ }
+ }
+ }
+ }
+
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development