From 73979675a7541b3636ace3eb405fce38dda151f1 Mon Sep 17 00:00:00 2001 From: GedMarc Date: Sat, 29 Jun 2024 13:57:36 +0200 Subject: [PATCH] Updates for Cerials, Websockets, and Queues --- .../guicedinjection/GuiceContext.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/guicedee/guicedinjection/GuiceContext.java b/src/main/java/com/guicedee/guicedinjection/GuiceContext.java index 02d1216..6dace63 100644 --- a/src/main/java/com/guicedee/guicedinjection/GuiceContext.java +++ b/src/main/java/com/guicedee/guicedinjection/GuiceContext.java @@ -91,8 +91,6 @@ private GuiceContext() //No config required } - - /** * Reference the Injector Directly * @@ -142,19 +140,16 @@ public Injector inject() log.config("Modules - " + Arrays.toString(cModules.toArray())); GuiceContext.instance().injector = Guice.createInjector(cModules); GuiceContext.buildingInjector = false; - GuiceContext - .instance() - .loadPostStartups(); - + startup.complete(true); + GuiceContext.instance().loadPostStartups(); + GuiceContext.instance().loadPreDestroyServices(); Runtime .getRuntime() .addShutdownHook(new Thread() { public void run() { - IGuiceContext - .getContext() - .destroy(); + GuiceContext.instance().destroy(); } }); LocalDateTime end = LocalDateTime.now(); @@ -170,10 +165,6 @@ public void run() return GuiceContext.instance().injector; } - private static Set destroyers = GuiceContext - .instance() - .getLoader(IGuicePreDestroy.class, false, ServiceLoader.load(IGuicePreDestroy.class)); - /** * Execute on Destroy */ @@ -182,7 +173,7 @@ public void destroy() { try { - for (IGuicePreDestroy destroyer : destroyers) + for (IGuicePreDestroy destroyer : loadPreDestroyServices()) { try { @@ -882,6 +873,17 @@ public Set loadPreStartupServices() return new TreeSet<>(getLoader(IGuicePreStartup.class, true, ServiceLoader.load(IGuicePreStartup.class))); } + + /** + * Returns the set of service lists of pre startup's for manual additions + * + * @return The list of guice post startups + */ + public Set loadPreDestroyServices() + { + return new TreeSet<>(getLoader(IGuicePreDestroy.class, true, ServiceLoader.load(IGuicePreDestroy.class))); + } + /** * Loads the service lists of post startup's for manual additions *