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

com.lithium.mineraloil.waiters.WaitConditionWithFailureAction Maven / Gradle / Ivy

There is a newer version: 0.1.23
Show newest version
package com.lithium.mineraloil.waiters;

import lombok.Delegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class WaitConditionWithFailureAction implements WaiterWithFailureAction {
    private final Logger logger = LoggerFactory.getLogger(WaitConditionWithFailureAction.class);

    private final int waitTimeBeforeExecutingFailureAction = 20;

    @Delegate
    WaiterImpl waiter;

    public WaitConditionWithFailureAction() {
        waiter = new WaiterImpl<>(this);
    }

    public boolean checkWaitCondition(long waitTimeElapsed, int timeout) {
        // try the onFailure if we've been in in this loop more than 20% of the allotted time
        double waiterProgressPercentage = ((double) waitTimeElapsed / (double) timeout) * 100;
        if (waiterProgressPercentage > waitTimeBeforeExecutingFailureAction) {
            logger.info(String.format("waiter progress: %.2f%% (running failure action)", waiterProgressPercentage));
            onFailureAction();
        }

        boolean result = isSatisfied();
        if (!result) {
            logger.info(String.format("waiter progress: %.2f%%", waiterProgressPercentage));
        }
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy