<commit_before>/*
 *  Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *  WSO2 Inc. licenses this file to you 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 org.wso2.carbon.transport.http.netty.internal;

import org.wso2.carbon.transport.http.netty.listener.CarbonNettyServerInitializer;

import java.util.HashMap;
import java.util.Map;

/**
 * DataHolder for the Netty transport.
 */
public class NettyTransportDataHolder {

    private static NettyTransportDataHolder instance = new NettyTransportDataHolder();
    private Map<String, CarbonNettyServerInitializer> channelInitializers = new HashMap<>();


    private NettyTransportDataHolder() {

    }

    public static NettyTransportDataHolder getInstance() {
        return instance;
    }

    public synchronized void addNettyChannelInitializer(String key, CarbonNettyServerInitializer initializer) {
        this.channelInitializers.put(key, initializer);
    }


    public CarbonNettyServerInitializer getChannelInitializer(String key) {
        return channelInitializers.get(key);
    }


    public void removeNettyChannelInitializer(String key) {
        channelInitializers.remove(key);
    }

}<commit_msg>Added log.error if there is a duplicate listener registration<commit_after>/*
 *  Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *  WSO2 Inc. licenses this file to you 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 org.wso2.carbon.transport.http.netty.internal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wso2.carbon.transport.http.netty.listener.CarbonNettyServerInitializer;

import java.util.HashMap;
import java.util.Map;

/**
 * DataHolder for the Netty transport.
 */
public class NettyTransportDataHolder {
    private static final Logger log = LoggerFactory.getLogger(NettyTransportDataHolder.class);

    private static NettyTransportDataHolder instance = new NettyTransportDataHolder();
    private Map<String, CarbonNettyServerInitializer> channelInitializers = new HashMap<>();

    private NettyTransportDataHolder() {

    }

    public static NettyTransportDataHolder getInstance() {
        return instance;
    }

    public synchronized void addNettyChannelInitializer(String key, CarbonNettyServerInitializer initializer) {
        if (channelInitializers.get(key) == null) {
            this.channelInitializers.put(key, initializer);
        } else {
            log.error("Netty transport listener " + key + " already registered");
        }
    }

    public CarbonNettyServerInitializer getChannelInitializer(String key) {
        return channelInitializers.get(key);
    }


    public void removeNettyChannelInitializer(String key) {
        channelInitializers.remove(key);
    }

}
{'fraction_non_alphanumeric': 0.08209150326797386, 'fraction_numerical': 0.009411764705882352, 'mean_word_length': 3.7825, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '685940', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1032, 'n_words': 328}