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;
}
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));
}
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));
}
Aggregations