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

skadistats.clarity.processor.runner.AbstractRunner Maven / Gradle / Ivy

Go to download

Clarity is an open source replay parser for Dota 2, CSGO, CS2 and Deadlock written in Java.

There is a newer version: 3.1.1
Show newest version
package skadistats.clarity.processor.runner;

import org.slf4j.Logger;
import skadistats.clarity.ClarityExceptionHandler;
import skadistats.clarity.LogChannel;
import skadistats.clarity.event.Event;
import skadistats.clarity.event.InsertEvent;
import skadistats.clarity.event.Provides;
import skadistats.clarity.io.Util;
import skadistats.clarity.logger.PrintfLoggerFactory;
import skadistats.clarity.model.EngineType;

@Provides({OnInit.class})
public abstract class AbstractRunner implements Runner {

    protected static final Logger log = PrintfLoggerFactory.getLogger(LogChannel.runner);

    @InsertEvent
    private Event evInitRun;

    protected final EngineType engineType;
    protected Context context;
    protected ClarityExceptionHandler exceptionHandler = (eventType, parameters, throwable) -> Util.uncheckedThrow(throwable);

    public AbstractRunner(EngineType engineType) {
        this.engineType = engineType;
    }

    private ExecutionModel createExecutionModel(Object... processors) {
        var executionModel = new ExecutionModel(this);
        addProcessorsToModel(executionModel, processors);
        return executionModel;
    }

    private void addProcessorsToModel(ExecutionModel executionModel, Object[] processors) {
        for (var p : processors) {
            if (p instanceof Object[]) {
                addProcessorsToModel(executionModel, (Object[]) p);
            } else {
                executionModel.addProcessor(p);
            }
        }
    }

    protected void initWithProcessors(Object... processors) {
        var em = createExecutionModel(processors);
        context = new Context(em, engineType.getContextData());
        em.initialize(context);
        if (evInitRun != null) {
            evInitRun.raise();
        }
    }

    @Override
    public EngineType getEngineType() {
        return engineType;
    }

    @Override
    public Context getContext() {
        return context;
    }

    @Override
    public ClarityExceptionHandler getExceptionHandler() {
        return exceptionHandler;
    }

    public void setExceptionHandler(ClarityExceptionHandler exceptionHandler) {
        this.exceptionHandler = exceptionHandler;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy