Example usage for org.apache.commons.collections BoundedFifoBuffer BoundedFifoBuffer

List of usage examples for org.apache.commons.collections BoundedFifoBuffer BoundedFifoBuffer

Introduction

In this page you can find the example usage for org.apache.commons.collections BoundedFifoBuffer BoundedFifoBuffer.

Prototype

public BoundedFifoBuffer(Collection coll) 

Source Link

Document

Constructs a new BoundedFifoBuffer big enough to hold all of the elements in the specified collection.

Usage

From source file:org.apache.avalon.fortress.impl.AbstractContainer.java

/**
 * Initializes the impl and all the components it hosts so that they are ready to be used.
 * Unless components ask for lazy activation, this is where they are activated.
 *
 * @throws CompositeException if one or more components could not be initialized.
 *                   The system <i>is</i> running properly so if the missing components are
 *                   not vital to operation, it should be possible to recover gracefully
 *///  w ww.j av a2s.  com
public void initialize() throws CompositeException, Exception {
    // go over all components
    final Iterator i = m_components.iterator();
    final BoundedFifoBuffer buffer = new BoundedFifoBuffer(Math.max(m_components.size(), 1));

    // just to be on the safe side
    m_extManager.makeReadOnly();

    verifyComponents();

    ComponentHandlerEntry entry;
    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()) {
                    final String message = "ComponentHandler (" + handler
                            + ") has specified a lazy activation policy, "
                            + "initialization deferred until first use";
                    getLogger().debug(message);
                }
                break;
            }
        } catch (final CascadingException e) {
            final String cName = entry.getMetaData().getName();

            if (getLogger().isWarnEnabled()) {
                final String message = "Could not initialize component " + cName;
                getLogger().warn(message, e);

                final String cause = "Cause for exception";
                getLogger().warn(cause, e.getCause());
            }
            buffer.add(e);
        } catch (final Exception e) {
            final String cName = entry.getMetaData().getName();

            if (getLogger().isWarnEnabled()) {
                final String message = "Could not initialize component " + cName;
                getLogger().warn(message, e);
            }
            buffer.add(e);
        } catch (final LinkageError le) {
            final String cName = entry.getMetaData().getName();

            if (getLogger().isWarnEnabled()) {
                final String message = "Could not initialize component " + cName;
                getLogger().warn(message, le);
            }
            buffer.add(le);
        }
    }

    // if we were unable to activate one or more components,
    // throw an exception
    if (buffer.size() > 0) {
        throw new CompositeException((Exception[]) buffer.toArray(new Exception[0]),
                "unable to instantiate one or more components");
    }
}

From source file:org.apache.excalibur.mpool.BlockingFixedSizePool.java

public BlockingFixedSizePool(ObjectFactory factory, int size, long timeout) throws Exception {
    m_timeout = (timeout < 1) ? 0 : timeout;
    m_buffer = new BoundedFifoBuffer(size);
    m_maxSize = size;/*w ww .  j av  a2 s .  c o  m*/
    m_factory = factory;
}

From source file:org.apache.excalibur.mpool.FixedSizePool.java

public FixedSizePool(ObjectFactory factory, int size) throws Exception {
    m_buffer = new BoundedFifoBuffer(size);
    m_factory = factory;/*from   www.  j a  va2s .co m*/

    for (int i = 0; i < size; i++) {
        m_buffer.add(newInstance());
    }
}