<commit_before>/*******************************************************************************
 * Copyright (c) 2010, 2013 Sonatype, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    <NAME> (Sonatype, Inc.) - initial API and implementation
 *******************************************************************************/
package org.eclipse.sisu.bean;

import java.util.ArrayList;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.matcher.Matchers;

/**
 * {@link BeanManager} that manages components requiring lifecycle scheduling.
 */
public abstract class AbstractLifecycleManager
    implements BeanManager, Module
{
    // ----------------------------------------------------------------------
    // Static initialization
    // ----------------------------------------------------------------------

    static
    {
        Object lifecycleListener;
        try
        {
            lifecycleListener = new LifecycleListener();
        }
        catch ( final LinkageError e )
        {
            lifecycleListener = null;
        }
        LIFECYCLE_LISTENER = lifecycleListener;
    }

    // ----------------------------------------------------------------------
    // Constants
    // ----------------------------------------------------------------------

    private static final Object LIFECYCLE_LISTENER;

    static final Object PLACEHOLDER = new Object();

    // ----------------------------------------------------------------------
    // Implementation fields
    // ----------------------------------------------------------------------

    private static final ThreadLocal<Object[]> pendingHolder = new ThreadLocal<Object[]>();

    // ----------------------------------------------------------------------
    // Public methods
    // ----------------------------------------------------------------------

    public void configure( final Binder binder )
    {
        if ( null != LIFECYCLE_LISTENER )
        {
            binder.bindListener( Matchers.any(), (com.google.inject.spi.ProvisionListener) LIFECYCLE_LISTENER );
        }
    }

    public final void schedule( final Object bean )
    {
        if ( null != LIFECYCLE_LISTENER )
        {
            final Object[] holder = getPendingHolder();
            final Object pending = holder[0];
            if ( pending == PLACEHOLDER )
            {<commit_msg>Bug 386446: allow loop detection to be optional<commit_after>/*******************************************************************************
 * Copyright (c) 2010, 2013 Sonatype, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    <NAME> (Sonatype, Inc.) - initial API and implementation
 *******************************************************************************/
package org.eclipse.sisu.bean;

import java.util.ArrayList;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.matcher.Matchers;

/**
 * {@link BeanManager} that manages components requiring lifecycle scheduling.
 */
public abstract class AbstractLifecycleManager
    implements BeanManager, Module
{
    // ----------------------------------------------------------------------
    // Static initialization
    // ----------------------------------------------------------------------

    static
    {
        Object lifecycleListener;
        try
        {
            lifecycleListener = new LifecycleListener();
        }
        catch ( final LinkageError e )
        {
            lifecycleListener = null;
        }
        LIFECYCLE_LISTENER = lifecycleListener;
    }

    // ----------------------------------------------------------------------
    // Constants
    // ----------------------------------------------------------------------

    private static final Object LIFECYCLE_LISTENER;

    static final Object PLACEHOLDER = new Object();

    // ----------------------------------------------------------------------
    // Implementation fields
    // ----------------------------------------------------------------------

    private static final ThreadLocal<Object[]> pendingHolder = new ThreadLocal<Object[]>();

    private final boolean detectLoops;

    // ----------------------------------------------------------------------
    // Constructors
    // ----------------------------------------------------------------------

    protected AbstractLifecycleManager( final boolean detectLoops )
    {
        this.detectLoops = detectLoops;
    }

    // ----------------------------------------------------------------------
    // Public methods
    // ----------------------------------------------------------------------

    public void configure( final Binder binder )
    {
        if ( null != LIFECYCLE_LISTENER && detectLoops )
        {
            binder.bindListener( Matchers.any(), (com.google.inject.spi.ProvisionListener) LIFECYCLE_LISTENER );
        }
    }

    public final void schedule( final Object bean )
    {
        if ( null != LIFECYCLE_LISTENER && detectLoops )
        {
            final Object[] holder = getPendingHolder();
            final Object pending = holder[0];
            if ( pending == PLACEHOLDER )
            {
{'fraction_non_alphanumeric': 0.34424778761061947, 'fraction_numerical': 0.005663716814159292, 'mean_word_length': 1.2540885520542482, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4743571', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1122, 'n_words': 309}