avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/merlin/activation/spi/src/java/org/apache/avalon/activation/appliance BlockContext.java
Date Tue, 13 Jan 2004 18:43:15 GMT
mcconnell    2004/01/13 10:43:15

  Modified:    merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl
                        AbstractBlock.java CompositeBlock.java
                        DefaultBlock.java
               merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl
                        DefaultFactory.java DefaultKernel.java
  Added:       merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl
                        DefaultKernelContext.java
  Removed:     merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl
                        DefaultBlockContext.java
               merlin/activation/spi/src/java/org/apache/avalon/activation/appliance
                        BlockContext.java
  Log:
  Cleanup the block constructor model (now ties to the model directly). Improve the kernel
constructor and implementation to handle event propergation.
  
  Revision  Changes    Path
  1.13      +12 -17    avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/AbstractBlock.java
  
  Index: AbstractBlock.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/AbstractBlock.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- AbstractBlock.java	13 Jan 2004 11:41:22 -0000	1.12
  +++ AbstractBlock.java	13 Jan 2004 18:43:15 -0000	1.13
  @@ -59,7 +59,6 @@
   import org.apache.avalon.activation.appliance.ApplianceRuntimeException;
   import org.apache.avalon.activation.appliance.AssemblyException;
   import org.apache.avalon.activation.appliance.Block;
  -import org.apache.avalon.activation.appliance.BlockContext;
   import org.apache.avalon.activation.appliance.Engine;
   import org.apache.avalon.activation.appliance.NoProviderDefinitionException;
   
  @@ -110,22 +109,21 @@
           {
               throw new NullPointerException( "model" );
           }
  -
  -        BlockContext context = 
  -          new DefaultBlockContext( model, null );
  -        return new DefaultBlock( context );
  +        return new DefaultBlock( model );
       }
   
       //-------------------------------------------------------------------
       // immmutable state
       //-------------------------------------------------------------------
   
  -    private final BlockContext m_context;
  +    private final ContainmentModel m_model;
   
       private final DefaultState m_deployment = new DefaultState();
   
       private final DefaultState m_self = new DefaultState();
   
  +    private final Engine m_engine;
  +
       //-------------------------------------------------------------------
       // constructor
       //-------------------------------------------------------------------
  @@ -136,15 +134,14 @@
       * @param context the block context
       * @exception ApplianceException if a block creation error occurs
       */
  -    AbstractBlock( BlockContext context )
  +    AbstractBlock( ContainmentModel model, Engine engine )
       {
  -        super( context.getContainmentModel() );
  +        super( model );
   
  -        m_context = context;
  +        m_model = model;
  +        m_engine = engine;
   
           m_self.setEnabled( true );
  -
  -        ContainmentModel model = m_context.getContainmentModel();
           synchronized( model )
           {
               model.addCompositionListener( this );
  @@ -161,7 +158,7 @@
       */
       public ContainmentModel getContainmentModel() 
       {
  -        return m_context.getContainmentModel();
  +        return m_model;
       }
   
       //-------------------------------------------------------------------
  @@ -254,7 +251,7 @@
       */
       public void deploy() throws Exception
       {
  -        if( !m_context.getContainmentModel().isAssembled() )
  +        if( !getContainmentModel().isAssembled() )
           {
               throw new IllegalStateException( "assembly" );
           }
  @@ -400,9 +397,7 @@
           {
               getLogger().debug( "creating block: " + path );
               ContainmentModel containment = (ContainmentModel) model;
  -            BlockContext context = 
  -              new DefaultBlockContext( containment, this );
  -            appliance = new CompositeBlock( context );
  +            appliance = new DefaultBlock( containment, this );
           }
           else
           {
  
  
  
  1.7       +3 -4      avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/CompositeBlock.java
  
  Index: CompositeBlock.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/CompositeBlock.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CompositeBlock.java	13 Jan 2004 11:41:22 -0000	1.6
  +++ CompositeBlock.java	13 Jan 2004 18:43:15 -0000	1.7
  @@ -61,7 +61,6 @@
   import org.apache.avalon.activation.appliance.Appliance;
   import org.apache.avalon.activation.appliance.ApplianceException;
   import org.apache.avalon.activation.appliance.ApplianceRuntimeException;
  -import org.apache.avalon.activation.appliance.BlockContext;
   import org.apache.avalon.activation.appliance.Home;
   import org.apache.avalon.composition.data.ServiceDirective;
   import org.apache.avalon.composition.model.ContainmentModel;
  @@ -89,9 +88,9 @@
       * @param context the block context
       * @exception ApplianceException if a block creation error occurs
       */
  -    CompositeBlock( BlockContext context )
  +    CompositeBlock( ContainmentModel model )
       {
  -        super( context );
  +        super( model );
       }
   
   }
  
  
  
  1.9       +16 -10    avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/DefaultBlock.java
  
  Index: DefaultBlock.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/DefaultBlock.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultBlock.java	13 Jan 2004 11:41:22 -0000	1.8
  +++ DefaultBlock.java	13 Jan 2004 18:43:15 -0000	1.9
  @@ -62,8 +62,8 @@
   import org.apache.avalon.activation.appliance.Appliance;
   import org.apache.avalon.activation.appliance.ApplianceException;
   import org.apache.avalon.activation.appliance.ApplianceRuntimeException;
  -import org.apache.avalon.activation.appliance.BlockContext;
   import org.apache.avalon.activation.appliance.Home;
  +import org.apache.avalon.activation.appliance.Engine;
   
   import org.apache.avalon.composition.data.ServiceDirective;
   import org.apache.avalon.composition.model.ContainmentModel;
  @@ -87,8 +87,6 @@
       // immmutable state
       //-------------------------------------------------------------------
   
  -    private final BlockContext m_context;
  -
       private final Object m_proxy;
   
       //-------------------------------------------------------------------
  @@ -96,14 +94,23 @@
       //-------------------------------------------------------------------
   
      /**
  +    * Creation of a new root block.
  +    *
  +    * @param model the root containment model
  +    */
  +    public DefaultBlock( ContainmentModel model )
  +    {
  +        this( model, null );
  +    }
  +
  +   /**
       * Creation of a new block.
       *
       * @param context the block context
       */
  -    DefaultBlock( BlockContext context )
  +    DefaultBlock( ContainmentModel model, Engine engine )
       {
  -        super( context );
  -        m_context = context;
  +        super( model, engine );
   
           //
           // build the default proxy
  @@ -111,7 +118,6 @@
   
           try
           {
  -            final ContainmentModel model = context.getContainmentModel();
               final Logger log = model.getLogger().getChildLogger( "proxy" );
               final BlockInvocationHandler handler = 
                 new BlockInvocationHandler( log, this );
  @@ -163,7 +169,7 @@
   
       private Class[] getInterfaceClasses() throws Exception
       {
  -        ContainmentModel model = m_context.getContainmentModel();
  +        ContainmentModel model = getContainmentModel();
           ClassLoader loader = model.getClassLoaderModel().getClassLoader();
           ArrayList list = new ArrayList();
           ServiceModel[] services = model.getServiceModels();
  @@ -223,7 +229,7 @@
               // delegate the operation to the block
               //
   
  -            final ContainmentModel model = m_context.getContainmentModel();
  +            final ContainmentModel model = getContainmentModel();
               Class source = method.getDeclaringClass();
               ServiceModel service = model.getServiceModel( source );
               if( null == service )
  
  
  
  1.13      +12 -16    avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java
  
  Index: DefaultFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DefaultFactory.java	13 Jan 2004 11:41:27 -0000	1.12
  +++ DefaultFactory.java	13 Jan 2004 18:43:15 -0000	1.13
  @@ -108,6 +108,7 @@
   import org.apache.avalon.merlin.KernelException;
   import org.apache.avalon.merlin.KernelRuntimeException;
   import org.apache.avalon.merlin.KernelCriteria;
  +import org.apache.avalon.merlin.KernelContext;
   
   import org.apache.avalon.repository.Repository;
   import org.apache.avalon.repository.provider.CacheManager;
  @@ -151,8 +152,6 @@
   
       private ClassLoader m_classloader;
   
  -    private Block m_application;
  -
       private Block m_system;
   
       //--------------------------------------------------------------------------
  @@ -313,18 +312,12 @@
           // kernel management logic.
           //
   
  -        try
  -        {
  -            getLogger().debug( "system assembly" );
  -            facilities.assemble();
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error = 
  -             "Facilities assembly failure.";
  -            throw new KernelException( error, e );
  -        }
  +        KernelContext kernelContext = 
  +          new DefaultKernelContext( getLogger(), facilities, application );
  +        Kernel kernel = new DefaultKernel( kernelContext );
  +        setShutdownHook( getLogger(), kernel );
   
  +        /*
           try
           {
               m_system = 
  @@ -349,6 +342,7 @@
                 "System deployment failure.";
               throw new KernelException( error, e );
           }
  +        */
   
           //
           // install any blocks declared within the kernel context
  @@ -406,9 +400,9 @@
           // instantiate the kernel
           //
   
  -        Kernel kernel = 
  -          createKernel( getLogger(), criteria, systemContext, application );
  -        setShutdownHook( getLogger(), kernel );
  +        //Kernel kernel = 
  +        //  createKernel( getLogger(), criteria, systemContext, application );
  +
           if( criteria.isAutostartEnabled() )
           {
               getLogger().debug( "startup phase" );
  @@ -446,6 +440,7 @@
           return kernel;
       }
   
  +    /*
       private Kernel createKernel(
         Logger logger, KernelCriteria criteria, SystemContext context, ContainmentModel application
)
         throws KernelException
  @@ -462,6 +457,7 @@
               throw new KernelException( error, e );
           }
       }
  +    */
   
      /**
       * If the kernel criteria includes a language code
  
  
  
  1.3       +188 -171  avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultKernel.java	13 Jan 2004 11:41:27 -0000	1.2
  +++ DefaultKernel.java	13 Jan 2004 18:43:15 -0000	1.3
  @@ -51,15 +51,20 @@
   package org.apache.avalon.merlin.impl;
   
   import java.net.URL;
  +import java.util.LinkedList;
  +import java.util.Iterator;
   
   import org.apache.avalon.merlin.Kernel;
  -import org.apache.avalon.merlin.KernelCriteria;
  +import org.apache.avalon.merlin.KernelContext;
  +import org.apache.avalon.merlin.KernelError;
   import org.apache.avalon.merlin.KernelException;
   import org.apache.avalon.merlin.KernelRuntimeException;
  +import org.apache.avalon.merlin.event.KernelEventListener;
  +import org.apache.avalon.merlin.event.KernelStateEvent;
   
   import org.apache.avalon.activation.appliance.Appliance;
   import org.apache.avalon.activation.appliance.Block;
  -import org.apache.avalon.activation.appliance.impl.AbstractBlock;
  +import org.apache.avalon.activation.appliance.impl.DefaultBlock;
   
   import org.apache.avalon.composition.data.TargetDirective;
   import org.apache.avalon.composition.logging.LoggingManager;
  @@ -69,6 +74,8 @@
   import org.apache.avalon.composition.model.SystemContext;
   import org.apache.avalon.composition.util.StringHelper;
   
  +import org.apache.avalon.util.exception.ExceptionHelper;
  +
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.logger.Logger;
   
  @@ -80,48 +87,20 @@
    */
   public class DefaultKernel implements Kernel
   {
  -    //--------------------------------------------------------------
  -    // static
  -    //--------------------------------------------------------------
  -
  -    private static final String INITIALIZING = "initializing";
  -    private static final String INITIALIZED = "initialized";
  -    private static final String STARTING = "starting";
  -    private static final String COMPOSITION = "model composition";
  -    private static final String ASSEMBLY = "model assembly";
  -    private static final String DEPLOYMENT = "block deployment";
  -    private static final String STARTED = "started";
  -    private static final String STOPPING = "stopping";
  -    private static final String DECOMMISSIONING = "decommissioning";
  -    private static final String DISSASSEMBLY = "dissassembly";
  -    private static final String BLOCK_DISPOSAL = "block disposal";
  -    private static final String STOPPED = "stopped";
   
       //--------------------------------------------------------------
       // immutable state
       //--------------------------------------------------------------
   
  -    private final Logger m_logger;
  -
  -    private final KernelCriteria m_criteria;
  -
  -    private final SystemContext m_context;
  -
  -    private final ContainmentModel m_model;
  -
  -    private final DefaultState m_self = new DefaultState();
  +    private final LinkedList m_listeners = new LinkedList();
   
  -    private final DefaultState m_start = new DefaultState();
  +    private final KernelContext m_context;
   
  -    //--------------------------------------------------------------
  -    // mutable state
  -    //--------------------------------------------------------------
  +    private final Block m_application;
   
  -    private String m_stateString = INITIALIZING;
  +    private final Block m_system;
   
  -    private long m_stateChangeSequenceId = 0;
  -
  -    private Block m_application;
  +    private final State m_state;
   
       //--------------------------------------------------------------
       // constructor
  @@ -129,46 +108,55 @@
   
      /**
       * Creation of a new Merlin Kernel.
  -    * @param logger the assigned logging channel
  -    * @param criteria the kernel creation criteria
  -    * @param model the application model
  -    * @exception KernelException if a kernel creation error occurs
  +    * @param context the creation context
  +    * @exception KernelException if a kernel initialization error occurs
       */
  -    public DefaultKernel( 
  -      final Logger logger,
  -      final KernelCriteria criteria, 
  -      final SystemContext context,
  -      final ContainmentModel model ) throws KernelException
  +    public DefaultKernel( KernelContext context ) throws KernelException
       {
  -        if( logger == null ) 
  -          throw new NullPointerException( "logger" );
  -        if( criteria == null ) 
  -          throw new NullPointerException( "criteria" );
           if( context == null ) 
             throw new NullPointerException( "context" );
  -        if( model == null ) 
  -          throw new NullPointerException( "model" );
   
  -        m_criteria = criteria;
           m_context = context;
  -        m_model = model;
  -        m_logger = logger;
  +        m_state = new State( this );
   
  -        setState( INITIALIZED );
  +        setState( INITIALIZING );
  +
  +        try
  +        {
  +            ContainmentModel facilities = 
  +              context.getFacilitiesModel();
  +            facilities.assemble();
  +            DefaultBlock system = 
  +              new DefaultBlock( facilities );
  +            system.deploy();
  +            m_system = system;
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Cannot create system facilities.";
  +            throw new KernelError( error, e );
  +        }
  +
  +
  +        try
  +        {
  +            m_application = 
  +              new DefaultBlock( context.getApplicationModel() );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Cannot create application runtime.";
  +            throw new KernelError( error, e );
  +        }
   
  +        setState( INITIALIZED );
           if( getLogger().isDebugEnabled() )
           {
  -            int count = 
  -              m_model.getModels().length;
  -            if( count == 0 )
  -            {
  -                getLogger().debug( "kernel established" );
  -            }
  -            else
  -            {
  -                getLogger().debug( "kernel established (" + count + ")" );
  -            }
  +            m_context.getLogger().debug( "kernel established" );
           }
  +        setState( STOPPED );
       }
   
       //--------------------------------------------------------------
  @@ -176,17 +164,31 @@
       //--------------------------------------------------------------
   
      /**
  -    * Return the block matching the supplied path.
  +    * Add a kernel listener.
  +    * @param listener the kernel listener to be added
  +    */
  +    public void addKernelEventListener( KernelEventListener listener )
  +    {
  +        m_state.addKernelEventListener( listener );
  +    }
  +
  +   /**
  +    * Remove a kernel listener.
  +    * @param listener the kernel listener to be removed
  +    */
  +    public void removeKernelEventListener( KernelEventListener listener )
  +    {
  +        m_state.removeKernelEventListener( listener );
  +    }
  +
  +   /**
  +    * Return the appliance matching the supplied path.
       * @param path an appliance path
       * @return the corresponding appliance
  +    * @exception KernelException if the path is unknown
       */
       public Appliance locate( String path ) throws KernelException
       {
  -        if( null == m_application )
  -        {
  -            throw new IllegalStateException( "not-started" );
  -        }
  -
           try
           {
               return m_application.locate( path );
  @@ -223,68 +225,47 @@
           // instantiate the runtime root application block
           //
   
  -        synchronized( m_self )
  +        synchronized( m_state )
           {
  -            if( m_self.isEnabled() ) return;
  -            setState( ASSEMBLY );
  -            try
  +            if( m_state.getState() != STOPPED ) return;
  +
  +            if( getLogger().isDebugEnabled() )
               {
                   getLogger().debug( "application assembly" );
  -                m_model.assemble();
  -            }
  -            catch( Throwable e )
  -            {
  -                final String error = 
  -                  "Application assembly failure.";
  -                throw new KernelException( error, e );
               }
   
               try
               {
  -                m_application = 
  -                  AbstractBlock.createRootBlock( m_model );
  -                setState( INITIALIZED );
  +                setState( ASSEMBLY );
  +                m_application.getModel().assemble();
               }
               catch( Throwable e )
               {
  -                final String error = 
  -                  "Application establishment failure.";
  +                setState( INITIALIZED );
  +                final String error =
  +                  "Cannot assemble application.";
                   throw new KernelException( error, e );
               }
   
  -            Throwable cause = null;
  -            setState( DEPLOYMENT );
  -            try
  +            if( getLogger().isDebugEnabled() )
               {
                   getLogger().debug( "application deployment" );
  +            }
  +
  +            try
  +            {
  +                setState( DEPLOYMENT );
                   m_application.deploy();
  -                m_self.setEnabled( true );
               }
               catch( Throwable e )
               {
                   setState( INITIALIZED );
  -                cause = e;
  -                final String error = 
  -                  "Application deployment failure.";
  +                final String error =
  +                  "Cannot deploy application.";
                   throw new KernelException( error, e );
               }
  -            finally
  -            {
  -                if( cause != null )
  -                {
  -                    shutdown();
  -                }
  -                else if( !m_criteria.isServerEnabled() )
  -                {
  -                    setState( STARTED );
  -                    // TODO: add pause parameter
  -                    shutdown();
  -                }
  -                else
  -                {
  -                    setState( STARTED );
  -                }
  -            }
  +            
  +            setState( STARTED );
           }
       }
   
  @@ -294,46 +275,44 @@
       */
       public void shutdown()
       {
  -        synchronized( m_self )
  +        synchronized( m_state )
           {
  -            if( !m_self.isEnabled() ) return;
  +            if( m_state.getState() != STARTED ) return;
   
               setState( STOPPING );
   
  -
  -            if( m_application != null )
  +            try
               {
  -                try
  -                {
  -                    setState( DECOMMISSIONING );
  -                    m_application.decommission();
  -                }
  -                catch( Throwable e )
  +                setState( DECOMMISSIONING );
  +                m_application.decommission();
  +            }
  +            catch( Throwable e )
  +            {
  +                if( getLogger().isWarnEnabled() )
                   {
  -                    if( getLogger().isWarnEnabled() )
  -                    {
  -                        final String error =
  -                          "Ignoring block decommissioning error.";
  -                        getLogger().warn( error, e );
  -                    }
  +                    final String error =
  +                      "Ignoring block decommissioning error.";
  +                    getLogger().warn( error, e );
                   }
  +            }
   
  -                try
  -                {
  -                    setState( DISSASSEMBLY );
  -                    getLogger().info( "dissassembly phase" );
  -                    m_model.disassemble();
  -                }
  -                catch( Throwable e )
  +            /*
  +            try
  +            {
  +                setState( DISSASSEMBLY );
  +                getLogger().info( "dissassembly phase" );
  +                m_model.disassemble();
  +            }
  +            catch( Throwable e )
  +            {
  +                if( getLogger().isWarnEnabled() )
                   {
  -                    if( getLogger().isWarnEnabled() )
  -                    {
  -                        final String error =
  -                          "Ignoring application dissassembly error.";
  -                        getLogger().warn( error, e );
  -                    }
  +                    final String error =
  +                      "Ignoring application dissassembly error.";
  +                    getLogger().warn( error, e );
                   }
               }
  +            */
   
               if( getLogger().isDebugEnabled() )
               {
  @@ -342,7 +321,6 @@
               }
   
               setState( STOPPED );
  -            m_self.setEnabled( false );
           }
       }
   
  @@ -357,46 +335,85 @@
        *
        * @param state a string representing the new kernel state
        */
  -     private void setState( String state )
  +     private void setState( int state )
        {
  -         if( m_stateString.equals( state ) ) return;
  -         getLogger().debug( "state: " + state );
  -         String old = m_stateString;
  -         m_stateString = state;
  -         long id = m_stateChangeSequenceId++;
  -         //AttributeChangeNotification notification = 
  -         //  new AttributeChangeNotification( 
  -         //    this, id, System.currentTimeMillis(),
  -         //    "State change", "state", "string", old, state );
  -         //sendNotification( notification );
  +         if( getLogger().isDebugEnabled() )
  +         {
  +             getLogger().debug( "state: " + state );
  +         }
  +         m_state.setState( state );
        }
   
  -    private class DefaultState
  +    private Logger getLogger()
  +    {
  +        return m_context.getLogger();
  +    }
  +
  +
  +    private class State
       {
  -        private boolean m_enabled = false;
  +        private int m_state = INITIALIZING;
   
  -       /**
  -        * Return the enabled state of the state.
  -        * @return TRUE if the state has been enabled else FALSE
  -        */
  -        public boolean isEnabled()
  +        private LinkedList m_listeners = new LinkedList();
  +
  +        private final Kernel m_kernel;
  +
  +        State( Kernel kernel )
           {
  -            return m_enabled;
  +            m_kernel = kernel;
           }
   
  -       /**
  -        * Set the enabled state of the state.
  -        * @param enabled the enabled state to assign
  -        */
  -        public void setEnabled( boolean enabled )
  +        public void addKernelEventListener( KernelEventListener listener )
           {
  -            m_enabled = enabled;
  +            synchronized( m_listeners )
  +            {
  +                m_listeners.add( listener );
  +            }
           }
  -    }
   
  -    private Logger getLogger()
  -    {
  -        return m_logger;
  -    }
  +        public void removeKernelEventListener( KernelEventListener listener )
  +        {
  +            synchronized( m_listeners )
  +            {
  +                m_listeners.remove( listener );
  +            }
  +        }
   
  +        public int getState()
  +        {
  +            return m_state;
  +        }
  +
  +        public synchronized void setState( int state )
  +        {
  +            int oldValue = m_state;
  +            int newValue = state;
  +
  +            m_state = newValue;
  +
  +            KernelStateEvent event = 
  +              new KernelStateEvent( m_kernel, oldValue, newValue );
  +            fireStateChangedEvent( event );
  +        }
  +
  +        private void fireStateChangedEvent( final KernelStateEvent event )
  +        {
  +            Iterator iterator = m_listeners.iterator();
  +            while( iterator.hasNext() )
  +            {
  +                final KernelEventListener listener = 
  +                  (KernelEventListener) iterator.next();
  +                try
  +                {
  +                    listener.stateChanged( event );
  +                }
  +                catch( Throwable e )
  +                {
  +                    final String error = 
  +                      ExceptionHelper.packException( e, true );
  +                    getLogger().warn( error );
  +                }
  +            }
  +        }
  +    }
   }
  
  
  
  1.1                  avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernelContext.java
  
  Index: DefaultKernelContext.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.merlin.impl;
  
  import java.net.URL;
  import java.io.File;
  
  import org.apache.avalon.framework.logger.Logger;
  
  import org.apache.avalon.composition.model.ContainmentModel;
  
  import org.apache.avalon.merlin.KernelContext;
  
  /**
   * The context argument supplied to a new kernel instance.
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2004/01/13 18:43:15 $
   */
  public class DefaultKernelContext implements KernelContext
  {
      private final Logger m_logger;
      private final ContainmentModel m_facilities;
      private final ContainmentModel m_application;
  
     /**
      * Creation of a new default kernel context.
      * @param logger the logging channel to be assigned to the kernel
      * @param facilities the internal facilities model
      * @param appliance the application model
      */
      public DefaultKernelContext( 
        final Logger logger, final ContainmentModel facilities, 
        final ContainmentModel application )
      {
          m_logger = logger;
          m_facilities = facilities;
          m_application = application;
      }
      
     /**
      * Return the assigned logging channel.
      * @return the loggging channel
      */
      public Logger getLogger()
      {
          return m_logger;
      }
  
     /**
      * Return the facilities model.
      * @return the internal container facilities
      */
      public ContainmentModel getFacilitiesModel()
      {
          return m_facilities;
      }
  
     /**
      * Return the application model.
      * @return the root application model 
      */
      public ContainmentModel getApplicationModel()
      {
          return m_application;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message