User: schaefera
Date: 02/03/12 14:22:39
Modified: src/main/org/jboss/management/j2ee EJBModule.java
Added: src/main/org/jboss/management/j2ee StateManagement.java
Log:
Took the StateManageable implementation in a separate class and adjusted
EJBModule as test class.
Revision Changes Path
1.2 +33 -83
jboss-management/src/main/org/jboss/management/j2ee/EJBModule.java
Index: EJBModule.java
===================================================================
RCS file:
/cvsroot/jboss/jboss-management/src/main/org/jboss/management/j2ee/EJBModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EJBModule.java 11 Mar 2002 04:31:32 -0000 1.1
+++ EJBModule.java 12 Mar 2002 22:22:39 -0000 1.2
@@ -24,14 +24,13 @@
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.EJBModule EJBModule}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>.
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
* <p><b>Revisions:</b>
*
@@ -55,15 +54,13 @@
// Attributes ----------------------------------------------------
private List mEJBs = new ArrayList();
- private long mStartTime = -1;
- private int mState = ServiceMBean.STOPPED;
+ private StateManagement mState;
private ObjectName mService;
- private Listener mListener;
//used to see if we should remove our parent when we are destroyed.
private static final Map iCreatedParent = new HashMap();
// Static --------------------------------------------------------
-
+/*
private static final String[] sTypes = new String[] {
"j2ee.object.created",
"j2ee.object.deleted",
@@ -73,6 +70,7 @@
"state.running",
"state.failed"
};
+*/
/**
* @todo AS: Now JVMs managed added now
@@ -214,6 +212,7 @@
{
super( J2EE_TYPE, pName, pApplication, pJVMs, pDeploymentDescriptor );
mService = pService;
+ mState = new StateManagement( this );
}
// Public --------------------------------------------------------
@@ -267,8 +266,7 @@
public void postCreation() {
try {
- mListener = new Listener();
- getServer().addNotificationListener( mService, mListener, null, null );
+ getServer().addNotificationListener( mService, mState, null, null );
}
catch( JMException jme ) {
//AS ToDo: later on we have to define what happens when service is null or
@@ -277,7 +275,7 @@
}
sendNotification(
new Notification(
- sTypes[ 0 ],
+ StateManagement.sTypes[ 0 ],
getName(),
1,
System.currentTimeMillis(),
@@ -289,7 +287,7 @@
public void preDestruction() {
sendNotification(
new Notification(
- sTypes[ 1 ],
+ StateManagement.sTypes[ 1 ],
getName(),
1,
System.currentTimeMillis(),
@@ -298,7 +296,7 @@
);
// Remove the listener of the target MBean
try {
- getServer().removeNotificationListener( mService, mListener );
+ getServer().removeNotificationListener( mService, mState );
}
catch( JMException jme ) {
//AS ToDo: later on we have to define what happens when service is null or
@@ -310,12 +308,12 @@
// javax.managment.j2ee.EventProvider implementation -------------
public String[] getEventTypes() {
- return sTypes;
+ return StateManagement.sTypes;
}
public String getEventType( int pIndex ) {
- if( pIndex >= 0 && pIndex < sTypes.length ) {
- return sTypes[ pIndex ];
+ if( pIndex >= 0 && pIndex < StateManagement.sTypes.length ) {
+ return StateManagement.sTypes[ pIndex ];
} else {
return null;
}
@@ -324,20 +322,25 @@
// javax.management.j2ee.StateManageable implementation ----------
public long getStartTime() {
- return mStartTime;
+ return mState.getStartTime();
}
public int getState() {
- return mState;
+ return mState.getState();
}
public void mejbStart()
{
try {
- start();
+ getServer().invoke(
+ mService,
+ "start",
+ new Object[] {},
+ new String[] {}
+ );
}
catch( Exception e ) {
- getLog().error( "start failed", e );
+ getLog().error( "Start of EJBModule failed", e );
}
}
@@ -345,70 +348,48 @@
// No recursive start here
try {
mejbStart();
+/*AS EJBs are not state manageable right now
Iterator i = mEJBs.iterator();
while( i.hasNext() ) {
ObjectName lName = (ObjectName) i.next();
try {
getServer().invoke(
lName,
- "start",
+ "mejbStart",
new Object[] {},
new String[] {}
);
}
catch( JMException jme ) {
- getLog().error( "start of EJB failed", jme );
+ getLog().error( "Start of EJBModule failed", jme );
}
}
+*/
}
catch( Exception e ) {
- getLog().error( "startRecursive failed", e );
+ getLog().error( "Recursive Start of EJBModule failed", e );
}
}
public void mejbStop() {
try {
+/* AS EJBs are not state manageable right now
Iterator i = mEJBs.iterator();
while( i.hasNext() ) {
ObjectName lName = (ObjectName) i.next();
try {
getServer().invoke(
lName,
- "stop",
+ "mejStop",
new Object[] {},
new String[] {}
);
}
catch( JMException jme ) {
- getLog().error( "stop of EJB failed", jme );
+ getLog().error( "Recursive Stop of EJBModule failed", jme );
}
}
- stop();
- }
- catch( Exception e ) {
- getLog().error( "stop failed", e );
- }
- }
-
- // ServiceMBeanSupport overrides ---------------------------------
-
- public void startService() {
- try {
- getServer().invoke(
- mService,
- "start",
- new Object[] {},
- new String[] {}
- );
- }
- catch( JMException jme ) {
- //AS ToDo: later on we have to define what happens when service could not
be started
- jme.printStackTrace();
- }
- }
-
- public void stopService() {
- try {
+*/
getServer().invoke(
mService,
"stop",
@@ -416,12 +397,11 @@
new String[] {}
);
}
- catch( JMException jme ) {
- //AS ToDo: later on we have to define what happens when service could not
be stopped
- jme.printStackTrace();
+ catch( Exception e ) {
+ getLog().error( "Stop of EJBMOdule failed", e );
}
}
-
+
// Object overrides ---------------------------------------------------
public String toString() {
@@ -437,34 +417,4 @@
// 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.1
jboss-management/src/main/org/jboss/management/j2ee/StateManagement.java
Index: StateManagement.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.management.j2ee;
import java.security.InvalidParameterException;
import javax.management.AttributeChangeNotification;
import javax.management.Notification;
import javax.management.NotificationListener;
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.1 $
*
* <p><b>Revisions:</b>
*
* <p><b>20011123 Andreas Schaefer:</b>
* <ul>
* <li> Adjustments to the JBoss Guidelines and implementing of the
* the create() and destroy() helper method
* </ul>
**/
public class StateManagement
implements NotificationListener
{
// Constants -----------------------------------------------------
public static final String[] sTypes = new String[] {
"j2ee.object.created",
"j2ee.object.deleted",
"state.stopped",
"state.stopping",
"state.starting",
"state.running",
"state.failed"
};
// Attributes ----------------------------------------------------
private long mStartTime = -1;
private int mState = ServiceMBean.STOPPED;
private J2EEManagedObject mTarget;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
/**
* Constructor taking the Name of this Object
*
* @param pName Name to be set which must not be null
* @param pDeploymentDescriptor
*
* @throws InvalidParameterException If the given Name is null
**/
public StateManagement( J2EEManagedObject pTarget )
{
if( pTarget == null ) {
throw new InvalidParameterException( "Target for State Management must be
defined" );
}
mTarget = pTarget;
}
// Public --------------------------------------------------------
public long getStartTime() {
return mStartTime;
}
public void setStartTime( long pTime ) {
mStartTime = pTime;
}
public int getState() {
return mState;
}
public void setState( int pState ) {
// Only send a notification if the state really changes
if( pState != mState ) {
mState = pState;
// Now send the event to the JSR-77 listeners
mTarget.sendNotification(
new Notification(
sTypes[ mState + 2 ],
mTarget.getName(),
1,
System.currentTimeMillis(),
"State changed"
)
);
}
}
// NotificationListener overrides ---------------------------------
public void handleNotification( Notification pNotification, Object pHandback )
{
if( pNotification instanceof AttributeChangeNotification ) {
AttributeChangeNotification lChange = (AttributeChangeNotification)
pNotification;
if( "State".equals( lChange.getAttributeName() ) )
{
int lState = ( (Integer) lChange.getNewValue() ).intValue();
long lStartTime = -1;
if( lState == ServiceMBean.STARTED ) {
lStartTime = lChange.getTimeStamp();
}
setStartTime( lStartTime );
setState( lState );
}
}
}
// Object overrides ---------------------------------------------------
public String toString() {
return "StateManagement [ " +
"State: " + mState +
", Start Time: " + mStartTime +
" ]";
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development