You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2002/03/05 13:39:22 UTC

cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces ApplicationMBean.java

leosimons    02/03/05 04:39:22

  Modified:    src/java/org/apache/avalon/phoenix/components/application
                        DefaultApplication.java
               src/java/org/apache/avalon/phoenix/components/kernel
                        DefaultKernel.java Resources.properties
               src/java/org/apache/avalon/phoenix/components/manager
                        Resources.properties
               src/java/org/apache/avalon/phoenix/interfaces
                        ApplicationMBean.java
  Log:
  Added support for managing applications, fixed some bugs.
  
  Revision  Changes    Path
  1.9       +151 -27   jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/DefaultApplication.java
  
  Index: DefaultApplication.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/DefaultApplication.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultApplication.java	26 Jan 2002 08:22:43 -0000	1.8
  +++ DefaultApplication.java	5 Mar 2002 12:39:21 -0000	1.9
  @@ -18,6 +18,8 @@
   import org.apache.avalon.phoenix.ApplicationEvent;
   import org.apache.avalon.phoenix.interfaces.Application;
   import org.apache.avalon.phoenix.interfaces.ApplicationContext;
  +import org.apache.avalon.phoenix.interfaces.ApplicationException;
  +import org.apache.avalon.phoenix.interfaces.ApplicationMBean;
   import org.apache.avalon.phoenix.metadata.BlockListenerMetaData;
   import org.apache.avalon.phoenix.metadata.BlockMetaData;
   import org.apache.avalon.phoenix.metadata.SarMetaData;
  @@ -28,10 +30,11 @@
    * an application.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  + * @author <a href="mailto:leosimons@apache.org">Leo Simons</a>
    */
   public final class DefaultApplication
       extends AbstractLogEnabled
  -    implements Application
  +    implements Application, ApplicationMBean
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( DefaultApplication.class );
  @@ -39,6 +42,8 @@
       private static final String PHASE_STARTUP = "startup";
       private static final String PHASE_SHUTDOWN = "shutdown";
   
  +	private boolean m_running = false;
  +
       private ApplicationContext m_context;
       private LifecycleHelper m_lifecycle;
       private HashMap m_entrys = new HashMap();
  @@ -48,7 +53,116 @@
       {
           m_sarMetaData = sarMetaData;
       }
  +    
  +    ///////////////////////
  +    // LifeCycle Methods //
  +    ///////////////////////
  +
  +    public void initialize()
  +        throws Exception
  +    {
  +    }
  +    
  +    /**
  +     * Start the application running.
  +     * This is only valid when isRunning() returns false,
  +     * otherwise it will generate an IllegalStateException.
  +     *
  +     * @exception IllegalStateException if application is already running
  +     * @exception ApplicationException if the application failed to start.
  +     *            the message part of exception will contain more information
  +     *            pertaining to why the application failed to startup
  +     */
  +    public void start()
  +        throws IllegalStateException, ApplicationException
  +    {
  +        if( isRunning() ) 
  +        	throw new IllegalStateException();
  +        else {
  +        	try {
  +		       	final BlockMetaData[] blocks = m_context.getMetaData().getBlocks();
  +		        for( int i = 0; i < blocks.length; i++ )
  +		        {
  +		            final String blockName = blocks[ i ].getName();
  +		            final BlockEntry blockEntry = new BlockEntry( blocks[ i ] );
  +		            m_entrys.put( blockName, blockEntry );
  +		        }
  +		
  +		        // load block listeners
  +		        loadBlockListeners();
  +		
  +		        // load blocks
  +		        runPhase( PHASE_STARTUP );
  +			}
  +			catch( Throwable t )
  +			{
  +  		        getLogger().info( "exception while starting:"+t.getMessage()+"\n" );
  +  		        t.printStackTrace();
  +				throw new ApplicationException( t.getMessage(), t );
  +			}
  +			
  +			m_running = true;
  +    	}
  +    }
  +
  +    /**
  +     * Shutdown and restart the application running.
  +     * This is only valid when isRunning() returns true,
  +     * otherwise it will generate an IllegalStateException.
  +     * This is equivelent to  calling stop() and then start()
  +     * in succession.
  +     *
  +     * @exception IllegalStateException if application is not already running
  +     * @exception ApplicationException if the application failed to stop or start.
  +     *            the message part of exception will contain more information
  +     *            pertaining to why the application failed to startup/shutdown
  +     */
  +    public void restart()
  +        throws IllegalStateException, ApplicationException
  +    {
  +    	stop();
  +    	start();
  +    }
  +    /**
  +     * Stop the application running.
  +     * This is only valid when isRunning() returns true,
  +     * otherwise it will generate an IllegalStateException.
  +     *
  +     * @exception IllegalStateException if application is not already running
  +     * @exception ApplicationException if the application failed to shutdown.
  +     *            the message part of exception will contain more information
  +     *            pertaining to why the application failed to shutodwn
  +     */
  +    public void stop()
  +        throws IllegalStateException, ApplicationException
  +    {
  +        if( !isRunning() )
  +        	throw new IllegalStateException();
  +        else
  +        {
  +        	try
  +        	{
  +        		runPhase( PHASE_SHUTDOWN );
  +        	}
  +        	catch( Throwable t )
  +        	{
  +  		        getLogger().info( "exception while stopping:"+t.getMessage()+"\n" );
  +  		        t.printStackTrace();
  +				throw new ApplicationException( t.getMessage(), t );
  +          	}
  +        	
  +        	m_running = false;
  +        }
  +    }
   
  +    public void dispose()
  +    {
  +        m_entrys.clear();
  +    }
  +    
  +    ////////////////////////////
  +    // Public Utility Methods //
  +    ////////////////////////////
       public void setApplicationContext( final ApplicationContext context )
       {
           m_context = context;
  @@ -68,50 +182,60 @@
           return entry.getProxy();
       }
   
  -    public void initialize()
  -        throws Exception
  +    /**
  +     * Get the name of the application.
  +     *
  +     * @return the name of the application
  +     */
  +    public String getName()
       {
  +    	return m_sarMetaData.getName();
       }
   
       /**
  -     * Startup application by running startup phase on all the blocks.
  +     * Get the name to display in Management UI.
        *
  -     * @exception Exception if an error occurs
  +     * @return the name of the application to display in UI
        */
  -    public void start()
  -        throws Exception
  +    public String getDisplayName()
       {
  -        final BlockMetaData[] blocks = m_context.getMetaData().getBlocks();
  -        for( int i = 0; i < blocks.length; i++ )
  -        {
  -            final String blockName = blocks[ i ].getName();
  -            final BlockEntry blockEntry = new BlockEntry( blocks[ i ] );
  -            m_entrys.put( blockName, blockEntry );
  -        }
  -
  -        // load block listeners
  -        loadBlockListeners();
  +    	return m_sarMetaData.getName();
  +    }
   
  -        // load blocks
  -        runPhase( PHASE_STARTUP );
  +    /**
  +     * Get the string used to describe the application in the UI.
  +     *
  +     * @return a short description of the application
  +     */
  +    public String getDescription()
  +    {
  +    	return "The "+m_sarMetaData.getName()+" application.";
       }
   
       /**
  -     * Shutdown the application.
  -     * This involves shutting down every contained block.
  +     * Get location of Application installation
        *
  -     * @exception Exception if an error occurs
  +     * @return the home directory of application
        */
  -    public void stop()
  -        throws Exception
  +    public String getHomeDirectory()
       {
  -        runPhase( PHASE_SHUTDOWN );
  +    	return m_sarMetaData.getHomeDirectory().getPath();
       }
   
  -    public void dispose()
  +    /**
  +     * Return true if the application is
  +     * running or false otherwise.
  +     *
  +     * @return true if application is running, false otherwise
  +     */
  +    public boolean isRunning()
       {
  -        m_entrys.clear();
  +    	return m_running;
       }
  +    
  +    /////////////////////////////
  +    // Private Utility Methods //
  +    /////////////////////////////
   
       private void loadBlockListeners()
           throws Exception
  
  
  
  1.52      +15 -2     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- DefaultKernel.java	4 Mar 2002 15:01:13 -0000	1.51
  +++ DefaultKernel.java	5 Mar 2002 12:39:21 -0000	1.52
  @@ -40,6 +40,7 @@
    * configured and initialized.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  + * @author <a href="mailto:leosimons@apache.org">Leo Simons</a>
    */
   public class DefaultKernel
       extends AbstractLogEnabled
  @@ -140,12 +141,12 @@
               // manage application
               try
               {
  -              	m_systemManager.register( name+" (Application)", application );
  +              	m_systemManager.register( name+" (Application)", application, new Class[]{ ApplicationMBean.class } );
             	}
               catch( final Throwable t )
               {
                   final String message =
  -                    REZ.getString( "kernel.error.entry.manage", entry.getMetaData().getName() );
  +                    REZ.getString( "kernel.error.entry.manage", name );
                   throw new CascadingException( message, t );
               }
           }
  @@ -233,6 +234,18 @@
           }
           else
           {
  +            // un-manage application
  +            try
  +            {
  +              	m_systemManager.unregister( name+" (Application)" );
  +          	}
  +            catch( final Throwable t )
  +            {
  +                final String message =
  +                    REZ.getString( "kernel.error.entry.unmanage", name );
  +                throw new CascadingException( message, t );
  +            }
  +
               shutdown( entry );
           }
       }
  
  
  
  1.6       +1 -0      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/Resources.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Resources.properties	4 Mar 2002 15:01:13 -0000	1.5
  +++ Resources.properties	5 Mar 2002 12:39:22 -0000	1.6
  @@ -3,6 +3,7 @@
   kernel.error.entry.initialize=Failed to initialize application {0}.
   kernel.error.entry.nostop=Failed to stop application {0} as it is not initialized/started.
   kernel.error.entry.manage=Failed to register application {0} with SystemManager.
  +kernel.error.entry.unmanage=Failed to unregister application {0} with SystemManager.
   
   kernel.error.entry.nofind=Unable to locate Application by the name "{0}".
   kernel.error.entry.prepare=Error preparing application {0}.
  
  
  
  1.4       +1 -1      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/Resources.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Resources.properties	9 Nov 2001 21:14:31 -0000	1.3
  +++ Resources.properties	5 Mar 2002 12:39:22 -0000	1.4
  @@ -6,5 +6,5 @@
   manager.error.register.exists=Entry with name {0} already exists.
   
   jmxmanager.error.export.fail=Unable to export {0} as mBean.
  -jmxmanager.error.export.fail=Unable to unexport {0} as mBean.
  +jmxmanager.error.unexport.fail=Unable to unexport {0} as mBean.
   jmxmanager.error.mbeanserver.create=Failed to create MBean Server of class {0}.
  
  
  
  1.4       +2 -14     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ApplicationMBean.java
  
  Index: ApplicationMBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ApplicationMBean.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ApplicationMBean.java	17 Feb 2002 11:15:28 -0000	1.3
  +++ ApplicationMBean.java	5 Mar 2002 12:39:22 -0000	1.4
  @@ -12,6 +12,7 @@
    * the root container of Applications.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  + * @author <a href="mailto:leosimons@apache.org">Leo Simons</a>
    */
   public interface ApplicationMBean
   {
  @@ -70,7 +71,7 @@
        * Shutdown and restart the application running.
        * This is only valid when isRunning() returns true,
        * otherwise it will generate an IllegalStateException.
  -     * This is equivelent to  calling start() and then stop()
  +     * This is equivelent to  calling stop() and then start()
        * in succession.
        *
        * @exception IllegalStateException if application is not already running
  @@ -92,18 +93,5 @@
        *            pertaining to why the application failed to shutodwn
        */
       void stop()
  -        throws IllegalStateException, ApplicationException;
  -
  -    /**
  -     * Uninstall the application.
  -     * This is only valid when isRunning() returns false,
  -     * otherwise it will generate an IllegalStateException.
  -     *
  -     * @exception IllegalStateException if application is running
  -     * @exception ApplicationException if the application failed to undeploy.
  -     *            the message part of exception will contain more information
  -     *            pertaining to why the application failed to undeploy
  -     */
  -    void undeploy()
           throws IllegalStateException, ApplicationException;
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>