Package org.apache.avalon.fortress.impl.handler

Examples of org.apache.avalon.fortress.impl.handler.ComponentHandler


    private ComponentHandler getComponentHandler( final MetaInfoEntry metaEntry,
                                                  final ComponentHandlerMetaData metaData )
            throws Exception
    {
        // get info from params
        final ComponentHandler handler;
        final String classname = metaEntry.getComponentClass().getName();
        final Configuration configuration = metaData.getConfiguration();

        try
        {
            final ObjectFactory factory =
                    createObjectFactory( classname, configuration );

            // create the appropriate handler instance
            final ComponentHandler targetHandler =
                    (ComponentHandler) metaEntry.getHandlerClass().newInstance();

            // do the handler lifecycle
            ContainerUtil.enableLogging( targetHandler, getLogger() );
            ContainerUtil.contextualize( targetHandler, m_context );
View Full Code Here


        while ( i.hasNext() )
        {
            entry = (ComponentHandlerEntry) i.next();
            try
            {
                final ComponentHandler handler = entry.getHandler();

                // Depending on the activation policy of the component decide
                //  how to initialize the component.  Make sure that we can
                //  perform the specified activation policy, if not modify it.
                int activation = entry.getMetaData().getActivation();
                if ( activation == ComponentHandlerMetaData.ACTIVATION_BACKGROUND )
                {
                    // If a sink is not set then we must change to inline.
                    if ( null == m_commandSink )
                    {
                        activation = ComponentHandlerMetaData.ACTIVATION_INLINE;
                    }
                }

                // We now have an activation policy we can handle.
                switch ( activation )
                {
                    case ComponentHandlerMetaData.ACTIVATION_BACKGROUND:
                        // Add a command to initialize the component to the command
                        //  sink so it will be initialized asynchronously in the
                        //  background.
                        final PrepareHandlerCommand element =
                                new PrepareHandlerCommand( handler, getLogger() );
                        m_commandSink.enqueue( element );
                        break;

                    case ComponentHandlerMetaData.ACTIVATION_INLINE:
                        // Initialize the component now.
                        handler.prepareHandler();
                        break;

                    default: // ComponentHandlerMetaData.ACTIVATION_LAZY
                        if ( getLogger().isDebugEnabled() )
                        {
View Full Code Here

        final Iterator i = m_shutDownOrder.iterator();
        while ( i.hasNext() )
        {
            final Vertex entry = (Vertex) i.next();
            final ComponentHandler handler = (ComponentHandler) entry.getNode();

            if ( getLogger().isDebugEnabled() ) getLogger().debug( "Shutting down: " + handler );
            ContainerUtil.dispose( handler );
            if ( getLogger().isDebugEnabled() ) getLogger().debug( "Done." );
        }
View Full Code Here

            throw new ServiceException( role, message );
        }

        try
        {
            final ComponentHandler handler = (ComponentHandler) result;
            final Object component = handler.get();

            // we only have to keep track of components that don't implement
            // the ReleasableComponent interface
            if ( !(component instanceof ReleasableComponent) )
            {
View Full Code Here

        if ( component instanceof ReleasableComponent )
        {
            ((ReleasableComponent)component).releaseOnComponentHandler();
            return;
        }
        final ComponentHandler handler = (ComponentHandler) m_used.remove( new ComponentKey( component ) );
        if ( null == handler )
        {
            if ( null == m_parent )
            {
                /* This is a purplexing problem.  SOmetimes the m_used hash
                 * returns null for the component--usually a ThreadSafe
                 * component.  When there is no handler and no parent, that
                 * is an error condition--but if the component is usually
                 * ThreadSafe, the impact is essentially nill.
                 */
                //Pete: This occurs when objects are released more often than
                //when they are aquired
                //Pete: It also happens when a release of a ComponentSelector occurs
            }
            else
            {
                m_parent.release( component );
            }
        }
        else
        {
            handler.put( component );
        }
    }
View Full Code Here

    public Object select( final Object hint )
        throws ServiceException
    {
        try
        {
            final ComponentHandler handler = getHandler( hint );
            final Object component = handler.get();
            // we only have to keep track of components that don't implement
            // the ReleasableComponent interface
            if ( !(component instanceof ReleasableComponent) )
            {
                m_used.put( new ComponentKey( component ), handler );
View Full Code Here

            throw new ServiceException( role, message );
        }

        try
        {
            final ComponentHandler handler = (ComponentHandler) result;
            final Object component = handler.get();

            m_used.put( new ComponentKey( component ), handler );
            return component;
        }
        catch ( final ServiceException ce )
View Full Code Here

        }
    }

    public void release( final Object component )
    {
        final ComponentHandler handler = (ComponentHandler) m_used.remove( new ComponentKey( component ) );
        if ( null == handler )
        {
            if ( null == m_parent )
            {
                /* This is a purplexing problem.  SOmetimes the m_used hash
                 * returns null for the component--usually a ThreadSafe
                 * component.  When there is no handler and no parent, that
                 * is an error condition--but if the component is usually
                 * ThreadSafe, the impact is essentially nill.
                 */
                //Pete: This occurs when objects are released more often than
                //when they are aquired
                //Pete: It also happens when a release of a ComponentSelector occurs
            }
            else
            {
                m_parent.release( component );
            }
        }
        else
        {
            handler.put( component );
        }
    }
View Full Code Here

    public Object select( final Object hint )
        throws ServiceException
    {
        try
        {
            final ComponentHandler handler = getHandler( hint );
            final Object component = handler.get();
            m_used.put( new ComponentKey( component ), handler );
            return component;
        }
        catch ( final ServiceException ce )
        {
View Full Code Here

        return m_container.has( m_key, hint );
    }

    public void release( final Object component )
    {
        final ComponentHandler handler =
            (ComponentHandler) m_used.remove( new ComponentKey( component ) );
        if ( null != handler )
        {
            handler.put( component );
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.avalon.fortress.impl.handler.ComponentHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.