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

io.github.devsecops.engine.core.InstructionInvoker Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
package io.github.devsecops.engine.core;

import com.google.common.collect.Lists;
import io.github.devsecops.engine.core.contract.Command;
import io.github.devsecops.engine.core.contract.Executor;
import io.github.devsecops.engine.core.contract.Instruction;

import java.util.List;

public class InstructionInvoker implements Command {

    private final List instructions;
    private final Executor executor;

    private InstructionInvoker(Executor executor) {
        this.executor = executor;
        this.instructions = Lists.newArrayList();
    }
    public InstructionInvoker append(Instruction instruction) {
        this.instructions.add(instruction);
        return this;
    }
    public static InstructionInvoker init(Executor executor) {
        return new InstructionInvoker(executor);
    }

    @Override
    public void execute() throws Exception {
        for (Instruction instruction : instructions) {
            executor.execute(instruction.getCmd());
        }
    }

    @Override
    public void rollback() throws Exception {
        throw new UnsupportedOperationException("No rollback defined for multiple instructions");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy