/** * Create a new instance that will interact with a collection of Collectors * and will push the notifications sent by these Collectors to the specified * NotificationListener * * @param collectors * the Collector instance configuration details * @param listener * the NotificationListener to which the notifications will be * pushed * @return the created instance * @throws NullPointerException * if any of the parameters is {@code null} */ public static NotificationManager newInstance(final List<CollectorConfiguration> collectors, final NotificationListener listener) { checkNotNull(collectors,"Target cannot be null"); checkNotNull(listener,"Listener cannot be null"); return new NotificationManager(collectors,listener); }
/** * TODO: Collector is not immutable, therefore the configuration could be * externally changed... */ private NotificationManager(final List<CollectorConfiguration> collectors, final NotificationListener listener) { this.id=UUID.randomUUID(); this.collectors=ImmutableList.copyOf(collectors); this.aggregator=CollectorAggregator.newInstance(managerName(this.id),listener); }
@Override public void onSuccess(final Boolean result) { DynamicPublisher.this.publishingCompleted.countDown(); if(result) { LOGGER.info("Initial publication completed. Started notification handling..."); } else { DynamicPublisher.this.manager.shutdown(); LOGGER.warn("Initial publication failed. Notification handling aborted."); } }
DynamicPublisher(final BackendController controller, final List<CollectorConfiguration> config) { this.controller = controller; this.pool = MoreExecutors. listeningDecorator( Executors. newFixedThreadPool( 10, new ThreadFactoryBuilder(). setNameFormat("Publisher-thread-%d"). build() ) ); this.publishingCompleted = new CountDownLatch(1); this.manager= NotificationManager. newInstance( config, new PublishingNotificationListener( this.publishingCompleted, controller.getTarget())); }
try { LOGGER.info("Starting notification manager..."); this.manager.start(); LOGGER.info("Started notification manager. Starting initial publication...");
@Override public void stop() { LOGGER.info("Finishing publisher..."); shutdownPool(); this.manager.shutdown(); LOGGER.info("Publisher finished."); }