boardRepository, final ScheduledExecutorService executorService) {
+ this.id = id;
+ this.boardRepository = boardRepository;
+ this.executorService = executorService;
+ }
+
+ /**
+ * Returns this thread-executor's identifier.
+ *
+ * @return This {@link CustomThreadExecutorModel}'s id.
+ * @since 1.0.0
+ */
+ @Override
+ public String id() {
+ return this.id;
+ }
+
+ /**
+ * Schedules and run this thread-executor at a fixed-rate using the given period-rate value.
+ *
+ * @param periodRate the value for this thread-executor's execution period.
+ * @since 1.0.0
+ */
+ public void schedule(final byte periodRate) {
+ this.executorService.scheduleAtFixedRate(this, 0, periodRate, TimeUnit.SECONDS);
+ }
+
+ /**
+ * Shutdowns this thread-executor and provides an status for this operation.
+ *
+ * @return The {@link ThreadShutdownStatusProvider} with the status for the operation.
+ * - {@link ThreadShutdownStatusProvider#withShutdownFailure()} if an exception ocurred during thread's
+ * shutdown-process.
+ *
+ * - {@link ThreadShutdownStatusProvider#withShutdownSuccess()} if the executor was shutdown correctly and
+ * during thread's termination-time {@code (5 seconds)}.
+ *
+ * - {@link ThreadShutdownStatusProvider#withShutdownImmediate()} if the executor couldn't terminate before
+ * given termination-time.
+ * @since 1.0.0
+ */
+ public ThreadShutdownStatusProvider shutdown() {
+ try {
+ this.executorService.shutdown();
+ final var terminatedBeforeTimeout = this.executorService.awaitTermination(5, TimeUnit.SECONDS);
+ if (terminatedBeforeTimeout) {
+ return ThreadShutdownStatusProvider.withShutdownSuccess();
+ }
+ this.executorService.shutdownNow();
+ return ThreadShutdownStatusProvider.withShutdownImmediate();
+ } catch (final InterruptedException exception) {
+ exception.printStackTrace();
+ return ThreadShutdownStatusProvider.withShutdownFailure();
+ }
+ }
+}