bloritsch 2002/09/19 10:09:29
Modified: fortress/src/java/org/apache/excalibur/fortress/container
MetaDataContainer.java
Added: fortress/src/java/org/apache/excalibur/fortress/container/commands
CheckTypeInfoCommand.java
CommandFinishedListener.java
Log:
start migration to generic commands and add a CommandFinishedListener
Revision Changes Path
1.5 +26 -108
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/MetaDataContainer.java
Index: MetaDataContainer.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/MetaDataContainer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MetaDataContainer.java 19 Sep 2002 04:07:23 -0000 1.4
+++ MetaDataContainer.java 19 Sep 2002 17:09:29 -0000 1.5
@@ -66,6 +66,7 @@
import org.apache.avalon.framework.service.*;
import org.apache.avalon.framework.logger.*;
+import org.apache.excalibur.fortress.container.commands.*;
import org.apache.excalibur.fortress.*;
import org.apache.excalibur.fortress.handler.*;
import org.apache.excalibur.fortress.lifecycle.*;
@@ -73,7 +74,7 @@
import org.apache.excalibur.container.classloader.*;
import org.apache.excalibur.container.legacy.*;
-import org.apache.excalibur.event.Queue;
+import org.apache.excalibur.event.*;
import org.apache.excalibur.event.command.Command;
import org.apache.excalibur.instrument.Instrumentable;
import org.apache.excalibur.instrument.InstrumentManager;
@@ -96,7 +97,8 @@
*/
public class MetaDataContainer
extends AbstractLogEnabled
- implements Configurable, Contextualizable, Initializable, Disposable,
Serviceable
+ implements Configurable, Contextualizable, Initializable, Disposable,
Serviceable,
+ CommandFinishedListener
{
protected final JarEntries m_jarEntries;
protected Context m_context;
@@ -110,14 +112,24 @@
protected InstrumentManager m_instrumentManager;
protected LifecycleExtensionManager m_extManager;
- protected Map m_services;
- protected Map m_types;
+ protected final Map m_services;
+ protected final Map m_types;
+ protected volatile boolean m_typeInfoChecked;
public MetaDataContainer()
{
m_jarEntries = JarScanner.getSystemJarEntries();
m_services = new HashMap();
m_types = new HashMap();
+ m_typeInfoChecked = false;
+ }
+
+ public void commandCompleted( Command cmd )
+ {
+ if ( cmd instanceof CheckTypeInfoCommand )
+ {
+ m_typeInfoChecked = true;
+ }
}
/**
@@ -166,12 +178,19 @@
try
{
m_commandQueue = (Queue)m_context.get( Container.COMMAND_QUEUE );
+
+ m_commandQueue.enqueue( new CheckTypeInfoCommand( m_jarEntries,
+ m_services, m_types, m_loader, this,
+ getLogger().getChildLogger("type-checker") ) );
}
catch( ContextException ce )
{
- m_commandQueue = null;
getLogger().warn( "No Container.COMMAND_QUEUE is given, all management
will be "
- + "performed synchronously" );
+ + "performed synchronously", ce );
+ }
+ catch( SinkException se )
+ {
+ getLogger().error( "The CommandQueue is unable to enqueue the command",
se );
}
m_instrumentManager = (InstrumentManager)m_context.get(
Container.INSTRUMENT_MANAGER );
@@ -189,107 +208,6 @@
public void initialize() throws Exception
{
- BlockBuilder blockBuilder = new BlockBuilder();
- TypeBuilder typeBuilder = new TypeBuilder();
- ServiceBuilder serviceBuilder = new ServiceBuilder();
- ComponentVerifier verifier = new ComponentVerifier();
-
- blockBuilder.enableLogging( getLogger().getChildLogger( "builder.block" ) );
- typeBuilder.enableLogging( getLogger().getChildLogger( "builder.type" ) );
- serviceBuilder.enableLogging( getLogger().getChildLogger( "builder.service"
) );
- verifier.enableLogging( getLogger().getChildLogger( "verifier" ) );
-
- Iterator it = m_jarEntries.getServiceEntries().iterator();
- while ( it.hasNext() )
- {
- String name = (String) it.next();
- try
- {
- Class service = m_loader.loadClass( name );
- m_services.put( service, serviceBuilder.build( service ) );
- verifier.verifyService( service.getName(), service );
- }
- catch ( Exception e )
- {
- getLogger().debug( "Could not read the descriptor for " + name, e );
- }
- }
-
- it = m_jarEntries.getBlockEntries().iterator();
- while ( it.hasNext() )
- {
- String name = (String) it.next();
- try
- {
- Class block = m_loader.loadClass( name );
- m_types.put( block, blockBuilder.build( block ) );
-
- Type check = (Type) m_types.get( block );
- ServiceDescriptor[] serviceDescriptors = check.getServices();
-
- Class[] services = new Class[ serviceDescriptors.length ];
- for ( int i = 0; i < serviceDescriptors.length; i++ )
- {
- services[i] = m_loader.loadClass(
- serviceDescriptors[i].getService().getClassname()
- );
- }
-
- StageDescriptor[] phaseDescriptors = check.getPhases();
-
- Class[] phases = new Class[ phaseDescriptors.length ];
- for ( int i = 0; i < phaseDescriptors.length; i++ )
- {
- phases[i] = m_loader.loadClass(
- phaseDescriptors[i].getReference().getClassname()
- );
- }
-
- verifier.verifyType( block.getName(), block, services, phases );
- }
- catch ( Exception e )
- {
- getLogger().debug( "Could not read the descriptor for " + name, e );
- }
- }
-
- it = m_jarEntries.getTypeEntries().iterator();
- while ( it.hasNext() )
- {
- String name = (String) it.next();
- try
- {
- Class type = m_loader.loadClass( name );
- m_types.put( type, typeBuilder.build( type ) );
-
- Type check = (Type) m_types.get( type );
- ServiceDescriptor[] serviceDescriptors = check.getServices();
-
- Class[] services = new Class[ serviceDescriptors.length ];
- for ( int i = 0; i < serviceDescriptors.length; i++ )
- {
- services[i] = m_loader.loadClass(
- serviceDescriptors[i].getService().getClassname()
- );
- }
-
- StageDescriptor[] phaseDescriptors = check.getPhases();
-
- Class[] phases = new Class[ phaseDescriptors.length ];
- for ( int i = 0; i < phaseDescriptors.length; i++ )
- {
- phases[i] = m_loader.loadClass(
- phaseDescriptors[i].getReference().getClassname()
- );
- }
-
- verifier.verifyType( type.getName(), type, services, phases );
- }
- catch ( Exception e )
- {
- getLogger().debug( "Could not read the descriptor for " + name, e );
- }
- }
}
public void dispose()
1.1
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/commands/CheckTypeInfoCommand.java
Index: CheckTypeInfoCommand.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ 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.excalibur.fortress.container.commands;
import java.util.Iterator;
import java.util.Map;
import org.apache.avalon.framework.logger.*;
import org.apache.excalibur.event.command.Command;
import org.apache.excalibur.container.classloader.JarEntries;
import org.apache.excalibur.meta.info.*;
import org.apache.excalibur.meta.info.builder.*;
import org.apache.excalibur.meta.verifier.*;
/**
* Execute this command to verify all the entries in a @link{JarEntries} object.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/09/19 17:09:29 $
*/
public final class CheckTypeInfoCommand implements Command
{
private final JarEntries m_jarEntries;
private final Map m_services;
private final Map m_types;
private final ClassLoader m_loader;
private final CommandFinishedListener m_listener;
private final Logger m_logger;
public CheckTypeInfoCommand(JarEntries entries,
Map services,
Map types,
ClassLoader loader,
CommandFinishedListener listener,
Logger logger)
{
if ( null == entries ||
null == services ||
null == types ||
null == loader ||
null == listener )
{
throw new NullPointerException( "All arguments must be supplied to the
CheckTypeInfoCommand" );
}
m_jarEntries = entries;
m_services = services;
m_types = types;
m_loader = loader;
m_listener = listener;
m_logger = ( null == logger ) ? new NullLogger() : logger;
}
public void execute()
throws Exception
{
BlockBuilder blockBuilder = new BlockBuilder();
TypeBuilder typeBuilder = new TypeBuilder();
ServiceBuilder serviceBuilder = new ServiceBuilder();
ComponentVerifier verifier = new ComponentVerifier();
blockBuilder.enableLogging( getLogger().getChildLogger( "builder.block" ) );
typeBuilder.enableLogging( getLogger().getChildLogger( "builder.type" ) );
serviceBuilder.enableLogging( getLogger().getChildLogger( "builder.service"
) );
verifier.enableLogging( getLogger().getChildLogger( "verifier" ) );
Iterator it = m_jarEntries.getServiceEntries().iterator();
while ( it.hasNext() )
{
String name = (String) it.next();
try
{
Class service = m_loader.loadClass( name );
m_services.put( service, serviceBuilder.build( service ) );
verifier.verifyService( service.getName(), service );
}
catch ( Exception e )
{
getLogger().debug( "Could not read the descriptor for " + name, e );
}
}
it = m_jarEntries.getBlockEntries().iterator();
while ( it.hasNext() )
{
String name = (String) it.next();
try
{
Class block = m_loader.loadClass( name );
m_types.put( block, blockBuilder.build( block ) );
Type check = (Type) m_types.get( block );
ServiceDescriptor[] serviceDescriptors = check.getServices();
Class[] services = new Class[ serviceDescriptors.length ];
for ( int i = 0; i < serviceDescriptors.length; i++ )
{
services[i] = m_loader.loadClass(
serviceDescriptors[i].getService().getClassname()
);
}
StageDescriptor[] phaseDescriptors = check.getPhases();
Class[] phases = new Class[ phaseDescriptors.length ];
for ( int i = 0; i < phaseDescriptors.length; i++ )
{
phases[i] = m_loader.loadClass(
phaseDescriptors[i].getReference().getClassname()
);
}
verifier.verifyType( block.getName(), block, services, phases );
}
catch ( Exception e )
{
getLogger().debug( "Could not read the descriptor for " + name, e );
}
}
it = m_jarEntries.getTypeEntries().iterator();
while ( it.hasNext() )
{
String name = (String) it.next();
try
{
Class type = m_loader.loadClass( name );
m_types.put( type, typeBuilder.build( type ) );
Type check = (Type) m_types.get( type );
ServiceDescriptor[] serviceDescriptors = check.getServices();
Class[] services = new Class[ serviceDescriptors.length ];
for ( int i = 0; i < serviceDescriptors.length; i++ )
{
services[i] = m_loader.loadClass(
serviceDescriptors[i].getService().getClassname()
);
}
StageDescriptor[] phaseDescriptors = check.getPhases();
Class[] phases = new Class[ phaseDescriptors.length ];
for ( int i = 0; i < phaseDescriptors.length; i++ )
{
phases[i] = m_loader.loadClass(
phaseDescriptors[i].getReference().getClassname()
);
}
verifier.verifyType( type.getName(), type, services, phases );
}
catch ( Exception e )
{
getLogger().debug( "Could not read the descriptor for " + name, e );
}
}
m_listener.commandCompleted( this );
}
private final Logger getLogger()
{
return m_logger;
}
}
1.1
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/commands/CommandFinishedListener.java
Index: CommandFinishedListener.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ 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.excalibur.fortress.container.commands;
import org.apache.excalibur.event.command.Command;
/**
* Implement this interface so that a Command object can let the listener know
* when it has been completed.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/09/19 17:09:29 $
*/
public interface CommandFinishedListener
{
void commandCompleted( Command arg );
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>