/** * Shutdown the notification publisher. Upon shutdown, the user will not be * able to push notifications. */ public void shutdown() { LOGGER.info("Shutting down notification publisher for {}...",this.configuration.getInstance()); this.controller.disconnect(); LOGGER.info("Notification manager {} shutdown",this.configuration.getInstance()); }
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()); } }
/** * Start the notification publisher. Upon this point, the user will be able * to push notifications. * * @throws IOException * if the notification publisher cannot connect to the broker * used by the specified Collector configuration */ public void start() throws IOException { LOGGER.info("Starting notification publisher for {}...",this.configuration.getInstance()); try { this.controller.connect(); LOGGER.info("Notification publisher for {} started",this.configuration.getInstance()); } catch (final ControllerException e) { LOGGER.warn("Could not start publisher using {}. Full stacktrace follows",this.configuration,e); throw new IOException("Could not start publisher using "+this.configuration,e); } }
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; } }
private CollectorController(final CollectorConfiguration collector, final String queueName, final BlockingQueue<SuspendedNotification> notificationQueue) { checkNotNull(collector,"Collector cannot be null"); this.collector=collector; this.manager=new ConnectionManager(collector.getInstance(),collector.getBrokerHost(),collector.getBrokerPort(),collector.getVirtualHost()); this.queueName=queueName; this.notificationQueue=notificationQueue; final ReadWriteLock lock=new ReentrantReadWriteLock(); this.write=lock.writeLock(); this.cleaners=Lists.newLinkedList(); this.callbacks=Lists.newArrayList(); }