<commit_before>package ru.semiot.services.analyzing.wamp;

import java.io.IOException;
import javax.annotation.PostConstruct;
import javax.ejb.Stateful;
import javax.faces.bean.ManagedBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static ru.semiot.services.analyzing.ServiceConfig.config;
import rx.functions.Action1;
import ws.wamp.jawampa.ApplicationError;
import ws.wamp.jawampa.WampClient;

@Stateful
@ManagedBean(eager = true)
@javax.faces.bean.ApplicationScoped
public class Launcher {

    private static final Logger logger = LoggerFactory
            .getLogger(Launcher.class);

    @PostConstruct
    public void run() {
        logger.info("Start WAMP");
        new Thread(new Runnable() {

            @Override
            public void run() {
                startWamp();
            }
        }).start();
    }

    private void startWamp() {
        try {
            WAMPClient
                    .getInstance()
                    .init()
                    .subscribe(new Action1<WampClient.Status>() {
<commit_msg>Added waiting a data store<commit_after>package ru.semiot.services.analyzing.wamp;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.annotation.PostConstruct;
import javax.ejb.Stateful;
import javax.faces.bean.ManagedBean;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.DefaultHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.semiot.services.analyzing.ServiceConfig;
import static ru.semiot.services.analyzing.ServiceConfig.config;
import rx.functions.Action1;
import ws.wamp.jawampa.ApplicationError;
import ws.wamp.jawampa.WampClient;

@Stateful
@ManagedBean(eager = true)
@javax.faces.bean.ApplicationScoped
public class Launcher {

    private static final Logger logger = LoggerFactory
            .getLogger(Launcher.class);

    @PostConstruct
    public void run() {
        logger.info("Start WAMP");
        connectWithDataStore();
        new Thread(new Runnable() {

            @Override
            public void run() {
                startWamp();
            }
        }).start();
    }

    private void connectWithDataStore() {
        try {
            URI uri = new URI(ServiceConfig.config.storeUrl());
            String URL = "http://" + uri.getHost() + ":" + uri.getPort();
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet(URL);
            HttpResponse resp = null;

            while (true) {
                try {
                    resp = client.execute(request);
                    if (resp.getStatusLine().getStatusCode() == 200) {
                        logger.info("Connected to " + URL);
                        break;
                    }
                } catch (HttpHostConnectException ex) {
                    logger.info("Try to connect with " + URL);
                } catch (IOException ex) {
                    logger.error("Something went wrong with error:\n"+ex.getMessage());
                }
            }
        } catch (URISyntaxException ex) {
            logger.error("The storeURL is WRONG!!!");
        }
    }

    private void startWamp() {
        try {
            WAMPClient
                    .getInstance()
                    .init()
                    .subscribe(new Action1<WampClient.Status>() {

{'fraction_non_alphanumeric': 0.10439716312056738, 'fraction_numerical': 0.003120567375886525, 'mean_word_length': 2.148214285714286, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, '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': '5566355', 'n_tokens_mistral': 993, 'n_tokens_neox': 951, 'n_words': 202}