<commit_before>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file 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.as.webservices.service;

import javax.management.MBeanServer;

import org.jboss.as.webservices.util.WSServices;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceBuilder.DependencyType;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceController.Mode;
import org.jboss.msc.service.ServiceListener;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import org.jboss.ws.common.management.DefaultEndpointRegistry;
import org.jboss.ws.common.management.ManagedEndpointRegistry;
import org.jboss.wsf.spi.management.EndpointRegistry;

/**
 * The service for the endpoint registry
 *
 * @author <EMAIL>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public final class EndpointRegistryService implements Service<EndpointRegistry> {

    private static final ServiceName MBEAN_SERVER_NAME = ServiceName.JBOSS.append("mbean", "server");
    private static final EndpointRegistryService INSTANCE = new EndpointRegistryService();

    private volatile EndpointRegistry registry;
    private final InjectedValue<MBeanServer> injectedMBeanServer = new InjectedValue<MBeanServer>();

    private EndpointRegistryService() {
        // forbidden inheritance
    }

    @Override
    public EndpointRegistry getValue() {
        return registry;
    }

    @Override
    public void start(final StartContext context) throws StartException {
        if (injectedMBeanServer.getValue() != null) {
            final ManagedEndpointRegistry managedEndpointRegistry = new ManagedEndpointRegistry();
            managedEndpointRegistry.setMbeanServer(injectedMBeanServer.getValue());
            registry = managedEndpointRegistry;
        } else {
            registry = new DefaultEndpointRegistry();
        }
    }

    @Override
    public void stop(final StopContext context) {
    }

    private InjectedValue<MBeanServer> getMBeanServerInjector() {
        return injectedMBeanServer;
    }

    public static ServiceController<?> install(final ServiceTarget serviceTarget, final ServiceListener<Object> listener) {
        final ServiceBuilder<EndpointRegistry> builder = serviceTarget.addService(WSServices.REGISTRY_SERVICE, INSTANCE);
        builder.addDependency(DependencyType.REQUIRED, MBEAN_SERVER_NAME, MBeanServer.class, INSTANCE.getMBeanServerInjector());
        builder.addListener(listener);
        builder.setInitialMode(Mode.ACTIVE);
        return builder.install();
    }

}<commit_msg>[AS7-3413] fix WS endpoint registry integration code<commit_after>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file 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.as.webservices.service;

import javax.management.MBeanServer;

import org.jboss.as.webservices.util.WSServices;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceBuilder.DependencyType;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceController.Mode;
import org.jboss.msc.service.ServiceListener;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import org.jboss.ws.common.management.ManagedEndpointRegistry;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.management.EndpointRegistry;
import org.jboss.wsf.spi.management.EndpointRegistryFactory;

/**
 * The service for the endpoint registry
 *
 * @author <EMAIL>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public final class EndpointRegistryService implements Service<EndpointRegistry> {

    private static final ServiceName MBEAN_SERVER_NAME = ServiceName.JBOSS.append("mbean", "server");
    private static final EndpointRegistryService INSTANCE = new EndpointRegistryService();
    private final InjectedValue<MBeanServer> injectedMBeanServer = new InjectedValue<MBeanServer>();
    private volatile EndpointRegistry registry;

    private EndpointRegistryService() {
    }

    @Override
    public EndpointRegistry getValue() {
        return registry;
    }

    @Override
    public void start(final StartContext context) throws StartException {
        final SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
        registry = spiProvider.getSPI(EndpointRegistryFactory.class).getEndpointRegistry();
        if (injectedMBeanServer.getValue() != null && registry instanceof ManagedEndpointRegistry) {
            final ManagedEndpointRegistry managedEndpointRegistry = (ManagedEndpointRegistry)registry;
            managedEndpointRegistry.setMbeanServer(injectedMBeanServer.getValue());
        }
    }

    @Override
    public void stop(final StopContext context) {
    }

    private InjectedValue<MBeanServer> getMBeanServerInjector() {
        return injectedMBeanServer;
    }

    public static ServiceController<?> install(final ServiceTarget serviceTarget, final ServiceListener<Object> listener) {
        final ServiceBuilder<EndpointRegistry> builder = serviceTarget.addService(WSServices.REGISTRY_SERVICE, INSTANCE);
        builder.addDependency(DependencyType.REQUIRED, MBEAN_SERVER_NAME, MBeanServer.class, INSTANCE.getMBeanServerInjector());
        builder.addListener(listener);
        builder.setInitialMode(Mode.ACTIVE);
        return builder.install();
    }

}
{'fraction_non_alphanumeric': 0.08413150401242557, 'fraction_numerical': 0.005047890240745535, 'mean_word_length': 4.418653576437587, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '5331185', 'n_tokens_mistral': 2135, 'n_tokens_neox': 2050, 'n_words': 608}