colus       2002/07/22 06:26:23

  Modified:    src/java/org/apache/avalon/phoenix/components/kernel
                        DefaultKernel.java
  Log:
  Lock startup and shutdown of application.
  Is it right implementation for PR8647?
  
  PR: 8647
  
  Revision  Changes    Path
  1.74      +69 -58    
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.73
  retrieving revision 1.74
  diff -u -r1.73 -r1.74
  --- DefaultKernel.java        14 Jul 2002 05:41:05 -0000      1.73
  +++ DefaultKernel.java        22 Jul 2002 13:26:23 -0000      1.74
  @@ -125,69 +125,80 @@
       private void startup( final SarEntry entry )
           throws Exception
       {
  -        final String name = entry.getMetaData().getName();
  -
  -        Application application = entry.getApplication();
  -        if( null == application )
  -        {
  -            try
  -            {
  -                final Application newApp = new DefaultApplication();
  -                final Logger childLogger = getLogger().getChildLogger( name );
  -                ContainerUtil.enableLogging( newApp, childLogger );
  -
  -                final ApplicationContext context = createApplicationContext( entry 
);
  -                newApp.setApplicationContext( context );
  -
  -                ContainerUtil.initialize( newApp );
  -                ContainerUtil.start( newApp );
  -
  -                entry.setApplication( newApp );
  -                application = newApp;
  -            }
  -            catch( final Throwable t )
  -            {
  -                //Initialization failed so clean entry
  -                //so invalid instance is not used
  -                entry.setApplication( null );
  -
  -                final String message =
  -                    REZ.getString( "kernel.error.entry.initialize",
  -                                   entry.getMetaData().getName() );
  -                throw new CascadingException( message, t );
  -            }
  -
  -            // manage application
  -            try
  -            {
  -                m_applicationManager.register( name,
  -                                               application,
  -                                               new Class[]{ApplicationMBean.class} 
);
  -            }
  -            catch( final Throwable t )
  -            {
  -                final String message =
  -                    REZ.getString( "kernel.error.entry.manage", name );
  -                throw new CascadingException( message, t );
  -            }
  -        }
  +     //lock for application startup and shutdown
  +     synchronized ( entry )
  +     {
  +         final String name = entry.getMetaData().getName();
  +
  +         Application application = entry.getApplication();
  +         if( null == application )
  +         {
  +             try
  +             {
  +                 final Application newApp = new DefaultApplication();
  +                 final Logger childLogger =
  +                     getLogger().getChildLogger( name );
  +                 ContainerUtil.enableLogging( newApp, childLogger );
  +
  +                 final ApplicationContext context =
  +                     createApplicationContext( entry );
  +                 newApp.setApplicationContext( context );
  +
  +                 ContainerUtil.initialize( newApp );
  +                 ContainerUtil.start( newApp );
  +
  +                 entry.setApplication( newApp );
  +                 application = newApp;
  +             }
  +             catch( final Throwable t )
  +             {
  +                 //Initialization failed so clean entry
  +                 //so invalid instance is not used
  +                 entry.setApplication( null );
  +
  +                 final String message =
  +                     REZ.getString( "kernel.error.entry.initialize",
  +                                    entry.getMetaData().getName() );
  +                 throw new CascadingException( message, t );
  +             }
  +
  +             // manage application
  +             try
  +             {
  +                 m_applicationManager.register( name,
  +                                                application,
  +                                                new Class[]{ApplicationMBean.class} 
);
  +             }
  +             catch( final Throwable t )
  +             {
  +                 final String message =
  +                     REZ.getString( "kernel.error.entry.manage", name );
  +                 throw new CascadingException( message, t );
  +             }
  +         }
  +     }
       }
   
       private void shutdown( final SarEntry entry )
           throws Exception
       {
  -        final Application application = entry.getApplication();
  -        if( null != application )
  -        {
  -            entry.setApplication( null );
  -            ContainerUtil.shutdown( application );
  -        }
  -        else
  -        {
  -            final String message =
  -                REZ.getString( "kernel.error.entry.nostop", 
entry.getMetaData().getName() );
  -            getLogger().warn( message );
  -        }
  +     //lock for application startup and shutdown
  +     synchronized ( entry )
  +     {
  +         final Application application = entry.getApplication();
  +         if( null != application )
  +         {
  +             entry.setApplication( null );
  +             ContainerUtil.shutdown( application );
  +         }
  +         else
  +         {
  +             final String message =
  +                 REZ.getString( "kernel.error.entry.nostop",
  +                                entry.getMetaData().getName() );
  +             getLogger().warn( message );
  +         }
  +     }
       }
   
       public void addApplication( final SarMetaData metaData,
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to