All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.addc.commons.queue.ReaderDelayGenerator Maven / Gradle / Ivy

Go to download

The addc-queues library supplies support for internal persistent queues using an optional DERBY database for storage.

The newest version!
package com.addc.commons.queue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.addc.commons.delay.DelayGenerator;

/**
 * The ReaderDelayGenerator generates exponentially increasing delays (1, 2, 4,
 * 8, 16, 32) in a {@link PersistingQueue} for errors thrown from a
 * {@link PayloadDispatcher}. Once the delay reaches 32 seconds it will keep
 * that value until the generator is reset.
 *
 */
public class ReaderDelayGenerator extends DelayGenerator implements PersistingQueueReaderListener {

    private static final Logger LOGGER= LoggerFactory.getLogger(ReaderDelayGenerator.class);
    private boolean lostConnection;
    
    /**
     * Constructor
     * @param reader The reader to listen to
     */
    public ReaderDelayGenerator(PersistingQueueReader reader) {
        super();
        reader.addListener(this);
        LOGGER.info("Created delay geneerator");
    }

    @Override
    public void onProcess(boolean lostConn, Exception excep) {
        LOGGER.debug("lost connection {}", lostConn);
        if (this.lostConnection != lostConn) {
            this.lostConnection= lostConn;
            LOGGER.debug("Re-initialize delay generator, connected={}", !lostConn);
            reset();
        }
    }

    @Override
    public void onDispatcherError(Exception e) {
        // These are handled elsewhere
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy