<commit_before>/*
 * Copyright 2013 CarCV Development Team
 *
 * 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.carcv.web.servlet;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.carcv.web.beans.RecognizerBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A Servlet that calls {@link RecognizerBean#recognize()} in a background thread.
 */
@WebServlet("/servlet/Recognize")
public class RecognizeServlet extends HttpServlet {
    
    final private static Logger LOGGER = LoggerFactory.getLogger(RecognizeServlet.class);

    private static final long serialVersionUID = -235344099282905675L;

    @EJB
    private RecognizerBean recognizerBean;

    private ExecutorService pool;

    @Override
    public void init() {
        pool = Executors.newFixedThreadPool(2);
    }

    /**
     * @param request the HttpServletRequest
     * @param response the HttpServletResponse
     * @throws ServletException
     * @throws IOException
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException,
        IOException {
        pool.execute(new RecognizeRunnable());
        response.sendRedirect("/app/refresh_in_progress.jsp");
        return;
    }

    /**
     * @see #processRequest(HttpServletRequest, HttpServletResponse)
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * @see #processRequest(HttpServletRequest, HttpServletResponse)
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * A runnable task that runs {@link RecognizerBean#recognize()}.
     */
    private class RecognizeRunnable implements Runnable {

        /**
         * NOTE: Catches all IOException and only logs them.
         */
        @Override
        public void run() {
            try {
                LOGGER.info("[RecognizeServlet]\tStarting recognizing...");
                recognizerBean.recognize();
                LOGGER.info("[RecognizeServlet]\tDone recognizing!");
            } catch (IOException e) {
                LOGGER.error("Error during refreshing and recognizing occured.");
                e.printStackTrace();
            }
        }
    }
}<commit_msg>Fixed a typo left over<commit_after>/*
 * Copyright 2013 CarCV Development Team
 *
 * 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.carcv.web.servlet;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.carcv.web.beans.RecognizerBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A Servlet that calls {@link RecognizerBean#recognize()} in a background thread.
 */
@WebServlet("/servlet/Recognize")
public class RecognizeServlet extends HttpServlet {
    
    final private static Logger LOGGER = LoggerFactory.getLogger(RecognizeServlet.class);

    private static final long serialVersionUID = -235344099282905675L;

    @EJB
    private RecognizerBean recognizerBean;

    private ExecutorService pool;

    @Override
    public void init() {
        pool = Executors.newFixedThreadPool(2);
    }

    /**
     * @param request the HttpServletRequest
     * @param response the HttpServletResponse
     * @throws ServletException
     * @throws IOException
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException,
        IOException {
        pool.execute(new RecognizeRunnable());
        response.sendRedirect("/app/refresh_in_progress.jsp");
        return;
    }

    /**
     * @see #processRequest(HttpServletRequest, HttpServletResponse)
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * @see #processRequest(HttpServletRequest, HttpServletResponse)
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * A runnable task that runs {@link RecognizerBean#recognize()}.
     */
    private class RecognizeRunnable implements Runnable {

        /**
         * NOTE: Catches all IOException and only logs them.
         */
        @Override
        public void run() {
            try {
                LOGGER.info("Starting recognizing...");
                recognizerBean.recognize();
                LOGGER.info("Done recognizing!");
            } catch (IOException e) {
                LOGGER.error("Error during refreshing and recognizing occured.");
                e.printStackTrace();
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.085383502170767, 'fraction_numerical': 0.008393632416787264, 'mean_word_length': 3.2660493827160493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5326640', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1745, 'n_words': 516}