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

📄 ipcjmssessionlist.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-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
 *
 * $Id: IpcJmsSessionList.java,v 1.6 2003/08/07 13:33:09 tanderson Exp $
 *
 * Date         Author  Changes
 * $Date	    jimm    Created
 */


package org.exolab.jms.server.mipc;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;

import org.exolab.core.mipc.MultiplexConnectionIfc;
import org.exolab.core.mipc.ObjectChannel;
import org.exolab.jms.server.JmsServerSession;


/**
 * Keep a list of all session Client connections for a client. All sessions
 * for a client are multiplexed through a single connection. Ensure the
 * same connection is used for all the clients sessions, and that the
 * connection is not destroyed until the last session for the client is
 * shutdown.
 *
 * @version     $Revision: 1.6 $ $Date: 2003/08/07 13:33:09 $
 * @author      <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
 * @see         org.exolab.jms.server.mipc.IpcJmsServer
 * @see		org.exolab.jms.server.mipc.IpcJmsSessionSender
 */
public class IpcJmsSessionList {

    /**
     * The client connection.
     */
    private ObjectChannel _client;

    /**
     * The list of session senders
     */
    private HashMap _list;


    /**
     * Create a connection to the client listener for sending JmsMessages.
     *
     * @param connection The MultiplexConnection between client and server
     * @exception IOException If a connection error results.
     *
     */
    public IpcJmsSessionList(MultiplexConnectionIfc connection)
        throws IOException {
        _list = new HashMap(10);
        _client = new ObjectChannel("message", connection);
    }

    /**
     * Add a new session sender for the client. If its not already active.
     *
     * @param session The session to add a notifier on
     */
    public synchronized void add(JmsServerSession session) {
        if (!_list.containsKey(session.getSessionId())) {
            _list.put(session.getSessionId(),
                new IpcJmsSessionSender(_client, session));
        }
    }

    /**
     * Remove a sesson notifier. If this is the last session for this client
     * close the client connection.
     *
     * @param session The session to remove the notifier from
     * @return boolean True there are no more connections for this client
     *
     */
    public synchronized boolean remove(JmsServerSession session) {
        IpcJmsSessionSender sender =
            (IpcJmsSessionSender) _list.remove(session.getSessionId());
        boolean result = false;

        if (sender != null) {
            sender.close();
        }
        if (_list.isEmpty()) {
            closeConnection();
            _list = null;
            result = true;
        }

        return result;
    }

    /**
     * Remove all session notfiers and close the client connection.
     */
    public synchronized void removeAll() {
        Iterator iterator = _list.values().iterator();
        while (iterator.hasNext()) {
            IpcJmsSessionSender sender = (IpcJmsSessionSender) iterator.next();
            sender.close();
        }
        _list.clear();
        closeConnection();
        _list = null;
    }

    // Close the connection to the client
    private void closeConnection() {
        if (_client != null) {
            try {
                _client.close();
            } catch (IOException ignore) {
            }
            _client = null;
        }
    }

} //-- IpcJmsSessionList

⌨️ 快捷键说明

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