use of com.github.robozonky.api.notifications.EventListener in project robozonky by RoboZonky.
the class JmxListenerService method newListener.
private static <T extends Event> EventListener<T> newListener(final Class<T> eventType) {
if (Objects.equals(eventType, ExecutionStartedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((ExecutionStartedEvent) event));
} else if (Objects.equals(eventType, ExecutionCompletedEvent.class)) {
return (event, sessionInfo) -> {
final ExecutionCompletedEvent evt = (ExecutionCompletedEvent) event;
callOnRuntime(bean -> bean.handle(evt, sessionInfo));
callOnPortfolio(bean -> bean.handle(evt));
};
} else if (Objects.equals(eventType, SellingStartedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((SellingStartedEvent) event));
} else if (Objects.equals(eventType, SellingCompletedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((SellingCompletedEvent) event));
} else if (Objects.equals(eventType, PurchasingStartedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((PurchasingStartedEvent) event));
} else if (Objects.equals(eventType, PurchasingCompletedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((PurchasingCompletedEvent) event));
} else if (Objects.equals(eventType, InvestmentDelegatedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentDelegatedEvent) event));
} else if (Objects.equals(eventType, InvestmentRejectedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentRejectedEvent) event));
} else if (Objects.equals(eventType, InvestmentMadeEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentMadeEvent) event));
} else if (Objects.equals(eventType, SaleOfferedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((SaleOfferedEvent) event));
} else if (Objects.equals(eventType, InvestmentPurchasedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentPurchasedEvent) event));
} else {
return null;
}
}
use of com.github.robozonky.api.notifications.EventListener in project robozonky by RoboZonky.
the class Checker method notifications.
public static boolean notifications(final String username, final List<EventListenerSupplier<RoboZonkyTestingEvent>> refreshables) {
final Collection<EventListener<RoboZonkyTestingEvent>> listeners = refreshables.stream().flatMap(r -> r.get().map(Stream::of).orElse(Stream.empty())).collect(Collectors.toSet());
if (listeners.size() > 0) {
final SessionInfo sessionInfo = new SessionInfo(username);
final RoboZonkyTestingEvent evt = new RoboZonkyTestingEvent();
listeners.forEach(l -> l.handle(evt, sessionInfo));
return true;
} else {
return false;
}
}
use of com.github.robozonky.api.notifications.EventListener in project robozonky by RoboZonky.
the class ListenerServiceLoaderTest method correctLoading.
@Test
void correctLoading() {
final RoboZonkyStartingEvent e = new RoboZonkyStartingEvent();
final EventListener<RoboZonkyStartingEvent> l = mock(EventListener.class);
final ListenerService s1 = mock(ListenerService.class);
final EventListenerSupplier<RoboZonkyStartingEvent> returned = () -> Optional.of(l);
doReturn(returned).when(s1).findListener(eq(e.getClass()));
final ListenerService s2 = mock(ListenerService.class);
doReturn((EventListenerSupplier<RoboZonkyStartingEvent>) Optional::empty).when(s2).findListener(eq(e.getClass()));
final Iterable<ListenerService> s = () -> Arrays.asList(s1, s2).iterator();
final List<EventListenerSupplier<RoboZonkyStartingEvent>> r = ListenerServiceLoader.load(RoboZonkyStartingEvent.class, s);
assertThat(r).hasSize(2);
assertThat(r).first().has(new Condition<>(result -> result.get().isPresent() && result.get().get() == l, "Exists"));
assertThat(r).last().has(new Condition<>(result -> !result.get().isPresent(), "Does not exist"));
}
Aggregations