User: schaefera
  Date: 01/05/14 11:39:27

  Added:       src/main/org/jboss/mgt Application.java Module.java
                        ServerDataCollector.java
                        ServerDataCollectorMBean.java
  Removed:     src/main/org/jboss/mgt JBossApplication.java
                        JBossModule.java JBossServer.java
                        JBossServerMBean.java
  Log:
  Implementation of the 1. draft for the JBoss management class in the
  J2EEDeployer to figure out what applications are deployed.
  
  Revision  Changes    Path
  1.1                  jboss/src/main/org/jboss/mgt/Application.java
  
  Index: Application.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.mgt;
  
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.Collection;
  
  /**
   * Contains the management information about
   * a deployed applications.
   *
   * @author Marc Fleury
   **/
  public class Application
     implements Serializable
  {
     // -------------------------------------------------------------------------
     // 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 Application(
        String pApplicationId,
        String pDeploymentDescriptor,
        Collection pModules
     ) {
        mApplicationId = pApplicationId;
        setDeploymentDescriptor( pDeploymentDescriptor );
        setModules( 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;
     }
     
     /**
      * @return Collection of Modules deployed with this application. Each
      *         item is of type {@link org.jboss.mgt.JBossModule JBossModule}.
      **/
     public Collection getModules() {
        return mModules;
     }
     
     /**
      * Sets a new list of modules
      *
      * @param pModules New list of modules to be set
      **/
     public void setModules( Collection pModules ) {
        if( pModules == null ) {
           // If null is passed then keep the list
           mModules = new ArrayList();
        }
        else {
           mModules = pModules;
        }
     }
     
     public String toString() {
        return "Application [ " + getId() +
           ", deployment descriptor : " + getDeploymentDescriptor() +
           ", modules: " + getModules() + " ]";
     }
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/mgt/Module.java
  
  Index: Module.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.mgt;
  
  import java.io.Serializable;
  import java.util.Collection;
  
  /**
   * Contains the management information about
   * a deployed applications.
   *
   * @author Marc Fleury
   **/
  public class Module
     implements Serializable
  {
     // -------------------------------------------------------------------------
     // 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 Module(
        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;
     }
  
     public String toString() {
        return "Module [ " + getId() +
           ", deployment descriptor : " + getDeploymentDescriptor() +
           ", items: " + getItems() + " ]";
     }
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/mgt/ServerDataCollector.java
  
  Index: ServerDataCollector.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.Hashtable;
  import java.util.Map;
  
  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 ServerDataCollector
     extends ServiceMBeanSupport
     implements ServerDataCollectorMBean
  {
  
     // -------------------------------------------------------------------------
     // Constants
     // -------------------------------------------------------------------------  
  
     public static String JNDI_NAME = "servercollector:domain";
     public static String JMX_NAME = "servercollector";
  
     // -------------------------------------------------------------------------
     // Members
     // -------------------------------------------------------------------------  
  
     private MBeanServer mServer;
     private String mName;
     private Map mApplications = new Hashtable();
  
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------  
  
     /**
      * Default (no-args) Constructor
      *
      * @param pName Name of the MBean
      **/
     public ServerDataCollector()
     {
        mName = null;
     }
  
     /**
      * Constructor with the necessary attributes to be set
      *
      * @param pName Name of the MBean
      **/
     public ServerDataCollector( 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 Application getApplication(
        String pApplicationId
     ) {
        // Loop through the applications and find the application
        if( pApplicationId != null ) {
           return (Application) mApplications.get( pApplicationId );
        }
        return null;
     }
     
     public Collection getApplications() {
        return new ArrayList( mApplications.values() );
     }
     
     public void saveApplication(
        String pApplicationId,
        Application pApplication
     ) {
        if( pApplicationId != null ) {
           mApplications.put( pApplicationId, pApplication ); 
        }
     }
     
     public void removeApplication(
        String pApplicationId
     ) {
        if( pApplicationId != null ) {
           mApplications.remove( pApplicationId );
        }
     }
     
     // -------------------------------------------------------------------------
     // ServiceMBean - Methods
     // -------------------------------------------------------------------------  
  
     protected void initService()
          throws Exception
     {
  //      mJBossServer = new JBossServer( mName );
     }
     
     protected void startService()
          throws Exception
     {
        bind( this );
  //      refresh();
     }
     
     protected void stopService() {
        try {
           unbind();
        }
        catch( Exception e ) {
           log.exception( e );
        }
     }
  
     // -------------------------------------------------------------------------
     // Helper methods to bind/unbind the Management class
     // -------------------------------------------------------------------------
  
        private void bind( ServerDataCollector 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(
           ServerDataCollector.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/ServerDataCollectorMBean.java
  
  Index: ServerDataCollectorMBean.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 ServerDataCollectorMBean
     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 Application getApplication(
        String pApplicationId
     );
  
     /**
      * @return All the registered applications where the element is of type
      *         {@link org.jboss.mpg.Application Application}.
      **/
     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 void saveApplication(
        String pApplicationId,
        Application 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

Reply via email to