use of com.github.robozonky.api.notifications.ExecutionCompletedEvent in project robozonky by RoboZonky.
the class JmxListenerServiceTest method getParametersForExecutionCompleted.
private DynamicTest getParametersForExecutionCompleted() {
final ExecutionCompletedEvent evt = new ExecutionCompletedEvent(Collections.emptyList(), null);
final Consumer<SoftAssertions> before = (softly) -> {
softly.assertThat(getRuntimeMBean().getZonkyUsername()).isEqualTo("");
};
final Consumer<SoftAssertions> after = (softly) -> {
softly.assertThat(getRuntimeMBean().getZonkyUsername()).isEqualTo(USERNAME);
softly.assertThat(getRuntimeMBean().getLatestUpdatedDateTime()).isEqualTo(evt.getCreatedOn());
softly.assertThat(getPortfolioMBean().getLatestUpdatedDateTime()).isEqualTo(evt.getCreatedOn());
};
return getParameters(evt, before, after);
}
use of com.github.robozonky.api.notifications.ExecutionCompletedEvent in project robozonky by RoboZonky.
the class Session method invest.
public static Collection<Investment> invest(final Portfolio portfolio, final Investor investor, final Authenticated auth, final Collection<LoanDescriptor> loans, final RestrictedInvestmentStrategy strategy) {
final Session session = new Session(portfolio, loans, investor, auth);
final PortfolioOverview portfolioOverview = session.portfolioOverview;
final int balance = portfolioOverview.getCzkAvailable();
Events.fire(new ExecutionStartedEvent(loans, portfolioOverview));
if (balance >= Defaults.MINIMUM_INVESTMENT_IN_CZK && !session.getAvailable().isEmpty()) {
session.invest(strategy);
}
final Collection<Investment> result = session.getResult();
// make sure we get fresh portfolio reference here
Events.fire(new ExecutionCompletedEvent(result, session.portfolioOverview));
return Collections.unmodifiableCollection(result);
}
use of com.github.robozonky.api.notifications.ExecutionCompletedEvent 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;
}
}
Aggregations