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

📄 ipcjmsreceiver.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: IpcJmsReceiver.java,v 1.8 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.HashMap;
import java.util.Vector;

import org.exolab.core.ipc.NotifierIfc;


/**
 * The receiver class handles all requests, delegating them to registered
 * {@link NotifierIfc} instances.
 *
 * @version     $Revision: 1.8 $ $Date: 2003/08/17 01:32:26 $
 * @author      <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
 * @see         org.exolab.core.ipc.NotifierIfc
 * @see         org.exolab.jms.server.mipc.IpcJmsServer
 */
public class IpcJmsReceiver implements NotifierIfc {

    /**
     * The set of registered dispatchers
     */
    private HashMap _dispatchers = new HashMap();


    /**
     * Construct a new <code>IpcJmsReceiver</code>
     */
    public IpcJmsReceiver() {
    }

    /**
     * A new request has been received.
     * Carry out the request, and pass back any relevent data.
     *
     * @param object the request
     * @param id the unique identifier of this connection.
     * @return the response. This must never be null.
     */
    public Serializable notify(Object object, String id) {
        Vector request = (Vector) object;
        Serializable result;

        String name = (String) request.get(0);
        NotifierIfc dispatcher = getDispatcher(name);
        if (dispatcher == null) {
            String error = "No dispatcher registered to handle messages " +
                "for: " + name;
            result = pack(Boolean.FALSE, error);
        } else {
            result = dispatcher.notify(object, id);
        }
        return result;
    }

    /**
     * Register a dispatcher to handle requests
     *
     * @param name the name of the dispatcher
     * @param dispatcher the dispatcher
     */
    public synchronized void addDispatcher(String name,
                                           NotifierIfc dispatcher) {
        _dispatchers.put(name, dispatcher);
    }

    /**
     * Returns a dispatcher for the specified name
     *
     * @param name the name of the dipatcher
     * @return a dispatcher corresponding to <code>name</code>, or
     * <code>null</code> if no dispatcher is registered
     */
    public synchronized NotifierIfc getDispatcher(String name) {
        return (NotifierIfc) _dispatchers.get(name);
    }

    /**
     * Invoked if the connection has been broken.
     * This notifies all registered dispatchers, before removing them.
     *
     * @param id the unique identifier of this connection.
     */
    public void disconnection(String id) {
        NotifierIfc[] dispatchers;
        synchronized (_dispatchers) {
            dispatchers = (NotifierIfc[]) _dispatchers.values().toArray(
                new NotifierIfc[0]);
        }
        for (int i = 0; i < dispatchers.length; ++i) {
            dispatchers[i].disconnection(id);
        }

        // clean up the dispatchers
        synchronized (_dispatchers) {
            _dispatchers.clear();
        }
    }


    /**
     * Pack all the data that is required by the server in a vector.
     * Set the size of the vector to be exactly the right size for efficiency.
     *
     * @param success Boolean indicating success or failure of request.
     * @param ob The Object being returned.
     * @return Vector The vector containing all the data.
     */
    private Vector pack(Boolean success, Object ob) {
        Vector v = new Vector(2);
        v.add(success);
        v.add(ob);
        return v;
    }

} //-- IpcJmsReceiver

⌨️ 快捷键说明

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