<commit_before>package io.joynr.dispatching;

/*
 * #%L
 * %%
 * Copyright (C) 2011 - 2015 BMW Car IT GmbH
 * %%
 * 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.
 * #L%
 */

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.inject.Singleton;

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

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.Inject;

import io.joynr.dispatching.subscription.PublicationManager;
import io.joynr.dispatching.subscription.SubscriptionManager;
import io.joynr.exceptions.JoynrException;
import io.joynr.exceptions.JoynrRuntimeException;
import io.joynr.messaging.MessagingQos;
import io.joynr.messaging.routing.MessageRouter;
import io.joynr.provider.ProviderCallback;

import joynr.JoynrMessage;
import joynr.OneWayRequest;
import joynr.Reply;
import joynr.Request;
import joynr.SubscriptionPublication;
import joynr.SubscriptionRequest;
import joynr.SubscriptionStop;

public class DispatcherImpl implements Dispatcher {

    private static final Logger logger = LoggerFactory.getLogger(DispatcherImpl.class);
    private final JoynrMessageFactory joynrMessageFactory;
    private RequestReplyManager requestReplyManager;
    private SubscriptionManager subscriptionManager;
    private PublicationManager publicationManager;
    private final MessageRouter messageRouter;
    private ObjectMapper objectMapper;

    @Inject
    @Singleton
    // CHECKSTYLE:OFF
    public DispatcherImpl(RequestReplyManager requestReplyManager,
                          SubscriptionManager subscriptionManager,
                          PublicationManager publicationManager,
                          MessageRouter messageRouter,
                          JoynrMessageFactory joynrMessageFactory,
                          ObjectMapper objectMapper) {
        this.requestReplyManager = requestReplyManager;
        this.subscriptionManager = subscriptionManager;
        this.publicationManager = publicationManager;
        this.messageRouter = messageRouter;
        this.joynrMessageFactory = joynrMessageFactory;
        this.objectMapper = objectMapper;
    }

    // CHECKSTYLE:ON

    @Override
    public void sendSubscriptionRequest(String fromParticipantId,
                                        Set<String> toParticipantIds,
                                        SubscriptionRequest subscriptionRequest,
                                        MessagingQos qosSettings,
                                        boolean broadcast) throws IOException {
        for (String toParticipantId : toParticipantIds) {
            JoynrMessage message = joynrMessageFactory.createSubscriptionRequest(fromParticipantId,
                                                                                 toParticipantId,
                                                                                 subscriptionRequest,
                                                                                 DispatcherUtils.convertTtlToExpirationDate(qosSettings.getRoundTripTtl_ms()),
                                                                                 broadcast);

            messageRouter.route(message);
        }
    }

    @Override
    public void sendSubscriptionStop(String fromParticipantId,
                                     Set<String> toParticipantIds,
                                     SubscriptionStop subscriptionStop,
                                     MessagingQos messagingQos) throws IOException {
        for (String toParticipantId : toParticipantIds) {
            JoynrMessage message = joynrMessageFactory.createSubscriptionStop(fromParticipantId,
                                                                              toParticipantId,
                                                                              subscriptionStop,
                                                                              DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms()));
            messageRouter.route(message);
        }

    }

    @Override
    public void sendSubscriptionPublication(String fromParticipantId,
                                            Set<String> toParticipantIds,
                                            SubscriptionPublication publication,
                                            MessagingQos qosSettings) throws IOException {

        for (String toParticipantId : toParticipantIds) {
            JoynrMessage message = joynrMessageFactory.createPublication(fromParticipantId,
                                                                         toParticipantId,
                                                                         publication,
                                                                         DispatcherUtils.convertTtlToExpirationDate(qosSettings.getRoundTripTtl_ms()));
            messageRouter.route(message);
        }
    }

    public void sendReply(final String fromParticipantId, final String toParticipantId, Reply reply, long expiryDate)
                                                                                                                     throws IOException {
        JoynrMessage message = joynrMessageFactory.createReply(fromParticipantId,
                                                               toParticipantId,
                                                               reply,
                                                               DispatcherUtils.convertTtlToExpirationDate(expiryDate));
        messageRouter.route(message);<commit_msg>[Java] Clean up DispatcherImpl<commit_after>package io.joynr.dispatching;

/*
 * #%L
 * %%
 * Copyright (C) 2011 - 2015 BMW Car IT GmbH
 * %%
 * 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.
 * #L%
 */

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.inject.Singleton;

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

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.Inject;

import io.joynr.common.ExpiryDate;
import io.joynr.dispatching.subscription.PublicationManager;
import io.joynr.dispatching.subscription.SubscriptionManager;
import io.joynr.exceptions.JoynrException;
import io.joynr.exceptions.JoynrRuntimeException;
import io.joynr.messaging.MessagingQos;
import io.joynr.messaging.routing.MessageRouter;
import io.joynr.provider.ProviderCallback;

import joynr.JoynrMessage;
import joynr.OneWayRequest;
import joynr.Reply;
import joynr.Request;
import joynr.SubscriptionPublication;
import joynr.SubscriptionRequest;
import joynr.SubscriptionStop;

public class DispatcherImpl implements Dispatcher {

    private static final Logger logger = LoggerFactory.getLogger(DispatcherImpl.class);
    private final JoynrMessageFactory joynrMessageFactory;
    private RequestReplyManager requestReplyManager;
    private SubscriptionManager subscriptionManager;
    private PublicationManager publicationManager;
    private final MessageRouter messageRouter;
    private ObjectMapper objectMapper;

    @Inject
    @Singleton
    // CHECKSTYLE:OFF
    public DispatcherImpl(RequestReplyManager requestReplyManager,
                          SubscriptionManager subscriptionManager,
                          PublicationManager publicationManager,
                          MessageRouter messageRouter,
                          JoynrMessageFactory joynrMessageFactory,
                          ObjectMapper objectMapper) {
        this.requestReplyManager = requestReplyManager;
        this.subscriptionManager = subscriptionManager;
        this.publicationManager = publicationManager;
        this.messageRouter = messageRouter;
        this.joynrMessageFactory = joynrMessageFactory;
        this.objectMapper = objectMapper;
    }

    // CHECKSTYLE:ON

    @Override
    public void sendSubscriptionRequest(String fromParticipantId,
                                        Set<String> toParticipantIds,
                                        SubscriptionRequest subscriptionRequest,
                                        MessagingQos messagingQos,
                                        boolean broadcast) throws IOException {
        for (String toParticipantId : toParticipantIds) {
            JoynrMessage message = joynrMessageFactory.createSubscriptionRequest(fromParticipantId,
                                                                                 toParticipantId,
                                                                                 subscriptionRequest,
                                                                                 ExpiryDate.fromRelativeTtl(messagingQos.getRoundTripTtl_ms()),
                                                                                 broadcast);

            messageRouter.route(message);
        }
    }

    @Override
    public void sendSubscriptionStop(String fromParticipantId,
                                     Set<String> toParticipantIds,
                                     SubscriptionStop subscriptionStop,
                                     MessagingQos messagingQos) throws IOException {
        for (String toParticipantId : toParticipantIds) {
            JoynrMessage message = joynrMessageFactory.createSubscriptionStop(fromParticipantId,
                                                                              toParticipantId,
                                                                              subscriptionStop,
                                                                              ExpiryDate.fromRelativeTtl(messagingQos.getRoundTripTtl_ms()));
            messageRouter.route(message);
        }

    }

    @Override
    public void sendSubscriptionPublication(String fromParticipantId,
                                            Set<String> toParticipantIds,
                                            SubscriptionPublication publication,
                                            MessagingQos messagingQos) throws IOException {

        for (String toParticipantId : toParticipantIds) {
            JoynrMessage message = joynrMessageFactory.createPublication(fromParticipantId,
                                                                         toParticipantId,
                                                                         publication,
                                                                         ExpiryDate.fromRelativeTtl(messagingQos.getRoundTripTtl_ms()));
            messageRouter.route(message);
        }
    }

    public void sendReply(final String fromParticipantId, final String toParticipantId, Reply reply, long expiryDateMs)
                                                                                                                       throws IOException {
        JoynrMessage message = joynrMessageFactory.createReply(fromParticipantId,
                                                               toParticipantId,
                                                               reply,
                                                               ExpiryDate.fromAbsolute(expiryDateMs));
        messageRouter.route(message);
{'fraction_non_alphanumeric': 0.050802354648818646, 'fraction_numerical': 0.002257882428836384, 'mean_word_length': 1.5983658076681333, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 108, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1117946', 'n_tokens_mistral': 2575, 'n_tokens_neox': 2438, 'n_words': 592}