class OakMachine {

    static Consumer<ProgressCheck>
    newProgressCheckEventConsumer(final boolean silenced,
                                  final @NotNull Fun.ThrowingConsumer<ProgressCheck> checkVisitor,
                                  final @NotNull BiConsumer<ProgressCheck, Exception> onError) {
        Consumer<ProgressCheck> consumer = check -> {
            try {
                if (silenced && check instanceof SilenceableCheck) {
                    ((SilenceableCheck) check).setSilenced(silenced);
                }
                if (!silenced || check instanceof SilenceableCheck) {
                    checkVisitor.tryAccept(check);
                }
            } catch (final Exception e) {
                if (!silenced) {
                    onError.accept(check, e);
                }
            }
        };
        return consumer.andThen(check -> {
            if (silenced && check instanceof SilenceableCheck) {
                ((SilenceableCheck) check).setSilenced(false);
            }
        });
    }

    private  OakMachine(final Packaging packagingService,
                       final List<ProgressCheck> progressChecks,
                       final ErrorListener errorListener,
                       final List<URL> preInstallUrls,
                       final List<InitStage> initStages,
                       final JcrCustomizer jcrCustomizer,
                       final InstallHookProcessorFactory installHookProcessorFactory,
                       final ClassLoader installHookClassLoader,
                       final boolean enablePreInstallHooks,
                       final InstallHookPolicy scanInstallHookPolicy,
                       final Supplier<NodeStore> nodeStoreSupplier,
                       final SubpackageSilencer subpackageSilencer,
                       final RepoInitProcessor repoInitProcessor,
                       final SlingSimulatorBackend slingSimulator,
                       final Set<String> runModes);

}