bt.processor.ChainProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bt-core Show documentation
Show all versions of bt-core Show documentation
BitTorrent Client Library (Core)
package bt.processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChainProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(ChainProcessor.class);
public static void execute(ProcessingStage chainHead, C context) {
ProcessingStage next = doExecute(chainHead, context);
if (next != null) {
execute(next, context);
}
}
private static ProcessingStage doExecute(ProcessingStage stage, C context) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Processing next stage: torrent ID (%s), stage (%s)",
context.getTorrentId().orElse(null), stage.getClass().getName()));
}
try {
return stage.execute(context);
} catch (Throwable e) {
LOGGER.error(String.format("Processing failed with error: torrent ID (%s), stage (%s)",
context.getTorrentId().orElse(null), stage.getClass().getName()), e);
throw e;
}
}
}