<commit_before>/*
 * Copyright (C) 2012 <NAME> (<EMAIL>)
 * All rights reserved.
 */

package com.ickstream.protocol.cloud;

import com.ickstream.common.jsonrpc.MessageLogger;
import com.ickstream.protocol.cloud.core.CoreService;
import com.ickstream.protocol.cloud.core.FindServicesRequest;
import com.ickstream.protocol.cloud.core.FindServicesResponse;
import com.ickstream.protocol.cloud.library.LibraryService;
import com.ickstream.protocol.cloud.scrobble.ScrobbleService;
import org.apache.http.impl.client.DefaultHttpClient;

public class ServiceFactory {
    private static final String CORESERVICE_ENDPOINT = "http://ickstream.isaksson.info/ickstream-cloud-core/jsonrpc";

    private static String getEndpoint() {
        String url = System.getProperty("ickstream-core-url");
        if (url != null) {
            return url;
        } else {
            return CORESERVICE_ENDPOINT;
        }
    }

    public static CoreService getCoreService(String accessToken, MessageLogger messageLogger) {
        CoreService coreService = new CoreService(new DefaultHttpClient(), getEndpoint());
        coreService.setAccessToken(accessToken);
        coreService.setMessageLogger(messageLogger);
        return coreService;
    }

    public static CoreService getCoreService(String accessToken) {
        return getCoreService(accessToken, null);
    }

    public static ScrobbleService getScrobbleService(String accessToken, MessageLogger messageLogger) {
        try {
            FindServicesResponse response = getCoreService(accessToken, messageLogger).findServices(new FindServicesRequest("scrobble"));
            if (response != null && response.getItems_loop().size() > 0) {
                ScrobbleService scrobbleService = new ScrobbleService(new DefaultHttpClient(), response.getItems_loop().get(0).getUrl());
                scrobbleService.setAccessToken(accessToken);
                scrobbleService.setMessageLogger(messageLogger);
                return scrobbleService;
            }
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (ServiceTimeoutException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static ScrobbleService getScrobbleService(String accessToken) {
        return getScrobbleService(accessToken, null);
    }

    public static LibraryService getLibraryService(String accessToken, MessageLogger messageLogger) {
        try {
            FindServicesResponse response = getCoreService(accessToken, messageLogger).findServices(new FindServicesRequest("librarymanagement"));
            if (response != null && response.getItems_loop().size() > 0) {
                LibraryService libraryService = new LibraryService(new DefaultHttpClient(), response.getItems_loop().get(0).getUrl());
                libraryService.setAccessToken(accessToken);
                libraryService.setMessageLogger(messageLogger);
                return libraryService;
            }
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (ServiceTimeoutException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static LibraryService getLibraryService(String accessToken) {
        return getLibraryService(accessToken, null);
    }
}
<commit_msg>Corrected so CoreService request can run in parallel<commit_after>/*
 * Copyright (C) 2012 <NAME> (<EMAIL>)
 * All rights reserved.
 */

package com.ickstream.protocol.cloud;

import com.ickstream.common.jsonrpc.MessageLogger;
import com.ickstream.protocol.cloud.core.CoreService;
import com.ickstream.protocol.cloud.core.FindServicesRequest;
import com.ickstream.protocol.cloud.core.FindServicesResponse;
import com.ickstream.protocol.cloud.library.LibraryService;
import com.ickstream.protocol.cloud.scrobble.ScrobbleService;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;

public class ServiceFactory {
    private static final String CORESERVICE_ENDPOINT = "http://ickstream.isaksson.info/ickstream-cloud-core/jsonrpc";

    private static String getEndpoint() {
        String url = System.getProperty("ickstream-core-url");
        if (url != null) {
            return url;
        } else {
            return CORESERVICE_ENDPOINT;
        }
    }

    public static CoreService getCoreService(String accessToken, MessageLogger messageLogger) {
        CoreService coreService = new CoreService(createHttpClient(), getEndpoint());
        coreService.setAccessToken(accessToken);
        coreService.setMessageLogger(messageLogger);
        return coreService;
    }

    private static HttpClient createHttpClient() {
        try {
            Class.forName("org.apache.http.impl.conn.PoolingClientConnectionManager");
            return new DefaultHttpClient(new PoolingClientConnectionManager());
        } catch (ClassNotFoundException e) {
            return new DefaultHttpClient(new ThreadSafeClientConnManager());
        }
    }

    public static CoreService getCoreService(String accessToken) {
        return getCoreService(accessToken, null);
    }

    public static ScrobbleService getScrobbleService(String accessToken, MessageLogger messageLogger) {
        try {
            FindServicesResponse response = getCoreService(accessToken, messageLogger).findServices(new FindServicesRequest("scrobble"));
            if (response != null && response.getItems_loop().size() > 0) {
                ScrobbleService scrobbleService = new ScrobbleService(new DefaultHttpClient(), response.getItems_loop().get(0).getUrl());
                scrobbleService.setAccessToken(accessToken);
                scrobbleService.setMessageLogger(messageLogger);
                return scrobbleService;
            }
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (ServiceTimeoutException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static ScrobbleService getScrobbleService(String accessToken) {
        return getScrobbleService(accessToken, null);
    }

    public static LibraryService getLibraryService(String accessToken, MessageLogger messageLogger) {
        try {
            FindServicesResponse response = getCoreService(accessToken, messageLogger).findServices(new FindServicesRequest("librarymanagement"));
            if (response != null && response.getItems_loop().size() > 0) {
                LibraryService libraryService = new LibraryService(new DefaultHttpClient(), response.getItems_loop().get(0).getUrl());
                libraryService.setAccessToken(accessToken);
                libraryService.setMessageLogger(messageLogger);
                return libraryService;
            }
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (ServiceTimeoutException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static LibraryService getLibraryService(String accessToken) {
        return getLibraryService(accessToken, null);
    }
}

{'fraction_non_alphanumeric': 0.08991410362981435, 'fraction_numerical': 0.0022166805209199226, 'mean_word_length': 3.158410138248848, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '6959863', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1774, 'n_words': 361}