test_class.declarator: scheduler = new SchedulerImpl()
test_class.modifier: private
test_class.original_string: private SchedulerImpl scheduler = new SchedulerImpl();
test_class.type: SchedulerImpl
test_class.var_name: scheduler
test_class.file: bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java
test_class.identifier: SchedulerImplTest
test_case.body: @Test
      @Timeout(value = 300, unit = TimeUnit.MILLISECONDS)
      public void testAfterTimeoutException() throws Throwable {
          CompletableFuture<Integer> d = new CompletableFuture<>();
          ScheduledCompletableFuture<Integer> before = scheduler.before(d, Duration.ofMillis(100));
          Thread.sleep(200);
          d.complete(3);
          d.get();
          assertTrue(before.isDone(), "Scheduled job should be done");
          assertTrue(before.getPromise().isCompletedExceptionally(),
                  "Before CompletableFuture should have completed with an exception");
          assertThrows(TimeoutException.class, () -> {
              try {
                  before.get();
              } catch (ExecutionException e) {
                  throw e.getCause();
              }
          });
      }
test_case.class_method_signature: SchedulerImplTest.testAfterTimeoutException()
test_case.full_signature: @Test @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) public void testAfterTimeoutException()
test_case.identifier: testAfterTimeoutException
test_case.invocations: before ofMillis sleep complete get assertTrue isDone assertTrue isCompletedExceptionally getPromise assertThrows get getCause
test_case.modifiers: @Test @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testAfterTimeoutException()
focal_class.declarator: SCHEDULER_THREAD_POOL = "scheduler"
focal_class.modifier: private static final
focal_class.original_string: private static final String SCHEDULER_THREAD_POOL = "scheduler";
focal_class.type: String
focal_class.var_name: SCHEDULER_THREAD_POOL
focal_class.declarator: logger = LoggerFactory.getLogger(SchedulerImpl.class)
focal_class.modifier: private final
focal_class.original_string: private final Logger logger = LoggerFactory.getLogger(SchedulerImpl.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: clock = Clock.systemDefaultZone()
focal_class.modifier: private final
focal_class.original_string: private final Clock clock = Clock.systemDefaultZone();
focal_class.type: Clock
focal_class.var_name: clock
focal_class.declarator: executor = ThreadPoolManager.getScheduledPool(SCHEDULER_THREAD_POOL)
focal_class.modifier: private final
focal_class.original_string: private final ScheduledExecutorService executor = ThreadPoolManager.getScheduledPool(SCHEDULER_THREAD_POOL);
focal_class.type: ScheduledExecutorService
focal_class.var_name: executor
focal_class.file: bundles/org.openhab.core/src/main/java/org/openhab/core/internal/scheduler/SchedulerImpl.java
focal_class.identifier: SchedulerImpl
focal_class.interfaces: implements Scheduler
focal_class.class_method_signature: SchedulerImpl.after(Duration duration)
focal_class.full_signature: @Override public ScheduledCompletableFuture<Instant> after(Duration duration)
focal_class.identifier: after
focal_class.modifiers: @Override public
focal_class.parameters: (Duration duration)
focal_class.return: ScheduledCompletableFuture<Instant>
focal_class.signature: ScheduledCompletableFuture<Instant> after(Duration duration)
focal_class.class_method_signature: SchedulerImpl.after(Callable<T> callable, Duration duration)
focal_class.full_signature: @Override public ScheduledCompletableFuture<T> after(Callable<T> callable, Duration duration)
focal_class.identifier: after
focal_class.modifiers: @Override public
focal_class.parameters: (Callable<T> callable, Duration duration)
focal_class.return: ScheduledCompletableFuture<T>
focal_class.signature: ScheduledCompletableFuture<T> after(Callable<T> callable, Duration duration)
focal_class.class_method_signature: SchedulerImpl.afterInternal(ScheduledCompletableFutureOnce<T> deferred,
              Callable<T> callable, Duration duration)
focal_class.full_signature: private ScheduledCompletableFutureOnce<T> afterInternal(ScheduledCompletableFutureOnce<T> deferred,
              Callable<T> callable, Duration duration)
focal_class.identifier: afterInternal
focal_class.modifiers: private
focal_class.parameters: (ScheduledCompletableFutureOnce<T> deferred,
              Callable<T> callable, Duration duration)
focal_class.return: ScheduledCompletableFutureOnce<T>
focal_class.signature: ScheduledCompletableFutureOnce<T> afterInternal(ScheduledCompletableFutureOnce<T> deferred,
              Callable<T> callable, Duration duration)
focal_class.class_method_signature: SchedulerImpl.before(CompletableFuture<T> promise, Duration timeout)
focal_class.full_signature: @Override public ScheduledCompletableFuture<T> before(CompletableFuture<T> promise, Duration timeout)
focal_class.identifier: before
focal_class.modifiers: @Override public
focal_class.parameters: (CompletableFuture<T> promise, Duration timeout)
focal_class.return: ScheduledCompletableFuture<T>
focal_class.signature: ScheduledCompletableFuture<T> before(CompletableFuture<T> promise, Duration timeout)
focal_class.class_method_signature: SchedulerImpl.at(Instant instant)
focal_class.full_signature: @Override public ScheduledCompletableFuture<Instant> at(Instant instant)
focal_class.identifier: at
focal_class.modifiers: @Override public
focal_class.parameters: (Instant instant)
focal_class.return: ScheduledCompletableFuture<Instant>
focal_class.signature: ScheduledCompletableFuture<Instant> at(Instant instant)
focal_class.class_method_signature: SchedulerImpl.at(Callable<T> callable, Instant instant)
focal_class.full_signature: @Override public ScheduledCompletableFuture<T> at(Callable<T> callable, Instant instant)
focal_class.identifier: at
focal_class.modifiers: @Override public
focal_class.parameters: (Callable<T> callable, Instant instant)
focal_class.return: ScheduledCompletableFuture<T>
focal_class.signature: ScheduledCompletableFuture<T> at(Callable<T> callable, Instant instant)
focal_class.class_method_signature: SchedulerImpl.atInternal(ScheduledCompletableFutureOnce<T> deferred,
              Callable<T> callable, Instant instant)
focal_class.full_signature: private ScheduledCompletableFuture<T> atInternal(ScheduledCompletableFutureOnce<T> deferred,
              Callable<T> callable, Instant instant)
focal_class.identifier: atInternal
focal_class.modifiers: private
focal_class.parameters: (ScheduledCompletableFutureOnce<T> deferred,
              Callable<T> callable, Instant instant)
focal_class.return: ScheduledCompletableFuture<T>
focal_class.signature: ScheduledCompletableFuture<T> atInternal(ScheduledCompletableFutureOnce<T> deferred,
              Callable<T> callable, Instant instant)
focal_class.class_method_signature: SchedulerImpl.schedule(SchedulerRunnable runnable, TemporalAdjuster temporalAdjuster)
focal_class.full_signature: @Override public ScheduledCompletableFuture<T> schedule(SchedulerRunnable runnable, TemporalAdjuster temporalAdjuster)
focal_class.identifier: schedule
focal_class.modifiers: @Override public
focal_class.parameters: (SchedulerRunnable runnable, TemporalAdjuster temporalAdjuster)
focal_class.return: ScheduledCompletableFuture<T>
focal_class.signature: ScheduledCompletableFuture<T> schedule(SchedulerRunnable runnable, TemporalAdjuster temporalAdjuster)
focal_class.class_method_signature: SchedulerImpl.schedule(ScheduledCompletableFutureRecurring<T> schedule, SchedulerRunnable runnable,
              TemporalAdjuster temporalAdjuster)
focal_class.full_signature: private void schedule(ScheduledCompletableFutureRecurring<T> schedule, SchedulerRunnable runnable,
              TemporalAdjuster temporalAdjuster)
focal_class.identifier: schedule
focal_class.modifiers: private
focal_class.parameters: (ScheduledCompletableFutureRecurring<T> schedule, SchedulerRunnable runnable,
              TemporalAdjuster temporalAdjuster)
focal_class.return: void
focal_class.signature: void schedule(ScheduledCompletableFutureRecurring<T> schedule, SchedulerRunnable runnable,
              TemporalAdjuster temporalAdjuster)
focal_method.body: @Override
      public <T> ScheduledCompletableFuture<T> before(CompletableFuture<T> promise, Duration timeout) {
          final AtomicBoolean done = new AtomicBoolean();
          final Consumer<Runnable> runOnce = runnable -> {
              if (!done.getAndSet(true)) {
                  runnable.run();
              }
          };
          final ScheduledCompletableFutureOnce<T> wrappedPromise = new ScheduledCompletableFutureOnce<>();
          Callable<T> callable = () -> {
              wrappedPromise.completeExceptionally(new TimeoutException());
              return null;
          };
          final ScheduledCompletableFutureOnce<T> afterPromise = afterInternal(wrappedPromise, callable, timeout);
          wrappedPromise.exceptionally(e -> {
              if (e instanceof CancellationException) {
                  // Also cancel the scheduled timer if returned completable future is cancelled.
                  afterPromise.cancel(true);
              }
              return null;
          });
  
          promise.thenAccept(p -> runOnce.accept(() -> wrappedPromise.complete(p))) //
                  .exceptionally(ex -> {
                      runOnce.accept(() -> wrappedPromise.completeExceptionally(ex));
                      return null;
                  });
          return wrappedPromise;
      }
focal_method.class_method_signature: SchedulerImpl.before(CompletableFuture<T> promise, Duration timeout)
focal_method.full_signature: @Override public ScheduledCompletableFuture<T> before(CompletableFuture<T> promise, Duration timeout)
focal_method.identifier: before
focal_method.invocations: getAndSet run completeExceptionally afterInternal exceptionally cancel exceptionally thenAccept accept complete accept completeExceptionally
focal_method.modifiers: @Override public
focal_method.parameters: (CompletableFuture<T> promise, Duration timeout)
focal_method.return: ScheduledCompletableFuture<T>
focal_method.signature: ScheduledCompletableFuture<T> before(CompletableFuture<T> promise, Duration timeout)