class AMQPUrlWaiter implements ApplicationListener<ApplicationEvent> {

    public AMQPUrlWaiter() {}

    static protected final Logger logger = Logger.getLogger(AMQPUrlWaiter.class.getName());

    protected int urlsPublished = 0;
    protected int urlsReceived = 0;

    protected CrawlController controller;
    public CrawlController getCrawlController() {
        return this.controller;
    }
    @Autowired
    public void setCrawlController(CrawlController controller) {
        this.controller = controller;
    }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof AMQPUrlPublishedEvent) {
            urlsPublished += 1;
        } else if (event instanceof AMQPUrlReceivedEvent) {
            urlsReceived += 1;
        } else if (event instanceof StatSnapshotEvent) {
            checkAMQPUrlWait();
        }
    }

    protected void checkAMQPUrlWait() {<FILL_FUNCTION_BODY>}
}

        if (controller.getState() == CrawlController.State.EMPTY && (urlsPublished == 0 || urlsReceived > 0)) {
            logger.info("crawl controller state is empty and we have received " + urlsReceived +
                        " urls from AMQP, and published " + urlsPublished +
                        ", stopping crawl with status " + CrawlStatus.FINISHED);
            controller.requestCrawlStop(CrawlStatus.FINISHED);
        }
    
<no_super_class>