public void run() {
        int timesFailed = 0;

        try {
            while (shouldRun()) {
                try {
                    listen();
                    timesFailed = 0;
                } catch (XMLStreamException e) {
                    timesFailed++;
                    if (shouldRun && timesFailed > MAXIMUM_RETRIES) {
                        disconnect("XML failure: " + e.getMessage());
                    }
                } catch (SAXException e) {
                    timesFailed++;
                    if (shouldRun && timesFailed > MAXIMUM_RETRIES) {
                        disconnect("SAX failure: " + e.getMessage());
                    }
                } catch (IOException e) {
                    if (shouldRun) {
                        disconnect("IO failure: " + e.getMessage());
                    }
                }
            }
        } finally {
            askToStop();
        }
    }