From 86fdcffec23c5abcf0381a531696b8dca1297b4f Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Fri, 18 Feb 2022 09:48:31 +0100 Subject: [PATCH] initial commit --- .idea/.gitignore | 3 + .idea/compiler.xml | 17 +++ .idea/google-java-format.xml | 6 + .idea/jarRepositories.xml | 20 +++ ..._com_google_code_findbugs_jsr305_3_0_2.xml | 13 ++ ...rorprone_error_prone_annotations_2_7_1.xml | 13 ++ ...__com_google_guava_failureaccess_1_0_1.xml | 13 ++ ...ven__com_google_guava_guava_31_0_1_jre.xml | 13 ++ ...9_0_empty_to_avoid_conflict_with_guava.xml | 13 ++ ...m_google_j2objc_j2objc_annotations_1_3.xml | 13 ++ ...aven__com_thoughtworks_qdox_qdox_2_0_1.xml | 13 ++ .../Maven__commons_io_commons_io_2_11_0.xml | 13 ++ ...org_apache_commons_commons_lang3_3_8_1.xml | 13 ++ ...n_plugins_maven_compiler_plugin_3_10_0.xml | 13 ++ ...en_shared_maven_shared_incremental_1_1.xml | 13 ++ ..._maven_shared_maven_shared_utils_3_3_4.xml | 13 ++ ...g_checkerframework_checker_qual_3_12_0.xml | 13 ++ ...haus_plexus_plexus_compiler_api_2_10_0.xml | 13 ++ ...us_plexus_plexus_compiler_javac_2_10_0.xml | 13 ++ ..._plexus_plexus_compiler_manager_2_10_0.xml | 13 ++ ...xus_plexus_component_annotations_1_5_5.xml | 13 ++ ..._org_codehaus_plexus_plexus_java_1_1_1.xml | 13 ++ ...org_codehaus_plexus_plexus_utils_1_5_8.xml | 13 ++ .../libraries/Maven__org_ow2_asm_asm_9_2.xml | 13 ++ ...aven__org_projectlombok_lombok_1_18_22.xml | 13 ++ ...ctlombok_lombok_maven_plugin_1_18_20_0.xml | 13 ++ ...sonatype_plexus_plexus_build_api_0_0_7.xml | 13 ++ .idea/misc.xml | 13 ++ .idea/modules.xml | 8 ++ .idea/uiDesigner.xml | 124 ++++++++++++++++++ TicketTest.iml | 36 +++++ pom.xml | 49 +++++++ .../horizoncode/tickettest/TicketTest.java | 33 +++++ .../tickettest/manager/Ticket.java | 56 ++++++++ .../tickettest/manager/TicketCallback.java | 8 ++ .../tickettest/manager/TicketManager.java | 76 +++++++++++ .../horizoncode/tickettest/TicketTest.class | Bin 0 -> 2610 bytes .../tickettest/manager/Ticket$Builder.class | Bin 0 -> 723 bytes .../Ticket$InternalTicketBuilder.class | Bin 0 -> 2070 bytes .../tickettest/manager/Ticket.class | Bin 0 -> 4228 bytes .../tickettest/manager/TicketCallback.class | Bin 0 -> 1049 bytes .../manager/TicketManager$Builder.class | Bin 0 -> 793 bytes ...Manager$InternalTicketManagerBuilder.class | Bin 0 -> 2485 bytes .../tickettest/manager/TicketManager.class | Bin 0 -> 6220 bytes 44 files changed, 748 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/google-java-format.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/libraries/Maven__com_google_code_findbugs_jsr305_3_0_2.xml create mode 100644 .idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_7_1.xml create mode 100644 .idea/libraries/Maven__com_google_guava_failureaccess_1_0_1.xml create mode 100644 .idea/libraries/Maven__com_google_guava_guava_31_0_1_jre.xml create mode 100644 .idea/libraries/Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml create mode 100644 .idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_3.xml create mode 100644 .idea/libraries/Maven__com_thoughtworks_qdox_qdox_2_0_1.xml create mode 100644 .idea/libraries/Maven__commons_io_commons_io_2_11_0.xml create mode 100644 .idea/libraries/Maven__org_apache_commons_commons_lang3_3_8_1.xml create mode 100644 .idea/libraries/Maven__org_apache_maven_plugins_maven_compiler_plugin_3_10_0.xml create mode 100644 .idea/libraries/Maven__org_apache_maven_shared_maven_shared_incremental_1_1.xml create mode 100644 .idea/libraries/Maven__org_apache_maven_shared_maven_shared_utils_3_3_4.xml create mode 100644 .idea/libraries/Maven__org_checkerframework_checker_qual_3_12_0.xml create mode 100644 .idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_api_2_10_0.xml create mode 100644 .idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_javac_2_10_0.xml create mode 100644 .idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_manager_2_10_0.xml create mode 100644 .idea/libraries/Maven__org_codehaus_plexus_plexus_component_annotations_1_5_5.xml create mode 100644 .idea/libraries/Maven__org_codehaus_plexus_plexus_java_1_1_1.xml create mode 100644 .idea/libraries/Maven__org_codehaus_plexus_plexus_utils_1_5_8.xml create mode 100644 .idea/libraries/Maven__org_ow2_asm_asm_9_2.xml create mode 100644 .idea/libraries/Maven__org_projectlombok_lombok_1_18_22.xml create mode 100644 .idea/libraries/Maven__org_projectlombok_lombok_maven_plugin_1_18_20_0.xml create mode 100644 .idea/libraries/Maven__org_sonatype_plexus_plexus_build_api_0_0_7.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 TicketTest.iml create mode 100644 pom.xml create mode 100644 src/net/horizoncode/tickettest/TicketTest.java create mode 100644 src/net/horizoncode/tickettest/manager/Ticket.java create mode 100644 src/net/horizoncode/tickettest/manager/TicketCallback.java create mode 100644 src/net/horizoncode/tickettest/manager/TicketManager.java create mode 100644 target/classes/net/horizoncode/tickettest/TicketTest.class create mode 100644 target/classes/net/horizoncode/tickettest/manager/Ticket$Builder.class create mode 100644 target/classes/net/horizoncode/tickettest/manager/Ticket$InternalTicketBuilder.class create mode 100644 target/classes/net/horizoncode/tickettest/manager/Ticket.class create mode 100644 target/classes/net/horizoncode/tickettest/manager/TicketCallback.class create mode 100644 target/classes/net/horizoncode/tickettest/manager/TicketManager$Builder.class create mode 100644 target/classes/net/horizoncode/tickettest/manager/TicketManager$InternalTicketManagerBuilder.class create mode 100644 target/classes/net/horizoncode/tickettest/manager/TicketManager.class diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..adc72bc --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/google-java-format.xml b/.idea/google-java-format.xml new file mode 100644 index 0000000..8b57f45 --- /dev/null +++ b/.idea/google-java-format.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_code_findbugs_jsr305_3_0_2.xml b/.idea/libraries/Maven__com_google_code_findbugs_jsr305_3_0_2.xml new file mode 100644 index 0000000..1c380d0 --- /dev/null +++ b/.idea/libraries/Maven__com_google_code_findbugs_jsr305_3_0_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_7_1.xml b/.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_7_1.xml new file mode 100644 index 0000000..3df0929 --- /dev/null +++ b/.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_7_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_guava_failureaccess_1_0_1.xml b/.idea/libraries/Maven__com_google_guava_failureaccess_1_0_1.xml new file mode 100644 index 0000000..36e948e --- /dev/null +++ b/.idea/libraries/Maven__com_google_guava_failureaccess_1_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_guava_guava_31_0_1_jre.xml b/.idea/libraries/Maven__com_google_guava_guava_31_0_1_jre.xml new file mode 100644 index 0000000..08b28cc --- /dev/null +++ b/.idea/libraries/Maven__com_google_guava_guava_31_0_1_jre.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml b/.idea/libraries/Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml new file mode 100644 index 0000000..4e15702 --- /dev/null +++ b/.idea/libraries/Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_3.xml b/.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_3.xml new file mode 100644 index 0000000..bacaa45 --- /dev/null +++ b/.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_thoughtworks_qdox_qdox_2_0_1.xml b/.idea/libraries/Maven__com_thoughtworks_qdox_qdox_2_0_1.xml new file mode 100644 index 0000000..d663c32 --- /dev/null +++ b/.idea/libraries/Maven__com_thoughtworks_qdox_qdox_2_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_io_commons_io_2_11_0.xml b/.idea/libraries/Maven__commons_io_commons_io_2_11_0.xml new file mode 100644 index 0000000..f94fc5a --- /dev/null +++ b/.idea/libraries/Maven__commons_io_commons_io_2_11_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_8_1.xml b/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_8_1.xml new file mode 100644 index 0000000..33b78e9 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_8_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_maven_plugins_maven_compiler_plugin_3_10_0.xml b/.idea/libraries/Maven__org_apache_maven_plugins_maven_compiler_plugin_3_10_0.xml new file mode 100644 index 0000000..12317a5 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_maven_plugins_maven_compiler_plugin_3_10_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_maven_shared_maven_shared_incremental_1_1.xml b/.idea/libraries/Maven__org_apache_maven_shared_maven_shared_incremental_1_1.xml new file mode 100644 index 0000000..86cb928 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_maven_shared_maven_shared_incremental_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_maven_shared_maven_shared_utils_3_3_4.xml b/.idea/libraries/Maven__org_apache_maven_shared_maven_shared_utils_3_3_4.xml new file mode 100644 index 0000000..18e1ac7 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_maven_shared_maven_shared_utils_3_3_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_checkerframework_checker_qual_3_12_0.xml b/.idea/libraries/Maven__org_checkerframework_checker_qual_3_12_0.xml new file mode 100644 index 0000000..1b2a35b --- /dev/null +++ b/.idea/libraries/Maven__org_checkerframework_checker_qual_3_12_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_api_2_10_0.xml b/.idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_api_2_10_0.xml new file mode 100644 index 0000000..f5f6716 --- /dev/null +++ b/.idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_api_2_10_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_javac_2_10_0.xml b/.idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_javac_2_10_0.xml new file mode 100644 index 0000000..cbfb463 --- /dev/null +++ b/.idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_javac_2_10_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_manager_2_10_0.xml b/.idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_manager_2_10_0.xml new file mode 100644 index 0000000..df1a190 --- /dev/null +++ b/.idea/libraries/Maven__org_codehaus_plexus_plexus_compiler_manager_2_10_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_codehaus_plexus_plexus_component_annotations_1_5_5.xml b/.idea/libraries/Maven__org_codehaus_plexus_plexus_component_annotations_1_5_5.xml new file mode 100644 index 0000000..9292317 --- /dev/null +++ b/.idea/libraries/Maven__org_codehaus_plexus_plexus_component_annotations_1_5_5.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_codehaus_plexus_plexus_java_1_1_1.xml b/.idea/libraries/Maven__org_codehaus_plexus_plexus_java_1_1_1.xml new file mode 100644 index 0000000..808e3f3 --- /dev/null +++ b/.idea/libraries/Maven__org_codehaus_plexus_plexus_java_1_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_codehaus_plexus_plexus_utils_1_5_8.xml b/.idea/libraries/Maven__org_codehaus_plexus_plexus_utils_1_5_8.xml new file mode 100644 index 0000000..d337042 --- /dev/null +++ b/.idea/libraries/Maven__org_codehaus_plexus_plexus_utils_1_5_8.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_ow2_asm_asm_9_2.xml b/.idea/libraries/Maven__org_ow2_asm_asm_9_2.xml new file mode 100644 index 0000000..3f9b2da --- /dev/null +++ b/.idea/libraries/Maven__org_ow2_asm_asm_9_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_projectlombok_lombok_1_18_22.xml b/.idea/libraries/Maven__org_projectlombok_lombok_1_18_22.xml new file mode 100644 index 0000000..72b596e --- /dev/null +++ b/.idea/libraries/Maven__org_projectlombok_lombok_1_18_22.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_projectlombok_lombok_maven_plugin_1_18_20_0.xml b/.idea/libraries/Maven__org_projectlombok_lombok_maven_plugin_1_18_20_0.xml new file mode 100644 index 0000000..c7c939a --- /dev/null +++ b/.idea/libraries/Maven__org_projectlombok_lombok_maven_plugin_1_18_20_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_sonatype_plexus_plexus_build_api_0_0_7.xml b/.idea/libraries/Maven__org_sonatype_plexus_plexus_build_api_0_0_7.xml new file mode 100644 index 0000000..9302938 --- /dev/null +++ b/.idea/libraries/Maven__org_sonatype_plexus_plexus_build_api_0_0_7.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1bfe194 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..07fb49c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TicketTest.iml b/TicketTest.iml new file mode 100644 index 0000000..d1109fe --- /dev/null +++ b/TicketTest.iml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..768ac5d --- /dev/null +++ b/pom.xml @@ -0,0 +1,49 @@ + + 4.0.0 + + net.horizoncode.tickettest + tickettest + 1.0.0 + jar + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.0 + + 1.8 + 1.8 + + + + + + + org.projectlombok + lombok + 1.18.22 + + + org.projectlombok + lombok-maven-plugin + 1.18.20.0 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.0 + + + commons-io + commons-io + 2.11.0 + + + com.google.guava + guava + 31.0.1-jre + + + \ No newline at end of file diff --git a/src/net/horizoncode/tickettest/TicketTest.java b/src/net/horizoncode/tickettest/TicketTest.java new file mode 100644 index 0000000..7016ec0 --- /dev/null +++ b/src/net/horizoncode/tickettest/TicketTest.java @@ -0,0 +1,33 @@ +package net.horizoncode.tickettest; + +import lombok.Getter; +import net.horizoncode.tickettest.manager.Ticket; +import net.horizoncode.tickettest.manager.TicketCallback; +import net.horizoncode.tickettest.manager.TicketManager; + +import java.util.stream.IntStream; + +public class TicketTest { + + @Getter private final TicketManager ticketManager; + + public static void main(String[] args) { + new TicketTest(); + } + + public TicketTest() { + this.ticketManager = TicketManager.builder().ticketLifespan(5000).maxTicketsExisting(2).build(); + + IntStream.range(0, 10) + .forEach( + (value) -> + getTicketManager() + .addTicket( + () -> { + System.out.println("i expired oof"); + }) + .use()); + + while (true) {} + } +} diff --git a/src/net/horizoncode/tickettest/manager/Ticket.java b/src/net/horizoncode/tickettest/manager/Ticket.java new file mode 100644 index 0000000..2aad54c --- /dev/null +++ b/src/net/horizoncode/tickettest/manager/Ticket.java @@ -0,0 +1,56 @@ +package net.horizoncode.tickettest.manager; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; + +@Builder( + toBuilder = true, + builderClassName = "InternalTicketBuilder", + builderMethodName = "internalBuilder") +public class Ticket extends CompletableFuture { + @Getter private UUID ticketID; + @Getter private Long timeTicketCreated; + private TicketManager ticketManager; + @Getter @Setter private Runnable onExpire; + + void init() { + ticketID = UUID.randomUUID(); + } + + public void use() { + ticketManager.getTicketSet().add(this); + ticketManager + .getService() + .submit( + () -> { + TimeUnit.MILLISECONDS.sleep(ticketManager.getTicketLifespan()); + System.out.println("ticket with UUID: " + getTicketID() + " expired."); + ticketManager.getTicketSet().remove(this); + getOnExpire().run(); + return null; + }); + } + + public static Ticket.Builder builder() { + return new Ticket.Builder(); + } + + public static class Builder extends InternalTicketBuilder { + + Builder() { + super(); + } + + @Override + public Ticket build() { + Ticket ticket = super.build(); + ticket.init(); + return ticket; + } + } +} diff --git a/src/net/horizoncode/tickettest/manager/TicketCallback.java b/src/net/horizoncode/tickettest/manager/TicketCallback.java new file mode 100644 index 0000000..9e71596 --- /dev/null +++ b/src/net/horizoncode/tickettest/manager/TicketCallback.java @@ -0,0 +1,8 @@ +package net.horizoncode.tickettest.manager; + +public class TicketCallback{ + public Ticket call(Ticket ticket) { + System.out.println("Ticket " + ticket.getTicketID() + " expired."); + return ticket; + } +} diff --git a/src/net/horizoncode/tickettest/manager/TicketManager.java b/src/net/horizoncode/tickettest/manager/TicketManager.java new file mode 100644 index 0000000..09606e9 --- /dev/null +++ b/src/net/horizoncode/tickettest/manager/TicketManager.java @@ -0,0 +1,76 @@ +package net.horizoncode.tickettest.manager; + +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; +import lombok.Builder; +import lombok.Getter; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +@Builder( + toBuilder = true, + builderClassName = "InternalTicketManagerBuilder", + builderMethodName = "internalBuilder") +@Getter +public class TicketManager { + + private ListeningExecutorService service; + private Set ticketSet; + private int maxTicketsExisting; + private long ticketLifespan; + + public Ticket addTicket(Runnable onExpire) { + ListenableFuture asyncTask = + service.submit( + () -> { + if (waitForFreeTicket()) + System.out.println("max amount of tickets reached, waiting..."); + + while (waitForFreeTicket()) { + TimeUnit.MILLISECONDS.sleep(1); + } + Ticket t = + Ticket.builder().timeTicketCreated(ticketLifespan).onExpire(onExpire).ticketManager(this).build(); + System.out.println("Got ticket with UUID: " + t.getTicketID()); + return t; + }); + try { + return asyncTask.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + return null; + } + } + + private boolean waitForFreeTicket() { + return ticketSet.size() >= maxTicketsExisting; + } + + void init() { + service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10)); + ticketSet = new HashSet<>(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends InternalTicketManagerBuilder { + + Builder() { + super(); + } + + @Override + public TicketManager build() { + TicketManager ticketManager = super.build(); + ticketManager.init(); + return ticketManager; + } + } +} diff --git a/target/classes/net/horizoncode/tickettest/TicketTest.class b/target/classes/net/horizoncode/tickettest/TicketTest.class new file mode 100644 index 0000000000000000000000000000000000000000..b4e1de4f4334af3a4389c83f8cd885ff22ed3915 GIT binary patch literal 2610 zcmbVO?N%FA6x}x=Ofw8kgn~-3#x_Vm>_CgQ8muiyZE9$dAhp)7o5>{%OlIPIP^d59 zoA}qdG_AOn58(2d)N^O1&9F*iF>B4-uXFd=XWw(r&ZQ3hQ1azZHCd( zz3MjK<+{b~re5=1({7fhHfVi`fEaRB(-yaaR$aL3yl&CVP}MQGwZUCej^oKb?lwJ! z;UmBp`WH;w^sg|aOChqqWs>b=FV+#;bqau}4%U2b?5yy1>@43D{-JOf=1Wt(;GQRf zX7N_N!Hc%IU!0?uOBG2lv&*f3B4rhZq{S?QT5|%|5Z6tqM6S#7yws3kqQ^mWjWxWE zf`Y1s6|5@wRKpt96?~>)19vohjtLE;cv-<+4PW3MLw?b5e9w1zdqwzLPQ%Of z>}5FVhqs_=ZVIo>DdzEt?F-lD)}efQN_?$!^Z0pH?1f4ESB}lU7a(287T=5Ld&_&K z=hF>lSff-v_Ko;2=9%zp8OFj)34GJiDJunU>BNv~2leRoxKv5#b`(k#qVRmnvI+-n zS@FK362T2av?=2%rCzMNcc`3%-VAKRHyvBjSaNJHXbG2uRyG}XnHyUS=Sm48M_Ny9 zNG6oEX*USVVvHY_#kIh;Ww9g7EN?U-77W*7)WbH%ke%?RUN{+uTHukciECQh_k2N; zr=5VL8;N2x9etImczhn@VmLg5!_y>ATN+su>qs(;r(XaCo(3QHHN1&Q4bvzvob6T! z)82J&u~j7FD`q8^a_9qjHSr0zVVK?%%Y+8=-H_ zD5eO#>vM*}I7>F?=ph#W&@xj(k4%1xkq}Ul{PL>I>==C_v>}y$ z#?a7k2d5+~OQ?LBR30Zi-lF*wW^kL@F&fX&pS4@$@*=f0Y6I+Hmk7KUJAR*R%2=RB K_O9X@uKo+gtHQAW literal 0 HcmV?d00001 diff --git a/target/classes/net/horizoncode/tickettest/manager/Ticket$Builder.class b/target/classes/net/horizoncode/tickettest/manager/Ticket$Builder.class new file mode 100644 index 0000000000000000000000000000000000000000..159d4b4ffbd0170bb0082e3e1e8ebb30cb73b41d GIT binary patch literal 723 zcmb7?&rZTX5XQfSmP)CBDEQyR!~;mAG2ls~i6k15#*2je0vlN^+oUZXd@8+Y;=u>- zp^URF@n!-|I*B}`TqI*0?@&M4HH#uYBn~pWntUG4nyujDj8ogWb2IqgV7Df zf}!L|CGKX^p$PkY=u@WR1tabccqnx|Pa5$=Mhw>VO!{LHGB`b@MA-Ft6bagBdrHLa zBnah8phiS?V>x;faV(qe4wi!w$`UAiHLtHm`v6^l@DKRw0YZ>|25Z!Aovo7MM> zLl`sy`pM8s{efYHR&DZ(ym|Zq_Lgkt$=XR-i$pH10Vgd&0Y!>vPEaPR0k`BevOs{0 z*L+8|`AT618dF4;Y@5E^q4+F8)zb1g%A~Wbp^`w>6Ws<@$ycb#pm}vjXOiDV{ukYQ Bu|@y@ literal 0 HcmV?d00001 diff --git a/target/classes/net/horizoncode/tickettest/manager/Ticket$InternalTicketBuilder.class b/target/classes/net/horizoncode/tickettest/manager/Ticket$InternalTicketBuilder.class new file mode 100644 index 0000000000000000000000000000000000000000..991f2c36623455913328df50c24df8b68b58a649 GIT binary patch literal 2070 zcmb_cYflqV5IwigrCkKdtKth4u`Q2P#AkUIOqx_p-6q7=M)}2#F;A z0DqKmW_Kx-R#TFG*gLZ~=bo86bLRf~{o^Nqd2GZm2%`rHJmTdsFLS&+iDEv62%bjq zECvmRhUaWw@bXf_D-Br<3mO)AV=0Q|C{_eC$0~i4PJUgWzi?oFGL5=pRgCTJ{CZYk zz_AYHmW#;Q(sblr16DCr*(g+1nP9yh$s1FdWoZk{6_j+0{iz^SKt*SOYA6d2(81gc4L%gpmWfm)v5RnB-SnQo2knMO?Q#?qW;}rt*1Iq?Yw2(i2K2>(ci7^26MQ`treI_U4e~d=u|fy+frqc zAsux`!p+XxB}8nqTDME`wZ&SCdpeqBoQ|8grDF)gIz}+6BZ=!e#&AO*-SI#$$*REU z<-iT4PWlns$}Z*jvuBzG z>Sdn&Hy(HCB_5=QI)ni0fV==p!L_6Y*ODN}M(HEDK;Slc23bKioH>Q~Mos{CXpOj= zag39%djJYCL4VX#JfM{iX9*o38_i68MhP+@i{+^I)ce|M8S@U_<~H7 z#KU$(p^k~TLQFJnU39V19zh`#VCqV0?3)jZj# zISqr)cR=OjhOL}I+dV~3B6fl}^PWIY^m=}f{cD~dV!zMx!|eBye}aMk#a;2^1~B8c RbQbr?#wc!rZgUSke*mfn|Iz>e literal 0 HcmV?d00001 diff --git a/target/classes/net/horizoncode/tickettest/manager/Ticket.class b/target/classes/net/horizoncode/tickettest/manager/Ticket.class new file mode 100644 index 0000000000000000000000000000000000000000..12f86f1b2fb5230a3b75a3e0310ba689be71bcad GIT binary patch literal 4228 zcmb_g_jl7)6#kT@#8#Gp00Bw}fhJ}cQs^Lz7AJtINhnUBj1I+qI09L6WjTyay7%6L z?!AB#Q{bHb0X_YjdU~%U+e+ec42K``-jj6ich~psd(PkgUik~a23!naFYaqX5BBkp z2w)UrLF~r?Ufmxep$CF^5D&?CIDjUo0jz+^qT@UyWuyXV;nyt?JRIdA&BH_!G#q1? z;{jUfO~}BIVFs`OY9q2dKN27ii&wcu*gWS0n8XS8;3R)L6~t*gD&sL3k4u;rGi+fQ zsy?bEj|+QyUei;;lAy#4Ls(H=&E-T+f?WF0Xgh+jK?!Z~W9pO;->h*iP6cbLvW_En51g&>w zihY4PxvU<)m^dFoDOH@GR?TBVsnpTya=#*xD3~VOEFlKd!gkBZ{0R~MEC$VWL}rnw zB2xX1fTF9J@s!#_RqRvS+D`O|j zypk&Gu5JcWA{^dYQZ4c5vyqu^;gBjZ^G&*6CmFW^PmYy@ZLY)j4V z5%z?c%C$D&r8dM`WxTB56}&3rH3hHZ4GHV3-g8B2Di}b&f>l_pAOcF!w(21&(u2c! zlL6o2nBHd8cVxV);61#r-~)W9;3Ir2;}Zp+;xh^J9lAJ`OW2lXq)W^SxecT1gl124 zaWmS~rQj?+S8z9H?JT~aN_7dRU!>M5_!3{q_*%g?_*TJpoW4N}$@pHu59pWBS9M?# zR+c$@t(r@iQ}({ZAqg#Ib@rP`V5vsR%(xHhs&=H*OqJ3mO9<+I?L`_peVSeo&zj3N z9hq7+MU8r%e`k1n?>j^e5nw`ClUkBkxs~9OW+sw0&9p8ew9J@>dj|NTk83$w7*wF4 zlOmb7P0Q0C2;fKj#K+Lj)RC#}>Js9;)i<#Lf5-6IixLuVFN$r`jeAF(H2@ z@4S@^RiB0OwkPireq86!yq+VX;wJK;mYd_vK+RuAVTz~A&9HmG&%^Q=RXt03{x45U z%Dng0bd>HaW6n)M*%OP$V~L^Y$nao7!qUp^yeLnJZ!hh&xOPZ@eYKD*-)NEE5v@6&6v*C8V;x3ro z2uX38d~p~1&YNkCljIw1(|tAb#Pe(w`_^<1>6(*ee{~9YTHh#oNHI59B4bWc&j^)+ zFP4+SxAJs%{YAmAIHzD2ViLN`a+)z|9v6|gb0X7GrXE$3)J9Ixv6v}8$+$pf;-+~# zPpSULpD7Q(Jq34BN7Y5H$CVtIl@0%!X^Nw#vf{=*x+br!>oqf{jGkF;WC_g{12X=Q zuwqt1D#at=mTSvl88zG$^uwbLHGF}fRSlow&P;a+XQl(4<{7<`Lix9$M8kbNED}0u^Jxfiv3!6M|yBwd$+pB0gcnN`XjwkGG zgX3K2!lh#Svu@b(7V0aZp7hXLDCA?+|wc&+zQ)n*xQ;Z{T6nBHfoL>&Ik3z+LBa$W%) z7cl=S7EoaphB^ya6fR(K0ZT%+(7J%71$4QhOyp%uudOJkhYHQ0k;XCA?=GC9;Yr3*M)B7<@1gL6>38$uiC;qKiN6FeZ`; zYZoTWFx3+(yOg~h`l*}|Zmgv59vtlL5ZqY%OwE7WmsFTBVwn4fca}QM@EpN3oPn0_ z2XrIn32xK7vFTOmF9)VaPU{SLE?GvlxOxKiEj_+MtC0rtsLNbS`vg{ksrpw+%Rxh1X-Sb787cgH1~GysFf8C2 LHDI`&*4+3DSiuq0 literal 0 HcmV?d00001 diff --git a/target/classes/net/horizoncode/tickettest/manager/TicketManager$Builder.class b/target/classes/net/horizoncode/tickettest/manager/TicketManager$Builder.class new file mode 100644 index 0000000000000000000000000000000000000000..78f4ea8f62e81c21906ba81dad88f0134dc692ed GIT binary patch literal 793 zcmbV~OHaZ;5Xb)uEtOIPQSpT)CLTZ%Ym|dg;{g(t1iVPNFJ&XEWt)`Z!B3?ZO+5Gk z{7}Z}BPLu-V3W@5ynZ{oo$sH|F8~efnb5Hwin56fY#P`yu+5OUlu8Cy4C!jE&!Dxu zpUa)!``nkIojA2%Bqt0;b1L1T@ENSOQo?V!d@>OfIPWMC z*dx!EFP?IUYzNYL5BS5NCe@D9hN@fZnW*O-yMaM1K?Fdzl(-V|Vy{w=VK~|%>HRMT`C`+TMx2R4h Hy@Tv8y@ky_ literal 0 HcmV?d00001 diff --git a/target/classes/net/horizoncode/tickettest/manager/TicketManager$InternalTicketManagerBuilder.class b/target/classes/net/horizoncode/tickettest/manager/TicketManager$InternalTicketManagerBuilder.class new file mode 100644 index 0000000000000000000000000000000000000000..308c10cf00665218414b3a42bc59b3e6b72fc5fa GIT binary patch literal 2485 zcmcImZBr9T5Pl{J*^t{4%>kn16g^);L|4zZy9*!(qJ|4%T`a5o<`T!an9Nd}jfMUP z|BF{8q3W#i2l%6|d}e2Xi_sJo_+h(yW_q4}neI+L{`c<(0N1dR#R#qsVi-3xxv9x- zn*46zk1WzCS(wfugXG3sL)O}%A5_illE7f-)n3T3Dno&x z%9{JqHMhB;Ppe*CxnVnq40WAOSCkB$=YHV5rXl~SbPQ4`TcOi*m0OpA^DqK0%@Qit zbT`bhwYWil=#79V3mh`{D&8~MT6YyUmju$&p7O$3fn;Iwkw9vJ2DF2olK0!qRT(^V zR~y{PRs5RUc;p72UdNlM@VVC#$d^?p1LZc1*=6I?eA{b0m4Sd=R!Rm74Y$>j)Lz+p zJTcOle)x>|O<_MzGkM_tJSlwkz6Wn&wEH<;t#3aGbFq)=Ie16^E|k9q=+eQ14y@{e z6}VRTc5D`5CiJUe5H;H{5u!(ExT@}$U20^jemkhiJ6_aJUA=NitJ|2sDI23WYGVw? zY~=B?jT1O2aCy%oAZ{6r#g;$%xf?r8d9~YqzYZ(JBXGvX68_Sp!ls^@Fyn;tYeryX zYNB`SL>HC?j%@30kDln@J_pdGjVt(7VEJ3)>pKzz4)4ajvbrW~oVgG7H6*&5s#IRm z!!qrzuS>;}xfnOy|KGc}1mfJY61wz_gQb4@dEG?2A(@KWh07P%4qrRQDgF$O@K-X0 zgsv@030+1cBZXDHi70cTO* zO3=(CslHsIc7oh0Uf4vU_?BYt^--e|U)T1vpW5meiagUm%j7#i$p|Rf<3}%$3G@O1 zjE@!}#|dmgpQ4nBq%)OyD~t`K9;`Y{B|6vWawT=QY@2G2R;8(s*<4k$Jp@!Cbb3A2e^ymvc86Ir=P>vQwc3qB literal 0 HcmV?d00001 diff --git a/target/classes/net/horizoncode/tickettest/manager/TicketManager.class b/target/classes/net/horizoncode/tickettest/manager/TicketManager.class new file mode 100644 index 0000000000000000000000000000000000000000..447e28634128392b6bdc9145b2e26c1ee6ab27b5 GIT binary patch literal 6220 zcmb_g`F|6~75|P8)|MB1U<^1M3UR;~+ad{R2zCg;*ug{wV%gB7SJu*EFP3)I)d~!4 z($XX8mELKZ-swftCM}^L4!3D~w`qFc_uc;9KcMM%c30BMHdG?mpU=+h%)IOS-n{o# z&;9q}GXS>W-}UIh;TF!*4R|%|285Z;IPhwunK5W=JQpnN)dN$B)X>ACt3>%f}}a zJg(rA0;`5iN4HHaIcCJCb!S8~wMpIHnKhCL-4;-XO;fiAl3FICX9SeOhLX|kBSu^o z=#R#&RAkb!CX;%E)0AaKvW}7D+>B>!TQ{9Z)W|rxX_%9PGkQGhSa!^#?h~kYT){Ej z5onAa){bZ%H5cS=%$PJaCu_TcN_P9BrtU6x@y!_@a?Qxm#9Cb>|ps1?_e2Q=G|@BX6T#AY3i74WOn z%Zp=<7M~u`(k_w;KBeH(3O*yyd{i@>AduY#5>Uf57<_y=zzCnnhkk!& z1s?Vx?(pviQCQS3*=`ru-&wZV3tW&nH)42?RPz3-$g(nkJ^77>pEL^T;O;8{>vE}w z2-Z7Rfq!UHcl?|ou${tQRL)V!&5Hpy?KG2LNot{RDWhbqGMspQDPv@TjKeTv&S@@a zP)s}AVd7~?YN?5Y)=|hm9h;ev7@wQUzwp#QR7e@j6``1wwd4Ab;U*lVQeb1*Iapwg zi>I4JUC-Ouw4)~qdJ1eP0v@OxUddqYE1Xnu3Zp9P@y!aJR&g3MU@LA_@MRTea8^N1 z#W|cO%0-5|wagTqtzsOb0$a;gd(OpHu?<9bq+!9V@J$up!naj? z2j5i@!}kv`Dv|FPnZ{a7{pgS}qbJ6u82E|(mPN2Pb`D40pe6H>}8hFYXztDWd14pweZw zo9^XE@}px}@FT;^y?wIRTV1>?fgCVqr1WvOZB<8xqtW5m;K07UyJ7-s16|7k=c!0- zCaLRbCM&{1{x?^W;{yHdl444YTJlp$Iie-A`o2RnRRUhRO}RIe?bo~%7I24ldi}}( zab&wdpi0BEP@rN#0HsQm#AnBXOsVzlLc; zxFklk6Y`sh1w~7zb(52xpvn1I4n#yrYeA433f=JVF6P{PMRrSpY%_SIgr#4lgF!Zz zWu0SrOLHr{ua1I0tN084t|Eck1lAS9)i94((|RQ8w&84qwL@B*Y5y42Ocmc0{F4Sp zEo(Z6NAspj(^ObFSA}>!Hgw7W$t9{IH^gadu z61aXIAPd=(FWPSJRHD9bH?CzT)yp5uYEUIVGB~S}jXMNh;?8g3J9~F`&eocv%DsNv z#^-jv&7zvLz`Cw85M7%t@;EM_x(XxR7f>VcENV~f?a84|oZ?n9+HnmQ`J+P0+ezEb z6<`$_u$nuYc%qwcJqS~?9o*^Sxm7%K2X;~#WnlojILg@|hNww1|L??ZN*Ly<)X-bm z!-#QTQa#W%sDZ8W6*0zv|uG&~Na<|JyWpX5%p ztL!58)J?8pQV=P8b)=wLRJHDqi+5v`n-ZZtB$O*Fx|%}gp`OR$vqWkZOYS*`#m{yrw^0ABSWe7$aK{s|!WU7`?}Ra*Z*Lrl3-`1PxSZ#% z9F|LG<%sbaEX`r1-K>P~4(uX!k zTtAn1`2xfq7O$ej`=BkLL4%C8p!zEoU?MPqc!Ai9U8(-kr{)l^oKM_TC9|rp{yE|* zeRq(N(f$}3PUD)ERXMEoUKgLnnotgFPrmS<^9W1+=W%Tg>o(VbYxm-s5Uaab5)jn>ltdWLud&A`G@BjyG_8gllqql;e*${uTeg S->?$XJTJo{NggSfu>J>d#t#z! literal 0 HcmV?d00001