use of io.muoncore.newton.NewtonEvent in project newton by muoncore.
the class MuonLookupUtils method init.
static void init(String[] packages) {
List<URL> urls = new ArrayList<>();
urls.addAll(ClasspathHelper.forPackage("io.muoncore.newton", MuonLookupUtils.class.getClassLoader()));
for (String aPackage : packages) {
log.info("Adding package {}", aPackage);
Collection<URL> urls1 = ClasspathHelper.forPackage(aPackage, MuonLookupUtils.class.getClassLoader());
log.info("Got {}", urls1);
urls.addAll(urls1);
}
log.info("Booting Reflections with urls {}", urls);
Reflections reflections = new Reflections(new ConfigurationBuilder().addScanners(new SubTypesScanner()).addScanners(new TypeAnnotationsScanner()).setUrls(urls));
final Set<Class<? extends NewtonEvent>> eventTypes = reflections.getSubTypesOf(NewtonEvent.class);
eventTypeMappings = new HashMap<>();
for (Class<? extends NewtonEvent> newtonEvent : eventTypes) {
eventTypeMappings.put(newtonEvent.getSimpleName(), newtonEvent);
}
final Set<Class<? extends AggregateRoot>> aggregateRootTypes = reflections.getSubTypesOf(AggregateRoot.class);
aggregateRootMappings = new HashMap<>();
for (Class<? extends AggregateRoot> root : aggregateRootTypes) {
aggregateRootMappings.put(root.getSimpleName(), root);
}
final Set<Class<? extends Saga>> sagaTypes = reflections.getSubTypesOf(Saga.class);
sagaTypeMappings = new HashMap<>();
for (Class<? extends Saga> root : sagaTypes) {
sagaTypeMappings.put(root.getSimpleName(), root);
}
ready.countDown();
}
use of io.muoncore.newton.NewtonEvent in project newton by muoncore.
the class MuonClusterAwareTrackingSubscriptionManager method localTrackingSubscription.
private void localTrackingSubscription(String subscriptionName, String streamName, Consumer<NewtonEvent> onData, Consumer<Throwable> onError) {
EventStreamIndex eventStreamIndex = getEventStreamIndex(subscriptionName, streamName);
Long lastSeen = eventStreamIndex.getLastSeen() + 1;
log.info("Subscribing from index {} to event stream {} '{}'", lastSeen, subscriptionName, streamName);
Map args = new HashMap();
args.put("from", lastSeen);
args.put("sub-name", subscriptionName);
eventClient.replay(streamName, EventReplayMode.REPLAY_THEN_LIVE, args, new EventSubscriber(event -> {
log.trace("Store is {}, event is {}, time is {}", eventStreamIndexStore, event, event.getOrderId());
Class<? extends NewtonEvent> eventType = MuonLookupUtils.getDomainClass(event);
if (log.isTraceEnabled()) {
log.trace("Store is {}, event is {}, time is {}", eventStreamIndexStore, event, event.getOrderId());
}
eventStreamIndexStore.save(new EventStreamIndex(subscriptionName, event.getOrderId() == null ? 0l : event.getOrderId()));
NewtonEvent newtonEvent;
if (eventType == null) {
newtonEvent = new EventTypeNotFound(event.getOrderId(), event);
} else {
newtonEvent = MuonLookupUtils.decorateMeta(event.getPayload(eventType), event);
}
worker.execute(() -> {
eventStreamProcessor.executeWithinEventContext(newtonEvent, onData);
});
}, onError));
}
Aggregations