com.github.lontime.extredisson.service.DelayedConsumerProcessor Maven / Gradle / Ivy
package com.github.lontime.extredisson.service;
import java.time.Duration;
import com.github.lontime.base.commonj.components.DelayedProcessor;
import com.github.lontime.base.commonj.utils.LoggerHelper;
import com.github.lontime.extredisson.configuration.ConsumerOption;
/**
* DelayedConsumerProcessor.
* @author lontime
* @since 1.0
*/
public class DelayedConsumerProcessor extends DelayedProcessor {
private final ConsumerOption consumerOptions;
private DefaultStreamService service;
public DelayedConsumerProcessor(ConsumerOption consumerOptions) {
this.consumerOptions = consumerOptions;
this.service = new DefaultStreamService(consumerOptions);
}
@Override
protected Duration sleepTimeout() {
return consumerOptions.getInterval();
}
@Override
protected Duration initialDelay() {
return consumerOptions.getWarmup();
}
@Override
protected void startUp() {
LoggerHelper.info(getClass(), "startUp state {0}", currentState());
if (service != null) {
service.initialize();
}
}
@Override
public boolean doLoop() {
if (service != null) {
return service.doLoop();
}
return false;
}
}