Java 类java.util.EventListener 实例源码
项目:monarch
文件:AbstractPoolCache.java
/**
* Constructor initializes the AbstractPoolCache properties.
*
* @param eventListner The event listner for the database connections.
* @param configs The ConfiguredDataSourceProperties object containing the configuration for the
* pool.
* @throws PoolException
*/
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "SC_START_IN_CTOR",
justification = "the thread started is a cleanup thread and is not active until there is a timeout tx")
public AbstractPoolCache(EventListener eventListner, ConfiguredDataSourceProperties configs)
throws PoolException {
availableCache = new HashMap();
activeCache = Collections.synchronizedMap(new LinkedHashMap());
connEventListner = eventListner;
expiredConns = Collections.synchronizedList(new ArrayList());
MAX_LIMIT = configs.getMaxPoolSize();
expirationTime = configs.getConnectionExpirationTime() * 1000;
timeOut = configs.getConnectionTimeOut() * 1000;
loginTimeOut = configs.getLoginTimeOut() * 1000;
INIT_LIMIT = Math.min(configs.getInitialPoolSize(), MAX_LIMIT);
configProps = configs;
cleaner = this.new ConnectionCleanUpThread();
ThreadGroup group = LoggingThreadGroup.createThreadGroup("Cleaner threads");
th = new Thread(group, cleaner);
th.setDaemon(true);
th.start();
}
项目:incubator-netbeans
文件:ListenerList.java
/**
* Removes the given listener from this listener list.
*
* @param listener the listener to be removed. If null is passed it is ignored (nothing gets removed).
*/
public synchronized void remove(T listener) {
if (listener == null)
return;
int idx = listenersList.indexOf(listener);
if (idx == -1) {
return;
}
EventListener [] arr = new EventListener[listenersList.getArray().length - 1];
if (arr.length > 0) {
System.arraycopy(listenersList.getArray(), 0, arr, 0, idx);
}
if (arr.length > idx) {
System.arraycopy(listenersList.getArray(), idx + 1, arr, idx, listenersList.getArray().length - idx - 1);
}
listenersList = new ImmutableList<T>(arr);
}
项目:MetadataEditor
文件:EventListenerList.java
private void writeObject(ObjectOutputStream s) throws IOException {
Object[] lList = listenerList;
s.defaultWriteObject();
// Save the non-null event listeners:
for (int i = 0; i < lList.length; i+=2) {
Class t = (Class)lList[i];
EventListener l = (EventListener)lList[i+1];
if ((l!=null) && (l instanceof Serializable)) {
s.writeObject(t.getName());
s.writeObject(l);
}
}
s.writeObject(null);
}
项目:incubator-netbeans
文件:JPDAClassTypeTest.java
private void checkInstanceOf() throws Exception {
boolean is = testAppClass.isInstanceOf(APP_SRC_NAME);
assertFalse(is);
is = testAppClass.isInstanceOf(APP_CLASS_NAME);
assertTrue("Instance of "+APP_CLASS_NAME, is);
is = testAppClass.isInstanceOf(EventListener.class.getName());
assertTrue("Instance of "+EventListener.class.getName(), is);
is = multiImplClass.isInstanceOf("huuuhuuu");
assertFalse(is);
is = multiImplClass.isInstanceOf(APP_CLASS_NAME+"$MultiImpl");
assertTrue("Instance of "+APP_CLASS_NAME+"$MultiImpl", is);
is = multiImplClass.isInstanceOf(Runnable.class.getName());
assertTrue("Instance of "+Runnable.class.getName(), is);
is = multiImplClass.isInstanceOf(APP_CLASS_NAME+"$SuperImpl");
assertTrue("Instance of "+APP_CLASS_NAME+"$SuperImpl", is);
is = multiImplClass.isInstanceOf(APP_CLASS_NAME+"$Intrfc4");
assertTrue("Instance of "+APP_CLASS_NAME+"$Intrfc4", is);
}
项目:Wurst-MC-1.12
文件:EventManager.java
@SuppressWarnings("unchecked")
public <T extends EventListener> void add(Class<T> type, T listener)
{
try
{
((ArrayList<T>)listenerMap.get(type)).add(listener);
}catch(Throwable e)
{
e.printStackTrace();
CrashReport report =
CrashReport.makeCrashReport(e, "Adding Wurst event listener");
CrashReportCategory category =
report.makeCategory("Affected listener");
category.setDetail("Listener type", () -> type.getName());
category.setDetail("Listener class",
() -> listener.getClass().getName());
throw new ReportedException(report);
}
}
项目:VTerminal
文件:Panel.java
/**
* Adds an event listener to the Panel.
*
* @param eventListener
* The event listener.
*
* @throws IllegalArgumentException
* If the event listener isn't supported by this function.
*/
public void addListener(final EventListener eventListener) {
if (eventListener instanceof KeyListener) {
this.addKeyListener((KeyListener) eventListener);
return;
}
if (eventListener instanceof MouseListener) {
this.addMouseListener((MouseListener) eventListener);
return;
}
if (eventListener instanceof MouseMotionListener) {
this.addMouseMotionListener((MouseMotionListener) eventListener);
return;
}
throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported.");
}
项目:fitnotifications
文件:ICUNotifier.java
/**
* Add a listener to be notified when notifyChanged is called.
* The listener must not be null. AcceptsListener must return
* true for the listener. Attempts to concurrently
* register the identical listener more than once will be
* silently ignored.
*/
public void addListener(EventListener l) {
if (l == null) {
throw new NullPointerException();
}
if (acceptsListener(l)) {
synchronized (notifyLock) {
if (listeners == null) {
listeners = new ArrayList<EventListener>();
} else {
// identity equality check
for (EventListener ll : listeners) {
if (ll == l) {
return;
}
}
}
listeners.add(l);
}
} else {
throw new IllegalStateException("Listener invalid for this notifier.");
}
}
项目:fitnotifications
文件:ICUNotifier.java
/**
* Stop notifying this listener. The listener must
* not be null. Attemps to remove a listener that is
* not registered will be silently ignored.
*/
public void removeListener(EventListener l) {
if (l == null) {
throw new NullPointerException();
}
synchronized (notifyLock) {
if (listeners != null) {
// identity equality check
Iterator<EventListener> iter = listeners.iterator();
while (iter.hasNext()) {
if (iter.next() == l) {
iter.remove();
if (listeners.size() == 0) {
listeners = null;
}
return;
}
}
}
}
}
项目:jdk8u-jdk
文件:AWTEventMulticaster.java
private static int populateListenerArray(EventListener[] a, EventListener l, int index) {
if (l instanceof AWTEventMulticaster) {
AWTEventMulticaster mc = (AWTEventMulticaster)l;
int lhs = populateListenerArray(a, mc.a, index);
return populateListenerArray(a, mc.b, lhs);
}
else if (a.getClass().getComponentType().isInstance(l)) {
a[index] = l;
return index + 1;
}
// Skip nulls, instances of wrong class
else {
return index;
}
}
项目:Equella
文件:DefaultSectionInfo.java
private <T extends EventListener> List<Object> getListeners(@Nullable String target, Class<T> clazz)
{
List<Object> listenerList = new ArrayList<Object>();
for( SectionTree tree : trees )
{
listenerList.addAll(tree.getListeners(target, clazz));
}
return listenerList;
}
项目:incubator-netbeans
文件:BaseDocument.java
private void fireAtomicLock(AtomicLockEvent evt) {
EventListener[] listeners = listenerList.getListeners(org.netbeans.api.editor.document.AtomicLockListener.class);
int cnt = listeners.length;
for (int i = 0; i < cnt; i++) {
((org.netbeans.api.editor.document.AtomicLockListener)listeners[i]).atomicLock(evt);
}
}
项目:incubator-netbeans
文件:BaseDocument.java
private void fireAtomicUnlock(AtomicLockEvent evt) {
EventListener[] listeners = listenerList.getListeners(org.netbeans.api.editor.document.AtomicLockListener.class);
int cnt = listeners.length;
for (int i = 0; i < cnt; i++) {
((org.netbeans.api.editor.document.AtomicLockListener)listeners[i]).atomicUnlock(evt);
}
}
项目:incubator-netbeans
文件:WeakListener.java
/**
* @param listenerClass class/interface of the listener
* @param l listener to delegate to, <code>l</code> must be an instance of
* listenerClass
*/
protected WeakListener(Class listenerClass, java.util.EventListener l) {
this.listenerClass = listenerClass;
ref = new ListenerReference(l, this);
if (!listenerClass.isAssignableFrom(l.getClass())) {
throw new IllegalArgumentException(
getClass().getName() + " constructor is calling WeakListner.<init> with illegal arguments"
); // NOI18N
}
}
项目:incubator-netbeans
文件:PriorityDocumentListenerList.java
/**
* Implementation of DocumentListener's method fires all the added
* listeners according to their priority.
*/
public void removeUpdate(DocumentEvent evt) {
logEvent(evt, "removeUpdate");
// Fire the prioritized listeners
EventListener[][] listenersArray = getListenersArray();
// Attempt to fire to all listeners catching possible exception(s) and report first fired then
RuntimeException runtimeException = null;
for (int priority = listenersArray.length - 1; priority >= 0; priority--) {
logPriority(priority);
EventListener[] listeners = listenersArray[priority];
for (int i = listeners.length - 1; i >= 0; i--) {
DocumentListener l = (DocumentListener) listeners[i];
logListener(l);
try {
l.removeUpdate(evt);
} catch (RuntimeException ex) {
if (runtimeException == null) { // Only record first thrown
runtimeException = ex;
}
}
}
}
if (runtimeException != null) {
throw runtimeException; // Re-throw remembered exception
}
logEventEnd("removeUpdate");
}
项目:lams
文件:ServletContextImpl.java
@Override
public void addListener(final String className) {
try {
Class<? extends EventListener> clazz = (Class<? extends EventListener>) deploymentInfo.getClassLoader().loadClass(className);
addListener(clazz);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
}
项目:incubator-netbeans
文件:PriorityListenerListTest.java
public void testSerialization() throws Exception {
PriorityListenerList<EventListener> ll = new PriorityListenerList<EventListener>();
ll.add(new L(), 3);
ll.add(new L(), 1);
ll.add(new L(), 1);
NbMarshalledObject mo = new NbMarshalledObject(ll);
PriorityListenerList sll = (PriorityListenerList)mo.get();
EventListener[][] lla = ll.getListenersArray();
EventListener[][] slla = sll.getListenersArray();
assertEquals(lla.length, slla.length);
for (int priority = lla.length - 1; priority >= 0; priority--) {
assertEquals(lla[priority].length, slla[priority].length);
}
}
项目:openjdk-jdk10
文件:GUIInitializedMulticaster.java
protected static EventListener removeInternal(EventListener l, EventListener oldl) {
if (l == oldl || l == null) {
return null;
} else if (l instanceof GUIInitializedMulticaster) {
return ((GUIInitializedMulticaster)l).remove(oldl);
} else {
return l; // it's not here
}
}
项目:hy.common.base
文件:TriggerEvent.java
/**
* 添加事件监听者
*
* 注意:1. 内部验证已保证事件监听者都是同一类型的
* 2. 当没有定义事件监听者的类型时,第一个监听者的类型就是标准
*
* @param i_EventListener
*/
public synchronized void addListener(EventListener i_EventListener)
{
if ( i_EventListener != null )
{
if ( this.eventListenerClass != null )
{
// 判断入参是否为 this.eventListenerClass 的实现类,保证事件监听者都是同一类型的。
if ( i_EventListener.getClass() != this.eventListenerClass )
{
if ( !MethodReflect.isExtendImplement(i_EventListener ,this.eventListenerClass) )
{
throw new java.lang.ClassCastException("EventListener not implements " + this.eventListenerClass.getName() + ".");
}
}
}
else if ( this.eventListeners.size() <= 0 )
{
// 当没有定义事件监听者的类型时,第一个监听者的类型就是标准
this.setEventListenerClass(i_EventListener.getClass());
}
this.eventListeners.add(i_EventListener);
}
else
{
throw new NullPointerException("EventListener is null.");
}
}
项目:apache-tomcat-7.0.73-with-comment
文件:ApplicationContextFacade.java
@Override
public void addListener(Class<? extends EventListener> listenerClass) {
if (SecurityUtil.isPackageProtectionEnabled()) {
doPrivileged("addListener",
new Class[]{Class.class},
new Object[]{listenerClass});
} else {
context.addListener(listenerClass);
}
}
项目:Pogamut3
文件:Listeners.java
/**
* Removes all listeners that are equal() to this one.
* @param listener
* @return how many listeners were removed
*/
public int removeEqualListener(EventListener listener) {
if (listener == null) return 0;
int removed = 0;
synchronized(listeners) {
boolean listenersIterationOriginal = listenersIteration;
listenersIteration = true;
try {
Iterator<ListenerStore<Listener>> iterator = listeners.iterator();
while(iterator.hasNext()) {
ListenerStore<Listener> store = iterator.next();
Listener storedListener = store.getListener();
if (storedListener == null) {
if (!listenersIterationOriginal) {
if ((store instanceof WeakListenerStore) && log != null && log.isLoggable(Level.FINE)) {
log.fine((name == null ? "" : name + ": ") + "Weakly referenced listener was GC()ed.");
}
iterator.remove();
}
continue;
}
if (listener.equals(storedListener)) {
store.clearListener();
++removed;
}
}
} finally {
listenersIteration = listenersIterationOriginal;
}
}
return removed;
}
项目:Pogamut3
文件:Listeners.java
/**
* Returns true if at least one equals listener to the param 'listener' is found.
* @param listener
* @return
*/
public boolean isEqualListening(EventListener listener) {
if (listener == null) return false;
synchronized(listeners) {
boolean listenersIterationOriginal = listenersIteration;
listenersIteration = true;
try {
Iterator<ListenerStore<Listener>> iterator = listeners.iterator();
while(iterator.hasNext()) {
ListenerStore<Listener> store = iterator.next();
Listener storedListener = store.getListener();
if (storedListener == null) {
if (!listenersIterationOriginal) {
if ((store instanceof WeakListenerStore) && log != null && log.isLoggable(Level.FINE)) {
log.fine((name == null ? "" : name + ": ") + "Weakly referenced listener was GC()ed.");
}
iterator.remove();
}
continue;
}
if (listener.equals(storedListener)) {
return true;
}
}
} finally {
listenersIteration = listenersIterationOriginal;
}
}
return false;
}
项目:lams
文件:ManagedListener.java
public EventListener instance() {
if (!started) {
try {
start();
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
return handle.getInstance();
}
项目:marathonv5
文件:EventListenerList.java
@SuppressWarnings("unchecked") public <T extends EventListener> T[] getListeners(Class<T> t) {
Object[] lList = listenerList;
int n = getListenerCount(lList, t);
T[] result = (T[]) Array.newInstance(t, n);
int j = 0;
for (int i = lList.length - 2; i >= 0; i -= 2) {
if (lList[i] == t) {
result[j++] = (T) lList[i + 1];
}
}
return result;
}
项目:openaudible
文件:EventListenerList.java
/**
* Return an array of all the listeners of the given type.
*
* @return all of the listeners of the specified type.
* @throws ClassCastException if the supplied class
* is not assignable to EventListener
* @since 1.3
*/
public <T extends EventListener> T[] getListeners(Class<T> t) {
Object[] lList = listenerList;
int n = getListenerCount(lList, t);
T[] result = (T[]) Array.newInstance(t, n);
int j = 0;
for (int i = lList.length - 2; i >= 0; i -= 2) {
if (lList[i] == t) {
result[j++] = (T) lList[i + 1];
}
}
return result;
}
项目:xdman
文件:ProtocolCommandSupport.java
/***
* Fires a ProtocolCommandEvent signalling the sending of a command to all
* registered listeners, invoking their
* {@link org.apache.commons.net.ProtocolCommandListener#protocolCommandSent protocolCommandSent() }
* methods.
* <p>
* @param command The string representation of the command type sent, not
* including the arguments (e.g., "STAT" or "GET").
* @param message The entire command string verbatim as sent to the server,
* including all arguments.
***/
public void fireCommandSent(String command, String message)
{
ProtocolCommandEvent event;
event = new ProtocolCommandEvent(__source, command, message);
for (EventListener listener : __listeners)
{
((ProtocolCommandListener)listener).protocolCommandSent(event);
}
}
项目:tomcat7
文件:ApplicationContextFacade.java
@Override
public <T extends EventListener> void addListener(T t) {
if (SecurityUtil.isPackageProtectionEnabled()) {
doPrivileged("addListener",
new Class[]{EventListener.class},
new Object[]{t});
} else {
context.addListener(t);
}
}
项目:MetadataEditor
文件:EventListenerList.java
/**
* Return an array of all the listeners of the given type.
* @return all of the listeners of the specified type.
* @exception ClassCastException if the supplied class
* is not assignable to EventListener
*
* @since 1.3
*/
public <T extends EventListener> T[] getListeners(Class<T> t) {
Object[] lList = listenerList;
int n = getListenerCount(lList, t);
T[] result = (T[])Array.newInstance(t, n);
int j = 0;
for (int i = lList.length-2; i>=0; i-=2) {
if (lList[i] == t) {
result[j++] = (T)lList[i+1];
}
}
return result;
}
项目:lams
文件:ListenerInfo.java
public ListenerInfo(final Class<? extends EventListener> listenerClass) {
this.listenerClass = listenerClass;
try {
final Constructor<EventListener> ctor = (Constructor<EventListener>) listenerClass.getDeclaredConstructor();
ctor.setAccessible(true);
this.instanceFactory = new ConstructorInstanceFactory<>(ctor);
} catch (NoSuchMethodException e) {
throw UndertowServletMessages.MESSAGES.componentMustHaveDefaultConstructor("Listener", listenerClass);
}
}
项目:lazycat
文件:ApplicationContextFacade.java
@Override
public void addListener(Class<? extends EventListener> listenerClass) {
if (SecurityUtil.isPackageProtectionEnabled()) {
doPrivileged("addListener", new Class[] { Class.class }, new Object[] { listenerClass });
} else {
context.addListener(listenerClass);
}
}
项目:scanning
文件:AbstractConsumerTest.java
private void dynamicBean(final StatusBean bean, IConsumer<StatusBean> fconsumer, int statusSize) throws Exception {
// Hard code the service for the test
ISubscriber<EventListener> sub = eservice.createSubscriber(fconsumer.getUri(), fconsumer.getStatusTopicName());
sub.addListener(new IBeanListener<StatusBean>() {
@Override
public void beanChangePerformed(BeanEvent<StatusBean> evt) {
if (!evt.getBean().getName().equals(bean.getName())) {
System.out.println("This is not our bean! It's called "+evt.getBean().getName()+" and we are "+bean.getName());
Thread.dumpStack();
}
}
});
doSubmit(bean);
Thread.sleep(500);
List<StatusBean> stati = fconsumer.getStatusSet();
if (stati.size()!=statusSize) throw new Exception("Unexpected status size in queue! Size "+stati.size()+" expected "+statusSize+". Might not have status or have forgotten to clear at end of test!");
StatusBean complete = stati.get(0); // The queue is date sorted.
if (complete.equals(bean)) {
throw new Exception("The bean from the status queue was the same as that submitted! It should have a different status. q="+complete+" submit="+bean);
}
if (complete.getStatus()!=Status.COMPLETE) {
throw new Exception("The bean in the queue is not complete!"+complete);
}
if (complete.getPercentComplete()<100) {
throw new Exception("The percent complete is less than 100!"+complete);
}
sub.disconnect();
}
项目:openjdk-jdk10
文件:AWTEventMulticaster.java
/**
* Saves a Serializable listener chain to a serialization stream.
*
* @param s the stream to save to
* @param k a prefix stream to put before each serializable listener
* @param l the listener chain to save
* @throws IOException if serialization fails
*/
protected static void save(ObjectOutputStream s, String k, EventListener l) throws IOException {
if (l == null) {
return;
}
else if (l instanceof AWTEventMulticaster) {
((AWTEventMulticaster)l).saveInternal(s, k);
}
else if (l instanceof Serializable) {
s.writeObject(k);
s.writeObject(l);
}
}
项目:openaudible
文件:EventListenerList.java
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException {
listenerList = NULL_ARRAY;
s.defaultReadObject();
Object listenerTypeOrNull;
while (null != (listenerTypeOrNull = s.readObject())) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
EventListener l = (EventListener) s.readObject();
add((Class<EventListener>) Class.forName((String) listenerTypeOrNull, true, cl), l);
}
}
项目:Equella
文件:WrappedSectionInfo.java
@Override
public <L extends EventListener> void queueEvent(SectionEvent<L> event)
{
info.queueEvent(event);
}
项目:jdk8u-jdk
文件:DnDEventMulticaster.java
protected static void save(ObjectOutputStream s, String k, EventListener l)
throws IOException {
AWTEventMulticaster.save(s, k, l);
}
项目:incubator-netbeans
文件:WeakListener.java
/** @param listener listener to delegate to
*/
public ProxyListener(Class c, java.util.EventListener listener) {
super(c, listener);
proxy = Proxy.newProxyInstance(c.getClassLoader(), new Class[] { c }, this);
}
项目:Equella
文件:DefaultSectionTree.java
@Override
public List<SectionEvent<? extends EventListener>> getApplicationEvents()
{
return applicationEvents;
}
项目:jdk8u-jdk
文件:Test7148143.java
public CustomProxy() {
super(new EventListener() {
});
}
项目:incubator-netbeans
文件:ListenerList.java
public EventListener[] getArray() {
return array;
}
项目:hy.common.base
文件:TriggerEvent.java
/**
* 获取:事件监听器的源类型
*/
public synchronized Class<? extends EventListener> getEventListenerClass()
{
return eventListenerClass;
}
项目:hy.common.base
文件:TriggerEvent.java
/**
* 触发(通知)所有监听者,执行某一动作的执行
*
* 当执行动作方法的返回值类型是Boolean时,表示是否中断后面的监听器的继续执行
*
* @param i_MethodName 执行动作的方法名称(不区分大小写)
* @param i_MethodArgs 执行动作方法的参数
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InvocationTargetException
*/
public synchronized void trigger(String i_MethodName ,Object ... i_MethodArgs) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
if ( Help.isNull(this.eventListeners) )
{
return;
}
if ( Help.isNull(this.eventListenerMethods) )
{
return;
}
if ( Help.isNull(i_MethodName) )
{
throw new NullPointerException("Method name is null.");
}
MethodInfo v_ActionMehod = this.eventListenerMethods.get(i_MethodName.trim().toUpperCase());
if ( v_ActionMehod == null )
{
throw new NullPointerException("Method[" + i_MethodName + "] is not find.");
}
Iterator<EventListener> v_Iter = this.eventListeners.iterator();
boolean v_IsContinue = true;
while ( v_IsContinue && v_Iter.hasNext() )
{
EventListener v_EventListener = v_Iter.next();
Object v_ActionRet = v_ActionMehod.toMethod(v_EventListener).invoke(v_EventListener ,i_MethodArgs);
if ( this.isAllowBreak )
{
if ( v_ActionRet instanceof Boolean )
{
v_IsContinue = (Boolean)v_ActionRet;
}
}
}
}