User: schaefera
  Date: 01/06/15 22:48:44

  Added:       src/main/org/jboss/management ContainerManagement.java
                        ContainerManagementMBean.java DataCollector.java
                        EJBDataCollector.java JDBCDataCollector.java
                        JNDIDataCollector.java MailDataCollector.java
                        NodeDataCollector.java ServerDataCollector.java
                        ServerDataCollectorMBean.java
  Log:
  Renamed the short directory to "mgt" and the add the new design how to
  collect the data. The DataCollector is the interface which has to be
  used by any class collecting management interface (mapping the JBoss
  data to the management understandable data).
  
  Revision  Changes    Path
  1.1                  jboss/src/main/org/jboss/management/ContainerManagement.java
  
  Index: ContainerManagement.java
  ===================================================================
  /*
  * JBoss, the OpenSource EJB server
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.management;
  
  /*
  import java.beans.Beans;
  import java.beans.beancontext.BeanContextServicesSupport;
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.net.MalformedURLException;
  import java.io.File;
  import java.io.InputStream;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.rmi.RemoteException;
  import java.rmi.ServerException;
  import java.rmi.server.UnicastRemoteObject;
  import java.util.Properties;
  import java.util.Iterator;
  import java.util.HashMap;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  import java.util.jar.JarFile;
  import java.util.jar.Manifest;
  import java.util.jar.Attributes;
  */
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.Name;
  import javax.naming.NameNotFoundException;
  import javax.naming.NamingException;
  import javax.management.MBeanServer;
  import javax.management.MBeanRegistration;
  import javax.management.ObjectName;
  import javax.transaction.TransactionManager;
  
  import org.jboss.ejb.Container;
  
  import org.jboss.logging.Log;
  import org.jboss.logging.ConsoleLogging;
  import org.jboss.logging.ConsoleLoggingMBean;
  
  import org.jboss.metadata.ApplicationMetaData;
  import org.jboss.metadata.BeanMetaData;
  import org.jboss.metadata.SessionMetaData;
  import org.jboss.metadata.EntityMetaData;
  import org.jboss.metadata.MessageDrivenMetaData;
  import org.jboss.metadata.ConfigurationMetaData;
  import org.jboss.metadata.XmlLoadable;
  import org.jboss.metadata.XmlFileLoader;
  import org.jboss.logging.Logger;
  
  /**
  *   A ContainerMgt is used as the long arm of a deployed EJB's container.
  *
  *   @see Container
  *   @author Andreas Schaefer ([EMAIL PROTECTED])
  *
  *   @version $Revision: 1.1 $
  */
  public class ContainerManagement
    extends org.jboss.util.ServiceMBeanSupport
    implements ContainerManagementMBean
  {
     // Attributes ----------------------------------------------------
     // Container this is the management proxy for
     Container mContainer = null;
     // The logger of this service
     Log mLog = Log.createLog( getName() );
     ObjectName mName = null;
  
     // Constructor ---------------------------------------------------
  
     public ContainerManagement( Container pContainer ) {
        setContainer( pContainer );
     }
     
     // Public --------------------------------------------------------
  
     private void setContainer( Container pContainer ) {
        mContainer = pContainer;
     }
     
     public Container getContainer() {
        return mContainer;
     }
     
     /**
     * Implements the abstract <code>getObjectName()</code> method in superclass
     * to return this service's name.
     *
     * @param   server
     * @param   name
     *
     * @exception MalformedObjectNameException
     * @return
     */
     public ObjectName getObjectName( MBeanServer server, ObjectName name )
        throws javax.management.MalformedObjectNameException
     {
        mName = name;
        return name;
     }
     
     /**
     * Implements the abstract <code>getName()</code> method in superclass to
     * return the name of this object.
     *
     * @return <tt>'Container factory'</code>
     */
     public String getName() {
        return "Container Management Proxy";
     }
     
     /**
     * Implements the template method in superclass. This method stops all the
     * applications in this server.
     */
     public void stopService() {
     }
     
     /**
     * Implements the template method in superclass. This method destroys all
     * the applications in this server and clears the deployments list.
     */
     public void destroyService() {
     }
     
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/management/ContainerManagementMBean.java
  
  Index: ContainerManagementMBean.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management;
  
  import org.jboss.ejb.Container;
  
  /**
   *   This is the interface of the ContainerMgt that is exposed for administration
   *
   *   @see ContainerMgt
   *   @author Andreas Schaefer ([EMAIL PROTECTED])
   *
   *   @version $Revision: 1.1 $
   */
  public interface ContainerManagementMBean
        extends org.jboss.util.ServiceMBean
  {
     // Constants -----------------------------------------------------
  
     // Public --------------------------------------------------------
  
     /**
      * @return Container this is a proxy for
      **/
     public Container getContainer();
  
  }
  
  
  
  
  1.1                  jboss/src/main/org/jboss/management/DataCollector.java
  
  Index: DataCollector.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management;
  
  import java.util.Collection;
  
  import javax.management.MBeanServer;
  
  import management.J2EEManagedObject;
  
  /**
   * Collector Interface which must be implemented by
   * any collector to lookup the management data
   *
   * @author Marc Fleury
   **/
  public interface DataCollector {
  
     // -------------------------------------------------------------------------
     // Methods
     // -------------------------------------------------------------------------  
  
     /**
      * Is called when the data must be refreshed
      *
      * @param pServer MBean Server is used to get the information about the server
      *
      * @return Collection of elements found (must be of type J2EEManagedObject)
      **/
     public Collection refresh( MBeanServer pServer );
  
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/management/EJBDataCollector.java
  
  Index: EJBDataCollector.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Hashtable;
  import java.util.Iterator;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  import org.jboss.ejb.Container;
  import org.jboss.ejb.StatefulSessionContainer;
  
  import org.jboss.management.JBossEjbModule;
  import org.jboss.management.JBossEntityBean;
  import org.jboss.management.JBossJ2EEApplication;
  import org.jboss.management.JBossMessageDrivenBean;
  import org.jboss.management.JBossStatefulSessionBean;
  import org.jboss.management.JBossStatelessSessionBean;
  
  import management.EjbModule;
  import management.EJB;
  import management.J2EEApplication;
  import management.J2EEModule;
  
  /**
   * JDBC Data Collector
   *
   * @author Marc Fleury
   **/
  public class EJBDataCollector
     implements DataCollector
  {
  
     // -------------------------------------------------------------------------
     // Constants
     // -------------------------------------------------------------------------  
  
     // -------------------------------------------------------------------------
     // Members
     // -------------------------------------------------------------------------  
  
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------  
  
     /**
      * Default (no-args) Constructor
      **/
     public EJBDataCollector() {
     }
  
     // -------------------------------------------------------------------------
     // Methods
     // -------------------------------------------------------------------------  
  
     public Collection refresh( MBeanServer pServer ) {
        Collection lReturn = new ArrayList();
        try {
           // Look up all the registered Containers for the EJB Module and loop through
           Hashtable lApplications = new Hashtable();
           Iterator i = pServer.queryNames( new ObjectName( "Management:*" ), null 
).iterator();
           while( i.hasNext() ) {
              ObjectName lName = (ObjectName) i.next();
              if( lName.getKeyProperty( "container" ) == null ) {
                 continue;
              }
              Container lContainer = (Container) pServer.getAttribute( lName, 
"Container" );
              Collection lBeans = null;
              // Check if application name already exists
              String lApplicationName = lContainer.getApplication().getName();
              if( lApplications.containsKey( lApplicationName ) ) {
                 lBeans = (Collection) lApplications.get( lApplicationName );
              }
              else {
                 lBeans = new ArrayList();
                 lApplications.put( lApplicationName, lBeans );
              }
              // Add EJB Info
              if( lContainer.getBeanMetaData().isSession() ) {
                 if( lContainer instanceof StatefulSessionContainer ) {
                    lBeans.add( new JBossStatefulSessionBean( 
lContainer.getBeanMetaData().getEjbName() ) );
                 }
                 else {
                    lBeans.add( new JBossStatelessSessionBean( 
lContainer.getBeanMetaData().getEjbName() ) );
                 }
              }
              if( lContainer.getBeanMetaData().isEntity() ) {
                 lBeans.add( new JBossEntityBean( 
lContainer.getBeanMetaData().getEjbName() ) );
              }
              if( lContainer.getBeanMetaData().isMessageDriven() ) {
                 lBeans.add( new JBossMessageDrivenBean( 
lContainer.getBeanMetaData().getEjbName() ) );
              }
           }
           i = lApplications.keySet().iterator();
           while( i.hasNext() ) {
              String lApplicationName = (String) i.next();
              ArrayList lBeans = (ArrayList) lApplications.get( lApplicationName );
              EjbModule lModule = new JBossEjbModule(
                 "EjbModule",
                 (EJB[]) lBeans.toArray( new EJB[ 0 ] )
              );
              lReturn.add(
                 new JBossJ2EEApplication(
                    lApplicationName,
                    null,
                    new J2EEModule[] { lModule }
                 )
              );
           }
        }
        catch( Exception e ) {
           e.printStackTrace();
        }
        return lReturn;
     }
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/management/JDBCDataCollector.java
  
  Index: JDBCDataCollector.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Iterator;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  import org.jboss.management.JBossJDBC;
  import org.jboss.management.JBossJDBCConnectionPool;
  import org.jboss.management.JBossJDBCDriver;
  
  import management.JDBC;
  import management.JDBCConnectionPool;
  import management.JDBCDriver;
  
  /**
   * JDBC Data Collector
   *
   * @author Marc Fleury
   **/
  public class JDBCDataCollector
     implements DataCollector
  {
  
     // -------------------------------------------------------------------------
     // Constants
     // -------------------------------------------------------------------------  
  
     // -------------------------------------------------------------------------
     // Members
     // -------------------------------------------------------------------------  
  
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------  
  
     /**
      * Default (no-args) Constructor
      **/
     public JDBCDataCollector() {
     }
  
     // -------------------------------------------------------------------------
     // Methods
     // -------------------------------------------------------------------------  
  
     public Collection refresh( MBeanServer pServer ) {
        Collection lReturn = new ArrayList();
        try {
           ArrayList lPools = new ArrayList();
           // Lookup all the JDBC Connection Pool
           Iterator i = pServer.queryMBeans( null, null ).iterator();
           while( i.hasNext() ) {
              ObjectInstance lBean = (ObjectInstance) i.next();
              if( "org.jboss.jdbc.XADataSourceLoader".equals( lBean.getClassName() ) ) 
{
                 ObjectName lBeanName = lBean.getObjectName();
                 // Data Sourec Found, no get the information
                 JDBCDriver lDriver = new JBossJDBCDriver(
                    (String) pServer.getAttribute( lBeanName, "URL" )
                 );
                 JDBCConnectionPool lPool = new JBossJDBCConnectionPool(
                    (String) pServer.getAttribute( lBeanName, "PoolName" ),
                    lDriver
                 );
                 lPools.add( lPool );
              }
           }
           // Add the Pools to the J2EE Server
           lReturn.add(
              new JBossJDBC(
                 "JDBC",
                 (JDBCConnectionPool[]) lPools.toArray( new JDBCConnectionPool[ 0 ] )
              )
           );
        }
        catch( Exception e ) {
           e.printStackTrace();
        }
        return lReturn;
     }
  
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/management/JNDIDataCollector.java
  
  Index: JNDIDataCollector.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management;
  
  import java.net.InetAddress;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Iterator;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  import org.jboss.management.JBossJNDI;
  
  import management.JNDI;
  
  /**
   * JNDI Data Collector
   *
   * @author Marc Fleury
   **/
  public class JNDIDataCollector
     implements DataCollector
  {
  
     // -------------------------------------------------------------------------
     // Constants
     // -------------------------------------------------------------------------  
  
     // -------------------------------------------------------------------------
     // Members
     // -------------------------------------------------------------------------  
  
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------  
  
     /**
      * Default (no-args) Constructor
      **/
     public JNDIDataCollector() {
     }
  
     // -------------------------------------------------------------------------
     // Methods
     // -------------------------------------------------------------------------  
  
     public Collection refresh( MBeanServer pServer ) {
        Collection lReturn = new ArrayList();
        try {
           Iterator i = pServer.queryNames(
              new ObjectName( "DefaultDomain", "service", "JNDIView" ),
              null
           ).iterator();
           while( i.hasNext() ) {
              ObjectName lBean = (ObjectName) i.next();
              lReturn.add(
                 new JBossJNDI(
                    (String) pServer.invoke(
                       lBean,
                       "listXML",
                       new Object[] {},
                       new String[] {}
                    )
                 )
              );
           }
        }
        catch( Exception e ) {
           e.printStackTrace();
        }
        return lReturn;
     }
  
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/management/MailDataCollector.java
  
  Index: MailDataCollector.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management;
  
  import java.net.InetAddress;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Iterator;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  import org.jboss.management.JBossJavaMail;
  
  import management.JavaMail;
  
  /**
   * Mail Data Collector
   *
   * @author Marc Fleury
   **/
  public class MailDataCollector
     implements DataCollector
  {
  
     // -------------------------------------------------------------------------
     // Constants
     // -------------------------------------------------------------------------  
  
     // -------------------------------------------------------------------------
     // Members
     // -------------------------------------------------------------------------  
  
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------  
  
     /**
      * Default (no-args) Constructor
      **/
     public MailDataCollector() {
     }
  
     // -------------------------------------------------------------------------
     // Methods
     // -------------------------------------------------------------------------  
  
     public Collection refresh( MBeanServer pServer ) {
        Collection lReturn = new ArrayList();
        try {
           Iterator i = pServer.queryNames(
              new ObjectName( "DefaultDomain", "service", "Mail" ),
              null
           ).iterator();
           while( i.hasNext() ) {
              ObjectName lBean = (ObjectName) i.next();
              lReturn.add(
                 new JBossJavaMail(
                    (String) pServer.getAttribute(
                       lBean,
                       "Name"
                    )
                 )
              );
           }
        }
        catch( Exception e ) {
           e.printStackTrace();
        }
        return lReturn;
     }
  
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/management/NodeDataCollector.java
  
  Index: NodeDataCollector.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management;
  
  import java.net.InetAddress;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Iterator;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  import org.jboss.management.JBossIpAddress;
  import org.jboss.management.JBossJVM;
  import org.jboss.management.JBossNode;
  import org.jboss.management.JBossPort;
  
  import management.IpAddress;
  import management.JVM;
  import management.Node;
  import management.Port;
  
  /**
   * Node Data Collector
   *
   * @author Marc Fleury
   **/
  public class NodeDataCollector
     implements DataCollector
  {
  
     // -------------------------------------------------------------------------
     // Constants
     // -------------------------------------------------------------------------  
  
     // -------------------------------------------------------------------------
     // Members
     // -------------------------------------------------------------------------  
  
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------  
  
     /**
      * Default (no-args) Constructor
      **/
     public NodeDataCollector() {
     }
  
     // -------------------------------------------------------------------------
     // Methods
     // -------------------------------------------------------------------------  
  
     public Collection refresh( MBeanServer pServer ) {
        Collection lReturn = new ArrayList();
        try {
           // Get the JVMs Info
           //AS Right now there is only one JVM at all
           Runtime lRuntime = Runtime.getRuntime();
           JVM[] lJVMs = new JVM[] {
              new JBossJVM(
                 System.getProperty( "java.runtime.name" ),
                 (int) ( lRuntime.totalMemory() - lRuntime.freeMemory() ),
                 (int) lRuntime.totalMemory(),
                 System.getProperty( "java.version" ),
                 System.getProperty( "java.vendor" ),
                 System.getProperty( "java.class.path" )
              )
           };
           //AS Right now I have no clue which ports should be
           //AS listed and how to get the Webserver port
           Port lWebPort = new JBossPort(
              "WebServer Port",
              8080,
              null
           );
           IpAddress lWebIpAddress = new JBossIpAddress(
              "WebServer IpAddress",
              InetAddress.getLocalHost().getHostAddress(),
              new Port[] { lWebPort }
           );
           lWebPort.setIpAddress( lWebIpAddress );
           IpAddress[] lIpAddresses = new IpAddress[] {
              new JBossIpAddress(
                 "WebServer",
                 InetAddress.getLocalHost().getHostAddress(),
                 new Port[] { lWebPort }
              )
           };
           // Create Node Info
           lReturn.add(
              new JBossNode(
                 InetAddress.getLocalHost().getHostName(),
                 System.getProperty( "os.arch" ),
                 System.getProperty( "os.name" ),
                 lJVMs,
                 lIpAddresses
              )
           );
        }
        catch( Exception e ) {
           e.printStackTrace();
        }
        return lReturn;
     }
  
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/management/ServerDataCollector.java
  
  Index: ServerDataCollector.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Hashtable;
  import java.util.Iterator;
  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;
  
  import management.J2EEApplication;
  
  /**
   * 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 Boolean mRefresh = new Boolean( true );
     private RefreshWorker mWorker;
     private int mRefreshSleep = 2000;
  
     private Map mApplications = new Hashtable();
     private Collection mResources = new ArrayList();
     private Collection mNodes = new ArrayList();
  
     // -------------------------------------------------------------------------
     // 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 int getRefreshSleep() {
        return mRefreshSleep;
     }
     
     public void setRefreshSleep( int pSleep ) {
        if( pSleep > 0 ) {
           mRefreshSleep = pSleep;
        }
     }
     
     public void refresh() {
        // Mark it to be refreshed
        synchronized( mRefresh ) {
           mRefresh = new Boolean( true );
        }
     }
  
     public void refreshNow() {
        synchronized( mRefresh ) {
           mWorker.doRefresh();
           mRefresh = new Boolean( false );
        }
     }
     
     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 Data Collector MBean";
     }
     
     public J2EEApplication getApplication(
        String pApplicationId
     ) {
        // Loop through the applications and find the application
        if( pApplicationId != null ) {
           return (J2EEApplication) mApplications.get( pApplicationId );
        }
        return null;
     }
     
     public Collection getApplications() {
        return new ArrayList( mApplications.values() );
     }
  
     public Collection getResources() {
        return mResources;
     }
  
     public Collection getNodes() {
        return mNodes;
     }
  
  /* AS Keep it but mostly likely it will removed later
     public void removeApplication(
        String pApplicationId
     ) {
        if( pApplicationId != null ) {
           mApplications.remove( pApplicationId );
        }
     }
  
     public void saveModule(
        String pApplicationId,
        int pModuleId,
        Module pModule
     ) {
        Application lApplication = getApplication( pApplicationId );
        System.out.println( "ServerDataCollector.saveModule(), App. Id: " + 
pApplicationId + ", application: " + lApplication );
        if( lApplication != null ) {
           lApplication.saveModule( pModuleId, pModule );
        }
     }
  
     /**
      * Removes the registered Module if found
      *
      * @param pApplicationId Id of the Application the Module is part of
      * @param pModuleId Id of the Module to be removed
      ** /
     public void removeModule(
        String pApplicationId,
        int pModuleId
     ) {
        Application lApplication = getApplication( pApplicationId );
        if( lApplication != null ) {
           lApplication.removeModule( pModuleId );
        }
     }
  */
  
     // -------------------------------------------------------------------------
     // ServiceMBean - Methods
     // -------------------------------------------------------------------------  
  
     protected void initService()
          throws Exception
     {
  //      mJBossServer = new JBossServer( mName );
     }
     
     protected void startService()
          throws Exception
     {
        bind( this );
        mWorker = new RefreshWorker( log );
        mWorker.start();
     }
     
     protected void stopService() {
        mWorker.stop();
        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" );
        }
     
     /**
      * Worker class to perform the refresh of the data
      **/
     private class RefreshWorker
        extends Thread
     {
        private Log mLog;
        
        public RefreshWorker( Log pLog ) {
           mLog = pLog;
        }
        
        public void run() {
           while( true ) {
              try {
                 synchronized( mRefresh ) {
                    if( mRefresh.booleanValue() ) {
                       doRefresh();
                       mRefresh = new Boolean( false );
                    }
                 }
                 Thread.sleep( mRefreshSleep );
              }
              catch( InterruptedException e ) {
              }
           }
        }
        
        private void doRefresh() {
           try {
              mApplications = new Hashtable();
              Collection lApplications = new EJBDataCollector().refresh( mServer );
              Iterator i = lApplications.iterator();
              while( i.hasNext() ) {
                 J2EEApplication lApplication = (J2EEApplication) i.next();
                 mApplications.put(
                    lApplication.getName(),
                    lApplication
                 );
              }
           }
           catch( Exception e ) {
              e.printStackTrace();
           }
           mResources = new ArrayList();
           try {
              // Get the info about JDBCs
              mResources.addAll( new JDBCDataCollector().refresh( mServer ) );
           }
           catch( Exception e ) {
              e.printStackTrace();
           }
           try {
              // Get the info about Mail
              mResources.addAll( new MailDataCollector().refresh( mServer ) );
           }
           catch( Exception e ) {
              e.printStackTrace();
           }
           try {
              // Get the info about JNDI
              mResources.addAll( new JNDIDataCollector().refresh( mServer ) );
           }
           catch( Exception e ) {
              e.printStackTrace();
           }
           try {
              // Get the info about current nodes
              mNodes = new NodeDataCollector().refresh( mServer );
           }
           catch( Exception e ) {
              e.printStackTrace();
           }
        }
     }
  
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/management/ServerDataCollectorMBean.java
  
  Index: ServerDataCollectorMBean.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management;
  
  import java.util.Collection;
  
  import org.jboss.util.ServiceMBean;
  
  import management.J2EEApplication;
  
  /**
   * 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
     // -------------------------------------------------------------------------
  
     /** @return Sleep period in milliseconds between to refresh cycles **/
     public int getRefreshSleep();
     /**
      * Sets the Sleep time (in milliseconds) between two refresh cycles
      *
      * @param pSleep Sleep period in milliseconds
      **/
     public void setRefreshSleep( int pSleep );
     
     /**
      * Informs this intance the environment changes and he should update its
      * data
      **/
     public void refresh();
  
     /**
      * Informs this intance the environment changes and he should update its
      * data right NOW
      **/
     public void refreshNow();
  
     /**
      * 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 J2EEApplication getApplication(
        String pApplicationId
     );
  
     /**
      * @return All the registered applications where the element is of type
      *         {@link org.jboss.mpg.Application Application}.
      **/
     public Collection getApplications();
     
     /**
      * @return All the registered resources of this server. All are of type
      *         {@link management.J2EEResource J2EEResource}.
      **/
     public Collection getResources();
     
     /**
      * @return All the nodes of this server running. All are of type
      *         {@link management.Node Node}.
      **/
     public Collection getNodes();
     
     /**
      * @return Information about the JVM this application server is running on
      **/
  //   public void getJVM(); 
  
  /* AS Is not used anymore
     /**
      * Saves the given application either by registering as new application
      * or updating the registered application
      *
      * @param pApplication Application to be saved
      ** /
     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
     );
  
     /**
      * Saves the given Module either by registering as new Module
      * or updating the registered Module
      *
      * @param pApplicationId Id of the Application the Module is part of
      * @param pModuleId Id of the Module to be saved
      * @param pModule Module to be saved
      ** /
     public void saveModule(
        String pApplicationId,
        int pModuleId,
        Module pModule
     );
  
     /**
      * Removes the registered Module if found
      *
      * @param pApplicationId Id of the Application the Module is part of
      * @param pModuleId Id of the Module to be removed
      ** /
     public void removeModule(
        String pApplicationId,
        int pModuleId
     );
  */
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to