1 11 12 package org.eclipse.osgi.framework.eventmgr; 13 14 import java.util.ArrayList ; 15 import org.eclipse.osgi.framework.eventmgr.EventListeners.ListElement; 16 import org.eclipse.osgi.framework.eventmgr.EventManager.EventThread; 17 18 41 public class ListenerQueue { 42 45 protected final EventManager manager; 46 49 private final ArrayList queue; 50 51 56 private boolean readOnly; 57 58 64 public ListenerQueue(EventManager manager) { 65 if (manager == null) { 66 throw new IllegalArgumentException (); 67 } 68 69 this.manager = manager; 70 queue = new ArrayList (); 71 readOnly = false; 72 } 73 74 86 public synchronized void queueListeners(EventListeners listeners, EventDispatcher dispatcher) { 87 if (readOnly) { 88 throw new IllegalStateException (); 89 } 90 91 if (listeners != null) { 92 ListElement[] list = listeners.getListeners(); 93 94 if (list.length > 0) { 95 queue.add(new EventListeners.ListElement(list, dispatcher)); 96 } 97 } 98 } 99 100 108 public void dispatchEventAsynchronous(int eventAction, Object eventObject) { 109 synchronized (this) { 110 readOnly = true; 111 } 112 EventThread eventThread = manager.getEventThread(); 113 synchronized (eventThread) { 114 int size = queue.size(); 115 for (int i = 0; i < size; i++) { 116 ListElement list = (ListElement)queue.get(i); 117 eventThread.postEvent((ListElement[]) list.primary, (EventDispatcher) list.companion, eventAction, eventObject); 118 } 119 } 120 } 121 122 132 public void dispatchEventSynchronous(int eventAction, Object eventObject) { 133 synchronized (this) { 134 readOnly = true; 135 } 136 int size = queue.size(); 139 for (int i = 0; i < size; i++) { 140 ListElement list = (ListElement)queue.get(i); 141 EventManager.dispatchEvent((ListElement[]) list.primary, (EventDispatcher) list.companion, eventAction, eventObject); 142 } 143 } 144 } 145 | Popular Tags |