mcconnell 2002/11/29 09:37:30 Modified: assembly/src/java/org/apache/avalon/assembly/lifestyle AbstractLifestyleHandler.java PooledLifestyleHandler.java SingletonLifestyleHandler.java ThreadLocalLifestyleHandler.java TransientLifestyleHandler.java Log: Updates to lifestyle management. Revision Changes Path 1.4 +3 -3 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/AbstractLifestyleHandler.java Index: AbstractLifestyleHandler.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/AbstractLifestyleHandler.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractLifestyleHandler.java 29 Nov 2002 16:06:35 -0000 1.3 +++ AbstractLifestyleHandler.java 29 Nov 2002 17:37:30 -0000 1.4 @@ -273,7 +273,7 @@ * @param object the object to process * @exception Exception if a stage procesing exception occurs */ - protected void processAccessStage( Object object ) throws Exception + protected void processAccessStage( Object object ) throws LifestyleException { StageDescriptor[] phases = m_appliance.getProfile().getType().getStages(); for( int i = 0; i < phases.length; i++ ) @@ -322,7 +322,7 @@ StageDescriptor stage, Object object, boolean access ) - throws Exception + throws LifestyleException { Appliance provider = m_appliance.getExtensionProvider( stage ); if( provider == null ) 1.2 +3 -2 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/PooledLifestyleHandler.java Index: PooledLifestyleHandler.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/PooledLifestyleHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PooledLifestyleHandler.java 29 Nov 2002 13:04:56 -0000 1.1 +++ PooledLifestyleHandler.java 29 Nov 2002 17:37:30 -0000 1.2 @@ -210,7 +210,7 @@ try { Object object = m_pool.acquire(); - //super.processAccessStage( object ); + super.processAccessStage( object ); return object; } catch( Throwable e ) @@ -235,6 +235,7 @@ try { + super.processReleaseStage( object ); m_pool.release( object ); } catch( Throwable e ) 1.2 +37 -4 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/SingletonLifestyleHandler.java Index: SingletonLifestyleHandler.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/SingletonLifestyleHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SingletonLifestyleHandler.java 29 Nov 2002 13:04:56 -0000 1.1 +++ SingletonLifestyleHandler.java 29 Nov 2002 17:37:30 -0000 1.2 @@ -88,7 +88,7 @@ */ public Object access( DependencyDescriptor dependency ) throws LifestyleException { - return newInstance(); + return access(); } /** @@ -97,7 +97,31 @@ */ public Object access( StageDescriptor stage ) throws LifestyleException { - return newInstance(); + return access(); + } + + /** + * Activate the implementation. + * @param appliance the appliance to deploy + */ + private Object access() throws LifestyleException + { + Object object = newInstance(); + try + { + super.processAccessStage( object ); + } + catch( Throwable e ) + { + // + // We really should be putting more effort into cleaning up + // the created instance - i.e. shoudown, disposal etc. Also, + // should we be releasing the component in this scenario? + // + + m_instance = null; + } + return object; } /** @@ -106,7 +130,16 @@ */ public void release( Object object ) { - // nothing to do + if( object.equals( m_instance ) ) + { + super.processReleaseStage( m_instance ); + } + else + { + final String warning = + "Illegal attempt to release an object that was not provided by this handler."; + getLogger().warn( warning ); + } } //============================================================== 1.2 +4 -3 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/ThreadLocalLifestyleHandler.java Index: ThreadLocalLifestyleHandler.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/ThreadLocalLifestyleHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ThreadLocalLifestyleHandler.java 29 Nov 2002 13:04:56 -0000 1.1 +++ ThreadLocalLifestyleHandler.java 29 Nov 2002 17:37:30 -0000 1.2 @@ -101,7 +101,7 @@ if( object.equals( m_instance.get() ) ) { - //super.processReleaseStage( object ); + super.processReleaseStage( object ); } } @@ -112,7 +112,7 @@ * @return an instance of the type defined by the appliance * @exception Exception if an access phase error occurs */ - private Object access() + private Object access() throws LifestyleException { getLogger().debug( "get" ); @@ -120,8 +120,9 @@ { m_instance = new ThreadLocalComponent( this ); } + Object object = m_instance.get(); - //super.processAccessStage( object ); + super.processAccessStage( object ); return object; } 1.2 +15 -4 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/TransientLifestyleHandler.java Index: TransientLifestyleHandler.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/TransientLifestyleHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TransientLifestyleHandler.java 29 Nov 2002 13:04:56 -0000 1.1 +++ TransientLifestyleHandler.java 29 Nov 2002 17:37:30 -0000 1.2 @@ -88,7 +88,7 @@ */ public Object access( DependencyDescriptor dependency ) throws LifestyleException { - return newInstance(); + return access(); } /** @@ -97,7 +97,18 @@ */ public Object access( StageDescriptor stage ) throws LifestyleException { - return newInstance(); + return access(); + } + + /** + * Activate the implementation. + * @param appliance the appliance to deploy + */ + private Object access() throws LifestyleException + { + Object object = newInstance(); + super.processAccessStage( object ); + return object; } /** @@ -106,7 +117,7 @@ */ public void release( Object object ) { - // need to stop and dispose of the object + super.processReleaseStage( object ); } //==============================================================
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>