<commit_before>/**
 * Copyright (C) 2014 <NAME> (<EMAIL>)
 *
 * Licensed 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.camel.cdi.example2;


import org.apache.camel.CamelContext;
import org.apache.deltaspike.cdise.api.CdiContainer;
import org.apache.deltaspike.cdise.api.CdiContainerLoader;

import javax.enterprise.inject.Vetoed;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import java.util.concurrent.CountDownLatch;

@Vetoed
public class Main {

    public static void main(String[] args) throws Exception {
        // Since version 2.3.0.Final and WELD-1915, Weld SE registers a shutdown hook. See WELD-2051. The system property above is available starting Weld 2.3.1.Final to deactivate the registration of the shutdown hook so that the example behave consistently between Weld and OpenWebBeans.
        System.setProperty("org.jboss.weld.se.shutdownHook", "false");

        CdiContainer container = CdiContainerLoader.getCdiContainer();
        ShutdownHook shutdownHook = new ShutdownHook(container);
        Runtime.getRuntime().addShutdownHook(shutdownHook);
        container.boot();

        BeanManager manager = container.getBeanManager();
        Bean<?> bean = manager.resolve(manager.getBeans(CamelContext.class));
        CamelContext context = (CamelContext) manager.getReference(bean, CamelContext.class, manager.createCreationalContext(bean));
        context.start();

        // Wait until the JVM exits
        shutdownHook.latch.await();
    }

    @Vetoed
    private static final class ShutdownHook extends Thread {

        private final CountDownLatch latch = new CountDownLatch(1);
        private final CdiContainer container;

        private ShutdownHook(CdiContainer container) {
            this.container = container;
        }

        @Override
        public void run() {
            try {
                // Camel context is stopped in the @PreDestroy lifecycle callback
                container.shutdown();
            } catch (Exception cause) {
                cause.printStackTrace();
            } finally {
                latch.countDown();
            }
        }
    }
}<commit_msg>Use the CDI API to retrieve the Camel context reference<commit_after>/**
 * Copyright (C) 2014 <NAME> (<EMAIL>)
 *
 * Licensed 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.camel.cdi.example2;


import org.apache.camel.CamelContext;
import org.apache.deltaspike.cdise.api.CdiContainer;
import org.apache.deltaspike.cdise.api.CdiContainerLoader;

import javax.enterprise.inject.Vetoed;
import javax.enterprise.inject.spi.CDI;
import java.util.concurrent.CountDownLatch;

@Vetoed
public class Main {

    public static void main(String[] args) throws Exception {
        // Since version 2.3.0.Final and WELD-1915, Weld SE registers a shutdown hook. See WELD-2051. The system property above is available starting Weld 2.3.1.Final to deactivate the registration of the shutdown hook so that the example behave consistently between Weld and OpenWebBeans.
        System.setProperty("org.jboss.weld.se.shutdownHook", "false");

        CdiContainer container = CdiContainerLoader.getCdiContainer();
        ShutdownHook shutdownHook = new ShutdownHook(container);
        Runtime.getRuntime().addShutdownHook(shutdownHook);
        container.boot();

        // Start the Camel context
        CDI.current().select(CamelContext.class).get().start();

        // Wait until the JVM exits
        shutdownHook.latch.await();
    }

    @Vetoed
    private static final class ShutdownHook extends Thread {

        private final CountDownLatch latch = new CountDownLatch(1);
        private final CdiContainer container;

        private ShutdownHook(CdiContainer container) {
            this.container = container;
        }

        @Override
        public void run() {
            try {
                // Camel context is gracefully shut down by Camel CDI
                container.shutdown();
            } catch (Exception cause) {
                cause.printStackTrace();
            } finally {
                latch.countDown();
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08481110254433308, 'fraction_numerical': 0.009252120277563608, 'mean_word_length': 2.8868913857677905, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '1922974', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1353, 'n_words': 449}