View Javadoc
1   package fr.paris.lutece.portal.service.event;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   import java.util.function.Consumer;
6   
7   import fr.paris.lutece.portal.business.event.AbstractLuteceEvent;
8   import fr.paris.lutece.portal.service.util.AppLogService;
9   
10  public  abstract class  AbstractEventManager <T extends AbstractLuteceEvent> 
11  {
12  
13  	private Map<String, Consumer<T>> _listeners = new HashMap<>( );
14     
15      /**
16       * Subscribe to this listener.
17       *
18       * @param listener
19       *            the listener
20       */
21  	public void register( String strName, Consumer<T> consumerFunction )
22      {
23      	_listeners.put( strName, consumerFunction );
24          AppLogService.info( "New Lutece event listener registered : {}", strName );
25      }
26      
27      /**
28       * Subscribe to this listener.
29       *
30       * @param listener
31       *            the listener
32       */
33  	public void notifyListeners( T event )
34      {
35          for ( String key : _listeners.keySet( ) )
36          {
37          	_listeners.get( key ).accept( event );            
38          }
39      }
40  }