⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remoteserverconnector.java

📁 一个java方面的消息订阅发送的源码
💻 JAVA
字号:
/**
 * Redistribution and use of this software and associated documentation
 * ("Software"), with or without modification, are permitted provided
 * that the following conditions are met:
 *
 * 1. Redistributions of source code must retain copyright
 *    statements and notices.  Redistributions must also contain a
 *    copy of this document.
 *
 * 2. Redistributions in binary form must reproduce the
 *    above copyright notice, this list of conditions and the
 *    following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. The name "Exolab" must not be used to endorse or promote
 *    products derived from this Software without prior written
 *    permission of Exoffice Technologies.  For written permission,
 *    please contact info@exolab.org.
 *
 * 4. Products derived from this Software may not be called "Exolab"
 *    nor may "Exolab" appear in their names without prior written
 *    permission of Exoffice Technologies. Exolab is a registered
 *    trademark of Exoffice Technologies.
 *
 * 5. Due credit should be given to the Exolab Project
 *    (http://www.exolab.org/).
 *
 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Copyright 2004-2005 (C) Exoffice Technologies Inc. All Rights Reserved.
 *
 * $Id: RemoteServerConnector.java,v 1.5 2005/06/07 14:33:15 tanderson Exp $
 */
package org.exolab.jms.server.net;

import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.Map;
import javax.naming.Context;
import javax.naming.NamingException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.spice.jndikit.NamingProvider;

import org.exolab.jms.authentication.AuthenticationMgr;
import org.exolab.jms.client.net.JmsServerStubImpl;
import org.exolab.jms.config.Configuration;
import org.exolab.jms.config.types.SchemeType;
import org.exolab.jms.net.orb.ORB;
import org.exolab.jms.net.orb.ORBFactory;
import org.exolab.jms.net.registry.LocalRegistry;
import org.exolab.jms.server.EmbeddedNameService;
import org.exolab.jms.server.ServerConnector;
import org.exolab.jms.server.ServerException;


/**
 * Implementation of the {@link ServerConnector} interface, that provides
 * remoting via an {@link ORB}.
 *
 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
 * @version $Revision: 1.5 $ $Date: 2005/06/07 14:33:15 $
 */
public class RemoteServerConnector implements ServerConnector {

    /**
     * The configuration.
     */
    private final Configuration _config;

    /**
     * The connector configuration.
     */
    private final ConnectorCfg _connector;

    /**
     * The URI to export the server on. This is the URI that the server accepts
     * connections from clients.
     */
    private final String _exportURI;

    /**
     * The URI that clients connect to the server on. This is different to the
     * {@link _exportURI) if clients connect via a webserver.
     */
    private final String _connectURI;

    /**
     * The ORB.
     */
    private ORB _orb;

    /**
     * The logger.
     */
    private static final Log _log = LogFactory.getLog(
            RemoteServerConnector.class);


    /**
     * Construct a new <code>RemoteServerConnector</code>.
     *
     * @param scheme the type of the connector to use
     * @param config the server configuration
     */
    public RemoteServerConnector(SchemeType scheme, Configuration config) {
        if (scheme == null) {
            throw new IllegalArgumentException("Argument 'scheme' is null");
        }
        if (config == null) {
            throw new IllegalArgumentException("Argument 'config' is null");
        }
        _connector = ConnectorCfgFactory.create(scheme, config);
        _config = config;
        _exportURI = _connector.getExportURI();
        _connectURI = _connector.getConnectURI();
    }

    /**
     * Initialises the server interface for the specified connector.
     *
     * @throws ServerException if the interface cannot be initialised
     */
    public void init() throws ServerException {
        try {
            Map properties = _connector.getAcceptProperties();
            _orb = ORBFactory.createORB(AuthenticationMgr.instance(),
                                        properties);
            if (!_connectURI.equals(_exportURI)) {
                _orb.addRoute(_exportURI, _connectURI);
            }
        } catch (RemoteException exception) {
            throw new ServerException(
                    "Failed to create ORB for URI:" + _exportURI, exception);
        }
        try {
            LocalRegistry registry = _orb.getRegistry();

            RemoteServerConnectionFactory server =
                    new RemoteServerConnectionFactory(_orb, _exportURI);
            registry.bind("server", server.getProxy());
            if (_log.isInfoEnabled()) {
                _log.info("Server accepting connections on " + _exportURI);
            }

            if (_config.getServerConfiguration().getEmbeddedJNDI()) {
                NamingProvider provider =
                        EmbeddedNameService.getInstance().getNamingProvider();
                RemoteNamingProvider jndi = new RemoteNamingProvider(
                        provider, _orb, _connector.getJNDIExportURI());
                registry.bind("jndi", jndi.getProxy());
                if (_log.isInfoEnabled()) {
                    _log.info("JNDI service accepting connections on "
                              + _connector.getJNDIExportURI());
                }
            }

            JmsAdminServerImpl admin = new JmsAdminServerImpl(
                    _orb, _connector.getAdminExportURI());
            registry.bind("admin", admin.getProxy());
            if (_log.isInfoEnabled()) {
                _log.info("Admin service accepting connections on "
                          + _connector.getAdminExportURI());
            }

            registry.setReadOnly(true);
        } catch (Exception exception) {
            throw new ServerException(
                    "Failed to initialise the server interface", exception);
        }
    }

    /**
     * Bind any factory object specified in the configuration file to the
     * specified JNDI context.
     *
     * @param context context to bind factory objects
     * @throws NamingException if a naming error occurs
     */
    public void bindConnectionFactories(Context context)
            throws NamingException {
        // put together a list of parameters that the connection factories will
        // need to use to connect to this server
        Map properties = _connector.getConnectProperties();
        Hashtable env = new Hashtable();
        env.putAll(properties);
        ConnectionFactoryHelper.bind(context,
                                     _connector.getConnectionFactories(),
                                     JmsServerStubImpl.class, env);
    }

    /**
     * Close the interface, releasing any resources.
     *
     * @throws ServerException if the interface cannot be closed
     */
    public void close() throws ServerException {
        try {
            _orb.shutdown();
        } catch (RemoteException exception) {
            throw new ServerException(exception.getMessage(), exception);
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -