Search in sources :

Example 1 with Saga

use of io.muoncore.newton.saga.Saga 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();
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) NewtonEvent(io.muoncore.newton.NewtonEvent) URL(java.net.URL) Saga(io.muoncore.newton.saga.Saga) AggregateRoot(io.muoncore.newton.AggregateRoot) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) Reflections(org.reflections.Reflections)

Aggregations

AggregateRoot (io.muoncore.newton.AggregateRoot)1 NewtonEvent (io.muoncore.newton.NewtonEvent)1 Saga (io.muoncore.newton.saga.Saga)1 URL (java.net.URL)1 Reflections (org.reflections.Reflections)1 SubTypesScanner (org.reflections.scanners.SubTypesScanner)1 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)1 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)1