/** * * @param e * @param beanManager */ public void registerMessageEvent(@Observes ProcessObserverMethod<Message, ?> e) { final ObserverMethod<Message> method = e.getObserverMethod(); for (Annotation a : method.getObservedQualifiers()) { if (a instanceof OnConnected) { registerMessageObserver(OnConnected.class, method); // e.veto(); // CDI 2.0 } else if (a instanceof OnSend) { registerMessageObserver(OnSend.class, method); // e.veto(); // CDI 2.0 } else if (a instanceof OnSubscribe) { registerMessageObserver(OnSubscribe.class, method); // e.veto(); // CDI 2.0 } else if (a instanceof OnUnsubscribe) { registerMessageObserver(OnUnsubscribe.class, method); // e.veto(); // CDI 2.0 } else if (a instanceof OnDisconnect) { registerMessageObserver(OnDisconnect.class, method); // e.veto(); // CDI 2.0 } } }
@Test @SuppressWarnings("unchecked") public void register_onConnected() { final ProcessObserverMethod<Message, ?> processObserverMethod = mock(ProcessObserverMethod.class); final ObserverMethod<Message> observerMethod = mock(ObserverMethod.class); when(processObserverMethod.getObserverMethod()).thenReturn(observerMethod); when(observerMethod.getObservedQualifiers()).thenReturn(singleton(OnConnected.Literal.onConnected())); this.extension.registerMessageEvent(processObserverMethod); assertEquals(observerMethod, getMessageObservers(this.extension).get(OnConnected.class).iterator().next()); verify(processObserverMethod).getObserverMethod(); verify(observerMethod).getObservedQualifiers(); verifyNoMoreInteractions(processObserverMethod, observerMethod); }
@Test @SuppressWarnings("unchecked") public void register_onSend() { final ProcessObserverMethod<Message, ?> processObserverMethod = mock(ProcessObserverMethod.class); final ObserverMethod<Message> observerMethod = mock(ObserverMethod.class); when(processObserverMethod.getObserverMethod()).thenReturn(observerMethod); when(observerMethod.getObservedQualifiers()).thenReturn(singleton(onSend(""))); this.extension.registerMessageEvent(processObserverMethod); assertEquals(observerMethod, getMessageObservers(this.extension).get(OnSend.class).iterator().next()); verify(processObserverMethod).getObserverMethod(); verify(observerMethod).getObservedQualifiers(); verifyNoMoreInteractions(processObserverMethod, observerMethod); }
@Test @SuppressWarnings("unchecked") public void register_onSubscribe() { final ProcessObserverMethod<Message, ?> processObserverMethod = mock(ProcessObserverMethod.class); final ObserverMethod<Message> observerMethod = mock(ObserverMethod.class); when(processObserverMethod.getObserverMethod()).thenReturn(observerMethod); when(observerMethod.getObservedQualifiers()).thenReturn(singleton(onSubscribe(""))); this.extension.registerMessageEvent(processObserverMethod); assertEquals(observerMethod, getMessageObservers(this.extension).get(OnSubscribe.class).iterator().next()); verify(processObserverMethod).getObserverMethod(); verify(observerMethod).getObservedQualifiers(); verifyNoMoreInteractions(processObserverMethod, observerMethod); }
@Test @SuppressWarnings("unchecked") public void register_onUnsubscribe() { final ProcessObserverMethod<Message, ?> processObserverMethod = mock(ProcessObserverMethod.class); final ObserverMethod<Message> observerMethod = mock(ObserverMethod.class); when(processObserverMethod.getObserverMethod()).thenReturn(observerMethod); when(observerMethod.getObservedQualifiers()).thenReturn(singleton(onUnsubscribe(""))); this.extension.registerMessageEvent(processObserverMethod); assertEquals(observerMethod, getMessageObservers(this.extension).get(OnUnsubscribe.class).iterator().next()); verify(processObserverMethod).getObserverMethod(); verify(observerMethod).getObservedQualifiers(); verifyNoMoreInteractions(processObserverMethod, observerMethod); }
@Test @SuppressWarnings("unchecked") public void register_onDisconnect() { final ProcessObserverMethod<Message, ?> processObserverMethod = mock(ProcessObserverMethod.class); final ObserverMethod<Message> observerMethod = mock(ObserverMethod.class); when(processObserverMethod.getObserverMethod()).thenReturn(observerMethod); when(observerMethod.getObservedQualifiers()).thenReturn(singleton(onDisconnect())); this.extension.registerMessageEvent(processObserverMethod); assertEquals(observerMethod, getMessageObservers(this.extension).get(OnDisconnect.class).iterator().next()); verify(processObserverMethod).getObserverMethod(); verify(observerMethod).getObservedQualifiers(); verifyNoMoreInteractions(processObserverMethod, observerMethod); }
private <T extends EventObject> void camelEventNotifiers(@Observes ProcessObserverMethod<T, ?> pom) { // Only activate Camel event notifiers for explicit Camel event observers, that is, an observer method for a super type won't activate notifiers. Type type = pom.getObserverMethod().getObservedType(); // Camel events are raw types if (type instanceof Class && Class.class.cast(type).getPackage().equals(AbstractExchangeEvent.class.getPackage())) { Set<Annotation> qualifiers = pom.getObserverMethod().getObservedQualifiers(); if (qualifiers.isEmpty()) { eventQualifiers.add(ANY); } else if (qualifiers.size() == 1 && qualifiers.stream() .filter(isAnnotationType(Named.class)).findAny().isPresent()) { eventQualifiers.add(DEFAULT); } else { eventQualifiers.addAll(qualifiers); } } }
/** * * @param e * @param beanManager */ public void registerDestinationEvent(@Observes ProcessObserverMethod<DestinationChanged, ?> e) { final ObserverMethod<DestinationChanged> method = e.getObserverMethod(); for (Annotation a : method.getObservedQualifiers()) { if (a instanceof OnAdded) registerDestinationObserver(OnAdded.class, method); if (a instanceof OnRemoved) registerDestinationObserver(OnRemoved.class, method); } }
public void processVertxEventObserver(@Observes ProcessObserverMethod<VertxEvent, ?> event) { String vertxAddress = getVertxAddress(event.getObserverMethod()); if (vertxAddress == null) { LOGGER.warn("VertxEvent observer found but no @VertxConsumer declared: {0}", event.getObserverMethod()); return; } LOGGER.debug("Vertx message consumer found: {0}", event.getObserverMethod()); consumerAddresses.add(vertxAddress); }
private <T extends EventObject> void camelEventNotifiers(@Observes ProcessObserverMethod<T, ?> pom) { // Only activate Camel event notifiers for explicit Camel event observers, that is, // an observer method for a super type won't activate notifiers. Type type = pom.getObserverMethod().getObservedType(); // Camel events are raw types if (type instanceof Class && Class.class.cast(type).getPackage().equals(AbstractExchangeEvent.class.getPackage())) { Set<Annotation> qualifiers = pom.getObserverMethod().getObservedQualifiers(); if (qualifiers.isEmpty()) eventQualifiers.add(ANY); else if (qualifiers.size() == 1 && qualifiers.stream().anyMatch(isAnnotationType(Named.class))) eventQualifiers.add(DEFAULT); else eventQualifiers.addAll(qualifiers); } }
<K, V> void processObserverMethod(@Observes ProcessObserverMethod<K, V> pom) { logger.info("finished the scanning process"); processObserverMethod++; }
private final <X> void processObserverMethod(@Observes final ProcessObserverMethod<Event, X> event, final BeanManager beanManager) { if (event != null && beanManager != null && !this.startWatcher && event.getObserverMethod() != null) { this.startWatcher = true; } }
<T, X> void logLifecycleEvent(@Observes ProcessObserverMethod<T, X> event) { LOGGER.info("ProcessObserverMethod: observerMethod" + event.getObserverMethod()); }