All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elder.sourcerer.spring.SourcererEventConfiguration Maven / Gradle / Ivy

package org.elder.sourcerer.spring;

import org.elder.sourcerer.DefaultEventSubscriptionFactory;
import org.elder.sourcerer.EventRepository;
import org.elder.sourcerer.EventRepositoryFactory;
import org.elder.sourcerer.EventSubscriptionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;

/**
 * Base class for Spring Java configurations defining all required components surrounding a given
 * event, i.e. event repository, and event subscription factory.
 * 

* Components are lazy loaded so as to not use any resources unless actually used in the system *

* To use this class, create a subclass with the given concrete types and any other customizations, * placed in the component scan path of your Spring application. You must also separately configure * a EventRepositoryFactory. */ public class SourcererEventConfiguration { private final Class eventType; @Autowired private EventRepositoryFactory repositoryFactory; protected SourcererEventConfiguration(final Class eventType) { this.eventType = eventType; } @Bean @Lazy @Scope(BeanDefinition.SCOPE_SINGLETON) public EventRepository getEventRepository() { return repositoryFactory.getEventRepository(eventType); } @Bean @Lazy @Scope(BeanDefinition.SCOPE_SINGLETON) EventSubscriptionFactory getEventSubscriptionFactory( final EventRepository eventRepository) { return new DefaultEventSubscriptionFactory<>(eventRepository); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy