donaldp 01/04/14 05:08:03 Modified: src/java/org/apache/avalon/atlantis AbstractKernel.java Application.java Kernel.java Added: src/java/org/apache/avalon/atlantis Embeddor.java Log: Migrate Embeddor from Phoenix to atlantis Revision Changes Path 1.2 +85 -89 jakarta-avalon/src/java/org/apache/avalon/atlantis/AbstractKernel.java Index: AbstractKernel.java =================================================================== RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/atlantis/AbstractKernel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractKernel.java 2001/02/24 04:00:50 1.1 +++ AbstractKernel.java 2001/04/14 12:08:03 1.2 @@ -18,8 +18,8 @@ import org.apache.avalon.DefaultContext; import org.apache.avalon.camelot.AbstractContainer; import org.apache.avalon.camelot.Container; -import org.apache.avalon.camelot.Entry; import org.apache.avalon.camelot.ContainerException; +import org.apache.avalon.camelot.Entry; import org.apache.avalon.camelot.FactoryException; import org.apache.avalon.camelot.Locator; @@ -40,12 +40,10 @@ extends AbstractContainer implements Kernel { - protected boolean m_initialised = false; - protected boolean m_running = false; - protected Class m_applicationClass; + protected boolean m_initialised; - public void init() - throws Exception + public void init() + throws Exception { final Iterator names = list(); while( names.hasNext() ) @@ -54,7 +52,7 @@ final Entry entry = getEntry( name ); initializeEntry( name, entry ); } - } + } public void start() throws Exception @@ -67,24 +65,10 @@ startEntry( name, entry ); } } - - public void run() - { - m_running = true; - - while( m_running ) - { - try { synchronized( this ) { wait(); } } - catch (InterruptedException e) {} - } - } - public void stop() + public void stop() throws Exception { - m_running = false; - synchronized( this ) { notifyAll(); } - final Iterator names = list(); while( names.hasNext() ) { @@ -93,12 +77,12 @@ stopEntry( name, entry ); } } - - public void dispose() + + public void dispose() throws Exception { m_initialised = false; - + final Iterator names = list(); while( names.hasNext() ) { @@ -109,85 +93,115 @@ } /** - * Retrieve Application from container. - * The Application that is returned must be initialized + * Retrieve Application from container. + * The Application that is returned must be initialized * and prepared for manipulation. * * @param name the name of application * @return the application - * @exception ContainerException if an error occurs + * @exception ContainerException if an error occurs */ public Application getApplication( String name ) throws ContainerException { final Entry entry = getEntry( name ); - try { initializeEntry( name, entry ); } - catch( final Exception e ) - { - throw new ContainerException( "Error prepareing entry", e ); - } + initializeEntry( name, entry ); return (Application)entry.getInstance(); } - protected void initializeEntry( final String name, final Entry entry ) - throws Exception + /** + * Create and initialize the application instance if it is not already initialized. + * + * @param name the name of application + * @param entry the entry for application + * @exception ContainerException if an error occurs + */ + private void initializeEntry( final String name, final Entry entry ) + throws ContainerException { Application application = (Application)entry.getInstance(); if( null == application ) { + //Give sub-class chance to do some validation + //by overiding preInitialize preInitializeEntry( name, entry ); + application = createApplicationFor( name, entry ); - entry.setInstance( application ); - prepareApplication( name, entry, application ); - application.init(); + try + { + entry.setInstance( application ); + + //Give sub-class chance to prepare entry + //This performs process required before the application + //is ready to be initialized + prepareApplication( name, entry ); + + application.init(); + } + catch( final Throwable t ) + { + //Initialization failed so clean entry + //so invalid instance is not used + entry.setInstance( null ); + } + + //Give sub-class chance to do something post + //initialisation postInitializeEntry( name, entry ); } } - protected void startEntry( final String name, final Entry entry ) + private void startEntry( final String name, final Entry entry ) throws Exception { final Application application = (Application)entry.getInstance(); - if( null != application ) + if( null != application ) { application.start(); } else { getLogger().warn( "Failed to start application " + name + - " as it is not initialized" ); + " as it is not initialized" ); } } - protected void stopEntry( final String name, final Entry entry ) + private void stopEntry( final String name, final Entry entry ) throws Exception { final Application application = (Application)entry.getInstance(); - if( null != application ) + if( null != application ) { application.stop(); } else { getLogger().warn( "Failed to stop application " + name + - " as it is not initialized/started" ); + " as it is not initialized/started" ); } } - protected void disposeEntry( final String name, final Entry entry ) - throws Exception + private void disposeEntry( final String name, final Entry entry ) + throws ContainerException { - Application application = (Application)entry.getInstance(); + final Application application = (Application)entry.getInstance(); if( null != application ) { preDisposeEntry( name, entry ); entry.setInstance( null ); - application.dispose(); + + try { application.dispose(); } + catch( final Exception e ) + { + throw new ContainerException( "Failed to dispose application " + name, + e ); + } + postDisposeEntry( name, entry ); } } @@ -198,11 +212,11 @@ * * @param name the name of the entry * @param entry the entry - * @exception Exception if an error occurs + * @exception ContainerException if an error occurs */ protected void preInitializeEntry( final String name, final Entry entry ) - throws Exception - { + throws ContainerException + { } /** @@ -211,11 +225,9 @@ * * @param name the name of the entry * @param entry the entry - * @exception Exception if an error occurs */ protected void postInitializeEntry( final String name, final Entry entry ) - throws Exception - { + { } /** @@ -224,11 +236,11 @@ * * @param name the name of the entry * @param entry the entry - * @exception Exception if an error occurs + * @exception ContainerException if an error occurs */ protected void preDisposeEntry( final String name, final Entry entry ) - throws Exception - { + throws ContainerException + { } /** @@ -237,49 +249,33 @@ * * @param name the name of the entry * @param entry the entry - * @exception Exception if an error occurs */ protected void postDisposeEntry( final String name, final Entry entry ) - throws Exception - { + { } /** * Prepare an application before it is initialized. - * Overide to provide functionality. + * Overide to provide functionality. * Usually used to setLogger(), contextualize, compose, configure. * * @param name the name of application - * @param entry the application entry - * @param application the application instance - * @exception Exception if an error occurs + * @param entry the application entry + * @exception ContainerException if an error occurs */ - protected void prepareApplication( final String name, - final Entry entry, - final Application application ) - throws Exception - { - } - - protected Application createApplicationFor( final String name, final Entry entry ) - throws Exception + protected void prepareApplication( final String name, final Entry entry ) + throws ContainerException { - final Application application = newApplication( name, entry ); - - if( !m_applicationClass.isInstance( application ) ) - { - throw new IllegalArgumentException( "Created an application that is not " + - "of type " + m_applicationClass.getName() + - " but of type " + - application.getClass().getName() ); - } - - return application; } - protected Application newApplication( final String name, final Entry entry ) - throws Exception - { - return (Application)m_applicationClass.newInstance(); - } + /** + * Create a new application for kernel. + * + * @param name the name of application + * @param entry the entry corresponding to application + * @return the new Application + * @exception ContainerException if an error occurs + */ + protected abstract Application createApplicationFor( String name, Entry entry ) + throws ContainerException; } 1.2 +1 -1 jakarta-avalon/src/java/org/apache/avalon/atlantis/Application.java Index: Application.java =================================================================== RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/atlantis/Application.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Application.java 2001/02/24 04:00:50 1.1 +++ Application.java 2001/04/14 12:08:03 1.2 @@ -24,6 +24,6 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a> */ public interface Application - extends Initializable, Startable, Stoppable, Disposable, Container + extends Container, Initializable, Startable, Stoppable, Disposable { } 1.2 +1 -1 jakarta-avalon/src/java/org/apache/avalon/atlantis/Kernel.java Index: Kernel.java =================================================================== RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/atlantis/Kernel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Kernel.java 2001/02/24 04:00:50 1.1 +++ Kernel.java 2001/04/14 12:08:03 1.2 @@ -23,7 +23,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a> */ public interface Kernel - extends Application, Runnable + extends Application { /** * Retrieve Application from container. 1.1 jakarta-avalon/src/java/org/apache/avalon/atlantis/Embeddor.java Index: Embeddor.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE file. */ package org.apache.avalon.atlantis; import org.apache.avalon.Disposable; import org.apache.avalon.Initializable; import org.apache.avalon.configuration.ConfigurationException; import org.apache.avalon.configuration.Parameters; /** * This is the object that is interacted with to create, manage and * dispose of the kernel and related resources. * * @author <a href="[EMAIL PROTECTED]">Leo Simons</a> * @author <a href="[EMAIL PROTECTED]">Peter Donald</a> */ public interface Embeddor extends Initializable, Disposable { /** * Kset parameters for this component. * This must be called before initialize() * * @param parameters the Parameters for embeddor * @exception ConfigurationException if an error occurs */ void setParameters( Parameters parameters ) throws ConfigurationException; /** * After the Embeddor is initialized, this method is called to actually * do the work. It will return when the embeddor is ready to be disposed. * * @exception Exception if an error occurs */ void execute() throws Exception; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]