<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.felix.scr.impl;


import org.osgi.framework.Bundle;
import org.osgi.service.log.LogService;


/**
 * The <code>ComponentActivatorTask</code> extends the <code>Runnable</code>
 * interface with the functionality to have a meaningful {@link #toString()}
 * implementation. This is mainly used when logging something around the task
 * being run or scheduled.
 */
abstract class ComponentActivatorTask implements Runnable
{

    private final String taskName;
    private final ComponentManager component;


    protected ComponentActivatorTask( String taskName, ComponentManager component )
    {
        this.taskName = taskName;
        this.component = component;
    }


    protected abstract void doRun();


    public void run()
    {
        // fail, if the bundle is not active
        if ( component.getBundle().getState() == Bundle.ACTIVE )
        {
            doRun();
        }
        else
        {
            Activator.log( LogService.LOG_WARNING, component.getBundle(), "Cannot run task '" + this
                + "': Providing bundle is not active", null );
        }
    }


    public String toString()
    {
        return taskName + " " + component;
    }
}<commit_msg>FELIX-1195 Check whether the component has already been destroyed and log this separately before checking for the bundle state<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.felix.scr.impl;


import org.apache.felix.scr.Component;
import org.osgi.framework.Bundle;
import org.osgi.service.log.LogService;


/**
 * The <code>ComponentActivatorTask</code> extends the <code>Runnable</code>
 * interface with the functionality to have a meaningful {@link #toString()}
 * implementation. This is mainly used when logging something around the task
 * being run or scheduled.
 */
abstract class ComponentActivatorTask implements Runnable
{

    private final String taskName;
    private final ComponentManager component;


    protected ComponentActivatorTask( String taskName, ComponentManager component )
    {
        this.taskName = taskName;
        this.component = component;
    }


    protected abstract void doRun();


    public void run()
    {
        // fail, if the bundle is not active
        if ( component.getState() == Component.STATE_DESTROYED )
        {
            // cannot use bundle to log because it is not accessible from the
            // component if the component is destroyed
            Activator.log( LogService.LOG_WARNING, null, "Cannot run task '" + this
                + "': Component has already been destroyed", null );
        }
        else if ( component.getBundle().getState() != Bundle.ACTIVE )
        {
            Activator.log( LogService.LOG_WARNING, component.getBundle(), "Cannot run task '" + this
                + "': Declaring bundle is not active", null );
        }
        else
        {
            doRun();
        }
    }


    public String toString()
    {
        return taskName + " " + component;
    }
}
{'fraction_non_alphanumeric': 0.07938234014789039, 'fraction_numerical': 0.0026098303610265334, 'mean_word_length': 2.8941574936494496, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6616165', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1123, 'n_words': 479}