Class ListenerService

java.lang.Object
io.meeds.deeds.service.ListenerService
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

@Component public class ListenerService extends Object implements org.springframework.context.ApplicationContextAware
  • Field Details

    • ES_LAST_SCANNED_DATE_SETTING_NAME

      public static final String ES_LAST_SCANNED_DATE_SETTING_NAME
      See Also:
    • LOG

      public static final org.slf4j.Logger LOG
    • subscriptionConnection

      protected io.lettuce.core.pubsub.StatefulRedisPubSubConnection<String,String> subscriptionConnection
    • publicationConnection

      protected io.lettuce.core.pubsub.StatefulRedisPubSubConnection<String,String> publicationConnection
  • Constructor Details

    • ListenerService

      public ListenerService()
  • Method Details

    • publishEvent

      public void publishEvent(String eventName, Object data)
      Triggers an event locally and remotely using persistent event listening based on a dedicated Elasticsearch index to persist the event and generates a unique identifier for it. This event id will be published on Redis as well in order to instantly inform all consumers that a new event has been published in Elasticsearch. If redis is down or out of service, a Scheduled Job ListenerEventTriggerTask on each consumer will retrieve events periodically.
      Parameters:
      eventName - Event Name as configured for listeners in EventListener.getSupportedEvents()
      data - Data Object to pass to listeners when executing EventListener.onEvent(String, Object)
    • addListener

      public void addListener(EventListener<?> listener)
      Add manually a listener for a dedicated event. This method is useless in general case since the listeners are added automatically when defined as any regular Spring Bean Component and that it inherits from EventListener
      Parameters:
      listener - local EventListener
    • removeListsner

      public void removeListsner(String listenerName)
      Removes all EventListener that have EventListener.getName() the designated name in param
      Parameters:
      listenerName - name of listeners to remove
    • removeListsner

      public void removeListsner(String eventName, String listenerName)
      Removes all EventListener that have EventListener.getName() the designated name in param and a EventListener.getSupportedEvents() as designated in param name
      Parameters:
      eventName - EventListener.getSupportedEvents() event name
      listenerName - EventListener.getName() name
    • triggerElasticSearchEvents

      public void triggerElasticSearchEvents()
      An INTERNAL method that is used to be triggered periodically through the Scheduled Task ListenerEventTriggerTask. In general case, this must not be used outside this provided Task.
    • cleanupElasticsearchEvents

      public void cleanupElasticsearchEvents()
      An INTERNAL method that is used to be triggered periodically through the Scheduled Task ListenerEventCleanupTask. In general case, this must not be used outside this provided Scheduled Task. This cleanup will be triggered on one single instance which has made a configuration of its periodicity, which is by default, the dApp only.
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • init

      @PostConstruct protected void init()
    • destroy

      @PreDestroy protected void destroy()
    • getListeners

      protected Map<String,List<EventListener<?>>> getListeners()