Example usage for java.util ServiceLoader forEach

List of usage examples for java.util ServiceLoader forEach

Introduction

In this page you can find the example usage for java.util ServiceLoader forEach.

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

From source file:org.kie.workbench.common.migration.cli.MigrationApp.java

public MigrationApp(String args[]) {

    actualConfig = parseToolConfigOrExit(args);

    ServiceLoader<MigrationTool> migrationLoader = ServiceLoader.load(MigrationTool.class);

    migrationLoader.forEach(migrationTool -> migrationTools.add(migrationTool));

    Collections.sort(migrationTools, Comparator.comparing(MigrationTool::getPriority));
}

From source file:org.wso2.ballerinalang.compiler.BinaryFileWriter.java

public void writeExecutableBinary(BLangPackage packageNode, String fileName) {
    String execFileName = cleanupExecFileName(fileName, BLANG_COMPILED_PROG_EXT);

    // Generate code for the given executable
    ProgramFile programFile = this.codeGenerator.generateBALX(packageNode);
    ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
    try {//ww  w .  ja  v a  2s  .  co  m
        ProgramFileWriter.writeProgram(programFile, byteArrayOS);
    } catch (IOException e) {
        throw new BLangCompilerException("error writing program file '" + execFileName + "'", e);
    }

    final Path execFilePath = this.sourceDirectory
            .saveCompiledProgram(new ByteArrayInputStream(byteArrayOS.toByteArray()), execFileName);
    ServiceLoader<CompilerPlugin> processorServiceLoader = ServiceLoader.load(CompilerPlugin.class);
    processorServiceLoader.forEach(plugin -> {
        plugin.codeGenerated(packageNode.packageID, execFilePath);
    });
}