class OakMachine {

    void processInstallableQueue(final @NotNull Session admin,
                                 final @NotNull JcrPackageManager manager,
                                 final @NotNull PackageId lastPackageId,
                                 final boolean preInstall) throws RepositoryException {
        final Session inspectSession = Util.wrapSessionReadOnly(admin);
        SlingInstallable dequeued = slingSimulator.dequeueInstallable();
        while (dequeued != null) {
            final SlingInstallable installable = dequeued;

            propagateCheckPackageEvent(preInstall, installable.getParentId(),
                    check -> check.beforeSlingInstall(lastPackageId, installable, inspectSession));

            Optional<SlingRepoInitScripts> initScriptsResult =
                    Optional.ofNullable(SlingRepoInitScripts.fromSlingInstallable(installable));

            initScriptsResult.ifPresent(initScripts -> {
                for (final String repoInitScript : initScripts.getScripts()) {
                    try (Reader reader = new StringReader(repoInitScript)) {
                        repoInitProcessor.apply(admin, reader);
                        admin.save();
                    } catch (final Exception e) {
                        getErrorListener().onSlingRepoInitScriptsError(e, initScripts.getScripts(),
                                repoInitScript, installable);
                        Fun.<Session>uncheckVoid1(session -> session.refresh(false)).accept(admin);
                    }
                }
                propagateCheckPackageEvent(preInstall, installable.getParentId(),
                        check -> check.appliedRepoInitScripts(lastPackageId, initScripts.getScripts(),
                                installable, inspectSession));
            });

            if (installable instanceof EmbeddedPackageInstallable) {
                processEmbeddedPackage(admin, manager, (EmbeddedPackageInstallable) installable, preInstall);
            }

            // do this at the end of the while scope, obviously.
            dequeued = slingSimulator.dequeueInstallable();
        }
    }

    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);

}