User: schaefera
Date: 01/05/12 20:34:20
Added: src/main/org/jboss/mgt JBossApplication.java
JBossModule.java JBossServer.java
JBossServerMBean.java
Log:
First Draft for the JBoss management classes delivering the necessary
information for a management tool to work with JBoss.
Revision Changes Path
1.1 jboss/src/main/org/jboss/mgt/JBossApplication.java
Index: JBossApplication.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mgt;
import java.util.Collection;
/**
* Contains the management information about
* a deployed applications.
*
* @author Marc Fleury
**/
public class JBossApplication {
// -------------------------------------------------------------------------
// Members
// -------------------------------------------------------------------------
private String mApplicationId;
private String mDeploymentDescriptor;
private Collection mModules;
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
/**
* @param pApplicationId Id of these Application which must be unique within
* the node/server.
* @param pDeploymentDescriptor Deployment Descriptor of this application
* which maybe is not set.
* @param pModules Collection of modules deployed with the given application
* each item is of type {@link org.jboss.mgt.JBossModule
* JBossModule}.
**/
public JBossApplication(
String pApplicationId,
String pDeploymentDescriptor,
Collection pModules
) {
mApplicationId = pApplicationId;
setDeploymentDescriptor( pDeploymentDescriptor );
mModules = pModules;
}
// -------------------------------------------------------------------------
// Properties (Getters/Setters)
// -------------------------------------------------------------------------
/**
* @return Id of these Application
**/
public String getId() {
return mApplicationId;
}
/**
* Returns the deployment descriptor
*
* @return Deployment Descriptor of this application which maybe is not set.
**/
public String getDeploymentDescriptor() {
return mDeploymentDescriptor;
}
/**
* Sets the deployment descriptor
*
* @param pDeploymentDescriptor Deployment Descriptor of this application
* which maybe is not set.
**/
public void setDeploymentDescriptor( String pDeploymentDescriptor ) {
mDeploymentDescriptor = pDeploymentDescriptor;
}
/**
* Adds a new Module
*
* @param pModule Module to be added
**/
public void addModule( JBossModule pModule ) {
mModules.add( pModule );
}
/**
* Removes a Module
*
* @param pModule Module to be removed
**/
public void removeModule( JBossModule pModule ) {
mModules.remove( pModule );
}
/**
* @return Collection of Modules deployed with this application. Each
* item is of type {@link org.jboss.mgt.JBossModule JBossModule}.
**/
public Collection getModules() {
return mModules;
}
}
1.1 jboss/src/main/org/jboss/mgt/JBossModule.java
Index: JBossModule.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mgt;
import java.util.Collection;
/**
* Contains the management information about
* a deployed applications.
*
* @author Marc Fleury
**/
public class JBossModule {
// -------------------------------------------------------------------------
// Members
// -------------------------------------------------------------------------
private String mModuleId;
private String mDeploymentDescriptor;
private Collection mItems;
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
/**
* @param pModuleId Id of these module which must be unique within the
application.
* @param pDeploymentDescriptor Deployment Descriptor of this module
* @param pItems Collection of Entities
**/
public JBossModule(
String pModuleId,
String pDeploymentDescriptor,
Collection pItems
) {
mModuleId = pModuleId;
setDeploymentDescriptor( pDeploymentDescriptor );
mItems = pItems;
}
// -------------------------------------------------------------------------
// Properties (Getters/Setters)
// -------------------------------------------------------------------------
/**
* @return Id of these Module
**/
public String getId() {
return mModuleId;
}
/**
* Returns the deployment descriptor
*
* @return Deployment Descriptor of this module.
**/
public String getDeploymentDescriptor() {
return mDeploymentDescriptor;
}
/**
* Sets the deployment descriptor
*
* @param pDeploymentDescriptor Deployment Descriptor of this application
* which maybe is not set.
**/
public void setDeploymentDescriptor( String pDeploymentDescriptor ) {
mDeploymentDescriptor = pDeploymentDescriptor;
}
/**
* Adds a new Item
*
* @param pItem Item to be added
**/
public void addItem( Object pItem ) {
mItems.add( pItem );
}
/**
* Removes a Item
*
* @param pItem Item to be removed
**/
public void removeItem( Object pItem ) {
mItems.remove( pItem );
}
/**
* @return Collection of Items deployed with this application. Each
* item is of type {@link java.lang.Object Object}.
**/
public Collection getItems() {
return mItems;
}
}
1.1 jboss/src/main/org/jboss/mgt/JBossServer.java
Index: JBossServer.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mgt;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javax.management.MalformedObjectNameException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.NameNotFoundException;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import org.jboss.logging.Log;
import org.jboss.naming.NonSerializableFactory;
import org.jboss.util.ServiceMBeanSupport;
/**
* JBoss Management MBean Wrapper
*
* @author Marc Fleury
**/
public class JBossServer
extends ServiceMBeanSupport
implements JBossServerMBean
{
// -------------------------------------------------------------------------
// Constants
// -------------------------------------------------------------------------
public static String JNDI_NAME = "j2eeserver:domain";
public static String JMX_NAME = "j2eeserver";
// -------------------------------------------------------------------------
// Members
// -------------------------------------------------------------------------
private MBeanServer mServer;
private JBossServer mJBossServer;
private String mName;
private Collection mApplications = new ArrayList();
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
/**
* Default (no-args) Constructor
*
* @param pName Name of the MBean
**/
public JBossServer()
{
mName = null;
}
/**
* Constructor with the necessary attributes to be set
*
* @param pName Name of the MBean
**/
public JBossServer( String pName )
{
mName = pName;
}
// -------------------------------------------------------------------------
// Methods
// -------------------------------------------------------------------------
public ObjectName getObjectName(
MBeanServer server,
ObjectName name
)
throws MalformedObjectNameException
{
mServer = server;
return new ObjectName( OBJECT_NAME );
}
public String getJNDIName() {
if( mName != null ) {
return JMX_NAME + ":" + mName;
}
else {
return JMX_NAME;
}
}
public String getName() {
return "JBoss Server MBean";
}
public JBossApplication getApplication(
String pApplicationId
) {
// Loop through the applications and find the application
if( pApplicationId != null ) {
Iterator i = getApplications().iterator();
while( i.hasNext() ) {
JBossApplication lTest = (JBossApplication) i.next();
if( pApplicationId.equals( lTest.getId() ) ) {
return lTest;
}
}
}
return null;
}
public Collection getApplications() {
return mApplications;
}
public JBossApplication saveApplication(
JBossApplication pApplication
) {
JBossApplication lApplication = null;
if( lApplication != null ) {
lApplication = getApplication( pApplication.getId() );
if( lApplication == null ) {
// No application found -> add
mApplications.add( lApplication );
}
else {
// Application found -> replace
mApplications.remove( lApplication );
mApplications.add( pApplication );
}
}
return pApplication;
}
public void removeApplication(
String pApplicationId
) {
if( pApplicationId != null ) {
JBossApplication lApplication = getApplication( pApplicationId );
if( lApplication != null ) {
mApplications.remove( lApplication );
}
}
}
// -------------------------------------------------------------------------
// ServiceMBean - Methods
// -------------------------------------------------------------------------
protected void initService()
throws Exception
{
mJBossServer = new JBossServer( mName );
}
protected void startService()
throws Exception
{
bind( mJBossServer );
// refresh();
}
protected void stopService() {
try {
unbind();
}
catch( Exception e ) {
log.exception( e );
}
}
// -------------------------------------------------------------------------
// Helper methods to bind/unbind the Management class
// -------------------------------------------------------------------------
private void bind( JBossServer pServer )
throws
NamingException
{
Context lContext = new InitialContext();
String lJNDIName = getJNDIName();
// Ah ! JBoss Server isn't serializable, so we use a helper class
NonSerializableFactory.bind( lJNDIName, pServer );
//AS Don't ask me what I am doing here
Name lName = lContext.getNameParser("").parse( lJNDIName );
while( lName.size() > 1 ) {
String lContextName = lName.get( 0 );
try {
lContext = (Context) lContext.lookup(lContextName);
}
catch( NameNotFoundException e ) {
lContext = lContext.createSubcontext(lContextName);
}
lName = lName.getSuffix( 1 );
}
// The helper class NonSerializableFactory uses address type nns, we
go on to
// use the helper class to bind the javax.mail.Session object in JNDI
StringRefAddr lAddress = new StringRefAddr( "nns", lJNDIName );
Reference lReference = new Reference(
JBossServer.class.getName(),
lAddress,
NonSerializableFactory.class.getName(),
null
);
lContext.bind( lName.get( 0 ), lReference );
log.log( "JBoss Management Service '" + getJNDIName() + "' bound to "
+ lJNDIName );
}
private void unbind() throws NamingException
{
String lJNDIName = getJNDIName();
new InitialContext().unbind( lJNDIName );
NonSerializableFactory.unbind( lJNDIName );
log.log("JBoss Management service '" + lJNDIName + "' removed from JNDI" );
}
}
1.1 jboss/src/main/org/jboss/mgt/JBossServerMBean.java
Index: JBossServerMBean.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mgt;
import java.util.Collection;
import org.jboss.util.ServiceMBean;
/**
* This interface defines the manageable interface for the JBoss Server
* management object to be used as a JMX MBean.
*
* @author Marc Fleury
**/
public interface JBossServerMBean
extends ServiceMBean
{
// -------------------------------------------------------------------------
// Constants
// -------------------------------------------------------------------------
public static final String OBJECT_NAME = "J2EEManagement:service=J2EEServer";
// -------------------------------------------------------------------------
// Methods
// -------------------------------------------------------------------------
/**
* Returns an application if found with the given key.
*
* @param pApplicationId Id of the application to be retrieved
*
* @return Application if found or null if not
**/
public JBossApplication getApplication(
String pApplicationId
);
/**
* @return All the registered applications where the element is of type
* {@link org.jboss.mgt.JBossApplication JBossApplicaton}.
**/
public Collection getApplications();
/**
* Saves the given application either by registering as new application
* or updating the registered application
*
* @param pApplication Application to be saved
*
* @return Saved Application which maybe contains updated values
**/
public JBossApplication saveApplication(
JBossApplication pApplication
);
/**
* Removes the registered application if found
*
* @param pApplicationId Id of the application to be removed
**/
public void removeApplication(
String pApplicationId
);
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development