private void ensureDirectoryIsRecreated(final Context ctx) { final File aeronDir = new File(ctx.dirName()); Consumer<String> logProgress = (message) -> {}; if (aeronDir.exists()) { if (ctx.warnIfDirectoriesExist()) { System.err.println("WARNING: " + aeronDir + " already exists."); logProgress = System.err::println; } if (ctx.dirsDeleteOnStart()) { ctx.deleteAeronDirectory(); } else { final boolean driverActive = ctx.isDriverActive(ctx.driverTimeoutMs(), logProgress); if (driverActive) { throw new ActiveDriverException("active driver detected"); } ctx.deleteAeronDirectory(); } } final BiConsumer<String, String> callback = (path, name) -> { if (ctx.warnIfDirectoriesExist()) { System.err.println("WARNING: " + name + " directory already exists: " + path); } }; IoUtil.ensureDirectoryIsRecreated(aeronDir, "aeron", callback); }
/** * Used to access the configured dirName for this MediaDriver Context typically used after the * {@link #launchEmbedded()} method is used. * * @return the context dirName */ public String contextDirName() { return ctx.dirName(); }
/** * Launch an isolated MediaDriver embedded in the current process with a provided configuration * context and a generated dirName (overwrites configured dirName) that can be retrieved by * calling contextDirName. * * @param ctx containing the configuration options. * @return the newly started MediaDriver. */ public static MediaDriver launchEmbedded(final Context ctx) { ctx.dirName(CommonContext.generateRandomDirName()); return launch(ctx); }