static CollectorController createPublisher(final CollectorConfiguration collector) { return new CollectorController(collector,null,null); }
private NotificationPublisher(final CollectorConfiguration configuration) { this.configuration = configuration; this.controller=CollectorController.createPublisher(configuration); }
private void disconnectControllers() { final Iterator<CollectorController> iterator = this.connectedControllers.descendingIterator(); while(iterator.hasNext()) { iterator.next().disconnect(); } this.connectedControllers.clear(); this.brokerController.clear(); }
void connect() throws ControllerException { this.write.lock(); try { checkState(!this.manager.isConnected(),"Already connected"); this.manager.connect(); declareExchange(); prepareQueue(); } catch(final ControllerException e) { disconnectGracefully(); throw e; } finally { this.write.unlock(); } }
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 void prepareQueue() throws ControllerException { if(this.notificationQueue!=null) { this.actualQueueName = declareQueue(); bindQueue(this.actualQueueName); try { final Channel currentChannel = this.manager.channel(); final NotificationConsumer callback = new NotificationConsumer(currentChannel,this.notificationQueue); currentChannel. basicConsume( this.actualQueueName, false, callback ); this.callbacks.add(callback); } catch (final IOException e) { throw new ControllerException(this.collector.getBrokerHost(),this.collector.getBrokerPort(),this.collector.getVirtualHost(),"Could not register consumer for queue '"+this.actualQueueName+"'",e); } } }
void disconnect() { this.write.lock(); try { disconnectGracefully(); } finally { this.write.unlock(); } }
private void disconnectGracefully() { if(this.manager.isConnected()) { cleanUp(); this.callbacks.clear(); this.actualQueueName=null; this.manager.disconnect(); } }
/** * 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); } }
static CollectorController createAnonymousReceiver(final CollectorConfiguration collector, final BlockingQueue<SuspendedNotification> queue) { checkNotNull(queue,"Notification queue cannot be null"); return new CollectorController(collector,null,queue); }
/** * 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()); }
static CollectorController createNamedReceiver(final CollectorConfiguration collector, final String queueName, final BlockingQueue<SuspendedNotification> queue) { Amqp.validateName(queueName,"Queue name"); checkNotNull(queue,"Notification queue cannot be null"); return new CollectorController(collector,queueName,queue); }