com.zipwhip.concurrent.OnlyRunIfNotSuccessfulObserverAdapter Maven / Gradle / Ivy
package com.zipwhip.concurrent;
import com.zipwhip.events.Observer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* So we can do conditionals with constructors
*
* @param
*/
public class OnlyRunIfNotSuccessfulObserverAdapter implements Observer> {
private final static Logger LOGGER = LoggerFactory.getLogger(OnlyRunIfNotSuccessfulObserverAdapter.class);
final Observer> observer;
public OnlyRunIfNotSuccessfulObserverAdapter(Observer> observer) {
this.observer = observer;
}
@Override
public void notify(Object sender, ObservableFuture item) {
if (!item.isSuccess()) {
if (LOGGER.isTraceEnabled())
LOGGER.trace(String.format("Running %s/%s/%s", observer, sender, item));
observer.notify(sender, item);
} else {
if (LOGGER.isTraceEnabled())
LOGGER.trace("Did not notify inner observer because successful. " + item);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy