<commit_before>/*******************************************************************************
 * Copyright (C) 2016 Push Technology Ltd.
 *
 * 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 com.pushtechnology.adapters.rest.client;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.pushtechnology.adapters.rest.model.latest.Model;
import com.pushtechnology.adapters.rest.model.latest.ServiceConfig;
import com.pushtechnology.adapters.rest.polling.EndpointClient;
import com.pushtechnology.adapters.rest.polling.PollHandlerFactory;
import com.pushtechnology.adapters.rest.polling.ServiceSession;
import com.pushtechnology.adapters.rest.polling.ServiceSessionImpl;
import com.pushtechnology.adapters.rest.publication.PublishingClient;
import com.pushtechnology.adapters.rest.topic.management.TopicManagementClient;

/**
 * Implementation for {@link ServiceSessionGroup}.
 *
 * @author Push Technology Limited
 */
public final class ServiceSessionGroupImpl implements ServiceSessionGroup {
    private static final Logger LOG = LoggerFactory.getLogger(ServiceSessionGroupImpl.class);
    private final Model model;
    private final ScheduledExecutorService executor;
    private final EndpointClient endpointClient;
    private final TopicManagementClient topicManagementClient;
    private final PublishingClient publishingClient;
    private final List<ServiceSession> serviceSessions;

    /**
     * Constructor.
     */
    public ServiceSessionGroupImpl(
            Model model,
            ScheduledExecutorService executor,
            EndpointClient endpointClient,
            TopicManagementClient topicManagementClient,
            PublishingClient publishingClient) {
        this.model = model;
        this.executor = executor;
        this.endpointClient = endpointClient;
        this.topicManagementClient = topicManagementClient;
        this.publishingClient = publishingClient;
        this.serviceSessions = new ArrayList<>();
    }

    @PostConstruct
    @Override
    public synchronized void start() {
        LOG.info("Opening polling component");
        final PollHandlerFactory handlerFactory = new PollHandlerFactoryImpl(publishingClient);
        for (final ServiceConfig service : model.getServices()) {
            final ServiceSession serviceSession = new ServiceSessionImpl(
                executor,
                endpointClient,
                service,
                handlerFactory);
            topicManagementClient.addService(service);
            publishingClient
                .addService(service)
                .thenAccept(new ServiceReadyForPublishing(topicManagementClient, serviceSession));
            serviceSessions.add(serviceSession);
        }
        LOG.info("Opened polling component");
    }

    @PreDestroy
    @Override
    public synchronized void close() {
        LOG.info("Closing polling component");
        serviceSessions.forEach(ServiceSession::stop);
        model.getServices().forEach(publishingClient::removeService);
        LOG.info("Closed polling component");
    }
}<commit_msg>Improved logging messages for ServiceSessionGroupImpl.<commit_after>/*******************************************************************************
 * Copyright (C) 2016 Push Technology Ltd.
 *
 * 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 com.pushtechnology.adapters.rest.client;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.pushtechnology.adapters.rest.model.latest.Model;
import com.pushtechnology.adapters.rest.model.latest.ServiceConfig;
import com.pushtechnology.adapters.rest.polling.EndpointClient;
import com.pushtechnology.adapters.rest.polling.PollHandlerFactory;
import com.pushtechnology.adapters.rest.polling.ServiceSession;
import com.pushtechnology.adapters.rest.polling.ServiceSessionImpl;
import com.pushtechnology.adapters.rest.publication.PublishingClient;
import com.pushtechnology.adapters.rest.topic.management.TopicManagementClient;

/**
 * Implementation for {@link ServiceSessionGroup}.
 *
 * @author Push Technology Limited
 */
public final class ServiceSessionGroupImpl implements ServiceSessionGroup {
    private static final Logger LOG = LoggerFactory.getLogger(ServiceSessionGroupImpl.class);
    private final Model model;
    private final ScheduledExecutorService executor;
    private final EndpointClient endpointClient;
    private final TopicManagementClient topicManagementClient;
    private final PublishingClient publishingClient;
    private final List<ServiceSession> serviceSessions;

    /**
     * Constructor.
     */
    public ServiceSessionGroupImpl(
            Model model,
            ScheduledExecutorService executor,
            EndpointClient endpointClient,
            TopicManagementClient topicManagementClient,
            PublishingClient publishingClient) {
        this.model = model;
        this.executor = executor;
        this.endpointClient = endpointClient;
        this.topicManagementClient = topicManagementClient;
        this.publishingClient = publishingClient;
        this.serviceSessions = new ArrayList<>();
    }

    @PostConstruct
    @Override
    public synchronized void start() {
        LOG.info("Opening service session group");
        final PollHandlerFactory handlerFactory = new PollHandlerFactoryImpl(publishingClient);
        for (final ServiceConfig service : model.getServices()) {
            final ServiceSession serviceSession = new ServiceSessionImpl(
                executor,
                endpointClient,
                service,
                handlerFactory);
            topicManagementClient.addService(service);
            publishingClient
                .addService(service)
                .thenAccept(new ServiceReadyForPublishing(topicManagementClient, serviceSession));
            serviceSessions.add(serviceSession);
        }
        LOG.info("Opened service session group");
    }

    @PreDestroy
    @Override
    public synchronized void close() {
        LOG.info("Closing service session group");
        serviceSessions.forEach(ServiceSession::stop);
        model.getServices().forEach(publishingClient::removeService);
        LOG.info("Closed service session group");
    }
}
{'fraction_non_alphanumeric': 0.11185480756854164, 'fraction_numerical': 0.0025743338911056765, 'mean_word_length': 3.7435897435897436, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '539287', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1799, 'n_words': 486}