<commit_before>/*
 * Copyright (c) 2014-2017 Globo.com - ATeam
 * All rights reserved.
 *
 * This source is subject to the Apache License, Version 2.0.
 * Please see the LICENSE file for more information.
 *
 * Authors: See AUTHORS file
 *
 * 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 io.galeb.health.services;

import com.google.gson.Gson;
import io.galeb.core.enums.SystemEnv;
import io.galeb.core.entity.Target;
import io.galeb.core.enums.EnumHealthState;
import io.galeb.health.util.CallBackQueue;
import org.asynchttpclient.AsyncCompletionHandler;
import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.RequestBuilder;
import org.asynchttpclient.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

import java.net.URI;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference;

import static io.galeb.core.enums.EnumHealthState.*;
import static io.galeb.core.enums.EnumPropHealth.*;
import static org.asynchttpclient.Dsl.asyncHttpClient;
import static org.asynchttpclient.Dsl.config;

@Service
public class HealthCheckerService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final String connectionTimeout = SystemEnv.TEST_CONN_TIMEOUT.getValue();

    private final CallBackQueue callBackQueue;

    private final AsyncHttpClient asyncHttpClient;

    @Autowired
    public HealthCheckerService(final CallBackQueue callBackQueue) {
        this.callBackQueue = callBackQueue;
        this.asyncHttpClient = asyncHttpClient(config()
                .setFollowRedirect(false)
                .setSoReuseAddress(true)
                .setKeepAlive(false)
                .setConnectTimeout(Integer.parseInt(connectionTimeout))
                .setPooledConnectionIdleTimeout(1)
                .setMaxConnectionsPerHost(1).build());
    }

    @SuppressWarnings("unused")
    @JmsListener(destination = "galeb-health", concurrency = "5-5")
    public void check(String targetStr) throws ExecutionException, InterruptedException {<commit_msg>HealthCheckerService: externalized params to asyncHttpClient<commit_after>/*
 * Copyright (c) 2014-2017 Globo.com - ATeam
 * All rights reserved.
 *
 * This source is subject to the Apache License, Version 2.0.
 * Please see the LICENSE file for more information.
 *
 * Authors: See AUTHORS file
 *
 * 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 io.galeb.health.services;

import com.google.gson.Gson;
import io.galeb.core.enums.SystemEnv;
import io.galeb.core.entity.Target;
import io.galeb.core.enums.EnumHealthState;
import io.galeb.health.util.CallBackQueue;
import org.asynchttpclient.AsyncCompletionHandler;
import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.RequestBuilder;
import org.asynchttpclient.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

import java.net.URI;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference;

import static io.galeb.core.enums.EnumHealthState.*;
import static io.galeb.core.enums.EnumPropHealth.*;
import static org.asynchttpclient.Dsl.asyncHttpClient;
import static org.asynchttpclient.Dsl.config;

@SuppressWarnings("FieldCanBeLocal")
@Service
public class HealthCheckerService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final boolean keepAlive                   = Boolean.parseBoolean(SystemEnv.TEST_KEEPALIVE.getValue());
    private final int     connectionTimeout           = Integer.parseInt(SystemEnv.TEST_CONN_TIMEOUT.getValue());
    private final int     pooledConnectionIdleTimeout = Integer.parseInt(SystemEnv.TEST_POOLED_IDLE_TIMEOUT.getValue());
    private final int     maxConnectionsPerHost       = Integer.parseInt(SystemEnv.TEST_MAXCONN_PER_HOST.getValue());

    private final CallBackQueue callBackQueue;
    private final AsyncHttpClient asyncHttpClient;

    @Autowired
    public HealthCheckerService(final CallBackQueue callBackQueue) {
        this.callBackQueue = callBackQueue;
        this.asyncHttpClient = asyncHttpClient(config()
                .setFollowRedirect(false)
                .setSoReuseAddress(true)
                .setKeepAlive(keepAlive)
                .setConnectTimeout(connectionTimeout)
                .setPooledConnectionIdleTimeout(pooledConnectionIdleTimeout)
                .setMaxConnectionsPerHost(maxConnectionsPerHost).build());
    }

    @SuppressWarnings("unused")
    @JmsListener(destination = "galeb-health", concurrency = "5-5")
    public void check(String targetStr) throws ExecutionException, InterruptedException {
{'fraction_non_alphanumeric': 0.08267575322812051, 'fraction_numerical': 0.005380200860832138, 'mean_word_length': 4.331739961759082, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1220424', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1537, 'n_words': 374}