You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by ha...@apache.org on 2004/07/05 18:58:16 UTC
svn commit: rev 22600 - in excalibur/branches/fortress-experiments: container-api/src/java/org/apache/avalon/fortress container-impl/src/java/org/apache/avalon/fortress/impl container-impl/src/java/org/apache/avalon/fortress/impl/handler container-test/src/test/org/apache/avalon/fortress/impl/lookup/test container-test/src/test/org/apache/avalon/fortress/test
Author: hammett
Date: Mon Jul 5 09:58:15 2004
New Revision: 22600
Added:
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultEventManager.java (contents, props changed)
excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/test/EventsTestCase.java (contents, props changed)
Modified:
excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/ContainerListener.java
excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/EventManager.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultECMContainer.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java
excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/impl/lookup/test/FortressServiceManagerTestCase.java
Log:
Event infrastructure.
Modified: excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/ContainerListener.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/ContainerListener.java (original)
+++ excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/ContainerListener.java Mon Jul 5 09:58:15 2004
@@ -18,25 +18,27 @@
package org.apache.avalon.fortress;
/**
- * Pending
+ * Listener to allow hooks into Container
*
+ * @author <a href="mailto:dev@excalibur.apache.org">Excalibur Team</a>
*/
public interface ContainerListener
{
/**
- * Pending
+ * Signalizes that a component instance has been created.
+ * The original or a wrapped instance must be returned by the implementation
*
- * @param entry
- * @param instance
- * @return
+ * @param entry Collection of information about the component
+ * @param instance The created instance
+ * @return the old or new instance
*/
Object componentCreated( MetaInfoEntry entry, Object instance );
/**
- * Pending
+ * Signalizes that a component instance has been destroyed.
*
- * @param entry
- * @param instance
+ * @param entry Collection of information about the component
+ * @param instance The instance being destroyed
*/
void componentDestroyed( MetaInfoEntry entry, Object instance );
}
Modified: excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/EventManager.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/EventManager.java (original)
+++ excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/EventManager.java Mon Jul 5 09:58:15 2004
@@ -18,29 +18,41 @@
package org.apache.avalon.fortress;
/**
- * Pending
+ * Holds the events subscribers and allows the container to
+ * raise the events.
*
+ * @author <a href="mailto:dev@excalibur.apache.org">Excalibur Team</a>
*/
public interface EventManager
{
+ /**
+ * Adds an event subscriber
+ *
+ * @param listener ContainerListener implementation
+ */
void addListener( ContainerListener listener );
+ /**
+ * Removes an event subscriber
+ *
+ * @param listener ContainerListener implementation
+ */
void removeListener( ContainerListener listener );
/**
- * Pending
+ * Raises the ComponentCreated event to susbcribers
*
- * @param newInstance
- * @return
+ * @param entry Collection of information about the component
+ * @param newInstance instance that has been created.
+ * @return the instance itself or a wrapped one
*/
- Object fireComponentCreated(Object newInstance);
+ Object fireComponentCreated( MetaInfoEntry entry, Object newInstance );
/**
- * Pending
+ * Raises the ComponentDestroyed event to susbcribers
*
- * @param newInstance
+ * @param entry Collection of information about the component
+ * @param newInstance instance that has been released.
*/
- void fireComponentDestroyed(Object newInstance);
-
-
+ void fireComponentDestroyed( MetaInfoEntry entry, Object newInstance );
}
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java Mon Jul 5 09:58:15 2004
@@ -19,6 +19,7 @@
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.apache.avalon.fortress.Container;
+import org.apache.avalon.fortress.EventManager;
import org.apache.avalon.fortress.MetaInfoEntry;
import org.apache.avalon.fortress.MetaInfoManager;
import org.apache.avalon.fortress.impl.extensions.InstrumentableCreator;
@@ -109,6 +110,8 @@
protected List m_components = new ArrayList( 10 );
protected List m_shutDownOrder;
+
+ protected EventManager m_eventManager;
private ProxyManager m_proxyManager;
@@ -162,6 +165,21 @@
{
m_classLoader = Thread.currentThread().getContextClassLoader();
}
+ }
+
+ /**
+ * Pending
+ *
+ * @return
+ */
+ public EventManager getEventManager()
+ {
+ if (m_eventManager == null)
+ {
+ m_eventManager = new DefaultEventManager();
+ }
+
+ return m_eventManager;
}
/**
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultECMContainer.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultECMContainer.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultECMContainer.java Mon Jul 5 09:58:15 2004
@@ -39,37 +39,42 @@
* @author <a href="mailto:dev@avalon.apache.org">The Avalon Team</a>
* @version CVS $ Revision: 1.1 $
*/
-public class DefaultECMContainer extends DefaultContainer {
-
+public class DefaultECMContainer extends DefaultContainer
+{
/**
* Retrieve the role for the component.
*
* @param config the component configuration
* @return the class name
*/
- private String getRole( final Configuration config )
- throws ConfigurationException {
+ private String getRole(final Configuration config) throws ConfigurationException
+ {
final String className;
- if ( "component".equals( config.getName() ) )
+ if ("component".equals(config.getName()))
{
- className = config.getAttribute( "role" );
+ className = config.getAttribute("role");
}
else
{
- final MetaInfoEntry roleEntry = m_metaManager.getMetaInfoForShortName( config.getName() );
- if ( null == roleEntry )
+ final MetaInfoEntry roleEntry = m_metaManager.getMetaInfoForShortName(config.getName());
+ if (null == roleEntry)
{
- final String message = "No class found matching configuration name " +
- "[name: " + config.getName() + ", location: " + config.getLocation() + "]";
- throw new ConfigurationException( message );
+ final String message =
+ "No class found matching configuration name "
+ + "[name: "
+ + config.getName()
+ + ", location: "
+ + config.getLocation()
+ + "]";
+ throw new ConfigurationException(message);
}
Iterator roleIterator = roleEntry.getRoles();
- if ( roleIterator.hasNext() )
+ if (roleIterator.hasNext())
{
- className = (String)roleIterator.next();
+ className = (String) roleIterator.next();
}
else
{
@@ -86,29 +91,34 @@
* @param config the component configuration
* @return the class name
*/
- protected String getClassname( final Configuration config )
- throws ConfigurationException {
+ protected String getClassname(final Configuration config) throws ConfigurationException
+ {
final String className;
- if ( "component".equals( config.getName() ) )
+ if ("component".equals(config.getName()))
{
- className = config.getAttribute( "class" );
+ className = config.getAttribute("class");
}
else
{
- if ( config.getAttribute("class", null) != null )
+ if (config.getAttribute("class", null) != null)
{
className = config.getAttribute("class");
}
else
{
- final MetaInfoEntry roleEntry = m_metaManager.getMetaInfoForShortName( config.getName() );
- if ( null == roleEntry )
+ final MetaInfoEntry roleEntry = m_metaManager.getMetaInfoForShortName(config.getName());
+ if (null == roleEntry)
{
- final String message = "No class found matching configuration name " +
- "[name: " + config.getName() + ", location: " + config.getLocation() + "]";
- throw new ConfigurationException( message );
+ final String message =
+ "No class found matching configuration name "
+ + "[name: "
+ + config.getName()
+ + ", location: "
+ + config.getLocation()
+ + "]";
+ throw new ConfigurationException(message);
}
className = roleEntry.getComponentClass().getName();
@@ -124,32 +134,31 @@
* @param conf The configuration
* @throws ConfigurationException if the coniguration is invalid
*/
- public void configure( Configuration conf )
- throws ConfigurationException {
- this.interpretProxy( conf.getAttribute("proxy-type", this.getDefaultProxyType()) );
+ public void configure(Configuration conf) throws ConfigurationException
+ {
+ interpretProxy(conf.getAttribute("proxy-type", this.getDefaultProxyType()));
final Configuration[] elements = conf.getChildren();
- for ( int i = 0; i < elements.length; i++ )
+ for (int i = 0; i < elements.length; i++)
{
final Configuration element = elements[i];
// figure out Role
- String role = getRole( element );
- if ( role.endsWith("Selector") )
+ String role = getRole(element);
+ if (role.endsWith("Selector"))
{
- processSelector(role.substring(0, role.length()-8), element );
+ processSelector(role.substring(0, role.length() - 8), element);
}
else
{
-
// get the implementation
- final String className = getClassname( element );
+ final String className = getClassname(element);
final int pos = role.indexOf('/');
final String hint;
- if ( pos != -1 )
+ if (pos != -1)
{
- hint = role.substring(pos+1);
+ hint = role.substring(pos + 1);
role = role.substring(0, pos);
}
else
@@ -158,7 +167,7 @@
}
final String shortName;
- if ( "component".equals( element.getName() ))
+ if ("component".equals(element.getName()))
{
shortName = null;
}
@@ -167,12 +176,12 @@
shortName = element.getName();
}
- this.addComponent(role, hint, shortName, className, element );
+ this.addComponent(role, hint, shortName, className, element);
}
- if ( getLogger().isDebugEnabled() )
+ if (getLogger().isDebugEnabled())
{
- getLogger().debug( "Configuration processed for: " + role );
+ getLogger().debug("Configuration processed for: " + role);
}
}
}
@@ -186,10 +195,11 @@
* @return the component handler
* @throws Exception if unable to provide a componenthandler
*/
- private ComponentHandler getComponentHandler( final String classname,
- final Class handlerClass,
- final ComponentHandlerMetaData metaData)
- throws Exception
+ private ComponentHandler getComponentHandler(
+ final String classname,
+ final Class handlerClass,
+ final ComponentHandlerMetaData metaData)
+ throws Exception
{
final Configuration configuration = metaData.getConfiguration();
@@ -198,150 +208,141 @@
try
{
- final ObjectFactory factory =
- createObjectFactory( classname, configuration );
+ final ObjectFactory factory = createObjectFactory(classname, configuration, null);
// create the appropriate handler instance
- final ComponentHandler targetHandler =
- (ComponentHandler) handlerClass.newInstance();
+ final ComponentHandler targetHandler = (ComponentHandler) handlerClass.newInstance();
// do the handler lifecycle
- ContainerUtil.enableLogging( targetHandler, getLogger() );
- ContainerUtil.contextualize( targetHandler, m_context );
- final DefaultServiceManager serviceManager =
- new DefaultServiceManager( getServiceManager() );
- serviceManager.put( ObjectFactory.class.getName(), factory );
+ ContainerUtil.enableLogging(targetHandler, getLogger());
+ ContainerUtil.contextualize(targetHandler, m_context);
+ final DefaultServiceManager serviceManager = new DefaultServiceManager(getServiceManager());
+ serviceManager.put(ObjectFactory.class.getName(), factory);
serviceManager.makeReadOnly();
- ContainerUtil.service( targetHandler, serviceManager );
- ContainerUtil.configure( targetHandler, configuration );
- ContainerUtil.initialize( targetHandler );
+ ContainerUtil.service(targetHandler, serviceManager);
+ ContainerUtil.configure(targetHandler, configuration);
+ ContainerUtil.initialize(targetHandler);
- if ( targetHandler instanceof Instrumentable )
+ if (targetHandler instanceof Instrumentable)
{
final Instrumentable instrumentable = (Instrumentable) targetHandler;
final String name = instrumentable.getInstrumentableName();
- m_instrumentManager.registerInstrumentable( instrumentable, name );
+ m_instrumentManager.registerInstrumentable(instrumentable, name);
}
// no other lifecycle stages supported for ComponentHandler;
// ComponentHandler is not a "true" avalon component
- handler = new LEAwareComponentHandler( targetHandler, m_extManager, m_context );
+ handler = new LEAwareComponentHandler(targetHandler, m_extManager, m_context);
}
- catch ( final Exception e )
+ catch (final Exception e)
{
// if anything went wrong, the component cannot be worked with
// and it cannot be added into the impl, so don't provide
// a handler
- if ( getLogger().isDebugEnabled() )
+ if (getLogger().isDebugEnabled())
{
- final String message =
- "Could not create the handler for the '" +
- classname + "' component.";
- getLogger().debug( message, e );
+ final String message = "Could not create the handler for the '" + classname + "' component.";
+ getLogger().debug(message, e);
}
throw e;
}
- if ( getLogger().isDebugEnabled() )
+ if (getLogger().isDebugEnabled())
{
- final String message =
- "Component " + classname +
- " uses handler " + handlerClass.getName();
- getLogger().debug( message );
+ final String message = "Component " + classname + " uses handler " + handlerClass.getName();
+ getLogger().debug(message);
}
// we're still here, so everything went smooth. Register the handler
// and return it
- final ComponentHandlerEntry entry =
- new ComponentHandlerEntry( handler, metaData );
- m_components.add( entry );
+ final ComponentHandlerEntry entry = new ComponentHandlerEntry(handler, metaData);
+ m_components.add(entry);
return handler;
}
- protected Class getComponentHandlerClass(final String defaultClassName, final String shortName )
- throws Exception
+ protected Class getComponentHandlerClass(final String defaultClassName, final String shortName) throws Exception
{
- if ( shortName == null )
+ if (shortName == null)
{
String handlerClassName = null;
Class clazz;
try
{
- clazz = m_classLoader.loadClass( defaultClassName );
+ clazz = m_classLoader.loadClass(defaultClassName);
- if ( ThreadSafe.class.isAssignableFrom( clazz ) )
+ if (ThreadSafe.class.isAssignableFrom(clazz))
{
handlerClassName = MetaInfoEntry.THREADSAFE_HANDLER;
}
- else if ( Service.isClassPoolable(clazz) )
+ else if (Service.isClassPoolable(clazz))
{
handlerClassName = MetaInfoEntry.POOLABLE_HANDLER;
}
- else if ( SingleThreaded.class.isAssignableFrom( clazz) )
+ else if (SingleThreaded.class.isAssignableFrom(clazz))
{
handlerClassName = MetaInfoEntry.FACTORY_HANDLER;
}
}
- catch ( final Exception e )
+ catch (final Exception e)
{
- final String message =
- "Unable to load class " + defaultClassName + ". Using dfault component handler.";
- getLogger().warn( message );
+ final String message = "Unable to load class " + defaultClassName + ". Using dfault component handler.";
+ getLogger().warn(message);
}
// Don't know, use default
- if ( handlerClassName == null )
+ if (handlerClassName == null)
{
handlerClassName = MetaInfoEntry.THREADSAFE_HANDLER;
}
- return m_classLoader.loadClass( handlerClassName ) ;
+ return m_classLoader.loadClass(handlerClassName);
}
else
{
- final MetaInfoEntry roleEntry = m_metaManager.getMetaInfoForShortName( shortName );
- if ( null == roleEntry )
+ final MetaInfoEntry roleEntry = m_metaManager.getMetaInfoForShortName(shortName);
+ if (null == roleEntry)
{
- final String message = "No class found matching configuration name " +
- "[name: " + shortName + "]";
- throw new ConfigurationException( message );
+ final String message = "No class found matching configuration name " + "[name: " + shortName + "]";
+ throw new ConfigurationException(message);
}
return roleEntry.getHandlerClass();
}
}
- protected void processSelector(String role, Configuration config)
- throws ConfigurationException
+ protected void processSelector(String role, Configuration config) throws ConfigurationException
{
final String selectorRole = role + "Selector";
FortressServiceSelector fss = new FortressServiceSelector(this, selectorRole);
Map hintMap = createHintMap();
- hintMap.put( DEFAULT_ENTRY, fss );
- hintMap.put( SELECTOR_ENTRY,
- new FortressServiceSelector( this, selectorRole ) );
- m_mapper.put( selectorRole, hintMap );
+ hintMap.put(DEFAULT_ENTRY, fss);
+ hintMap.put(SELECTOR_ENTRY, new FortressServiceSelector(this, selectorRole));
+ m_mapper.put(selectorRole, hintMap);
final Configuration[] children = config.getChildren();
- if ( children != null )
+ if (children != null)
{
- for(int i=0; i<children.length; i++)
+ for (int i = 0; i < children.length; i++)
{
final Configuration element = children[i];
final String hint = element.getAttribute("name");
final String className = element.getAttribute("class");
- if ( m_metaManager instanceof ECMMetaInfoManager )
+ if (m_metaManager instanceof ECMMetaInfoManager)
{
try
{
- ((ECMMetaInfoManager)m_metaManager).addSelectorComponent(role, hint, className, getComponentHandlerClass(className, null).getName());
+ ((ECMMetaInfoManager) m_metaManager).addSelectorComponent(
+ role,
+ hint,
+ className,
+ getComponentHandlerClass(className, null).getName());
}
- catch (ConfigurationException ce )
+ catch (ConfigurationException ce)
{
throw ce;
}
@@ -350,75 +351,71 @@
throw new ConfigurationException("Unable to add selector component.", e);
}
}
- addComponent(role, hint, null, className, element );
+ addComponent(role, hint, null, className, element);
}
}
}
- protected void addComponent(final String role,
- String hint,
- String shortName,
- final String className,
- final Configuration element)
+ protected void addComponent(
+ final String role,
+ String hint,
+ String shortName,
+ final String className,
+ final Configuration element)
throws ConfigurationException
{
final int activation = ComponentHandlerMetaData.ACTIVATION_BACKGROUND;
// Fortress requires a hint, so we just give it one :) (if missing)
- final String metaDataHint = element.getAttribute( "id", element.getLocation() );
+ final String metaDataHint = element.getAttribute("id", element.getLocation());
- if ( hint == null )
+ if (hint == null)
{
hint = metaDataHint;
}
final ComponentHandlerMetaData metaData =
- new ComponentHandlerMetaData( metaDataHint, className, element, activation );
+ new ComponentHandlerMetaData(metaDataHint, className, element, activation);
try
{
-
- if ( DEFAULT_ENTRY.equals( metaData.getName() ) ||
- SELECTOR_ENTRY.equals( metaData.getName() ) )
+ if (DEFAULT_ENTRY.equals(metaData.getName()) || SELECTOR_ENTRY.equals(metaData.getName()))
{
- throw new IllegalArgumentException( "Using a reserved id name" + metaData.getName() );
+ throw new IllegalArgumentException("Using a reserved id name" + metaData.getName());
}
// create a handler for the combo of Role+MetaData
final ComponentHandler handler =
- getComponentHandler( className,
- getComponentHandlerClass( className, shortName),
- metaData );
+ getComponentHandler(className, getComponentHandlerClass(className, shortName), metaData);
// put the role into our role mapper. If the role doesn't exist
// yet, just stuff it in as DEFAULT_ENTRY. If it does, we create a
// ServiceSelector and put that in as SELECTOR_ENTRY.
- Map hintMap = (Map) m_mapper.get( role );
+ Map hintMap = (Map) m_mapper.get(role);
// Initialize the hintMap if it doesn't exist yet.
- if ( null == hintMap )
+ if (null == hintMap)
{
hintMap = createHintMap();
- hintMap.put( DEFAULT_ENTRY, handler );
- hintMap.put( SELECTOR_ENTRY,
- new FortressServiceSelector( this, role ) );
- m_mapper.put( role, hintMap );
+ hintMap.put(DEFAULT_ENTRY, handler);
+ hintMap.put(SELECTOR_ENTRY, new FortressServiceSelector(this, role));
+ m_mapper.put(role, hintMap);
}
- hintMap.put( hint, handler );
+ hintMap.put(hint, handler);
- if ( element.getAttributeAsBoolean( "default", false ) )
+ if (element.getAttributeAsBoolean("default", false))
{
- hintMap.put( DEFAULT_ENTRY, handler );
+ hintMap.put(DEFAULT_ENTRY, handler);
}
}
- catch ( ConfigurationException ce )
+ catch (ConfigurationException ce)
{
throw ce;
}
- catch ( Exception e )
+ catch (Exception e)
{
- throw new ConfigurationException( "Could not add component", e );
+ throw new ConfigurationException("Could not add component", e);
}
}
@@ -427,7 +424,8 @@
* This method can be overwritten in subclasses to provide a different
* default proxy type.
*/
- protected String getDefaultProxyType() {
+ protected String getDefaultProxyType()
+ {
return "none";
}
}
Added: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultEventManager.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultEventManager.java Mon Jul 5 09:58:15 2004
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.fortress.impl;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.avalon.fortress.ContainerListener;
+import org.apache.avalon.fortress.EventManager;
+import org.apache.avalon.fortress.MetaInfoEntry;
+
+/**
+ * Default implementation of EventManager
+ *
+ * @author <a href="mailto:dev@excalibur.apache.org">Excalibur Team</a>
+ */
+public class DefaultEventManager implements EventManager
+{
+ /**
+ * Holds the subscribers
+ */
+ private Set m_listeners = Collections.synchronizedSet( new HashSet() );
+
+ /**
+ * Adds an event subscriber
+ *
+ * @param listener ContainerListener implementation
+ */
+ public void addListener(ContainerListener listener)
+ {
+ m_listeners.add( listener );
+ }
+
+ /**
+ * Removes an event subscriber
+ *
+ * @param listener ContainerListener implementation
+ */
+ public void removeListener(ContainerListener listener)
+ {
+ m_listeners.remove( listener );
+ }
+
+ /**
+ * Raises the ComponentCreated event to susbcribers
+ *
+ * @param entry Collection of information about the component
+ * @param newInstance instance that has been created.
+ * @return the instance itself or a wrapped one
+ */
+ public Object fireComponentCreated(MetaInfoEntry entry, Object newInstance)
+ {
+ Object wrapperInstance = newInstance;
+
+ for (Iterator iter = m_listeners.iterator(); iter.hasNext();)
+ {
+ ContainerListener listener = (ContainerListener) iter.next();
+ wrapperInstance = listener.componentCreated( entry, wrapperInstance );
+ }
+
+ return wrapperInstance;
+ }
+
+ /**
+ * Raises the ComponentDestroyed event to susbcribers
+ *
+ * @param entry Collection of information about the component
+ * @param newInstance instance that has been released.
+ */
+ public void fireComponentDestroyed(MetaInfoEntry entry, Object newInstance)
+ {
+ for (Iterator iter = m_listeners.iterator(); iter.hasNext();)
+ {
+ ContainerListener listener = (ContainerListener) iter.next();
+ listener.componentDestroyed( entry, newInstance );
+ }
+ }
+}
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java Mon Jul 5 09:58:15 2004
@@ -424,12 +424,12 @@
protected Object raiseComponentCreatedEvent( final Object newInstance )
{
- return m_container.getEventManager().fireComponentCreated( newInstance );
+ return m_container.getEventManager().fireComponentCreated( m_metaEntry, newInstance );
}
protected void raiseComponentDestroyedEvent( final Object newInstance )
{
- m_container.getEventManager().fireComponentDestroyed( newInstance );
+ m_container.getEventManager().fireComponentDestroyed( m_metaEntry, newInstance );
}
/**
Modified: excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/impl/lookup/test/FortressServiceManagerTestCase.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/impl/lookup/test/FortressServiceManagerTestCase.java (original)
+++ excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/impl/lookup/test/FortressServiceManagerTestCase.java Mon Jul 5 09:58:15 2004
@@ -19,6 +19,7 @@
import junit.framework.TestCase;
import org.apache.avalon.fortress.Container;
+import org.apache.avalon.fortress.EventManager;
import org.apache.avalon.fortress.impl.AbstractContainer;
import org.apache.avalon.fortress.impl.lookup.FortressServiceManager;
import org.apache.avalon.fortress.impl.lookup.FortressServiceSelector;
@@ -100,6 +101,11 @@
public void setExpectedHint( Object hint )
{
m_hint = hint;
+ }
+
+ public EventManager getEventManager()
+ {
+ return null;
}
public Object get( String key, Object hint ) throws ServiceException
Added: excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/test/EventsTestCase.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/test/EventsTestCase.java Mon Jul 5 09:58:15 2004
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.fortress.test;
+
+import junit.framework.TestCase;
+
+import org.apache.avalon.fortress.ContainerListener;
+import org.apache.avalon.fortress.ContainerManager;
+import org.apache.avalon.fortress.MetaInfoEntry;
+import org.apache.avalon.fortress.impl.DefaultContainer;
+import org.apache.avalon.fortress.impl.DefaultContainerManager;
+import org.apache.avalon.fortress.test.data.*;
+import org.apache.avalon.fortress.util.FortressConfig;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.service.ServiceManager;
+
+/**
+ * A testcase for the events infrastructure
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ */
+public class EventsTestCase extends TestCase implements ContainerListener
+{
+ private boolean creationEventCalled = false;
+ private boolean destructionEventCalled = false;
+
+ public EventsTestCase( final String name )
+ {
+ super( name );
+ }
+
+ public void testCreatedEvent() throws Exception
+ {
+ final DefaultContainer container = createContainer();
+
+ container.getEventManager().addListener( this );
+ assertFalse( creationEventCalled );
+ assertFalse( destructionEventCalled );
+
+ final ServiceManager serviceManager = container.getServiceManager();
+ final String key = Role4.ROLE;
+ final BaseRole object = (BaseRole) serviceManager.lookup( key );
+
+ assertTrue( creationEventCalled );
+ assertFalse( destructionEventCalled );
+
+ serviceManager.release( object );
+
+ assertTrue( destructionEventCalled );
+ }
+
+ private DefaultContainer createContainer() throws Exception
+ {
+ final FortressConfig config = new FortressConfig();
+ config.setContextDirectory( "./" );
+ config.setWorkDirectory( "./" );
+ final String BASE = "resource://org/apache/avalon/fortress/test/data/";
+ config.setContainerConfiguration( BASE + "test1.xconf" );
+ config.setLoggerManagerConfiguration( BASE + "test1.xlog" );
+
+ final ContainerManager cm = new DefaultContainerManager( config.getContext() );
+ ContainerUtil.initialize( cm );
+
+ return (DefaultContainer) cm.getContainer();
+ }
+
+ public Object componentCreated(MetaInfoEntry entry, Object instance)
+ {
+ assertNotNull(entry);
+ assertNotNull(instance);
+ creationEventCalled = true;
+ return instance;
+ }
+
+ public void componentDestroyed(MetaInfoEntry entry, Object instance)
+ {
+ assertNotNull(entry);
+ assertNotNull(instance);
+ destructionEventCalled = true;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org