All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.remoting3.LocalConnectionProvider Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and Jakarta Messaging BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 35.0.0.Beta1
Show newest version
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2011, 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.remoting3;

import java.net.SocketAddress;
import java.security.Principal;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.Executor;

import org.jboss.remoting3.security.UserInfo;
import org.jboss.remoting3.spi.AbstractHandleableCloseable;
import org.jboss.remoting3.spi.ConnectionHandler;
import org.jboss.remoting3.spi.ConnectionHandlerContext;
import org.jboss.remoting3.spi.ConnectionHandlerFactory;
import org.jboss.remoting3.spi.ConnectionProvider;
import org.jboss.remoting3.spi.ConnectionProviderContext;
import org.jboss.remoting3.spi.SpiUtils;
import org.xnio.Cancellable;
import org.xnio.OptionMap;
import org.xnio.Result;
import org.xnio.ssl.XnioSsl;

import javax.net.ssl.SSLSession;
import javax.security.auth.callback.CallbackHandler;

import static org.xnio.IoUtils.nullCancellable;

final class LocalConnectionProvider extends AbstractHandleableCloseable implements ConnectionProvider {

    private final Executor executor;
    private final ConnectionProviderContext context;

    LocalConnectionProvider(final ConnectionProviderContext context, final Executor executor) {
        super(executor);
        this.context = context;
        this.executor = executor;
    }

    public Cancellable connect(final SocketAddress bindAddress, final SocketAddress destination, final OptionMap connectOptions, final Result result, final CallbackHandler callbackHandler, final XnioSsl xnioSsl) throws IllegalArgumentException {
        context.accept(new ConnectionHandlerFactory() {
            public ConnectionHandler createInstance(final ConnectionHandlerContext connectionContext) {
                return new LoopbackConnectionHandler(connectionContext);
            }
        });
        return nullCancellable();
    }

    public Object getProviderInterface() {
        return NO_PROVIDER_INTERFACES;
    }

    private class LoopbackConnectionHandler extends AbstractHandleableCloseable implements ConnectionHandler {

        private final ConnectionHandlerContext context;

        LoopbackConnectionHandler(final ConnectionHandlerContext context) {
            super(executor);
            this.context = context;
        }

        public Cancellable open(final String serviceType, final Result result, final OptionMap optionMap) {
            LocalChannel channel = new LocalChannel(executor, context);
            try {
                final OpenListener openListener = context.getServiceOpenListener(serviceType);
                if (openListener == null) {
                    throw new ServiceNotFoundException("Unable to find service type '" + serviceType + "'");
                }
                context.getConnectionProviderContext().getExecutor().execute(SpiUtils.getServiceOpenTask(channel.getOtherSide(), openListener));
            } catch (ServiceNotFoundException e) {
                result.setException(e);
                return nullCancellable();
            }
            result.setResult(channel);
            return nullCancellable();
        }

        public Collection getPrincipals() {
            return Collections.emptySet();
        }

        public UserInfo getUserInfo() {
            return new UserInfo() {

                public String getUserName() {
                    return null;
                }

            };
        }

        public SSLSession getSslSession() {
            return null;
        }

        public String getRemoteEndpointName() {
            return context.getConnectionProviderContext().getEndpoint().getName();
        }
    }

    public String toString() {
        return String.format("Remoting local connection provider %x for %s", Integer.valueOf(hashCode()), context.getEndpoint());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy