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

📄 rmijmsserverstub.java

📁 实现了Jms的服务器源码,支持多种适配器,DB,FTP,支持多种数据库
💻 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 2000-2001,2003 (C) Exoffice Technologies Inc. All Rights Reserved.
 *
 * $Id: RmiJmsServerStub.java,v 1.15 2003/08/07 13:32:54 tanderson Exp $
 *
 * Date         Author  Changes
 * 04/18/2000    jima    Created
 */
package org.exolab.jms.client.rmi;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.util.Hashtable;

import javax.jms.ExceptionListener;
import javax.jms.JMSException;

import org.exolab.jms.client.JmsConnectionStubIfc;
import org.exolab.jms.client.JmsServerStubIfc;
import org.exolab.jms.server.rmi.RemoteJmsServerConnectionIfc;
import org.exolab.jms.server.rmi.RemoteJmsServerIfc;


/**
 * This class is responsible for returning a reference to the remote JMS
 * server.
 *
 * @version     $Revision: 1.15 $ $Date: 2003/08/07 13:32:54 $
 * @author      <a href="mailto:jima@intalio.com">Jim Alateras</a>
 */
public class RmiJmsServerStub implements JmsServerStubIfc {

    /**
     * This is a reference to the remote server stub that is constructed during
     * object initialisation.
     */
    private RemoteJmsServerIfc _delegate = null;

    /**
     * The server URL
     */
    private final String _serverURL;

    /**
     * The exception listener, which is shared by all the connections to the
     * server
     */
    private ExceptionListener _listener = null;

    /**
     * This is the client ping interval time for all rmi clients connecting
     * to this server. A value of 0 disables the ping functionality.
     */
    private final int _pingInterval;

    /**
     * The constructor instantiate server based on the environment variables
     * passed in
     *
     * @param environment the environment
     */
    public RmiJmsServerStub(Hashtable environment) {
        if (environment == null) {
            throw new IllegalArgumentException("Argument environment is null");
        }

        _serverURL = (String) environment.get(RmiJmsConstants.SERVER_URL);
        if (_serverURL == null) {
            throw new IllegalArgumentException(
                "Environment does not contain property " +
                RmiJmsConstants.SERVER_URL);
        }

        String interval = (String) environment.get(
            RmiJmsConstants.RMI_CLIENT_PING_INTERVAL);
        if (interval == null) {
            throw new IllegalArgumentException(
                "Environment does not contain property " +
                RmiJmsConstants.RMI_CLIENT_PING_INTERVAL);
        }
        try {
            _pingInterval = Integer.parseInt(interval);
        } catch (NumberFormatException exception) {
            throw new IllegalArgumentException(
                "Property " + RmiJmsConstants.RMI_CLIENT_PING_INTERVAL +
                " is invalid, value=" + interval);
        }
    }

    /**
     * This class attempts to return a delegate remote stub to the RMI JMS
     * Server. If there are any problems creating or returning the singleton
     * then throw JMSException
     *
     * @return remote reference to stub
     * @throws JMSException if the stub cannot be obtained
     */
    public synchronized RemoteJmsServerIfc getDelegate() throws JMSException {
        if (_delegate == null) {
            try {
                _delegate = (RemoteJmsServerIfc) Naming.lookup(_serverURL);
            } catch (Exception exception) {
                String msg = "Failed to locate server, url=" + _serverURL +
                    ": " + exception.getMessage();
                JMSException error = new JMSException(msg);
                error.setLinkedException(error);
                throw error;
            }
        }

        return _delegate;
    }

    /**
     * Create a connection to the JMS Server. If one cannot be established then
     * throw JMSException exception
     *
     * @param id identity of client
     * @param username the client username
     * @param password  the client password
     * @return created stub
     * @throws JMSException if a connection cannot be established
     */
    public JmsConnectionStubIfc createConnection(String id, String username,
                                                 String password)
        throws JMSException {
        JmsConnectionStubIfc stub = null;

        try {
            RemoteJmsServerConnectionIfc connection =
                getDelegate().createConnection(id, username, password);
            if (connection != null) {
                stub = new RmiJmsConnectionStub(connection, _pingInterval,
                    this);
            } else {
                throw new JMSException("Failed to create remote connection");
            }
        } catch (RemoteException exception) {
            JMSException error = new JMSException(
                "Failed to create connection: " + exception.getMessage());
            error.setLinkedException(exception);
            throw error;
        }

        return stub;
    }

    // implementation of JmsServerStubIfc.setExceptionListener
    public void setExceptionListener(ExceptionListener listener) {
        _listener = listener;
    }

    /**
     * Return a reference to the exception listener
     *
     * @param ExceptionListener
     */
    public ExceptionListener getExceptionListener() {
        return _listener;
    }

} //-- RmiJmsServerStub

⌨️ 快捷键说明

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