List of usage examples for java.util EventListener getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java
/** * Sets an event listener to be called when events occur, so they can be reported * by the app as, for example, Google Analytics events. * If not set or set to null, no events will be reported. * * @param eventListener The event listener. * @throws IllegalArgumentException if the eventListener is an inner or anonymous class *//*from w w w. j a va 2 s . c om*/ public static void setEventListener(EventListener eventListener) { if (eventListener != null && eventListener.getClass().getEnclosingClass() != null && !Modifier.isStatic(eventListener.getClass().getModifiers())) { throw new IllegalArgumentException( "The event listener cannot be an inner or anonymous class, because it will need to be serialized. Change it to a class of its own, or make it a static inner class."); } else { CustomActivityOnCrash.eventListener = eventListener; } }
From source file:com.mindquarry.desktop.event.EventBus.java
/** * Registers an event listener to receive all events sent over this * EventBus./*from w w w .java2 s .co m*/ */ public void registerEventListener(EventListener listener) { log.info("registerEventListener: listener=" + listener.getClass().getName()); registeredListeners.add(listener); }
From source file:com.mindquarry.desktop.event.EventBus.java
/** * Unregisters an registered event listener so that it no longer * receives any events sent over this Eventbus. *///from w w w. j a v a2 s . c o m public void unregisterEventListener(EventListener listener) { log.info("unregisterEventListener: listener=" + listener.getClass().getName()); if (registeredListeners.contains(listener)) { registeredListeners.remove(listener); } }
From source file:org.openmrs.event.EventEngine.java
/** * @see Event#unsubscribe(Destination, EventListener) *//* ww w .j ava 2 s . com*/ public void unsubscribe(Destination dest, EventListener listener) { initializeIfNeeded(); if (dest != null) { Topic topic = (Topic) dest; try { String key = topic.getTopicName() + DELIMITER + listener.getClass().getName(); if (subscribers.get(key) != null) subscribers.get(key).close(); subscribers.remove(key); } catch (JMSException e) { log.error("Failed to unsubscribe from the specified destination:", e); } } }
From source file:com.netspective.sparx.Project.java
public void addListener(EventListener listener) { if (listener instanceof ProjectLifecyleListener) lifecycleListeners.add(listener); else//from w w w . ja v a2 s. co m log.error("Unknown listener type: " + listener.getClass()); }
From source file:org.openmrs.event.EventEngine.java
/** * @see Event#subscribe(Destination, EventListener) */// w w w.j av a2 s . c o m public void subscribe(Destination destination, final EventListener listenerToRegister) { initializeIfNeeded(); TopicConnection conn; Topic topic = (Topic) destination; try { conn = (TopicConnection) jmsTemplate.getConnectionFactory().createConnection(); TopicSession session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); TopicSubscriber subscriber = session.createSubscriber(topic); subscriber.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { listenerToRegister.onMessage(message); } }); //Check if this is a duplicate and remove it String key = topic.getTopicName() + DELIMITER + listenerToRegister.getClass().getName(); if (subscribers.containsKey(key)) { unsubscribe(destination, listenerToRegister); } subscribers.put(key, subscriber); conn.start(); } catch (JMSException e) { // TODO Auto-generated catch block. Do something smarter here. e.printStackTrace(); } // List<EventListener> currentListeners = listeners.get(key); // // if (currentListeners == null) { // currentListeners = new ArrayList<EventListener>(); // currentListeners.add(listenerToRegister); // listeners.put(key, currentListeners); // if (log.isInfoEnabled()) // log.info("subscribed: " + listenerToRegister + " to key: " // + key); // // } else { // // prevent duplicates because of weird spring loading // String listernToRegisterName = listenerToRegister.getClass() // .getName(); // Iterator<EventListener> iterator = currentListeners.iterator(); // while (iterator.hasNext()) { // EventListener lstnr = iterator.next(); // if (lstnr.getClass().getName().equals(listernToRegisterName)) // iterator.remove(); // } // // if (log.isInfoEnabled()) // log.info("subscribing: " + listenerToRegister + " to key: " // + key); // // currentListeners.add(listenerToRegister); // } }
From source file:org.eclipse.scanning.event.SubscriberImpl.java
private boolean diseminate(Object bean, Collection<T> listeners) { if (listeners == null) return false; if (listeners.isEmpty()) return false; final EventListener[] ls = listeners.toArray(new EventListener[listeners.size()]); boolean ret = true; for (EventListener listener : ls) { @SuppressWarnings("unchecked") List<Class<?>> types = getAllInterfaces(listener.getClass()); boolean diseminated = false; for (Class<?> type : types) { DiseminateHandler handler = dMap.get(type); if (handler == null) continue; handler.diseminate(bean, listener); diseminated = true;/*from w w w . ja v a 2 s . co m*/ } ret = ret && diseminated; } return ret; }
From source file:org.ireland.jnetty.http.HttpServletRequestImpl.java
public void addEventListener(final EventListener listener) { if (listener instanceof ServletRequestAttributeListener) { if (_requestAttributeListeners == null) _requestAttributeListeners = new ArrayList<ServletRequestAttributeListener>(); _requestAttributeListeners.add((ServletRequestAttributeListener) listener); }/* w w w.ja v a 2 s. c o m*/ if (listener instanceof AsyncListener) throw new IllegalArgumentException(listener.getClass().toString()); }
From source file:org.jahia.services.templates.TemplatePackageRegistry.java
public void handleJCREventListener(Object bean, final boolean register) { final DefaultEventListener eventListener = (DefaultEventListener) bean; if (eventListener.getEventTypes() > 0) { try {//from ww w.ja v a2 s.c om JCRTemplate.getInstance().doExecuteWithSystemSessionAsUser(null, eventListener.getWorkspace(), null, new JCRCallback<Object>() { public Object doInJCR(JCRSessionWrapper session) throws RepositoryException { final Workspace workspace = session.getWorkspace(); ObservationManager observationManager = workspace.getObservationManager(); //first remove existing listener of same type final EventListenerIterator registeredEventListeners = observationManager .getRegisteredEventListeners(); while (registeredEventListeners.hasNext()) { javax.jcr.observation.EventListener next = registeredEventListeners .nextEventListener(); if (next.getClass().equals(eventListener.getClass()) && (!(next instanceof DefaultEventListener) || StringUtils.equals( ((DefaultEventListener) next).getWorkspace(), eventListener.getWorkspace()))) { observationManager.removeEventListener(next); break; } } if (register) { observationManager.addEventListener(eventListener, eventListener.getEventTypes(), eventListener.getPath(), eventListener.isDeep(), eventListener.getUuids(), eventListener.getNodeTypes(), false); } return null; } }); if (logger.isDebugEnabled()) { logger.debug((register ? "Registering" : "Unregistering") + " event listener" + eventListener.getClass().getName() + " for workspace '" + eventListener.getWorkspace() + "'"); } } catch (RepositoryException e) { logger.error(e.getMessage(), e); } } else { logger.info("Skipping listener {} as it has no event types configured.", eventListener.getClass().getName()); } }
From source file:ru.caffeineim.protocols.icq.metainfo.AffilationsUserInfoParser.java
protected void sendMessage(EventListener listener, EventObject e) { log.debug("notify listener " + listener.getClass().getName() + " onAffilationUserInfo()"); ((MetaInfoListener) listener).onAffilationsUserInfo((MetaAffilationsUserInfoEvent) e); }