use of org.motechproject.event.listener.EventListener in project motech by motech.
the class TaskTriggerHandlerTest method shouldRegisterHandlerForSubject.
@Test
public void shouldRegisterHandlerForSubject() {
String subject = "org.motechproject.messagecampaign.campaign-completed";
handler.registerHandlerFor(subject);
ArgumentCaptor<EventListener> captor = ArgumentCaptor.forClass(EventListener.class);
verify(registryService).registerListener(captor.capture(), eq(subject));
MotechListenerEventProxy proxy = (MotechListenerEventProxy) captor.getValue();
assertEquals("taskTriggerHandler", proxy.getIdentifier());
assertEquals(handler, proxy.getBean());
assertEquals(findMethod(getTargetClass(handler), "handle", MotechEvent.class), proxy.getMethod());
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class EventBundleIT method testEventListener.
@Test
public void testEventListener() throws Exception {
final String subject = "OSGi IT - 001";
final ArrayList<String> receivedEvents = new ArrayList<>();
registry.registerListener(new EventListener() {
@Override
public void handle(MotechEvent event) {
receivedEvents.add(event.getSubject());
synchronized (waitLock) {
waitLock.notify();
}
}
@Override
public String getIdentifier() {
return subject;
}
}, subject);
wait2s();
eventRelay.sendEventMessage(new MotechEvent(subject));
wait2s();
assertEquals(1, receivedEvents.size());
assertEquals(subject, receivedEvents.get(0));
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class EventBundleIT method shouldProxyOSGiEvents.
@Test
public void shouldProxyOSGiEvents() throws InterruptedException {
final ArrayList<MotechEvent> receivedEvents = new ArrayList<>();
final String subject = "OSGi IT PROX";
final DateTime now = DateUtil.now();
final Map<String, Object> params = new HashMap<>();
params.put("now", now);
params.put("key", "value");
registry.registerListener(new EventListener() {
@Override
public void handle(MotechEvent event) {
receivedEvents.add(event);
synchronized (waitLock) {
waitLock.notify();
}
}
@Override
public String getIdentifier() {
return subject;
}
}, subject);
wait2s();
osgiEventProxy.sendEvent(subject, params);
wait2s();
assertEquals(1, receivedEvents.size());
MotechEvent event = receivedEvents.get(0);
assertEquals(subject, event.getSubject());
assertEquals(now, event.getParameters().get("now"));
assertEquals("value", event.getParameters().get("key"));
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class ServerEventRelay method splitEvent.
/**
* Split a given message into multiple messages with specific message destination
* parameters. Message destinations will route the message to the specific message
* listener.
*
* @param event Event message to be split
* @param listeners A list of listeners for this given message that will be used as message destinations
*/
private void splitEvent(MotechEvent event, Set<EventListener> listeners) {
MotechEvent enrichedEventMessage;
Map<String, Object> parameters;
for (EventListener listener : listeners) {
parameters = new HashMap<>();
parameters.putAll(event.getParameters());
enrichedEventMessage = new MotechEvent(event.getSubject(), parameters, event.getCallbackName());
enrichedEventMessage.setMetadata(event.getMetadata());
enrichedEventMessage.setMessageDestination(listener.getIdentifier());
outboundEventGateway.sendEventMessage(enrichedEventMessage);
}
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class EventListenerTree method removeListeners.
private boolean removeListeners(String beanName) {
boolean removed = false;
if (listeners != null) {
for (Iterator<EventListener> listenerIterator = listeners.iterator(); listenerIterator.hasNext(); ) {
EventListener nextListener = listenerIterator.next();
if (nextListener.getIdentifier().equals(beanName)) {
listenerIterator.remove();
removed = true;
}
}
}
if (wildcardListeners != null) {
for (Iterator<EventListener> listenerIterator = wildcardListeners.iterator(); listenerIterator.hasNext(); ) {
EventListener nextListener = listenerIterator.next();
if (nextListener.getIdentifier().equals(beanName)) {
listenerIterator.remove();
removed = true;
}
}
}
for (EventListenerTree childTree : children) {
if (childTree.removeListeners(beanName)) {
removed = true;
}
}
return removed;
}
Aggregations