Search in sources :

Example 1 with ApplicationEvent

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);
}
Also used : ApplicationEvent(org.qi4j.library.eventsourcing.application.api.ApplicationEvent)

Example 2 with ApplicationEvent

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;
}
Also used : UnitOfWorkCallback(org.qi4j.api.unitofwork.UnitOfWorkCallback) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) ApplicationEvent(org.qi4j.library.eventsourcing.application.api.ApplicationEvent) IOException(java.io.IOException)

Example 3 with ApplicationEvent

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));
}
Also used : TransactionApplicationEvents(org.qi4j.library.eventsourcing.application.api.TransactionApplicationEvents) ArrayList(java.util.ArrayList) ApplicationEvent(org.qi4j.library.eventsourcing.application.api.ApplicationEvent)

Example 4 with ApplicationEvent

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));
}
Also used : TransactionApplicationEvents(org.qi4j.library.eventsourcing.application.api.TransactionApplicationEvents) ArrayList(java.util.ArrayList) ApplicationEvent(org.qi4j.library.eventsourcing.application.api.ApplicationEvent)

Aggregations

ApplicationEvent (org.qi4j.library.eventsourcing.application.api.ApplicationEvent)4 ArrayList (java.util.ArrayList)2 TransactionApplicationEvents (org.qi4j.library.eventsourcing.application.api.TransactionApplicationEvents)2 IOException (java.io.IOException)1 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)1 UnitOfWorkCallback (org.qi4j.api.unitofwork.UnitOfWorkCallback)1 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)1