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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? dispatchqueue.java

?? OSGI 的 源碼實現,采用JAVA書寫
?? JAVA
字號:
/* * Oscar - An implementation of the OSGi framework. * Copyright (c) 2004, Richard S. Hall * All rights reserved. *   * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *   *   * Redistributions of source code must retain the above copyright *     notice, this list of conditions and the following disclaimer. *   * 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. *   * Neither the name of the ungoverned.org nor the names of its *     contributors may be used to endorse or promote products derived *     from this software without specific prior written permission. *   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS 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 THE COPYRIGHT * OWNER OR 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. *  * Contact: Richard S. Hall (heavy@ungoverned.org) * Contributor(s): ***/package org.ungoverned.oscar.util;import java.util.ArrayList;import java.util.EventListener;import java.util.EventObject;import org.ungoverned.oscar.Oscar;/** * This class implements an event dispatching queue to simplify delivering * events to a list of event listener. To use this class, simply create an * instance and use it to keep track of your event listeners, much like * <tt>javax.swing.event.EventListenerList</tt>. To dispatch an event, * simply create an instance of a <tt>Dispatcher</tt> and pass the instance * to <tt>DispatchQueue.dispatch()</tt> method, for example: * <pre> *  Dispatcher d = new Dispatcher() { *      public void dispatch(EventListener l, Object eventObj) *      { *          ((FooListener) l).fooXXX((FooEvent) eventObj); *      } *  }; *  FooEvent event = new FooEvent(this); *  dispatchQueue.dispatch(d, FooListener.class, event); * </pre> * In the above code substitute a specific listener and event for the * <tt>Foo</tt> listener and event. Since <tt>Dispatcher</tt>s are * reusable, it is probably a good idea to create one for each type of * event to be delivered and just reuse them everytime to avoid unnecessary * memory allocation. * <p> * Currently, the <tt>DispatchQueue</tt> creates an internal thread with * which all events are delivered; this means that events are never delivered * using the caller's thread.**/public class DispatchQueue{    // Representation of an empty listener list.    private static final Object[] m_emptyList = new Object[0];    // The event listeners for a particular queue instance.    private Object[] m_listeners = m_emptyList;    // A single thread is used to deliver events for all dispatchers.    private static Thread m_thread = null;    private static String m_threadLock = "thread lock";    private static boolean m_stopping = false;    private static boolean m_stopped = false;    // List of dispatch requests.    private static final ArrayList m_requestList = new ArrayList();    // Cached dispatch requests to avoid memory allocation.    private static final ArrayList m_requestCache = new ArrayList();    /**     * Constructs a dispatch queue and starts a dispather thread if     * necessary.    **/    public DispatchQueue()    {        synchronized (m_threadLock)        {            // Start event dispatching thread if necessary.            if (m_thread == null)            {                m_thread = new Thread(new Runnable() {                    public void run()                    {                        DispatchQueue.run();                    }                }, "OscarDispatchQueue");                m_thread.start();            }        }    }    /**     * Terminates the dispatching thread for a graceful shutdown     * of the dispatching queue; the caller will block until the     * dispatching thread has completed all pending dispatches.     * Since there is only one thread per all instances of     * <tt>DispatchQueue</tt>, this method should only be called     * prior to exiting the JVM.    **/    public static void shutdown()    {        synchronized (m_threadLock)        {            // Return if already stopped.            if (m_stopped)            {                return;            }            // Signal dispatch thread.            m_stopping = true;            synchronized (m_requestList)            {                m_requestList.notify();            }            // Wait for dispatch thread to stop.            while (!m_stopped)            {                try {                    m_threadLock.wait();                } catch (InterruptedException ex) {                }            }        }    }    /**     * Returns a pointer to the array of event listeners. The array stores pairs     * of associated <tt>Class</tt> and <tt>EventListener</tt> objects; a pair     * corresponds to the arguments passed in to the <tt>addListener()</tt> method.     * Even numbered array elements are the class object and odd numbered elements     * are the corresponding event listener instance.     *     * @return guaranteed to return a non-null object array.    **/    public Object[] getListeners()    {        return m_listeners;    }    /**     * Returns the listener if it is already in the dispatch queue.     * @param clazz the class of the listener to find.     * @param l the listener instance to find.     * @return the listener instance or <tt>null</tt> if the listener was     *         not found.    **/    public EventListener getListener(Class clazz, EventListener l)    {        // Verify listener.        if (l == null)        {            throw new IllegalArgumentException("Listener is null");        }        else if (!clazz.isInstance(l))        {            throw new IllegalArgumentException(                "Listener not of type " + clazz.getName());        }        // Lock the object.        synchronized (this)        {            // Try to find the instance in our list.            int idx = -1;            for (int i = 0; i < m_listeners.length; i += 2)            {                if ((m_listeners[i] == clazz) &&                    (m_listeners[i + 1].equals(l)))                {                    return (EventListener) m_listeners[i + 1];                }            }        }                return null;    }    /**     * Adds a listener to the dispatch queue's listener list; the listener     * is then able to receive events.     *     * @param clazz the class object associated with the event listener type.     * @param l the instance of the event listener to add.    **/    public void addListener(Class clazz, EventListener l)    {        // Verify listener.        if (l == null)        {            throw new IllegalArgumentException("Listener is null");        }        else if (!clazz.isInstance(l))        {            throw new IllegalArgumentException(                "Listener not of type " + clazz.getName());        }        // Lock the object.        synchronized (this)        {            // If we have no listeners, then just add the new listener.            if (m_listeners == m_emptyList)            {                m_listeners = new Object[] { clazz, l };            }            // Otherwise, we need to do some array copying.            // Notice, the old array is always valid, so if            // the dispatch thread is in the middle of a dispatch,            // then it has a reference to the old listener array            // and is not affected by the new value.            else            {                Object[] newList = new Object[m_listeners.length + 2];                System.arraycopy(m_listeners, 0, newList, 0, m_listeners.length);                newList[m_listeners.length] = clazz;                newList[m_listeners.length + 1] = l;                m_listeners = newList;            }        }    }    /**     * Removes a listener from the dispatch queue's listener list; the listener     * is no longer able to receive events.     *     * @param clazz the class object associated with the event listener type.     * @param l the instance of the event listener to remove.    **/    public void removeListener(Class clazz, EventListener l)    {        // Verify listener.        if (l == null)        {            throw new IllegalArgumentException("Listener is null");        }        else if (!clazz.isInstance(l))        {            throw new IllegalArgumentException(                "Listener not of type " + clazz.getName());        }        // Lock the object.        synchronized (this)        {            // Try to find the instance in our list.            int idx = -1;            for (int i = 0; i < m_listeners.length; i += 2)            {                if ((m_listeners[i] == clazz) &&                    (m_listeners[i + 1].equals(l)))                {                    idx = i;                    break;                }            }            // If we have the instance, then remove it.            if (idx >= 0)            {                // If this is the last listener, then point to empty list.                if ((m_listeners.length - 2) == 0)                {                    m_listeners = m_emptyList;                }                // Otherwise, we need to do some array copying.                // Notice, the old array is always valid, so if                // the dispatch thread is in the middle of a dispatch,                // then it has a reference to the old listener array                // and is not affected by the new value.                else                {                    Object[] newList  = new Object[m_listeners.length - 2];                    System.arraycopy(m_listeners, 0, newList, 0, idx);                    if (idx < newList.length)                    {                        System.arraycopy(m_listeners, idx + 2, newList, idx,                            newList.length - idx);                    }                    m_listeners = newList;                }            }        }    }    /**     * Dispatches an event to a set of event listeners using a specified     * dispatcher object.     *     * @param d the dispatcher used to actually dispatch the event; this     *          varies according to the type of event listener.     * @param clazz the class associated with the target event listener type;     *              only event listeners of this type will receive the event.     * @param eventObj the actual event object to dispatch.    **/    public void dispatch(Dispatcher d, Class clazz, EventObject eventObj)    {        dispatch(m_listeners, d, clazz, eventObj);    }    protected void dispatch(        Object[] listeners, Dispatcher d, Class clazz, EventObject eventObj)    {        // If dispatch thread is stopped, then ignore dispatch request.        if (m_stopped)        {            return;        }        // First get a dispatch request from the cache or        // create one if necessary.        DispatchRequest dr = null;        synchronized (m_requestCache)        {            if (m_requestCache.size() > 0)                dr = (DispatchRequest) m_requestCache.remove(0);            else                dr = new DispatchRequest();        }        // Initialize dispatch request.        dr.m_listeners = listeners;        dr.m_dispatcher = d;        dr.m_clazz = clazz;        dr.m_eventObj = eventObj;        // Lock the request list.        synchronized (m_requestList)        {            // Add our request to the list.            m_requestList.add(dr);            // Notify the dispatch thread that there is            // work to do.            m_requestList.notify();        }    }    private static void run()    {        DispatchRequest dr = null;        while (true)        {            // Lock the request list so we can try to get a            // dispatch request from it.            synchronized (m_requestList)            {                // Wait while there are no requests to dispatch. If the                // dispatcher thread is supposed to stop, then let the                // dispatcher thread exit the loop and stop.                while ((m_requestList.size() == 0) && !m_stopping)                {                    // Wait until some signals us for work.                    try {                        m_requestList.wait();                    } catch (InterruptedException ex) {                        Oscar.error("Dispatch thread error.", ex);                    }                }                // If there are no events to dispatch and shutdown                // has been called then exit, otherwise dispatch event.                if ((m_requestList.size() == 0) && (m_stopping))                {                    synchronized (m_threadLock)                    {                        m_stopped = true;                        m_threadLock.notifyAll();                    }                    return;                }                // Get the dispatch request.                dr = (DispatchRequest) m_requestList.remove(0);            }            // Deliver event outside of synchronized block            // so that we don't block other requests from being            // queued during event processing.            // Try to dispatch to the listeners.            if (dr.m_listeners.length > 0)            {                // Notify appropriate listeners.                for (int i = dr.m_listeners.length - 2; i >= 0; i -= 2)                {                    if (dr.m_listeners[i] == dr.m_clazz)                    {                        try {                            dr.m_dispatcher.dispatch(                                (EventListener) dr.m_listeners[i + 1], dr.m_eventObj);                        } catch (Throwable th) {                            Oscar.error("DispatchQueue: Error during dispatch.", th);                        }                    }                }            }            // Put dispatch request in cache.            synchronized (m_requestCache)            {                m_requestCache.add(dr);            }        }    }    private static class DispatchRequest    {        public Object[] m_listeners = null;        public Dispatcher m_dispatcher = null;        public Class m_clazz = null;        public EventObject m_eventObj = null;    }}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲少妇最新在线视频| 岛国av在线一区| 欧美一区二区大片| 日本不卡视频在线| 欧美成人性战久久| 成人黄色777网| 三级久久三级久久久| 精品99一区二区三区| jvid福利写真一区二区三区| 亚洲一二三区在线观看| 色综合色综合色综合| 亚洲一区二区三区美女| 亚洲精品视频在线观看网站| 欧美成人官网二区| 精品成人免费观看| 久久久久久久性| 在线观看免费视频综合| 国产一级精品在线| 亚洲一二三四区| 日韩av一二三| 一区二区免费在线播放| 国产日韩在线不卡| 欧美一级片在线| wwwwxxxxx欧美| 91精品国产乱| 欧美精品一区二区三区四区 | 91麻豆国产福利在线观看| 日本色综合中文字幕| 精品一区二区久久久| 亚洲色图欧美偷拍| 亚洲h动漫在线| 亚洲一级不卡视频| 蓝色福利精品导航| 亚洲国产精品久久久久秋霞影院| 亚洲一级二级三级在线免费观看| 免费成人在线观看| 成人性生交大片免费看在线播放 | 制服丝袜亚洲播放| caoporen国产精品视频| 欧美亚洲愉拍一区二区| 91理论电影在线观看| 欧美日精品一区视频| 色吧成人激情小说| 99久久综合国产精品| 欧美性色黄大片| 久久精品亚洲精品国产欧美| 欧美人动与zoxxxx乱| 欧美视频精品在线观看| 欧美精品一区二区在线播放| 亚洲免费在线观看| 亚洲嫩草精品久久| 蜜桃91丨九色丨蝌蚪91桃色| 蜜臀av性久久久久蜜臀aⅴ四虎| 国产jizzjizz一区二区| 高清在线观看日韩| 欧美精选一区二区| 欧美一级夜夜爽| 亚洲人精品午夜| 国产一区视频网站| 欧美日韩国产综合一区二区三区 | 日韩高清在线电影| 不卡的av在线播放| 日韩一区二区三区四区五区六区| 欧美日韩的一区二区| 国产精品人人做人人爽人人添| 久久久久成人黄色影片| 午夜视频一区在线观看| 日韩精品一区第一页| 99精品视频在线播放观看| 色婷婷综合激情| 精品国产乱码久久久久久免费 | 激情欧美一区二区| 不卡在线视频中文字幕| 精品国产一区久久| 丝瓜av网站精品一区二区| aaa亚洲精品| 国产精品私人自拍| 国内久久婷婷综合| 日韩欧美资源站| 午夜久久久久久电影| 色婷婷久久综合| 1000精品久久久久久久久| 亚洲午夜久久久久久久久电影网| 国产凹凸在线观看一区二区| 日韩精品在线看片z| 精品少妇一区二区三区视频免付费 | 26uuu久久天堂性欧美| 污片在线观看一区二区| 欧美日韩免费一区二区三区视频| 亚洲区小说区图片区qvod| 成人深夜在线观看| 国产欧美一区二区精品性色| 国产最新精品免费| 日韩欧美国产精品| 美女诱惑一区二区| 日韩欧美高清dvd碟片| 蜜臀久久99精品久久久久宅男 | 国产精品福利一区| 亚洲成在线观看| 欧美视频一区二区在线观看| 亚洲精品免费看| 91美女福利视频| 中文字幕字幕中文在线中不卡视频| 成人一区在线看| 国产精品二区一区二区aⅴ污介绍| 高清av一区二区| 中文字幕久久午夜不卡| 亚洲国产精品久久人人爱| 色悠久久久久综合欧美99| 亚洲三级视频在线观看| 91视频国产资源| 亚洲一区二区中文在线| 欧美日韩精品免费观看视频| 亚洲国产一区视频| 在线电影院国产精品| 男女激情视频一区| 精品福利在线导航| 国内不卡的二区三区中文字幕| 欧美精品一区二区三区蜜桃| 国产乱码精品一品二品| 欧美性做爰猛烈叫床潮| 午夜精品在线看| 欧美精品一区二区三区久久久 | 不卡的av网站| 亚洲欧美日韩小说| 欧美日韩一区二区三区四区 | 国产在线播放一区三区四| 日本一区二区三区在线观看| 99久久精品国产毛片| 一区二区三区成人在线视频| 91超碰这里只有精品国产| 精品在线观看免费| 中文字幕中文字幕一区二区| 欧美性猛交xxxx乱大交退制版| 免费成人在线影院| 中文在线资源观看网站视频免费不卡| 91在线视频观看| 日本伊人精品一区二区三区观看方式| 久久男人中文字幕资源站| 91女厕偷拍女厕偷拍高清| 天天操天天综合网| 国产欧美日韩在线| 在线精品视频一区二区三四| 精品一区二区精品| 国产精品动漫网站| 欧美一区二区三级| 成人av综合在线| 毛片不卡一区二区| 成人免费小视频| 日韩免费视频一区二区| 91在线视频官网| 精东粉嫩av免费一区二区三区| 国产精品久久久久一区| 在线91免费看| 91免费视频观看| 久久精品国产网站| 亚洲女厕所小便bbb| 久久这里只有精品首页| 欧美午夜精品电影| 顶级嫩模精品视频在线看| 日韩一区精品字幕| 亚洲日韩欧美一区二区在线| 日韩欧美的一区二区| 色综合av在线| 国产自产高清不卡| 午夜成人免费视频| 亚洲欧美一区二区不卡| 精品免费99久久| 欧美日韩三级一区| 日本精品视频一区二区| 国产一级精品在线| 日本最新不卡在线| 亚洲综合一二三区| 国产精品久久久久桃色tv| 欧美mv和日韩mv的网站| 欧美日本一道本| 色婷婷久久综合| www.66久久| 国产精品白丝jk黑袜喷水| 日韩精品成人一区二区在线| 亚洲精品网站在线观看| 中文久久乱码一区二区| 亚洲精品一区二区三区香蕉| 欧美日产国产精品| 在线观看91精品国产入口| aaa亚洲精品| 不卡一区二区在线| 国产大陆亚洲精品国产| 国产精品天天看| 久久久久久久综合日本| 欧美成人a在线| 欧美一二区视频| 欧美另类高清zo欧美| 欧美午夜精品一区二区三区| 91久久线看在观草草青青 | xnxx国产精品| 精品久久国产97色综合| 日韩亚洲欧美在线观看| 日韩视频免费观看高清完整版在线观看 | 成人97人人超碰人人99|