Search in sources :

Example 1 with TransactionApplicationEvents

use of org.qi4j.library.eventsourcing.application.api.TransactionApplicationEvents in project qi4j-sdk by Qi4j.

the class AbstractApplicationEventStoreMixin method storeEvents.

// This is how transactions are put into the store
@Override
public TransactionApplicationEvents storeEvents(Iterable<ApplicationEvent> events) throws IOException {
    // Create new TransactionApplicationEvents
    ValueBuilder<TransactionApplicationEvents> builder = vbf.newValueBuilder(TransactionApplicationEvents.class);
    Iterables.addAll(builder.prototype().events().get(), events);
    builder.prototype().timestamp().set(getCurrentTimestamp());
    final TransactionApplicationEvents transactionDomain = builder.newInstance();
    // Lock store so noone else can interrupt
    lock();
    try {
        storeEvents(transactionDomain);
    } finally {
        lock.unlock();
    }
    // Notify listeners
    transactionNotifier.submit(new Runnable() {

        @Override
        public void run() {
            synchronized (listeners) {
                Input<TransactionApplicationEvents, RuntimeException> input = Inputs.iterable(Collections.singleton(transactionDomain));
                for (Output<TransactionApplicationEvents, ? extends Throwable> listener : listeners) {
                    try {
                        input.transferTo(listener);
                    } catch (Throwable e) {
                        logger.warn("Could not notify event listener", e);
                    }
                }
            }
        }
    });
    return transactionDomain;
}
Also used : Input(org.qi4j.io.Input) TransactionApplicationEvents(org.qi4j.library.eventsourcing.application.api.TransactionApplicationEvents) Output(org.qi4j.io.Output)

Example 2 with TransactionApplicationEvents

use of org.qi4j.library.eventsourcing.application.api.TransactionApplicationEvents 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 3 with TransactionApplicationEvents

use of org.qi4j.library.eventsourcing.application.api.TransactionApplicationEvents 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

TransactionApplicationEvents (org.qi4j.library.eventsourcing.application.api.TransactionApplicationEvents)3 ArrayList (java.util.ArrayList)2 ApplicationEvent (org.qi4j.library.eventsourcing.application.api.ApplicationEvent)2 Input (org.qi4j.io.Input)1 Output (org.qi4j.io.Output)1