use of org.motechproject.event.listener.EventListener in project motech by motech.
the class EventListenerRegistryTest method testRegisterSingleListener.
@Test
public void testRegisterSingleListener() {
EventListener sel = new SampleEventListener();
registry.registerListener(sel, "org.motechproject.server.someevent");
Set<EventListener> listeners = registry.getListeners("org.motechproject.server.someevent");
assertNotNull(listeners);
assertTrue(listeners.size() == 1);
assertEquals(listeners.iterator().next(), sel);
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class EventListenerRegistryTest method testRegisterTwice.
@Test
public void testRegisterTwice() {
EventListener sel = new SampleEventListener();
registry.registerListener(sel, "org.motechproject.server.someevent");
registry.registerListener(sel, "org.motechproject.server.someevent");
Set<EventListener> el = registry.getListeners("org.motechproject.server.someevent");
assertNotNull(el);
assertTrue(el.size() == 1);
assertTrue(el.contains(sel));
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class EventBundleIT method testEventWithTypedPayloadAndMetadata.
@Test
public void testEventWithTypedPayloadAndMetadata() throws Exception {
final ArrayList<MotechEvent> receivedEvents = new ArrayList<>();
registry.registerListener(new EventListener() {
@Override
public void handle(MotechEvent event) {
receivedEvents.add(event);
synchronized (waitLock) {
waitLock.notify();
}
}
@Override
public String getIdentifier() {
return "event";
}
}, "event");
Map<String, Object> params = new HashMap<>();
params.put("foo", new TestEventPayload());
Map<String, Object> metadata = new HashMap<>();
metadata.put("meta", new TestEventPayload());
metadata.put("theNumberSeven", 7);
wait2s();
MotechEvent testEvent = new MotechEvent("event", params);
testEvent.setMetadata(metadata);
eventRelay.sendEventMessage(testEvent);
wait2s();
assertEquals(1, receivedEvents.size());
MotechEvent receivedEvent = receivedEvents.get(0);
assertTrue(receivedEvent.getParameters().get("foo") instanceof TestEventPayload);
assertEquals(2, receivedEvent.getMetadata().size());
assertTrue(receivedEvent.getMetadata().containsKey("meta"));
assertTrue(receivedEvent.getMetadata().containsKey("theNumberSeven"));
assertTrue(receivedEvent.getMetadata().get("meta") instanceof TestEventPayload);
assertEquals(7, receivedEvent.getMetadata().get("theNumberSeven"));
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class ServerEventRelay method relayTopicEvent.
/**
* Relays the event that were published in the message topic to all listeners of that event.
*
* @param event the event being relayed
*/
public void relayTopicEvent(MotechEvent event) {
verifyEventNotNull(event);
Set<EventListener> listeners = getEventListeners(event);
for (EventListener listener : listeners) {
handleTopicEvent(listener, event);
}
// broadcast events can be also be additionally sent as OSGi events upon being received
if (proxyInOsgi(event)) {
sendInOSGi(event);
}
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class ServerEventRelay method relayQueueEvent.
/**
* Relays the event that were published in the message queue to all listeners of that event.
*
* @param event the event being relayed
*/
public void relayQueueEvent(MotechEvent event) {
verifyEventNotNull(event);
String messageDestination = event.getMessageDestination();
if (null != messageDestination) {
EventListener listener = getEventListener(event, messageDestination);
if (null != listener) {
MotechEvent e = copyMotechEvent(event);
handleQueueEvent(listener, e);
} else {
LOGGER.warn("Event listener with identifier {} not present to handle the event: {}", messageDestination, event);
}
} else {
LOGGER.warn("Message destination not present in event: {}", event);
}
}
Aggregations