static CollectorAggregator newInstance(final String name, final NotificationListener listener) { return new CollectorAggregator(name,listener); }
void connect(final List<CollectorConfiguration> collectors) throws ControllerException { LOGGER.info("Setting up collector aggregator for {}...",this.name); startNotificationPump(); for(final CollectorConfiguration collector:collectors) { verifyCollectorIsNotConfigured(collector); addCollector(collector, queueName(collector)); } LOGGER.info("Collector aggregator for {} connected",this.name); }
/** * Shutdown the notification manager. Upon shutdown, the listener will stop * receiving notifications. */ public void shutdown() { LOGGER.info("Shutting down notification manager {}...",this.id); this.aggregator.disconnect(); LOGGER.info("Notification manager {} shutdown",this.id); }
private void shutdownGracefully() { disconnectControllers(); stopNotificationPump(); this.brokerInstances.clear(); this.brokerCollectors.clear(); drainPendingNotifications(); }
void disconnect() { LOGGER.info("Disconnecting {} collector aggregator...",this.name); shutdownGracefully(); LOGGER.info("Collector aggregator for {} disconnected",this.name); }
/** * 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); }
/** * Start the notification manager. Upon this point, the manager will push to * the listener any notification sent by the specified Collector instances. * * @throws IOException * if the notification manager cannot connect to the specified * to the brokers used by the specified Collectors instances */ public void start() throws IOException { LOGGER.info("Starting notification manager {}...",this.id); try { this.aggregator.connect(this.collectors); LOGGER.info("Notification manager {} started",this.id); } catch (final ControllerException e) { LOGGER.warn("Could not connect to collectors of {}. Full stacktrace follows",this.id,e); throw new IOException("Could not connect to collectors of "+this.id,e); } }
private void addCollector(final CollectorConfiguration collector, final String queueName) throws ControllerException { final boolean isNew=!this.brokerCollectors.containsKey(queueName); this.brokerInstances.put(queueName,collector.getInstance()); this.instanceBroker.put(collector.getInstance(),queueName); this.brokerCollectors.put(queueName,collector); if(isNew) { final CollectorController controller=startController(collector,queueName); this.brokerController.put(queueName, controller); this.connectedControllers.add(controller); } }
private void verifyCollectorIsNotConfigured(final CollectorConfiguration collector) { if(this.brokerInstances.containsValue(collector.getInstance())) { shutdownGracefully(); throw new IllegalArgumentException("Multiple configurations found for collector "+collector.getInstance()); } }
private CollectorController startController(final CollectorConfiguration collector, final String queueName) throws ControllerException { final CollectorController controller = CollectorController.createNamedReceiver(collector,queueName,this.notificationQueue); LOGGER.info("Connecting controller for collector {}...",collector.getInstance()); try { controller.connect(); return controller; } catch (final ControllerException e) { LOGGER.warn("Could not connect controller for collector {}. Full stacktrace follows",collector.getInstance(),e); shutdownGracefully(); throw e; } }