bloritsch 2003/05/27 11:39:48
Modified: fortress/src/java/org/apache/avalon/fortress/impl
AbstractContainer.java DefaultContainerManager.java
fortress/src/java/org/apache/avalon/fortress/util
ContextManager.java
Added: fortress/src/java/org/apache/avalon/fortress/impl/lookup
NoopServiceManager.java
Log:
apply partial of Patch #9 from Anton Tagunov
Revision Changes Path
1.29 +43 -90
avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java
Index: AbstractContainer.java
===================================================================
RCS file:
/home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- AbstractContainer.java 20 May 2003 20:26:08 -0000 1.28
+++ AbstractContainer.java 27 May 2003 18:39:46 -0000 1.29
@@ -53,19 +53,19 @@
import org.apache.avalon.fortress.Container;
import org.apache.avalon.fortress.MetaInfoEntry;
import org.apache.avalon.fortress.MetaInfoManager;
-import org.apache.avalon.fortress.RoleManager;
import org.apache.avalon.fortress.impl.extensions.InstrumentableCreator;
-import org.apache.avalon.fortress.impl.handler.*;
-import org.apache.avalon.fortress.impl.lookup.FortressServiceManager;
-import org.apache.avalon.fortress.impl.lookup.FortressServiceSelector;
-import org.apache.avalon.fortress.impl.role.FortressRoleManager;
-import org.apache.avalon.fortress.impl.role.Role2MetaInfoManager;
-import org.apache.avalon.fortress.impl.role.ServiceMetaManager;
import org.apache.avalon.fortress.impl.factory.ProxyManager;
import org.apache.avalon.fortress.impl.handler.ComponentFactory;
+import org.apache.avalon.fortress.impl.handler.ComponentHandler;
+import org.apache.avalon.fortress.impl.handler.LEAwareComponentHandler;
+import org.apache.avalon.fortress.impl.handler.PrepareHandlerCommand;
+import org.apache.avalon.fortress.impl.lookup.FortressServiceManager;
+import org.apache.avalon.fortress.impl.lookup.FortressServiceSelector;
import org.apache.avalon.fortress.util.CompositeException;
import org.apache.avalon.fortress.util.LifecycleExtensionManager;
-import org.apache.avalon.fortress.util.dag.*;
+import org.apache.avalon.fortress.util.dag.CyclicDependencyException;
+import org.apache.avalon.fortress.util.dag.DirectedAcyclicGraphVerifier;
+import org.apache.avalon.fortress.util.dag.Vertex;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configuration;
@@ -186,15 +186,47 @@
// get optional services, or a default if the service isn't provided
+ setupExtensionManager( serviceManager );
+
+ if ( serviceManager.hasService( Queue.ROLE ) )
+ {
+ m_commandQueue = (Queue) serviceManager.lookup( Queue.ROLE );
+ }
+ else
+ {
+ final String message =
+ "No " + Queue.ROLE + " is given, all " +
+ "management will be performed synchronously";
+ getLogger().warn( message );
+ }
+
+ m_metaManager = (MetaInfoManager) serviceManager.lookup(
MetaInfoManager.ROLE );
+
+ // set up our ServiceManager
+ m_serviceManager = new FortressServiceManager( this, serviceManager );
+ }
+
+ /**
+ * Set up the Lifecycle Extension Manager.
+ *
+ * @param serviceManager The serviceManager we are using to determine if the
extension manager is being passed.
+ * @throws ServiceException if the ServiceManager does not live up to its
contract.
+ */
+ private void setupExtensionManager( final ServiceManager serviceManager )
throws ServiceException
+ {
+ final Logger extLogger = m_loggerManager.getLoggerForCategory(
"system.extensions" );
if ( serviceManager.hasService( LifecycleExtensionManager.ROLE ) )
{
m_extManager =
(LifecycleExtensionManager) serviceManager.lookup(
LifecycleExtensionManager.ROLE );
+
+ extLogger.debug( "Found the LifecycleExtensionManager" );
}
else
{
m_extManager = new LifecycleExtensionManager();
- m_extManager.enableLogging( getLogger() );
+ m_extManager.enableLogging( extLogger );
+ m_extManager.addCreatorExtension( new InstrumentableCreator(
m_instrumentManager ) );
if ( getLogger().isDebugEnabled() )
{
@@ -221,88 +253,9 @@
if ( !isInstrumentEnabled )
{
+ extLogger.debug("No Instrumentable Creator was found. We are adding a
new one.");
m_extManager.addCreatorExtension( new InstrumentableCreator(
m_instrumentManager ) );
}
-
- if ( serviceManager.hasService( Queue.ROLE ) )
- {
- m_commandQueue = (Queue) serviceManager.lookup( Queue.ROLE );
- }
- else
- {
- final String message =
- "No Container.COMMAND_QUEUE is given, all " +
- "management will be performed synchronously";
- getLogger().warn( message );
- }
-
- try
- {
- if ( serviceManager.hasService( MetaInfoManager.ROLE ) )
- {
- m_metaManager = (MetaInfoManager) serviceManager.lookup(
MetaInfoManager.ROLE );
-
- if ( serviceManager.hasService( RoleManager.ROLE ) )
- {
- getLogger().warn( "MetaInfoManager found, ignoring RoleManager"
);
- }
- }
- else if ( serviceManager.hasService( RoleManager.ROLE ) )
- {
- m_metaManager = createMetaManager(
- new Role2MetaInfoManager(
- (RoleManager) serviceManager.lookup( RoleManager.ROLE ) ) );
- }
- else
- {
- m_metaManager = createDefaultMetaManager();
- }
- }
- catch ( ServiceException se )
- {
- throw se;
- }
- catch ( Exception e )
- {
- final String message = "Unable to create default role manager";
- throw new ServiceException( MetaInfoManager.ROLE, message, e );
- }
-
- // set up our ServiceManager
- m_serviceManager = new FortressServiceManager( this, serviceManager );
- }
-
- /**
- * Create a default RoleManager that can be used to addRole system.
- *
- * @return the default role manager
- * @throws Exception if unable to create role manager
- */
- private MetaInfoManager createDefaultMetaManager()
- throws Exception
- {
- final FortressRoleManager roleManager =
- new FortressRoleManager( null, m_classLoader );
- ContainerUtil.enableLogging( roleManager, getLogger().getChildLogger(
"roles" ) );
- ContainerUtil.initialize( roleManager );
- return createMetaManager( new Role2MetaInfoManager( roleManager ) );
- }
-
- /**
- * Create a default RoleManager that can be used to addRole system.
- *
- * @return the default role manager
- * @throws Exception if unable to create role manager
- */
- private ServiceMetaManager createMetaManager( final MetaInfoManager root )
- throws Exception
- {
- final ServiceMetaManager metaManager =
- new ServiceMetaManager( root, m_classLoader );
- final Logger mmLogger = m_loggerManager.getLoggerForCategory( "system.meta"
);
- ContainerUtil.enableLogging( metaManager, mmLogger );
- ContainerUtil.initialize( metaManager );
- return metaManager;
}
/**
1.20 +4 -6
avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/DefaultContainerManager.java
Index: DefaultContainerManager.java
===================================================================
RCS file:
/home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/DefaultContainerManager.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- DefaultContainerManager.java 23 May 2003 17:31:20 -0000 1.19
+++ DefaultContainerManager.java 27 May 2003 18:39:47 -0000 1.20
@@ -50,9 +50,7 @@
package org.apache.avalon.fortress.impl;
import org.apache.avalon.excalibur.logger.LoggerManager;
-import org.apache.avalon.fortress.InitializationException;
-import org.apache.avalon.fortress.MetaInfoManager;
-import org.apache.avalon.fortress.RoleManager;
+import org.apache.avalon.fortress.*;
import org.apache.avalon.fortress.util.ContextManager;
import org.apache.avalon.fortress.util.LifecycleExtensionManager;
import org.apache.avalon.framework.activity.Disposable;
@@ -63,8 +61,8 @@
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.logger.ConsoleLogger;
-import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.Loggable;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.DefaultServiceManager;
import org.apache.avalon.framework.service.ServiceManager;
@@ -81,7 +79,7 @@
* @version CVS $Revision$ $Date$
*/
public class DefaultContainerManager
- implements Initializable, Disposable,
org.apache.avalon.fortress.ContainerManager,
org.apache.avalon.fortress.ContainerManagerConstants
+ implements Initializable, Disposable, ContainerManager,
ContainerManagerConstants
{
private final ContextManager m_contextManager;
private final Logger m_logger;
1.1
avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/lookup/NoopServiceManager.java
Index: NoopServiceManager.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 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", "Avalon", "Excalibur" 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
[EMAIL PROTECTED]
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.fortress.impl.lookup;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceException;
/**
* No-op ServiceManager contains no components, and is used when we don't want to
allow a component to access other
* components.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version CVS $ Revision: 1.1 $
*/
public class NoopServiceManager implements ServiceManager
{
private static final String MESSAGE = "Could not return a reference to the
Component";
public Object lookup( String role ) throws ServiceException
{
throw new ServiceException(role, MESSAGE);
}
public boolean hasService( String role )
{
return false;
}
public void release( Object component )
{
// Do nothing
}
}
1.29 +78 -15
avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/util/ContextManager.java
Index: ContextManager.java
===================================================================
RCS file:
/home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/util/ContextManager.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- ContextManager.java 22 May 2003 14:44:04 -0000 1.28
+++ ContextManager.java 27 May 2003 18:39:47 -0000 1.29
@@ -52,8 +52,11 @@
import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.apache.avalon.fortress.RoleManager;
+import org.apache.avalon.fortress.MetaInfoManager;
import org.apache.avalon.fortress.impl.role.ConfigurableRoleManager;
import org.apache.avalon.fortress.impl.role.FortressRoleManager;
+import org.apache.avalon.fortress.impl.role.ServiceMetaManager;
+import org.apache.avalon.fortress.impl.role.Role2MetaInfoManager;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configuration;
@@ -196,7 +199,14 @@
// warning or error messages. However in most cases, the debug
// information should not be displayed, so turn it off by default.
// Unfortunately, there is not a very good place to make this settable.
- m_primordialLogger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
+ if ( m_logger == null )
+ {
+ m_primordialLogger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
+ }
+ else
+ {
+ m_primordialLogger = null;
+ }
}
/**
@@ -229,7 +239,7 @@
{
initializeServiceManager();
initializeLoggerManager();
- initializeRoleManager();
+ initializeMetaInfoManager();
initializeCommandQueue();
initializePoolManager();
initializeContext();
@@ -300,16 +310,19 @@
}
/**
- * Checks if a specified entry in <code>rootContext</code>
+ * Checks if a specified entry in <code>context</code>
* has been supplied by the invoker.
+ *
+ * @param context The context to check
+ * @param key The key name to check
*/
- protected boolean entryPresent( final String key )
+ protected boolean entryPresent( Context context, final String key )
{
boolean isPresent = false;
try
{
- m_rootContext.get( key );
+ context.get( key );
isPresent = true;
}
catch( ContextException ce )
@@ -492,14 +505,25 @@
*
* @throws Exception if there is an error.
*/
- protected void initializeRoleManager() throws Exception
+ protected RoleManager obtainRoleManager() throws Exception
{
/* we don't want an error message from getConfiguration, so
* check if there is job to do first
*/
- if ( entryPresent(RoleManager.ROLE) ) return;
- if ( !entryPresent( ROLE_MANAGER_CONFIGURATION ) &&
- !entryPresent( ROLE_MANAGER_CONFIGURATION_URI ) ) return;
+ if ( entryPresent( m_rootContext, RoleManager.ROLE) )
+ {
+ /* RoleManager is a compatibility mechanism to read in ECM roles files.
The role manager will be wrapped
+ * by a MetaInfoManager. So we hide the RoleManager here from the
contaienr implementation.
+ */
+ m_childContext.put( RoleManager.ROLE, null );
+ return (RoleManager)m_rootContext.get( RoleManager.ROLE );
+ }
+
+ if ( !entryPresent( m_rootContext, ROLE_MANAGER_CONFIGURATION ) &&
+ !entryPresent( m_rootContext, ROLE_MANAGER_CONFIGURATION_URI ) )
+ {
+ return null;
+ }
Configuration roleConfig =
getConfiguration( ROLE_MANAGER_CONFIGURATION,
ROLE_MANAGER_CONFIGURATION_URI );
@@ -507,19 +531,19 @@
if ( roleConfig == null )
{
// Something went wrong, but the error has already been reported
- return;
+ return null;
}
// Get the context Logger Manager
final LoggerManager loggerManager = (LoggerManager) m_childContext.get(
LoggerManager.ROLE );
+ // Lookup the context class loader
+ final ClassLoader classLoader = (ClassLoader) m_rootContext.get(
ClassLoader.class.getName() );
+
// Create a logger for the role manager
final Logger rmLogger = loggerManager.getLoggerForCategory(
roleConfig.getAttribute( "logger", "system.roles" ) );
- // Lookup the context class loader
- final ClassLoader classLoader = (ClassLoader) m_rootContext.get(
ClassLoader.class.getName() );
-
// Create a parent role manager with all the default roles
final FortressRoleManager frm = new FortressRoleManager( null, classLoader
);
frm.enableLogging( rmLogger.getChildLogger( "defaults" ) );
@@ -531,7 +555,45 @@
rm.configure( roleConfig );
assumeOwnership( rm );
- m_childContext.put( RoleManager.ROLE, rm );
+ return rm;
+ }
+
+ protected void initializeMetaInfoManager() throws Exception
+ {
+ final boolean mmSupplied = entryPresent( m_rootContext,
MetaInfoManager.ROLE );
+ RoleManager roleManager = obtainRoleManager();
+ final boolean rmSupplied = roleManager != null;
+
+ if ( mmSupplied )
+ {
+ if ( rmSupplied )
+ {
+ getLogger().warn( "MetaInfoManager found, ignoring RoleManager" );
+ }
+
+ // Otherwise everything is ok, and we continue on (i.e. return)
+ }
+ else
+ {
+ final LoggerManager loggerManager = (LoggerManager)m_childContext.get(
LoggerManager.ROLE );
+ final ClassLoader classLoader = (ClassLoader)m_rootContext.get(
ClassLoader.class.getName() );
+
+ if ( ! rmSupplied )
+ {
+ final FortressRoleManager newRoleManager = new FortressRoleManager(
null, classLoader );
+
newRoleManager.enableLogging(loggerManager.getLoggerForCategory("system.roles"));
+ newRoleManager.initialize();
+
+ roleManager = newRoleManager;
+ }
+
+ final ServiceMetaManager metaManager = new ServiceMetaManager( new
Role2MetaInfoManager( roleManager ), classLoader );
+
+ metaManager.enableLogging(
loggerManager.getLoggerForCategory("system.meta") );
+ metaManager.initialize();
+ assumeOwnership( metaManager );
+ m_childContext.put( MetaInfoManager.ROLE, metaManager );
+ }
}
/**
@@ -817,6 +879,7 @@
if ( obj instanceof CommandManager ) retVal = 0;
if ( obj instanceof ThreadManager ) retVal = 2;
+ if ( obj instanceof LoggerManager ) retVal = 3;
return retVal;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]