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

📄 ipcjmsadminconnection.java

📁 实现了Jms的服务器源码,支持多种适配器,DB,FTP,支持多种数据库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * 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-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
 *
 * $Id: IpcJmsAdminConnection.java,v 1.10 2003/08/17 01:32:26 tanderson Exp $
 *
 * Date         Author  Changes
 * $Date       jimm    Created
 */

package org.exolab.jms.server.mipc;

import java.io.Serializable;
import java.util.Vector;

import javax.jms.JMSException;
import javax.jms.JMSSecurityException;

import org.exolab.core.ipc.NotifierIfc;
import org.exolab.jms.server.AdminConnection;
import org.exolab.jms.server.AdminConnectionManager;


/**
 * This is the server side receiver for admin requests.
 *
 * @version     $Revision: 1.10 $ $Date: 2003/08/17 01:32:26 $
 * @author      <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
 * @see         org.exolab.jms.administration.mipc.IpcJmsAdminConnection
 */
public class IpcJmsAdminConnection implements NotifierIfc {

    /**
     * Default constructor.
     *
     */
    public IpcJmsAdminConnection() {
    }


    /**
     * A new request has been received.
     * Carry out the request, and pass back any relevent data.
     *
     * @param ob The data received,
     * @param id The id of the calling connection, not used by the client.
     * @return Object Return any requested result. This must never be null.
     *
     */
    public Serializable notify(Object ob, String id) {
        Vector v = (Vector) ob;
        String func = (String) v.get(1);
        Serializable result = null;
        String identifierId = (String) v.get(2);

        if (func.equals("createConnection")) {
            result = createConnection(id, (String) v.get(3), (String) v.get(4));
        } else if (func.equals("addDurableConsumer")) {
            result = addDurableConsumer((String) v.get(3), (String) v.get(4),
                (String) v.get(2));
        } else if (func.equals("removeDurableConsumer")) {
            result = removeDurableConsumer((String) v.get(3),
                (String) v.get(2));
        } else if (func.equals("durableConsumerExists")) {
            result = durableConsumerExists((String) v.get(3),
                (String) v.get(2));
        } else if (func.equals("getDurableConsumers")) {
            result = getDurableConsumers((String) v.get(3), (String) v.get(2));
        } else if (func.equals("unregisterConsumer")) {
            result = unregisterConsumer((String) v.get(3), (String) v.get(2));
        } else if (func.equals("isConnected")) {
            result = isConnected((String) v.get(3), (String) v.get(2));
        } else if (func.equals("getAllDestinations")) {
            result = getAllDestinations((String) v.get(2));
        } else if (func.equals("addDestination")) {
            result = addDestination((String) v.get(3), (Boolean) v.get(4),
                (String) v.get(2));
        } else if (func.equals("removeDestination")) {
            result = removeDestination((String) v.get(3), (String) v.get(2));
        } else if (func.equals("destinationExists")) {
            result = destinationExists((String) v.get(3), (String) v.get(2));
        } else if (func.equals("getDurableConsumerMessageCount")) {
            result = getDurableConsumerMessageCount((String) v.get(3),
                (String) v.get(4), (String) v.get(2));
        } else if (func.equals("getQueueMessageCount")) {
            result = getQueueMessageCount((String) v.get(3), (String) v.get(2));
        } else if (func.equals("stopServer")) {
            result = stopServer((String) v.get(2));
        } else if (func.equals("addUser")) {
            result = addUser((String) v.get(3), (String) v.get(4),
                (String) v.get(2));
        } else if (func.equals("changePassword")) {
            result = changePassword((String) v.get(3), (String) v.get(4),
                (String) v.get(2));
        } else if (func.equals("removeUser")) {
            result = removeUser((String) v.get(3), (String) v.get(2));
        } else if (func.equals("getAllUsers")) {
            result = getAllUsers((String) v.get(2));
        } else if (func.equals("purgeMessages")) {
            result = purgeMessages((String) v.get(2));
        } else {
            String st = ("Unknown request received: " + func);
            System.err.println(st);
            result = pack(new Boolean(false), st);
        }

        return result;
    }

    /**
     * The connection has been broken.
     *
     * @param id   the unique identifier of this connection.
     *
     */
    public void disconnection(String id) {
    }

    /**
     * A new connection request has been made.
     *
     * @param ipcId The unique IPC id of this connection.
     * @param username the client's username
     * @param password the client's password
     * @return Vector The result of the request.
     */
    private Vector createConnection(String ipcId,
                                    String username,
                                    String password) {
        Vector result;

        try {
            AdminConnection connection =
                AdminConnectionManager.instance().createConnection(
                    ipcId, username, password);
            result = pack(Boolean.TRUE, connection.getIdentifierId());
        } catch (JMSException exception) {
            result = pack(Boolean.FALSE, exception);
        }

        return result;
    }

    /**
     * Add a durable consumer to for a topic
     *
     * @param topic         the name of the topic destination
     * @param name          consumer name
     * @param identifierId  the unique identifier for this connection
     * @return Vector      The result of the operation
     */
    private Vector addDurableConsumer(String topic, String name,
                                      String identifierId) {
        boolean result;

        try {
            result =
                getAdminConnection(identifierId).addDurableConsumer(topic, name);
            return pack(Boolean.TRUE, new Boolean(result));
        } catch (JMSException exception) {
            return pack(Boolean.FALSE, exception);
        }
    }

    /**
     * Remove the specified durable consumer
     *
     * @param name - the consumer name
     * @param identifierId  the unique identifier for this connection
     * @return Vector - the result of the operation
     */
    private Vector removeDurableConsumer(String name, String identifierId) {
        boolean result;

        try {
            result =
                getAdminConnection(identifierId).removeDurableConsumer(name);
            return pack(Boolean.TRUE, new Boolean(result));
        } catch (JMSException exception) {
            return pack(Boolean.FALSE, exception);
        }
    }

    /**
     * Determine whether the specified durable consumer exists
     *
     * @param name - the consumer name
     * @param identifierId  the unique identifier for this connection
     * @return Vector - the result of the operation
     */
    private Vector durableConsumerExists(String name, String identifierId) {
        boolean result;

        try {
            result =
                getAdminConnection(identifierId).durableConsumerExists(name);
            return pack(Boolean.TRUE, new Boolean(result));
        } catch (JMSException exception) {
            return pack(Boolean.FALSE, exception);
        }
    }

    /**
     * Return a list of durable consumers for the specified topic
     *
     * @param topic - the queue/topic name
     * @param identifierId  the unique identifier for this connection
     * @return Vector - the result of the operation
     *
     */
    private Vector getDurableConsumers(String topic, String identifierId) {
        Vector consumers;

        try {
            consumers =
                getAdminConnection(identifierId).getDurableConsumers(topic);
            return pack(Boolean.TRUE, consumers);
        } catch (JMSException exception) {
            return pack(Boolean.FALSE, exception);
        }
    }

    /**
     * Deactivate the specified durable consumer
     *
     * @param name - the name of the durable consumer
     * @param identifierId  the unique identifier for this connection
     * @return Vector - the result of the operation
     */
    private Vector unregisterConsumer(String name, String identifierId) {
        boolean result;

        try {
            result = getAdminConnection(identifierId).unregisterConsumer(name);
            return pack(Boolean.TRUE, new Boolean(result));
        } catch (JMSException exception) {
            return pack(Boolean.FALSE, exception);
        }
    }

    /**
     * Check to see if the given consumer is currently connected to the

⌨️ 快捷键说明

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