use of org.qi4j.library.eventsourcing.application.api.ApplicationEvent in project qi4j-sdk by Qi4j.
the class ApplicationEventCreationConcern method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (args[0] == null) {
// Create application event
ApplicationEvent event = eventFactory.createEvent(method.getName(), args);
args[0] = event;
}
return next.invoke(proxy, method, args);
}
use of org.qi4j.library.eventsourcing.application.api.ApplicationEvent in project qi4j-sdk by Qi4j.
the class TransactionNotificationConcern method createEvent.
@Override
public ApplicationEvent createEvent(String name, Object[] args) {
final UnitOfWork unitOfWork = uowf.currentUnitOfWork();
ApplicationEvent event = next.createEvent(name, args);
// Add event to list in UoW
UnitOfWorkApplicationEvents events = unitOfWork.metaInfo(UnitOfWorkApplicationEvents.class);
if (events == null) {
events = new UnitOfWorkApplicationEvents();
unitOfWork.setMetaInfo(events);
unitOfWork.addUnitOfWorkCallback(new UnitOfWorkCallback() {
@Override
public void beforeCompletion() throws UnitOfWorkCompletionException {
}
@Override
public void afterCompletion(UnitOfWorkStatus status) {
if (status.equals(UnitOfWorkStatus.COMPLETED)) {
UnitOfWorkApplicationEvents events = unitOfWork.metaInfo(UnitOfWorkApplicationEvents.class);
try {
eventStore.storeEvents(events.getEvents());
} catch (IOException e) {
logger.error("Could not store events", e);
// How do we handle this? This is a major error!
}
}
}
});
}
events.add(event);
return event;
}
use of org.qi4j.library.eventsourcing.application.api.ApplicationEvent in project qi4j-sdk by Qi4j.
the class ApplicationEvents method events.
public static Iterable<ApplicationEvent> events(Iterable<TransactionApplicationEvents> transactions) {
List<Iterable<ApplicationEvent>> events = new ArrayList<Iterable<ApplicationEvent>>();
for (TransactionApplicationEvents transactionDomain : transactions) {
events.add(transactionDomain.events().get());
}
Iterable<ApplicationEvent>[] iterables = (Iterable<ApplicationEvent>[]) new Iterable[events.size()];
return Iterables.flatten(events.<Iterable<ApplicationEvent>>toArray(iterables));
}
use of org.qi4j.library.eventsourcing.application.api.ApplicationEvent in project qi4j-sdk by Qi4j.
the class ApplicationEvents method events.
public static Iterable<ApplicationEvent> events(TransactionApplicationEvents... transactionDomains) {
List<Iterable<ApplicationEvent>> events = new ArrayList<Iterable<ApplicationEvent>>();
for (TransactionApplicationEvents transactionDomain : transactionDomains) {
events.add(transactionDomain.events().get());
}
Iterable<ApplicationEvent>[] iterables = (Iterable<ApplicationEvent>[]) new Iterable[events.size()];
return Iterables.flatten(events.<Iterable<ApplicationEvent>>toArray(iterables));
}
Aggregations