亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? basiceventmanager.java

?? 一個java方面的消息訂閱發(fā)送的源碼
?? 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-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
 *
 * $Id: BasicEventManager.java,v 1.1 2004/11/26 01:50:41 tanderson Exp $
 */
package org.exolab.jms.events;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.exolab.jms.service.BasicService;
import org.exolab.jms.service.ServiceException;
import org.exolab.jms.service.ServiceState;
import org.exolab.jms.common.threads.ThreadPool;
import org.exolab.jms.common.util.OrderedQueue;
import org.exolab.jms.threads.ThreadPoolExistsException;
import org.exolab.jms.threads.ThreadPoolManager;


/**
 * The EventManager manages {@link Event} objects. It has methods to
 * register and unregister events. It also extends {@link Runnable} interface
 * which defines the thread responsible for dispatching events.
 * <p>
 * An event is defined to occur at sometime in the future, as specified either
 * by an absolute time through {@link #registerEvent} or as relative time
 * through {@link #registerEventRelative}. An event must have an associated
 * event type and may have an attached <code>Serializable</code>,
 * which is used when the EventManager makes a callback to the registered
 * handler when the event fires.
 * <p>
 * The register methids will return an event identifier which can subsequently
 * be used to unregister the event through the {@link #unregisterEvent} event.
 * This is the only means of unregister an event.
 * <p>
 * If the {@link Event} object is incorrectly specified then the
 * {@link IllegalEventDefinedException} exception is raised.
 * <p>
 * When an event fires the {@link EventManager} is responsible for ensuring
 * that the event handler is notified. If the event handler has since been
 * removed then the EventManager must gracefully abort the delivery and
 * continue processing the next event.
 * <p>
 * Objects of type {@link Event} need to survive subsequent
 * {@link EventManager} restarts, as such they must be persisted, which
 * implies that the {@link EventHandler} needs to also be persisted. The
 * ability to store the {@link EventHandler} as a <code>HandleIfc</code> object
 * which can later be resolved to an object will be required.
 *
 * @version   $Revision: 1.1 $ $Date: 2004/11/26 01:50:41 $
 * @author    <a href="mailto:wood@intalio.com">Chris Wood</a>
 */
public class BasicEventManager
    extends BasicService
    implements EventManager {

    // The unique name of this ThreadPool.
    public transient static final String NAME = "EventManager";

    // The max number of threads for this pool.
    public transient static final int MAX_THREADS = 5;

    /**
     * Maps ids to events.
     */
    private HashMap _events = new HashMap();

    /**
     * Thread pool manager.
     */
    private transient ThreadPool _pool;

    /**
     * Synchonization for the following two collections.
     */
    private transient Object _queueSync = new Object();

    /**
     * Event queue.
     */
    private transient OrderedQueue _queue = new OrderedQueue(_queueComparator);

    /**
     * Used to generate unique queue entry ids.
     */
    private transient long _seed;

    /**
     * this is the name of the EventManagerThread in which events excecute.
     */
    private static final String EVENT_MANAGER_THREAD_NAME =
        "EventManagerThread";

    /**
     * Singleton instance.
     */
    transient static private BasicEventManager _instance = null;

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


    /**
     * Return the singleton instance of the EventManager
     *
     * @return    EventManager
     */
    public static BasicEventManager instance() {
        if (_instance == null)
            _instance = new BasicEventManager();

        return _instance;
    }

    protected BasicEventManager() {
        super(EVENT_MANAGER_THREAD_NAME);
    }

    /**
     * Register an event to be fired once and only once at the specified
     * abolsute time. The event object must be Serializable so that it can
     * be persisted and restored across EventManager restarts.
     * <p>
     * If the specified event is ill-defined then the IllegalEventDefined-
     * Exception exception is thrown.
     * <p>
     * Similarly, if the abolsute time has already passed then the exception
     * IllegalEventDefinedException is raised.
     * <p>
     * The method returns an unique event identifier, which can subsequently
     * be used to deregister the event.
     *
     * @param event    information about the event
     * @param abolsute the abolsute time, in ms, that the event
     *                 must fire
     * @return String  unique event identifier
     * @exception IllegalEventDefinedException
     */
    public String registerEvent(Event event, long absolute)
        throws IllegalEventDefinedException {
        synchronized (_queueSync) {
            QueueEntry entry = new QueueEntry(event, absolute, generateId());

            // add entry to the queue.
            _queue.add(entry);
            _events.put(entry.id, entry);

            // notify the event thread.
            _queueSync.notifyAll();
            return entry.id;
        }
    }

    /**
     * Register an event to be fired once and only once at a time relative to
     * now. The event object must be Serializable so that it can be persisted
     * and restored across EventManager restarts.
     * <p>
     * If the specified event is ill-defined then the IllegalEventDefined-
     * Exception exception is thrown.
     * <p>
     * The method returns an unique event identifier, which can subsequently
     * be used to deregister the event.
     *
     * @param event    information about the event
     * @param relative the relative time in ms
     *                 (currently no reference to locale).
     * @return String  unique event identifier,
     * @exception IllegalEventDefinedException
     */
    public String registerEventRelative(Event event, long relative)
        throws IllegalEventDefinedException {
        return registerEvent(event, System.currentTimeMillis() + relative);
    }

    /**
     * Unregister the event specified by the event identifier. If the event
     * does not exist then fail silently.
     *
     * @param String unique event identifier.
     */
    public void unregisterEvent(String id) {
        synchronized (_queueSync) {
            // remove from the events list
            Object obj = _events.remove(id);
            if (obj == null)
                return;
            // remove from the queue.
            _queue.remove(obj);
        }
    }

    // implementation of BasicService.run
    public void run() {
        synchronized (_queueSync) {
            QueueEntry entry;
            long currentTime;
            while (getState() != ServiceState.STOPPED) {
                currentTime = System.currentTimeMillis();
                try {
                    entry = (QueueEntry) _queue.firstElement();
                } catch (java.util.NoSuchElementException ex) {
                    // queue is empty.
                    try {
                        _queueSync.wait();
                    } catch (InterruptedException ex1) {
                        break;
                    }
                    continue;
                }

                if (entry.absolute <= currentTime) {
                    // trigger any expired events
                    try {
                        getThreadPool().execute(entry);
                    } catch (InterruptedException ex) {
                    }
                    _queue.removeFirstElement();
                    _events.remove(entry.id);
                } else {
                    // wait for either the next event to expire or an element to be
                    // added to the queue.
                    try {
                        _queueSync.wait(entry.absolute - currentTime);
                    } catch (InterruptedException ex) {
                        // ignore
                    }
                }
            }
        }
    }

    /**
     * Generate unique queued object identifier.
     */
    private synchronized String generateId() {
        return Long.toString(++_seed);
    }

    public void start() throws ServiceException {
        super.start();
    }

    /**
     * Return a reference ot the thread pool manager. This object is chached
     * for future reference
     *
     * @return      ThreadPool
     */
    private ThreadPool getThreadPool() {
        if (_pool == null) {
            // At startup Event Mgr is triggered before the Service
            // locator has registered the ThreadPoolMgr, causing
            // an exception. Use the instance variable for now to
            // avoid this problem. jimm
            // _pool = (ThreadPoolMgr)ServiceLocator.locateService(
            //    ServiceConstants.ThreadPoolManager);
            try {
                _pool = ThreadPoolManager.instance().createThreadPool
                    (NAME, MAX_THREADS);
            } catch (ThreadPoolExistsException err) {
                _log.error("Thread pool " + NAME + " already exists");
            }
        }

        return _pool;
    }

    /**
     * Compare queue entries on expiration times
     */
    private transient static final Comparator _queueComparator =
        new Comparator() {

            public int compare(Object obj1, Object obj2) {
                QueueEntry qe1 = (QueueEntry) obj1;
                QueueEntry qe2 = (QueueEntry) obj2;

                if (qe1.absolute < qe2.absolute)
                    return -1;
                if (qe1.absolute > qe2.absolute)
                    return 1;
                return 0;
            }

            public boolean equals(Object that) {
                return (this == that);
            }
        };

    /**
     * Entry on the task queue.
     */
    class QueueEntry implements Runnable {

        QueueEntry(Event event, long absolute, String id) {
            this.absolute = absolute;
            this.event = event;
            this.id = id;
        }

        private long absolute;
        private Event event;
        private String id;

        public void run() {
            event.getEventListener().handleEvent(event.getEventType(),
                event.getCallbackObject(), System.currentTimeMillis());
        }
    }

}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美电视剧在线观看完整版| 亚洲一区二区三区精品在线| 日韩欧美精品在线视频| 欧美日韩一区视频| 欧美性受xxxx| 欧美日韩精品一区二区三区蜜桃 | 91美女在线观看| 日韩欧美亚洲另类制服综合在线| 欧美日韩久久久一区| 欧美人狂配大交3d怪物一区 | 久久女同精品一区二区| 久久理论电影网| 国产日韩成人精品| 中文字幕亚洲视频| 亚洲综合一二区| 五月婷婷久久综合| 久久精品国产免费| 国产乱人伦偷精品视频不卡| 国产不卡在线播放| 99久免费精品视频在线观看| 色婷婷久久久亚洲一区二区三区| 日本韩国精品在线| 欧美日韩大陆一区二区| 欧美一区二区三区免费视频| 2023国产精品自拍| 国产精品美女一区二区在线观看| 日韩美女视频一区二区| 一区二区三区 在线观看视频| 亚洲福利一二三区| 久草这里只有精品视频| 国产成人av一区二区三区在线 | 国产精品一区二区久激情瑜伽| 国产成人av一区二区三区在线 | 美女精品一区二区| 国产激情一区二区三区四区| 95精品视频在线| 在线不卡免费欧美| 久久一区二区视频| 亚洲欧美另类小说| 日韩精品91亚洲二区在线观看 | 欧美一级黄色录像| 国产无人区一区二区三区| 亚洲欧美日韩在线| 日韩国产欧美三级| 成人性生交大片免费看中文网站| 91久久精品国产91性色tv| 欧美一级二级在线观看| 国产精品毛片久久久久久| 午夜精品久久久久久久蜜桃app| 国产中文一区二区三区| 色综合天天做天天爱| 日韩欧美色综合| 亚洲欧美一区二区三区孕妇| 免费人成在线不卡| 91免费观看视频在线| 欧美一二三区在线| 亚洲欧美一区二区三区国产精品| 91精品国产综合久久精品性色| 精品成人一区二区| 亚洲国产一区二区三区| 久久99精品久久久久婷婷| 色综合久久66| 国产亚洲美州欧州综合国| 亚洲国产成人精品视频| 国产成人免费视| 日韩一级片在线观看| 亚洲精品亚洲人成人网| 国产99久久久国产精品潘金 | 亚洲精品福利视频网站| 国产精品一区二区你懂的| 在线播放一区二区三区| 日韩毛片高清在线播放| 久久精品国产99国产| 欧美亚日韩国产aⅴ精品中极品| 国产精品蜜臀av| 激情五月播播久久久精品| 欧美日韩mp4| 一区二区三区视频在线观看| 成人免费视频播放| 久久人人爽爽爽人久久久| 日日夜夜精品视频免费| 国产成a人无v码亚洲福利| 日韩欧美中文一区| 亚洲成av人片在线观看| 日本电影亚洲天堂一区| 亚洲欧洲www| 成人一二三区视频| 欧美极品另类videosde| 国产一区二区美女| 久久先锋资源网| 久久精品国产亚洲5555| 欧美女孩性生活视频| 亚洲一区二区三区四区在线观看 | 777欧美精品| 亚洲一二三区视频在线观看| 色综合中文综合网| 韩国午夜理伦三级不卡影院| 51精品国自产在线| 日韩黄色免费网站| 欧美一区二区三区四区久久| 亚洲一区电影777| 欧美综合在线视频| 亚洲尤物视频在线| 欧美日韩高清一区二区三区| 夜夜嗨av一区二区三区| 在线视频欧美精品| 亚洲在线视频一区| 欧美日韩在线不卡| 日韩精品每日更新| 日韩免费电影网站| 国产乱码精品一区二区三| 久久精品一区二区三区av| 国产激情视频一区二区在线观看| 国产亚洲午夜高清国产拍精品 | 日韩欧美色综合| 精品中文字幕一区二区| 久久老女人爱爱| av中文字幕不卡| 亚洲精品高清在线观看| 欧美日韩国产系列| 日韩中文字幕区一区有砖一区| 欧美肥妇毛茸茸| 久久超碰97中文字幕| 久久久久久毛片| 95精品视频在线| 亚洲一区视频在线| 欧美成人精品3d动漫h| 国产一区二区三区在线观看免费视频 | 4438x成人网最大色成网站| 日韩 欧美一区二区三区| 精品国产一区二区三区久久影院| 国产麻豆一精品一av一免费| 国产精品美女久久久久av爽李琼| 91香蕉国产在线观看软件| 亚洲综合丁香婷婷六月香| 91精品国产丝袜白色高跟鞋| 久久不见久久见免费视频1| 国产日韩av一区二区| 色婷婷久久久久swag精品| 免费亚洲电影在线| 国产精品超碰97尤物18| 欧美日韩国产欧美日美国产精品| 久久精品国产99久久6| 日韩一区中文字幕| 69av一区二区三区| 高清在线不卡av| 亚洲成av人影院| 国产午夜亚洲精品午夜鲁丝片| 99精品国产91久久久久久 | 国产精品白丝av| 一区二区三区欧美激情| 日韩午夜电影av| 国产不卡在线视频| 日韩av在线免费观看不卡| 国产精品视频一二三区| 欧美日韩国产成人在线免费| 国产精品一区二区果冻传媒| 亚洲第一久久影院| 中文字幕av一区二区三区免费看 | 国产精品国产三级国产aⅴ中文| 欧美日韩中文另类| 粗大黑人巨茎大战欧美成人| 亚洲国产视频a| 亚洲国产精品成人综合色在线婷婷| 91国产视频在线观看| 韩国成人福利片在线播放| 亚洲永久精品大片| 国产精品乱人伦| 日韩欧美一区二区久久婷婷| 99精品欧美一区二区蜜桃免费| 青青草国产成人99久久| 一区二区三区日韩精品| 久久精品人人爽人人爽| 在线播放中文字幕一区| 91麻豆国产香蕉久久精品| 国产精品影视在线| 日韩激情在线观看| 亚洲激情成人在线| 中文字幕乱码亚洲精品一区| 欧美成人性福生活免费看| 亚洲日本在线看| 国产亚洲精品aa午夜观看| 91精品免费在线| 欧美日韩一区二区欧美激情| 99国内精品久久| 大桥未久av一区二区三区中文| 麻豆一区二区在线| 亚洲午夜精品在线| 亚洲精品一二三区| 亚洲同性同志一二三专区| 国产亚洲成aⅴ人片在线观看| 欧美日韩成人激情| 欧美色爱综合网| 色呦呦日韩精品| 9色porny自拍视频一区二区| 国产成人亚洲精品青草天美| 国产原创一区二区| 久久精品国产一区二区| 日韩精品亚洲一区| 日本vs亚洲vs韩国一区三区|