<commit_before>/*
 * JBoss, Home of Professional Open Source
 * Copyright 2008, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.jboss.remoting.spi;

import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Collections;
import java.io.IOException;
import org.jboss.remoting.ServiceRegistrationException;
import org.jboss.remoting.CloseHandler;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.log.Logger;

/**
 * A registry associating names with services.  Specifically, the name is associated with a handle to a request handler
 * source instance; this handle is owned by the registry, so closing the handle will remove the entry.
 */
public final class NamedServiceRegistry {
    public static final Logger log = Logger.getLogger("org.jboss.remoting.named-registry");

    private final ConcurrentMap<QualifiedName, Handle<RequestHandlerSource>> map = new ConcurrentHashMap<QualifiedName, Handle<RequestHandlerSource>>();

    /**
     * Construct a new empty registry.
     */
    public NamedServiceRegistry() {
    }

    /**
     * Register a service at the given path.  If the given service is closed, an exception will be thrown.  Returns
     * a handle to the service which may be used to unregister this service from the registry.  In addition, if the
     * service is closed, the registration will be automatically removed.  To monitor the registration, add a close
     * handler to the returned handle.
     *
     * @param path the path of the service registration
     * @param service the service
     * @return a handle which can be used to unregister the service
     * @throws IOException if an error occurs
     */
    public Handle<RequestHandlerSource> registerService(final QualifiedName path, final RequestHandlerSource service) throws IOException {
        if (path == null) {
            throw new NullPointerException("path is null");
        }
        if (service == null) {
            throw new NullPointerException("service is null");
        }
        final Handle<RequestHandlerSource> handle = service.getHandle();
        boolean ok = false;<commit_msg>Logger should be private<commit_after>/*
 * JBoss, Home of Professional Open Source
 * Copyright 2008, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.jboss.remoting.spi;

import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Collections;
import java.io.IOException;
import org.jboss.remoting.ServiceRegistrationException;
import org.jboss.remoting.CloseHandler;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.log.Logger;

/**
 * A registry associating names with services.  Specifically, the name is associated with a handle to a request handler
 * source instance; this handle is owned by the registry, so closing the handle will remove the entry.
 */
public final class NamedServiceRegistry {
    private static final Logger log = Logger.getLogger("org.jboss.remoting.named-registry");

    private final ConcurrentMap<QualifiedName, Handle<RequestHandlerSource>> map = new ConcurrentHashMap<QualifiedName, Handle<RequestHandlerSource>>();

    /**
     * Construct a new empty registry.
     */
    public NamedServiceRegistry() {
    }

    /**
     * Register a service at the given path.  If the given service is closed, an exception will be thrown.  Returns
     * a handle to the service which may be used to unregister this service from the registry.  In addition, if the
     * service is closed, the registration will be automatically removed.  To monitor the registration, add a close
     * handler to the returned handle.
     *
     * @param path the path of the service registration
     * @param service the service
     * @return a handle which can be used to unregister the service
     * @throws IOException if an error occurs
     */
    public Handle<RequestHandlerSource> registerService(final QualifiedName path, final RequestHandlerSource service) throws IOException {
        if (path == null) {
            throw new NullPointerException("path is null");
        }
        if (service == null) {
            throw new NullPointerException("service is null");
        }
        final Handle<RequestHandlerSource> handle = service.getHandle();
        boolean ok = false;
{'fraction_non_alphanumeric': 0.06981981981981981, 'fraction_numerical': 0.0054697554697554695, 'mean_word_length': 3.6188707280832095, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2276426', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1528, 'n_words': 718}