<commit_before>package org.jboss.cx.remoting;

import org.jboss.cx.remoting.spi.EndpointProvider;

/**
 *
 */
public final class Remoting {

    private static final class EndpointProviderHolder {
        private static final EndpointProvider provider;

        static {
            provider = load();
        }

        private static EndpointProvider load() {
            return load("org.jboss.cx.remoting.core.CoreEndpointProvider");
        }

        private static EndpointProvider load(String name) {
            try {
                return (EndpointProvider) Class.forName(name).newInstance();
            } catch (Exception ex) {
                throw new IllegalArgumentException("Failed to instantiate Remoting endpoint provider: " + ex.getMessage(), ex);
            }
        }
    }

    public static Endpoint createEndpoint(String name) {
        return EndpointProviderHolder.provider.createEndpoint(name);
    }

    // privates

    private Remoting() { /* empty */ }
}<commit_msg>Create simplified static client API<commit_after>package org.jboss.cx.remoting;

import org.jboss.cx.remoting.spi.EndpointProvider;
import org.jboss.cx.remoting.spi.wrapper.SessionWrapper;
import org.jboss.cx.remoting.spi.wrapper.ContextSourceWrapper;
import org.jboss.cx.remoting.core.util.Logger;
import java.net.URI;

/**
 *
 */
public final class Remoting {
    private static final Logger log = Logger.getLogger(Remoting.class);

    private static final class EndpointProviderHolder {
        private static final EndpointProvider provider;

        static {
            provider = load();
        }

        private static EndpointProvider load() {
            return load("org.jboss.cx.remoting.core.CoreEndpointProvider");
        }

        private static EndpointProvider load(String name) {
            try {
                return (EndpointProvider) Class.forName(name).newInstance();
            } catch (Exception ex) {
                throw new IllegalArgumentException("Failed to instantiate Remoting endpoint provider: " + ex.getMessage(), ex);
            }
        }
    }

    public static Endpoint createEndpoint(String name) {
        return EndpointProviderHolder.provider.createEndpoint(name);
    }

    public static Session createEndpointAndSession(String endpointName, URI remoteUri, String userName, char[] password) throws RemotingException {
        final Endpoint endpoint = createEndpoint(endpointName);
        boolean ok = false;
        try {
            final Session session = new SessionWrapper(endpoint.openSession(EndpointLocator.DEFAULT.setEndpointUri(remoteUri).setClientAuthentication(userName, password))) {
                public void close() throws RemotingException {
                    try {
                        super.close();
                    } finally {
                        endpoint.shutdown();
                    }
                }
            };
            ok = true;
            return session;
        } finally {
            if (! ok) {
                endpoint.shutdown();
            }
        }
    }

    public static <I, O> ContextSource<I, O> createEndpointAndOpenService(String endpointName, URI remoteUri, String userName, char[] password, Class<I> requestType, Class<O> replyType, String serviceType, String serviceGroupName) throws RemotingException {
        final Session session = createEndpointAndSession(endpointName, remoteUri, userName, password);
        boolean ok = false;
        try {
            final ContextSource<I, O> service = new ContextSourceWrapper<I, O>(session.openService(ServiceLocator.DEFAULT.setRequestType(requestType).setReplyType(replyType).setServiceGroupName(serviceGroupName).setServiceType(serviceType))) {
                public void close() {
                    try {
                        super.close();
                    } finally {
                        try {
                            session.close();
                        } catch (RemotingException e) {
                            log.error(e, "Failed to close Remoting session");
                        }
                    }
                }
            };
            ok = true;
            return service;
        } finally {
            if (! ok) {
                session.close();
            }
        }
    }

    // privates

    private Remoting() { /* empty */ }
}
{'fraction_non_alphanumeric': 0.08814102564102565, 'fraction_numerical': 0.0, 'mean_word_length': 1.952027027027027, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7655210', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1020, 'n_words': 249}