@Override public Platform getPlatform(Option... options) { OptionsByType optionsByType = OptionsByType.of(options); PlatformPredicate predicate = optionsByType.getOrDefault(PlatformPredicate.class, PlatformPredicate.any()); Optional<Platform> platform = platforms.stream().filter(predicate).unordered().findFirst(); return platform.isPresent() ? platform.get() : null; } }
@Override public Platform getPlatform(Option... options) { OptionsByType optionsByType = OptionsByType.of(options); PlatformPredicate predicate = optionsByType.getOrDefault(PlatformPredicate.class, PlatformPredicate.any()); Optional<Platform> platform = platforms.stream().filter(predicate).unordered().findFirst(); return platform.isPresent() ? platform.get() : null; } }
@Override public Object resolve(Platform platform, OptionsByType optionsByType) { DisplayName displayName = optionsByType.get(DisplayName.class); PlatformSeparators separators = optionsByType.get(PlatformSeparators.class); String sanitizedDisplayName = separators.asSanitizedFileName(displayName.resolve(optionsByType)); Calendar now = Calendar.getInstance(); String temporaryDirectoryName = String.format("%1$s-%2$tY%2$tm%2$td-%2$tH%2$tM%2$tS-%2$tL", sanitizedDisplayName, now); TemporaryDirectory defaultTemp = TemporaryDirectory.at(separators.getFileSeparator() + "tmp"); TemporaryDirectory temporaryDirectory = optionsByType.getOrDefault(TemporaryDirectory.class, defaultTemp); return new File(temporaryDirectory.get().toFile(), temporaryDirectoryName); } };
@Override public Object resolve(Platform platform, OptionsByType optionsByType) { DisplayName displayName = optionsByType.get(DisplayName.class); PlatformSeparators separators = optionsByType.get(PlatformSeparators.class); String sanitizedDisplayName = separators.asSanitizedFileName(displayName.resolve(optionsByType)); Calendar now = Calendar.getInstance(); String temporaryDirectoryName = String.format("%1$s-%2$tY%2$tm%2$td-%2$tH%2$tM%2$tS-%2$tL", sanitizedDisplayName, now); TemporaryDirectory defaultTemp = TemporaryDirectory.at(separators.getFileSeparator() + "tmp"); TemporaryDirectory temporaryDirectory = optionsByType.getOrDefault(TemporaryDirectory.class, defaultTemp); return new File(temporaryDirectory.get().toFile(), temporaryDirectoryName); } };
/** * Invokes the {@link RemoteCallable} in the {@link JavaApplication}, * waiting the default or provided {@link Timeout} for the result. * * @param callable the {@link RemoteCallable} * @param options the {@link Option}s * * @param <T> the type of the result * @return the value from the {@link RemoteCallable} */ default <T> T invoke(RemoteCallable<T> callable, Option... options) { // determine the timeout OptionsByType optionsByType = OptionsByType.of(options); Timeout timeout = optionsByType.getOrDefault(Timeout.class, getOptions().get(Timeout.class)); CompletableFuture<T> future = submit(callable, options); try { return future.get(timeout.to(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Constructs an {@link Ensured}. * * @param deferred the {@link Deferred} to ensure * @param options the {@link Option} for the {@link Ensured} */ public Ensured(Deferred<T> deferred, Option... options) { // when we're ensuring an ensured, use the adapted deferred // (this is to ensure that we don't attempt to ensure another ensured) this.deferred = deferred instanceof Ensured ? ((Ensured<T>) deferred).getDeferred() : deferred; // determine the timeout constraints based on the provided options OptionsByType optionsByType = OptionsByType.of(options); this.initialDelayDurationMS = optionsByType.getOrDefault(InitialDelay.class, InitialDelay.none()).to(TimeUnit.MILLISECONDS); this.maximumRetryDurationMS = optionsByType.getOrDefault(Timeout.class, Timeout.after(DeferredHelper.getDefaultEnsuredMaximumRetryDuration())) .to(TimeUnit.MILLISECONDS); this.maximumPollingDurationMS = optionsByType.getOrDefault(MaximumRetryDelay.class, MaximumRetryDelay.of(DeferredHelper.getDefaultEnsuredMaximumPollingDuration())) .to(TimeUnit.MILLISECONDS); this.retryDurations = optionsByType.getOrDefault(RetryFrequency.class, RetryFrequency.of(DeferredHelper.getDefaultEnsuredRetryDurationsIterable())) .get().iterator(); }
/** * Invokes the {@link RemoteCallable} in the {@link JavaApplication}, * waiting the default or provided {@link Timeout} for the result. * * @param callable the {@link RemoteCallable} * @param options the {@link Option}s * * @param <T> the type of the result * @return the value from the {@link RemoteCallable} */ default <T> T invoke(RemoteCallable<T> callable, Option... options) { // determine the timeout OptionsByType optionsByType = OptionsByType.of(options); Timeout timeout = optionsByType.getOrDefault(Timeout.class, getOptions().get(Timeout.class)); CompletableFuture<T> future = submit(callable, options); try { return future.get(timeout.to(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Constructs an {@link Ensured}. * * @param deferred the {@link Deferred} to ensure * @param options the {@link Option} for the {@link Ensured} */ public Ensured(Deferred<T> deferred, Option... options) { // when we're ensuring an ensured, use the adapted deferred // (this is to ensure that we don't attempt to ensure another ensured) this.deferred = deferred instanceof Ensured ? ((Ensured<T>) deferred).getDeferred() : deferred; // determine the timeout constraints based on the provided options OptionsByType optionsByType = OptionsByType.of(options); this.initialDelayDurationMS = optionsByType.getOrDefault(InitialDelay.class, InitialDelay.none()).to(TimeUnit.MILLISECONDS); this.maximumRetryDurationMS = optionsByType.getOrDefault(Timeout.class, Timeout.after(DeferredHelper.getDefaultEnsuredMaximumRetryDuration())) .to(TimeUnit.MILLISECONDS); this.maximumPollingDurationMS = optionsByType.getOrDefault(MaximumRetryDelay.class, MaximumRetryDelay.of(DeferredHelper.getDefaultEnsuredMaximumPollingDuration())) .to(TimeUnit.MILLISECONDS); this.retryDurations = optionsByType.getOrDefault(RetryFrequency.class, RetryFrequency.of(DeferredHelper.getDefaultEnsuredRetryDurationsIterable())) .get().iterator(); }
/** * Called after the {@link Assembly} {@link Application}s have been added or removed. * * @param optionsByType the {@link OptionsByType} used for the change */ protected void onChanged(OptionsByType optionsByType) { // ensure the stability of the assembly after it was changed StabilityPredicate<Assembly> stabilityPredicate = optionsByType.getOrDefault(StabilityPredicate.class, null); if (stabilityPredicate != null) { DeferredPredicate deferredPredicate = new DeferredPredicate<>(this, stabilityPredicate.get()); ensure(eventually(deferredPredicate), is(true)); } }
/** * Called after the {@link Assembly} {@link Application}s have been added or removed. * * @param optionsByType the {@link OptionsByType} used for the change */ protected void onChanged(OptionsByType optionsByType) { // ensure the stability of the assembly after it was changed StabilityPredicate<Assembly> stabilityPredicate = optionsByType.getOrDefault(StabilityPredicate.class, null); if (stabilityPredicate != null) { DeferredPredicate deferredPredicate = new DeferredPredicate<>(this, stabilityPredicate.get()); ensure(eventually(deferredPredicate), is(true)); } }
Timeout timeout = optionsByType.getOrDefault(Timeout.class, Timeout.autoDetect()); int timeoutMS = (int) timeout.getDuration().to(TimeUnit.MILLISECONDS);
long initialDelayDurationMS = optionsByType.getOrDefault(InitialDelay.class, InitialDelay.none()).to(TimeUnit.MILLISECONDS); long maximumRetryDurationMS = optionsByType.getOrDefault(Timeout.class, Timeout.after(DeferredHelper.getDefaultEnsuredMaximumRetryDuration())) .to(TimeUnit.MILLISECONDS); long maximumPollingDurationMS = optionsByType.getOrDefault(MaximumRetryDelay.class, MaximumRetryDelay.of(DeferredHelper.getDefaultEnsuredMaximumPollingDuration())) .to(TimeUnit.MILLISECONDS); Iterator<Duration> retryDurations = optionsByType.getOrDefault(RetryFrequency.class, RetryFrequency.of(DeferredHelper.getDefaultEnsuredRetryDurationsIterable())) .get().iterator();
Cell.Width width = cell.getOptions().getOrDefault(Cell.Width.class, row.getOptions().getOrDefault(Cell.Width.class, this.getOptions() .get(Cell Cell.DisplayNull displayNull = cell.getOptions().getOrDefault(Cell.DisplayNull.class, row.getOptions() .getOrDefault(Cell .DisplayNull.class, this.getOptions() Cell.Justification justification = cell.getOptions().getOrDefault(Cell.Justification.class, row.getOptions() .getOrDefault(Cell .Justification.class, this.getOptions() Cell.DisplayNull displayNull = cell.getOptions().getOrDefault(Cell.DisplayNull.class, row.getOptions() .getOrDefault(Cell .DisplayNull.class, this.getOptions()
long initialDelayDurationMS = optionsByType.getOrDefault(InitialDelay.class, InitialDelay.none()).to(TimeUnit.MILLISECONDS); long maximumRetryDurationMS = optionsByType.getOrDefault(Timeout.class, Timeout.after(DeferredHelper.getDefaultEnsuredMaximumRetryDuration())) .to(TimeUnit.MILLISECONDS); long maximumPollingDurationMS = optionsByType.getOrDefault(MaximumRetryDelay.class, MaximumRetryDelay.of(DeferredHelper.getDefaultEnsuredMaximumPollingDuration())) .to(TimeUnit.MILLISECONDS); Iterator<Duration> retryDurations = optionsByType.getOrDefault(RetryFrequency.class, RetryFrequency.of(DeferredHelper.getDefaultEnsuredRetryDurationsIterable())) .get().iterator();
/** * Obtains {@link Infrastructure} represents the {@link LocalPlatform}. * <p> * All calls to {@link #getPlatform(Option...)} will attempt to match against * the {@link LocalPlatform}. * * @return {@link Infrastructure} representing the {@link LocalPlatform} */ static Infrastructure local() { return (options -> { // obtain the PlatformPredicate (just in case one has been provided) OptionsByType optionsByType = OptionsByType.of(options); // assume using the LocalPlatform if there's no predicate PlatformPredicate predicate = optionsByType.getOrDefault(PlatformPredicate.class, PlatformPredicate.isLocal()); // only return the LocalPlatform if the predicate matches return predicate.test(LocalPlatform.get()) ? LocalPlatform.get() : null; }); }
/** * Obtains {@link Infrastructure} represents the {@link LocalPlatform}. * <p> * All calls to {@link #getPlatform(Option...)} will attempt to match against * the {@link LocalPlatform}. * * @return {@link Infrastructure} representing the {@link LocalPlatform} */ static Infrastructure local() { return (options -> { // obtain the PlatformPredicate (just in case one has been provided) OptionsByType optionsByType = OptionsByType.of(options); // assume using the LocalPlatform if there's no predicate PlatformPredicate predicate = optionsByType.getOrDefault(PlatformPredicate.class, PlatformPredicate.isLocal()); // only return the LocalPlatform if the predicate matches return predicate.test(LocalPlatform.get()) ? LocalPlatform.get() : null; }); }
DisplayName displayName = launchOptions.getOrDefault(DisplayName.class, null);
DisplayName displayName = launchOptions.getOrDefault(DisplayName.class, null);
ApplicationClosingBehavior closingBehavior = closingOptions.getOrDefault(ApplicationClosingBehavior.class, defaultClosingBehavior);
ApplicationClosingBehavior closingBehavior = closingOptions.getOrDefault(ApplicationClosingBehavior.class, defaultClosingBehavior);