CVS: plexus-container-new/src/java/org/apache/plexus/service/repository/instance AbstractInstanceManager.java,NONE,1.1 InstanceManager.java,NONE,1.1 PerLookupInstanceManager.java,NONE,1.1 PoolableInstanceManager.java,NONE,1.1 SingletonInstanceManager.java,NONE,1.1

[email protected] Thu, 1 May 2003 14:35:39 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/service/repository/instance
In directory eng.werken.com:/tmp/cvs-serv18124/src/java/org/apache/plexus/service/repository/instance

Added Files:
	AbstractInstanceManager.java InstanceManager.java 
	PerLookupInstanceManager.java PoolableInstanceManager.java 
	SingletonInstanceManager.java 
Log Message:
o This will require a separate message as more than a few changes have
occurred in order to support handling for various instantiation strategies
and scriptable components.



--- NEW FILE: AbstractInstanceManager.java ---
package org.apache.plexus.service.repository.instance;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.plexus.service.repository.ComponentHousing;
import org.apache.plexus.service.repository.ComponentManager;

/**
 *
 *
 * @author <a href="mailto:[email protected]">Jason van Zyl</a>
 *
 * @version $Id: AbstractInstanceManager.java,v 1.1 2003/05/01 19:35:36 jvanzyl Exp $
 */
public abstract class AbstractInstanceManager
    implements InstanceManager
{
    private ClassLoader classLoader;

    private Configuration configuration;

    private String implementation;

    private ComponentManager componentManager;

    // ----------------------------------------------------------------------
    // Lifecylce Management
    // ----------------------------------------------------------------------

    public void configure( Configuration configuration )
        throws ConfigurationException
    {
        this.configuration = configuration;

        implementation = configuration.getChild( "implementation" ).getValue();
    }

    // ----------------------------------------------------------------------
    // Accessors
    // ----------------------------------------------------------------------

    public Configuration getConfiguration()
    {
        return configuration;
    }

    public void setConfiguration( Configuration configuration )
    {
        this.configuration = configuration;
    }

    public String getImplementation()
    {
        return implementation;
    }

    public void setImplementation( String implementation )
    {
        this.implementation = implementation;
    }

    public ClassLoader getClassLoader()
    {
        return classLoader;
    }

    public void setClassLoader( ClassLoader classLoader )
    {
        this.classLoader = classLoader;
    }

    public ComponentManager getComponentManager()
    {
        return componentManager;
    }

    public void setComponentManager( ComponentManager componentManager )
    {
        this.componentManager = componentManager;
    }

    // ----------------------------------------------------------------------
    // Implementation
    // ----------------------------------------------------------------------

    protected ComponentHousing createInstance()
        throws Exception
    {
        ComponentHousing housing = new  ComponentHousing();

        housing.setComponent( getClassLoader().loadClass( getImplementation() ).newInstance() );
        housing.setComponentManager( getComponentManager() );

        return housing;
    }
}

--- NEW FILE: InstanceManager.java ---
package org.apache.plexus.service.repository.instance;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.plexus.service.repository.ComponentHousing;
import org.apache.plexus.service.repository.ComponentManager;

/**
 *
 *
 * @author <a href="mailto:[email protected]">Jason van Zyl</a>
 *
 * @version $Id: InstanceManager.java,v 1.1 2003/05/01 19:35:36 jvanzyl Exp $
 */
public interface InstanceManager
{
    static String ROLE = InstanceManager.class.getName();

    ComponentHousing getInstance()
        throws Exception;

    void configure( Configuration configuration )
        throws ConfigurationException;

    void initialize()
        throws Exception;

    void setClassLoader( ClassLoader classLoader );

    void setImplementation( String implementation );

    void setComponentManager( ComponentManager manager );
}

--- NEW FILE: PerLookupInstanceManager.java ---
package org.apache.plexus.service.repository.instance;

import org.apache.plexus.service.repository.ComponentHousing;

/**
 *
 * 
 * @author <a href="mailto:[email protected]">Jason van Zyl</a>
 *
 * @version $Id: PerLookupInstanceManager.java,v 1.1 2003/05/01 19:35:36 jvanzyl Exp $
 */
public class PerLookupInstanceManager
    extends AbstractInstanceManager
{
    public void initialize()
        throws Exception
    {
    }

    public ComponentHousing getInstance()
        throws Exception
    {
        return createInstance();
    }
}

--- NEW FILE: PoolableInstanceManager.java ---
package org.apache.plexus.service.repository.instance;

import org.apache.plexus.service.repository.ComponentHousing;

/**
 *
 *
 * @author <a href="mailto:[email protected]">Jason van Zyl</a>
 *
 * @version $Id: PoolableInstanceManager.java,v 1.1 2003/05/01 19:35:36 jvanzyl Exp $
 */
public class PoolableInstanceManager
    extends AbstractInstanceManager
{
    private SimplePool pool;

    private int size = 6;

    public void initialize()
        throws Exception
    {
        pool = new SimplePool( size );

        for ( int i = 0; i < size; i++ )
        {
            pool.put( createInstance() );
        }
    }

    public ComponentHousing getInstance()
        throws Exception
    {
        return (ComponentHousing) pool.get();
    }
}

--- NEW FILE: SingletonInstanceManager.java ---
package org.apache.plexus.service.repository.instance;

import org.apache.plexus.service.repository.ComponentHousing;

/**
 *
 * 
 * @author <a href="mailto:[email protected]">Jason van Zyl</a>
 *
 * @version $Id: SingletonInstanceManager.java,v 1.1 2003/05/01 19:35:36 jvanzyl Exp $
 */
public class SingletonInstanceManager
    extends AbstractInstanceManager
{
    private ComponentHousing instance;

    public void initialize()
        throws Exception
    {
    }

    public ComponentHousing getInstance()
        throws Exception
    {
        if ( instance == null )
        {
            instance = createInstance();
        }

        return instance;
    }
}