<commit_before>package io.joynr.messaging;

/*
 * #%L
 * %%
 * Copyright (C) 2011 - 2013 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 io.joynr.capabilities.LocalCapabilitiesDirectory;
import io.joynr.exceptions.JoynrRuntimeException;
import io.joynr.proxy.Callback;
import io.joynr.proxy.ProxyInvocationHandlerFactory;
import joynr.types.ChannelUrlInformation;

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

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;

@Singleton
public class LocalChannelUrlDirectoryClientImpl implements LocalChannelUrlDirectoryClient {

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

    private final GlobalChannelUrlDirectoryClient channelUrlDirectoryClient;
    private final ChannelUrlStore channelUrlStore;

    @Inject
    // CHECKSTYLE:OFF
    public LocalChannelUrlDirectoryClientImpl(@Named(ConfigurableMessagingSettings.PROPERTY_DISCOVERY_DIRECTORIES_DOMAIN) String discoveryDirectoriesDomain,
                                              @Named(ConfigurableMessagingSettings.PROPERTY_CHANNEL_URL_DIRECTORY_CHANNEL_ID) String channelUrlDirectoryChannelId,
                                              @Named(MessagingPropertyKeys.CHANNELURLDIRECTORYURL) String channelUrlDirectoryUrl,
                                              @Named(ConfigurableMessagingSettings.PROPERTY_CAPABILITIES_DIRECTORY_CHANNEL_ID) String capabilitiesDirectoryChannelId,
                                              @Named(MessagingPropertyKeys.CAPABILITIESDIRECTORYURL) String capabilitiesDirectoryUrl,
                                              LocalCapabilitiesDirectory localCapabilitiesDirectory,
                                              ChannelUrlStore channelUrlStore,
                                              MessagingSettings settings,
                                              ProxyInvocationHandlerFactory proxyInvocationHandlerFactory) {
        // CHECKSTYLE:ON
        this.channelUrlDirectoryClient = new GlobalChannelUrlDirectoryClient(discoveryDirectoriesDomain,
                                                                             localCapabilitiesDirectory,
                                                                             proxyInvocationHandlerFactory);
        this.channelUrlStore = channelUrlStore;
        channelUrlStore.registerChannelUrl(channelUrlDirectoryChannelId, channelUrlDirectoryUrl);
        channelUrlStore.registerChannelUrl(capabilitiesDirectoryChannelId, capabilitiesDirectoryUrl);

    }

    @Override
    public void registerChannelUrls(final String channelId, final ChannelUrlInformation channelUrlInformation) {
        logger.debug("registered {} for {}", channelId, channelUrlInformation);

        channelUrlStore.registerChannelUrls(channelId, channelUrlInformation);
        try {
            channelUrlDirectoryClient.registerChannelUrls(new Callback<Void>() {

                @Override
                public void onSuccess(Void result) {
                    logger.debug("successfully registered channelId: {} channelUrls: {}",
                                 channelId,
                                 channelUrlInformation.getUrls());
                }

                @Override
                public void onFailure(JoynrRuntimeException e) {
                    //Currently not retrying. Using long TTL instead.
                    logger.error("exception while registering channelId: {} reason: {}", channelId, e.getMessage());

                }
            }, channelId, channelUrlInformation);

        } catch (JoynrRuntimeException e) {
            logger.error("exception while registering channelId: {} reason: {}", channelId, e.getMessage());
        }
    }

    @Override
    public void unregisterChannelUrls(String channelId) {
        logger.debug("removing {}", channelId);

        channelUrlStore.removeChannelUrls(channelId);
        channelUrlDirectoryClient.unregisterChannelUrls(channelId);
    }

    @Override
    public ChannelUrlInformation getUrlsForChannel(String channelId) {
        logger.debug("get URLs for Channel: {}", channelId);

        // retrieve from cache
        ChannelUrlInformation channelUrlInformation = channelUrlStore.findChannelEntry(channelId);
        if (channelUrlInformation.getUrls().isEmpty()) {
            // retrieve from remote store
            synchronized (channelUrlInformation) {
                if (channelUrlInformation.getUrls().isEmpty()) {
                    ChannelUrlInformation remoteChannelUrlInformation = channelUrlDirectoryClient.getUrlsForChannel(channelId);
                    if (remoteChannelUrlInformation != null) {
                        channelUrlInformation.setUrls(remoteChannelUrlInformation.getUrls());
                    }
                    if (remoteChannelUrlInformation.getUrls().size() == 0) {
                        logger.error("No channelurls found for channel {}", channelId);
                    }
                }
            }
        }

        return channelUrlInformation;
    }

}<commit_msg>[Java] Fixed null pointer reference (findbugs)<commit_after>package io.joynr.messaging;

/*
 * #%L
 * %%
 * Copyright (C) 2011 - 2013 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 io.joynr.capabilities.LocalCapabilitiesDirectory;
import io.joynr.exceptions.JoynrRuntimeException;
import io.joynr.proxy.Callback;
import io.joynr.proxy.ProxyInvocationHandlerFactory;
import joynr.types.ChannelUrlInformation;

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

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;

@Singleton
public class LocalChannelUrlDirectoryClientImpl implements LocalChannelUrlDirectoryClient {

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

    private final GlobalChannelUrlDirectoryClient channelUrlDirectoryClient;
    private final ChannelUrlStore channelUrlStore;

    @Inject
    // CHECKSTYLE:OFF
    public LocalChannelUrlDirectoryClientImpl(@Named(ConfigurableMessagingSettings.PROPERTY_DISCOVERY_DIRECTORIES_DOMAIN) String discoveryDirectoriesDomain,
                                              @Named(ConfigurableMessagingSettings.PROPERTY_CHANNEL_URL_DIRECTORY_CHANNEL_ID) String channelUrlDirectoryChannelId,
                                              @Named(MessagingPropertyKeys.CHANNELURLDIRECTORYURL) String channelUrlDirectoryUrl,
                                              @Named(ConfigurableMessagingSettings.PROPERTY_CAPABILITIES_DIRECTORY_CHANNEL_ID) String capabilitiesDirectoryChannelId,
                                              @Named(MessagingPropertyKeys.CAPABILITIESDIRECTORYURL) String capabilitiesDirectoryUrl,
                                              LocalCapabilitiesDirectory localCapabilitiesDirectory,
                                              ChannelUrlStore channelUrlStore,
                                              MessagingSettings settings,
                                              ProxyInvocationHandlerFactory proxyInvocationHandlerFactory) {
        // CHECKSTYLE:ON
        this.channelUrlDirectoryClient = new GlobalChannelUrlDirectoryClient(discoveryDirectoriesDomain,
                                                                             localCapabilitiesDirectory,
                                                                             proxyInvocationHandlerFactory);
        this.channelUrlStore = channelUrlStore;
        channelUrlStore.registerChannelUrl(channelUrlDirectoryChannelId, channelUrlDirectoryUrl);
        channelUrlStore.registerChannelUrl(capabilitiesDirectoryChannelId, capabilitiesDirectoryUrl);

    }

    @Override
    public void registerChannelUrls(final String channelId, final ChannelUrlInformation channelUrlInformation) {
        logger.debug("registered {} for {}", channelId, channelUrlInformation);

        channelUrlStore.registerChannelUrls(channelId, channelUrlInformation);
        try {
            channelUrlDirectoryClient.registerChannelUrls(new Callback<Void>() {

                @Override
                public void onSuccess(Void result) {
                    logger.debug("successfully registered channelId: {} channelUrls: {}",
                                 channelId,
                                 channelUrlInformation.getUrls());
                }

                @Override
                public void onFailure(JoynrRuntimeException e) {
                    //Currently not retrying. Using long TTL instead.
                    logger.error("exception while registering channelId: {} reason: {}", channelId, e.getMessage());

                }
            }, channelId, channelUrlInformation);

        } catch (JoynrRuntimeException e) {
            logger.error("exception while registering channelId: {} reason: {}", channelId, e.getMessage());
        }
    }

    @Override
    public void unregisterChannelUrls(String channelId) {
        logger.debug("removing {}", channelId);

        channelUrlStore.removeChannelUrls(channelId);
        channelUrlDirectoryClient.unregisterChannelUrls(channelId);
    }

    @Override
    public ChannelUrlInformation getUrlsForChannel(String channelId) {
        logger.debug("get URLs for Channel: {}", channelId);

        // retrieve from cache
        ChannelUrlInformation channelUrlInformation = channelUrlStore.findChannelEntry(channelId);
        if (channelUrlInformation.getUrls().isEmpty()) {
            // retrieve from remote store
            synchronized (channelUrlInformation) {
                if (channelUrlInformation.getUrls().isEmpty()) {
                    ChannelUrlInformation remoteChannelUrlInformation = channelUrlDirectoryClient.getUrlsForChannel(channelId);
                    if (remoteChannelUrlInformation == null || remoteChannelUrlInformation.getUrls() == null
                            || remoteChannelUrlInformation.getUrls().isEmpty()) {
                        logger.error("No channelurls found for channel {}", channelId);
                    } else {
                        channelUrlInformation.setUrls(remoteChannelUrlInformation.getUrls());
                    }
                }
            }
        }

        return channelUrlInformation;
    }

}
{'fraction_non_alphanumeric': 0.06775680612333652, 'fraction_numerical': 0.0025223971470818476, 'mean_word_length': 2.3600233781414377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3528098', 'n_tokens_mistral': 2554, 'n_tokens_neox': 2458, 'n_words': 568}