DefaultRepositoryEventDispatcher implements RepositoryEventDispatcher, Service { public void dispatch( RepositoryEvent event ) { if ( !listeners.isEmpty() ) { for ( RepositoryListener listener : listeners ) { dispatch( event, listener ); } } if ( !localRepositoryMaintainers.isEmpty() ) { if ( EventType.ARTIFACT_DOWNLOADED.equals( event.getType() ) ) { DefaultLocalRepositoryEvent evt = new DefaultLocalRepositoryEvent( LocalRepositoryEvent.EventType.ARTIFACT_DOWNLOADED, event.getSession(), event.getArtifact(), event.getFile() ); for ( LocalRepositoryMaintainer maintainer : localRepositoryMaintainers ) { try { maintainer.artifactDownloaded( evt ); } catch ( Exception e ) { logError( e, maintainer ); } } } else if ( EventType.ARTIFACT_INSTALLED.equals( event.getType() ) ) { DefaultLocalRepositoryEvent evt = new DefaultLocalRepositoryEvent( LocalRepositoryEvent.EventType.ARTIFACT_INSTALLED, event.getSession(), event.getArtifact(), event.getFile() ); for ( LocalRepositoryMaintainer maintainer : localRepositoryMaintainers ) { try { maintainer.artifactInstalled( evt ); } catch ( Exception e ) { logError( e, maintainer ); } } } } RepositoryListener listener = event.getSession().getRepositoryListener(); if ( listener != null ) { dispatch( event, listener ); } } DefaultRepositoryEventDispatcher();  DefaultRepositoryEventDispatcher( Logger logger, List<RepositoryListener> listeners );  DefaultRepositoryEventDispatcher( Logger logger, List<RepositoryListener> listeners,
                                             List<LocalRepositoryMaintainer> localRepositoryMaintainers ); DefaultRepositoryEventDispatcher setLogger( Logger logger ); DefaultRepositoryEventDispatcher addListener( RepositoryListener listener ); DefaultRepositoryEventDispatcher setListeners( List<RepositoryListener> listeners ); DefaultRepositoryEventDispatcher addLocalRepositoryMaintainer( LocalRepositoryMaintainer maintainer ); DefaultRepositoryEventDispatcher setLocalRepositoryMaintainers( List<LocalRepositoryMaintainer> maintainers ); void initService( ServiceLocator locator ); void dispatch( RepositoryEvent event );  }
@Test public void testDispatchHandlesAllEventTypes() throws Exception { DefaultRepositoryEventDispatcher dispatcher = new DefaultRepositoryEventDispatcher(); ListenerHandler handler = new ListenerHandler(); RepositoryListener listener = (RepositoryListener) Proxy.newProxyInstance( getClass().getClassLoader(), new Class<?>[] { RepositoryListener.class }, handler ); TestRepositorySystemSession session = new TestRepositorySystemSession(); session.setRepositoryListener( listener ); for ( RepositoryEvent.EventType type : RepositoryEvent.EventType.values() ) { DefaultRepositoryEvent event = new DefaultRepositoryEvent( type, session, null ); handler.methodName = null; dispatcher.dispatch( event ); assertNotNull( "not handled: " + type, handler.methodName ); assertEquals( "badly handled: " + type, type.name().replace( "_", "" ).toLowerCase( Locale.ENGLISH ), handler.methodName.toLowerCase( Locale.ENGLISH ) ); } }