You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/04/30 01:35:25 UTC
cvs commit: avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifestyle/impl DefaultLifestyleService.java
mcconnell 2003/04/29 16:35:25
Modified: merlin/assembly/src/java/org/apache/avalon/assembly/appliance/impl
DefaultApplianceFactory.java
merlin/assembly/src/java/org/apache/avalon/assembly/engine/impl
EngineClassLoader.java
merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl
AbstractContextualizer.java
DefaultDeploymentService.java
WrapperComponentManager.java
WrapperComponentSelector.java
merlin/assembly/src/java/org/apache/avalon/assembly/lifestyle/impl
DefaultLifestyleService.java
Log:
Improving the code relating to the deployment service including improvement to the references of keys, reduction in the number of instances, and rationalization of creation process.
Revision Changes Path
1.5 +85 -74 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance/impl/DefaultApplianceFactory.java
Index: DefaultApplianceFactory.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance/impl/DefaultApplianceFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultApplianceFactory.java 29 Apr 2003 17:26:26 -0000 1.4
+++ DefaultApplianceFactory.java 29 Apr 2003 23:35:24 -0000 1.5
@@ -103,12 +103,15 @@
* @exception ApplianceException if a creation error occurs
*/
public static ApplianceFactory createApplianceFactory(
- EngineClassLoader loader, Logger logger, ApplianceRepository repository,
- Locator system )
- throws ApplianceException
+ EngineClassLoader loader,
+ Logger logger,
+ LoggingManager logging,
+ ApplianceRepository repository,
+ Locator system )
+ throws ApplianceException
{
return createApplianceFactory(
- loader, DefaultApplianceFactory.class.getName(), logger, repository, system );
+ loader, DefaultApplianceFactory.class.getName(), logger, logging, repository, system );
}
/**
@@ -122,9 +125,13 @@
* @exception ApplianceException if a creation error occurs
*/
public static ApplianceFactory createApplianceFactory(
- Engine loader, String classname, Logger logger,
- ApplianceRepository repository, Locator system )
- throws ApplianceException
+ Engine loader,
+ String classname,
+ Logger logger,
+ LoggingManager logging,
+ ApplianceRepository repository,
+ Locator system )
+ throws ApplianceException
{
if( classname == null )
{
@@ -153,25 +160,13 @@
if( classname.equals( DefaultApplianceFactory.class.getName() ) )
{
- return createDefaultApplianceFactory( logger, system, repository );
+ return createDefaultApplianceFactory( logger, logging, system, repository );
}
//
// we are building a custom appliance factory
//
- LoggingManager logging = null;
- try
- {
- logging = (LoggingManager) system.get( LoggingManager.KEY );
- }
- catch( ContextException e )
- {
- final String error =
- "Supplied system context does not container the logging manager.";
- throw new ApplianceException( error, e );
- }
-
try
{
Type type = loader.getRepository().getTypeRepository().getType( classname );
@@ -184,19 +179,21 @@
context.makeReadOnly();
Appliance appliance = loader.createAppliance( context, true );
- appliance.assemble( new DependencyGraph() );
+ appliance.assemble();
Object factory = appliance.resolve( loader );
if( factory instanceof ApplianceFactory )
{
return (ApplianceFactory) factory;
- } else
+ }
+ else
{
final String error =
"Supplied classname '" + classname
+ "' does not implement the ApplianceFactory interface.";
throw new ApplianceException( error );
}
- } catch( Throwable e )
+ }
+ catch( Throwable e )
{
final String error =
"Could not create appliance factory using : "
@@ -214,18 +211,24 @@
* @exception ApplianceException if a creation error occurs
*/
private static ApplianceFactory createDefaultApplianceFactory(
- final Logger logger, final Locator context, final ApplianceRepository repository )
- throws ApplianceException
+ final Logger logger,
+ final LoggingManager logging,
+ final Locator context,
+ final ApplianceRepository repository )
+ throws ApplianceException
{
DefaultApplianceFactory factory = new DefaultApplianceFactory();
factory.enableLogging( logger );
try
{
DefaultLocator locator = new DefaultLocator( context );
+ final Logger log = logger.getChildLogger( "deployment" );
locator.put( ApplianceRepository.KEY, repository );
+ locator.put( LoggingManager.KEY, logging );
factory.contextualize( locator );
factory.initialize();
- } catch( Throwable e )
+ }
+ catch( Throwable e )
{
final String error =
"Unexpected error while attempting to create default appliance factory.";
@@ -234,6 +237,34 @@
return factory;
}
+ /**
+ * Static utility to create a deployment service.
+ * @param logging the logging manager
+ * @param logger the logging channel to assign to the deployment service
+ * @return the deployment service
+ */
+ private static DeploymentService createDeploymentService(
+ LoggingManager logging, Logger logger )
+ throws ApplianceException
+ {
+ try
+ {
+ DefaultDeploymentService deployment = new DefaultDeploymentService();
+ deployment.enableLogging( logger );
+ DefaultLocator locator = new DefaultLocator();
+ locator.put( LoggingManager.KEY, logging );
+ deployment.contextualize( locator );
+ deployment.initialize();
+ return deployment;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Internal error while attempting to create bootstrap deployment service.";
+ throw new ApplianceException( error, e );
+ }
+ }
+
//---------------------------------------------------------------------------
// state
//---------------------------------------------------------------------------
@@ -244,6 +275,10 @@
private PoolManager m_pool;
+ private LoggingManager m_logging;
+
+ private DeploymentService m_deployment;
+
//---------------------------------------------------------------------------
// contextualization
//---------------------------------------------------------------------------
@@ -253,6 +288,7 @@
m_system = context;
m_repository = (ApplianceRepository) context.get( ApplianceRepository.KEY );
m_pool = (PoolManager) context.get( "urn:assembly:threads.manager" );
+ m_logging = (LoggingManager) context.get( LoggingManager.KEY );
}
//---------------------------------------------------------------------------
@@ -265,6 +301,8 @@
{
throw new IllegalStateException( "context" );
}
+ final Logger logger = getLogger().getChildLogger( "deployment" );
+ m_deployment = createDeploymentService( m_logging, logger );
}
//---------------------------------------------------------------------------
@@ -295,22 +333,12 @@
}
//
- // we are building a custom appliance
+ // create the lifestyle service
//
- LoggingManager logging = null;
- try
- {
- logging = (LoggingManager) system.get( LoggingManager.KEY );
- }
- catch( ContextException e )
- {
- final String error =
- "Supplied system context does not container the logging manager.";
- throw new ApplianceException( error, e );
- }
+ LifestyleService lifestyle =
+ createLifestyleService( engine, m_pool, m_deployment );
- LifestyleService lifestyle = createLifestyleService( logging, engine, m_pool );
DefaultLocator locator = null;
try
{
@@ -322,7 +350,8 @@
locator.put( "urn:assembly:appliance.system", system );
locator.put( "urn:assembly:threads.manager", m_pool );
locator.makeReadOnly();
- } catch( Throwable e )
+ }
+ catch( Throwable e )
{
final String error =
"Unexpected error while building appliance context.";
@@ -344,13 +373,15 @@
appliance.contextualize( locator );
appliance.initialize();
return appliance;
- } catch( Throwable e )
+ }
+ catch( Throwable e )
{
final String error =
- "Unable to create appliance from context: " + context.getName();
+ "Unable to create appliance from context: " + context.getName();
throw new ApplianceException( error, e );
}
- } else
+ }
+ else
{
//
// its a custom appliance so in this case we use an apppliance to
@@ -384,14 +415,16 @@
if( object instanceof Appliance )
{
return (Appliance) object;
- } else
+ }
+ else
{
final String error =
"Supplied classname '" + classname
+ "' does not implement the Appliance interface.";
throw new ApplianceException( error );
}
- } catch( Throwable e )
+ }
+ catch( Throwable e )
{
final String error =
"Could not create appliance using : " + classname;
@@ -404,14 +437,17 @@
* Utility to create the default lifestyle service.
* @param engine the engine classloader
* @param pool the pool manager
+ * @param deployment the deployment service
* @return the lifestyle service
*/
private LifestyleService createLifestyleService(
- LoggingManager logging, Engine engine, PoolManager pool ) throws ApplianceException
+ Engine engine,
+ PoolManager pool,
+ DeploymentService deployment )
+ throws ApplianceException
{
try
{
- DeploymentService deployment = createDeploymentService( logging );
DefaultLifestyleService lifestyle = new DefaultLifestyleService();
lifestyle.enableLogging( getLogger().getChildLogger( "lifestyle" ) );
DefaultLocator context = new DefaultLocator();
@@ -422,7 +458,7 @@
lifestyle.contextualize( context );
lifestyle.initialize();
return lifestyle;
- }
+ }
catch( Throwable e )
{
final String error =
@@ -431,29 +467,4 @@
}
}
- private DeploymentService createDeploymentService( LoggingManager logging )
- throws ApplianceException
- {
- if( logging == null )
- {
- throw new NullPointerException( "logging" );
- }
-
- try
- {
- DefaultDeploymentService deployment = new DefaultDeploymentService();
- deployment.enableLogging( getLogger().getChildLogger( "deployment" ) );
- DefaultLocator locator = new DefaultLocator();
- locator.put( LoggingManager.KEY, logging );
- deployment.contextualize( locator );
- deployment.initialize();
- return deployment;
- }
- catch( Throwable e )
- {
- final String error =
- "Internal error while attempting to create bootstrap deployment service.";
- throw new ApplianceException( error, e );
- }
- }
}
1.3 +5 -4 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/engine/impl/EngineClassLoader.java
Index: EngineClassLoader.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/engine/impl/EngineClassLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- EngineClassLoader.java 29 Apr 2003 14:22:19 -0000 1.2
+++ EngineClassLoader.java 29 Apr 2003 23:35:24 -0000 1.3
@@ -419,7 +419,7 @@
m_meta = createRepositoryManager();
m_factory = DefaultApplianceFactory.createApplianceFactory(
- this, getLogger(), m_manager, getSystemContext() );
+ this, getLogger(), getLoggingManager(), m_manager, getSystemContext() );
//
// install the set of extensions
@@ -1073,11 +1073,12 @@
if( classname == null )
{
factory = m_factory;
- } else
+ }
+ else
{
factory =
DefaultApplianceFactory.createApplianceFactory(
- this, classname, logger, m_manager, getSystemContext() );
+ this, classname, logger, getLoggingManager(), m_manager, getSystemContext() );
}
Appliance appliance = factory.createAppliance( getSystemContext(), this, context, logger );
1.2 +1 -1 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/AbstractContextualizer.java
Index: AbstractContextualizer.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/AbstractContextualizer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractContextualizer.java 29 Apr 2003 00:55:46 -0000 1.1
+++ AbstractContextualizer.java 29 Apr 2003 23:35:24 -0000 1.2
@@ -68,7 +68,7 @@
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
*/
-public abstract class AbstractContextualizer implements Contextualization
+abstract class AbstractContextualizer implements Contextualization
{
//=======================================================================
// Extension
1.6 +66 -79 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/DefaultDeploymentService.java
Index: DefaultDeploymentService.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/DefaultDeploymentService.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultDeploymentService.java 29 Apr 2003 14:22:19 -0000 1.5
+++ DefaultDeploymentService.java 29 Apr 2003 23:35:24 -0000 1.6
@@ -69,6 +69,8 @@
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.parameters.Parameterizable;
import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.lifecycle.Creator;
import org.apache.avalon.meta.info.StageDescriptor;
import org.apache.avalon.meta.info.LoggerDescriptor;
@@ -88,11 +90,19 @@
// state
//==============================================================
- private Locator m_context;
+ /**
+ * The logger manager.
+ */
private LoggingManager m_logging;
+
+ /**
+ * Internal contextualization helper class.
+ */
private ContextualizationService m_contextualization;
- //private InitializationService m_initialization;
+ /**
+ * Initialization flag.
+ */
private boolean m_initialized = false;
//==============================================================
@@ -112,7 +122,6 @@
throw new NullPointerException( "context" );
}
m_logging = (LoggingManager) context.get( LoggingManager.KEY );
- m_context = context;
}
//==============================================================
@@ -121,32 +130,19 @@
public void initialize() throws Exception
{
- if( m_context == null )
+ try
{
- throw new IllegalStateException( "context" );
+ final DefaultContextualizationService service = new DefaultContextualizationService();
+ service.enableLogging( getLogger().getChildLogger( "context" ) );
+ m_contextualization = service;
}
-
- if( m_context.hasEntry( ContextualizationService.KEY ) )
- {
- m_contextualization =
- (ContextualizationService) m_context.get( ContextualizationService.KEY );
- }
- else
+ catch( Throwable e )
{
- m_contextualization = makeContextualizationService();
+ final String error =
+ "Internal error while attempting to build the bootstrap contextualization service.";
+ throw new DeploymentException( error, e );
}
-
- //if( m_context.hasEntry( InitializationService.KEY ) )
- //{
- // m_initialization =
- // (InitializationService) m_context.get( InitializationService.KEY );
- //} else
- //{
- // m_initialization = makeInitializationService();
- //}
-
m_initialized = true;
-
}
//==============================================================
@@ -218,6 +214,15 @@
// configure the component
//
+ if(( instance instanceof Serviceable ) || (instance instanceof Composable) )
+ {
+ handleServiceable( appliance, instance );
+ }
+
+ //
+ // configure the component
+ //
+
if( instance instanceof Configurable )
{
handleConfiguration( appliance, ((Configurable)instance) );
@@ -456,6 +461,42 @@
}
/**
+ * Service or compose a serviceable/composable object based on the information
+ * exposed by the supplied appliance.
+ *
+ * @param object the object to service or compose
+ * @param appliance the source of the composition information
+ */
+ private void handleServiceable( Appliance appliance, Object object )
+ throws Exception
+ {
+ if( object instanceof Serviceable )
+ {
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message = "servicing: " + appliance.toString();
+ getLogger().debug( message );
+ }
+ StandardServiceManager manager = new StandardServiceManager( appliance );
+ manager.enableLogging( getLogger().getChildLogger( "manager" ) );
+ ((Serviceable) object).service( manager );
+
+ }
+ else if( object instanceof Composable )
+ {
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message = "composing: " + appliance.toString();
+ getLogger().debug( message );
+ }
+ StandardServiceManager manager = new StandardServiceManager( appliance );
+ manager.enableLogging( getLogger().getChildLogger( "manager" ) );
+ ((Composable) object).compose(
+ new WrapperComponentManager( manager ) );
+ }
+ }
+
+ /**
* Processing of a stage handler for the create stage in the component
* lifecyle.
*
@@ -554,58 +595,4 @@
}
}
}
-
-
- //----------------------------------------------------------------------------
- // internal services
- //----------------------------------------------------------------------------
-
- private ContextualizationService makeContextualizationService() throws DeploymentException
- {
- try
- {
- DefaultCompositionService service = new DefaultCompositionService();
- service.enableLogging( getLogger().getChildLogger( "context" ) );
- return service;
- } catch( Throwable e )
- {
- final String error =
- "Internal error while attempting to build the bootstrap contextualization service.";
- throw new DeploymentException( error, e );
- }
- }
-
- /*
- private InitializationService makeInitializationService() throws DeploymentException
- {
- try
- {
- ExtendedInitializationService service = new ExtendedInitializationService();
- service.enableLogging( getLogger().getChildLogger( "init" ) );
- return service;
- }
- catch( Throwable e )
- {
- final String error =
- "Internal error while attempting to create an initialization service.";
- throw new DeploymentException( error, e );
- }
- }
- */
-
- //private DisposalService makeDisposalService() throws DeploymentException
- //{
- // try
- // {
- // ExtendedDisposalService service = new ExtendedDisposalService();
- // service.enableLogging( getLogger().getChildLogger( "disposal" ) );
- // return service;
- // }
- // catch( Throwable e )
- // {
- // final String error =
- // "Internal error while attempting to build the bootstrap disposal service.";
- // throw new DeploymentException( error, e );
- // }
- //}
}
1.2 +2 -2 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/WrapperComponentManager.java
Index: WrapperComponentManager.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/WrapperComponentManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WrapperComponentManager.java 29 Apr 2003 00:55:46 -0000 1.1
+++ WrapperComponentManager.java 29 Apr 2003 23:35:24 -0000 1.2
@@ -66,7 +66,7 @@
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision$ $Date$
*/
-public class WrapperComponentManager
+class WrapperComponentManager
implements ComponentManager
{
/**
1.2 +2 -2 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/WrapperComponentSelector.java
Index: WrapperComponentSelector.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/WrapperComponentSelector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WrapperComponentSelector.java 29 Apr 2003 00:55:46 -0000 1.1
+++ WrapperComponentSelector.java 29 Apr 2003 23:35:24 -0000 1.2
@@ -69,7 +69,7 @@
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version CVS $Revision$ $Date$
*/
-public class WrapperComponentSelector
+class WrapperComponentSelector
implements ComponentSelector
{
/**
1.2 +2 -5 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifestyle/impl/DefaultLifestyleService.java
Index: DefaultLifestyleService.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifestyle/impl/DefaultLifestyleService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultLifestyleService.java 26 Apr 2003 12:37:47 -0000 1.1
+++ DefaultLifestyleService.java 29 Apr 2003 23:35:25 -0000 1.2
@@ -113,11 +113,8 @@
throw new ContextException( key );
}
+ m_deployment = (DeploymentService) context.get( DeploymentService.KEY );
m_context = context;
-
- m_deployment =
- (DeploymentService) context.get( "urn:assembly:lifecycle.deployment" );
-
}
//==============================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org