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

bt.processor.ChainProcessor Maven / Gradle / Ivy

There is a newer version: 1.10
Show newest version
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;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy